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 
29 #include <memory>
30 
32 {
33 void GetState(const SdrMarkView* pSdrView, SfxItemSet& rSet)
34 {
35  if (!pSdrView)
36  return;
37 
38  SfxWhichIter aIter(rSet);
39 
40  for (sal_uInt16 nWhich = aIter.FirstWhich(); nWhich; nWhich = aIter.NextWhich())
41  {
42  if (SID_AVMEDIA_TOOLBOX != nWhich)
43  continue;
44 
45 #if HAVE_FEATURE_AVMEDIA
46  const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
47  bool bDisable = true;
48 
49  if (1 == rMarkList.GetMarkCount())
50  {
51  SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
52 
53  if (dynamic_cast<SdrMediaObj*>(pObj))
54  {
55  ::avmedia::MediaItem aItem(SID_AVMEDIA_TOOLBOX);
56 
58  .updateMediaItem(aItem);
59  rSet.Put(aItem);
60  bDisable = false;
61  }
62  }
63 
64  if (bDisable)
65 #endif
66  rSet.DisableItem(SID_AVMEDIA_TOOLBOX);
67  }
68 }
69 
70 const ::avmedia::MediaItem* Execute(const SdrMarkView* pSdrView, SfxRequest const& rReq)
71 {
72 #if !HAVE_FEATURE_AVMEDIA
73  (void)pSdrView;
74  (void)rReq;
75  return nullptr;
76 #else
77  if (!pSdrView)
78  return nullptr;
79 
80  if (SID_AVMEDIA_TOOLBOX != rReq.GetSlot())
81  return nullptr;
82 
83  const SfxItemSet* pArgs = rReq.GetArgs();
84  const SfxPoolItem* pItem;
85 
86  if (!pArgs || (SfxItemState::SET != pArgs->GetItemState(SID_AVMEDIA_TOOLBOX, false, &pItem)))
87  pItem = nullptr;
88 
89  if (!pItem)
90  return nullptr;
91 
92  const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
93 
94  if (1 != rMarkList.GetMarkCount())
95  return nullptr;
96 
97  SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
98 
99  if (!dynamic_cast<SdrMediaObj*>(pObj))
100  return nullptr;
101 
102  const ::avmedia::MediaItem* pMediaItem = static_cast<const ::avmedia::MediaItem*>(pItem);
104  .executeMediaItem(*pMediaItem);
105 
106  return pMediaItem;
107 #endif
108 }
109 
110 } // end of namespace svx::MediaShellHelpers
111 
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
size_t GetMarkCount() const
Definition: svdmark.hxx:178
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:251
sal_uInt16 NextWhich()
void GetState(const SdrMarkView *pSdrView, SfxItemSet &rSet)
SdrObject * GetMarkedSdrObj() const
Definition: svdmark.hxx:68
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SdrMarkList & GetMarkedObjectList() const
Definition: svdmrkv.hxx:252
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