diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2024-11-07 12:41:25 +0500 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2024-11-08 05:35:34 +0100 |
commit | 9d6e1594a298c9d41f3dc64ad80edf4b9868c2e8 (patch) | |
tree | 354ff3a785ea2ba56031bcd1e238211604a6f0d1 /framework | |
parent | ef261d4e80e784519a94b23f78ca4fb42d8bcbd9 (diff) |
Deduplicate and unify using vcl::GetBitmap
Change-Id: Ie940990b604cf23c961aa5b6fad124f1ebaf338c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176186
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'framework')
-rw-r--r-- | framework/source/fwe/helper/actiontriggerhelper.cxx | 46 |
1 files changed, 7 insertions, 39 deletions
diff --git a/framework/source/fwe/helper/actiontriggerhelper.cxx b/framework/source/fwe/helper/actiontriggerhelper.cxx index 1369efcf6b7e..e1ae01a4da28 100644 --- a/framework/source/fwe/helper/actiontriggerhelper.cxx +++ b/framework/source/fwe/helper/actiontriggerhelper.cxx @@ -30,6 +30,7 @@ #include <tools/stream.hxx> #include <vcl/dibtools.hxx> #include <vcl/graph.hxx> +#include <vcl/graphic/BitmapHelper.hxx> #include <vcl/svapp.hxx> #include <o3tl/string_view.hxx> @@ -64,7 +65,7 @@ static void GetMenuItemAttributes( const Reference< XPropertySet >& xActionTrigg OUString& aMenuLabel, OUString& aCommandURL, OUString& aHelpURL, - Reference< XBitmap >& xBitmap, + Any& rImage, Reference< XIndexContainer >& xSubContainer ) { try @@ -72,7 +73,7 @@ static void GetMenuItemAttributes( const Reference< XPropertySet >& xActionTrigg // mandatory properties xActionTriggerPropertySet->getPropertyValue(u"Text"_ustr) >>= aMenuLabel; xActionTriggerPropertySet->getPropertyValue(u"CommandURL"_ustr) >>= aCommandURL; - xActionTriggerPropertySet->getPropertyValue(u"Image"_ustr) >>= xBitmap; + rImage = xActionTriggerPropertySet->getPropertyValue(u"Image"_ustr); xActionTriggerPropertySet->getPropertyValue(u"SubContainer"_ustr) >>= xSubContainer; } catch (const Exception&) @@ -116,11 +117,11 @@ static void InsertSubMenuItems(const Reference<XPopupMenu>& rSubMenu, sal_uInt16 OUString aLabel; OUString aCommandURL; OUString aHelpURL; - Reference< XBitmap > xBitmap; + Any aImage; Reference< XIndexContainer > xSubContainer; sal_uInt16 nNewItemId = nItemId++; - GetMenuItemAttributes( xPropSet, aLabel, aCommandURL, aHelpURL, xBitmap, xSubContainer ); + GetMenuItemAttributes( xPropSet, aLabel, aCommandURL, aHelpURL, aImage, xSubContainer ); { // insert new menu item @@ -141,43 +142,10 @@ static void InsertSubMenuItems(const Reference<XPopupMenu>& rSubMenu, sal_uInt16 } // handle bitmap - if ( xBitmap.is() ) + if (aImage.hasValue()) { - bool bImageSet = false; - - Reference<css::graphic::XGraphic> xGraphic(xBitmap, UNO_QUERY); - if (xGraphic.is()) - { - // we can take the optimized route if XGraphic is supported + if (auto xGraphic = vcl::GetGraphic(aImage)) rSubMenu->setItemImage(nNewItemId, xGraphic, false); - bImageSet = true; - } - - if ( !bImageSet ) - { - // This is an unknown implementation of a XBitmap interface. We have to - // use a more time consuming way to build an Image! - BitmapEx aBitmap; - - Sequence< sal_Int8 > aDIBSeq; - { - aDIBSeq = xBitmap->getDIB(); - SvMemoryStream aMem( const_cast<sal_Int8 *>(aDIBSeq.getConstArray()), aDIBSeq.getLength(), StreamMode::READ ); - ReadDIBBitmapEx(aBitmap, aMem); - } - - aDIBSeq = xBitmap->getMaskDIB(); - if ( aDIBSeq.hasElements() ) - { - Bitmap aMaskBitmap; - SvMemoryStream aMem( const_cast<sal_Int8 *>(aDIBSeq.getConstArray()), aDIBSeq.getLength(), StreamMode::READ ); - ReadDIB(aMaskBitmap, aMem, true); - aBitmap = BitmapEx(aBitmap.GetBitmap(), aMaskBitmap); - } - - if (!aBitmap.IsEmpty()) - rSubMenu->setItemImage(nNewItemId, Graphic(aBitmap).GetXGraphic(), false); - } } else { |