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

Generated by: LCOV version 1.10