Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / source / ui / drawfunc / mediash.cxx
blobb70c5cb31d23230cca5387929ea9d128166bb045
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <memory>
21 #include <sfx2/objface.hxx>
22 #include <sfx2/request.hxx>
23 #include <avmedia/mediaitem.hxx>
24 #include <svl/whiter.hxx>
25 #include <svx/svdomedia.hxx>
26 #include <svx/sdr/contact/viewcontactofsdrmediaobj.hxx>
27 #include <vcl/EnumContext.hxx>
29 #include <mediash.hxx>
30 #include <strings.hrc>
31 #include <viewdata.hxx>
32 #include <drawview.hxx>
33 #include <scresid.hxx>
35 #define ShellClass_ScMediaShell
36 #include <scslots.hxx>
38 SFX_IMPL_INTERFACE(ScMediaShell, ScDrawShell)
40 void ScMediaShell::InitInterface_Impl()
42 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, SfxVisibilityFlags::Invisible, ToolbarId::Media_Objectbar);
44 GetStaticInterface()->RegisterPopupMenu("media");
48 ScMediaShell::ScMediaShell(ScViewData* pData) :
49 ScDrawShell(pData)
51 SetName( ScResId( SCSTR_MEDIASHELL ) );
52 SfxShell::SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::Media));
55 ScMediaShell::~ScMediaShell()
59 void ScMediaShell::GetMediaState( SfxItemSet& rSet )
61 ScDrawView* pView = GetViewData()->GetScDrawView();
63 if( pView )
65 SfxWhichIter aIter( rSet );
66 sal_uInt16 nWhich = aIter.FirstWhich();
68 while( nWhich )
70 if( SID_AVMEDIA_TOOLBOX == nWhich )
72 std::unique_ptr<SdrMarkList> pMarkList(new SdrMarkList( pView->GetMarkedObjectList() ));
73 bool bDisable = true;
75 if( 1 == pMarkList->GetMarkCount() )
77 SdrObject* pObj = pMarkList->GetMark( 0 )->GetMarkedSdrObj();
79 if( dynamic_cast<const SdrMediaObj*>( pObj) )
81 ::avmedia::MediaItem aItem( SID_AVMEDIA_TOOLBOX );
83 static_cast< sdr::contact::ViewContactOfSdrMediaObj& >( pObj->GetViewContact() ).updateMediaItem( aItem );
84 rSet.Put( aItem );
85 bDisable = false;
89 if( bDisable )
90 rSet.DisableItem( SID_AVMEDIA_TOOLBOX );
93 nWhich = aIter.NextWhich();
98 void ScMediaShell::ExecuteMedia( const SfxRequest& rReq )
100 ScDrawView* pView = GetViewData()->GetScDrawView();
102 if( pView && SID_AVMEDIA_TOOLBOX == rReq.GetSlot() )
104 const SfxItemSet* pArgs = rReq.GetArgs();
105 const SfxPoolItem* pItem;
107 if( !pArgs || ( SfxItemState::SET != pArgs->GetItemState( SID_AVMEDIA_TOOLBOX, false, &pItem ) ) )
108 pItem = nullptr;
110 if( pItem )
112 std::unique_ptr<SdrMarkList> pMarkList(new SdrMarkList( pView->GetMarkedObjectList() ));
114 if( 1 == pMarkList->GetMarkCount() )
116 SdrObject* pObj = pMarkList->GetMark( 0 )->GetMarkedSdrObj();
118 if( dynamic_cast<const SdrMediaObj*>( pObj) )
120 static_cast< sdr::contact::ViewContactOfSdrMediaObj& >( pObj->GetViewContact() ).executeMediaItem(
121 static_cast< const ::avmedia::MediaItem& >( *pItem ) );
127 Invalidate();
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */