dbaccess/source/ui/control/dbtreelistbox.cxx | 2 framework/Library_fwk.mk | 1 framework/inc/classes/imagewrapper.hxx | 58 ------------- framework/source/fwe/classes/imagewrapper.cxx | 86 -------------------- framework/source/fwe/helper/actiontriggerhelper.cxx | 67 +++++++-------- include/framework/actiontriggerhelper.hxx | 11 -- sfx2/source/view/viewsh.cxx | 10 -- solenv/clang-format/excludelist | 2 8 files changed, 39 insertions(+), 198 deletions(-)
New commits: commit 569de88e9c7eda964252518282d26a8f7d059718 Author: Caolán McNamara <[email protected]> AuthorDate: Sat Dec 11 20:25:28 2021 +0000 Commit: Caolán McNamara <[email protected]> CommitDate: Sun Dec 12 13:33:27 2021 +0100 prefer css::awt::XPopupMenu api and using GetXGraphic will return a vcl unographic::XGraphic which also supports XBitmap as well as XGraphic so we can check if the XBitmap we're passing around supports XGraphic and use that if it does and drop the imagewrapper in favor of doing that Change-Id: I3bd7963b53c3f715fca4b5cfb2ddad650ca92e1d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126691 Tested-by: Jenkins Reviewed-by: Caolán McNamara <[email protected]> diff --git a/dbaccess/source/ui/control/dbtreelistbox.cxx b/dbaccess/source/ui/control/dbtreelistbox.cxx index aab0f5efcc9f..efb5a6871668 100644 --- a/dbaccess/source/ui/control/dbtreelistbox.cxx +++ b/dbaccess/source/ui/control/dbtreelistbox.cxx @@ -448,7 +448,7 @@ IMPL_LINK(TreeListBox, CommandHdl, const CommandEvent&, rCEvt, bool) { xPopupMenu->clear(); ::framework::ActionTriggerHelper::CreateMenuFromActionTriggerContainer( - pContextMenu, aEvent.ActionTriggerContainer ); + xPopupMenu, aEvent.ActionTriggerContainer ); aEvent.ActionTriggerContainer.clear(); } } diff --git a/framework/Library_fwk.mk b/framework/Library_fwk.mk index fa75122a8729..07ffd62770b8 100644 --- a/framework/Library_fwk.mk +++ b/framework/Library_fwk.mk @@ -108,7 +108,6 @@ $(eval $(call gb_Library_add_exception_objects,fwk,\ framework/source/fwe/classes/addonsoptions \ framework/source/fwe/classes/framelistanalyzer \ framework/source/fwe/classes/fwkresid \ - framework/source/fwe/classes/imagewrapper \ framework/source/fwe/classes/rootactiontriggercontainer \ framework/source/fwe/classes/sfxhelperfunctions \ framework/source/fwe/dispatch/interaction \ diff --git a/framework/inc/classes/imagewrapper.hxx b/framework/inc/classes/imagewrapper.hxx deleted file mode 100644 index eea43c4e0394..000000000000 --- a/framework/inc/classes/imagewrapper.hxx +++ /dev/null @@ -1,58 +0,0 @@ -/* -*- 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 . - */ - -#pragma once - -#include <com/sun/star/awt/XBitmap.hpp> -#include <com/sun/star/lang/XUnoTunnel.hpp> -#include <cppuhelper/implbase.hxx> -#include <vcl/image.hxx> - -namespace framework -{ - -class ImageWrapper final : public ::cppu::WeakImplHelper< css::awt::XBitmap, - css::lang::XUnoTunnel > -{ - public: - ImageWrapper( const Image& aImage ); - virtual ~ImageWrapper() override; - - const Image& GetImage() const - { - return m_aImage; - } - - static css::uno::Sequence<sal_Int8> const& getUnoTunnelId(); - - // XBitmap - virtual css::awt::Size SAL_CALL getSize() override; - virtual css::uno::Sequence< sal_Int8 > SAL_CALL getDIB() override; - virtual css::uno::Sequence< sal_Int8 > SAL_CALL getMaskDIB() override; - - // XUnoTunnel - virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; - - private: - Image m_aImage; -}; - -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/framework/source/fwe/classes/imagewrapper.cxx b/framework/source/fwe/classes/imagewrapper.cxx deleted file mode 100644 index 978ef77a474f..000000000000 --- a/framework/source/fwe/classes/imagewrapper.cxx +++ /dev/null @@ -1,86 +0,0 @@ -/* -*- 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 <classes/imagewrapper.hxx> -#include <comphelper/servicehelper.hxx> -#include <vcl/svapp.hxx> -#include <vcl/bitmapex.hxx> -#include <vcl/BitmapTools.hxx> -#include <tools/stream.hxx> -#include <vcl/dibtools.hxx> - -using namespace com::sun::star::lang; -using namespace com::sun::star::uno; - -namespace framework -{ - -static Sequence< sal_Int8 > const & impl_getStaticIdentifier() -{ - static const sal_uInt8 pGUID[16] = { 0x46, 0xAD, 0x69, 0xFB, 0xA7, 0xBE, 0x44, 0x83, 0xB2, 0xA7, 0xB3, 0xEC, 0x59, 0x4A, 0xB7, 0x00 }; - static css::uno::Sequence< sal_Int8 > seqID(reinterpret_cast<const sal_Int8*>(pGUID), 16); - return seqID; -} - -ImageWrapper::ImageWrapper( const Image& aImage ) : m_aImage( aImage ) -{ -} - -ImageWrapper::~ImageWrapper() -{ -} - -Sequence<sal_Int8> const& ImageWrapper::getUnoTunnelId() { return impl_getStaticIdentifier(); } - -// XBitmap -css::awt::Size SAL_CALL ImageWrapper::getSize() -{ - SolarMutexGuard aGuard; - - BitmapEx aBitmapEx( m_aImage.GetBitmapEx() ); - Size aBitmapSize( aBitmapEx.GetSizePixel() ); - - return css::awt::Size( aBitmapSize.Width(), aBitmapSize.Height() ); -} - -Sequence< sal_Int8 > SAL_CALL ImageWrapper::getDIB() -{ - SolarMutexGuard aGuard; - - SvMemoryStream aMem; - WriteDIB(m_aImage.GetBitmapEx().GetBitmap(), aMem, false, true); - return Sequence< sal_Int8 >( static_cast<sal_Int8 const *>(aMem.GetData()), aMem.Tell() ); -} - -Sequence< sal_Int8 > SAL_CALL ImageWrapper::getMaskDIB() -{ - SolarMutexGuard aGuard; - - return vcl::bitmap::GetMaskDIB(m_aImage.GetBitmapEx()); -} - -// XUnoTunnel -sal_Int64 SAL_CALL ImageWrapper::getSomething( const Sequence< sal_Int8 >& aIdentifier ) -{ - return comphelper::getSomethingImpl(aIdentifier, this); -} - -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/framework/source/fwe/helper/actiontriggerhelper.cxx b/framework/source/fwe/helper/actiontriggerhelper.cxx index d96e44cb9bae..60917cccbfd0 100644 --- a/framework/source/fwe/helper/actiontriggerhelper.cxx +++ b/framework/source/fwe/helper/actiontriggerhelper.cxx @@ -20,16 +20,19 @@ #include <framework/actiontriggerhelper.hxx> #include <classes/actiontriggerseparatorpropertyset.hxx> #include <classes/rootactiontriggercontainer.hxx> -#include <classes/imagewrapper.hxx> #include <framework/addonsoptions.hxx> +#include <com/sun/star/awt/XBitmap.hpp> +#include <com/sun/star/awt/XPopupMenu.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> -#include <com/sun/star/beans/XPropertySet.hpp> -#include <com/sun/star/awt/XBitmap.hpp> -#include <vcl/svapp.hxx> +#include <toolkit/awt/vclxmenu.hxx> #include <tools/stream.hxx> #include <comphelper/servicehelper.hxx> #include <cppuhelper/weak.hxx> +#include <vcl/image.hxx> +#include <vcl/svapp.hxx> +#include <vcl/graph.hxx> #include <vcl/dibtools.hxx> const sal_uInt16 START_ITEMID = 1000; @@ -95,7 +98,8 @@ static void GetMenuItemAttributes( const Reference< XPropertySet >& xActionTrigg } } -static void InsertSubMenuItems( Menu* pSubMenu, sal_uInt16& nItemId, const Reference< XIndexContainer >& xActionTriggerContainer ) +static void InsertSubMenuItems(const Reference<XPopupMenu>& rSubMenu, sal_uInt16& nItemId, + const Reference<XIndexContainer>& xActionTriggerContainer) { if ( !xActionTriggerContainer.is() ) return; @@ -114,7 +118,7 @@ static void InsertSubMenuItems( Menu* pSubMenu, sal_uInt16& nItemId, const Refer { // Separator SolarMutexGuard aGuard; - pSubMenu->InsertSeparator(); + rSubMenu->insertSeparator(i); } else { @@ -139,12 +143,12 @@ static void InsertSubMenuItems( Menu* pSubMenu, sal_uInt16& nItemId, const Refer // got a special url during conversion from menu=>actiontriggercontainer. // Now we have to extract this special url and set the correct item id!!! nNewItemId = static_cast<sal_uInt16>(aCommandURL.copy( nIndex+aSlotURL.getLength() ).toInt32()); - pSubMenu->InsertItem( nNewItemId, aLabel ); + rSubMenu->insertItem(nNewItemId, aLabel, 0, i); } else { - pSubMenu->InsertItem( nNewItemId, aLabel ); - pSubMenu->SetItemCommand( nNewItemId, aCommandURL ); + rSubMenu->insertItem(nNewItemId, aLabel, 0, i); + rSubMenu->setCommand(nNewItemId, aCommandURL); } // handle bitmap @@ -152,16 +156,11 @@ static void InsertSubMenuItems( Menu* pSubMenu, sal_uInt16& nItemId, const Refer { bool bImageSet = false; - Reference< XUnoTunnel > xUnoTunnel( xBitmap, UNO_QUERY ); - // Try to get implementation pointer through XUnoTunnel - if (auto pImageWrapper = comphelper::getFromUnoTunnel<ImageWrapper>(xUnoTunnel)) + Reference<css::graphic::XGraphic> xGraphic(xBitmap, UNO_QUERY); + if (xGraphic.is()) { - // This is our own optimized implementation of menu images! - const Image& aMenuImage = pImageWrapper->GetImage(); - - if ( !!aMenuImage ) - pSubMenu->SetItemImage( nNewItemId, aMenuImage ); - + // we can take the optimized route if XGraphic is supported + rSubMenu->setItemImage(nNewItemId, xGraphic, false); bImageSet = true; } @@ -169,7 +168,6 @@ static void InsertSubMenuItems( Menu* pSubMenu, sal_uInt16& nItemId, const Refer { // This is an unknown implementation of a XBitmap interface. We have to // use a more time consuming way to build an Image! - Image aImage; BitmapEx aBitmap; Sequence< sal_Int8 > aDIBSeq; @@ -185,30 +183,28 @@ static void InsertSubMenuItems( Menu* pSubMenu, sal_uInt16& nItemId, const Refer Bitmap aMaskBitmap; SvMemoryStream aMem( const_cast<sal_Int8 *>(aDIBSeq.getConstArray()), aDIBSeq.getLength(), StreamMode::READ ); ReadDIB(aMaskBitmap, aMem, true); - aImage = Image(BitmapEx(aBitmap.GetBitmap(), aMaskBitmap)); + aBitmap = BitmapEx(aBitmap.GetBitmap(), aMaskBitmap); } - else - aImage = Image( aBitmap ); - if ( !!aImage ) - pSubMenu->SetItemImage( nNewItemId, aImage ); + if (!aBitmap.IsEmpty()) + rSubMenu->setItemImage(nNewItemId, Graphic(aBitmap).GetXGraphic(), false); } } else { // Support add-on images for context menu interceptors - Image aImage(aAddonOptions.GetImageFromURL(aCommandURL, false, true)); - if ( !!aImage ) - pSubMenu->SetItemImage( nNewItemId, aImage ); + BitmapEx aBitmap(aAddonOptions.GetImageFromURL(aCommandURL, false, true)); + if (!aBitmap.IsEmpty()) + rSubMenu->setItemImage(nNewItemId, Graphic(aBitmap).GetXGraphic(), false); } if ( xSubContainer.is() ) { - VclPtr<PopupMenu> pNewSubMenu = VclPtr<PopupMenu>::Create(); + rtl::Reference xNewSubMenu(new VCLXPopupMenu); // Sub menu (recursive call CreateSubMenu ) - InsertSubMenuItems( pNewSubMenu, nItemId, xSubContainer ); - pSubMenu->SetPopupMenu( nNewItemId, pNewSubMenu ); + InsertSubMenuItems(xNewSubMenu, nItemId, xSubContainer); + rSubMenu->setPopupMenu(nNewItemId, xNewSubMenu); } } } @@ -264,8 +260,9 @@ static Reference< XPropertySet > CreateActionTrigger( sal_uInt16 nItemId, const Image aImage = pMenu->GetItemImage( nItemId ); if ( !!aImage ) { - // We use our own optimized XBitmap implementation - Reference< XBitmap > xBitmap = new ImageWrapper( aImage ); + Reference<css::graphic::XGraphic> xGraphic = Graphic(aImage.GetBitmapEx()).GetXGraphic(); + Reference<XBitmap> xBitmap(xGraphic, UNO_QUERY); + assert(xGraphic.is() == xBitmap.is()); a <<= xBitmap; xPropSet->setPropertyValue("Image", a ); } @@ -353,13 +350,13 @@ static void FillActionTriggerContainerWithMenu( const Menu* pMenu, Reference< XI } void ActionTriggerHelper::CreateMenuFromActionTriggerContainer( - Menu* pNewMenu, - const Reference< XIndexContainer >& rActionTriggerContainer ) + const Reference<XPopupMenu>& rNewMenu, + const Reference<XIndexContainer>& rActionTriggerContainer) { sal_uInt16 nItemId = START_ITEMID; if ( rActionTriggerContainer.is() ) - InsertSubMenuItems( pNewMenu, nItemId, rActionTriggerContainer ); + InsertSubMenuItems(rNewMenu, nItemId, rActionTriggerContainer); } void ActionTriggerHelper::FillActionTriggerContainerFromMenu( diff --git a/include/framework/actiontriggerhelper.hxx b/include/framework/actiontriggerhelper.hxx index ceccea40433b..227535648950 100644 --- a/include/framework/actiontriggerhelper.hxx +++ b/include/framework/actiontriggerhelper.hxx @@ -17,16 +17,15 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_FRAMEWORK_ACTIONTRIGGERHELPER_HXX -#define INCLUDED_FRAMEWORK_ACTIONTRIGGERHELPER_HXX +#pragma once #include <framework/fwkdllapi.h> #include <com/sun/star/uno/Reference.hxx> +namespace com::sun::star::awt { class XPopupMenu; } namespace com::sun::star::container { class XIndexContainer; } class Menu; - namespace framework { class FWK_DLLPUBLIC ActionTriggerHelper @@ -38,8 +37,8 @@ namespace framework // @param rActionTriggerContainer = must be an instance of service "com.sun.star.ui.ActionTriggerContainer" static void CreateMenuFromActionTriggerContainer( - Menu* pNewMenu, - const css::uno::Reference< css::container::XIndexContainer >& rActionTriggerContainer ); + const css::uno::Reference<css::awt::XPopupMenu>& rNewMenu, + const css::uno::Reference<css::container::XIndexContainer>& rActionTriggerContainer); // Creates a "css::ui::ActionTriggerContainer" with the structure of the menu // provided as a parameter. The implementation class stores the menu pointer @@ -64,6 +63,4 @@ namespace framework }; } -#endif // INCLUDED_FRAMEWORK_ACTIONTRIGGERHELPER_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx index 860310b73667..03cd1fe842d0 100644 --- a/sfx2/source/view/viewsh.cxx +++ b/sfx2/source/view/viewsh.cxx @@ -1911,13 +1911,7 @@ bool SfxViewShell::TryContextMenuInterception(const Menu& rIn, const OUString& r // container was modified, create a new menu out of it css::uno::Reference<uno::XComponentContext> xContext(::comphelper::getProcessComponentContext(), css::uno::UNO_SET_THROW); rOut.set(xContext->getServiceManager()->createInstanceWithContext("com.sun.star.awt.PopupMenu", xContext), css::uno::UNO_QUERY_THROW); - - VCLXMenu* pAwtMenu = comphelper::getFromUnoTunnel<VCLXMenu>(rOut); - assert(pAwtMenu); - PopupMenu* pVCLMenu = static_cast<PopupMenu*>(pAwtMenu->GetMenu()); - assert(pVCLMenu); - - ::framework::ActionTriggerHelper::CreateMenuFromActionTriggerContainer(pVCLMenu, aEvent.ActionTriggerContainer); + ::framework::ActionTriggerHelper::CreateMenuFromActionTriggerContainer(rOut, aEvent.ActionTriggerContainer); } return true; @@ -1984,7 +1978,7 @@ bool SfxViewShell::TryContextMenuInterception(const css::uno::Reference<css::awt if ( bModified ) { rPopupMenu->clear(); - ::framework::ActionTriggerHelper::CreateMenuFromActionTriggerContainer(pVCLMenu, aEvent.ActionTriggerContainer); + ::framework::ActionTriggerHelper::CreateMenuFromActionTriggerContainer(rPopupMenu, aEvent.ActionTriggerContainer); } return true; diff --git a/solenv/clang-format/excludelist b/solenv/clang-format/excludelist index 0c2f856a2187..a6be56e95bfa 100644 --- a/solenv/clang-format/excludelist +++ b/solenv/clang-format/excludelist @@ -4267,7 +4267,6 @@ framework/inc/classes/actiontriggercontainer.hxx framework/inc/classes/actiontriggerpropertyset.hxx framework/inc/classes/actiontriggerseparatorpropertyset.hxx framework/inc/classes/converter.hxx -framework/inc/classes/imagewrapper.hxx framework/inc/classes/protocolhandlercache.hxx framework/inc/classes/resource.hxx framework/inc/classes/rootactiontriggercontainer.hxx @@ -4404,7 +4403,6 @@ framework/source/fwe/classes/actiontriggerseparatorpropertyset.cxx framework/source/fwe/classes/addonmenu.cxx framework/source/fwe/classes/addonsoptions.cxx framework/source/fwe/classes/framelistanalyzer.cxx -framework/source/fwe/classes/imagewrapper.cxx framework/source/fwe/classes/rootactiontriggercontainer.cxx framework/source/fwe/classes/sfxhelperfunctions.cxx framework/source/fwe/dispatch/interaction.cxx
