From 76f81d58ab0cd701182f2d55281546ecd8b08c2c Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Mon, 16 Jan 2017 15:14:20 +0200 Subject: use rtl::Reference in LngSvcMgr instead of storing both raw pointers and uno::Reference Change-Id: Ie403e1e7a081bc3f91fd25be89c54ddc1d1cadd2 --- linguistic/source/lngsvcmgr.cxx | 155 +++++++++++++++++++--------------------- linguistic/source/lngsvcmgr.hxx | 25 ++----- 2 files changed, 79 insertions(+), 101 deletions(-) (limited to 'linguistic') diff --git a/linguistic/source/lngsvcmgr.cxx b/linguistic/source/lngsvcmgr.cxx index 35cc6e7fcd1c..9a752aee085b 100644 --- a/linguistic/source/lngsvcmgr.cxx +++ b/linguistic/source/lngsvcmgr.cxx @@ -272,8 +272,8 @@ void LngSvcMgrListenerHelper::Timeout() static_cast(&rMyManager), nCombinedLngSvcEvt ); nCombinedLngSvcEvt = 0; - if (rMyManager.pSpellDsp) - rMyManager.pSpellDsp->FlushSpellCache(); + if (rMyManager.mxSpellDsp.is()) + rMyManager.mxSpellDsp->FlushSpellCache(); // pass event on to linguistic2::XLinguServiceEventListener's aLngSvcMgrListeners.notifyEach( &linguistic2::XLinguServiceEventListener::processLinguServiceEvent, aEvtObj ); @@ -340,8 +340,8 @@ void SAL_CALL if (0 != (nDlEvt & nHyphenateFlags)) nLngSvcEvt |= linguistic2::LinguServiceEventFlags::HYPHENATE_AGAIN; - if (rMyManager.pSpellDsp) - rMyManager.pSpellDsp->FlushSpellCache(); + if (rMyManager.mxSpellDsp.is()) + rMyManager.mxSpellDsp->FlushSpellCache(); if (nLngSvcEvt) LaunchEvent( nLngSvcEvt ); } @@ -431,16 +431,10 @@ LngSvcMgr::LngSvcMgr() { bDisposing = false; - pSpellDsp = nullptr; - pGrammarDsp = nullptr; - pHyphDsp = nullptr; - pThesDsp = nullptr; - pAvailSpellSvcs = nullptr; pAvailGrammarSvcs = nullptr; pAvailHyphSvcs = nullptr; pAvailThesSvcs = nullptr; - pListenerHelper = nullptr; // request notify events when properties (i.e. something in the subtree) changes uno::Sequence< OUString > aNames(4); @@ -508,9 +502,9 @@ IMPL_LINK_NOARG(LngSvcMgr, updateAndBroadcast, Idle *, void) UpdateAll(); - if (pListenerHelper) + if (mxListenerHelper.is()) { - pListenerHelper->AddLngSvcEvt( + mxListenerHelper->AddLngSvcEvt( linguistic2::LinguServiceEventFlags::SPELL_CORRECT_WORDS_AGAIN | linguistic2::LinguServiceEventFlags::SPELL_WRONG_WORDS_AGAIN | linguistic2::LinguServiceEventFlags::PROOFREAD_AGAIN | @@ -845,7 +839,7 @@ void LngSvcMgr::Notify( const uno::Sequence< OUString > &rPropertyNames ) nLang = LanguageTag::convertToLanguageType( aKeyText ); GetSpellCheckerDsp_Impl( false ); // don't set service list, it will be done below - pSpellDsp->SetServiceList( LanguageTag::convertToLocale(nLang), aSvcImplNames ); + mxSpellDsp->SetServiceList( LanguageTag::convertToLocale(nLang), aSvcImplNames ); } } else if (rName.startsWith( aGrammarCheckerList )) @@ -870,7 +864,7 @@ void LngSvcMgr::Notify( const uno::Sequence< OUString > &rPropertyNames ) if (SvtLinguConfig().HasGrammarChecker()) { GetGrammarCheckerDsp_Impl( false ); // don't set service list, it will be done below - pGrammarDsp->SetServiceList( LanguageTag::convertToLocale(nLang), aSvcImplNames ); + mxGrammarDsp->SetServiceList( LanguageTag::convertToLocale(nLang), aSvcImplNames ); } } } @@ -894,7 +888,7 @@ void LngSvcMgr::Notify( const uno::Sequence< OUString > &rPropertyNames ) nLang = LanguageTag::convertToLanguageType( aKeyText ); GetHyphenatorDsp_Impl( false ); // don't set service list, it will be done below - pHyphDsp->SetServiceList( LanguageTag::convertToLocale(nLang), aSvcImplNames ); + mxHyphDsp->SetServiceList( LanguageTag::convertToLocale(nLang), aSvcImplNames ); } } else if (rName.startsWith( aThesaurusList )) @@ -917,7 +911,7 @@ void LngSvcMgr::Notify( const uno::Sequence< OUString > &rPropertyNames ) nLang = LanguageTag::convertToLanguageType( aKeyText ); GetThesaurusDsp_Impl( false ); // don't set service list, it will be done below - pThesDsp->SetServiceList( LanguageTag::convertToLocale(nLang), aSvcImplNames ); + mxThesDsp->SetServiceList( LanguageTag::convertToLocale(nLang), aSvcImplNames ); } } else @@ -938,29 +932,27 @@ void LngSvcMgr::ImplCommit() void LngSvcMgr::GetListenerHelper_Impl() { - if (!pListenerHelper) + if (!mxListenerHelper.is()) { - pListenerHelper = new LngSvcMgrListenerHelper( *this, linguistic::GetDictionaryList() ); - xListenerHelper = static_cast(pListenerHelper); + mxListenerHelper = new LngSvcMgrListenerHelper( *this, linguistic::GetDictionaryList() ); } } void LngSvcMgr::GetSpellCheckerDsp_Impl( bool bSetSvcList ) { - if (!pSpellDsp) + if (!mxSpellDsp.is()) { - pSpellDsp = new SpellCheckerDispatcher( *this ); - xSpellDsp = pSpellDsp; + mxSpellDsp = new SpellCheckerDispatcher( *this ); if (bSetSvcList) - SetCfgServiceLists( *pSpellDsp ); + SetCfgServiceLists( *mxSpellDsp ); } } void LngSvcMgr::GetGrammarCheckerDsp_Impl( bool bSetSvcList ) { - if (!pGrammarDsp && SvtLinguConfig().HasGrammarChecker()) + if (!mxGrammarDsp.is() && SvtLinguConfig().HasGrammarChecker()) { //! since the grammar checking iterator needs to be a one instance service //! we need to create it the correct way! @@ -976,11 +968,10 @@ void LngSvcMgr::GetGrammarCheckerDsp_Impl( bool bSetSvcList ) if (xGCI.is()) { - pGrammarDsp = dynamic_cast< GrammarCheckingIterator * >(xGCI.get()); - xGrammarDsp = xGCI; - SAL_WARN_IF( pGrammarDsp == nullptr, "linguistic", "failed to get implementation" ); - if (bSetSvcList && pGrammarDsp) - SetCfgServiceLists( *pGrammarDsp ); + mxGrammarDsp = dynamic_cast< GrammarCheckingIterator * >(xGCI.get()); + SAL_WARN_IF( mxGrammarDsp == nullptr, "linguistic", "failed to get implementation" ); + if (bSetSvcList && mxGrammarDsp.is()) + SetCfgServiceLists( *mxGrammarDsp ); } } } @@ -988,24 +979,22 @@ void LngSvcMgr::GetGrammarCheckerDsp_Impl( bool bSetSvcList ) void LngSvcMgr::GetHyphenatorDsp_Impl( bool bSetSvcList ) { - if (!pHyphDsp) + if (!mxHyphDsp.is()) { - pHyphDsp = new HyphenatorDispatcher( *this ); - xHyphDsp = pHyphDsp; + mxHyphDsp = new HyphenatorDispatcher( *this ); if (bSetSvcList) - SetCfgServiceLists( *pHyphDsp ); + SetCfgServiceLists( *mxHyphDsp ); } } void LngSvcMgr::GetThesaurusDsp_Impl( bool bSetSvcList ) { - if (!pThesDsp) + if (!mxThesDsp.is()) { - pThesDsp = new ThesaurusDispatcher; - xThesDsp = pThesDsp; + mxThesDsp = new ThesaurusDispatcher; if (bSetSvcList) - SetCfgServiceLists( *pThesDsp ); + SetCfgServiceLists( *mxThesDsp ); } } @@ -1429,9 +1418,9 @@ uno::Reference< linguistic2::XSpellChecker > SAL_CALL uno::Reference< linguistic2::XSpellChecker > xRes; if (!bDisposing) { - if (!xSpellDsp.is()) + if (!mxSpellDsp.is()) GetSpellCheckerDsp_Impl(); - xRes = xSpellDsp; + xRes = mxSpellDsp.get(); } return xRes; } @@ -1448,9 +1437,9 @@ uno::Reference< linguistic2::XHyphenator > SAL_CALL uno::Reference< linguistic2::XHyphenator > xRes; if (!bDisposing) { - if (!xHyphDsp.is()) + if (!mxHyphDsp.is()) GetHyphenatorDsp_Impl(); - xRes = xHyphDsp; + xRes = mxHyphDsp.get(); } return xRes; } @@ -1467,9 +1456,9 @@ uno::Reference< linguistic2::XThesaurus > SAL_CALL uno::Reference< linguistic2::XThesaurus > xRes; if (!bDisposing) { - if (!xThesDsp.is()) + if (!mxThesDsp.is()) GetThesaurusDsp_Impl(); - xRes = xThesDsp; + xRes = mxThesDsp.get(); } return xRes; } @@ -1485,9 +1474,9 @@ sal_Bool SAL_CALL bool bRes = false; if (!bDisposing && xListener.is()) { - if (!pListenerHelper) + if (!mxListenerHelper.is()) GetListenerHelper_Impl(); - bRes = pListenerHelper->AddLngSvcMgrListener( xListener ); + bRes = mxListenerHelper->AddLngSvcMgrListener( xListener ); } return bRes; } @@ -1503,10 +1492,10 @@ sal_Bool SAL_CALL bool bRes = false; if (!bDisposing && xListener.is()) { - DBG_ASSERT( pListenerHelper, "listener removed without being added" ); - if (!pListenerHelper) + DBG_ASSERT( mxListenerHelper.is(), "listener removed without being added" ); + if (!mxListenerHelper.is()) GetListenerHelper_Impl(); - bRes = pListenerHelper->RemoveLngSvcMgrListener( xListener ); + bRes = mxListenerHelper->RemoveLngSvcMgrListener( xListener ); } return bRes; } @@ -1642,62 +1631,62 @@ void SAL_CALL { if (rServiceName == SN_SPELLCHECKER) { - if (!xSpellDsp.is()) + if (!mxSpellDsp.is()) GetSpellCheckerDsp_Impl(); bool bChanged = !IsEqSvcList( rServiceImplNames, - pSpellDsp->GetServiceList( rLocale ) ); + mxSpellDsp->GetServiceList( rLocale ) ); if (bChanged) { - pSpellDsp->SetServiceList( rLocale, rServiceImplNames ); + mxSpellDsp->SetServiceList( rLocale, rServiceImplNames ); SaveCfgSvcs( SN_SPELLCHECKER ); - if (pListenerHelper && bChanged) - pListenerHelper->AddLngSvcEvt( + if (mxListenerHelper.is() && bChanged) + mxListenerHelper->AddLngSvcEvt( linguistic2::LinguServiceEventFlags::SPELL_CORRECT_WORDS_AGAIN | linguistic2::LinguServiceEventFlags::SPELL_WRONG_WORDS_AGAIN ); } } else if (rServiceName == SN_GRAMMARCHECKER) { - if (!xGrammarDsp.is()) + if (!mxGrammarDsp.is()) GetGrammarCheckerDsp_Impl(); bool bChanged = !IsEqSvcList( rServiceImplNames, - pGrammarDsp->GetServiceList( rLocale ) ); + mxGrammarDsp->GetServiceList( rLocale ) ); if (bChanged) { - pGrammarDsp->SetServiceList( rLocale, rServiceImplNames ); + mxGrammarDsp->SetServiceList( rLocale, rServiceImplNames ); SaveCfgSvcs( SN_GRAMMARCHECKER ); - if (pListenerHelper && bChanged) - pListenerHelper->AddLngSvcEvt( + if (mxListenerHelper.is() && bChanged) + mxListenerHelper->AddLngSvcEvt( linguistic2::LinguServiceEventFlags::PROOFREAD_AGAIN ); } } else if (rServiceName == SN_HYPHENATOR) { - if (!xHyphDsp.is()) + if (!mxHyphDsp.is()) GetHyphenatorDsp_Impl(); bool bChanged = !IsEqSvcList( rServiceImplNames, - pHyphDsp->GetServiceList( rLocale ) ); + mxHyphDsp->GetServiceList( rLocale ) ); if (bChanged) { - pHyphDsp->SetServiceList( rLocale, rServiceImplNames ); + mxHyphDsp->SetServiceList( rLocale, rServiceImplNames ); SaveCfgSvcs( SN_HYPHENATOR ); - if (pListenerHelper && bChanged) - pListenerHelper->AddLngSvcEvt( + if (mxListenerHelper.is() && bChanged) + mxListenerHelper->AddLngSvcEvt( linguistic2::LinguServiceEventFlags::HYPHENATE_AGAIN ); } } else if (rServiceName == SN_THESAURUS) { - if (!xThesDsp.is()) + if (!mxThesDsp.is()) GetThesaurusDsp_Impl(); bool bChanged = !IsEqSvcList( rServiceImplNames, - pThesDsp->GetServiceList( rLocale ) ); + mxThesDsp->GetServiceList( rLocale ) ); if (bChanged) { - pThesDsp->SetServiceList( rLocale, rServiceImplNames ); + mxThesDsp->SetServiceList( rLocale, rServiceImplNames ); SaveCfgSvcs( SN_THESAURUS ); } } @@ -1716,30 +1705,30 @@ bool LngSvcMgr::SaveCfgSvcs( const OUString &rServiceName ) if (rServiceName == SN_SPELLCHECKER) { - if (!pSpellDsp) + if (!mxSpellDsp.get()) GetSpellCheckerDsp_Impl(); - pDsp = pSpellDsp; + pDsp = mxSpellDsp.get(); aLocales = getAvailableLocales( SN_SPELLCHECKER ); } else if (rServiceName == SN_GRAMMARCHECKER) { - if (!pGrammarDsp) + if (!mxGrammarDsp.is()) GetGrammarCheckerDsp_Impl(); - pDsp = pGrammarDsp; + pDsp = mxGrammarDsp.get(); aLocales = getAvailableLocales( SN_GRAMMARCHECKER ); } else if (rServiceName == SN_HYPHENATOR) { - if (!pHyphDsp) + if (!mxHyphDsp.is()) GetHyphenatorDsp_Impl(); - pDsp = pHyphDsp; + pDsp = mxHyphDsp.get(); aLocales = getAvailableLocales( SN_HYPHENATOR ); } else if (rServiceName == SN_THESAURUS) { - if (!pThesDsp) + if (!mxThesDsp.is()) GetThesaurusDsp_Impl(); - pDsp = pThesDsp; + pDsp = mxThesDsp.get(); aLocales = getAvailableLocales( SN_THESAURUS ); } @@ -1754,13 +1743,13 @@ bool LngSvcMgr::SaveCfgSvcs( const OUString &rServiceName ) // get node name to be used const char *pNodeName = nullptr; - if (pDsp == pSpellDsp) + if (pDsp == mxSpellDsp.get()) pNodeName = "ServiceManager/SpellCheckerList"; - else if (pDsp == pGrammarDsp) + else if (pDsp == mxGrammarDsp.get()) pNodeName = "ServiceManager/GrammarCheckerList"; - else if (pDsp == pHyphDsp) + else if (pDsp == mxHyphDsp.get()) pNodeName = "ServiceManager/HyphenatorList"; - else if (pDsp == pThesDsp) + else if (pDsp == mxThesDsp.get()) pNodeName = "ServiceManager/ThesaurusList"; else { @@ -1775,7 +1764,7 @@ bool LngSvcMgr::SaveCfgSvcs( const OUString &rServiceName ) // build value to be written back to configuration uno::Any aCfgAny; - if ((pDsp == pHyphDsp || pDsp == pGrammarDsp) && aSvcImplNames.getLength() > 1) + if ((pDsp == mxHyphDsp.get() || pDsp == mxGrammarDsp.get()) && aSvcImplNames.getLength() > 1) aSvcImplNames.realloc(1); // there should be only one entry for hyphenators or grammar checkers (because they are not chained) aCfgAny <<= aSvcImplNames; DBG_ASSERT( aCfgAny.hasValue(), "missing value for 'Any' type" ); @@ -1936,8 +1925,8 @@ void SAL_CALL lang::EventObject aEvtObj( static_cast(this) ); aEvtListeners.disposeAndClear( aEvtObj ); - if (pListenerHelper) - pListenerHelper->DisposeAndClear( aEvtObj ); + if (mxListenerHelper.is()) + mxListenerHelper->DisposeAndClear( aEvtObj ); } } @@ -1976,9 +1965,9 @@ bool LngSvcMgr::AddLngSvcEvtBroadcaster( bool bRes = false; if (rxBroadcaster.is()) { - if (!pListenerHelper) + if (!mxListenerHelper.is()) GetListenerHelper_Impl(); - bRes = pListenerHelper->AddLngSvcEvtBroadcaster( rxBroadcaster ); + bRes = mxListenerHelper->AddLngSvcEvtBroadcaster( rxBroadcaster ); } return bRes; } diff --git a/linguistic/source/lngsvcmgr.hxx b/linguistic/source/lngsvcmgr.hxx index 493e6dd0fd72..348ca0905a0e 100644 --- a/linguistic/source/lngsvcmgr.hxx +++ b/linguistic/source/lngsvcmgr.hxx @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -65,19 +66,7 @@ class LngSvcMgr : { friend class LngSvcMgrListenerHelper; - ::comphelper::OInterfaceContainerHelper2 aEvtListeners; - - css::uno::Reference< - css::linguistic2::XSpellChecker > xSpellDsp; - css::uno::Reference< - css::linguistic2::XProofreadingIterator > xGrammarDsp; - css::uno::Reference< - css::linguistic2::XHyphenator > xHyphDsp; - css::uno::Reference< - css::linguistic2::XThesaurus > xThesDsp; - - css::uno::Reference< - css::lang::XEventListener > xListenerHelper; + ::comphelper::OInterfaceContainerHelper2 aEvtListeners; css::uno::Reference< css::util::XModifyBroadcaster> xMB; @@ -94,12 +83,12 @@ class LngSvcMgr : css::uno::Sequence< css::lang::Locale > aAvailThesLocales; - SpellCheckerDispatcher * pSpellDsp; - GrammarCheckingIterator * pGrammarDsp; - HyphenatorDispatcher * pHyphDsp; - ThesaurusDispatcher * pThesDsp; + rtl::Reference mxSpellDsp; + rtl::Reference mxGrammarDsp; + rtl::Reference mxHyphDsp; + rtl::Reference mxThesDsp; - LngSvcMgrListenerHelper * pListenerHelper; + rtl::Reference mxListenerHelper; typedef std::vector< std::unique_ptr > SvcInfoArray; SvcInfoArray * pAvailSpellSvcs; -- cgit