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