xref: /trunk/main/sd/source/ui/view/MediaObjectBar.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 #include "MediaObjectBar.hxx"
32 #include <avmedia/mediaitem.hxx>
33 #include <sfx2/msg.hxx>
34 #include <sfx2/app.hxx>
35 #include <sfx2/sfxsids.hrc>
36 #include <sfx2/request.hxx>
37 #include <sfx2/objface.hxx>
38 #include <svl/whiter.hxx>
39 #include <svl/itempool.hxx>
40 #include <svx/svdomedia.hxx>
41 #include <svx/sdr/contact/viewcontactofsdrmediaobj.hxx>
42 
43 #include "app.hrc"
44 #include "res_bmp.hrc"
45 #include "glob.hrc"
46 #include "strings.hrc"
47 #include "DrawDocShell.hxx"
48 #include "ViewShell.hxx"
49 #include "Window.hxx"
50 #include "drawview.hxx"
51 #include "sdresid.hxx"
52 #include "drawdoc.hxx"
53 
54 using namespace sd;
55 
56 #define MediaObjectBar
57 #include "sdslots.hxx"
58 
59 namespace sd {
60 
61 // ------------------
62 // - MediaObjectBar -
63 // ------------------
64 
65 TYPEINIT1( MediaObjectBar, SfxShell );
66 
67 // -----------------------------------------------------------------------------
68 
69 SFX_IMPL_INTERFACE( MediaObjectBar, SfxShell, SdResId( STR_MEDIAOBJECTBARSHELL ) )
70 {
71 }
72 
73 // -----------------------------------------------------------------------------
74 
75 MediaObjectBar::MediaObjectBar( ViewShell* pSdViewShell, ::sd::View* pSdView ) :
76 	SfxShell( pSdViewShell->GetViewShell() ),
77     mpView( pSdView ),
78     mpViewSh( pSdViewShell )
79 {
80 	DrawDocShell* pDocShell = mpViewSh->GetDocSh();
81 
82 	SetPool( &pDocShell->GetPool() );
83 	SetUndoManager( pDocShell->GetUndoManager() );
84 	SetRepeatTarget( mpView );
85 	SetHelpId( SD_IF_SDDRAWMEDIAOBJECTBAR );
86 	SetName( String( SdResId( RID_DRAW_MEDIA_TOOLBOX ) ) );
87 }
88 
89 // -----------------------------------------------------------------------------
90 
91 MediaObjectBar::~MediaObjectBar()
92 {
93 	SetRepeatTarget( NULL );
94 }
95 
96 // -----------------------------------------------------------------------------
97 
98 void MediaObjectBar::GetState( SfxItemSet& rSet )
99 {
100 	SfxWhichIter	aIter( rSet );
101 	sal_uInt16			nWhich = aIter.FirstWhich();
102 
103 	while( nWhich )
104 	{
105 		if( SID_AVMEDIA_TOOLBOX == nWhich )
106 		{
107 			SdrMarkList* pMarkList = new SdrMarkList( mpView->GetMarkedObjectList() );
108 			bool		 bDisable = true;
109 
110 			if( 1 == pMarkList->GetMarkCount() )
111 			{
112 				SdrObject* pObj =pMarkList->GetMark( 0 )->GetMarkedSdrObj();
113 
114 				if( pObj && pObj->ISA( SdrMediaObj ) )
115 				{
116 					::avmedia::MediaItem aItem( SID_AVMEDIA_TOOLBOX );
117 
118 					static_cast< sdr::contact::ViewContactOfSdrMediaObj& >( pObj->GetViewContact() ).updateMediaItem( aItem );
119 					rSet.Put( aItem );
120 					bDisable = false;
121 				}
122 			}
123 
124 			if( bDisable )
125 				rSet.DisableItem( SID_AVMEDIA_TOOLBOX );
126 
127 			delete pMarkList;
128 		}
129 
130 		nWhich = aIter.NextWhich();
131 	}
132 }
133 
134 // -----------------------------------------------------------------------------
135 
136 void MediaObjectBar::Execute( SfxRequest& rReq )
137 {
138 	if( SID_AVMEDIA_TOOLBOX == rReq.GetSlot() )
139 	{
140 		const SfxItemSet*	pArgs = rReq.GetArgs();
141 		const SfxPoolItem*	pItem;
142 
143 		if( !pArgs || ( SFX_ITEM_SET != pArgs->GetItemState( SID_AVMEDIA_TOOLBOX, sal_False, &pItem ) ) )
144 			pItem = NULL;
145 
146 		if( pItem )
147 		{
148 			SdrMarkList* pMarkList = new SdrMarkList( mpView->GetMarkedObjectList() );
149 
150 			if( 1 == pMarkList->GetMarkCount() )
151 			{
152 				SdrObject* pObj = pMarkList->GetMark( 0 )->GetMarkedSdrObj();
153 
154 				if( pObj && pObj->ISA( SdrMediaObj ) )
155 				{
156 					static_cast< sdr::contact::ViewContactOfSdrMediaObj& >( pObj->GetViewContact() ).executeMediaItem(
157 						static_cast< const ::avmedia::MediaItem& >( *pItem ) );
158 				}
159 			}
160 
161 			delete pMarkList;
162 		}
163 	}
164 }
165 
166 } // end of namespace sd
167