framework/inc/classes/actiontriggercontainer.hxx | 17 +--- framework/inc/classes/rootactiontriggercontainer.hxx | 19 +--- framework/inc/helper/propertysetcontainer.hxx | 13 +-- framework/source/fwe/classes/actiontriggercontainer.cxx | 45 ----------- framework/source/fwe/classes/rootactiontriggercontainer.cxx | 48 ------------ framework/source/fwe/helper/actiontriggerhelper.cxx | 46 +---------- framework/source/fwe/helper/propertysetcontainer.cxx | 28 ------- svx/source/unodraw/unoshap2.cxx | 21 +---- toolkit/source/helper/vclunohelper.cxx | 34 +------- 9 files changed, 29 insertions(+), 242 deletions(-)
New commits: commit 00b15057a39989dee9f14c76236ba140aa2bfa66 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Thu Nov 7 14:15:15 2024 +0500 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Fri Nov 8 05:35:40 2024 +0100 Simplify using WeakImplHelper / ImplInheritanceHelper Change-Id: Ieb3b8e07e0361da89da5b4a6db9e3c45389b636f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176200 Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> Tested-by: Jenkins diff --git a/framework/inc/classes/actiontriggercontainer.hxx b/framework/inc/classes/actiontriggercontainer.hxx index 25511d52b357..d485a716a722 100644 --- a/framework/inc/classes/actiontriggercontainer.hxx +++ b/framework/inc/classes/actiontriggercontainer.hxx @@ -20,6 +20,7 @@ #pragma once #include <helper/propertysetcontainer.hxx> +#include <cppuhelper/compbase.hxx> #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/lang/XTypeProvider.hpp> @@ -30,20 +31,14 @@ inline constexpr OUString IMPLEMENTATIONNAME_ACTIONTRIGGERCONTAINER = u"com.sun. namespace framework { -class ActionTriggerContainer final : public PropertySetContainer, - public css::lang::XMultiServiceFactory, - public css::lang::XServiceInfo, - public css::lang::XTypeProvider +class ActionTriggerContainer final : public cppu::ImplInheritanceHelper<PropertySetContainer, + css::lang::XMultiServiceFactory, + css::lang::XServiceInfo> { public: ActionTriggerContainer(); virtual ~ActionTriggerContainer() override; - // XInterface - virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override; - virtual void SAL_CALL acquire() noexcept override; - virtual void SAL_CALL release() noexcept override; - // XMultiServiceFactory virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance( const OUString& aServiceSpecifier ) override; virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArguments( const OUString& ServiceSpecifier, const css::uno::Sequence< css::uno::Any >& Arguments ) override; @@ -53,10 +48,6 @@ class ActionTriggerContainer final : public PropertySetContainer, virtual OUString SAL_CALL getImplementationName( ) override; virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; - - // XTypeProvider - virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; - virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) override; }; } diff --git a/framework/inc/classes/rootactiontriggercontainer.hxx b/framework/inc/classes/rootactiontriggercontainer.hxx index 87ba5b518fd1..adfa01d59014 100644 --- a/framework/inc/classes/rootactiontriggercontainer.hxx +++ b/framework/inc/classes/rootactiontriggercontainer.hxx @@ -20,6 +20,7 @@ #pragma once #include <helper/propertysetcontainer.hxx> +#include <cppuhelper/compbase.hxx> #include <com/sun/star/awt/XPopupMenu.hpp> #include <com/sun/star/container/XNamed.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> @@ -31,21 +32,15 @@ inline constexpr OUString IMPLEMENTATIONNAME_ROOTACTIONTRIGGERCONTAINER = u"com. namespace framework { -class RootActionTriggerContainer final : public PropertySetContainer, - public css::lang::XMultiServiceFactory, - public css::lang::XServiceInfo, - public css::lang::XTypeProvider, - public css::container::XNamed +class RootActionTriggerContainer final : public cppu::ImplInheritanceHelper<PropertySetContainer, + css::lang::XMultiServiceFactory, + css::lang::XServiceInfo, + css::container::XNamed> { public: RootActionTriggerContainer(css::uno::Reference<css::awt::XPopupMenu> xMenu, const OUString* pMenuIdentifier); virtual ~RootActionTriggerContainer() override; - // XInterface - virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override; - virtual void SAL_CALL acquire() noexcept override; - virtual void SAL_CALL release() noexcept override; - // XMultiServiceFactory virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance( const OUString& aServiceSpecifier ) override; virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArguments( const OUString& ServiceSpecifier, const css::uno::Sequence< css::uno::Any >& Arguments ) override; @@ -74,10 +69,6 @@ class RootActionTriggerContainer final : public PropertySetContainer, virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; - // XTypeProvider - virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; - virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) override; - // XNamed virtual OUString SAL_CALL getName( ) override; virtual void SAL_CALL setName( const OUString& aName ) override; diff --git a/framework/inc/helper/propertysetcontainer.hxx b/framework/inc/helper/propertysetcontainer.hxx index 849899784c64..8c32ef1a0ddf 100644 --- a/framework/inc/helper/propertysetcontainer.hxx +++ b/framework/inc/helper/propertysetcontainer.hxx @@ -23,25 +23,21 @@ #include <mutex> #include <vector> -#include <cppuhelper/weak.hxx> + +#include <comphelper/compbase.hxx> + #include <com/sun/star/container/XIndexContainer.hpp> #include <com/sun/star/beans/XPropertySet.hpp> namespace framework { -class PropertySetContainer : public css::container::XIndexContainer , - public ::cppu::OWeakObject +class PropertySetContainer : public comphelper::WeakImplHelper<css::container::XIndexContainer> { public: PropertySetContainer(); virtual ~PropertySetContainer() override; - // XInterface - virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override; - virtual void SAL_CALL acquire() noexcept override; - virtual void SAL_CALL release() noexcept override; - // XIndexContainer virtual void SAL_CALL insertByIndex( sal_Int32 Index, const css::uno::Any& Element ) override; @@ -66,7 +62,6 @@ class PropertySetContainer : public css::container::XIndexContainer , private: typedef std::vector< css::uno::Reference< css::beans::XPropertySet > > PropertySetVector; PropertySetVector m_aPropertySetVector; - std::mutex m_aMutex; }; } diff --git a/framework/source/fwe/classes/actiontriggercontainer.cxx b/framework/source/fwe/classes/actiontriggercontainer.cxx index 39646f1a56b7..81699bdf9fde 100644 --- a/framework/source/fwe/classes/actiontriggercontainer.cxx +++ b/framework/source/fwe/classes/actiontriggercontainer.cxx @@ -40,33 +40,6 @@ ActionTriggerContainer::~ActionTriggerContainer() { } -// XInterface -Any SAL_CALL ActionTriggerContainer::queryInterface( const Type& aType ) -{ - Any a = ::cppu::queryInterface( - aType , - static_cast< XMultiServiceFactory* >(this), - static_cast< XServiceInfo* >(this), - static_cast< XTypeProvider* >(this)); - - if( a.hasValue() ) - { - return a; - } - - return PropertySetContainer::queryInterface( aType ); -} - -void ActionTriggerContainer::acquire() noexcept -{ - PropertySetContainer::acquire(); -} - -void ActionTriggerContainer::release() noexcept -{ - PropertySetContainer::release(); -} - // XMultiServiceFactory Reference< XInterface > SAL_CALL ActionTriggerContainer::createInstance( const OUString& aServiceSpecifier ) { @@ -111,24 +84,6 @@ Sequence< OUString > SAL_CALL ActionTriggerContainer::getSupportedServiceNames() return seqServiceNames; } -// XTypeProvider -Sequence< Type > SAL_CALL ActionTriggerContainer::getTypes() -{ - // Create a static typecollection ... - static ::cppu::OTypeCollection ourTypeCollection( - cppu::UnoType<XMultiServiceFactory>::get(), - cppu::UnoType<XIndexContainer>::get(), - cppu::UnoType<XServiceInfo>::get(), - cppu::UnoType<XTypeProvider>::get()); - - return ourTypeCollection.getTypes(); -} - -Sequence< sal_Int8 > SAL_CALL ActionTriggerContainer::getImplementationId() -{ - return css::uno::Sequence<sal_Int8>(); -} - } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/framework/source/fwe/classes/rootactiontriggercontainer.cxx b/framework/source/fwe/classes/rootactiontriggercontainer.cxx index edcee5bf260c..dff698066dbe 100644 --- a/framework/source/fwe/classes/rootactiontriggercontainer.cxx +++ b/framework/source/fwe/classes/rootactiontriggercontainer.cxx @@ -50,34 +50,6 @@ RootActionTriggerContainer::~RootActionTriggerContainer() { } -// XInterface -Any SAL_CALL RootActionTriggerContainer::queryInterface( const Type& aType ) -{ - Any a = ::cppu::queryInterface( - aType , - static_cast< XMultiServiceFactory* >(this), - static_cast< XServiceInfo* >(this), - static_cast< XTypeProvider* >(this), - static_cast< XNamed* >(this)); - - if( a.hasValue() ) - { - return a; - } - - return PropertySetContainer::queryInterface( aType ); -} - -void SAL_CALL RootActionTriggerContainer::acquire() noexcept -{ - PropertySetContainer::acquire(); -} - -void SAL_CALL RootActionTriggerContainer::release() noexcept -{ - PropertySetContainer::release(); -} - // XMultiServiceFactory Reference< XInterface > SAL_CALL RootActionTriggerContainer::createInstance( const OUString& aServiceSpecifier ) { @@ -193,26 +165,6 @@ Sequence< OUString > SAL_CALL RootActionTriggerContainer::getSupportedServiceNam return { SERVICENAME_ACTIONTRIGGERCONTAINER }; } -// XTypeProvider -Sequence< Type > SAL_CALL RootActionTriggerContainer::getTypes() -{ - // Create a static typecollection ... - static ::cppu::OTypeCollection ourTypeCollection( - cppu::UnoType<XMultiServiceFactory>::get(), - cppu::UnoType<XIndexContainer>::get(), - cppu::UnoType<XServiceInfo>::get(), - cppu::UnoType<XTypeProvider>::get(), - cppu::UnoType<XUnoTunnel>::get(), - cppu::UnoType<XNamed>::get()); - - return ourTypeCollection.getTypes(); -} - -Sequence< sal_Int8 > SAL_CALL RootActionTriggerContainer::getImplementationId() -{ - return css::uno::Sequence<sal_Int8>(); -} - // private implementation helper void RootActionTriggerContainer::FillContainer() { diff --git a/framework/source/fwe/helper/propertysetcontainer.cxx b/framework/source/fwe/helper/propertysetcontainer.cxx index e2768f1cec64..0182c33f261a 100644 --- a/framework/source/fwe/helper/propertysetcontainer.cxx +++ b/framework/source/fwe/helper/propertysetcontainer.cxx @@ -42,34 +42,6 @@ PropertySetContainer::~PropertySetContainer() { } -// XInterface -void SAL_CALL PropertySetContainer::acquire() noexcept -{ - OWeakObject::acquire(); -} - -void SAL_CALL PropertySetContainer::release() noexcept -{ - OWeakObject::release(); -} - -Any SAL_CALL PropertySetContainer::queryInterface( const Type& rType ) -{ - Any a = ::cppu::queryInterface( - rType , - static_cast< XIndexContainer* >(this), - static_cast< XIndexReplace* >(this), - static_cast< XIndexAccess* >(this), - static_cast< XElementAccess* >(this) ); - - if( a.hasValue() ) - { - return a; - } - - return OWeakObject::queryInterface( rType ); -} - // XIndexContainer void SAL_CALL PropertySetContainer::insertByIndex( sal_Int32 Index, const css::uno::Any& Element ) { commit 9d6e1594a298c9d41f3dc64ad80edf4b9868c2e8 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Thu Nov 7 12:41:25 2024 +0500 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Fri Nov 8 05:35:34 2024 +0100 Deduplicate and unify using vcl::GetBitmap Change-Id: Ie940990b604cf23c961aa5b6fad124f1ebaf338c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176186 Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> Tested-by: Jenkins 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 { diff --git a/svx/source/unodraw/unoshap2.cxx b/svx/source/unodraw/unoshap2.cxx index bb2707af781c..668a76c05b52 100644 --- a/svx/source/unodraw/unoshap2.cxx +++ b/svx/source/unodraw/unoshap2.cxx @@ -36,6 +36,7 @@ #include <vcl/svapp.hxx> #include <vcl/wmf.hxx> #include <vcl/cvtgrf.hxx> +#include <vcl/graphic/BitmapHelper.hxx> #include <vcl/GraphicLoader.hxx> #include <svx/svdpool.hxx> @@ -1196,23 +1197,11 @@ bool SvxGraphicObject::setPropertyValueImpl( const OUString& rName, const SfxIte bOk = true; } } - else if (uno::Reference<graphic::XGraphic> xGraphic; rValue >>= xGraphic) + else if (uno::Reference<graphic::XGraphic> xGraphic = vcl::GetGraphic(rValue)) { - if (xGraphic.is()) - { - static_cast<SdrGrafObj*>(GetSdrObject())->SetGraphic(Graphic(xGraphic)); - bOk = true; - } - } - else if (uno::Reference<awt::XBitmap> xBitmap; rValue >>= xBitmap) - { - if (xBitmap.is()) - { - xGraphic.set(xBitmap, uno::UNO_QUERY); - Graphic aGraphic(xGraphic); - static_cast<SdrGrafObj*>(GetSdrObject())->SetGraphic(aGraphic); - bOk = true; - } + // Handles both graphic::XGraphic and awt::XBitmap + static_cast<SdrGrafObj*>(GetSdrObject())->SetGraphic(Graphic(xGraphic)); + bOk = true; } if (bOk) GetSdrObject()->SetEmptyPresObj(false); diff --git a/toolkit/source/helper/vclunohelper.cxx b/toolkit/source/helper/vclunohelper.cxx index dfedb5043b1b..0e5da47ccc72 100644 --- a/toolkit/source/helper/vclunohelper.cxx +++ b/toolkit/source/helper/vclunohelper.cxx @@ -21,6 +21,7 @@ #include <vcl/dibtools.hxx> #include <vcl/event.hxx> #include <vcl/graph.hxx> +#include <vcl/graphic/BitmapHelper.hxx> #include <vcl/metric.hxx> #include <vcl/ptrstyle.hxx> #include <vcl/unohelp.hxx> @@ -60,37 +61,10 @@ uno::Reference< css::awt::XToolkit> VCLUnoHelper::CreateToolkit() BitmapEx VCLUnoHelper::GetBitmap( const css::uno::Reference< css::awt::XBitmap>& rxBitmap ) { - BitmapEx aBmp; + if (VCLXBitmap* pVCLBitmap = dynamic_cast<VCLXBitmap*>(rxBitmap.get())) + return pVCLBitmap->GetBitmap(); - css::uno::Reference< css::graphic::XGraphic > xGraphic( rxBitmap, css::uno::UNO_QUERY ); - if( xGraphic.is() ) - { - Graphic aGraphic( xGraphic ); - aBmp = aGraphic.GetBitmapEx(); - } - else if ( rxBitmap.is() ) - { - VCLXBitmap* pVCLBitmap = dynamic_cast<VCLXBitmap*>( rxBitmap.get() ); - if ( pVCLBitmap ) - aBmp = pVCLBitmap->GetBitmap(); - else - { - Bitmap aDIB, aMask; - { - css::uno::Sequence<sal_Int8> aBytes = rxBitmap->getDIB(); - SvMemoryStream aMem( aBytes.getArray(), aBytes.getLength(), StreamMode::READ ); - ReadDIB(aDIB, aMem, true); - } - { - css::uno::Sequence<sal_Int8> aBytes = rxBitmap->getMaskDIB(); - SvMemoryStream aMem( aBytes.getArray(), aBytes.getLength(), StreamMode::READ ); - ReadDIB(aMask, aMem, true); - } - aMask.Invert(); // Convert from transparency to alpha - aBmp = BitmapEx( aDIB, aMask ); - } - } - return aBmp; + return vcl::GetBitmap(rxBitmap); } css::uno::Reference< css::awt::XBitmap> VCLUnoHelper::CreateBitmap( const BitmapEx& rBitmap )