xref: /trunk/main/sw/source/ui/shells/mediash.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_sw.hxx"
30 
31 
32 
33 
34 #ifndef _CMDID_H
35 #include <cmdid.h>
36 #endif
37 #include <hintids.hxx>
38 #include <tools/urlobj.hxx>
39 #include <vcl/msgbox.hxx>
40 #include <svl/stritem.hxx>
41 #include <svl/whiter.hxx>
42 #include <svl/urihelper.hxx>
43 #include <sfx2/dispatch.hxx>
44 #include <editeng/sizeitem.hxx>
45 #include <editeng/protitem.hxx>
46 #include <sfx2/request.hxx>
47 #include <svl/srchitem.hxx>
48 #include <svx/htmlmode.hxx>
49 #include <svx/sdgluitm.hxx>
50 #include <svx/sdgcoitm.hxx>
51 #include <svx/sdggaitm.hxx>
52 #include <svx/sdgtritm.hxx>
53 #include <svx/sdginitm.hxx>
54 #include <svx/sdgmoitm.hxx>
55 #include <editeng/brshitem.hxx>
56 #include <svx/grfflt.hxx>
57 #include <fmturl.hxx>
58 #include <view.hxx>
59 #include <wrtsh.hxx>
60 #include <viewopt.hxx>
61 #include <swmodule.hxx>
62 #include <frmatr.hxx>
63 #include <swundo.hxx>
64 #include <uitool.hxx>
65 #include <docsh.hxx>
66 #include <mediash.hxx>
67 #include <frmmgr.hxx>
68 #include <frmdlg.hxx>
69 #include <frmfmt.hxx>
70 #include <grfatr.hxx>
71 #include <usrpref.hxx>
72 #include <edtwin.hxx>
73 #include <swwait.hxx>
74 #ifndef _SHELLS_HRC
75 #include <shells.hrc>
76 #endif
77 #ifndef _POPUP_HRC
78 #include <popup.hrc>
79 #endif
80 
81 #include <sfx2/objface.hxx>
82 #include <svx/svdomedia.hxx>
83 #include <svx/sdr/contact/viewcontactofsdrmediaobj.hxx>
84 #include <avmedia/mediaitem.hxx>
85 
86 #define SwMediaShell
87 #include <sfx2/msg.hxx>
88 #include "swslots.hxx"
89 #include "swabstdlg.hxx"
90 
91 SFX_IMPL_INTERFACE(SwMediaShell, SwBaseShell, SW_RES(STR_SHELLNAME_MEDIA))
92 {
93 	SFX_POPUPMENU_REGISTRATION(SW_RES(MN_MEDIA_POPUPMENU));
94 	SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT, SW_RES(RID_MEDIA_TOOLBOX));
95 }
96 
97 // ------------------------------------------------------------------------------
98 
99 void SwMediaShell::ExecMedia(SfxRequest &rReq)
100 {
101 	SwWrtShell* pSh = &GetShell();
102 	SdrView*	pSdrView = pSh->GetDrawView();
103 
104 	if( pSdrView )
105 	{
106     	const SfxItemSet*   pArgs = rReq.GetArgs();
107 	    sal_uInt16		        nSlotId = rReq.GetSlot();
108     	sal_Bool                bChanged = pSdrView->GetModel()->IsChanged();
109 
110 	    pSdrView->GetModel()->SetChanged( sal_False );
111 
112 	    switch( nSlotId )
113 	    {
114 		    case SID_DELETE:
115 		    {
116 			    if( pSh->IsObjSelected() )
117 			    {
118     				pSh->SetModified();
119 				    pSh->DelSelectedObj();
120 
121 				    if( pSh->IsSelFrmMode() )
122 					    pSh->LeaveSelFrmMode();
123 
124 				    GetView().AttrChangedNotify( pSh );
125 			    }
126 		    }
127 		    break;
128 
129 		    case( SID_AVMEDIA_TOOLBOX ):
130 		    {
131 			    if( pSh->IsObjSelected() )
132 		        {
133 			        const SfxPoolItem*	pItem;
134 
135 			        if( !pArgs || ( SFX_ITEM_SET != pArgs->GetItemState( SID_AVMEDIA_TOOLBOX, sal_False, &pItem ) ) )
136 				        pItem = NULL;
137 
138 			        if( pItem )
139 			        {
140 				        SdrMarkList* pMarkList = new SdrMarkList( pSdrView->GetMarkedObjectList() );
141 
142 				        if( 1 == pMarkList->GetMarkCount() )
143 				        {
144 					        SdrObject* pObj = pMarkList->GetMark( 0 )->GetMarkedSdrObj();
145 
146 					        if( pObj && pObj->ISA( SdrMediaObj ) )
147 					        {
148 						        static_cast< sdr::contact::ViewContactOfSdrMediaObj& >( pObj->GetViewContact() ).executeMediaItem(
149 							        static_cast< const ::avmedia::MediaItem& >( *pItem ) );
150 					        }
151 				        }
152 
153 				        delete pMarkList;
154 			        }
155 		        }
156             }
157 		    break;
158 
159 		    default:
160 		    break;
161         }
162 
163 	    if( pSdrView->GetModel()->IsChanged() )
164 		    GetShell().SetModified();
165 	    else if( bChanged )
166 		    pSdrView->GetModel()->SetChanged(sal_True);
167     }
168 }
169 
170 // ------------------------------------------------------------------------------
171 
172 void SwMediaShell::GetMediaState(SfxItemSet &rSet)
173 {
174 	SfxWhichIter	aIter( rSet );
175 	sal_uInt16			nWhich = aIter.FirstWhich();
176 
177 	while( nWhich )
178 	{
179 		if( SID_AVMEDIA_TOOLBOX == nWhich )
180 		{
181 			SwWrtShell&	rSh = GetShell();
182 			SdrView*	pView = rSh.GetDrawView();
183 			bool		bDisable = true;
184 
185 			if( pView )
186 			{
187 				SdrMarkList* pMarkList = new SdrMarkList( pView->GetMarkedObjectList() );
188 
189 				if( 1 == pMarkList->GetMarkCount() )
190 				{
191 					SdrObject* pObj = pMarkList->GetMark( 0 )->GetMarkedSdrObj();
192 
193 					if( pObj && pObj->ISA( SdrMediaObj ) )
194 					{
195 						::avmedia::MediaItem aItem( SID_AVMEDIA_TOOLBOX );
196 
197 						static_cast< sdr::contact::ViewContactOfSdrMediaObj& >( pObj->GetViewContact() ).updateMediaItem( aItem );
198 						rSet.Put( aItem );
199 						bDisable = false;
200 					}
201 				}
202 
203 				if( bDisable )
204 					rSet.DisableItem( SID_AVMEDIA_TOOLBOX );
205 
206 				delete pMarkList;
207 			}
208 		}
209 
210 		nWhich = aIter.NextWhich();
211 	}
212 }
213 
214 // ------------------------------------------------------------------------------
215 
216 SwMediaShell::SwMediaShell(SwView &_rView) :
217     SwBaseShell(_rView)
218 
219 {
220 	SetName(String::CreateFromAscii("Media Playback"));
221 	SetHelpId(SW_MEDIASHELL);
222 }
223