Skip to content

Commit

Permalink
XUnoTunnel->dynamic_cast in sd::DrawController
Browse files Browse the repository at this point in the history
Just past the concrete type down through a couple of layers, rather than
using a generic type and then casting

Change-Id: I7ba6c83463f3db7176b72cb7e764d3659706ae78
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145638
Tested-by: Jenkins
Reviewed-by: Noel Grandin <[email protected]>
  • Loading branch information
Noel Grandin committed Jan 17, 2023
1 parent c1d50d7 commit 5355f52
Show file tree
Hide file tree
Showing 23 changed files with 61 additions and 70 deletions.
3 changes: 1 addition & 2 deletions sd/source/ui/framework/factories/BasicPaneFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ void SAL_CALL BasicPaneFactory::initialize (const Sequence<Any>& aArguments)
// Tunnel through the controller to obtain access to the ViewShellBase.
try
{
Reference<lang::XUnoTunnel> xTunnel (xController, UNO_QUERY_THROW);
if (auto pController = comphelper::getFromUnoTunnel<DrawController>(xTunnel))
if (auto pController = dynamic_cast<DrawController*>(xController.get()))
mpViewShellBase = pController->GetViewShellBase();
}
catch(RuntimeException&)
Expand Down
3 changes: 1 addition & 2 deletions sd/source/ui/framework/factories/BasicViewFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,7 @@ void SAL_CALL BasicViewFactory::initialize (const Sequence<Any>& aArguments)
Reference<frame::XController> xController (aArguments[0], UNO_QUERY_THROW);

// Tunnel through the controller to obtain a ViewShellBase.
Reference<lang::XUnoTunnel> xTunnel (xController, UNO_QUERY_THROW);
::sd::DrawController* pController = comphelper::getFromUnoTunnel<sd::DrawController>(xTunnel);
::sd::DrawController* pController = dynamic_cast<sd::DrawController*>(xController.get());
if (pController != nullptr)
mpBase = pController->GetViewShellBase();

