class MasterPageObserver::Implementation
: public SfxListener
{ public: /** The master page observer will listen to events of this document and detectchangesoftheuseofmasterpages.
*/ void RegisterDocument (SdDrawDocument& rDocument);
/** The master page observer will stop to listen to events of this document.
*/ void UnregisterDocument (SdDrawDocument& rDocument);
/** Add a listener that is informed of master pages that are newly assignedtoslidesorbecomeunassigned. @paramrEventListener Theeventlistenertocallforfutureevents.Call RemoveEventListener()beforethelistenerisdestroyed.
*/ void AddEventListener (const Link<MasterPageObserverEvent&,void>& rEventListener);
/** Remove the given listener from the list of listeners. @paramrEventListener Afterthismethodreturnsthegivenlistenerisnotcalledback fromthisobject.Passingalistenerthathasnot beenregisteredbeforeissafeandissilentlyignored.
*/ void RemoveEventListener (const Link<MasterPageObserverEvent&,void>& rEventListener);
void MasterPageObserver::Implementation::RegisterDocument (
SdDrawDocument& rDocument)
{ // Gather the names of all the master pages in the given document.
MasterPageContainer::mapped_type aMasterPageSet;
sal_uInt16 nMasterPageCount = rDocument.GetMasterSdPageCount(PageKind::Standard); for (sal_uInt16 nIndex=0; nIndex<nMasterPageCount; nIndex++)
{
SdPage* pMasterPage = rDocument.GetMasterSdPage (nIndex, PageKind::Standard); if (pMasterPage != nullptr)
aMasterPageSet.insert (pMasterPage->GetName());
}
// Tell the new listener about all the master pages that are // currently in use. for (constauto& rDocument : maUsedMasterPages)
{
::std::set<OUString>::reverse_iterator aNameIterator; for (aNameIterator=rDocument.second.rbegin();
aNameIterator!=rDocument.second.rend();
++aNameIterator)
{
MasterPageObserverEvent aEvent (
MasterPageObserverEvent::ET_MASTER_PAGE_EXISTS,
*aNameIterator);
SendEvent (aEvent);
}
}
}
switch (pSdrHint->GetKind())
{ case SdrHintKind::PageOrderChange: // Process the modified set of pages only when the number of // standard and notes master pages are equal. This test // filters out events that are sent in between the insertion // of a new standard master page and a new notes master // page. if (auto pDrawDocument = dynamic_cast<SdDrawDocument *>( &rBroadcaster ))
{ if (pDrawDocument->GetMasterSdPageCount(PageKind::Standard)
== pDrawDocument->GetMasterSdPageCount(PageKind::Notes))
{
AnalyzeUsedMasterPages (*pDrawDocument);
}
} break;
default: break;
}
}
void MasterPageObserver::Implementation::AnalyzeUsedMasterPages (
SdDrawDocument& rDocument)
{ // Create a set of names of the master pages used by the given document.
sal_uInt16 nMasterPageCount = rDocument.GetMasterSdPageCount(PageKind::Standard);
::std::set<OUString> aCurrentMasterPages; for (sal_uInt16 nIndex=0; nIndex<nMasterPageCount; nIndex++)
{
SdPage* pMasterPage = rDocument.GetMasterSdPage (nIndex, PageKind::Standard); if (pMasterPage != nullptr)
aCurrentMasterPages.insert (pMasterPage->GetName());
}
// Send events about the newly used master pages.
::std::set_difference (
aCurrentMasterPages.begin(),
aCurrentMasterPages.end(),
aOldMasterPagesDescriptor->second.begin(),
aOldMasterPagesDescriptor->second.end(),
std::back_inserter(aNewMasterPages)); for (constauto& aNewMasterPage : aNewMasterPages)
{
MasterPageObserverEvent aEvent (
MasterPageObserverEvent::ET_MASTER_PAGE_ADDED,
aNewMasterPage);
SendEvent (aEvent);
}
// Send events about master pages that are not used any longer.
::std::set_difference (
aOldMasterPagesDescriptor->second.begin(),
aOldMasterPagesDescriptor->second.end(),
aCurrentMasterPages.begin(),
aCurrentMasterPages.end(),
std::back_inserter(aRemovedMasterPages)); for (constauto& aRemovedMasterPage : aRemovedMasterPages)
{
MasterPageObserverEvent aEvent (
MasterPageObserverEvent::ET_MASTER_PAGE_REMOVED,
aRemovedMasterPage);
SendEvent (aEvent);
}
// Store the new list of master pages.
aOldMasterPagesDescriptor->second = std::move(aCurrentMasterPages);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.