summaryrefslogtreecommitdiff
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
commit6d192be41c725fb83cdd8c093873ff574696b995 (patch)
tree6da9e37d0114633942f5b2ed5356354d0b5f3d60
parent7c20143b0935f73b2e1146e896f5502f5354aee4 (diff)
make this a non-leaky singletonfeature/calc-multiline-input
-rw-r--r--starmath/inc/smdll.hxx17
-rw-r--r--starmath/qa/cppunit/test_nodetotextvisitors.cxx2
-rw-r--r--starmath/qa/cppunit/test_starmath.cxx2
-rw-r--r--starmath/source/smdll.cxx104
-rw-r--r--starmath/source/unodoc.cxx9
5 files changed, 62 insertions, 72 deletions
diff --git a/starmath/inc/smdll.hxx b/starmath/inc/smdll.hxx
index aba28e3819..b1097da9d8 100644
--- a/starmath/inc/smdll.hxx
+++ b/starmath/inc/smdll.hxx
@@ -28,21 +28,10 @@
#ifndef SMDLL_HXX
#define SMDLL_HXX
-#include <tools/resid.hxx>
-#include <sfx2/sfxdefs.hxx>
-#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 aec9be0efa..f7b282c60e 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 cc013bfa65..b19ead0cae 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 f9f07c414a..b519b48726 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 9fae49f782..2e4eae8bc7 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() );
}