LibreOffice Module svx (master)  1
MediaShellHelpers.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 <config_features.h>
22 #include <avmedia/mediaitem.hxx>
23 #include <sfx2/request.hxx>
24 #include <sfx2/sfxsids.hrc>
25 #include <svl/whiter.hxx>
27 #include <svx/svdmrkv.hxx>
28 
30 {
31 void GetState(const SdrMarkView* pSdrView, SfxItemSet& rSet)
32 {
33  if (!pSdrView)
34  return;
35 
36  SfxWhichIter aIter(rSet);
37 
38  for (sal_uInt16 nWhich = aIter.FirstWhich(); nWhich; nWhich = aIter.NextWhich())
39  {
40  if (SID_AVMEDIA_TOOLBOX != nWhich)
41  continue;
42 
43 #if HAVE_FEATURE_AVMEDIA
44  const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
45  bool bDisable = true;
46 
47  if (1 == rMarkList.GetMarkCount())
48  {
49  SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
50 
51  if (dynamic_cast<SdrMediaObj*>(pObj))
52  {
53  ::avmedia::MediaItem aItem(SID_AVMEDIA_TOOLBOX);
54 
56  .updateMediaItem(aItem);
57  rSet.Put(aItem);
58  bDisable = false;
59  }
60  }
61 
62  if (bDisable)
63 #endif
64  rSet.DisableItem(SID_AVMEDIA_TOOLBOX);
65  }
66 }
67 
68 const ::avmedia::MediaItem* Execute(const SdrMarkView* pSdrView, SfxRequest const& rReq)
69 {
70 #if !HAVE_FEATURE_AVMEDIA
71  (void)pSdrView;
72  (void)rReq;
73  return nullptr;
74 #else
75  if (!pSdrView)
76  return nullptr;
77 
78  if (SID_AVMEDIA_TOOLBOX != rReq.GetSlot())
79  return nullptr;
80 
81  const SfxItemSet* pArgs = rReq.GetArgs();
82  if (!pArgs)
83  return nullptr;
84 
85  const ::avmedia::MediaItem* pMediaItem = pArgs->GetItemIfSet(SID_AVMEDIA_TOOLBOX, false);
86  if (!pMediaItem)
87  return nullptr;
88 
89  const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
90 
91  if (1 != rMarkList.GetMarkCount())
92  return nullptr;
93 
94  SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
95 
96  if (!dynamic_cast<SdrMediaObj*>(pObj))
97  return nullptr;
98 
100  .executeMediaItem(*pMediaItem);
101 
102  return pMediaItem;
103 #endif
104 }
105 
106 } // end of namespace svx::MediaShellHelpers
107 
108 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
size_t GetMarkCount() const
Definition: svdmark.hxx:178
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
const ::avmedia::MediaItem * Execute(const SdrMarkView *pSdrView, SfxRequest const &rReq)
sal_uInt16 FirstWhich()
SdrMark * GetMark(size_t nNum) const
Definition: svdmark.cxx:230
const SfxItemSet * GetArgs() const
sdr::contact::ViewContact & GetViewContact() const
Definition: svdobj.cxx:256
sal_uInt16 NextWhich()
void GetState(const SdrMarkView *pSdrView, SfxItemSet &rSet)
SdrObject * GetMarkedSdrObj() const
Definition: svdmark.hxx:68
const SdrMarkList & GetMarkedObjectList() const
Definition: svdmrkv.hxx:258
Abstract DrawObject.
Definition: svdobj.hxx:260
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_uInt16 GetSlot() const
void DisableItem(sal_uInt16 nWhich)
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo