From f7a86c5cdf4323c99d26512bf78de7f7c380667d Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 12 May 2021 15:07:37 +0200 Subject: simplify the vcl<->toolkit connection No need to store two different pointers and hide the underlying class behind an UNO interface Change-Id: I72c55e912caa9eae1cffa6c9d1b1d480e5668d40 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115496 Tested-by: Jenkins Reviewed-by: Noel Grandin --- toolkit/inc/controls/svmedit.hxx | 2 +- toolkit/inc/helper/unowrapper.hxx | 4 ++-- toolkit/source/awt/vclxaccessiblecomponent.cxx | 2 +- toolkit/source/awt/vclxtoolkit.cxx | 6 +++--- toolkit/source/awt/vclxwindow.cxx | 2 +- toolkit/source/controls/svmedit.cxx | 7 +++---- toolkit/source/helper/unowrapper.cxx | 22 ++++++++++------------ 7 files changed, 21 insertions(+), 24 deletions(-) (limited to 'toolkit') diff --git a/toolkit/inc/controls/svmedit.hxx b/toolkit/inc/controls/svmedit.hxx index 33586c84f064..4b7f155dcc3c 100644 --- a/toolkit/inc/controls/svmedit.hxx +++ b/toolkit/inc/controls/svmedit.hxx @@ -26,7 +26,7 @@ class MultiLineEdit : public VclMultiLineEdit public: MultiLineEdit( vcl::Window* pParent, WinBits nWinStyle ); - virtual css::uno::Reference< css::awt::XWindowPeer > GetComponentInterface(bool bCreate = true) override; + virtual VCLXWindow* GetComponentInterface(bool bCreate = true) override; }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/toolkit/inc/helper/unowrapper.hxx b/toolkit/inc/helper/unowrapper.hxx index 6e10e870506d..b606a7df70c5 100644 --- a/toolkit/inc/helper/unowrapper.hxx +++ b/toolkit/inc/helper/unowrapper.hxx @@ -51,8 +51,8 @@ public: virtual void ReleaseAllGraphics( OutputDevice* pOutDev ) override; // Window - virtual css::uno::Reference< css::awt::XWindowPeer> GetWindowInterface( vcl::Window* pWindow ) override; - virtual void SetWindowInterface( vcl::Window* pWindow, css::uno::Reference< css::awt::XWindowPeer> xIFace ) override; + virtual rtl::Reference GetWindowInterface( vcl::Window* pWindow ) override; + virtual void SetWindowInterface( vcl::Window* pWindow, VCLXWindow* pIFace ) override; virtual VclPtr GetWindow(const css::uno::Reference& rxWindow) override; // Menu diff --git a/toolkit/source/awt/vclxaccessiblecomponent.cxx b/toolkit/source/awt/vclxaccessiblecomponent.cxx index 101307bf1d96..46fad7979c9d 100644 --- a/toolkit/source/awt/vclxaccessiblecomponent.cxx +++ b/toolkit/source/awt/vclxaccessiblecomponent.cxx @@ -780,7 +780,7 @@ uno::Reference< awt::XFont > SAL_CALL VCLXAccessibleComponent::getFont( ) VclPtr pWindow = GetWindow(); if ( pWindow ) { - uno::Reference< awt::XDevice > xDev( pWindow->GetComponentInterface(), uno::UNO_QUERY ); + auto xDev = pWindow->GetComponentInterfaceAs(); if ( xDev.is() ) { vcl::Font aFont; diff --git a/toolkit/source/awt/vclxtoolkit.cxx b/toolkit/source/awt/vclxtoolkit.cxx index 10eb7f8019e2..287dc93f9676 100644 --- a/toolkit/source/awt/vclxtoolkit.cxx +++ b/toolkit/source/awt/vclxtoolkit.cxx @@ -1946,9 +1946,9 @@ css::uno::Reference< css::awt::XWindowPeer > VCLXToolkit::ImplCreateWindow( else { xRef = pNewComp; - pNewWindow->SetComponentInterface( xRef ); + pNewWindow->SetComponentInterface( pNewComp.get() ); } - DBG_ASSERT( pNewWindow->GetComponentInterface( false ) == xRef, + DBG_ASSERT( pNewWindow->GetComponentInterface( false ) == pNewComp.get(), "VCLXToolkit::createWindow: did #133706# resurge?" ); if ( rDescriptor.WindowAttributes & css::awt::WindowAttribute::SHOW ) @@ -2502,7 +2502,7 @@ void VCLXToolkit::callFocusListeners(::VclSimpleEvent const * pEvent, break; } if (pFocus != nullptr) - xNext = pFocus->GetComponentInterface(); + xNext = static_cast(pFocus->GetComponentInterface()); css::awt::FocusEvent aAwtEvent( static_cast< css::awt::XWindow * >(pWindow->GetWindowPeer()), static_cast(pWindow->GetGetFocusFlags()), diff --git a/toolkit/source/awt/vclxwindow.cxx b/toolkit/source/awt/vclxwindow.cxx index dfc6ba8f7c00..d770b8570234 100644 --- a/toolkit/source/awt/vclxwindow.cxx +++ b/toolkit/source/awt/vclxwindow.cxx @@ -912,7 +912,7 @@ void VCLXWindow::dispose( ) if ( auto pWindow = GetWindow() ) { pWindow->RemoveEventListener( LINK( this, VCLXWindow, WindowEventListener ) ); - pWindow->SetWindowPeer( nullptr, nullptr ); + pWindow->SetWindowPeer( nullptr ); pWindow->SetAccessible( nullptr ); VclPtr pOutDev = GetOutputDevice(); diff --git a/toolkit/source/controls/svmedit.cxx b/toolkit/source/controls/svmedit.cxx index 383f2280412e..2abd5e4ebed2 100644 --- a/toolkit/source/controls/svmedit.cxx +++ b/toolkit/source/controls/svmedit.cxx @@ -26,11 +26,10 @@ MultiLineEdit::MultiLineEdit(vcl::Window* pParent, WinBits nWinStyle) } // virtual -css::uno::Reference MultiLineEdit::GetComponentInterface(bool bCreate) +VCLXWindow* MultiLineEdit::GetComponentInterface(bool bCreate) { - css::uno::Reference xPeer( - VclMultiLineEdit::GetComponentInterface(false)); - if (!xPeer.is() && bCreate) + VCLXWindow* xPeer = VclMultiLineEdit::GetComponentInterface(false); + if (!xPeer && bCreate) { rtl::Reference xVCLMEdit(new VCLXMultiLineEdit); xVCLMEdit->SetWindow(this); diff --git a/toolkit/source/helper/unowrapper.cxx b/toolkit/source/helper/unowrapper.cxx index ab7d28493c62..19b0822534a9 100644 --- a/toolkit/source/helper/unowrapper.cxx +++ b/toolkit/source/helper/unowrapper.cxx @@ -35,7 +35,7 @@ using namespace ::com::sun::star; -static css::uno::Reference< css::awt::XWindowPeer > CreateXWindow( vcl::Window const * pWindow ) +static rtl::Reference CreateXWindow( vcl::Window const * pWindow ) { switch ( pWindow->GetType() ) { @@ -145,13 +145,13 @@ css::uno::Reference< css::awt::XToolkit> UnoWrapper::GetVCLToolkit() return mxToolkit; } -css::uno::Reference< css::awt::XWindowPeer> UnoWrapper::GetWindowInterface( vcl::Window* pWindow ) +rtl::Reference UnoWrapper::GetWindowInterface( vcl::Window* pWindow ) { - css::uno::Reference< css::awt::XWindowPeer> xPeer = pWindow->GetWindowPeer(); + rtl::Reference xPeer = pWindow->GetWindowPeer(); if ( !xPeer.is() ) { xPeer = CreateXWindow( pWindow ); - SetWindowInterface( pWindow, xPeer ); + SetWindowInterface( pWindow, xPeer.get() ); } return xPeer; } @@ -161,10 +161,8 @@ VclPtr UnoWrapper::GetWindow(const css::uno::Reference xIFace ) +void UnoWrapper::SetWindowInterface( vcl::Window* pWindow, VCLXWindow* pVCLXWindow ) { - VCLXWindow* pVCLXWindow = comphelper::getUnoTunnelImplementation( xIFace ); - DBG_ASSERT( pVCLXWindow, "SetComponentInterface - unsupported type" ); if ( !pVCLXWindow ) return; @@ -178,7 +176,7 @@ void UnoWrapper::SetWindowInterface( vcl::Window* pWindow, css::uno::Reference< return; } pVCLXWindow->SetWindow( pWindow ); - pWindow->SetWindowPeer( xIFace, pVCLXWindow ); + pWindow->SetWindowPeer( pVCLXWindow ); } css::uno::Reference UnoWrapper::CreateMenuInterface( PopupMenu* pPopupMenu ) @@ -227,7 +225,7 @@ void UnoWrapper::WindowDestroyed( vcl::Window* pWindow ) VclPtr< vcl::Window > pClient = pChild->GetWindow( GetWindowType::Client ); if ( pClient && pClient->GetWindowPeer() ) { - css::uno::Reference< css::lang::XComponent > xComp = pClient->GetComponentInterface( false ); + rtl::Reference xComp = pClient->GetComponentInterface( false ); xComp->dispose(); } @@ -246,7 +244,7 @@ void UnoWrapper::WindowDestroyed( vcl::Window* pWindow ) if ( pClient && pClient->GetWindowPeer() && lcl_ImplIsParent( pWindow, pClient ) ) { - css::uno::Reference< css::lang::XComponent > xComp = pClient->GetComponentInterface( false ); + rtl::Reference xComp = pClient->GetComponentInterface( false ); xComp->dispose(); } @@ -261,13 +259,13 @@ void UnoWrapper::WindowDestroyed( vcl::Window* pWindow ) } VCLXWindow* pWindowPeer = pWindow->GetWindowPeer(); - uno::Reference< lang::XComponent > xWindowPeerComp = pWindow->GetComponentInterface( false ); + rtl::Reference xWindowPeerComp = pWindow->GetComponentInterface( false ); OSL_ENSURE( ( pWindowPeer != nullptr ) == xWindowPeerComp.is(), "UnoWrapper::WindowDestroyed: inconsistency in the window's peers!" ); if ( pWindowPeer ) { pWindowPeer->SetWindow( nullptr ); - pWindow->SetWindowPeer( nullptr, nullptr ); + pWindow->SetWindowPeer( nullptr ); } if ( xWindowPeerComp.is() ) xWindowPeerComp->dispose(); -- cgit