From c20f15c1ebf648c3ed71de0ac4771029c9bb59bb Mon Sep 17 00:00:00 2001 From: "Uray M. János" Date: Sat, 25 Aug 2012 12:43:27 +0200 Subject: Basic IDE: namespace basctl Now all names in basctl are in namespace 'basctl'. There were lots of names that included the word 'Basic' or 'BasicIDE' in it, e.g. BasicIDEData, BasicDocumentEntry, BasicTreeListBox, BasicIDEModule, IDEBaseWindow etc. This information is now stored in the namespace name, so the names could be shortened: basctl::DocumentEntry, basctl::TreeListBox, basctl::Module, basctl::BaseWindow etc. Some other minor changes: * LibInfos, LibInfoItem, LibInfoKey -> LibInfos, LibInfos::Item, LibInfos::Key * The header guards are now uniformly BASCTL_FILENAME_HXX, instead of e.g. _FILENAME_HXX, which is undefined behaviour because of the '_'. * namespace BasicIDE, BasicIDEGlobals, basicide -> namespace basctl * BASICIDE_TYPE_MODULE, ... -> basctl::TYPE_MODULE, ... Change-Id: I2a9b493562d0d8a2510d569798fbe9e1161b7c9b Reviewed-on: https://gerrit.libreoffice.org/501 Reviewed-by: Andras Timar Tested-by: Andras Timar --- basctl/source/basicide/iderdll.cxx | 185 +++++++++++++++++++------------------ 1 file changed, 93 insertions(+), 92 deletions(-) (limited to 'basctl/source/basicide/iderdll.cxx') diff --git a/basctl/source/basicide/iderdll.cxx b/basctl/source/basicide/iderdll.cxx index 357a3ddd56de..75b5c31f347c 100644 --- a/basctl/source/basicide/iderdll.cxx +++ b/basctl/source/basicide/iderdll.cxx @@ -41,127 +41,135 @@ #include #include +#include + +namespace basctl +{ + using ::rtl::OUString; using namespace ::com::sun::star; using namespace ::com::sun::star::uno; -class BasicIDEDLL +namespace +{ + +class Dll { - BasicIDEShell* m_pShell; - BasicIDEData* m_pExtraData; + Shell* m_pShell; + boost::scoped_ptr m_pExtraData; public: - BasicIDEDLL(); - ~BasicIDEDLL(); + Dll (); - BasicIDEShell* GetShell() const { return m_pShell; } - void SetShell(BasicIDEShell* pShell) { m_pShell = pShell; } - BasicIDEData* GetExtraData(); + Shell* GetShell() const { return m_pShell; } + void SetShell (Shell* pShell) { m_pShell = pShell; } + ExtraData* GetExtraData (); }; -namespace +// Holds a basctl::Dll and release it on exit, or dispose of the +//default XComponent, whichever comes first +class DllInstance : public comphelper::scoped_disposing_solar_mutex_reset_ptr { - //Holds a BasicIDEDLL and release it on exit, or dispose of the - //default XComponent, whichever comes first - class BasicIDEDLLInstance : public comphelper::scoped_disposing_solar_mutex_reset_ptr - { - public: - BasicIDEDLLInstance() : comphelper::scoped_disposing_solar_mutex_reset_ptr(::com::sun::star::uno::Reference(comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop"))), ::com::sun::star::uno::UNO_QUERY_THROW), new BasicIDEDLL) - { - } - }; - - struct theBasicIDEDLLInstance : public rtl::Static {}; -} +public: + DllInstance() : comphelper::scoped_disposing_solar_mutex_reset_ptr(::com::sun::star::uno::Reference(comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop"))), ::com::sun::star::uno::UNO_QUERY_THROW), new Dll) + { } +}; -namespace BasicIDEGlobals -{ - void ensure() - { - theBasicIDEDLLInstance::get(); - } +struct theDllInstance : public rtl::Static { }; - BasicIDEShell* GetShell() - { - BasicIDEDLL *pIDEGlobals = theBasicIDEDLLInstance::get().get(); - return pIDEGlobals ? pIDEGlobals->GetShell() : NULL; - } +} // namespace - void ShellCreated(BasicIDEShell* pShell) - { - BasicIDEDLL *pIDEGlobals = theBasicIDEDLLInstance::get().get(); - if (pIDEGlobals && pIDEGlobals->GetShell() == NULL) - pIDEGlobals->SetShell(pShell); - } +void EnsureIde () +{ + theDllInstance::get(); +} - void ShellDestroyed(BasicIDEShell* pShell) - { - BasicIDEDLL *pIDEGlobals = theBasicIDEDLLInstance::get().get(); - if (pIDEGlobals && pIDEGlobals->GetShell() == pShell) - pIDEGlobals->SetShell(NULL); - } +Shell* GetShell () +{ + if (Dll* pDll = theDllInstance::get().get()) + return pDll->GetShell(); + return 0; +} - BasicIDEData* GetExtraData() - { - BasicIDEDLL *pIDEGlobals = theBasicIDEDLLInstance::get().get(); - return pIDEGlobals ? pIDEGlobals->GetExtraData() : NULL; - } +void ShellCreated (Shell* pShell) +{ + Dll* pDll = theDllInstance::get().get(); + if (pDll && !pDll->GetShell()) + pDll->SetShell(pShell); } -IDEResId::IDEResId( sal_uInt16 nId ): - ResId( nId, *(BASIC_MOD())->GetResMgr() ) +void ShellDestroyed (Shell* pShell) { + Dll* pDll = theDllInstance::get().get(); + if (pDll && pDll->GetShell() == pShell) + pDll->SetShell(0); } -BasicIDEDLL::~BasicIDEDLL() +ExtraData* GetExtraData() { - delete m_pExtraData; + if (Dll* pDll = theDllInstance::get().get()) + return pDll->GetExtraData(); + return 0; } -BasicIDEDLL::BasicIDEDLL() - : m_pShell(0) - , m_pExtraData(0) + +IDEResId::IDEResId( sal_uInt16 nId ): + ResId(nId, *Module::Get()->GetResMgr()) +{ } + +namespace { - SfxObjectFactory* pFact = &BasicDocShell::Factory(); + +Dll::Dll () : + m_pShell(0) +{ + SfxObjectFactory* pFact = &DocShell::Factory(); (void)pFact; ResMgr* pMgr = ResMgr::CreateResMgr( - "basctl", Application::GetSettings().GetUILocale() ); + "basctl", Application::GetSettings().GetUILocale() + ); - BASIC_MOD() = new BasicIDEModule( pMgr, &BasicDocShell::Factory() ); + Module::Get() = new Module( pMgr, &DocShell::Factory() ); GetExtraData(); // to cause GlobalErrorHdl to be set - SfxModule* pMod = BASIC_MOD(); + SfxModule* pMod = Module::Get(); - SfxObjectFactory& rFactory = BasicDocShell::Factory(); + SfxObjectFactory& rFactory = DocShell::Factory(); rFactory.SetDocumentServiceName( rtl::OUString("com.sun.star.script.BasicIDE") ); - BasicDocShell::RegisterInterface( pMod ); - BasicIDEShell::RegisterFactory( SVX_INTERFACE_BASIDE_VIEWSH ); - BasicIDEShell::RegisterInterface( pMod ); + DocShell::RegisterInterface( pMod ); + Shell::RegisterFactory( SVX_INTERFACE_BASIDE_VIEWSH ); + Shell::RegisterInterface( pMod ); PropBrwMgr::RegisterChildWindow(); } -BasicIDEData* BasicIDEDLL::GetExtraData() +ExtraData* Dll::GetExtraData () { if (!m_pExtraData) - m_pExtraData = new BasicIDEData; - return m_pExtraData; + m_pExtraData.reset(new ExtraData); + return m_pExtraData.get(); } -BasicIDEData::BasicIDEData() -{ - nBasicDialogCount = 0; - bChoosingMacro = false; - bShellInCriticalSection = false; - pSearchItem = new SvxSearchItem( SID_SEARCH_ITEM ); +} // namespace - StarBASIC::SetGlobalBreakHdl( LINK( this, BasicIDEData, GlobalBasicBreakHdl ) ); +// +// basctl::ExtraData +// =================== +// + +ExtraData::ExtraData () : + pSearchItem(new SvxSearchItem(SID_SEARCH_ITEM)), + nBasicDialogCount(0), + bChoosingMacro(false), + bShellInCriticalSection(false) +{ + StarBASIC::SetGlobalBreakHdl(LINK(this, ExtraData, GlobalBasicBreakHdl)); } -BasicIDEData::~BasicIDEData() +ExtraData::~ExtraData () { // Resetting ErrorHdl is cleaner indeed but this instance is destroyed // pretty late, after the last Basic, anyway. @@ -170,36 +178,26 @@ BasicIDEData::~BasicIDEData() // StarBASIC::SetGlobalErrorHdl( Link() ); // StarBASIC::SetGlobalBreakHdl( Link() ); // StarBASIC::setGlobalStarScriptListener( XEngineListenerRef() ); - - delete pSearchItem; } -SvxSearchItem& BasicIDEData::GetSearchItem() const +void ExtraData::SetSearchItem (const SvxSearchItem& rItem) { - return *pSearchItem; + pSearchItem.reset((SvxSearchItem*)rItem.Clone()); } -void BasicIDEData::SetSearchItem( const SvxSearchItem& rItem ) -{ - delete pSearchItem; - pSearchItem = (SvxSearchItem*)rItem.Clone(); -} - -IMPL_LINK( BasicIDEData, GlobalBasicBreakHdl, StarBASIC *, pBasic ) +IMPL_LINK(ExtraData, GlobalBasicBreakHdl, StarBASIC *, pBasic ) { long nRet = 0; - BasicIDEShell* pIDEShell = BasicIDEGlobals::GetShell(); - if ( pIDEShell ) + if (Shell* pShell = GetShell()) { - BasicManager* pBasMgr = BasicIDE::FindBasicManager( pBasic ); - if ( pBasMgr ) + if (BasicManager* pBasMgr = FindBasicManager(pBasic)) { // I do get here twice if Step into protected Basic // => bad, if password query twice, also you don't see // the lib in the PasswordDlg... // => start no password query at this point ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) ); - OSL_ENSURE( aDocument.isValid(), "BasicIDEData::GlobalBasicBreakHdl: no document for the basic manager!" ); + OSL_ENSURE( aDocument.isValid(), "basctl::ExtraData::GlobalBasicBreakHdl: no document for the basic manager!" ); if ( aDocument.isValid() ) { ::rtl::OUString aOULibName( pBasic->GetName() ); @@ -214,7 +212,7 @@ IMPL_LINK( BasicIDEData, GlobalBasicBreakHdl, StarBASIC *, pBasic ) } else { - nRet = pIDEShell->CallBasicBreakHdl( pBasic ); + nRet = pShell->CallBasicBreakHdl( pBasic ); } } } @@ -224,4 +222,7 @@ IMPL_LINK( BasicIDEData, GlobalBasicBreakHdl, StarBASIC *, pBasic ) return nRet; } + +} // namespace basctl + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3