From 37a4d67d6885860c279476c2504e35c3190ffc6c Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Fri, 3 Mar 2023 13:15:24 +0200 Subject: [PATCH] flatten DocumentUndoGuard which is a small object, and doesn't need a pimpl pattern Change-Id: Ib76f6e5ad0347be61fe29b22f57e1211ce3337cc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148172 Tested-by: Jenkins Reviewed-by: Noel Grandin --- .../source/fwe/helper/documentundoguard.cxx | 73 ++++++------------- include/framework/documentundoguard.hxx | 11 +-- 2 files changed, 29 insertions(+), 55 deletions(-) diff --git a/framework/source/fwe/helper/documentundoguard.cxx b/framework/source/fwe/helper/documentundoguard.cxx index 3442cd501131..0a027921817a 100644 --- a/framework/source/fwe/helper/documentundoguard.cxx +++ b/framework/source/fwe/helper/documentundoguard.cxx @@ -44,8 +44,6 @@ namespace framework typedef ::cppu::WeakImplHelper < XUndoManagerListener > UndoManagerContextListener_Base; - namespace { - class UndoManagerContextListener : public UndoManagerContextListener_Base { public: @@ -100,8 +98,6 @@ namespace framework bool m_documentDisposed; }; - } - void SAL_CALL UndoManagerContextListener::undoActionAdded( const UndoManagerEvent& ) { // not interested in @@ -162,60 +158,37 @@ namespace framework m_documentDisposed = true; } - //= DocumentUndoGuard_Data - - struct DocumentUndoGuard_Data - { - Reference< XUndoManager > xUndoManager; - ::rtl::Reference< UndoManagerContextListener > pContextListener; - }; - - namespace - { - - void lcl_init( DocumentUndoGuard_Data& i_data, const Reference< XInterface >& i_undoSupplierComponent ) - { - try - { - Reference< XUndoManagerSupplier > xUndoSupplier( i_undoSupplierComponent, UNO_QUERY ); - if ( xUndoSupplier.is() ) - i_data.xUndoManager.set( xUndoSupplier->getUndoManager(), css::uno::UNO_SET_THROW ); - - if ( i_data.xUndoManager.is() ) - i_data.pContextListener.set( new UndoManagerContextListener( i_data.xUndoManager ) ); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION("fwk"); - } - } - - void lcl_restore( DocumentUndoGuard_Data& i_data ) - { - try - { - if ( i_data.pContextListener.is() ) - i_data.pContextListener->finish(); - i_data.pContextListener.clear(); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION("fwk"); - } - } - } - //= DocumentUndoGuard DocumentUndoGuard::DocumentUndoGuard( const Reference< XInterface >& i_undoSupplierComponent ) - :m_xData( new DocumentUndoGuard_Data ) { - lcl_init( *m_xData, i_undoSupplierComponent ); + try + { + Reference< XUndoManagerSupplier > xUndoSupplier( i_undoSupplierComponent, UNO_QUERY ); + if ( xUndoSupplier.is() ) + mxUndoManager.set( xUndoSupplier->getUndoManager(), css::uno::UNO_SET_THROW ); + + if ( mxUndoManager.is() ) + mxContextListener.set( new UndoManagerContextListener( mxUndoManager ) ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION("fwk"); + } } DocumentUndoGuard::~DocumentUndoGuard() { - lcl_restore( *m_xData ); + try + { + if ( mxContextListener.is() ) + mxContextListener->finish(); + mxContextListener.clear(); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION("fwk"); + } } } // namespace framework diff --git a/include/framework/documentundoguard.hxx b/include/framework/documentundoguard.hxx index ec1a5951b15c..c0cf232e7f28 100644 --- a/include/framework/documentundoguard.hxx +++ b/include/framework/documentundoguard.hxx @@ -21,18 +21,18 @@ #define INCLUDED_FRAMEWORK_DOCUMENTUNDOGUARD_HXX #include - #include - -#include +#include namespace com::sun::star::uno { class XInterface; } +namespace com::sun::star::document { class XUndoManager; } namespace framework { + class UndoManagerContextListener; + //= DocumentUndoGuard - struct DocumentUndoGuard_Data; /** a helper class guarding the Undo manager of a document This class guards, within a given scope, the Undo Manager of a document (or another component supporting @@ -49,7 +49,8 @@ namespace framework ~DocumentUndoGuard(); private: - std::unique_ptr< DocumentUndoGuard_Data > m_xData; + css::uno::Reference< css::document::XUndoManager > mxUndoManager; + ::rtl::Reference< UndoManagerContextListener > mxContextListener; };