1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <cmdid.h>
21 #include <hintids.hxx>
22 #include <svl/stritem.hxx>
23 #include <svl/whiter.hxx>
24 #include <svl/urihelper.hxx>
25 #include <sfx2/dispatch.hxx>
26 #include <editeng/sizeitem.hxx>
27 #include <editeng/protitem.hxx>
28 #include <sfx2/request.hxx>
29 #include <svl/srchitem.hxx>
30 #include <sfx2/htmlmode.hxx>
31 #include <svx/sdgluitm.hxx>
32 #include <svx/sdgcoitm.hxx>
33 #include <svx/sdggaitm.hxx>
34 #include <svx/sdgtritm.hxx>
35 #include <svx/sdginitm.hxx>
36 #include <svx/sdgmoitm.hxx>
37 #include <svx/svdview.hxx>
38 #include <editeng/brushitem.hxx>
39 #include <svx/grfflt.hxx>
40 #include <fmturl.hxx>
41 #include <view.hxx>
42 #include <wrtsh.hxx>
43 #include <viewopt.hxx>
44 #include <swmodule.hxx>
45 #include <frmatr.hxx>
46 #include <swundo.hxx>
47 #include <uitool.hxx>
48 #include <docsh.hxx>
49 #include <mediash.hxx>
50 #include <frmmgr.hxx>
51 #include <frmdlg.hxx>
52 #include <frmfmt.hxx>
53 #include <grfatr.hxx>
54 #include <usrpref.hxx>
55 #include <edtwin.hxx>
56 #include <swwait.hxx>
57 
58 #include <sfx2/objface.hxx>
59 #include <vcl/EnumContext.hxx>
60 #include <svx/svdomedia.hxx>
61 #include <svx/sdr/contact/viewcontactofsdrmediaobj.hxx>
62 #include <avmedia/mediaitem.hxx>
63 
64 #define ShellClass_SwMediaShell
65 #include <sfx2/msg.hxx>
66 #include <swslots.hxx>
67 #include <swabstdlg.hxx>
68 #include <memory>
69 
SFX_IMPL_INTERFACE(SwMediaShell,SwBaseShell)70 SFX_IMPL_INTERFACE(SwMediaShell, SwBaseShell)
71 
72 void SwMediaShell::InitInterface_Impl()
73 {
74     GetStaticInterface()->RegisterPopupMenu("media");
75 
76     GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, SfxVisibilityFlags::Invisible, ToolbarId::Media_Toolbox);
77 }
78 
ExecMedia(SfxRequest const & rReq)79 void SwMediaShell::ExecMedia(SfxRequest const &rReq)
80 {
81     SwWrtShell* pSh = &GetShell();
82     SdrView*    pSdrView = pSh->GetDrawView();
83 
84     if( pSdrView )
85     {
86         const SfxItemSet*   pArgs = rReq.GetArgs();
87         bool                bChanged = pSdrView->GetModel()->IsChanged();
88 
89         pSdrView->GetModel()->SetChanged( false );
90 
91         switch( rReq.GetSlot() )
92         {
93             case SID_DELETE:
94             {
95                 if( pSh->IsObjSelected() )
96                 {
97                     pSh->SetModified();
98                     pSh->DelSelectedObj();
99 
100                     if( pSh->IsSelFrameMode() )
101                         pSh->LeaveSelFrameMode();
102 
103                     GetView().AttrChangedNotify(nullptr);
104                 }
105             }
106             break;
107 
108             case SID_AVMEDIA_TOOLBOX:
109             {
110                 if( pSh->IsObjSelected() )
111                 {
112                     const SfxPoolItem*  pItem;
113 
114                     if( !pArgs || ( SfxItemState::SET != pArgs->GetItemState( SID_AVMEDIA_TOOLBOX, false, &pItem ) ) )
115                         pItem = nullptr;
116 
117                     if( pItem )
118                     {
119                         std::unique_ptr<SdrMarkList> pMarkList(new SdrMarkList( pSdrView->GetMarkedObjectList() ));
120 
121                         if( 1 == pMarkList->GetMarkCount() )
122                         {
123                             SdrObject* pObj = pMarkList->GetMark( 0 )->GetMarkedSdrObj();
124 
125                             if( dynamic_cast< const SdrMediaObj *>( pObj ) )
126                             {
127                                 static_cast< sdr::contact::ViewContactOfSdrMediaObj& >( pObj->GetViewContact() ).executeMediaItem(
128                                     static_cast< const ::avmedia::MediaItem& >( *pItem ) );
129                             }
130                         }
131                     }
132                 }
133             }
134             break;
135 
136             default:
137             break;
138         }
139 
140         if( pSdrView->GetModel()->IsChanged() )
141             GetShell().SetModified();
142         else if( bChanged )
143             pSdrView->GetModel()->SetChanged();
144     }
145 }
146 
GetMediaState(SfxItemSet & rSet)147 void SwMediaShell::GetMediaState(SfxItemSet &rSet)
148 {
149     SfxWhichIter    aIter( rSet );
150     sal_uInt16          nWhich = aIter.FirstWhich();
151 
152     while( nWhich )
153     {
154         if( SID_AVMEDIA_TOOLBOX == nWhich )
155         {
156             SwWrtShell& rSh = GetShell();
157             SdrView*    pView = rSh.GetDrawView();
158 
159             if( pView )
160             {
161                 bool bDisable = true;
162                 std::unique_ptr<SdrMarkList> pMarkList(new SdrMarkList( pView->GetMarkedObjectList() ));
163 
164                 if( 1 == pMarkList->GetMarkCount() )
165                 {
166                     SdrObject* pObj = pMarkList->GetMark( 0 )->GetMarkedSdrObj();
167 
168                     if( dynamic_cast< const SdrMediaObj *>( pObj ) )
169                     {
170                         ::avmedia::MediaItem aItem( SID_AVMEDIA_TOOLBOX );
171 
172                         static_cast< sdr::contact::ViewContactOfSdrMediaObj& >( pObj->GetViewContact() ).updateMediaItem( aItem );
173                         rSet.Put( aItem );
174                         bDisable = false;
175                     }
176                 }
177 
178                 if( bDisable )
179                     rSet.DisableItem( SID_AVMEDIA_TOOLBOX );
180             }
181         }
182 
183         nWhich = aIter.NextWhich();
184     }
185 }
186 
SwMediaShell(SwView & _rView)187 SwMediaShell::SwMediaShell(SwView &_rView) :
188     SwBaseShell(_rView)
189 
190 {
191     SetName("Media Playback");
192     SfxShell::SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::Media));
193 }
194 
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
196