Simplify unocontrols::BaseControl hierarchy

Change-Id: I7c690cd429b2ac52f8aac602b4c9129bdd774b09
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178052
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
Mike Kaganski 2024-12-07 23:15:21 +05:00
parent cd9976d2b1
commit 05eb50c396
8 changed files with 34 additions and 327 deletions

View File

@ -33,9 +33,11 @@ struct IMPL_ControlInfo
OUString sName; OUString sName;
}; };
class BaseContainerControl : public css::awt::XControlModel using BaseContainerControl_BASE = cppu::ImplInheritanceHelper<BaseControl,
, public css::awt::XControlContainer css::awt::XControlModel,
, public BaseControl css::awt::XControlContainer>;
class BaseContainerControl : public BaseContainerControl_BASE
{ {
public: public:
@ -43,37 +45,6 @@ public:
virtual ~BaseContainerControl() override; virtual ~BaseContainerControl() override;
// XInterface
/**
@short give answer, if interface is supported
@descr The interfaces are searched by type.
@seealso XInterface
@param "rType" is the type of searched interface.
@return Any information about found interface
@onerror A RuntimeException is thrown.
*/
virtual css::uno::Any SAL_CALL queryInterface(
const css::uno::Type& aType
) override;
// XTypeProvider
/**
@short get information about supported interfaces
@seealso XTypeProvider
@return Sequence of types of all supported interfaces
@onerror A RuntimeException is thrown.
*/
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override;
// XControl // XControl
virtual void SAL_CALL createPeer( virtual void SAL_CALL createPeer(
@ -121,7 +92,7 @@ public:
virtual void SAL_CALL setVisible( sal_Bool bVisible ) override; virtual void SAL_CALL setVisible( sal_Bool bVisible ) override;
protected: protected:
using WeakComponentImplHelper::disposing; using WeakComponentImplHelperBase::disposing;
virtual css::awt::WindowDescriptor impl_getWindowDescriptor( virtual css::awt::WindowDescriptor impl_getWindowDescriptor(
const css::uno::Reference< css::awt::XWindowPeer >& xParentPeer const css::uno::Reference< css::awt::XWindowPeer >& xParentPeer

View File

@ -39,82 +39,19 @@ namespace unocontrols { class OMRCListenerMultiplexerHelper; }
namespace unocontrols { namespace unocontrols {
class BaseControl : public css::lang::XServiceInfo class BaseControl : public cppu::BaseMutex,
, public css::awt::XPaintListener public cppu::WeakComponentImplHelper<css::lang::XServiceInfo,
, public css::awt::XWindowListener css::awt::XPaintListener,
, public css::awt::XView css::awt::XWindowListener,
, public css::awt::XWindow css::awt::XView,
, public css::awt::XControl css::awt::XWindow,
, public cppu::BaseMutex css::awt::XControl>
, public ::cppu::WeakComponentImplHelper<>
{ {
public: public:
BaseControl( const css::uno::Reference< css::uno::XComponentContext >& rxContext ); BaseControl( const css::uno::Reference< css::uno::XComponentContext >& rxContext );
virtual ~BaseControl() override; virtual ~BaseControl() override;
// XInterface
/**
@short give answer, if interface is supported
@descr The interfaces are searched by type.
@seealso XInterface
@param "rType" is the type of searched interface.
@return Any information about found interface
@onerror A RuntimeException is thrown.
*/
virtual css::uno::Any SAL_CALL queryInterface(
const css::uno::Type& aType
) override;
/**
@short increment refcount
@seealso XInterface
@seealso release()
@onerror A RuntimeException is thrown.
*/
virtual void SAL_CALL acquire() noexcept override;
/**
@short decrement refcount
@seealso XInterface
@seealso acquire()
@onerror A RuntimeException is thrown.
*/
virtual void SAL_CALL release() noexcept override;
// XTypeProvider
/**
@short get information about supported interfaces
@seealso XTypeProvider
@return Sequence of types of all supported interfaces
@onerror A RuntimeException is thrown.
*/
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override;
/**
@short get implementation id
@descr This ID is necessary for UNO-caching. If there no ID, cache is disabled.
Another way, cache is enabled.
@seealso XTypeProvider
@return ID as Sequence of byte
@onerror A RuntimeException is thrown.
*/
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override;
// XServiceInfo // XServiceInfo
virtual sal_Bool SAL_CALL supportsService( virtual sal_Bool SAL_CALL supportsService(
@ -265,7 +202,7 @@ public:
virtual void SAL_CALL windowHidden( const css::lang::EventObject& aEvent ) override; virtual void SAL_CALL windowHidden( const css::lang::EventObject& aEvent ) override;
protected: protected:
using WeakComponentImplHelper::disposing; using WeakComponentImplHelperBase::disposing;
const css::uno::Reference< css::uno::XComponentContext >& impl_getComponentContext() const { return m_xComponentContext;} const css::uno::Reference< css::uno::XComponentContext >& impl_getComponentContext() const { return m_xComponentContext;}

View File

@ -40,7 +40,7 @@ namespace unocontrols {
// construct/destruct // construct/destruct
BaseContainerControl::BaseContainerControl( const Reference< XComponentContext >& rxContext ) BaseContainerControl::BaseContainerControl( const Reference< XComponentContext >& rxContext )
: BaseControl ( rxContext ) : BaseContainerControl_BASE(rxContext)
, m_aListeners ( m_aMutex ) , m_aListeners ( m_aMutex )
{ {
} }
@ -49,43 +49,6 @@ BaseContainerControl::~BaseContainerControl()
{ {
} }
// XInterface
Any SAL_CALL BaseContainerControl::queryInterface( const Type& rType )
{
// Ask for my own supported interfaces ...
// Attention: XTypeProvider and XInterface are supported by WeakComponentImplHelper!
Any aReturn ( ::cppu::queryInterface( rType ,
static_cast< XControlModel* > ( this ) ,
static_cast< XControlContainer* > ( this )
)
);
// If searched interface supported by this class ...
if ( aReturn.hasValue() )
{
// ... return this information.
return aReturn;
}
else
{
// Else; ... ask baseclass for interfaces!
return BaseControl::queryInterface( rType );
}
}
// XTypeProvider
Sequence< Type > SAL_CALL BaseContainerControl::getTypes()
{
static OTypeCollection ourTypeCollection(
cppu::UnoType<XControlModel>::get(),
cppu::UnoType<XControlContainer>::get(),
BaseControl::getTypes() );
return ourTypeCollection.getTypes();
}
// XControl // XControl
void SAL_CALL BaseContainerControl::createPeer( const Reference< XToolkit >& xToolkit , void SAL_CALL BaseContainerControl::createPeer( const Reference< XToolkit >& xToolkit ,

View File

@ -65,80 +65,6 @@ BaseControl::~BaseControl()
{ {
} }
// XInterface
Any SAL_CALL BaseControl::queryInterface( const Type& rType )
{
// Ask for my own supported interfaces ...
// Attention: XTypeProvider and XInterface are supported by WeakComponentImplHelper!
Any aReturn ( ::cppu::queryInterface( rType ,
static_cast< XPaintListener*> ( this ) ,
static_cast< XWindowListener*> ( this ) ,
static_cast< XView* > ( this ) ,
static_cast< XWindow* > ( this ) ,
static_cast< XServiceInfo* > ( this ) ,
static_cast< XControl* > ( this )
)
);
// If searched interface supported by this class ...
if ( aReturn.hasValue() )
{
// ... return this information.
return aReturn;
}
else
{
// Else; ... ask baseclass for interfaces!
return WeakComponentImplHelper::queryInterface( rType );
}
}
// XInterface
void SAL_CALL BaseControl::acquire() noexcept
{
// Attention:
// Don't use mutex or guard in this method!!! Is a method of XInterface.
// Forward to baseclass
WeakComponentImplHelper::acquire();
}
// XInterface
void SAL_CALL BaseControl::release() noexcept
{
// Attention:
// Don't use mutex or guard in this method!!! Is a method of XInterface.
// Forward to baseclass
WeakComponentImplHelper::release();
}
// XTypeProvider
Sequence< Type > SAL_CALL BaseControl::getTypes()
{
static OTypeCollection ourTypeCollection(
cppu::UnoType<XPaintListener>::get(),
cppu::UnoType<XWindowListener>::get(),
cppu::UnoType<XView>::get(),
cppu::UnoType<XWindow>::get(),
cppu::UnoType<XServiceInfo>::get(),
cppu::UnoType<XControl>::get(),
WeakComponentImplHelper::getTypes() );
return ourTypeCollection.getTypes();
}
// XTypeProvider
Sequence< sal_Int8 > SAL_CALL BaseControl::getImplementationId()
{
return css::uno::Sequence<sal_Int8>();
}
// XServiceInfo // XServiceInfo
OUString SAL_CALL BaseControl::getImplementationName() OUString SAL_CALL BaseControl::getImplementationName()

View File

@ -27,6 +27,7 @@
#include <com/sun/star/frame/XDispatch.hpp> #include <com/sun/star/frame/XDispatch.hpp>
#include <com/sun/star/util/URLTransformer.hpp> #include <com/sun/star/util/URLTransformer.hpp>
#include <com/sun/star/util/XURLTransformer.hpp> #include <com/sun/star/util/XURLTransformer.hpp>
#include <comphelper/sequence.hxx>
#include <cppuhelper/queryinterface.hxx> #include <cppuhelper/queryinterface.hxx>
#include <cppuhelper/typeprovider.hxx> #include <cppuhelper/typeprovider.hxx>
#include <osl/diagnose.h> #include <osl/diagnose.h>
@ -58,7 +59,7 @@ enum PropertyHandle // values represent index in PropertyArray
// construct/destruct // construct/destruct
FrameControl::FrameControl( const Reference< XComponentContext >& rxContext) FrameControl::FrameControl( const Reference< XComponentContext >& rxContext)
: BaseControl ( rxContext ) : FrameControl_BASE ( rxContext )
, OBroadcastHelper ( m_aMutex ) , OBroadcastHelper ( m_aMutex )
, OPropertySetHelper ( *static_cast< OBroadcastHelper * >(this) ) , OPropertySetHelper ( *static_cast< OBroadcastHelper * >(this) )
, m_aConnectionPointContainer ( new OConnectionPointContainerHelper(m_aMutex) ) , m_aConnectionPointContainer ( new OConnectionPointContainerHelper(m_aMutex) )
@ -72,23 +73,10 @@ FrameControl::~FrameControl()
// XInterface // XInterface
Any SAL_CALL FrameControl::queryInterface( const Type& rType ) Any SAL_CALL FrameControl::queryInterface( const Type& rType )
{ {
// Ask for my own supported interfaces ... Any aReturn = OPropertySetHelper::queryInterface(rType);
// Attention: XTypeProvider and XInterface are supported by WeakComponentImplHelper!
Any aReturn ( ::cppu::queryInterface( rType ,
static_cast< XControlModel* > ( this ) ,
static_cast< XConnectionPointContainer* > ( this )
)
);
if (aReturn.hasValue()) if (aReturn.hasValue())
return aReturn; return aReturn;
return FrameControl_BASE::queryInterface(rType);
// If searched interface not supported by this class ...
// ... ask baseclasses.
aReturn = OPropertySetHelper::queryInterface(rType);
if (aReturn.hasValue())
return aReturn;
return BaseControl::queryInterface(rType);
} }
// XInterface // XInterface
@ -98,7 +86,7 @@ void SAL_CALL FrameControl::acquire() noexcept
// Don't use mutex or guard in this method!!! Is a method of XInterface. // Don't use mutex or guard in this method!!! Is a method of XInterface.
// Forward to baseclass // Forward to baseclass
BaseControl::acquire(); FrameControl_BASE::acquire();
} }
// XInterface // XInterface
@ -108,20 +96,16 @@ void SAL_CALL FrameControl::release() noexcept
// Don't use mutex or guard in this method!!! Is a method of XInterface. // Don't use mutex or guard in this method!!! Is a method of XInterface.
// Forward to baseclass // Forward to baseclass
BaseControl::release(); FrameControl_BASE::release();
} }
// XTypeProvider // XTypeProvider
Sequence< Type > SAL_CALL FrameControl::getTypes() Sequence< Type > SAL_CALL FrameControl::getTypes()
{ {
static OTypeCollection ourTypeCollection( static Sequence myTypes = comphelper::concatSequences(FrameControl_BASE::getTypes(),
cppu::UnoType<XControlModel>::get(), OPropertySetHelper::getTypes());
cppu::UnoType<XControlContainer>::get(), return myTypes;
cppu::UnoType<XConnectionPointContainer>::get(),
BaseControl::getTypes() );
return ourTypeCollection.getTypes();
} }
OUString FrameControl::getImplementationName() OUString FrameControl::getImplementationName()

View File

@ -34,7 +34,7 @@ namespace unocontrols {
// construct/destruct // construct/destruct
ProgressBar::ProgressBar( const Reference< XComponentContext >& rxContext ) ProgressBar::ProgressBar( const Reference< XComponentContext >& rxContext )
: BaseControl ( rxContext ) : ProgressBar_BASE ( rxContext )
, m_bHorizontal ( PROGRESSBAR_DEFAULT_HORIZONTAL ) , m_bHorizontal ( PROGRESSBAR_DEFAULT_HORIZONTAL )
, m_aBlockSize ( PROGRESSBAR_DEFAULT_BLOCKDIMENSION ) , m_aBlockSize ( PROGRESSBAR_DEFAULT_BLOCKDIMENSION )
, m_nForegroundColor ( PROGRESSBAR_DEFAULT_FOREGROUNDCOLOR ) , m_nForegroundColor ( PROGRESSBAR_DEFAULT_FOREGROUNDCOLOR )
@ -50,57 +50,6 @@ ProgressBar::~ProgressBar()
{ {
} }
// XInterface
Any SAL_CALL ProgressBar::queryInterface( const Type& rType )
{
// Ask for my own supported interfaces ...
// Attention: XTypeProvider and XInterface are supported by WeakComponentImplHelper!
Any aReturn ( ::cppu::queryInterface( rType ,
static_cast< XControlModel* > ( this ) ,
static_cast< XProgressBar* > ( this )
)
);
if (aReturn.hasValue())
return aReturn;
// If searched interface not supported by this class ...
// ... ask baseclasses.
return BaseControl::queryInterface(rType);
}
// XInterface
void SAL_CALL ProgressBar::acquire() noexcept
{
// Attention:
// Don't use mutex or guard in this method!!! Is a method of XInterface.
// Forward to baseclass
BaseControl::acquire();
}
// XInterface
void SAL_CALL ProgressBar::release() noexcept
{
// Attention:
// Don't use mutex or guard in this method!!! Is a method of XInterface.
// Forward to baseclass
BaseControl::release();
}
// XTypeProvider
Sequence< Type > SAL_CALL ProgressBar::getTypes()
{
static OTypeCollection ourTypeCollection(
cppu::UnoType<XControlModel>::get(),
cppu::UnoType<XProgressBar>::get(),
BaseControl::getTypes() );
return ourTypeCollection.getTypes();
}
// XProgressBar // XProgressBar
void SAL_CALL ProgressBar::setForegroundColor( sal_Int32 nColor ) void SAL_CALL ProgressBar::setForegroundColor( sal_Int32 nColor )

View File

@ -31,9 +31,10 @@ namespace unocontrols { class OConnectionPointContainerHelper; }
namespace unocontrols { namespace unocontrols {
class FrameControl final : public css::awt::XControlModel using FrameControl_BASE = cppu::ImplInheritanceHelper<BaseControl, css::awt::XControlModel,
, public css::lang::XConnectionPointContainer css::lang::XConnectionPointContainer>;
, public BaseControl // This order is necessary for right initialization of m_aMutex!
class FrameControl final : public FrameControl_BASE // This order is necessary for right initialization of m_aMutex!
, public ::cppu::OBroadcastHelper , public ::cppu::OBroadcastHelper
, public ::cppu::OPropertySetHelper , public ::cppu::OPropertySetHelper
{ {

View File

@ -41,9 +41,11 @@ constexpr auto PROGRESSBAR_DEFAULT_BLOCKVALUE = 1;
constexpr sal_Int32 PROGRESSBAR_LINECOLOR_BRIGHT = sal_Int32(COL_WHITE); constexpr sal_Int32 PROGRESSBAR_LINECOLOR_BRIGHT = sal_Int32(COL_WHITE);
constexpr sal_Int32 PROGRESSBAR_LINECOLOR_SHADOW = sal_Int32(COL_BLACK); constexpr sal_Int32 PROGRESSBAR_LINECOLOR_SHADOW = sal_Int32(COL_BLACK);
class ProgressBar final : public css::awt::XControlModel using ProgressBar_BASE = cppu::ImplInheritanceHelper<BaseControl,
, public css::awt::XProgressBar css::awt::XControlModel,
, public BaseControl css::awt::XProgressBar>;
class ProgressBar final : public ProgressBar_BASE
{ {
public: public:
@ -51,32 +53,6 @@ public:
virtual ~ProgressBar() override; virtual ~ProgressBar() override;
// XInterface
virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override;
/**
@short increment refcount
@seealso XInterface
@seealso release()
@onerror A RuntimeException is thrown.
*/
virtual void SAL_CALL acquire() noexcept override;
/**
@short decrement refcount
@seealso XInterface
@seealso acquire()
@onerror A RuntimeException is thrown.
*/
virtual void SAL_CALL release() noexcept override;
// XTypeProvider
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override;
// XProgressBar // XProgressBar
virtual void SAL_CALL setForegroundColor( sal_Int32 nColor ) override; virtual void SAL_CALL setForegroundColor( sal_Int32 nColor ) override;