From 454e1756a60d9b8eb4f9152b93fe560777a9e01a Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Sun, 22 May 2011 16:41:01 +0100 Subject: make this a non-leaky singleton --- starmath/inc/smdll.hxx | 17 +--- starmath/qa/cppunit/test_nodetotextvisitors.cxx | 2 +- starmath/qa/cppunit/test_starmath.cxx | 2 +- starmath/source/smdll.cxx | 104 +++++++++++++----------- starmath/source/unodoc.cxx | 9 +- 5 files changed, 62 insertions(+), 72 deletions(-) diff --git a/starmath/inc/smdll.hxx b/starmath/inc/smdll.hxx index 324f3308608b..be46c1dc8ad0 100644 --- a/starmath/inc/smdll.hxx +++ b/starmath/inc/smdll.hxx @@ -28,21 +28,10 @@ #ifndef SMDLL_HXX #define SMDLL_HXX -#include -#include -#include "smmod.hxx" - -class SmData; -class SfxMedium; -class SfxFilter; - -class SmDLL +namespace SmGlobals { - static bool bInitialized; -public: - static void Init(); - static void Exit(); -}; + void ensure(); +} #endif diff --git a/starmath/qa/cppunit/test_nodetotextvisitors.cxx b/starmath/qa/cppunit/test_nodetotextvisitors.cxx index aec9be0efa46..f7b282c60e6d 100644 --- a/starmath/qa/cppunit/test_nodetotextvisitors.cxx +++ b/starmath/qa/cppunit/test_nodetotextvisitors.cxx @@ -150,7 +150,7 @@ Test::Test() InitVCL(xSM); - SmDLL::Init(); + SmGlobals::ensure(); } void Test::setUp() diff --git a/starmath/qa/cppunit/test_starmath.cxx b/starmath/qa/cppunit/test_starmath.cxx index cc013bfa6558..b19ead0caeaf 100644 --- a/starmath/qa/cppunit/test_starmath.cxx +++ b/starmath/qa/cppunit/test_starmath.cxx @@ -115,7 +115,7 @@ Test::Test() InitVCL(xSM); - SmDLL::Init(); + SmGlobals::ensure(); } void Test::setUp() diff --git a/starmath/source/smdll.cxx b/starmath/source/smdll.cxx index 00ea0f5d49b2..7c4a19b49439 100644 --- a/starmath/source/smdll.cxx +++ b/starmath/source/smdll.cxx @@ -50,59 +50,65 @@ #include - - -bool SmDLL::bInitialized = false; - - -// Initialization - -void SmDLL::Init() +namespace { - if ( bInitialized ) - return; - - bInitialized = true; - - SfxObjectFactory& rFactory = SmDocShell::Factory(); - - SmModule** ppShlPtr = (SmModule**) GetAppData(SHL_SM); - *ppShlPtr = new SmModule( &rFactory ); - - SfxModule *p = SM_MOD(); - SmModule *pp = (SmModule *) p; - - rFactory.SetDocumentServiceName( String::CreateFromAscii("com.sun.star.formula.FormulaProperties") ); - - SmModule::RegisterInterface(pp); - SmDocShell::RegisterInterface(pp); - SmViewShell::RegisterInterface(pp); - - SmViewShell::RegisterFactory(1); - - SvxZoomStatusBarControl::RegisterControl( SID_ATTR_ZOOM, pp ); - SvxModifyControl::RegisterControl( SID_TEXTSTATUS, pp ); - SvxUndoRedoControl::RegisterControl( SID_UNDO, pp ); - SvxUndoRedoControl::RegisterControl( SID_REDO, pp ); - XmlSecStatusBarControl::RegisterControl( SID_SIGNATURE, pp ); - - SmToolBoxWrapper::RegisterChildWindow(true); - SmCmdBoxWrapper::RegisterChildWindow(true); - - ::sfx2::TaskPaneWrapper::RegisterChildWindow( false, pp ); + class SmDLL + { + public: + SmDLL(); + ~SmDLL(); + }; + + SmDLL::SmDLL() + { + SmModule** ppShlPtr = (SmModule**) GetAppData(SHL_SM); + if ( *ppShlPtr ) + return; + + SfxObjectFactory& rFactory = SmDocShell::Factory(); + SmModule *pModule = new SmModule( &rFactory ); + *ppShlPtr = pModule; + + rFactory.SetDocumentServiceName( String::CreateFromAscii("com.sun.star.formula.FormulaProperties") ); + + SmModule::RegisterInterface(pModule); + SmDocShell::RegisterInterface(pModule); + SmViewShell::RegisterInterface(pModule); + + SmViewShell::RegisterFactory(1); + + SvxZoomStatusBarControl::RegisterControl(SID_ATTR_ZOOM, pModule); + SvxModifyControl::RegisterControl(SID_TEXTSTATUS, pModule); + SvxUndoRedoControl::RegisterControl(SID_UNDO, pModule); + SvxUndoRedoControl::RegisterControl(SID_REDO, pModule); + XmlSecStatusBarControl::RegisterControl(SID_SIGNATURE, pModule); + + SmToolBoxWrapper::RegisterChildWindow(true); + SmCmdBoxWrapper::RegisterChildWindow(true); + + ::sfx2::TaskPaneWrapper::RegisterChildWindow(false, pModule); + } + + SmDLL::~SmDLL() + { +#if 0 + // the SdModule must be destroyed + SmModule** ppShlPtr = (SmModule**) GetAppData(SHL_SM); + delete (*ppShlPtr); + (*ppShlPtr) = NULL; + *GetAppData(SHL_SM) = 0; +#endif + } + + struct theSmDLLInstance : public rtl::Static {}; } - -// Deinitialization - -void SmDLL::Exit() +namespace SmGlobals { - // the SdModule must be destroyed - SmModule** ppShlPtr = (SmModule**) GetAppData(SHL_SM); - delete (*ppShlPtr); - (*ppShlPtr) = NULL; - - *GetAppData(SHL_SM) = 0; + void ensure() + { + theSmDLLInstance::get(); + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/starmath/source/unodoc.cxx b/starmath/source/unodoc.cxx index 4f0205f5cd38..aa322f9b6810 100644 --- a/starmath/source/unodoc.cxx +++ b/starmath/source/unodoc.cxx @@ -59,14 +59,9 @@ uno::Reference< uno::XInterface > SAL_CALL SmDocument_createInstance( const uno::Reference< lang::XMultiServiceFactory > & /*rSMgr*/, const sal_uInt64 _nCreationFlags ) throw( uno::Exception ) { SolarMutexGuard aGuard; - if ( !SM_MOD() ) - SmDLL::Init(); - + SmGlobals::ensure(); SfxObjectShell* pShell = new SmDocShell( _nCreationFlags ); - if( pShell ) - return uno::Reference< uno::XInterface >( pShell->GetModel() ); - - return uno::Reference< uno::XInterface >(); + return uno::Reference< uno::XInterface >( pShell->GetModel() ); } -- cgit