From 79c80fc9c4b819c3d1a4ad7aeacf7be90a9410c5 Mon Sep 17 00:00:00 2001 From: Andre Fischer Date: Fri, 18 Jun 2010 13:26:40 +0200 Subject: [PATCH] renaissance1: #1107215# Previews are updated on model changes (to reflect changes of page numbers etc). Fixed insert position at end of document. --- .../slidesorter/cache/SlsPageCacheManager.cxx | 26 +++++++ .../ui/slidesorter/controller/SlsListener.cxx | 71 +++++++++---------- .../ui/slidesorter/controller/SlsListener.hxx | 5 ++ .../inc/cache/SlsPageCacheManager.hxx | 6 ++ .../ui/slidesorter/view/SlsButtonBar.cxx | 52 +++++++------- sd/source/ui/slidesorter/view/SlsLayouter.cxx | 2 +- 6 files changed, 98 insertions(+), 64 deletions(-) diff --git a/sd/source/ui/slidesorter/cache/SlsPageCacheManager.cxx b/sd/source/ui/slidesorter/cache/SlsPageCacheManager.cxx index 97eb70dd7296..37bb6aa10208 100644 --- a/sd/source/ui/slidesorter/cache/SlsPageCacheManager.cxx +++ b/sd/source/ui/slidesorter/cache/SlsPageCacheManager.cxx @@ -385,6 +385,32 @@ bool PageCacheManager::InvalidatePreviewBitmap ( +void PageCacheManager::InvalidateAllPreviewBitmaps (DocumentKey pDocument) +{ + if (pDocument == NULL) + return; + + // Iterate over all caches that are currently in use and invalidate the + // previews in those that belong to the document. + PageCacheContainer::iterator iCache; + for (iCache=mpPageCaches->begin(); iCache!=mpPageCaches->end(); ++iCache) + if (iCache->first.mpDocument == pDocument) + iCache->second->InvalidateCache(); + + // Invalidate the previews in the recently used caches belonging to the + // given document. + RecentlyUsedPageCaches::iterator iQueue (mpRecentlyUsedPageCaches->find(pDocument)); + if (iQueue != mpRecentlyUsedPageCaches->end()) + { + RecentlyUsedQueue::const_iterator iCache2; + for (iCache2=iQueue->second.begin(); iCache2!=iQueue->second.end(); ++iCache2) + iCache2->mpCache->InvalidateCache(); + } +} + + + + void PageCacheManager::InvalidateAllCaches (void) { // Iterate over all caches that are currently in use and invalidate diff --git a/sd/source/ui/slidesorter/controller/SlsListener.cxx b/sd/source/ui/slidesorter/controller/SlsListener.cxx index 03cba2e4a522..fe2a85c20401 100644 --- a/sd/source/ui/slidesorter/controller/SlsListener.cxx +++ b/sd/source/ui/slidesorter/controller/SlsListener.cxx @@ -318,42 +318,7 @@ void Listener::Notify ( { case HINT_PAGEORDERCHG: if (&rBroadcaster == mrSlideSorter.GetModel().GetDocument()) - { - // Notify model and selection observer about the page. - // The return value of the model call acts as filter as - // to which events to pass to the selection observer. - if (mrSlideSorter.GetModel().NotifyPageEvent(rSdrHint.GetPage())) - { - // The page of the hint belongs (or belonged) - // to the model. - - // Tell the cache manager that the preview - // bitmaps for a deleted page can be removed - // from all caches. - const SdrPage* pPage = rSdrHint.GetPage(); - if (pPage!=NULL && ! pPage->IsInserted()) - cache::PageCacheManager::Instance()->ReleasePreviewBitmap(pPage); - - mrController.GetSelectionManager() - ->GetSelectionObserver()->NotifyPageEvent(rSdrHint.GetPage()); - } - - if (rBroadcaster.ISA(SdDrawDocument)) - { - SdDrawDocument& rDocument (static_cast(rBroadcaster)); - if (rDocument.GetMasterSdPageCount(PK_STANDARD) - == rDocument.GetMasterSdPageCount(PK_NOTES)) - { - mrController.HandleModelChange(); - } - } - } - break; - - case HINT_OBJINSERTED: - case HINT_OBJREMOVED: - case HINT_OBJCHG: - HandleShapeModification(rSdrHint.GetPage()); + HandleModelChange(rSdrHint.GetPage()); break; default: @@ -641,6 +606,40 @@ void Listener::UpdateEditMode (void) +void Listener::HandleModelChange (const SdrPage* pPage) +{ + // Notify model and selection observer about the page. The return value + // of the model call acts as filter as to which events to pass to the + // selection observer. + if (mrSlideSorter.GetModel().NotifyPageEvent(pPage)) + { + // The page of the hint belongs (or belonged) to the model. + + // Tell the cache manager that the preview bitmaps for a deleted + // page can be removed from all caches. + if (pPage!=NULL && ! pPage->IsInserted()) + cache::PageCacheManager::Instance()->ReleasePreviewBitmap(pPage); + + mrController.GetSelectionManager()->GetSelectionObserver()->NotifyPageEvent(pPage); + } + + // Tell the controller about the model change only when the document is + // in a sane state, not just in the middle of a larger change. + SdDrawDocument* pDocument (mrSlideSorter.GetModel().GetDocument()); + if (pDocument != NULL + && pDocument->GetMasterSdPageCount(PK_STANDARD) == pDocument->GetMasterSdPageCount(PK_NOTES)) + { + // A model change can make updates of some text fields necessary + // (like page numbers and page count.) Invalidate all previews in + // the cache to cope with this. Doing this on demand would be a + // nice optimization. + cache::PageCacheManager::Instance()->InvalidateAllPreviewBitmaps(pDocument->getUnoModel()); + + mrController.HandleModelChange(); + } +} + + void Listener::HandleShapeModification (const SdrPage* pPage) { diff --git a/sd/source/ui/slidesorter/controller/SlsListener.hxx b/sd/source/ui/slidesorter/controller/SlsListener.hxx index d10c46fa9423..7f65435ff738 100644 --- a/sd/source/ui/slidesorter/controller/SlsListener.hxx +++ b/sd/source/ui/slidesorter/controller/SlsListener.hxx @@ -169,6 +169,11 @@ private: */ void UpdateEditMode (void); + /** Handle a change in the order of slides or when the set of slides has + changed, i.e. a slide has been created. + */ + void HandleModelChange (const SdrPage* pPage); + /** Handle a modification to a shape on the given page. When this is a regular page then update its preview. When it is a master page then additionally update the previews of all pages linked to it. diff --git a/sd/source/ui/slidesorter/inc/cache/SlsPageCacheManager.hxx b/sd/source/ui/slidesorter/inc/cache/SlsPageCacheManager.hxx index c6b18eb077bc..71d7778f549f 100644 --- a/sd/source/ui/slidesorter/inc/cache/SlsPageCacheManager.hxx +++ b/sd/source/ui/slidesorter/inc/cache/SlsPageCacheManager.hxx @@ -107,6 +107,12 @@ public: DocumentKey pDocument, const SdrPage* pPage); + /** Invalidate the preview bitmaps for all slides that belong to the + specified document. This is necessary after model changes that + affect e.g. page number fiels. + */ + void InvalidateAllPreviewBitmaps (DocumentKey pDocument); + /** Invalidate all the caches that are currently in use and destroy those that are not. This is used for example when the high contrast mode is turned on or off. diff --git a/sd/source/ui/slidesorter/view/SlsButtonBar.cxx b/sd/source/ui/slidesorter/view/SlsButtonBar.cxx index 0b835d2afbef..3a5746e6a891 100644 --- a/sd/source/ui/slidesorter/view/SlsButtonBar.cxx +++ b/sd/source/ui/slidesorter/view/SlsButtonBar.cxx @@ -1407,7 +1407,7 @@ bool StartShowButton::IsEnabled (void) const return false; SfxDispatcher* pDispatcher = pViewShell->GetDispatcher(); if (pDispatcher == NULL) - return NULL; + return false; const SfxPoolItem* pState = NULL; const SfxItemState eState (pDispatcher->QueryState(SID_PRESENTATION, pState)); @@ -1416,33 +1416,21 @@ bool StartShowButton::IsEnabled (void) const + void StartShowButton::ProcessClick (const model::SharedPageDescriptor& rpDescriptor) { - // mrSlideSorter.GetController().GetCurrentSlideManager()->SwitchCurrentSlide( - // rpDescriptor); - if (mrSlideSorter.GetViewShell() != NULL - && mrSlideSorter.GetViewShell()->GetDispatcher() != NULL) + // Hide the tool tip early, while the slide show still intializes. + mrSlideSorter.GetView().GetToolTip().SetPage(model::SharedPageDescriptor()); + + Reference< XPresentation2 > xPresentation( + mrSlideSorter.GetModel().GetDocument()->getPresentation()); + if (xPresentation.is()) { - // Hide the tool tip early, while the slide show still intializes. - mrSlideSorter.GetView().GetToolTip().SetPage(model::SharedPageDescriptor()); - - Reference< XPresentation2 > xPresentation( - mrSlideSorter.GetModel().GetDocument()->getPresentation()); - if (xPresentation.is()) - { - Sequence aProperties (1); - aProperties[0].Name = ::rtl::OUString::createFromAscii("FirstPage"); - const ::rtl::OUString sName (rpDescriptor->GetPage()->GetName()); - aProperties[0].Value = Any(sName); - xPresentation->startWithArguments(aProperties); - } - - /* - // Request the start of the slide show. - mrSlideSorter.GetViewShell()->GetDispatcher()->Execute( - SID_PRESENTATION, - SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD); - */ + Sequence aProperties (1); + aProperties[0].Name = ::rtl::OUString::createFromAscii("FirstPage"); + const ::rtl::OUString sName (rpDescriptor->GetPage()->GetName()); + aProperties[0].Value = Any(sName); + xPresentation->startWithArguments(aProperties); } } @@ -1501,8 +1489,15 @@ DuplicateButton::DuplicateButton (SlideSorter& rSlideSorter) bool DuplicateButton::IsEnabled (void) const { + ViewShell* pViewShell = mrSlideSorter.GetViewShell(); + if (pViewShell == NULL) + return false; + SfxDispatcher* pDispatcher = pViewShell->GetDispatcher(); + if (pDispatcher == NULL) + return false; + const SfxPoolItem* pState = NULL; - const SfxItemState eState (mrSlideSorter.GetViewShell()->GetDispatcher()->QueryState( + const SfxItemState eState (pDispatcher->QueryState( SID_DUPLICATE_PAGE, pState)); return (eState & SFX_ITEM_DISABLED) == 0; @@ -1527,10 +1522,13 @@ void DuplicateButton::ProcessClick (const model::SharedPageDescriptor& rpDescrip } // Duplicate the selected pages. Insert the new pages right // after the current selection and select them - if (mrSlideSorter.GetViewShell() != NULL) + if (mrSlideSorter.GetViewShell() != NULL + && mrSlideSorter.GetViewShell()->GetDispatcher() != NULL) + { mrSlideSorter.GetViewShell()->GetDispatcher()->Execute( SID_DUPLICATE_PAGE, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD); + } } diff --git a/sd/source/ui/slidesorter/view/SlsLayouter.cxx b/sd/source/ui/slidesorter/view/SlsLayouter.cxx index 9d1b43903b21..d1d30a7cf9a1 100644 --- a/sd/source/ui/slidesorter/view/SlsLayouter.cxx +++ b/sd/source/ui/slidesorter/view/SlsLayouter.cxx @@ -1466,7 +1466,7 @@ void GridImplementation::CalculateLogicalInsertPosition ( { nIndex = mnPageCount; nRow = mnRowCount-1; - nColumn = mnPageCount%mnColumnCount; + nColumn = ::std::min(::std::min(mnPageCount, mnColumnCount), nColumn); bIsAtRunEnd = true; }