summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2021-12-11 20:25:28 +0000
committerCaolán McNamara <caolanm@redhat.com>2021-12-12 13:33:27 +0100
commit569de88e9c7eda964252518282d26a8f7d059718 (patch)
treee8a8988ea61bbd3b398ed63e517145e9a1088012 /framework
parent73e9e027e9978cf5136731118f18b832bd361181 (diff)
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 <caolanm@redhat.com>
Diffstat (limited to 'framework')
-rw-r--r--framework/Library_fwk.mk1
-rw-r--r--framework/inc/classes/imagewrapper.hxx58
-rw-r--r--framework/source/fwe/classes/imagewrapper.cxx86
-rw-r--r--framework/source/fwe/helper/actiontriggerhelper.cxx67
4 files changed, 32 insertions, 180 deletions
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(