From 96bd77de5ad7b7a13f7e48e0f95c05ef49255aa0 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Mon, 13 Sep 2021 11:29:37 +0300 Subject: Use implementing XUnoTunnel part 5 - Revise uses of getSomething to use getFromUnoTunnel Where that is impossible, use getSomething_cast to unify casting, and minimize number of places doing low-level transformations. The change keeps the existing tunnel references that last for the duration of the pointers' life, because sometimes destroying such reference may destroy the pointed object, and result in use after free. Change-Id: I291c33223582c34cd2c763aa8aacf0ae899ca4c0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122101 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- framework/source/fwe/helper/actiontriggerhelper.cxx | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'framework/source/fwe') diff --git a/framework/source/fwe/helper/actiontriggerhelper.cxx b/framework/source/fwe/helper/actiontriggerhelper.cxx index 9cff941e23c3..d96e44cb9bae 100644 --- a/framework/source/fwe/helper/actiontriggerhelper.cxx +++ b/framework/source/fwe/helper/actiontriggerhelper.cxx @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -152,21 +153,16 @@ static void InsertSubMenuItems( Menu* pSubMenu, sal_uInt16& nItemId, const Refer bool bImageSet = false; Reference< XUnoTunnel > xUnoTunnel( xBitmap, UNO_QUERY ); - if ( xUnoTunnel.is() ) + // Try to get implementation pointer through XUnoTunnel + if (auto pImageWrapper = comphelper::getFromUnoTunnel(xUnoTunnel)) { - // Try to get implementation pointer through XUnoTunnel - sal_Int64 nPointer = xUnoTunnel->getSomething( ImageWrapper::getUnoTunnelId() ); - if ( nPointer ) - { - // This is our own optimized implementation of menu images! - ImageWrapper* pImageWrapper = reinterpret_cast< ImageWrapper * >( nPointer ); - const Image& aMenuImage = pImageWrapper->GetImage(); + // This is our own optimized implementation of menu images! + const Image& aMenuImage = pImageWrapper->GetImage(); - if ( !!aMenuImage ) - pSubMenu->SetItemImage( nNewItemId, aMenuImage ); + if ( !!aMenuImage ) + pSubMenu->SetItemImage( nNewItemId, aMenuImage ); - bImageSet = true; - } + bImageSet = true; } if ( !bImageSet ) -- cgit