xref: /trunk/main/sc/source/ui/drawfunc/mediash.cxx (revision b3f79822)
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 
35 #include "mediash.hxx"
36 #include "sc.hrc"
37 #include "viewdata.hxx"
38 #include "drawview.hxx"
39 #include "scresid.hxx"
40 
41 #define ScMediaShell
42 #include "scslots.hxx"
43 
44 #define ITEMVALUE(ItemSet,Id,Cast) ((const Cast&)(ItemSet).Get(Id)).GetValue()
45 
46 
47 SFX_IMPL_INTERFACE(ScMediaShell, ScDrawShell, ScResId(SCSTR_GRAPHICSHELL) )
48 {
49 	SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT, ScResId(RID_MEDIA_OBJECTBAR) );
50 	SFX_POPUPMENU_REGISTRATION( ScResId(RID_POPUP_MEDIA) );
51 }
52 
53 TYPEINIT1( ScMediaShell, ScDrawShell );
54 
55 ScMediaShell::ScMediaShell(ScViewData* pData) :
56 	ScDrawShell(pData)
57 {
58 	SetHelpId(HID_SCSHELL_MEDIA);
59 	SetName( String( ScResId( SCSTR_MEDIASHELL ) ) );
60 }
61 
62 ScMediaShell::~ScMediaShell()
63 {
64 }
65 
66 void ScMediaShell::GetMediaState( SfxItemSet& rSet )
67 {
68 	ScDrawView* pView = GetViewData()->GetScDrawView();
69 
70 	if( pView )
71 	{
72 		SfxWhichIter	aIter( rSet );
73 		sal_uInt16			nWhich = aIter.FirstWhich();
74 
75 		while( nWhich )
76 		{
77 			if( SID_AVMEDIA_TOOLBOX == nWhich )
78 			{
79 				SdrMarkList*	pMarkList = new SdrMarkList( pView->GetMarkedObjectList() );
80 				bool			bDisable = true;
81 
82 				if( 1 == pMarkList->GetMarkCount() )
83 				{
84 					SdrObject* pObj = pMarkList->GetMark( 0 )->GetMarkedSdrObj();
85 
86 					if( pObj && pObj->ISA( SdrMediaObj ) )
87 					{
88 						::avmedia::MediaItem aItem( SID_AVMEDIA_TOOLBOX );
89 
90 						static_cast< sdr::contact::ViewContactOfSdrMediaObj& >( pObj->GetViewContact() ).updateMediaItem( aItem );
91 						rSet.Put( aItem );
92 						bDisable = false;
93 					}
94 				}
95 
96 				if( bDisable )
97 					rSet.DisableItem( SID_AVMEDIA_TOOLBOX );
98 
99 				delete pMarkList;
100 			}
101 
102 			nWhich = aIter.NextWhich();
103 		}
104 	}
105 }
106 
107 void ScMediaShell::ExecuteMedia( SfxRequest& rReq )
108 {
109 	ScDrawView* pView = GetViewData()->GetScDrawView();
110 
111 	if( pView && SID_AVMEDIA_TOOLBOX == rReq.GetSlot() )
112 	{
113 		const SfxItemSet*	pArgs = rReq.GetArgs();
114 		const SfxPoolItem*	pItem;
115 
116 		if( !pArgs || ( SFX_ITEM_SET != pArgs->GetItemState( SID_AVMEDIA_TOOLBOX, sal_False, &pItem ) ) )
117 			pItem = NULL;
118 
119 		if( pItem )
120 		{
121 			SdrMarkList* pMarkList = new SdrMarkList( pView->GetMarkedObjectList() );
122 
123 			if( 1 == pMarkList->GetMarkCount() )
124 			{
125 				SdrObject* pObj = pMarkList->GetMark( 0 )->GetMarkedSdrObj();
126 
127 				if( pObj && pObj->ISA( SdrMediaObj ) )
128 				{
129 					static_cast< sdr::contact::ViewContactOfSdrMediaObj& >( pObj->GetViewContact() ).executeMediaItem(
130 						static_cast< const ::avmedia::MediaItem& >( *pItem ) );
131 				}
132 
133 				delete pMarkList;
134 			}
135 		}
136 	}
137 
138 	Invalidate();
139 }
140