LCOV - code coverage report
Current view: top level - libreoffice/sd/source/ui/slidesorter/controller - SlsPageSelector.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 195 0.0 %
Date: 2012-12-27 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(false)
      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 == NULL)
     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             :         assert(nSelectionCount==mnSelectedPageCount);
     248             :     }
     249           0 : }
     250             : 
     251             : 
     252             : 
     253             : 
     254           0 : bool PageSelector::IsPageSelected (int nPageIndex)
     255             : {
     256           0 :     SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(nPageIndex));
     257           0 :     if (pDescriptor.get() != NULL)
     258           0 :         return pDescriptor->HasState(PageDescriptor::ST_Selected);
     259             :     else
     260           0 :         return false;
     261             : }
     262             : 
     263             : 
     264             : 
     265             : 
     266           0 : int PageSelector::GetPageCount (void) const
     267             : {
     268           0 :     return mrModel.GetPageCount();
     269             : }
     270             : 
     271             : 
     272             : 
     273             : 
     274           0 : int PageSelector::GetSelectedPageCount (void) const
     275             : {
     276           0 :     return mnSelectedPageCount;
     277             : }
     278             : 
     279             : 
     280             : 
     281             : 
     282           0 : SharedPageDescriptor PageSelector::GetSelectionAnchor (void) const
     283             : {
     284           0 :     return mpSelectionAnchor;
     285             : }
     286             : 
     287             : 
     288             : 
     289             : 
     290           0 : void PageSelector::CountSelectedPages (void)
     291             : {
     292           0 :     mnSelectedPageCount = 0;
     293             :     model::PageEnumeration aSelectedPages (
     294           0 :         model::PageEnumerationProvider::CreateSelectedPagesEnumeration(mrModel));
     295           0 :     while (aSelectedPages.HasMoreElements())
     296             :     {
     297           0 :         mnSelectedPageCount++;
     298           0 :         aSelectedPages.GetNextElement();
     299           0 :     }
     300           0 : }
     301             : 
     302             : 
     303             : 
     304             : 
     305           0 : void PageSelector::EnableBroadcasting (void)
     306             : {
     307           0 :     if (mnBroadcastDisableLevel > 0)
     308           0 :         mnBroadcastDisableLevel --;
     309           0 :     if (mnBroadcastDisableLevel==0 && mbSelectionChangeBroadcastPending)
     310             :     {
     311           0 :         mrController.GetSelectionManager()->SelectionHasChanged();
     312           0 :         mbSelectionChangeBroadcastPending = false;
     313             :     }
     314           0 : }
     315             : 
     316             : 
     317             : 
     318             : 
     319           0 : void PageSelector::DisableBroadcasting (void)
     320             : {
     321           0 :     mnBroadcastDisableLevel ++;
     322           0 : }
     323             : 
     324             : 
     325             : 
     326             : 
     327           0 : ::boost::shared_ptr<PageSelector::PageSelection> PageSelector::GetPageSelection (void) const
     328             : {
     329           0 :     ::boost::shared_ptr<PageSelection> pSelection (new PageSelection());
     330           0 :     pSelection->reserve(GetSelectedPageCount());
     331             : 
     332           0 :     int nPageCount = GetPageCount();
     333           0 :     for (int nIndex=0; nIndex<nPageCount; nIndex++)
     334             :     {
     335           0 :         SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(nIndex));
     336           0 :         if (pDescriptor.get()!=NULL && pDescriptor->HasState(PageDescriptor::ST_Selected))
     337           0 :             pSelection->push_back(pDescriptor->GetPage());
     338           0 :     }
     339             : 
     340           0 :     return pSelection;
     341             : }
     342             : 
     343             : 
     344             : 
     345             : 
     346           0 : void PageSelector::SetPageSelection (
     347             :     const ::boost::shared_ptr<PageSelection>& rpSelection,
     348             :     const bool bUpdateCurrentPage)
     349             : {
     350           0 :     PageSelection::const_iterator iPage;
     351           0 :     for (iPage=rpSelection->begin(); iPage!=rpSelection->end(); ++iPage)
     352           0 :         SelectPage(*iPage);
     353           0 :     if (bUpdateCurrentPage)
     354           0 :         UpdateCurrentPage();
     355           0 : }
     356             : 
     357             : 
     358             : 
     359             : 
     360           0 : void PageSelector::UpdateCurrentPage (const bool bUpdateOnlyWhenPending)
     361             : {
     362           0 :     if (mnUpdateLockCount > 0)
     363             :     {
     364           0 :         mbIsUpdateCurrentPagePending = true;
     365           0 :         return;
     366             :     }
     367             : 
     368           0 :     if ( ! mbIsUpdateCurrentPagePending && bUpdateOnlyWhenPending)
     369           0 :         return;
     370             : 
     371           0 :     mbIsUpdateCurrentPagePending = false;
     372             : 
     373             :     // Make the first selected page the current page.
     374           0 :     const sal_Int32 nPageCount (GetPageCount());
     375           0 :     for (sal_Int32 nIndex=0; nIndex<nPageCount; ++nIndex)
     376             :     {
     377           0 :         SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(nIndex));
     378           0 :         if (pDescriptor && pDescriptor->HasState(PageDescriptor::ST_Selected))
     379             :         {
     380             :             // Switching the current slide normally sets also the selection
     381             :             // to just the new current slide.  To prevent that, we store
     382             :             // (and at the end of this scope restore) the current selection.
     383           0 :             ::boost::shared_ptr<PageSelection> pSelection (GetPageSelection());
     384             : 
     385           0 :             mrController.GetCurrentSlideManager()->SwitchCurrentSlide(pDescriptor);
     386             : 
     387             :             // Restore the selection and prevent a recursive call to
     388             :             // UpdateCurrentPage().
     389           0 :             SetPageSelection(pSelection, false);
     390           0 :             return;
     391             :         }
     392           0 :     }
     393             : 
     394             :     // No page is selected.  Do not change the current slide.
     395             : }
     396             : 
     397             : 
     398             : 
     399             : 
     400             : //===== PageSelector::UpdateLock ==============================================
     401             : 
     402           0 : PageSelector::UpdateLock::UpdateLock (SlideSorter& rSlideSorter)
     403           0 :     : mpSelector(&rSlideSorter.GetController().GetPageSelector())
     404             : {
     405           0 :     ++mpSelector->mnUpdateLockCount;
     406           0 : }
     407             : 
     408             : 
     409             : 
     410             : 
     411           0 : PageSelector::UpdateLock::UpdateLock (PageSelector& rSelector)
     412           0 :     : mpSelector(&rSelector)
     413             : {
     414           0 :     ++mpSelector->mnUpdateLockCount;
     415           0 : }
     416             : 
     417             : 
     418             : 
     419             : 
     420           0 : PageSelector::UpdateLock::~UpdateLock (void)
     421             : {
     422           0 :     Release();
     423           0 : }
     424             : 
     425           0 : void PageSelector::UpdateLock::Release (void)
     426             : {
     427           0 :     if (mpSelector != NULL)
     428             :     {
     429           0 :         --mpSelector->mnUpdateLockCount;
     430             :         OSL_ASSERT(mpSelector->mnUpdateLockCount >= 0);
     431           0 :         if (mpSelector->mnUpdateLockCount == 0)
     432           0 :             mpSelector->UpdateCurrentPage(true);
     433             : 
     434           0 :         mpSelector = NULL;
     435             :     }
     436           0 : }
     437             : 
     438             : 
     439             : 
     440             : 
     441             : //===== PageSelector::BroadcastLock ==============================================
     442             : 
     443           0 : PageSelector::BroadcastLock::BroadcastLock (SlideSorter& rSlideSorter)
     444           0 :     : mrSelector(rSlideSorter.GetController().GetPageSelector())
     445             : {
     446           0 :     mrSelector.DisableBroadcasting();
     447           0 : }
     448             : 
     449             : 
     450             : 
     451             : 
     452           0 : PageSelector::BroadcastLock::BroadcastLock (PageSelector& rSelector)
     453           0 :     : mrSelector(rSelector)
     454             : {
     455           0 :     mrSelector.DisableBroadcasting();
     456           0 : }
     457             : 
     458             : 
     459             : 
     460             : 
     461           0 : PageSelector::BroadcastLock::~BroadcastLock (void)
     462             : {
     463           0 :     mrSelector.EnableBroadcasting();
     464           0 : }
     465             : 
     466             : } } } // end of namespace ::sd::slidesorter::controller
     467             : 
     468             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10