xref: /aoo42x/main/sd/source/ui/view/MediaObjectBar.cxx (revision 5b190011)
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_sd.hxx"
26 
27 #include "MediaObjectBar.hxx"
28 #include <avmedia/mediaitem.hxx>
29 #include <sfx2/msg.hxx>
30 #include <sfx2/app.hxx>
31 #include <sfx2/sfxsids.hrc>
32 #include <sfx2/request.hxx>
33 #include <sfx2/objface.hxx>
34 #include <svl/whiter.hxx>
35 #include <svl/itempool.hxx>
36 #include <svx/svdomedia.hxx>
37 #include <svx/sdr/contact/viewcontactofsdrmediaobj.hxx>
38 
39 #include "app.hrc"
40 #include "res_bmp.hrc"
41 #include "glob.hrc"
42 #include "strings.hrc"
43 #include "DrawDocShell.hxx"
44 #include "ViewShell.hxx"
45 #include "Window.hxx"
46 #include "drawview.hxx"
47 #include "sdresid.hxx"
48 #include "drawdoc.hxx"
49 
50 using namespace sd;
51 
52 #define MediaObjectBar
53 #include "sdslots.hxx"
54 
55 namespace sd {
56 
57 // ------------------
58 // - MediaObjectBar -
59 // ------------------
60 
61 TYPEINIT1( MediaObjectBar, SfxShell );
62 
63 // -----------------------------------------------------------------------------
64 
65 SFX_IMPL_INTERFACE( MediaObjectBar, SfxShell, SdResId( STR_MEDIAOBJECTBARSHELL ) )
66 {
67 }
68 
69 // -----------------------------------------------------------------------------
70 
71 MediaObjectBar::MediaObjectBar( ViewShell* pSdViewShell, ::sd::View* pSdView ) :
72 	SfxShell( pSdViewShell->GetViewShell() ),
73     mpView( pSdView ),
74     mpViewSh( pSdViewShell )
75 {
76 	DrawDocShell* pDocShell = mpViewSh->GetDocSh();
77 
78 	SetPool( &pDocShell->GetPool() );
79 	SetUndoManager( pDocShell->GetUndoManager() );
80 	SetRepeatTarget( mpView );
81 	SetHelpId( SD_IF_SDDRAWMEDIAOBJECTBAR );
82 	SetName( String( SdResId( RID_DRAW_MEDIA_TOOLBOX ) ) );
83 }
84 
85 // -----------------------------------------------------------------------------
86 
87 MediaObjectBar::~MediaObjectBar()
88 {
89 	SetRepeatTarget( NULL );
90 }
91 
92 // -----------------------------------------------------------------------------
93 
94 void MediaObjectBar::GetState( SfxItemSet& rSet )
95 {
96 	SfxWhichIter	aIter( rSet );
97 	sal_uInt16			nWhich = aIter.FirstWhich();
98 
99 	while( nWhich )
100 	{
101 		if( SID_AVMEDIA_TOOLBOX == nWhich )
102 		{
103 			SdrMarkList* pMarkList = new SdrMarkList( mpView->GetMarkedObjectList() );
104 			bool		 bDisable = true;
105 
106 			if( 1 == pMarkList->GetMarkCount() )
107 			{
108 				SdrObject* pObj =pMarkList->GetMark( 0 )->GetMarkedSdrObj();
109 
110 				if( pObj && pObj->ISA( SdrMediaObj ) )
111 				{
112 					::avmedia::MediaItem aItem( SID_AVMEDIA_TOOLBOX );
113 
114 					static_cast< sdr::contact::ViewContactOfSdrMediaObj& >( pObj->GetViewContact() ).updateMediaItem( aItem );
115 					rSet.Put( aItem );
116 					bDisable = false;
117 				}
118 			}
119 
120 			if( bDisable )
121 				rSet.DisableItem( SID_AVMEDIA_TOOLBOX );
122 
123 			delete pMarkList;
124 		}
125 
126 		nWhich = aIter.NextWhich();
127 	}
128 }
129 
130 // -----------------------------------------------------------------------------
131 
132 void MediaObjectBar::Execute( SfxRequest& rReq )
133 {
134 	if( SID_AVMEDIA_TOOLBOX == rReq.GetSlot() )
135 	{
136 		const SfxItemSet*	pArgs = rReq.GetArgs();
137 		const SfxPoolItem*	pItem;
138 
139 		if( !pArgs || ( SFX_ITEM_SET != pArgs->GetItemState( SID_AVMEDIA_TOOLBOX, sal_False, &pItem ) ) )
140 			pItem = NULL;
141 
142 		if( pItem )
143 		{
144 			SdrMarkList* pMarkList = new SdrMarkList( mpView->GetMarkedObjectList() );
145 
146 			if( 1 == pMarkList->GetMarkCount() )
147 			{
148 				SdrObject* pObj = pMarkList->GetMark( 0 )->GetMarkedSdrObj();
149 
150 				if( pObj && pObj->ISA( SdrMediaObj ) )
151 				{
152 					static_cast< sdr::contact::ViewContactOfSdrMediaObj& >( pObj->GetViewContact() ).executeMediaItem(
153 						static_cast< const ::avmedia::MediaItem& >( *pItem ) );
154 				}
155 			}
156 
157 			delete pMarkList;
158 		}
159 	}
160 }
161 
162 } // end of namespace sd
163