From 2e30d16bb945042b5c033dc9bdba690ee4a08fed Mon Sep 17 00:00:00 2001 From: Jan-Marek Glogowski Date: Mon, 17 May 2021 22:59:52 +0200 Subject: 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 --- svx/Library_svx.mk | 1 + svx/source/svdraw/MediaShellHelpers.cxx | 103 ++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 svx/source/svdraw/MediaShellHelpers.cxx (limited to 'svx') 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 +#include +#include +#include +#include +#include +#include + +#include + +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 pMarkList(new SdrMarkList(pSdrView->GetMarkedObjectList())); + bool bDisable = true; + + if (1 == pMarkList->GetMarkCount()) + { + SdrObject* pObj = pMarkList->GetMark(0)->GetMarkedSdrObj(); + + if (dynamic_cast(pObj)) + { + ::avmedia::MediaItem aItem(SID_AVMEDIA_TOOLBOX); + + static_cast(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 pMarkList(new SdrMarkList(pSdrView->GetMarkedObjectList())); + + if (1 != pMarkList->GetMarkCount()) + return nullptr; + + SdrObject* pObj = pMarkList->GetMark(0)->GetMarkedSdrObj(); + + if (!dynamic_cast(pObj)) + return nullptr; + + const ::avmedia::MediaItem* pMediaItem = static_cast(pItem); + static_cast(pObj->GetViewContact()) + .executeMediaItem(*pMediaItem); + + return pMediaItem; +} + +} // end of namespace svx::MediaShellHelpers + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit