LCOV - code coverage report
Current view: top level - sd/source/ui/slidesorter/model - SlideSorterModel.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 199 272 73.2 %
Date: 2012-08-25 Functions: 28 33 84.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 203 513 39.6 %

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

Generated by: LCOV version 1.10