Expand Down
2 changes: 1 addition & 1 deletion sd/source/ui/framework/factories/PresentationFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void SAL_CALL PresentationFactory::releaseResource (
{
ThrowIfDisposed();

auto pController = comphelper::getFromUnoTunnel<sd::DrawController>(mxController);
auto pController = dynamic_cast<sd::DrawController*>(mxController.get());
if (pController != nullptr)
{
ViewShellBase* pBase = pController->GetViewShellBase();
Expand Down
12 changes: 5 additions & 7 deletions sd/source/ui/framework/module/CenterViewFocusModule.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,18 @@ namespace sd::framework {

//===== CenterViewFocusModule ====================================================

CenterViewFocusModule::CenterViewFocusModule (Reference<frame::XController> const & rxController)
CenterViewFocusModule::CenterViewFocusModule (rtl::Reference<sd::DrawController> const & rxController)
: mbValid(false),
mpBase(nullptr),
mbNewViewCreated(false)
{
Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY);
if (xControllerManager.is())
if (rxController.is())
{
mxConfigurationController = xControllerManager->getConfigurationController();
mxConfigurationController = rxController->getConfigurationController();

// Tunnel through the controller to obtain a ViewShellBase.
auto pController = comphelper::getFromUnoTunnel<sd::DrawController>(rxController);
if (pController != nullptr)
mpBase = pController->GetViewShellBase();
if (rxController != nullptr)
mpBase = rxController->GetViewShellBase();

// Check, if all required objects do exist.
if (mxConfigurationController.is() && mpBase!=nullptr)
Expand Down
5 changes: 3 additions & 2 deletions sd/source/ui/framework/module/CenterViewFocusModule.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <com/sun/star/drawing/framework/XConfigurationChangeListener.hpp>
#include <comphelper/compbase.hxx>
#include <rtl/ref.hxx>

namespace com::sun::star::drawing::framework
{
Expand All @@ -33,6 +34,7 @@ class XController;

namespace sd
{
class DrawController;
class ViewShellBase;
}

Expand All @@ -49,8 +51,7 @@ typedef comphelper::WeakComponentImplHelper<css::drawing::framework::XConfigurat
class CenterViewFocusModule final : public CenterViewFocusModuleInterfaceBase
{
public:
explicit CenterViewFocusModule(
css::uno::Reference<css::frame::XController> const& rxController);
explicit CenterViewFocusModule(rtl::Reference<sd::DrawController> const& rxController);
virtual ~CenterViewFocusModule() override;

virtual void disposing(std::unique_lock<std::mutex>&) override;
Expand Down
3 changes: 2 additions & 1 deletion sd/source/ui/framework/module/DrawModule.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
#include "CenterViewFocusModule.hxx"
#include "SlideSorterModule.hxx"
#include "ToolBarModule.hxx"
#include <DrawController.hxx>

using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;

namespace sd::framework
{
void DrawModule::Initialize(Reference<frame::XController> const& rxController)
void DrawModule::Initialize(rtl::Reference<sd::DrawController> const& rxController)
{
new sd::framework::CenterViewFocusModule(rxController);
new sd::framework::SlideSorterModule(rxController, FrameworkHelper::msLeftDrawPaneURL);
Expand Down
3 changes: 2 additions & 1 deletion sd/source/ui/framework/module/ImpressModule.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
#include "SlideSorterModule.hxx"
#include "ToolBarModule.hxx"
#include "ShellStackGuard.hxx"
#include <DrawController.hxx>

using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;

namespace sd::framework {

void ImpressModule::Initialize (Reference<frame::XController> const & rxController)
void ImpressModule::Initialize (rtl::Reference<sd::DrawController> const & rxController)
{
new CenterViewFocusModule(rxController);
new ViewTabBarModule(
Expand Down
2 changes: 1 addition & 1 deletion sd/source/ui/framework/module/PresentationModule.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ using namespace ::com::sun::star::uno;

namespace sd::framework
{
void PresentationModule::Initialize(Reference<frame::XController> const& rxController)
void PresentationModule::Initialize(rtl::Reference<sd::DrawController> const& rxController)
{
new sd::framework::CenterViewFocusModule(rxController);
}
Expand Down
11 changes: 4 additions & 7 deletions sd/source/ui/framework/module/ShellStackGuard.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,16 @@ namespace sd::framework {

//===== CenterViewFocusModule ====================================================

ShellStackGuard::ShellStackGuard (Reference<frame::XController> const & rxController)
ShellStackGuard::ShellStackGuard (rtl::Reference<sd::DrawController> const & rxController)
: mpBase(nullptr),
maPrinterPollingIdle("sd ShellStackGuard PrinterPollingIdle")
{
Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY);
if (xControllerManager.is())
if (rxController.is())
{
mxConfigurationController = xControllerManager->getConfigurationController();
mxConfigurationController = rxController->getConfigurationController();

// Tunnel through the controller to obtain a ViewShellBase.
auto pController = comphelper::getFromUnoTunnel<sd::DrawController>(rxController);
if (pController != nullptr)
mpBase = pController->GetViewShellBase();
mpBase = rxController->GetViewShellBase();
}

if (mxConfigurationController.is())
Expand Down
4 changes: 3 additions & 1 deletion sd/source/ui/framework/module/ShellStackGuard.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <com/sun/star/drawing/framework/XConfigurationChangeListener.hpp>

#include <rtl/ref.hxx>
#include <vcl/idle.hxx>
#include <comphelper/compbase.hxx>
#include <memory>
Expand All @@ -38,6 +39,7 @@ class XController;

namespace sd
{
class DrawController;
class ViewShellBase;
}

Expand All @@ -59,7 +61,7 @@ typedef comphelper::WeakComponentImplHelper<css::drawing::framework::XConfigurat
class ShellStackGuard : public ShellStackGuardInterfaceBase
{
public:
explicit ShellStackGuard(css::uno::Reference<css::frame::XController> const& rxController);
explicit ShellStackGuard(rtl::Reference<sd::DrawController> const& rxController);
virtual ~ShellStackGuard() override;

virtual void disposing(std::unique_lock<std::mutex>&) override;
Expand Down
12 changes: 5 additions & 7 deletions sd/source/ui/framework/module/ToolBarModule.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,18 @@ namespace sd::framework {
//===== ToolBarModule =========================================================

ToolBarModule::ToolBarModule (
const Reference<frame::XController>& rxController)
const rtl::Reference<sd::DrawController>& rxController)
: mpBase(nullptr),
mbMainViewSwitchUpdatePending(false)
{
// Tunnel through the controller to obtain a ViewShellBase.
auto pController = comphelper::getFromUnoTunnel<sd::DrawController>(rxController);
if (pController != nullptr)
mpBase = pController->GetViewShellBase();
if (rxController != nullptr)
mpBase = rxController->GetViewShellBase();

Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY);
if (!xControllerManager.is())
if (!rxController.is())
return;

mxConfigurationController = xControllerManager->getConfigurationController();
mxConfigurationController = rxController->getConfigurationController();
if (!mxConfigurationController.is())
return;

Expand Down
4 changes: 3 additions & 1 deletion sd/source/ui/framework/module/ToolBarModule.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
#include <com/sun/star/drawing/framework/XConfigurationChangeListener.hpp>
#include <comphelper/compbase.hxx>
#include <o3tl/deleter.hxx>
#include <rtl/ref.hxx>
#include <memory>

namespace com::sun::star::drawing::framework { class XConfigurationController; }
namespace com::sun::star::frame { class XController; }

namespace sd {
class DrawController;
class ViewShellBase;
}

Expand All @@ -50,7 +52,7 @@ public:
This is the access point to the drawing framework.
*/
explicit ToolBarModule (
const css::uno::Reference<css::frame::XController>& rxController);
const rtl::Reference<sd::DrawController>& rxController);
virtual ~ToolBarModule() override;

virtual void disposing(std::unique_lock<std::mutex>&) override;
Expand Down
10 changes: 1 addition & 9 deletions sd/source/ui/inc/DrawController.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <com/sun/star/drawing/XDrawView.hpp>
#include <com/sun/star/drawing/framework/XControllerManager.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <comphelper/uno3.hxx>
#include <cppuhelper/implbase.hxx>
#include <unotools/weakref.hxx>
Expand All @@ -51,8 +50,7 @@ typedef ::cppu::ImplInheritanceHelper <
css::drawing::XDrawView,
css::view::XSelectionChangeListener,
css::view::XFormLayerAccess,
css::drawing::framework::XControllerManager,
css::lang::XUnoTunnel
css::drawing::framework::XControllerManager
> DrawControllerInterfaceBase;

class BroadcastHelperOwner
Expand Down Expand Up @@ -159,8 +157,6 @@ public:
*/
void ReleaseViewShellBase();

static const css::uno::Sequence<sal_Int8>& getUnoTunnelId();

DECLARE_XINTERFACE()
DECLARE_XTYPEPROVIDER()

Expand Down Expand Up @@ -220,10 +216,6 @@ public:
virtual css::uno::Reference<css::drawing::framework::XModuleController> SAL_CALL
getModuleController() override;

// XUnoTunnel

virtual sal_Int64 SAL_CALL getSomething (const css::uno::Sequence<sal_Int8>& rId) override;

private:
/** This method must return the name to index table. This table
contains all property names and types of this object.
Expand Down
7 changes: 6 additions & 1 deletion sd/source/ui/inc/framework/DrawModule.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#pragma once

#include <sal/types.h>
#include <rtl/ref.hxx>

namespace com::sun::star::frame
{
Expand All @@ -29,6 +30,10 @@ namespace com::sun::star::uno
{
template <typename> class Reference;
}
namespace sd
{
class DrawController;
}

namespace sd::framework
{
Expand All @@ -38,7 +43,7 @@ namespace sd::framework
class DrawModule
{
public:
static void Initialize(css::uno::Reference<css::frame::XController> const& rxController);
static void Initialize(rtl::Reference<sd::DrawController> const& rxController);
};

} // end of namespace sd::framework
Expand Down
7 changes: 6 additions & 1 deletion sd/source/ui/inc/framework/ImpressModule.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#pragma once

#include <sal/types.h>
#include <rtl/ref.hxx>

namespace com::sun::star::frame
{
Expand All @@ -29,6 +30,10 @@ namespace com::sun::star::uno
{
template <class interface_type> class Reference;
}
namespace sd
{
class DrawController;
}

namespace sd::framework
{
Expand All @@ -38,7 +43,7 @@ namespace sd::framework
class ImpressModule
{
public:
static void Initialize(css::uno::Reference<css::frame::XController> const& rxController);
static void Initialize(rtl::Reference<sd::DrawController> const& rxController);
};

} // end of namespace sd::framework
Expand Down
7 changes: 6 additions & 1 deletion sd/source/ui/inc/framework/PresentationModule.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#pragma once

#include <sal/types.h>
#include <rtl/ref.hxx>

namespace com::sun::star::frame
{
Expand All @@ -29,6 +30,10 @@ namespace com::sun::star::uno
{
template <class interface_type> class Reference;
}
namespace sd
{
class DrawController;
}

namespace sd::framework
{
Expand All @@ -38,7 +43,7 @@ namespace sd::framework
class PresentationModule
{
public:
static void Initialize(css::uno::Reference<css::frame::XController> const& rxController);
static void Initialize(rtl::Reference<sd::DrawController> const& rxController);
};

} // end of namespace sd::framework
Expand Down
2 changes: 1 addition & 1 deletion sd/source/ui/sidebar/PanelFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Reference<ui::XUIElement> SAL_CALL PanelFactory::createUIElement (

// Tunnel through the controller to obtain a ViewShellBase.
ViewShellBase* pBase = nullptr;
auto pController = comphelper::getFromUnoTunnel<sd::DrawController>(xFrame->getController());
rtl::Reference<sd::DrawController> pController = dynamic_cast<sd::DrawController*>(xFrame->getController().get());
if (pController != nullptr)
pBase = pController->GetViewShellBase();
if (pBase == nullptr)
Expand Down
3 changes: 1 addition & 2 deletions sd/source/ui/slidesorter/shell/SlideSorterService.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ void SAL_CALL SlideSorterService::initialize (const Sequence<Any>& rArguments)

// Tunnel through the controller to obtain a ViewShellBase.
ViewShellBase* pBase = nullptr;
Reference<lang::XUnoTunnel> xTunnel (xController, UNO_QUERY_THROW);
::sd::DrawController* pController = comphelper::getFromUnoTunnel<sd::DrawController>(xTunnel);
::sd::DrawController* pController = dynamic_cast<sd::DrawController*>(xController.get());
if (pController != nullptr)
pBase = pController->GetViewShellBase();

Expand Down
13 changes: 0 additions & 13 deletions sd/source/ui/unoidl/DrawController.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -551,19 +551,6 @@ Reference<XModuleController> SAL_CALL
return mxModuleController;
}

//===== XUnoTunnel ============================================================

const Sequence<sal_Int8>& DrawController::getUnoTunnelId()
{
static const comphelper::UnoIdInit theDrawControllerUnoTunnelId;
return theDrawControllerUnoTunnelId.getSeq();
}

sal_Int64 SAL_CALL DrawController::getSomething (const Sequence<sal_Int8>& rId)
{
return comphelper::getSomethingImpl(rId, this);
}

//===== Properties ============================================================

void DrawController::FillPropertyTable (
Expand Down
3 changes: 2 additions & 1 deletion sd/source/ui/view/GraphicViewShellBase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <GraphicViewShellBase.hxx>

#include <GraphicDocShell.hxx>
#include <DrawController.hxx>
#include <app.hrc>
#include <framework/DrawModule.hxx>
#include <framework/FrameworkHelper.hxx>
Expand Down Expand Up @@ -84,7 +85,7 @@ void GraphicViewShellBase::Execute(SfxRequest& rRequest)

void GraphicViewShellBase::InitializeFramework()
{
css::uno::Reference<css::frame::XController> xController(GetController());
rtl::Reference<sd::DrawController> xController(&GetDrawController());
sd::framework::DrawModule::Initialize(xController);
}

Expand Down
Loading

0 comments on commit 5355f52

Please sign in to comment.