Author: af
Date: Fri Feb 21 11:55:33 2014
New Revision: 1570539

URL: http://svn.apache.org/r1570539
Log:
123197: Fixed selection problems when switching between normal and master mode.

Modified:
    
openoffice/trunk/main/sd/source/ui/slidesorter/controller/SlideSorterController.cxx
    
openoffice/trunk/main/sd/source/ui/slidesorter/controller/SlsCurrentSlideManager.cxx
    
openoffice/trunk/main/sd/source/ui/slidesorter/controller/SlsPageSelector.cxx
    
openoffice/trunk/main/sd/source/ui/slidesorter/inc/model/SlideSorterModel.hxx
    openoffice/trunk/main/sd/source/ui/slidesorter/inc/view/SlideSorterView.hxx
    openoffice/trunk/main/sd/source/ui/slidesorter/model/SlideSorterModel.cxx
    openoffice/trunk/main/sd/source/ui/slidesorter/view/SlideSorterView.cxx
    openoffice/trunk/main/sd/source/ui/slidesorter/view/SlsViewCacheContext.cxx

Modified: 
openoffice/trunk/main/sd/source/ui/slidesorter/controller/SlideSorterController.cxx
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/sd/source/ui/slidesorter/controller/SlideSorterController.cxx?rev=1570539&r1=1570538&r2=1570539&view=diff
==============================================================================
--- 
openoffice/trunk/main/sd/source/ui/slidesorter/controller/SlideSorterController.cxx
 (original)
+++ 
openoffice/trunk/main/sd/source/ui/slidesorter/controller/SlideSorterController.cxx
 Fri Feb 21 11:55:33 2014
