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

Generated by: LCOV version 1.11