loplugin:unocast (weld::TransportAsXWindow)

(See the upcoming commit introducing that loplugin:unocast on why such
dynamic_casts from UNO types are dangerous.)

On macOS, where we implicitly use -fvisibility-inlines-hidden-static-local-var
since
<https://github.com/llvm/llvm-project/commit/d46f2c51e4c849683434bb5a0fb6164957474b8f>
"Make -fvisibility-inlines-hidden apply to static local variables in inline
functions on Darwin", the static id local var in
weld::TransportAsXWindow::getUnoTunnelId cannot be in an inline function
implicitly hidden via -fvisibility-inlines-hidden.  Explicitly marking the
function as VCL_DLLPUBLIC would help, but would in turn cause MSVC error 2487
("member of a dll interface class may not be declared with dll interface").  So
just make the function non-inline in a new vcl/source/window/weldutils.cxx
(which would arguably be the best approach for the whole class, anyway).

Change-Id: Ib5615f6aae19346ea05b8b85ff77c0e5ea860994
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144331
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
Stephan Bergmann
2022-12-20 08:34:38 +00:00
parent f6b4c3fb68
commit feba0ddb15
14 changed files with 57 additions and 14 deletions
@@ -23,6 +23,7 @@
#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
#include <cppuhelper/exc_hlp.hxx>
#include <comphelper/namedvaluecollection.hxx>
#include <comphelper/servicehelper.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <vcl/weldutils.hxx>
@@ -61,7 +62,7 @@ Reference<css::ui::XUIElement> SAL_CALL ChartPanelFactory::createUIElement (
Reference<css::frame::XController> xController (aArguments.getOrDefault("Controller", Reference<css::frame::XController>()));
weld::Widget* pParent(nullptr);
if (weld::TransportAsXWindow* pTunnel = dynamic_cast<weld::TransportAsXWindow*>(xParentWindow.get()))
if (weld::TransportAsXWindow* pTunnel = comphelper::getFromUnoTunnel<weld::TransportAsXWindow>(xParentWindow))
pParent = pTunnel->getWidget();
if (!pParent)
+2 -1
View File
@@ -26,6 +26,7 @@
#include <comphelper/processfactory.hxx>
#include <comphelper/propertyvalue.hxx>
#include <comphelper/servicehelper.hxx>
#include <comphelper/string.hxx>
#include <tools/debug.hxx>
#include <comphelper/diagnose_ex.hxx>
@@ -110,7 +111,7 @@ namespace pcr
{
m_xControl = rxControl;
auto xWindow = m_xControl->getControlWindow();
if (weld::TransportAsXWindow* pTunnel = dynamic_cast<weld::TransportAsXWindow*>(xWindow.get()))
if (weld::TransportAsXWindow* pTunnel = comphelper::getFromUnoTunnel<weld::TransportAsXWindow>(xWindow))
m_pControlWindow = pTunnel->getWidget();
else
m_pControlWindow = nullptr;
@@ -30,6 +30,7 @@
#include <com/sun/star/inspection/XStringListControl.hpp>
#include <com/sun/star/inspection/XNumericControl.hpp>
#include <comphelper/diagnose_ex.hxx>
#include <comphelper/servicehelper.hxx>
#include <vcl/svapp.hxx>
#include <vcl/weld.hxx>
#include <vcl/weldutils.hxx>
@@ -291,8 +292,9 @@ namespace pcr
std::unique_ptr<weld::Builder> PropertyHandlerHelper::makeBuilder(const OUString& rUIFile, const Reference<XComponentContext>& rContext)
{
Reference<XWindow> xWindow(rContext->getValueByName("BuilderParent"), UNO_QUERY_THROW);
weld::TransportAsXWindow& rTunnel = dynamic_cast<weld::TransportAsXWindow&>(*xWindow);
return Application::CreateBuilder(rTunnel.getWidget(), rUIFile);
weld::TransportAsXWindow* rTunnel
= comphelper::getFromUnoTunnel<weld::TransportAsXWindow>(xWindow);
return Application::CreateBuilder(rTunnel->getWidget(), rUIFile);
}
void PropertyHandlerHelper::setBuilderParent(const css::uno::Reference<css::uno::XComponentContext>& rContext, weld::Widget* pParent)
@@ -38,6 +38,7 @@
#include <com/sun/star/util/VetoException.hpp>
#include <tools/debug.hxx>
#include <comphelper/diagnose_ex.hxx>
#include <comphelper/servicehelper.hxx>
#include <toolkit/helper/vclunohelper.hxx>
#include <vcl/svapp.hxx>
#include <vcl/weld.hxx>
@@ -338,7 +339,7 @@ namespace pcr
OUString sUIFile("modules/spropctrlr/ui/formproperties.ui");
std::unique_ptr<weld::Builder> xBuilder;
if (weld::TransportAsXWindow* pTunnel = dynamic_cast<weld::TransportAsXWindow*>(xContainerWindow.get()))
if (weld::TransportAsXWindow* pTunnel = comphelper::getFromUnoTunnel<weld::TransportAsXWindow>(xContainerWindow))
{
xBuilder = Application::CreateBuilder(pTunnel->getWidget(), sUIFile);
}
@@ -1107,7 +1108,7 @@ namespace pcr
// for ui-testing try and distinguish different instances of the controls
auto xWindow = _rDescriptor.Control->getControlWindow();
if (weld::TransportAsXWindow* pTunnel = dynamic_cast<weld::TransportAsXWindow*>(xWindow.get()))
if (weld::TransportAsXWindow* pTunnel = comphelper::getFromUnoTunnel<weld::TransportAsXWindow>(xWindow))
{
weld::Widget* m_pControlWindow = pTunnel->getWidget();
if (m_pControlWindow)
@@ -24,6 +24,7 @@
#include <com/sun/star/ui/UIElementType.hpp>
#include <com/sun/star/lang/DisposedException.hpp>
#include <comphelper/servicehelper.hxx>
#include <toolkit/helper/vclunohelper.hxx>
#include <vcl/svapp.hxx>
@@ -153,7 +154,7 @@ void SAL_CALL ToolBarWrapper::initialize( const Sequence< Any >& aArguments )
m_xToolBarManager = pToolBarManager;
pToolBar->WillUsePopupMode( bPopupMode );
}
else if (weld::TransportAsXWindow* pTunnel = dynamic_cast<weld::TransportAsXWindow*>(xParentWindow.get()))
else if (weld::TransportAsXWindow* pTunnel = comphelper::getFromUnoTunnel<weld::TransportAsXWindow>(xParentWindow))
{
m_xBuilder = Application::CreateBuilder(pTunnel->getWidget(), "svt/ui/managedtoolbar.ui");
m_xTopLevel = m_xBuilder->weld_container("toolbarcontainer");
+11 -1
View File
@@ -14,9 +14,11 @@
#include <com/sun/star/frame/XDispatch.hpp>
#include <com/sun/star/frame/XFrame.hpp>
#include <com/sun/star/frame/XStatusListener.hpp>
#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <com/sun/star/uno/Reference.hxx>
#include <comphelper/interfacecontainer4.hxx>
#include <comphelper/compbase.hxx>
#include <comphelper/servicehelper.hxx>
#include <tools/time.hxx>
#include <vcl/dllapi.h>
#include <vcl/formatter.hxx>
@@ -33,7 +35,8 @@ class Window;
namespace weld
{
typedef comphelper::WeakComponentImplHelper<css::awt::XWindow> TransportAsXWindow_Base;
typedef comphelper::WeakComponentImplHelper<css::awt::XWindow, css::lang::XUnoTunnel>
TransportAsXWindow_Base;
class VCL_DLLPUBLIC TransportAsXWindow : public TransportAsXWindow_Base
{
@@ -168,6 +171,13 @@ public:
std::unique_lock g(m_aMutex);
m_aPaintListeners.removeInterface(g, rListener);
}
sal_Int64 SAL_CALL getSomething(css::uno::Sequence<sal_Int8> const& aIdentifier) override
{
return comphelper::getSomethingImpl(aIdentifier, this);
}
static css::uno::Sequence<sal_Int8> const& getUnoTunnelId();
};
// don't export to avoid duplicate WeakImplHelper definitions with MSVC
+2 -1
View File
@@ -29,6 +29,7 @@
#include <vcl/weldutils.hxx>
#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
#include <comphelper/namedvaluecollection.hxx>
#include <comphelper/servicehelper.hxx>
#include <cppuhelper/exc_hlp.hxx>
#include <cppuhelper/supportsservice.hxx>
@@ -60,7 +61,7 @@ Reference<ui::XUIElement> SAL_CALL ScPanelFactory::createUIElement (
SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue);
weld::Widget* pParent(nullptr);
if (weld::TransportAsXWindow* pTunnel = dynamic_cast<weld::TransportAsXWindow*>(xParentWindow.get()))
if (weld::TransportAsXWindow* pTunnel = comphelper::getFromUnoTunnel<weld::TransportAsXWindow>(xParentWindow))
pParent = pTunnel->getWidget();
if (!pParent)
+1 -1
View File
@@ -67,7 +67,7 @@ Reference<ui::XUIElement> SAL_CALL PanelFactory::createUIElement (
// Throw exceptions when the arguments are not as expected.
weld::Widget* pParent(nullptr);
if (weld::TransportAsXWindow* pTunnel = dynamic_cast<weld::TransportAsXWindow*>(xParentWindow.get()))
if (weld::TransportAsXWindow* pTunnel = comphelper::getFromUnoTunnel<weld::TransportAsXWindow>(xParentWindow))
pParent = pTunnel->getWidget();
if (!pParent)
+2 -1
View File
@@ -26,6 +26,7 @@
#include <cppuhelper/exc_hlp.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <comphelper/namedvaluecollection.hxx>
#include <comphelper/servicehelper.hxx>
#include <sfx2/sidebar/SidebarPanelBase.hxx>
#include <vcl/weldutils.hxx>
@@ -69,7 +70,7 @@ css::uno::Reference<css::ui::XUIElement> SAL_CALL SmPanelFactory::createUIElemen
SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue);
weld::Widget* pParent(nullptr);
if (auto pTunnel = dynamic_cast<weld::TransportAsXWindow*>(xParentWindow.get()))
if (auto pTunnel = comphelper::getFromUnoTunnel<weld::TransportAsXWindow>(xParentWindow))
pParent = pTunnel->getWidget();
if (!pParent)
+2 -1
View File
@@ -34,6 +34,7 @@
#include <vcl/weldutils.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/propertyvalue.hxx>
#include <comphelper/servicehelper.hxx>
const int TOOLBARCONTROLLER_PROPHANDLE_SUPPORTSVISIBLE = 1;
constexpr OUStringLiteral TOOLBARCONTROLLER_PROPNAME_SUPPORTSVISIBLE = u"SupportsVisible";
@@ -222,7 +223,7 @@ void SAL_CALL ToolboxController::initialize( const Sequence< Any >& aArguments )
if ( !m_aCommandURL.isEmpty() )
m_aListenerMap.emplace( m_aCommandURL, Reference< XDispatch >() );
if (weld::TransportAsXWindow* pTunnel = dynamic_cast<weld::TransportAsXWindow*>(getParent().get()))
if (weld::TransportAsXWindow* pTunnel = comphelper::getFromUnoTunnel<weld::TransportAsXWindow>(getParent()))
{
m_pToolbar = dynamic_cast<weld::Toolbar*>(pTunnel->getWidget());
assert(m_pToolbar && "must be a toolbar");
+2 -1
View File
@@ -42,6 +42,7 @@
#include <vcl/weldutils.hxx>
#include <comphelper/namedvaluecollection.hxx>
#include <comphelper/compbase.hxx>
#include <comphelper/servicehelper.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/ui/XSidebar.hpp>
@@ -102,7 +103,7 @@ Reference<ui::XUIElement> SAL_CALL PanelFactory::createUIElement (
SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue);
weld::Widget* pParent(nullptr);
if (weld::TransportAsXWindow* pTunnel = dynamic_cast<weld::TransportAsXWindow*>(xParentWindow.get()))
if (weld::TransportAsXWindow* pTunnel = comphelper::getFromUnoTunnel<weld::TransportAsXWindow>(xParentWindow))
pParent = pTunnel->getWidget();
if (!pParent)
+2 -1
View File
@@ -37,6 +37,7 @@
#include <com/sun/star/uno/XComponentContext.hpp>
#include <comphelper/namedvaluecollection.hxx>
#include <comphelper/compbase.hxx>
#include <comphelper/servicehelper.hxx>
#include <cppuhelper/supportsservice.hxx>
@@ -90,7 +91,7 @@ Reference<ui::XUIElement> SAL_CALL SwPanelFactory::createUIElement (
SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue);
weld::Widget* pParent(nullptr);
if (weld::TransportAsXWindow* pTunnel = dynamic_cast<weld::TransportAsXWindow*>(xParentWindow.get()))
if (weld::TransportAsXWindow* pTunnel = comphelper::getFromUnoTunnel<weld::TransportAsXWindow>(xParentWindow))
pParent = pTunnel->getWidget();
if (!pParent)
+1
View File
@@ -162,6 +162,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/source/window/taskpanelist \
vcl/source/window/toolbox2 \
vcl/source/window/toolbox \
vcl/source/window/weldutils \
vcl/source/window/window2 \
vcl/source/window/window3 \
vcl/source/window/window \
+21
View File
@@ -0,0 +1,21 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <sal/config.h>
#include <comphelper/servicehelper.hxx>
#include <vcl/weldutils.hxx>
css::uno::Sequence<sal_Int8> const& weld::TransportAsXWindow::getUnoTunnelId()
{
static comphelper::UnoIdInit const id;
return id.getSeq();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */