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

Generated by: LCOV version 1.10