LibreOffice Module sc (master)  1
mediash.cxx
Go to the documentation of this file.
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 <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>
27 #include <vcl/EnumContext.hxx>
28 
29 #include <mediash.hxx>
30 #include <strings.hrc>
31 #include <viewdata.hxx>
32 #include <drawview.hxx>
33 #include <scresid.hxx>
34 
35 #define ShellClass_ScMediaShell
36 #include <scslots.hxx>
37 
39 
40 void ScMediaShell::InitInterface_Impl()
41 {
42  GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, SfxVisibilityFlags::Invisible, ToolbarId::Media_Objectbar);
43 
44  GetStaticInterface()->RegisterPopupMenu("media");
45 }
46 
47 
49  ScDrawShell(rData)
50 {
51  SetName( ScResId( SCSTR_MEDIASHELL ) );
53 }
54 
56 {
57 }
58 
60 {
62 
63  if( !pView )
64  return;
65 
66  SfxWhichIter aIter( rSet );
67  sal_uInt16 nWhich = aIter.FirstWhich();
68 
69  while( nWhich )
70  {
71  if( SID_AVMEDIA_TOOLBOX == nWhich )
72  {
73  std::unique_ptr<SdrMarkList> pMarkList(new SdrMarkList( pView->GetMarkedObjectList() ));
74  bool bDisable = true;
75 
76  if( 1 == pMarkList->GetMarkCount() )
77  {
78  SdrObject* pObj = pMarkList->GetMark( 0 )->GetMarkedSdrObj();
79 
80  if( dynamic_cast<const SdrMediaObj*>( pObj) )
81  {
82  ::avmedia::MediaItem aItem( SID_AVMEDIA_TOOLBOX );
83 
84  static_cast< sdr::contact::ViewContactOfSdrMediaObj& >( pObj->GetViewContact() ).updateMediaItem( aItem );
85  rSet.Put( aItem );
86  bDisable = false;
87  }
88  }
89 
90  if( bDisable )
91  rSet.DisableItem( SID_AVMEDIA_TOOLBOX );
92  }
93 
94  nWhich = aIter.NextWhich();
95  }
96 }
97 
99 {
100  ScDrawView* pView = GetViewData().GetScDrawView();
101 
102  if( pView && SID_AVMEDIA_TOOLBOX == rReq.GetSlot() )
103  {
104  const SfxItemSet* pArgs = rReq.GetArgs();
105  const SfxPoolItem* pItem;
106 
107  if( !pArgs || ( SfxItemState::SET != pArgs->GetItemState( SID_AVMEDIA_TOOLBOX, false, &pItem ) ) )
108  pItem = nullptr;
109 
110  if( pItem )
111  {
112  std::unique_ptr<SdrMarkList> pMarkList(new SdrMarkList( pView->GetMarkedObjectList() ));
113 
114  if( 1 == pMarkList->GetMarkCount() )
115  {
116  SdrObject* pObj = pMarkList->GetMark( 0 )->GetMarkedSdrObj();
117 
118  if( dynamic_cast<const SdrMediaObj*>( pObj) )
119  {
120  static_cast< sdr::contact::ViewContactOfSdrMediaObj& >( pObj->GetViewContact() ).executeMediaItem(
121  static_cast< const ::avmedia::MediaItem& >( *pItem ) );
122  }
123  }
124  }
125  }
126 
127  Invalidate();
128 }
129 
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define SFX_IMPL_INTERFACE(Class, SuperClass)
ScViewData & GetViewData()
Definition: drawsh.hxx:51
sal_uInt16 FirstWhich()
const SfxItemSet * GetArgs() const
sdr::contact::ViewContact & GetViewContact() const
sal_uInt16 NextWhich()
ScDrawView * GetScDrawView()
Definition: viewdata.cxx:3074
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
void ExecuteMedia(const SfxRequest &rReq)
Definition: mediash.cxx:98
const SdrMarkList & GetMarkedObjectList() const
OUString ScResId(const char *pId)
Definition: scdll.cxx:95
ScMediaShell(ScViewData &rData)
Definition: mediash.cxx:48
void SetName(const OUString &rName)
#define SFX_OBJECTBAR_OBJECT
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_uInt16 GetSlot() const
static const OUString & GetContextName(const Context eContext)
void DisableItem(sal_uInt16 nWhich)
virtual void Invalidate(sal_uInt16 nId=0)
virtual ~ScMediaShell() override
Definition: mediash.cxx:55
void GetMediaState(SfxItemSet &rSet)
Definition: mediash.cxx:59
void SetContextName(const OUString &rsContextName)
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo