LCOV - code coverage report
Current view: top level - sd/source/ui/slidesorter/controller - SlsPageSelector.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 203 0.0 %
Date: 2014-04-14 Functions: 0 28 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 "controller/SlsPageSelector.hxx"
      22             : 
      23             : #include "SlideSorter.hxx"
      24             : #include "SlideSorterViewShell.hxx"
      25             : #include "controller/SlideSorterController.hxx"
      26             : #include "controller/SlsSelectionManager.hxx"
      27             : #include "controller/SlsAnimator.hxx"
      28             : #include "controller/SlsCurrentSlideManager.hxx"
      29             : #include "controller/SlsVisibleAreaManager.hxx"
      30             : #include "model/SlsPageDescriptor.hxx"
      31             : #include "model/SlsPageEnumerationProvider.hxx"
      32             : #include "model/SlideSorterModel.hxx"
      33             : #include "view/SlideSorterView.hxx"
      34             : 
      35             : #include "sdpage.hxx"
      36             : #include "ViewShell.hxx"
      37             : #include "DrawViewShell.hxx"
      38             : #include "ViewShellBase.hxx"
      39             : #include <com/sun/star/drawing/XDrawView.hpp>
      40             : #include <com/sun/star/beans/XPropertySet.hpp>
      41             : #include <boost/shared_ptr.hpp>
      42             : 
      43             : 
      44             : using namespace ::com::sun::star;
      45             : using namespace ::com::sun::star::uno;
      46             : using namespace ::sd::slidesorter::model;
      47             : using namespace ::sd::slidesorter::view;
      48             : 
      49             : 
      50             : namespace sd { namespace slidesorter { namespace controller {
      51             : 
      52           0 : PageSelector::PageSelector (SlideSorter& rSlideSorter)
      53           0 :     : mrModel(rSlideSorter.GetModel()),
      54             :       mrSlideSorter(rSlideSorter),
      55           0 :       mrController(mrSlideSorter.GetController()),
      56             :       mnSelectedPageCount(0),
      57             :       mnBroadcastDisableLevel(0),
      58             :       mbSelectionChangeBroadcastPending(false),
      59             :       mpMostRecentlySelectedPage(),
      60             :       mpSelectionAnchor(),
      61             :       mpCurrentPage(),
      62             :       mnUpdateLockCount(0),
      63           0 :       mbIsUpdateCurrentPagePending(true)
      64             : {
      65           0 :     CountSelectedPages ();
      66           0 : }
      67             : 
      68             : 
      69             : 
      70             : 
      71           0 : void PageSelector::SelectAllPages (void)
      72             : {
      73           0 :     VisibleAreaManager::TemporaryDisabler aDisabler (mrSlideSorter);
      74           0 :     PageSelector::UpdateLock aLock (*this);
      75             : 
      76           0 :     int nPageCount = mrModel.GetPageCount();
      77           0 :     for (int nPageIndex=0; nPageIndex<nPageCount; nPageIndex++)
      78           0 :         SelectPage(nPageIndex);
      79           0 : }
      80             : 
      81             : 
      82             : 
      83             : 
      84           0 : void PageSelector::DeselectAllPages (void)
      85             : {
      86           0 :     VisibleAreaManager::TemporaryDisabler aDisabler (mrSlideSorter);
      87           0 :     PageSelector::UpdateLock aLock (*this);
      88             : 
      89           0 :     int nPageCount = mrModel.GetPageCount();
      90           0 :     for (int nPageIndex=0; nPageIndex<nPageCount; nPageIndex++)
      91           0 :         DeselectPage(nPageIndex);
      92             : 
      93             :     DBG_ASSERT (mnSelectedPageCount==0,
      94             :         "PageSelector::DeselectAllPages: the selected pages counter is not 0");
      95           0 :     mnSelectedPageCount = 0;
      96           0 :     mpSelectionAnchor.reset();
      97           0 : }
      98             : 
      99             : 
     100             : 
     101             : 
     102           0 : void PageSelector::GetCoreSelection (void)
     103             : {
     104           0 :     PageSelector::UpdateLock aLock (*this);
     105             : 
     106           0 :     bool bSelectionHasChanged (true);
     107           0 :     mnSelectedPageCount = 0;
     108             :     model::PageEnumeration aAllPages (
     109           0 :         model::PageEnumerationProvider::CreateAllPagesEnumeration(mrModel));
     110           0 :     while (aAllPages.HasMoreElements())
     111             :     {
     112           0 :         model::SharedPageDescriptor pDescriptor (aAllPages.GetNextElement());
     113           0 :         if (pDescriptor->GetCoreSelection())
     114             :         {
     115           0 :             mrSlideSorter.GetController().GetVisibleAreaManager().RequestVisible(pDescriptor);
     116           0 :             mrSlideSorter.GetView().RequestRepaint(pDescriptor);
     117           0 :             bSelectionHasChanged = true;
     118             :         }
     119             : 
     120           0 :         if (pDescriptor->HasState(PageDescriptor::ST_Selected))
     121           0 :             mnSelectedPageCount++;
     122           0 :     }
     123             : 
     124           0 :     if (bSelectionHasChanged)
     125             :     {
     126           0 :         if (mnBroadcastDisableLevel > 0)
     127           0 :             mbSelectionChangeBroadcastPending = true;
     128             :         else
     129           0 :             mrController.GetSelectionManager()->SelectionHasChanged();
     130           0 :     }
     131           0 : }
     132             : 
     133             : 
     134             : 
     135             : 
     136           0 : void PageSelector::SetCoreSelection (void)
     137             : {
     138             :     model::PageEnumeration aAllPages (
     139           0 :         model::PageEnumerationProvider::CreateAllPagesEnumeration(mrModel));
     140           0 :     while (aAllPages.HasMoreElements())
     141             :     {
     142           0 :         model::SharedPageDescriptor pDescriptor (aAllPages.GetNextElement());
     143           0 :         pDescriptor->SetCoreSelection();
     144           0 :     }
     145           0 : }
     146             : 
     147             : 
     148             : 
     149             : 
     150           0 : void PageSelector::SelectPage (int nPageIndex)
     151             : {
     152           0 :     SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(nPageIndex));
     153           0 :     if (pDescriptor.get() != NULL)
     154           0 :         SelectPage(pDescriptor);
     155           0 : }
     156             : 
     157             : 
     158             : 
     159             : 
     160           0 : void PageSelector::SelectPage (const SdPage* pPage)
     161             : {
     162           0 :     const sal_Int32 nPageIndex (mrModel.GetIndex(pPage));
     163           0 :     SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(nPageIndex));
     164           0 :     if (pDescriptor.get()!=NULL && pDescriptor->GetPage()==pPage)
     165           0 :         SelectPage(pDescriptor);
     166           0 : }
     167             : 
     168             : 
     169             : 
     170             : 
     171           0 : void PageSelector::SelectPage (const SharedPageDescriptor& rpDescriptor)
     172             : {
     173           0 :     if (rpDescriptor.get()!=NULL
     174           0 :         && mrSlideSorter.GetView().SetState(rpDescriptor, PageDescriptor::ST_Selected, true))
     175             :     {
     176           0 :         ++mnSelectedPageCount;
     177           0 :         mrSlideSorter.GetController().GetVisibleAreaManager().RequestVisible(rpDescriptor,true);
     178           0 :         mrSlideSorter.GetView().RequestRepaint(rpDescriptor);
     179             : 
     180           0 :         mpMostRecentlySelectedPage = rpDescriptor;
     181           0 :         if (mpSelectionAnchor == 0)
     182           0 :             mpSelectionAnchor = rpDescriptor;
     183             : 
     184           0 :         if (mnBroadcastDisableLevel > 0)
     185           0 :             mbSelectionChangeBroadcastPending = true;
     186             :         else
     187           0 :             mrController.GetSelectionManager()->SelectionHasChanged();
     188           0 :         UpdateCurrentPage();
     189             : 
     190           0 :         CheckConsistency();
     191             :     }
     192           0 : }
     193             : 
     194             : 
     195             : 
     196             : 
     197           0 : void PageSelector::DeselectPage (
     198             :     int nPageIndex,
     199             :     const bool bUpdateCurrentPage)
     200             : {
     201           0 :     model::SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(nPageIndex));
     202           0 :     if (pDescriptor.get() != NULL)
     203           0 :         DeselectPage(pDescriptor, bUpdateCurrentPage);
     204           0 : }
     205             : 
     206             : 
     207             : 
     208             : 
     209           0 : void PageSelector::DeselectPage (
     210             :     const SharedPageDescriptor& rpDescriptor,
     211             :     const bool bUpdateCurrentPage)
     212             : {
     213           0 :     if (rpDescriptor.get()!=NULL
     214           0 :         && mrSlideSorter.GetView().SetState(rpDescriptor, PageDescriptor::ST_Selected, false))
     215             :     {
     216           0 :         --mnSelectedPageCount;
     217           0 :         mrSlideSorter.GetController().GetVisibleAreaManager().RequestVisible(rpDescriptor);
     218           0 :         mrSlideSorter.GetView().RequestRepaint(rpDescriptor);
     219           0 :         if (mpMostRecentlySelectedPage == rpDescriptor)
     220           0 :             mpMostRecentlySelectedPage.reset();
     221           0 :         if (mnBroadcastDisableLevel > 0)
     222           0 :             mbSelectionChangeBroadcastPending = true;
     223             :         else
     224           0 :             mrController.GetSelectionManager()->SelectionHasChanged();
     225           0 :         if (bUpdateCurrentPage)
     226           0 :             UpdateCurrentPage();
     227             : 
     228           0 :         CheckConsistency();
     229             :     }
     230           0 : }
     231             : 
     232             : 
     233             : 
     234             : 
     235           0 : void PageSelector::CheckConsistency (void) const
     236             : {
     237           0 :     int nSelectionCount (0);
     238           0 :     for (int nPageIndex=0,nPageCount=mrModel.GetPageCount(); nPageIndex<nPageCount; nPageIndex++)
     239             :     {
     240           0 :         SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(nPageIndex));
     241             :         assert(pDescriptor);
     242           0 :         if (pDescriptor->HasState(PageDescriptor::ST_Selected))
     243           0 :             ++nSelectionCount;
     244           0 :     }
     245           0 :     if (nSelectionCount!=mnSelectedPageCount)
     246             :     {
     247             :         // #i120020# The former call to assert(..) internally calls
     248             :         // SlideSorterModel::GetPageDescriptor which will crash in this situation
     249             :         // (only in non-pro code). All what is wanted there is to assert it (the
     250             :         // error is already detected), so do this directly.
     251             :         OSL_ENSURE(false, "PageSelector: Consistency error (!)");
     252             :     }
     253           0 : }
     254             : 
     255             : 
     256             : 
     257             : 
     258           0 : bool PageSelector::IsPageSelected (int nPageIndex)
     259             : {
     260           0 :     SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(nPageIndex));
     261           0 :     if (pDescriptor.get() != NULL)
     262           0 :         return pDescriptor->HasState(PageDescriptor::ST_Selected);
     263             :     else
     264           0 :         return false;
     265             : }
     266             : 
     267             : 
     268             : 
     269             : 
     270           0 : int PageSelector::GetPageCount (void) const
     271             : {
     272           0 :     return mrModel.GetPageCount();
     273             : }
     274             : 
     275             : 
     276             : 
     277             : 
     278           0 : int PageSelector::GetSelectedPageCount (void) const
     279             : {
     280           0 :     return mnSelectedPageCount;
     281             : }
     282             : 
     283             : 
     284             : 
     285             : 
     286           0 : SharedPageDescriptor PageSelector::GetSelectionAnchor (void) const
     287             : {
     288           0 :     return mpSelectionAnchor;
     289             : }
     290             : 
     291             : 
     292             : 
     293             : 
     294           0 : void PageSelector::CountSelectedPages (void)
     295             : {
     296           0 :     mnSelectedPageCount = 0;
     297             :     model::PageEnumeration aSelectedPages (
     298           0 :         model::PageEnumerationProvider::CreateSelectedPagesEnumeration(mrModel));
     299           0 :     while (aSelectedPages.HasMoreElements())
     300             :     {
     301           0 :         mnSelectedPageCount++;
     302           0 :         aSelectedPages.GetNextElement();
     303           0 :     }
     304           0 : }
     305             : 
     306             : 
     307             : 
     308             : 
     309           0 : void PageSelector::EnableBroadcasting (void)
     310             : {
     311           0 :     if (mnBroadcastDisableLevel > 0)
     312           0 :         mnBroadcastDisableLevel --;
     313           0 :     if (mnBroadcastDisableLevel==0 && mbSelectionChangeBroadcastPending)
     314             :     {
     315           0 :         mrController.GetSelectionManager()->SelectionHasChanged();
     316           0 :         mbSelectionChangeBroadcastPending = false;
     317             :     }
     318           0 : }
     319             : 
     320             : 
     321             : 
     322             : 
     323           0 : void PageSelector::DisableBroadcasting (void)
     324             : {
     325           0 :     mnBroadcastDisableLevel ++;
     326           0 : }
     327             : 
     328             : 
     329             : 
     330             : 
     331           0 : ::boost::shared_ptr<PageSelector::PageSelection> PageSelector::GetPageSelection (void) const
     332             : {
     333           0 :     ::boost::shared_ptr<PageSelection> pSelection (new PageSelection());
     334           0 :     pSelection->reserve(GetSelectedPageCount());
     335             : 
     336           0 :     int nPageCount = GetPageCount();
     337           0 :     for (int nIndex=0; nIndex<nPageCount; nIndex++)
     338             :     {
     339           0 :         SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(nIndex));
     340           0 :         if (pDescriptor.get()!=NULL && pDescriptor->HasState(PageDescriptor::ST_Selected))
     341           0 :             pSelection->push_back(pDescriptor->GetPage());
     342           0 :     }
     343             : 
     344           0 :     return pSelection;
     345             : }
     346             : 
     347             : 
     348             : 
     349             : 
     350           0 : void PageSelector::SetPageSelection (
     351             :     const ::boost::shared_ptr<PageSelection>& rpSelection,
     352             :     const bool bUpdateCurrentPage)
     353             : {
     354           0 :     PageSelection::const_iterator iPage;
     355           0 :     for (iPage=rpSelection->begin(); iPage!=rpSelection->end(); ++iPage)
     356           0 :         SelectPage(*iPage);
     357           0 :     if (bUpdateCurrentPage)
     358           0 :         UpdateCurrentPage();
     359           0 : }
     360             : 
     361             : 
     362             : 
     363             : 
     364           0 : void PageSelector::UpdateCurrentPage (const bool bUpdateOnlyWhenPending)
     365             : {
     366           0 :     if (mnUpdateLockCount > 0)
     367             :     {
     368           0 :         mbIsUpdateCurrentPagePending = true;
     369           0 :         return;
     370             :     }
     371             : 
     372           0 :     if ( ! mbIsUpdateCurrentPagePending && bUpdateOnlyWhenPending)
     373           0 :         return;
     374             : 
     375           0 :     mbIsUpdateCurrentPagePending = false;
     376             : 
     377             :     // Make the first selected page the current page.
     378           0 :     SharedPageDescriptor pCurrentPageDescriptor;
     379           0 :     const sal_Int32 nPageCount (GetPageCount());
     380           0 :     for (sal_Int32 nIndex=0; nIndex<nPageCount; ++nIndex)
     381             :     {
     382           0 :         SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(nIndex));
     383           0 :         if ( ! pDescriptor)
     384           0 :             continue;
     385           0 :         if (pDescriptor->HasState(PageDescriptor::ST_Selected))
     386             :         {
     387           0 :             pCurrentPageDescriptor = pDescriptor;
     388           0 :             break;
     389             :         }
     390           0 :     }
     391           0 :     if ( ! pCurrentPageDescriptor && nPageCount>0)
     392             :     {
     393             :         // No page is selected.  Make the first slide the current page.
     394           0 :         pCurrentPageDescriptor = mrModel.GetPageDescriptor(0);
     395             :     }
     396             : 
     397           0 :     if (pCurrentPageDescriptor)
     398             :     {
     399             :         // Switching the current slide normally sets also the
     400             :         // selection to just the new current slide.  To prevent that,
     401             :         // we store (and at the end of this scope restore) the current
     402             :         // selection.
     403           0 :         ::boost::shared_ptr<PageSelection> pSelection (GetPageSelection());
     404             : 
     405           0 :         mrController.GetCurrentSlideManager()->SwitchCurrentSlide(pCurrentPageDescriptor);
     406             : 
     407             :         // Restore the selection and prevent a recursive call to
     408             :         // UpdateCurrentPage().
     409           0 :         SetPageSelection(pSelection, false);
     410           0 :     }
     411             : }
     412             : 
     413             : 
     414             : 
     415             : 
     416             : //===== PageSelector::UpdateLock ==============================================
     417             : 
     418           0 : PageSelector::UpdateLock::UpdateLock (SlideSorter& rSlideSorter)
     419           0 :     : mpSelector(&rSlideSorter.GetController().GetPageSelector())
     420             : {
     421           0 :     ++mpSelector->mnUpdateLockCount;
     422           0 : }
     423             : 
     424             : 
     425             : 
     426             : 
     427           0 : PageSelector::UpdateLock::UpdateLock (PageSelector& rSelector)
     428           0 :     : mpSelector(&rSelector)
     429             : {
     430           0 :     ++mpSelector->mnUpdateLockCount;
     431           0 : }
     432             : 
     433             : 
     434             : 
     435             : 
     436           0 : PageSelector::UpdateLock::~UpdateLock (void)
     437             : {
     438           0 :     Release();
     439           0 : }
     440             : 
     441           0 : void PageSelector::UpdateLock::Release (void)
     442             : {
     443           0 :     if (mpSelector != NULL)
     444             :     {
     445           0 :         --mpSelector->mnUpdateLockCount;
     446             :         OSL_ASSERT(mpSelector->mnUpdateLockCount >= 0);
     447           0 :         if (mpSelector->mnUpdateLockCount == 0)
     448           0 :             mpSelector->UpdateCurrentPage(true);
     449             : 
     450           0 :         mpSelector = NULL;
     451             :     }
     452           0 : }
     453             : 
     454             : 
     455             : 
     456             : 
     457             : //===== PageSelector::BroadcastLock ==============================================
     458             : 
     459           0 : PageSelector::BroadcastLock::BroadcastLock (SlideSorter& rSlideSorter)
     460           0 :     : mrSelector(rSlideSorter.GetController().GetPageSelector())
     461             : {
     462           0 :     mrSelector.DisableBroadcasting();
     463           0 : }
     464             : 
     465             : 
     466             : 
     467             : 
     468           0 : PageSelector::BroadcastLock::BroadcastLock (PageSelector& rSelector)
     469           0 :     : mrSelector(rSelector)
     470             : {
     471           0 :     mrSelector.DisableBroadcasting();
     472           0 : }
     473             : 
     474             : 
     475             : 
     476             : 
     477           0 : PageSelector::BroadcastLock::~BroadcastLock (void)
     478             : {
     479           0 :     mrSelector.EnableBroadcasting();
     480           0 : }
     481             : 
     482             : } } } // end of namespace ::sd::slidesorter::controller
     483             : 
     484             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10