summaryrefslogtreecommitdiff
path: root/starmath/source
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2011-05-22 16:41:01 +0100
committerCaolán McNamara <caolanm@redhat.com>2011-05-23 12:35:54 +0100
commit454e1756a60d9b8eb4f9152b93fe560777a9e01a (patch)
tree0bb38131e1dea7c428fe2826505dec6bb960bf44 /starmath/source
parent1adb8f26cb9eeb71fc73029292257258ade7142e (diff)
make this a non-leaky singleton
Diffstat (limited to 'starmath/source')
-rw-r--r--starmath/source/smdll.cxx104
-rw-r--r--starmath/source/unodoc.cxx9
2 files changed, 57 insertions, 56 deletions
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 <svx/xmlsecctrl.hxx>
-
-
-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<SmDLL, theSmDLLInstance> {};
}
-
-// 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() );
}