xref: /aoo41x/main/sc/source/ui/drawfunc/mediash.cxx (revision f120fe41)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 
27 #include <sfx2/app.hxx>
28 #include <sfx2/objface.hxx>
29 #include <sfx2/request.hxx>
30 #include <avmedia/mediaitem.hxx>
31 #include <svl/whiter.hxx>
32 #include <svx/svdomedia.hxx>
33 #include <svx/sdr/contact/viewcontactofsdrmediaobj.hxx>
34 #include <sfx2/sidebar/EnumContext.hxx>
35 
36 #include "mediash.hxx"
37 #include "sc.hrc"
38 #include "viewdata.hxx"
39 #include "drawview.hxx"
40 #include "scresid.hxx"
41 
42 #define ScMediaShell
43 #include "scslots.hxx"
44 
45 #define ITEMVALUE(ItemSet,Id,Cast) ((const Cast&)(ItemSet).Get(Id)).GetValue()
46 
47 
SFX_IMPL_INTERFACE(ScMediaShell,ScDrawShell,ScResId (SCSTR_GRAPHICSHELL))48 SFX_IMPL_INTERFACE(ScMediaShell, ScDrawShell, ScResId(SCSTR_GRAPHICSHELL) )
49 {
50 	SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT, ScResId(RID_MEDIA_OBJECTBAR) );
51 	SFX_POPUPMENU_REGISTRATION( ScResId(RID_POPUP_MEDIA) );
52 }
53 
54 TYPEINIT1( ScMediaShell, ScDrawShell );
55 
ScMediaShell(ScViewData * pData)56 ScMediaShell::ScMediaShell(ScViewData* pData) :
57 	ScDrawShell(pData)
58 {
59 	SetHelpId(HID_SCSHELL_MEDIA);
60 	SetName( String( ScResId( SCSTR_MEDIASHELL ) ) );
61     SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_Media));
62 }
63 
~ScMediaShell()64 ScMediaShell::~ScMediaShell()
65 {
66 }
67 
GetMediaState(SfxItemSet & rSet)68 void ScMediaShell::GetMediaState( SfxItemSet& rSet )
69 {
70 	ScDrawView* pView = GetViewData()->GetScDrawView();
71 
72 	if( pView )
73 	{
74 		SfxWhichIter	aIter( rSet );
75 		sal_uInt16			nWhich = aIter.FirstWhich();
76 
77 		while( nWhich )
78 		{
79 			if( SID_AVMEDIA_TOOLBOX == nWhich )
80 			{
81 				SdrMarkList*	pMarkList = new SdrMarkList( pView->GetMarkedObjectList() );
82 				bool			bDisable = true;
83 
84 				if( 1 == pMarkList->GetMarkCount() )
85 				{
86 					SdrObject* pObj = pMarkList->GetMark( 0 )->GetMarkedSdrObj();
87 
88 					if( pObj && pObj->ISA( SdrMediaObj ) )
89 					{
90 						::avmedia::MediaItem aItem( SID_AVMEDIA_TOOLBOX );
91 
92 						static_cast< sdr::contact::ViewContactOfSdrMediaObj& >( pObj->GetViewContact() ).updateMediaItem( aItem );
93 						rSet.Put( aItem );
94 						bDisable = false;
95 					}
96 				}
97 
98 				if( bDisable )
99 					rSet.DisableItem( SID_AVMEDIA_TOOLBOX );
100 
101 				delete pMarkList;
102 			}
103 
104 			nWhich = aIter.NextWhich();
105 		}
106 	}
107 }
108 
ExecuteMedia(SfxRequest & rReq)109 void ScMediaShell::ExecuteMedia( SfxRequest& rReq )
110 {
111 	ScDrawView* pView = GetViewData()->GetScDrawView();
112 
113 	if( pView && SID_AVMEDIA_TOOLBOX == rReq.GetSlot() )
114 	{
115 		const SfxItemSet*	pArgs = rReq.GetArgs();
116 		const SfxPoolItem*	pItem;
117 
118 		if( !pArgs || ( SFX_ITEM_SET != pArgs->GetItemState( SID_AVMEDIA_TOOLBOX, sal_False, &pItem ) ) )
119 			pItem = NULL;
120 
121 		if( pItem )
122 		{
123 			SdrMarkList* pMarkList = new SdrMarkList( pView->GetMarkedObjectList() );
124 
125 			if( 1 == pMarkList->GetMarkCount() )
126 			{
127 				SdrObject* pObj = pMarkList->GetMark( 0 )->GetMarkedSdrObj();
128 
129 				if( pObj && pObj->ISA( SdrMediaObj ) )
130 				{
131 					static_cast< sdr::contact::ViewContactOfSdrMediaObj& >( pObj->GetViewContact() ).executeMediaItem(
132 						static_cast< const ::avmedia::MediaItem& >( *pItem ) );
133 				}
134 
135 				delete pMarkList;
136 			}
137 		}
138 	}
139 
140 	Invalidate();
141 }
142