diff options
23 files changed, 54 insertions, 44 deletions
diff --git a/accessibility/source/extended/textwindowaccessibility.cxx b/accessibility/source/extended/textwindowaccessibility.cxx index 24433d0505bc..50b472d66371 100644 --- a/accessibility/source/extended/textwindowaccessibility.cxx +++ b/accessibility/source/extended/textwindowaccessibility.cxx @@ -38,7 +38,7 @@ void SfxListenerGuard::startListening(::SfxBroadcaster & rNotifier) { assert(m_pNotifier == nullptr && "called more than once"); m_pNotifier = &rNotifier; - m_rListener.StartListening(*m_pNotifier, true); + m_rListener.StartListening(*m_pNotifier, DuplicateHandling::Prevent); } void SfxListenerGuard::endListening() diff --git a/basctl/source/basicide/basides1.cxx b/basctl/source/basicide/basides1.cxx index 4c3f3dabffe5..c79557501913 100644 --- a/basctl/source/basicide/basides1.cxx +++ b/basctl/source/basicide/basides1.cxx @@ -282,7 +282,7 @@ void Shell::ExecuteGlobal( SfxRequest& rReq ) ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) ); - StartListening( *pBasMgr, true /* log on only once */ ); + StartListening(*pBasMgr, DuplicateHandling::Prevent /* log on only once */); OUString aLibName( rInfo.GetLib() ); if ( aLibName.isEmpty() ) aLibName = "Standard" ; @@ -1229,7 +1229,7 @@ VclPtr<ModulWindow> Shell::ShowActiveModuleWindow( StarBASIC const * pBasic ) else SAL_WARN( "basctl.basicide", "No BASIC!"); if (BasicManager* pBasicMgr = FindBasicManager(pBasic)) - StartListening( *pBasicMgr, true /* log on only once */ ); + StartListening(*pBasicMgr, DuplicateHandling::Prevent /* log on only once */); return pWin; } return nullptr; diff --git a/basctl/source/basicide/basidesh.cxx b/basctl/source/basicide/basidesh.cxx index 8c5518d17160..ad39f4c84b70 100644 --- a/basctl/source/basicide/basidesh.cxx +++ b/basctl/source/basicide/basidesh.cxx @@ -633,7 +633,7 @@ void Shell::UpdateWindows() ++doc ) { - StartListening( *doc->getBasicManager(), true /* log on only once */ ); + StartListening(*doc->getBasicManager(), DuplicateHandling::Prevent /* log on only once */); // libraries Sequence< OUString > aLibNames( doc->getLibraryNames() ); @@ -669,7 +669,7 @@ void Shell::UpdateWindows() { StarBASIC* pLib = doc->getBasicManager()->GetLib( aLibName ); if ( pLib ) - StartListening( pLib->GetBroadcaster(), true /* log on only once */ ); + StartListening(pLib->GetBroadcaster(), DuplicateHandling::Prevent /* log on only once */); try { diff --git a/basic/source/classes/sb.cxx b/basic/source/classes/sb.cxx index 524b392a6e98..132ea5d49415 100644 --- a/basic/source/classes/sb.cxx +++ b/basic/source/classes/sb.cxx @@ -657,7 +657,7 @@ SbClassModuleObject::SbClassModuleObject( SbModule* pClassModule ) pNewMethod->pMod = this; pNewMethod->SetParent( this ); pMethods->PutDirect( pNewMethod, i ); - StartListening( pNewMethod->GetBroadcaster(), true ); + StartListening(pNewMethod->GetBroadcaster(), DuplicateHandling::Prevent); } } } @@ -709,7 +709,7 @@ SbClassModuleObject::SbClassModuleObject( SbModule* pClassModule ) pNewProp->ResetFlag( SbxFlagBits::NoBroadcast ); // except the Broadcast if it was set pProcedureProp->SetFlags( nFlags_ ); pProps->PutDirect( pNewProp, i ); - StartListening( pNewProp->GetBroadcaster(), true ); + StartListening(pNewProp->GetBroadcaster(), DuplicateHandling::Prevent); } else { @@ -1068,7 +1068,7 @@ void StarBASIC::Insert( SbxVariable* pVar ) { pModules.emplace_back(static_cast<SbModule*>(pVar)); pVar->SetParent( this ); - StartListening( pVar->GetBroadcaster(), true ); + StartListening(pVar->GetBroadcaster(), DuplicateHandling::Prevent); } else { diff --git a/basic/source/classes/sbxmod.cxx b/basic/source/classes/sbxmod.cxx index 97fe73dbface..8c2edf1c8912 100644 --- a/basic/source/classes/sbxmod.cxx +++ b/basic/source/classes/sbxmod.cxx @@ -534,7 +534,7 @@ SbMethod* SbModule::GetMethod( const OUString& rName, SbxDataType t ) pMeth->SetParent( this ); pMeth->SetFlags( SbxFlagBits::Read ); pMethods->Put( pMeth, pMethods->Count() ); - StartListening( pMeth->GetBroadcaster(), true ); + StartListening(pMeth->GetBroadcaster(), DuplicateHandling::Prevent); } // The method is per default valid, because it could be // created from the compiler (code generator) as well. @@ -572,7 +572,7 @@ SbProperty* SbModule::GetProperty( const OUString& rName, SbxDataType t ) pProp->SetFlag( SbxFlagBits::ReadWrite ); pProp->SetParent( this ); pProps->Put( pProp, pProps->Count() ); - StartListening( pProp->GetBroadcaster(), true ); + StartListening(pProp->GetBroadcaster(), DuplicateHandling::Prevent); } return pProp; } @@ -591,7 +591,7 @@ void SbModule::GetProcedureProperty( const OUString& rName, SbxDataType t ) pProp->SetFlag( SbxFlagBits::ReadWrite ); pProp->SetParent( this ); pProps->Put( pProp, pProps->Count() ); - StartListening( pProp->GetBroadcaster(), true ); + StartListening(pProp->GetBroadcaster(), DuplicateHandling::Prevent); } } diff --git a/basic/source/sbx/sbxcoll.cxx b/basic/source/sbx/sbxcoll.cxx index c6a3d956a914..a4175c310318 100644 --- a/basic/source/sbx/sbxcoll.cxx +++ b/basic/source/sbx/sbxcoll.cxx @@ -47,7 +47,7 @@ SbxCollection::SbxCollection() } Initialize(); // For Access on itself - StartListening( GetBroadcaster(), true ); + StartListening(GetBroadcaster(), DuplicateHandling::Prevent); } SbxCollection::SbxCollection( const SbxCollection& rColl ) diff --git a/basic/source/sbx/sbxobj.cxx b/basic/source/sbx/sbxobj.cxx index e241b53c0387..54eedd360bda 100644 --- a/basic/source/sbx/sbxobj.cxx +++ b/basic/source/sbx/sbxobj.cxx @@ -413,7 +413,7 @@ SbxVariable* SbxObject::Make( const OUString& rName, SbxClassType ct, SbxDataTyp pArray->Put( pVar, pArray->Count() ); SetModified( true ); // The object listen always - StartListening( pVar->GetBroadcaster(), true ); + StartListening(pVar->GetBroadcaster(), DuplicateHandling::Prevent); return pVar; } @@ -450,7 +450,7 @@ void SbxObject::Insert( SbxVariable* pVar ) } } } - StartListening( pVar->GetBroadcaster(), true ); + StartListening(pVar->GetBroadcaster(), DuplicateHandling::Prevent); pArray->Put( pVar, nIdx ); if( pVar->GetParent() != this ) { @@ -494,7 +494,7 @@ void SbxObject::QuickInsert( SbxVariable* pVar ) } if( pArray ) { - StartListening( pVar->GetBroadcaster(), true ); + StartListening(pVar->GetBroadcaster(), DuplicateHandling::Prevent); pArray->Put( pVar, pArray->Count() ); if( pVar->GetParent() != this ) { @@ -573,7 +573,7 @@ static bool LoadArray( SvStream& rStrm, SbxObject* pThis, SbxArray* pArray ) if( pVar ) { pVar->SetParent( pThis ); - pThis->StartListening( pVar->GetBroadcaster(), true ); + pThis->StartListening(pVar->GetBroadcaster(), DuplicateHandling::Prevent); } } pArray->Merge( p.get() ); diff --git a/editeng/source/editeng/impedit5.cxx b/editeng/source/editeng/impedit5.cxx index 753d26678007..f826e9077062 100644 --- a/editeng/source/editeng/impedit5.cxx +++ b/editeng/source/editeng/impedit5.cxx @@ -92,7 +92,7 @@ void ImpEditEngine::SetStyleSheet( sal_Int32 nPara, SfxStyleSheet* pStyle ) EndListening( *pCurStyle ); pNode->SetStyleSheet( pStyle, aStatus.UseCharAttribs() ); if ( pStyle ) - StartListening( *pStyle, true ); + StartListening(*pStyle, DuplicateHandling::Prevent); ParaAttribsChanged( pNode ); } FormatAndUpdate(); diff --git a/include/svl/lstner.hxx b/include/svl/lstner.hxx index ad79698728cb..c9a807fa8d13 100644 --- a/include/svl/lstner.hxx +++ b/include/svl/lstner.hxx @@ -25,6 +25,16 @@ class SfxBroadcaster; class SfxHint; +//StartListening duplicate handling options +//Prevent only adds the listener if its not already added +//Allow allows duplicate listeners +//Unexpected, the default, is for the usual case where the +//listener should only be added once and duplicates are +//unexpected. In dbgutil mode this tracks where the original +//listener was added from and reports the duplicate addition +//as an error +enum class DuplicateHandling { Unexpected, Prevent, Allow }; + class SVL_DLLPUBLIC SfxListener { struct Impl; @@ -39,7 +49,7 @@ public: SfxListener( const SfxListener &rCopy ); virtual ~SfxListener() COVERITY_NOEXCEPT_FALSE; - void StartListening( SfxBroadcaster& rBroadcaster, bool bPreventDuplicates = false ); + void StartListening(SfxBroadcaster& rBroadcaster, DuplicateHandling eDuplicateHanding = DuplicateHandling::Unexpected); void EndListening( SfxBroadcaster& rBroadcaster, bool bRemoveAllDuplicates = false ); void EndListeningAll(); bool IsListening( SfxBroadcaster& rBroadcaster ) const; diff --git a/sc/source/ui/Accessibility/AccessibleDocument.cxx b/sc/source/ui/Accessibility/AccessibleDocument.cxx index 1e8c71967deb..5e8eac4c4a4c 100644 --- a/sc/source/ui/Accessibility/AccessibleDocument.cxx +++ b/sc/source/ui/Accessibility/AccessibleDocument.cxx @@ -392,7 +392,7 @@ void ScChildrenShapes::SetDrawBroadcaster() SfxBroadcaster* pDrawBC = rViewData.GetDocument()->GetDrawBroadcaster(); if (pDrawBC) { - StartListening(*pDrawBC, true); + StartListening(*pDrawBC, DuplicateHandling::Prevent); maShapeTreeInfo.SetModelBroadcaster( new ScDrawModelBroadcaster(rViewData.GetDocument()->GetDrawLayer()) ); maShapeTreeInfo.SetSdrView(rViewData.GetScDrawView()); diff --git a/sc/source/ui/Accessibility/AccessibleDocumentPagePreview.cxx b/sc/source/ui/Accessibility/AccessibleDocumentPagePreview.cxx index e5bb6a38389a..b9f0d3188209 100644 --- a/sc/source/ui/Accessibility/AccessibleDocumentPagePreview.cxx +++ b/sc/source/ui/Accessibility/AccessibleDocumentPagePreview.cxx @@ -681,7 +681,7 @@ void ScShapeChildren::SetDrawBroadcaster() { SfxBroadcaster* pDrawBC = mpViewShell->GetDocument().GetDrawBroadcaster(); if (pDrawBC) - StartListening(*pDrawBC, true); + StartListening(*pDrawBC, DuplicateHandling::Prevent); } } diff --git a/sc/source/ui/condformat/condformatdlgentry.cxx b/sc/source/ui/condformat/condformatdlgentry.cxx index 00b3937373bc..ede6a4ead202 100644 --- a/sc/source/ui/condformat/condformatdlgentry.cxx +++ b/sc/source/ui/condformat/condformatdlgentry.cxx @@ -207,7 +207,7 @@ ScConditionFrmtEntry::ScConditionFrmtEntry(vcl::Window* pParent, ScDocument* pDo Init(pDialogParent); - StartListening(*pDoc->GetStyleSheetPool(), true); + StartListening(*pDoc->GetStyleSheetPool(), DuplicateHandling::Prevent); if(pFormatEntry) { @@ -1230,7 +1230,7 @@ ScDateFrmtEntry::ScDateFrmtEntry(vcl::Window* pParent, ScDocument* pDoc, const S Init(); - StartListening(*pDoc->GetStyleSheetPool(), true); + StartListening(*pDoc->GetStyleSheetPool(), DuplicateHandling::Prevent); if(pFormat) { diff --git a/sc/source/ui/view/prevwsh.cxx b/sc/source/ui/view/prevwsh.cxx index c94ed163ce5d..eedfa3d50821 100644 --- a/sc/source/ui/view/prevwsh.cxx +++ b/sc/source/ui/view/prevwsh.cxx @@ -134,8 +134,8 @@ void ScPreviewShell::Construct( vcl::Window* pParent ) SetPool( &SC_MOD()->GetPool() ); SetWindow( pPreview ); - StartListening(*pDocShell,true); - StartListening(*SfxGetpApp(),true); // #i62045# #i62046# application is needed for Calc's own hints + StartListening(*pDocShell, DuplicateHandling::Prevent); + StartListening(*SfxGetpApp(), DuplicateHandling::Prevent); // #i62045# #i62046# application is needed for Calc's own hints SfxBroadcaster* pDrawBC = pDocShell->GetDocument().GetDrawBroadcaster(); if (pDrawBC) StartListening(*pDrawBC); diff --git a/sc/source/ui/view/tabvwsh4.cxx b/sc/source/ui/view/tabvwsh4.cxx index c01208394702..fe203ae346d8 100644 --- a/sc/source/ui/view/tabvwsh4.cxx +++ b/sc/source/ui/view/tabvwsh4.cxx @@ -1451,9 +1451,9 @@ void ScTabViewShell::Construct( TriState nForceDesignMode ) pCurFrameLine = new ::editeng::SvxBorderLine(&aColBlack, 20, SvxBorderLineStyle::SOLID); pPivotSource = new ScArea; - StartListening(*GetViewData().GetDocShell(),true); - StartListening(*GetViewFrame(),true); - StartListening(*pSfxApp,true); // #i62045# #i62046# application is needed for Calc's own hints + StartListening(*GetViewData().GetDocShell(), DuplicateHandling::Prevent); + StartListening(*GetViewFrame(), DuplicateHandling::Prevent); + StartListening(*pSfxApp, DuplicateHandling::Prevent); // #i62045# #i62046# application is needed for Calc's own hints SfxViewFrame* pFirst = SfxViewFrame::GetFirst(pDocSh); bool bFirstView = !pFirst diff --git a/sd/source/ui/view/ViewShellBase.cxx b/sd/source/ui/view/ViewShellBase.cxx index 2ba60d39bd29..12ac6a0d72e8 100644 --- a/sd/source/ui/view/ViewShellBase.cxx +++ b/sd/source/ui/view/ViewShellBase.cxx @@ -298,8 +298,8 @@ ViewShellBase::~ViewShellBase() void ViewShellBase::LateInit (const OUString& rsDefaultView) { - StartListening(*GetViewFrame(),true); - StartListening(*GetDocShell(),true); + StartListening(*GetViewFrame(), DuplicateHandling::Prevent); + StartListening(*GetDocShell(), DuplicateHandling::Prevent); mpImpl->LateInit(); InitializeFramework(); diff --git a/svl/qa/unit/notify/test_SfxBroadcaster.cxx b/svl/qa/unit/notify/test_SfxBroadcaster.cxx index d7b127c4c1ef..f0bd409cd969 100644 --- a/svl/qa/unit/notify/test_SfxBroadcaster.cxx +++ b/svl/qa/unit/notify/test_SfxBroadcaster.cxx @@ -62,7 +62,7 @@ SfxBroadcasterTest::AddingListenersIncreasesCount() CPPUNIT_ASSERT_EQUAL(size_t(0), sb.GetListenerCount()); - sl.StartListening(sb, true); + sl.StartListening(sb, DuplicateHandling::Prevent); CPPUNIT_ASSERT_EQUAL(size_t(1), sb.GetListenerCount()); } @@ -73,7 +73,7 @@ SfxBroadcasterTest::RemovingListenersDecreasesCount() MockedSfxListener sl; CPPUNIT_ASSERT_EQUAL(size_t(0), sb.GetListenerCount()); - sl.StartListening(sb, true); + sl.StartListening(sb, DuplicateHandling::Prevent); CPPUNIT_ASSERT_EQUAL(size_t(1), sb.GetListenerCount()); sl.EndListening(sb, true); CPPUNIT_ASSERT_EQUAL(size_t(0), sb.GetListenerCount()); @@ -87,8 +87,8 @@ SfxBroadcasterTest::HintsAreNotForwardedToRemovedListeners() MockedSfxListener sl2; SfxHint hint; - sl1.StartListening(sb, true); - sl2.StartListening(sb, true); + sl1.StartListening(sb, DuplicateHandling::Prevent); + sl2.StartListening(sb, DuplicateHandling::Prevent); CPPUNIT_ASSERT_EQUAL_MESSAGE("All listeners were added.", size_t(2), sb.GetListenerCount()); sl1.EndListening(sb, true); sb.Forward(sb, hint); diff --git a/svl/source/notify/lstner.cxx b/svl/source/notify/lstner.cxx index 9c79da9e5185..5be1e2bdffdf 100644 --- a/svl/source/notify/lstner.cxx +++ b/svl/source/notify/lstner.cxx @@ -88,20 +88,20 @@ void SfxListener::RemoveBroadcaster_Impl( SfxBroadcaster& rBroadcaster ) Some code uses duplicates as a kind of ref-counting thing i.e. they add and remove listeners on different code paths, and they only really stop listening when the last EndListening() is called. */ -void SfxListener::StartListening( SfxBroadcaster& rBroadcaster, bool bPreventDuplicates ) +void SfxListener::StartListening(SfxBroadcaster& rBroadcaster, DuplicateHandling eDuplicateHanding) { bool bListeningAlready = IsListening( rBroadcaster ); #ifdef DBG_UTIL - if (bListeningAlready && !bPreventDuplicates) + if (bListeningAlready && eDuplicateHanding == DuplicateHandling::Unexpected) { auto f = mpImpl->maCallStacks.find( &rBroadcaster ); SAL_WARN("svl", "previous StartListening call came from: " << sal::backtrace_to_string(f->second.get())); } #endif - assert(!(bListeningAlready && !bPreventDuplicates) && "duplicate listener, try building with DBG_UTIL to find the other insert site."); + assert(!(bListeningAlready && eDuplicateHanding == DuplicateHandling::Unexpected) && "duplicate listener, try building with DBG_UTIL to find the other insert site."); - if ( !bListeningAlready || !bPreventDuplicates ) + if (!bListeningAlready || eDuplicateHanding != DuplicateHandling::Prevent) { rBroadcaster.AddListener(*this); mpImpl->maBCs.push_back( &rBroadcaster ); diff --git a/svx/source/gallery2/gallery1.cxx b/svx/source/gallery2/gallery1.cxx index 3d3107296a9b..2245a7f6ed7e 100644 --- a/svx/source/gallery2/gallery1.cxx +++ b/svx/source/gallery2/gallery1.cxx @@ -756,7 +756,7 @@ GalleryTheme* Gallery::AcquireTheme( const OUString& rThemeName, SfxListener& rL GalleryThemeEntry* pThemeEntry = ImplGetThemeEntry( rThemeName ); if( pThemeEntry && ( ( pTheme = ImplGetCachedTheme( pThemeEntry ) ) != nullptr ) ) - rListener.StartListening( *pTheme, true ); + rListener.StartListening(*pTheme, DuplicateHandling::Prevent); return pTheme; } diff --git a/svx/source/svdraw/svdobj.cxx b/svx/source/svdraw/svdobj.cxx index 2512c4571d0f..bcbd47923633 100644 --- a/svx/source/svdraw/svdobj.cxx +++ b/svx/source/svdraw/svdobj.cxx @@ -590,7 +590,7 @@ void SdrObject::AddListener(SfxListener& rListener) // SdrEdgeObj may be connected to same SdrObject on both ends so allow it // to listen twice SdrEdgeObj const*const pEdge(dynamic_cast<SdrEdgeObj const*>(&rListener)); - rListener.StartListening(*pPlusData->pBroadcast, pEdge != nullptr); + rListener.StartListening(*pPlusData->pBroadcast, pEdge ? DuplicateHandling::Allow : DuplicateHandling::Unexpected); } void SdrObject::RemoveListener(SfxListener& rListener) diff --git a/svx/source/svdraw/svdotxat.cxx b/svx/source/svdraw/svdotxat.cxx index 7d92683764d0..f8c4f2105276 100644 --- a/svx/source/svdraw/svdotxat.cxx +++ b/svx/source/svdraw/svdotxat.cxx @@ -383,7 +383,7 @@ void SdrTextObj::ImpSetTextStyleSheetListeners() for(std::set<SfxStyleSheet*>::const_iterator it = aStyleSheets.begin(); it != aStyleSheets.end(); ++it) { SfxStyleSheet* pStyle=*it; // let StartListening see for itself if there's already a listener registered - StartListening(*pStyle,true); + StartListening(*pStyle, DuplicateHandling::Prevent); } } } diff --git a/svx/source/tbxctrls/colrctrl.cxx b/svx/source/tbxctrls/colrctrl.cxx index d77fa2c729c9..46e82045ace1 100644 --- a/svx/source/tbxctrls/colrctrl.cxx +++ b/svx/source/tbxctrls/colrctrl.cxx @@ -230,7 +230,7 @@ SvxColorDockingWindow::SvxColorDockingWindow SetSize(); aColorSet->Show(); if (_pBindings != nullptr) - StartListening( *_pBindings, true ); + StartListening(*_pBindings, DuplicateHandling::Prevent); } SvxColorDockingWindow::~SvxColorDockingWindow() diff --git a/sw/source/uibase/uiview/srcview.cxx b/sw/source/uibase/uiview/srcview.cxx index 84593117acce..746dd72fb49b 100644 --- a/sw/source/uibase/uiview/srcview.cxx +++ b/sw/source/uibase/uiview/srcview.cxx @@ -262,7 +262,7 @@ void SwSrcView::Init() } SetNewWindowAllowed( false ); - StartListening(*pDocShell,true); + StartListening(*pDocShell, DuplicateHandling::Prevent); } SwDocShell* SwSrcView::GetDocShell() diff --git a/sw/source/uibase/uiview/view.cxx b/sw/source/uibase/uiview/view.cxx index 556d3a9ce44a..494949dbe62a 100644 --- a/sw/source/uibase/uiview/view.cxx +++ b/sw/source/uibase/uiview/view.cxx @@ -866,8 +866,8 @@ SwView::SwView( SfxViewFrame *_pFrame, SfxViewShell* pOldSh ) SfxViewFrame* pViewFrame = GetViewFrame(); - StartListening(*pViewFrame, true); - StartListening(rDocSh, true); + StartListening(*pViewFrame, DuplicateHandling::Prevent); + StartListening(rDocSh, DuplicateHandling::Prevent); // Set Zoom-factor from HRuler Fraction aZoomFract( aUsrPref.GetZoom(), 100 ); |