@@ -946,6 +946,8 @@ void SlideSorterController::FinishEditMo
 {
     if (mrModel.GetEditMode() == EM_MASTERPAGE)
     {
+        mpPageSelector->DeselectAllPages();
+
         // Search for the master page that was determined in
         // PrepareEditModeChange() and make it the current page.
         PageEnumeration aAllPages 
(PageEnumerationProvider::CreateAllPagesEnumeration(mrModel));
@@ -955,16 +957,20 @@ void SlideSorterController::FinishEditMo
             if (pDescriptor->GetPage() == mpEditModeChangeMasterPage)
             {
                 GetCurrentSlideManager()->SwitchCurrentSlide(pDescriptor);
+                mpPageSelector->SelectPage(pDescriptor);
                 break;
             }
         }
     }
     else
     {
+        PageSelector::BroadcastLock aBroadcastLock (*mpPageSelector);
+
         SharedPageDescriptor pDescriptor 
(mrModel.GetPageDescriptor(mnCurrentPageBeforeSwitch));
         GetCurrentSlideManager()->SwitchCurrentSlide(pDescriptor);
 
         // Restore the selection.
+        mpPageSelector->DeselectAllPages();
         ::std::vector<SdPage*>::iterator iPage;
         for (iPage=maSelectionBeforeSwitch.begin();
              iPage!=maSelectionBeforeSwitch.end();
@@ -1047,14 +1053,8 @@ void SlideSorterController::SetDocumentS
     {
         ModelChangeLock aLock (*this);
         PreModelChange();
-        
-        mrModel.SetDocumentSlides(rxSlides);
-        mrView.Layout();
 
-        // Select just the current slide.
-        PageSelector::BroadcastLock aBroadcastLock (*mpPageSelector);
-        mpPageSelector->DeselectAllPages();
-        mpPageSelector->SelectPage(mpCurrentSlideManager->GetCurrentSlide());
+        mrModel.SetDocumentSlides(rxSlides);
     }
 }
 

Modified: 
openoffice/trunk/main/sd/source/ui/slidesorter/controller/SlsCurrentSlideManager.cxx
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/sd/source/ui/slidesorter/controller/SlsCurrentSlideManager.cxx?rev=1570539&r1=1570538&r2=1570539&view=diff
==============================================================================
--- 
openoffice/trunk/main/sd/source/ui/slidesorter/controller/SlsCurrentSlideManager.cxx
 (original)
+++ 
openoffice/trunk/main/sd/source/ui/slidesorter/controller/SlsCurrentSlideManager.cxx
 Fri Feb 21 11:55:33 2014
@@ -86,11 +86,14 @@ void CurrentSlideManager::NotifyCurrentS
 {
     if (mnCurrentSlideIndex != nSlideIndex)
     {
+        PageSelector::BroadcastLock aBroadcastLock 
(mrSlideSorter.GetController().GetPageSelector());
+
+        mrSlideSorter.GetController().GetPageSelector().DeselectAllPages();
+
         ReleaseCurrentSlide();
         AcquireCurrentSlide(nSlideIndex);
 
         // Update the selection.
-        mrSlideSorter.GetController().GetPageSelector().DeselectAllPages();
         if (mpCurrentSlide)
         {
             
mrSlideSorter.GetController().GetPageSelector().SelectPage(mpCurrentSlide);

Modified: 
openoffice/trunk/main/sd/source/ui/slidesorter/controller/SlsPageSelector.cxx
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/sd/source/ui/slidesorter/controller/SlsPageSelector.cxx?rev=1570539&r1=1570538&r2=1570539&view=diff
==============================================================================
--- 
openoffice/trunk/main/sd/source/ui/slidesorter/controller/SlsPageSelector.cxx 
(original)
+++ 
openoffice/trunk/main/sd/source/ui/slidesorter/controller/SlsPageSelector.cxx 
Fri Feb 21 11:55:33 2014
@@ -65,7 +65,7 @@ PageSelector::PageSelector (SlideSorter&
       mpSelectionAnchor(),
       mpCurrentPage(),
       mnUpdateLockCount(0),
-      mbIsUpdateCurrentPagePending(false)
+      mbIsUpdateCurrentPagePending(true)
 {
     CountSelectedPages ();
 }
@@ -393,27 +393,39 @@ void PageSelector::UpdateCurrentPage (co
     mbIsUpdateCurrentPagePending = false;
     
     // Make the first selected page the current page.
+    SharedPageDescriptor pCurrentPageDescriptor;
     const sal_Int32 nPageCount (GetPageCount());
     for (sal_Int32 nIndex=0; nIndex<nPageCount; ++nIndex)
     {
         SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(nIndex));
-        if (pDescriptor && pDescriptor->HasState(PageDescriptor::ST_Selected))
+        if ( ! pDescriptor)
+            continue;
+        if (pDescriptor->HasState(PageDescriptor::ST_Selected))
         {
-            // Switching the current slide normally sets also the selection
-            // to just the new current slide.  To prevent that, we store
-            // (and at the end of this scope restore) the current selection.
-            ::boost::shared_ptr<PageSelection> pSelection (GetPageSelection());
-                
-            
mrController.GetCurrentSlideManager()->SwitchCurrentSlide(pDescriptor);
-                
-            // Restore the selection and prevent a recursive call to
-            // UpdateCurrentPage().
-            SetPageSelection(pSelection, false);
-            return;
+            pCurrentPageDescriptor = pDescriptor;
+            break;
         }
     }
+    if ( ! pCurrentPageDescriptor && nPageCount>0)
+    {
+        // No page is selected.  Make the first slide the current page.
+        pCurrentPageDescriptor = mrModel.GetPageDescriptor(0);
+    }
 
-    // No page is selected.  Do not change the current slide.
+    if (pCurrentPageDescriptor)
+    {
+        // Switching the current slide normally sets also the
+        // selection to just the new current slide.  To prevent that,
+        // we store (and at the end of this scope restore) the current
+        // selection.
+        ::boost::shared_ptr<PageSelection> pSelection (GetPageSelection());
+                
+        
mrController.GetCurrentSlideManager()->SwitchCurrentSlide(pCurrentPageDescriptor);
+                
+        // Restore the selection and prevent a recursive call to
+        // UpdateCurrentPage().
+        SetPageSelection(pSelection, false);
+    }
 }
 
 

Modified: 
openoffice/trunk/main/sd/source/ui/slidesorter/inc/model/SlideSorterModel.hxx
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/sd/source/ui/slidesorter/inc/model/SlideSorterModel.hxx?rev=1570539&r1=1570538&r2=1570539&view=diff
==============================================================================
--- 
openoffice/trunk/main/sd/source/ui/slidesorter/inc/model/SlideSorterModel.hxx 
(original)
+++ 
openoffice/trunk/main/sd/source/ui/slidesorter/inc/model/SlideSorterModel.hxx 
Fri Feb 21 11:55:33 2014
@@ -56,7 +56,7 @@ namespace sd { namespace slidesorter { n
 class DocumentPageContainer;
 
 inline sal_Int32 FromCoreIndex (const sal_uInt16 nCoreIndex) { return 
(nCoreIndex-1)/2; }
-inline sal_uInt16 ToCoreIndex (const sal_Int32 nIndex) { return nIndex*2+1; }
+inline sal_uInt16 ToCoreIndex (const sal_Int32 nIndex) { return 
static_cast<sal_uInt16>(nIndex*2+1); }
 
 /** The model of the slide sorter gives access to the slides that are to be
     displayed in the slide sorter view.  Via the SetDocumentSlides() method

Modified: 
openoffice/trunk/main/sd/source/ui/slidesorter/inc/view/SlideSorterView.hxx
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/sd/source/ui/slidesorter/inc/view/SlideSorterView.hxx?rev=1570539&r1=1570538&r2=1570539&view=diff
==============================================================================
--- openoffice/trunk/main/sd/source/ui/slidesorter/inc/view/SlideSorterView.hxx 
(original)
+++ openoffice/trunk/main/sd/source/ui/slidesorter/inc/view/SlideSorterView.hxx 
Fri Feb 21 11:55:33 2014
@@ -110,9 +110,9 @@ public:
 
     view::Layouter& GetLayouter (void);
 
-       virtual void ModelHasChanged (void);
+    virtual void ModelHasChanged (void);
 
-       void LocalModelHasChanged(void);
+    void LocalModelHasChanged(void);
 
     /** This method is typically called before a model change takes place.
         All references to model data are released.  PostModelChange() has to

Modified: 
openoffice/trunk/main/sd/source/ui/slidesorter/model/SlideSorterModel.cxx
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/sd/source/ui/slidesorter/model/SlideSorterModel.cxx?rev=1570539&r1=1570538&r2=1570539&view=diff
==============================================================================
--- openoffice/trunk/main/sd/source/ui/slidesorter/model/SlideSorterModel.cxx 
(original)
+++ openoffice/trunk/main/sd/source/ui/slidesorter/model/SlideSorterModel.cxx 
Fri Feb 21 11:55:33 2014
@@ -173,7 +173,6 @@ bool SlideSorterModel::SetEditMode (Edit
     {
         meEditMode = eEditMode;
         UpdatePageList();
-        ClearDescriptorList();
         bEditModeChanged = true;
     }
     return bEditModeChanged;
@@ -424,7 +423,8 @@ void SlideSorterModel::SynchronizeDocume
     while (aAllPages.HasMoreElements())
     {
         SharedPageDescriptor pDescriptor (aAllPages.GetNextElement());
-        
pDescriptor->GetPage()->SetSelected(pDescriptor->HasState(PageDescriptor::ST_Selected));
+        const bool bIsSelected 
(pDescriptor->HasState(PageDescriptor::ST_Selected));
+        pDescriptor->GetPage()->SetSelected(bIsSelected);
     }
 }
 
@@ -439,7 +439,8 @@ void SlideSorterModel::SynchronizeModelS
     while (aAllPages.HasMoreElements())
     {
         SharedPageDescriptor pDescriptor (aAllPages.GetNextElement());
-        pDescriptor->SetState(PageDescriptor::ST_Selected, 
pDescriptor->GetPage()->IsSelected());
+        const bool bIsSelected (pDescriptor->GetPage()->IsSelected());
+        pDescriptor->SetState(PageDescriptor::ST_Selected, bIsSelected);
     }
 }
 
@@ -459,11 +460,29 @@ void SlideSorterModel::SetDocumentSlides
 {
     ::osl::MutexGuard aGuard (maMutex);
 
-    // Reset the current page so to cause everbody to release references to it.
+    // Make the current selection persistent and then release the
+    // current set of pages.
+    SynchronizeDocumentSelection();
+    mxSlides = NULL;
+    ClearDescriptorList ();
+
+    // Reset the current page to cause everbody to release references to it.
     
mrSlideSorter.GetController().GetCurrentSlideManager()->NotifyCurrentSlideChange(-1);
 
+    // Set the new set of pages.
     mxSlides = rxSlides;
-    Resync();
+    AdaptSize();
+    SynchronizeModelSelection();
+    mrSlideSorter.GetController().GetPageSelector().CountSelectedPages();
+
+    model::PageEnumeration aSelectedPages (
+        model::PageEnumerationProvider::CreateSelectedPagesEnumeration(*this));
+    if (aSelectedPages.HasMoreElements())
+    {
+        SharedPageDescriptor pDescriptor (aSelectedPages.GetNextElement());
+        
mrSlideSorter.GetController().GetCurrentSlideManager()->NotifyCurrentSlideChange(
+            pDescriptor->GetPage());
+    }
 
     ViewShell* pViewShell = mrSlideSorter.GetViewShell();
     if (pViewShell != NULL)
@@ -667,7 +686,6 @@ void SlideSorterModel::InsertSlide (SdPa
 
     // Update page indices.
     UpdateIndices(nIndex+1);
-    OSL_TRACE("page inserted");
 }
 
 
@@ -705,7 +723,6 @@ void SlideSorterModel::DeleteSlide (cons
         maPageDescriptors.erase(maPageDescriptors.begin()+nIndex);
         UpdateIndices(nIndex);
     }
-    OSL_TRACE("page removed");
 }
 
 

Modified: 
openoffice/trunk/main/sd/source/ui/slidesorter/view/SlideSorterView.cxx
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/sd/source/ui/slidesorter/view/SlideSorterView.cxx?rev=1570539&r1=1570538&r2=1570539&view=diff
==============================================================================
--- openoffice/trunk/main/sd/source/ui/slidesorter/view/SlideSorterView.cxx 
(original)
+++ openoffice/trunk/main/sd/source/ui/slidesorter/view/SlideSorterView.cxx Fri 
Feb 21 11:55:33 2014
@@ -278,10 +278,10 @@ void SlideSorterView::ModelHasChanged (v
 
 void SlideSorterView::LocalModelHasChanged(void)
 {
-       mbModelChangedWhileModifyEnabled = false;
-
-       // First call our base class.
-       View::ModelHasChanged ();
+    mbModelChangedWhileModifyEnabled = false;
+    
+    // First call our base class.
+    View::ModelHasChanged ();
 }
 
 

Modified: 
openoffice/trunk/main/sd/source/ui/slidesorter/view/SlsViewCacheContext.cxx
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/sd/source/ui/slidesorter/view/SlsViewCacheContext.cxx?rev=1570539&r1=1570538&r2=1570539&view=diff
==============================================================================
--- openoffice/trunk/main/sd/source/ui/slidesorter/view/SlsViewCacheContext.cxx 
(original)
+++ openoffice/trunk/main/sd/source/ui/slidesorter/view/SlsViewCacheContext.cxx 
Fri Feb 21 11:55:33 2014
@@ -70,7 +70,9 @@ void ViewCacheContext::NotifyPreviewCrea
     }
     else
     {
-        OSL_ASSERT(pDescriptor);
+        // It is OK when a preview was created for a page that is not
+        // currently displayed because both normal and master pages are
+        // kept in the same cache.
     }
 }
 


Reply via email to