LCOV - code coverage report
Current view: top level - sd/source/ui/slidesorter/model - SlideSorterModel.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 198 291 68.0 %
Date: 2014-04-11 Functions: 28 33 84.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include "model/SlideSorterModel.hxx"
      22             : 
      23             : #include "SlideSorter.hxx"
      24             : #include "model/SlsPageDescriptor.hxx"
      25             : #include "model/SlsPageEnumerationProvider.hxx"
      26             : #include "controller/SlideSorterController.hxx"
      27             : #include "controller/SlsProperties.hxx"
      28             : #include "controller/SlsPageSelector.hxx"
      29             : #include "controller/SlsCurrentSlideManager.hxx"
      30             : #include "controller/SlsSlotManager.hxx"
      31             : #include "view/SlideSorterView.hxx"
      32             : #include "taskpane/SlideSorterCacheDisplay.hxx"
      33             : #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
      34             : #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
      35             : #include <com/sun/star/beans/XPropertySet.hpp>
      36             : #include <com/sun/star/beans/UnknownPropertyException.hpp>
      37             : 
      38             : #include "ViewShellBase.hxx"
      39             : #include "DrawViewShell.hxx"
      40             : #include "DrawDocShell.hxx"
      41             : #include "drawdoc.hxx"
      42             : #include "sdpage.hxx"
      43             : #include "FrameView.hxx"
      44             : 
      45             : #include <tools/diagnose_ex.h>
      46             : 
      47             : using namespace ::com::sun::star;
      48             : using namespace ::com::sun::star::uno;
      49             : 
      50             : namespace sd { namespace slidesorter { namespace model {
      51             : 
      52             : namespace {
      53           0 :     bool PrintModel (const SlideSorterModel& rModel)
      54             :     {
      55           0 :         for (sal_Int32 nIndex=0,nCount=rModel.GetPageCount(); nIndex<nCount; ++nIndex)
      56             :         {
      57           0 :             SharedPageDescriptor pDescriptor (rModel.GetPageDescriptor(nIndex));
      58           0 :             if (pDescriptor)
      59             :             {
      60             :                 OSL_TRACE("%d %d %d %d %p",
      61             :                     nIndex,
      62             :                     pDescriptor->GetPageIndex(),
      63             :                     pDescriptor->GetVisualState().mnPageId,
      64             :                     FromCoreIndex(pDescriptor->GetPage()->GetPageNum()),
      65             :                     pDescriptor->GetPage());
      66             :             }
      67             :             else
      68             :             {
      69             :                 OSL_TRACE("%d", nIndex);
      70             :             }
      71           0 :         }
      72             : 
      73           0 :         return true;
      74             :     }
      75          90 :     bool CheckModel (const SlideSorterModel& rModel)
      76             :     {
      77         212 :         for (sal_Int32 nIndex=0,nCount=rModel.GetPageCount(); nIndex<nCount; ++nIndex)
      78             :         {
      79         122 :             SharedPageDescriptor pDescriptor (rModel.GetPageDescriptor(nIndex));
      80         122 :             if ( ! pDescriptor)
      81             :             {
      82           0 :                 PrintModel(rModel);
      83             :                 OSL_ASSERT(pDescriptor);
      84           0 :                 return false;
      85             :             }
      86         122 :             if (nIndex != pDescriptor->GetPageIndex())
      87             :             {
      88           0 :                 PrintModel(rModel);
      89             :                 OSL_ASSERT(nIndex == pDescriptor->GetPageIndex());
      90           0 :                 return false;
      91             :             }
      92         122 :             if (nIndex != pDescriptor->GetVisualState().mnPageId)
      93             :             {
      94           0 :                 PrintModel(rModel);
      95             :                 OSL_ASSERT(nIndex == pDescriptor->GetVisualState().mnPageId);
      96           0 :                 return false;
      97             :             }
      98         122 :         }
      99             : 
     100          90 :         return true;
     101             :     }
     102             : }
     103             : 
     104             : 
     105             : 
     106             : 
     107          63 : SlideSorterModel::SlideSorterModel (SlideSorter& rSlideSorter)
     108             :     : maMutex(),
     109             :       mrSlideSorter(rSlideSorter),
     110             :       mxSlides(),
     111             :       mePageKind(PK_STANDARD),
     112             :       meEditMode(EM_PAGE),
     113          63 :       maPageDescriptors(0)
     114             : {
     115          63 : }
     116             : 
     117             : 
     118             : 
     119             : 
     120         189 : SlideSorterModel::~SlideSorterModel (void)
     121             : {
     122          63 :     ClearDescriptorList ();
     123         126 : }
     124             : 
     125             : 
     126             : 
     127             : 
     128          63 : void SlideSorterModel::Init (void)
     129             : {
     130          63 : }
     131             : 
     132             : 
     133             : 
     134             : 
     135          63 : void SlideSorterModel::Dispose (void)
     136             : {
     137          63 :     ClearDescriptorList ();
     138          63 : }
     139             : 
     140             : 
     141             : 
     142             : 
     143        2098 : SdDrawDocument* SlideSorterModel::GetDocument (void)
     144             : {
     145        2098 :     if (mrSlideSorter.GetViewShellBase() != NULL)
     146        2098 :         return mrSlideSorter.GetViewShellBase()->GetDocument();
     147             :     else
     148           0 :          return NULL;
     149             : }
     150             : 
     151             : 
     152             : 
     153             : 
     154           0 : bool SlideSorterModel::SetEditMode (EditMode eEditMode)
     155             : {
     156           0 :     bool bEditModeChanged = false;
     157           0 :     if (meEditMode != eEditMode)
     158             :     {
     159           0 :         meEditMode = eEditMode;
     160           0 :         UpdatePageList();
     161           0 :         bEditModeChanged = true;
     162             :     }
     163           0 :     return bEditModeChanged;
     164             : }
     165             : 
     166             : 
     167             : 
     168             : 
     169           1 : EditMode SlideSorterModel::GetEditMode (void) const
     170             : {
     171           1 :     return meEditMode;
     172             : }
     173             : 
     174             : 
     175             : 
     176             : 
     177           1 : PageKind SlideSorterModel::GetPageType (void) const
     178             : {
     179           1 :     return mePageKind;
     180             : }
     181             : 
     182             : 
     183             : 
     184             : 
     185       22983 : sal_Int32 SlideSorterModel::GetPageCount (void) const
     186             : {
     187       22983 :     return maPageDescriptors.size();
     188             : }
     189             : 
     190             : 
     191             : 
     192             : 
     193        8744 : SharedPageDescriptor SlideSorterModel::GetPageDescriptor (
     194             :     const sal_Int32 nPageIndex,
     195             :     const bool bCreate) const
     196             : {
     197        8744 :     ::osl::MutexGuard aGuard (maMutex);
     198             : 
     199        8744 :     SharedPageDescriptor pDescriptor;
     200             : 
     201        8744 :     if (nPageIndex>=0 && nPageIndex<GetPageCount())
     202             :     {
     203        8353 :         pDescriptor = maPageDescriptors[nPageIndex];
     204        8353 :         if (pDescriptor == 0 && bCreate && mxSlides.is())
     205             :         {
     206          63 :             SdPage* pPage = GetPage(nPageIndex);
     207             :             pDescriptor.reset(new PageDescriptor (
     208          63 :                 Reference<drawing::XDrawPage>(mxSlides->getByIndex(nPageIndex),UNO_QUERY),
     209             :                 pPage,
     210          63 :                 nPageIndex));
     211          63 :             maPageDescriptors[nPageIndex] = pDescriptor;
     212             :         }
     213             :     }
     214             : 
     215        8744 :     return pDescriptor;
     216             : }
     217             : 
     218             : 
     219             : 
     220             : 
     221         189 : sal_Int32 SlideSorterModel::GetIndex (const Reference<drawing::XDrawPage>& rxSlide) const
     222             : {
     223         189 :     ::osl::MutexGuard aGuard (maMutex);
     224             : 
     225             :     // First try to guess the right index.
     226         378 :     Reference<beans::XPropertySet> xSet (rxSlide, UNO_QUERY);
     227         189 :     if (xSet.is())
     228             :     {
     229             :         try
     230             :         {
     231         189 :             const Any aNumber (xSet->getPropertyValue("Number"));
     232         189 :             sal_Int16 nNumber (-1);
     233         189 :             aNumber >>= nNumber;
     234         189 :             nNumber -= 1;
     235         189 :             SharedPageDescriptor pDescriptor (GetPageDescriptor(nNumber, false));
     236         567 :             if (pDescriptor.get() != NULL
     237         756 :                 && pDescriptor->GetXDrawPage() == rxSlide)
     238             :             {
     239         189 :                 return nNumber;
     240           0 :             }
     241             :         }
     242           0 :         catch (uno::Exception&)
     243             :         {
     244             :             DBG_UNHANDLED_EXCEPTION();
     245             :         }
     246             :     }
     247             : 
     248             :     // Guess was wrong, iterate over all slides and search for the right
     249             :     // one.
     250           0 :     const sal_Int32 nCount (maPageDescriptors.size());
     251           0 :     for (sal_Int32 nIndex=0; nIndex<nCount; ++nIndex)
     252             :     {
     253           0 :         SharedPageDescriptor pDescriptor (maPageDescriptors[nIndex]);
     254             : 
     255             :         // Make sure that the descriptor exists.  Without it the given slide
     256             :         // can not be found.
     257           0 :         if (pDescriptor.get() == NULL)
     258             :         {
     259             :             // Call GetPageDescriptor() to create the missing descriptor.
     260           0 :             pDescriptor = GetPageDescriptor(nIndex,true);
     261             :         }
     262             : 
     263           0 :         if (pDescriptor->GetXDrawPage() == rxSlide)
     264           0 :             return nIndex;
     265           0 :     }
     266             : 
     267         189 :     return  -1;
     268             : }
     269             : 
     270             : 
     271             : 
     272             : 
     273          67 : sal_Int32 SlideSorterModel::GetIndex (const SdrPage* pPage) const
     274             : {
     275          67 :     if (pPage == NULL)
     276           0 :         return -1;
     277             : 
     278          67 :     ::osl::MutexGuard aGuard (maMutex);
     279             : 
     280             :     // First try to guess the right index.
     281          67 :     sal_Int16 nNumber ((pPage->GetPageNum()-1)/2);
     282         134 :     SharedPageDescriptor pDescriptor (GetPageDescriptor(nNumber, false));
     283         134 :     if (pDescriptor.get() != NULL
     284          67 :         && pDescriptor->GetPage() == pPage)
     285             :     {
     286          67 :         return nNumber;
     287             :     }
     288             : 
     289             :     // Guess was wrong, iterate over all slides and search for the right
     290             :     // one.
     291           0 :     const sal_Int32 nCount (maPageDescriptors.size());
     292           0 :     for (sal_Int32 nIndex=0; nIndex<nCount; ++nIndex)
     293             :     {
     294           0 :         pDescriptor = maPageDescriptors[nIndex];
     295             : 
     296             :         // Make sure that the descriptor exists.  Without it the given slide
     297             :         // can not be found.
     298           0 :         if (pDescriptor.get() == NULL)
     299             :         {
     300             :             // Call GetPageDescriptor() to create the missing descriptor.
     301           0 :             pDescriptor = GetPageDescriptor(nIndex, true);
     302             :         }
     303             : 
     304           0 :         if (pDescriptor->GetPage() == pPage)
     305           0 :             return nIndex;
     306             :     }
     307             : 
     308          67 :     return  -1;
     309             : }
     310             : 
     311             : 
     312             : 
     313             : 
     314           0 : sal_uInt16 SlideSorterModel::GetCoreIndex (const sal_Int32 nIndex) const
     315             : {
     316           0 :     SharedPageDescriptor pDescriptor (GetPageDescriptor(nIndex));
     317           0 :     if (pDescriptor)
     318           0 :         return pDescriptor->GetPage()->GetPageNum();
     319             :     else
     320           0 :         return mxSlides->getCount()*2+1;
     321             : }
     322             : 
     323             : 
     324             : 
     325             : 
     326             : /** For now this method uses a trivial algorithm: throw away all descriptors
     327             :     and create them anew (on demand).  The main problem that we are facing
     328             :     when designing a better algorithm is that we can not compare pointers to
     329             :     pages stored in the PageDescriptor objects and those obtained from the
     330             :     document: pages may have been deleted and others may have been created
     331             :     at the exact same memory locations.
     332             : */
     333          79 : void SlideSorterModel::Resync (void)
     334             : {
     335          79 :     ::osl::MutexGuard aGuard (maMutex);
     336             : 
     337             :     // Check if document and this model really differ.
     338          79 :     bool bIsUpToDate (true);
     339          79 :     SdDrawDocument* pDocument = GetDocument();
     340          79 :     if (pDocument!=NULL && maPageDescriptors.size()==pDocument->GetSdPageCount(mePageKind))
     341             :     {
     342         174 :         for (sal_Int32 nIndex=0,nCount=maPageDescriptors.size(); nIndex<nCount; ++nIndex)
     343             :         {
     344         190 :             if (maPageDescriptors[nIndex]
     345         190 :                 && maPageDescriptors[nIndex]->GetPage()
     346         190 :                 != GetPage(nIndex))
     347             :             {
     348             :                 OSL_TRACE("page %d differs", nIndex);
     349           0 :                 bIsUpToDate = false;
     350           0 :                 break;
     351             :             }
     352             :         }
     353             :     }
     354             :     else
     355             :     {
     356           0 :         bIsUpToDate = false;
     357             :         OSL_TRACE("models differ");
     358             :     }
     359             : 
     360          79 :     if ( ! bIsUpToDate)
     361             :     {
     362           0 :         SynchronizeDocumentSelection(); // Try to make the current selection persistent.
     363           0 :         ClearDescriptorList ();
     364           0 :         AdaptSize();
     365           0 :         SynchronizeModelSelection();
     366           0 :         mrSlideSorter.GetController().GetPageSelector().CountSelectedPages();
     367             :     }
     368          79 :     CheckModel(*this);
     369          79 : }
     370             : 
     371             : 
     372             : 
     373             : 
     374         189 : void SlideSorterModel::ClearDescriptorList (void)
     375             : {
     376         189 :     DescriptorContainer aDescriptors;
     377             : 
     378             :     {
     379         189 :         ::osl::MutexGuard aGuard (maMutex);
     380         189 :         aDescriptors.swap(maPageDescriptors);
     381             :     }
     382             : 
     383         261 :     for (DescriptorContainer::iterator iDescriptor=aDescriptors.begin(), iEnd=aDescriptors.end();
     384             :          iDescriptor!=iEnd;
     385             :          ++iDescriptor)
     386             :     {
     387          72 :         if (iDescriptor->get() != NULL)
     388             :         {
     389          72 :             if ( ! iDescriptor->unique())
     390             :             {
     391             :                 OSL_TRACE("SlideSorterModel::ClearDescriptorList: trying to delete page descriptor  that is still used with count %zu", iDescriptor->use_count());
     392             :                 // No assertion here because that can hang the office when
     393             :                 // opening a dialog from here.
     394             :             }
     395          72 :             iDescriptor->reset();
     396             :         }
     397         189 :     }
     398         189 : }
     399             : 
     400             : 
     401             : 
     402             : 
     403          63 : void SlideSorterModel::SynchronizeDocumentSelection (void)
     404             : {
     405          63 :     ::osl::MutexGuard aGuard (maMutex);
     406             : 
     407         126 :     PageEnumeration aAllPages (PageEnumerationProvider::CreateAllPagesEnumeration(*this));
     408         126 :     while (aAllPages.HasMoreElements())
     409             :     {
     410           0 :         SharedPageDescriptor pDescriptor (aAllPages.GetNextElement());
     411           0 :         const bool bIsSelected (pDescriptor->HasState(PageDescriptor::ST_Selected));
     412           0 :         pDescriptor->GetPage()->SetSelected(bIsSelected);
     413          63 :     }
     414          63 : }
     415             : 
     416             : 
     417             : 
     418             : 
     419          63 : void SlideSorterModel::SynchronizeModelSelection (void)
     420             : {
     421          63 :     ::osl::MutexGuard aGuard (maMutex);
     422             : 
     423         126 :     PageEnumeration aAllPages (PageEnumerationProvider::CreateAllPagesEnumeration(*this));
     424         189 :     while (aAllPages.HasMoreElements())
     425             :     {
     426          63 :         SharedPageDescriptor pDescriptor (aAllPages.GetNextElement());
     427          63 :         const bool bIsSelected (pDescriptor->GetPage()->IsSelected());
     428          63 :         pDescriptor->SetState(PageDescriptor::ST_Selected, bIsSelected);
     429         126 :     }
     430          63 : }
     431             : 
     432             : 
     433             : 
     434             : 
     435         142 : ::osl::Mutex& SlideSorterModel::GetMutex (void)
     436             : {
     437         142 :     return maMutex;
     438             : }
     439             : 
     440             : 
     441             : 
     442             : 
     443          63 : void SlideSorterModel::SetDocumentSlides (
     444             :     const Reference<container::XIndexAccess>& rxSlides)
     445             : {
     446          63 :     ::osl::MutexGuard aGuard (maMutex);
     447             : 
     448             :     // Make the current selection persistent and then release the
     449             :     // current set of pages.
     450          63 :     SynchronizeDocumentSelection();
     451          63 :     mxSlides = NULL;
     452          63 :     ClearDescriptorList ();
     453             : 
     454             :     // Reset the current page to cause everbody to release references to it.
     455          63 :     mrSlideSorter.GetController().GetCurrentSlideManager()->NotifyCurrentSlideChange(-1);
     456             : 
     457             :     // Set the new set of pages.
     458          63 :     mxSlides = rxSlides;
     459          63 :     AdaptSize();
     460          63 :     SynchronizeModelSelection();
     461          63 :     mrSlideSorter.GetController().GetPageSelector().CountSelectedPages();
     462             : 
     463             :     model::PageEnumeration aSelectedPages (
     464         126 :         model::PageEnumerationProvider::CreateSelectedPagesEnumeration(*this));
     465          63 :     if (aSelectedPages.HasMoreElements())
     466             :     {
     467          63 :         SharedPageDescriptor pDescriptor (aSelectedPages.GetNextElement());
     468          63 :         mrSlideSorter.GetController().GetCurrentSlideManager()->NotifyCurrentSlideChange(
     469         126 :             pDescriptor->GetPage());
     470             :     }
     471             : 
     472          63 :     ViewShell* pViewShell = mrSlideSorter.GetViewShell();
     473          63 :     if (pViewShell != NULL)
     474             :     {
     475          63 :         SdPage* pPage = pViewShell->getCurrentPage();
     476          63 :         if (pPage != NULL)
     477          63 :             mrSlideSorter.GetController().GetCurrentSlideManager()->NotifyCurrentSlideChange(
     478          63 :                 pPage);
     479             :         else
     480             :         {
     481             :             // No current page.  This can only be when the slide sorter is
     482             :             // the main view shell.  Get current slide form frame view.
     483           0 :             const FrameView* pFrameView = pViewShell->GetFrameView();
     484           0 :             if (pFrameView != NULL)
     485           0 :                 mrSlideSorter.GetController().GetCurrentSlideManager()->NotifyCurrentSlideChange(
     486           0 :                     pFrameView->GetSelectedPage());
     487             :             else
     488             :             {
     489             :                 // No frame view.  As a last resort use the first slide as
     490             :                 // current slide.
     491           0 :                 mrSlideSorter.GetController().GetCurrentSlideManager()->NotifyCurrentSlideChange(
     492           0 :                     sal_Int32(0));
     493             :             }
     494             :         }
     495             :     }
     496             : 
     497         126 :     mrSlideSorter.GetController().GetSlotManager()->NotifyEditModeChange();
     498          63 : }
     499             : 
     500             : 
     501             : 
     502             : 
     503          63 : Reference<container::XIndexAccess> SlideSorterModel::GetDocumentSlides (void) const
     504             : {
     505          63 :     ::osl::MutexGuard aGuard (maMutex);
     506          63 :     return mxSlides;
     507             : }
     508             : 
     509             : 
     510             : 
     511             : 
     512          63 : void SlideSorterModel::UpdatePageList (void)
     513             : {
     514          63 :     ::osl::MutexGuard aGuard (maMutex);
     515             : 
     516         126 :     Reference<container::XIndexAccess> xPages;
     517             : 
     518             :     // Get the list of pages according to the edit mode.
     519         126 :     Reference<frame::XController> xController (mrSlideSorter.GetXController());
     520          63 :     if (xController.is())
     521             :     {
     522          63 :         switch (meEditMode)
     523             :         {
     524             :             case EM_MASTERPAGE:
     525             :             {
     526             :                 Reference<drawing::XMasterPagesSupplier> xSupplier (
     527           0 :                     xController->getModel(), UNO_QUERY);
     528           0 :                 if (xSupplier.is())
     529             :                 {
     530           0 :                     xPages = Reference<container::XIndexAccess>(
     531           0 :                         xSupplier->getMasterPages(), UNO_QUERY);
     532           0 :                 }
     533             :             }
     534           0 :             break;
     535             : 
     536             :             case EM_PAGE:
     537             :             {
     538             :                 Reference<drawing::XDrawPagesSupplier> xSupplier (
     539          63 :                     xController->getModel(), UNO_QUERY);
     540          63 :                 if (xSupplier.is())
     541             :                 {
     542         126 :                     xPages = Reference<container::XIndexAccess>(
     543         126 :                         xSupplier->getDrawPages(), UNO_QUERY);
     544          63 :                 }
     545             :             }
     546          63 :             break;
     547             : 
     548             :             default:
     549             :                 // We should never get here.
     550             :                 OSL_ASSERT(false);
     551           0 :                 break;
     552             :         }
     553             :     }
     554             : 
     555         126 :     mrSlideSorter.GetController().SetDocumentSlides(xPages);
     556          63 : }
     557             : 
     558             : 
     559             : 
     560             : 
     561          63 : void SlideSorterModel::AdaptSize (void)
     562             : {
     563          63 :     if (mxSlides.is())
     564          63 :         maPageDescriptors.resize(mxSlides->getCount());
     565             :     else
     566           0 :         maPageDescriptors.resize(0);
     567          63 : }
     568             : 
     569             : 
     570             : 
     571             : 
     572          63 : bool SlideSorterModel::IsReadOnly (void) const
     573             : {
     574         126 :     if (mrSlideSorter.GetViewShellBase() != NULL
     575          63 :         && mrSlideSorter.GetViewShellBase()->GetDocShell())
     576          63 :         return mrSlideSorter.GetViewShellBase()->GetDocShell()->IsReadOnly();
     577             :     else
     578           0 :         return true;
     579             : }
     580             : 
     581             : 
     582             : 
     583             : 
     584           0 : void SlideSorterModel::SaveCurrentSelection (void)
     585             : {
     586           0 :     PageEnumeration aPages (PageEnumerationProvider::CreateAllPagesEnumeration(*this));
     587           0 :     while (aPages.HasMoreElements())
     588             :     {
     589           0 :         SharedPageDescriptor pDescriptor (aPages.GetNextElement());
     590             :         pDescriptor->SetState(
     591             :             PageDescriptor::ST_WasSelected,
     592           0 :             pDescriptor->HasState(PageDescriptor::ST_Selected));
     593           0 :     }
     594           0 : }
     595             : 
     596             : 
     597             : 
     598             : 
     599           0 : Region SlideSorterModel::RestoreSelection (void)
     600             : {
     601           0 :     Region aRepaintRegion;
     602           0 :     PageEnumeration aPages (PageEnumerationProvider::CreateAllPagesEnumeration(*this));
     603           0 :     while (aPages.HasMoreElements())
     604             :     {
     605           0 :         SharedPageDescriptor pDescriptor (aPages.GetNextElement());
     606           0 :         if (pDescriptor->SetState(
     607             :             PageDescriptor::ST_Selected,
     608           0 :             pDescriptor->HasState(PageDescriptor::ST_WasSelected)))
     609             :         {
     610           0 :             aRepaintRegion.Union(pDescriptor->GetBoundingBox());
     611             :         }
     612           0 :     }
     613           0 :     return aRepaintRegion;
     614             : }
     615             : 
     616             : 
     617             : 
     618             : 
     619          60 : bool SlideSorterModel::NotifyPageEvent (const SdrPage* pSdrPage)
     620             : {
     621          60 :     ::osl::MutexGuard aGuard (maMutex);
     622             : 
     623          60 :     SdPage* pPage = const_cast<SdPage*>(dynamic_cast<const SdPage*>(pSdrPage));
     624          60 :     if (pPage == NULL)
     625           0 :         return false;
     626             : 
     627             :     // We are only interested in pages that are currently served by this
     628             :     // model.
     629          60 :     if (pPage->GetPageKind() != mePageKind)
     630          16 :         return false;
     631          44 :     if (pPage->IsMasterPage() != (meEditMode==EM_MASTERPAGE))
     632          33 :         return false;
     633             : 
     634          11 :     if (pPage->IsInserted())
     635          10 :         InsertSlide(pPage);
     636             :     else
     637           1 :         DeleteSlide(pPage);
     638          11 :     CheckModel(*this);
     639             : 
     640          11 :     return true;
     641             : }
     642             : 
     643             : 
     644             : 
     645             : 
     646          10 : void SlideSorterModel::InsertSlide (SdPage* pPage)
     647             : {
     648             :     // Find the index at which to insert the given page.
     649          10 :     sal_uInt16 nCoreIndex (pPage->GetPageNum());
     650          10 :     sal_Int32 nIndex (FromCoreIndex(nCoreIndex));
     651          10 :     if (pPage != GetPage(nIndex))
     652           0 :         return;
     653             : 
     654             :     // Check that the pages in the document before and after the given page
     655             :     // are present in this model.
     656          10 :     if (nIndex>0)
     657          10 :         if (GetPage(nIndex-1) != GetPageDescriptor(nIndex-1)->GetPage())
     658           0 :             return;
     659          10 :     if (size_t(nIndex)<maPageDescriptors.size()-1)
     660           1 :         if (GetPage(nIndex+1) != GetPageDescriptor(nIndex)->GetPage())
     661           0 :             return;
     662             : 
     663             :     // Insert the given page at index nIndex
     664             :     maPageDescriptors.insert(
     665          10 :         maPageDescriptors.begin()+nIndex,
     666             :         SharedPageDescriptor(
     667             :             new PageDescriptor (
     668          10 :                 Reference<drawing::XDrawPage>(mxSlides->getByIndex(nIndex),UNO_QUERY),
     669             :                 pPage,
     670          20 :                 nIndex)));
     671             : 
     672             :     // Update page indices.
     673          10 :     UpdateIndices(nIndex+1);
     674             : }
     675             : 
     676             : 
     677             : 
     678             : 
     679           1 : void SlideSorterModel::DeleteSlide (const SdPage* pPage)
     680             : {
     681           1 :     sal_Int32 nIndex(0);
     682             : 
     683             :     // Caution, GetIndex() may be negative since it uses GetPageNumber()-1
     684             :     // for calculation, so do this only when page is inserted, else the
     685             :     // GetPageNumber() will be zero and thus GetIndex() == -1
     686           1 :     if(pPage->IsInserted())
     687             :     {
     688           0 :         nIndex = GetIndex(pPage);
     689             :     }
     690             :     else
     691             :     {
     692             :         // if not inserted, search for page
     693           2 :         for(; nIndex < static_cast<sal_Int32>(maPageDescriptors.size()); nIndex++)
     694             :         {
     695           2 :             if(maPageDescriptors[nIndex]->GetPage() == pPage)
     696             :             {
     697           1 :                 break;
     698             :             }
     699             :         }
     700             :     }
     701             : 
     702           1 :     if(nIndex >= 0 && nIndex < static_cast<sal_Int32>(maPageDescriptors.size()))
     703             :     {
     704           1 :         if (maPageDescriptors[nIndex])
     705           1 :             if (maPageDescriptors[nIndex]->GetPage() != pPage)
     706           1 :                 return;
     707             : 
     708           1 :         maPageDescriptors.erase(maPageDescriptors.begin()+nIndex);
     709           1 :         UpdateIndices(nIndex);
     710             :     }
     711             : }
     712             : 
     713             : 
     714             : 
     715             : 
     716          11 : void SlideSorterModel::UpdateIndices (const sal_Int32 nFirstIndex)
     717             : {
     718          38 :     for (sal_Int32 nDescriptorIndex=0,nCount=maPageDescriptors.size();
     719             :          nDescriptorIndex<nCount;
     720             :          ++nDescriptorIndex)
     721             :     {
     722          27 :         SharedPageDescriptor& rpDescriptor (maPageDescriptors[nDescriptorIndex]);
     723          27 :         if (rpDescriptor)
     724             :         {
     725          27 :             if (nDescriptorIndex < nFirstIndex)
     726             :             {
     727          22 :                 if (rpDescriptor->GetPageIndex()!=nDescriptorIndex)
     728             :                 {
     729             :                     OSL_ASSERT(rpDescriptor->GetPageIndex()==nDescriptorIndex);
     730             :                 }
     731             :             }
     732             :             else
     733             :             {
     734           5 :                 rpDescriptor->SetPageIndex(nDescriptorIndex);
     735             :             }
     736             :         }
     737             :     }
     738          11 : }
     739             : 
     740             : 
     741             : 
     742             : 
     743         179 : SdPage* SlideSorterModel::GetPage (const sal_Int32 nSdIndex) const
     744             : {
     745         179 :     SdDrawDocument* pModel = const_cast<SlideSorterModel*>(this)->GetDocument();
     746         179 :     if (pModel != NULL)
     747             :     {
     748         179 :         if (meEditMode == EM_PAGE)
     749         179 :             return pModel->GetSdPage ((sal_uInt16)nSdIndex, mePageKind);
     750             :         else
     751           0 :             return pModel->GetMasterSdPage ((sal_uInt16)nSdIndex, mePageKind);
     752             :     }
     753             :     else
     754           0 :         return NULL;
     755             : }
     756             : 
     757             : 
     758             : } } } // end of namespace ::sd::slidesorter::model
     759             : 
     760             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10