27#include <unordered_map>
31#include <osl/doublecheckedlocking.h>
32#include <osl/getglobalmutex.hxx>
68 ::std::vector<Link<MasterPageObserverEvent&,void>>
maListeners;
72 {
return reinterpret_cast<sal_uIntPtr
>(
argument); }
97 ::std::unique_ptr<SdGlobalResource>(pInstance));
105 mpImpl->RegisterDocument (rDocument);
110 mpImpl->UnregisterDocument (rDocument);
116 mpImpl->AddEventListener (rEventListener);
121 mpImpl->RemoveEventListener (rEventListener);
137 MasterPageContainer::mapped_type aMasterPageSet;
142 if (pMasterPage !=
nullptr)
143 aMasterPageSet.insert (pMasterPage->
GetName());
156 EndListening (rDocument);
158 MasterPageContainer::iterator aMasterPageDescriptor(maUsedMasterPages.find(&rDocument));
159 if(aMasterPageDescriptor != maUsedMasterPages.end())
160 maUsedMasterPages.erase(aMasterPageDescriptor);
169 rEventListener) != maListeners.end())
172 maListeners.push_back (rEventListener);
176 for (
const auto& rDocument : maUsedMasterPages)
178 ::std::set<OUString>::reverse_iterator aNameIterator;
179 for (aNameIterator=rDocument.second.rbegin();
180 aNameIterator!=rDocument.second.rend();
205 if (rHint.
GetId() != SfxHintId::ThisIsAnSdrHint)
211 case SdrHintKind::PageOrderChange:
217 if (
auto pDrawDocument =
dynamic_cast<SdDrawDocument *
>( &rBroadcaster ))
222 AnalyzeUsedMasterPages (*pDrawDocument);
237 ::std::set<OUString> aCurrentMasterPages;
241 if (pMasterPage !=
nullptr)
242 aCurrentMasterPages.insert (pMasterPage->
GetName());
245 std::vector<OUString> aNewMasterPages;
246 std::vector<OUString> aRemovedMasterPages;
247 MasterPageContainer::iterator aOldMasterPagesDescriptor (
248 maUsedMasterPages.find(&rDocument));
249 if (aOldMasterPagesDescriptor == maUsedMasterPages.end())
253 ::std::set_difference (
254 aCurrentMasterPages.begin(),
255 aCurrentMasterPages.end(),
256 aOldMasterPagesDescriptor->second.begin(),
257 aOldMasterPagesDescriptor->second.end(),
258 std::back_inserter(aNewMasterPages));
259 for (
const auto& aNewMasterPage : aNewMasterPages)
268 ::std::set_difference (
269 aOldMasterPagesDescriptor->second.begin(),
270 aOldMasterPagesDescriptor->second.end(),
271 aCurrentMasterPages.begin(),
272 aCurrentMasterPages.end(),
273 std::back_inserter(aRemovedMasterPages));
274 for (
const auto& aRemovedMasterPage : aRemovedMasterPages)
283 aOldMasterPagesDescriptor->second = aCurrentMasterPages;
289 for (
const auto& aLink : maListeners)
::boost::spirit::classic::rule< ScannerT > argument
sal_uInt16 GetMasterSdPageCount(PageKind ePgKind) const
SdPage * GetMasterSdPage(sal_uInt16 nPgNum, PageKind ePgKind)
const OUString & GetName() const
SdrHintKind GetKind() const
void StartListening(SfxBroadcaster &rBroadcaster, DuplicateHandling eDuplicateHanding=DuplicateHandling::Unexpected)
Objects of this class are sent to listeners of the MasterPageObserver singleton when the list of mast...
@ ET_MASTER_PAGE_EXISTS
Master page already exists when document is registered.
@ ET_MASTER_PAGE_ADDED
Master page has been added to a document.
@ ET_MASTER_PAGE_REMOVED
Master page has been removed from to a document.
void SendEvent(MasterPageObserverEvent &rEvent)
std::unordered_map< SdDrawDocument *, MasterPageObserver::MasterPageNameSet, DrawDocHash > MasterPageContainer
virtual void Notify(SfxBroadcaster &rBroadcaster, const SfxHint &rHint) override
void RemoveEventListener(const Link< MasterPageObserverEvent &, void > &rEventListener)
Remove the given listener from the list of listeners.
void UnregisterDocument(SdDrawDocument &rDocument)
The master page observer will stop to listen to events of this document.
void AnalyzeUsedMasterPages(SdDrawDocument &rDocument)
void AddEventListener(const Link< MasterPageObserverEvent &, void > &rEventListener)
Add a listener that is informed of master pages that are newly assigned to slides or become unassigne...
::std::vector< Link< MasterPageObserverEvent &, void > > maListeners
MasterPageContainer maUsedMasterPages
void RegisterDocument(SdDrawDocument &rDocument)
The master page observer will listen to events of this document and detect changes of the use of mast...
This singleton observes all registered documents for changes in the used master pages and in turn inf...
::std::unique_ptr< Implementation > mpImpl
void UnregisterDocument(SdDrawDocument &rDocument)
The master page observer will stop to listen to events of this document.
::std::set< OUString > MasterPageNameSet
void AddEventListener(const Link< MasterPageObserverEvent &, void > &rEventListener)
Add a listener that is informed of master pages that are newly assigned to slides or become unassigne...
static MasterPageObserver & Instance()
Return the single instance of this class.
virtual ~MasterPageObserver() override
void RemoveEventListener(const Link< MasterPageObserverEvent &, void > &rEventListener)
Remove the given listener from the list of listeners.
void RegisterDocument(SdDrawDocument &rDocument)
The master page observer will listen to events of this document and detect changes of the use of mast...
void AddResource(::std::unique_ptr< SdGlobalResource > pResource)
Add a resource to the container.
static SdGlobalResourceContainer & Instance()
size_t operator()(SdDrawDocument *argument) const