summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2021-05-17 22:59:52 +0200
committerJan-Marek Glogowski <glogow@fbihome.de>2021-05-26 15:37:06 +0200
commit2e30d16bb945042b5c033dc9bdba690ee4a08fed (patch)
tree5122c1b3e6a5859141a35ec897c6a727f9c499bd /svx
parent456b87b6b188984579c1d809aab805f6f324ea53 (diff)
Refactor module media item handling
Move common functionality into svx::MediaShellHelpers. Change-Id: I6f5db59bdcff7cad00a64e76f6aad7b8ecb4ffa9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116126 Tested-by: Jenkins Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
Diffstat (limited to 'svx')
-rw-r--r--svx/Library_svx.mk1
-rw-r--r--svx/source/svdraw/MediaShellHelpers.cxx103
2 files changed, 104 insertions, 0 deletions
diff --git a/svx/Library_svx.mk b/svx/Library_svx.mk
index c951d91169f3..5ff8a89f6196 100644
--- a/svx/Library_svx.mk
+++ b/svx/Library_svx.mk
@@ -220,6 +220,7 @@ $(eval $(call gb_Library_add_exception_objects,svx,\
svx/source/stbctrls/zoomsliderctrl \
svx/source/stbctrls/zoomctrl \
svx/source/svdraw/ActionDescriptionProvider \
+ svx/source/svdraw/MediaShellHelpers \
svx/source/smarttags/SmartTagMgr \
svx/source/table/accessiblecell \
svx/source/table/accessibletableshape \
diff --git a/svx/source/svdraw/MediaShellHelpers.cxx b/svx/source/svdraw/MediaShellHelpers.cxx
new file mode 100644
index 000000000000..03fb24174e7b
--- /dev/null
+++ b/svx/source/svdraw/MediaShellHelpers.cxx
@@ -0,0 +1,103 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <svx/MediaShellHelpers.hxx>
+#include <avmedia/mediaitem.hxx>
+#include <sfx2/request.hxx>
+#include <sfx2/sfxsids.hrc>
+#include <svl/whiter.hxx>
+#include <svx/sdr/contact/viewcontactofsdrmediaobj.hxx>
+#include <svx/svdmrkv.hxx>
+
+#include <memory>
+
+namespace svx::MediaShellHelpers
+{
+void GetState(SdrMarkView* pSdrView, SfxItemSet& rSet)
+{
+ if (!pSdrView)
+ return;
+
+ SfxWhichIter aIter(rSet);
+
+ for (sal_uInt16 nWhich = aIter.FirstWhich(); nWhich; nWhich = aIter.NextWhich())
+ {
+ if (SID_AVMEDIA_TOOLBOX != nWhich)
+ continue;
+
+ std::unique_ptr<SdrMarkList> pMarkList(new SdrMarkList(pSdrView->GetMarkedObjectList()));
+ bool bDisable = true;
+
+ if (1 == pMarkList->GetMarkCount())
+ {
+ SdrObject* pObj = pMarkList->GetMark(0)->GetMarkedSdrObj();
+
+ if (dynamic_cast<SdrMediaObj*>(pObj))
+ {
+ ::avmedia::MediaItem aItem(SID_AVMEDIA_TOOLBOX);
+
+ static_cast<sdr::contact::ViewContactOfSdrMediaObj&>(pObj->GetViewContact())
+ .updateMediaItem(aItem);
+ rSet.Put(aItem);
+ bDisable = false;
+ }
+ }
+
+ if (bDisable)
+ rSet.DisableItem(SID_AVMEDIA_TOOLBOX);
+ }
+}
+
+const ::avmedia::MediaItem* Execute(SdrMarkView* pSdrView, SfxRequest const& rReq)
+{
+ if (!pSdrView)
+ return nullptr;
+
+ if (SID_AVMEDIA_TOOLBOX != rReq.GetSlot())
+ return nullptr;
+
+ const SfxItemSet* pArgs = rReq.GetArgs();
+ const SfxPoolItem* pItem;
+
+ if (!pArgs || (SfxItemState::SET != pArgs->GetItemState(SID_AVMEDIA_TOOLBOX, false, &pItem)))
+ pItem = nullptr;
+
+ if (!pItem)
+ return nullptr;
+
+ std::unique_ptr<SdrMarkList> pMarkList(new SdrMarkList(pSdrView->GetMarkedObjectList()));
+
+ if (1 != pMarkList->GetMarkCount())
+ return nullptr;
+
+ SdrObject* pObj = pMarkList->GetMark(0)->GetMarkedSdrObj();
+
+ if (!dynamic_cast<SdrMediaObj*>(pObj))
+ return nullptr;
+
+ const ::avmedia::MediaItem* pMediaItem = static_cast<const ::avmedia::MediaItem*>(pItem);
+ static_cast<sdr::contact::ViewContactOfSdrMediaObj&>(pObj->GetViewContact())
+ .executeMediaItem(*pMediaItem);
+
+ return pMediaItem;
+}
+
+} // end of namespace svx::MediaShellHelpers
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */