Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / svdraw / MediaShellHelpers.cxx
blob8cf760a7b093b0a362345f11494c2176c45fe4b8
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 <config_features.h>
21 #include <svx/MediaShellHelpers.hxx>
22 #include <avmedia/mediaitem.hxx>
23 #include <sfx2/request.hxx>
24 #include <sfx2/sfxsids.hrc>
25 #include <svl/whiter.hxx>
26 #include <svx/sdr/contact/viewcontactofsdrmediaobj.hxx>
27 #include <svx/svdmrkv.hxx>
29 namespace svx::MediaShellHelpers
31 void GetState(const SdrMarkView* pSdrView, SfxItemSet& rSet)
33 if (!pSdrView)
34 return;
36 SfxWhichIter aIter(rSet);
38 for (sal_uInt16 nWhich = aIter.FirstWhich(); nWhich; nWhich = aIter.NextWhich())
40 if (SID_AVMEDIA_TOOLBOX != nWhich)
41 continue;
43 #if HAVE_FEATURE_AVMEDIA
44 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
45 bool bDisable = true;
47 if (1 == rMarkList.GetMarkCount())
49 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
51 if (dynamic_cast<SdrMediaObj*>(pObj))
53 ::avmedia::MediaItem aItem(SID_AVMEDIA_TOOLBOX);
55 static_cast<sdr::contact::ViewContactOfSdrMediaObj&>(pObj->GetViewContact())
56 .updateMediaItem(aItem);
57 rSet.Put(aItem);
58 bDisable = false;
62 if (bDisable)
63 #endif
64 rSet.DisableItem(SID_AVMEDIA_TOOLBOX);
68 const ::avmedia::MediaItem* Execute(const SdrMarkView* pSdrView, SfxRequest const& rReq)
70 #if !HAVE_FEATURE_AVMEDIA
71 (void)pSdrView;
72 (void)rReq;
73 return nullptr;
74 #else
75 if (!pSdrView)
76 return nullptr;
78 if (SID_AVMEDIA_TOOLBOX != rReq.GetSlot())
79 return nullptr;
81 const SfxItemSet* pArgs = rReq.GetArgs();
82 if (!pArgs)
83 return nullptr;
85 const ::avmedia::MediaItem* pMediaItem = pArgs->GetItemIfSet(SID_AVMEDIA_TOOLBOX, false);
86 if (!pMediaItem)
87 return nullptr;
89 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
91 if (1 != rMarkList.GetMarkCount())
92 return nullptr;
94 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
96 if (!dynamic_cast<SdrMediaObj*>(pObj))
97 return nullptr;
99 static_cast<sdr::contact::ViewContactOfSdrMediaObj&>(pObj->GetViewContact())
100 .executeMediaItem(*pMediaItem);
102 return pMediaItem;
103 #endif
106 } // end of namespace svx::MediaShellHelpers
108 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */