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 
21 #include <avmedia/mediaitem.hxx>
22 #include <sfx2/request.hxx>
23 #include <sfx2/sfxsids.hrc>
24 #include <svl/whiter.hxx>
26 #include <svx/svdmrkv.hxx>
27 
28 #include <memory>
29 
31 {
32 void GetState(const SdrMarkView* pSdrView, SfxItemSet& rSet)
33 {
34  if (!pSdrView)
35  return;
36 
37  SfxWhichIter aIter(rSet);
38 
39  for (sal_uInt16 nWhich = aIter.FirstWhich(); nWhich; nWhich = aIter.NextWhich())
40  {
41  if (SID_AVMEDIA_TOOLBOX != nWhich)
42  continue;
43 
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  rSet.DisableItem(SID_AVMEDIA_TOOLBOX);
64  }
65 }
66 
67 const ::avmedia::MediaItem* Execute(const SdrMarkView* pSdrView, SfxRequest const& rReq)
68 {
69  if (!pSdrView)
70  return nullptr;
71 
72  if (SID_AVMEDIA_TOOLBOX != rReq.GetSlot())
73  return nullptr;
74 
75  const SfxItemSet* pArgs = rReq.GetArgs();
76  const SfxPoolItem* pItem;
77 
78  if (!pArgs || (SfxItemState::SET != pArgs->GetItemState(SID_AVMEDIA_TOOLBOX, false, &pItem)))
79  pItem = nullptr;
80 
81  if (!pItem)
82  return nullptr;
83 
84  const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
85 
86  if (1 != rMarkList.GetMarkCount())
87  return nullptr;
88 
89  SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
90 
91  if (!dynamic_cast<SdrMediaObj*>(pObj))
92  return nullptr;
93 
94  const ::avmedia::MediaItem* pMediaItem = static_cast<const ::avmedia::MediaItem*>(pItem);
96  .executeMediaItem(*pMediaItem);
97 
98  return pMediaItem;
99 }
100 
101 } // end of namespace svx::MediaShellHelpers
102 
103 /* 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:251
Abstract DrawObject.
Definition: svdobj.hxx:259
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_uInt16 GetSlot() const
void DisableItem(sal_uInt16 nWhich)