LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sd/source/ui/slidesorter/controller - SlsPageSelector.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 157 196 80.1 %
Date: 2013-07-09 Functions: 24 30 80.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          65 : PageSelector::PageSelector (SlideSorter& rSlideSorter)
      53          65 :     : mrModel(rSlideSorter.GetModel()),
      54             :       mrSlideSorter(rSlideSorter),
      55          65 :       mrController(mrSlideSorter.GetController()),
      56             :       mnSelectedPageCount(0),
      57             :       mnBroadcastDisableLevel(0),
      58             :       mbSelectionChangeBroadcastPending(false),
      59             :       mpMostRecentlySelectedPage(),
      60             :       mpSelectionAnchor(),
      61             :       mpCurrentPage(),
      62             :       mnUpdateLockCount(0),
      63         195 :       mbIsUpdateCurrentPagePending(false)
      64             : {
      65          65 :     CountSelectedPages ();
      66          65 : }
      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         134 : void PageSelector::DeselectAllPages (void)
      85             : {
      86         134 :     VisibleAreaManager::TemporaryDisabler aDisabler (mrSlideSorter);
      87         268 :     PageSelector::UpdateLock aLock (*this);
      88             : 
      89         134 :     int nPageCount = mrModel.GetPageCount();
      90         272 :     for (int nPageIndex=0; nPageIndex<nPageCount; nPageIndex++)
      91         138 :         DeselectPage(nPageIndex);
      92             : 
      93             :     DBG_ASSERT (mnSelectedPageCount==0,
      94             :         "PageSelector::DeselectAllPages: the selected pages counter is not 0");
      95         134 :     mnSelectedPageCount = 0;
      96         268 :     mpSelectionAnchor.reset();
      97         134 : }
      98             : 
      99             : 
     100             : 
     101             : 
     102          65 : void PageSelector::GetCoreSelection (void)
     103             : {
     104          65 :     PageSelector::UpdateLock aLock (*this);
     105             : 
     106          65 :     bool bSelectionHasChanged (true);
     107          65 :     mnSelectedPageCount = 0;
     108             :     model::PageEnumeration aAllPages (
     109         130 :         model::PageEnumerationProvider::CreateAllPagesEnumeration(mrModel));
     110         130 :     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          65 :     if (bSelectionHasChanged)
     125             :     {
     126          65 :         if (mnBroadcastDisableLevel > 0)
     127           0 :             mbSelectionChangeBroadcastPending = true;
     128             :         else
     129          65 :             mrController.GetSelectionManager()->SelectionHasChanged();
     130          65 :     }
     131          65 : }
     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           4 : void PageSelector::SelectPage (int nPageIndex)
     151             : {
     152           4 :     SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(nPageIndex));
     153           4 :     if (pDescriptor.get() != NULL)
     154           4 :         SelectPage(pDescriptor);
     155           4 : }
     156             : 
     157             : 
     158             : 
     159             : 
     160         134 : void PageSelector::SelectPage (const SdPage* pPage)
     161             : {
     162         134 :     const sal_Int32 nPageIndex (mrModel.GetIndex(pPage));
     163         134 :     SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(nPageIndex));
     164         134 :     if (pDescriptor.get()!=NULL && pDescriptor->GetPage()==pPage)
     165         134 :         SelectPage(pDescriptor);
     166         134 : }
     167             : 
     168             : 
     169             : 
     170             : 
     171         272 : void PageSelector::SelectPage (const SharedPageDescriptor& rpDescriptor)
     172             : {
     173         544 :     if (rpDescriptor.get()!=NULL
     174         272 :         && mrSlideSorter.GetView().SetState(rpDescriptor, PageDescriptor::ST_Selected, true))
     175             :     {
     176         134 :         ++mnSelectedPageCount;
     177         134 :         mrSlideSorter.GetController().GetVisibleAreaManager().RequestVisible(rpDescriptor,true);
     178         134 :         mrSlideSorter.GetView().RequestRepaint(rpDescriptor);
     179             : 
     180         134 :         mpMostRecentlySelectedPage = rpDescriptor;
     181         134 :         if (mpSelectionAnchor == 0)
     182         134 :             mpSelectionAnchor = rpDescriptor;
     183             : 
     184         134 :         if (mnBroadcastDisableLevel > 0)
     185          65 :             mbSelectionChangeBroadcastPending = true;
     186             :         else
     187          69 :             mrController.GetSelectionManager()->SelectionHasChanged();
     188         134 :         UpdateCurrentPage();
     189             : 
     190         134 :         CheckConsistency();
     191             :     }
     192         272 : }
     193             : 
     194             : 
     195             : 
     196             : 
     197         138 : void PageSelector::DeselectPage (
     198             :     int nPageIndex,
     199             :     const bool bUpdateCurrentPage)
     200             : {
     201         138 :     model::SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(nPageIndex));
     202         138 :     if (pDescriptor.get() != NULL)
     203         138 :         DeselectPage(pDescriptor, bUpdateCurrentPage);
     204         138 : }
     205             : 
     206             : 
     207             : 
     208             : 
     209         138 : void PageSelector::DeselectPage (
     210             :     const SharedPageDescriptor& rpDescriptor,
     211             :     const bool bUpdateCurrentPage)
     212             : {
     213         276 :     if (rpDescriptor.get()!=NULL
     214         138 :         && mrSlideSorter.GetView().SetState(rpDescriptor, PageDescriptor::ST_Selected, false))
     215             :     {
     216         134 :         --mnSelectedPageCount;
     217         134 :         mrSlideSorter.GetController().GetVisibleAreaManager().RequestVisible(rpDescriptor);
     218         134 :         mrSlideSorter.GetView().RequestRepaint(rpDescriptor);
     219         134 :         if (mpMostRecentlySelectedPage == rpDescriptor)
     220          69 :             mpMostRecentlySelectedPage.reset();
     221         134 :         if (mnBroadcastDisableLevel > 0)
     222          65 :             mbSelectionChangeBroadcastPending = true;
     223             :         else
     224          69 :             mrController.GetSelectionManager()->SelectionHasChanged();
     225         134 :         if (bUpdateCurrentPage)
     226         134 :             UpdateCurrentPage();
     227             : 
     228         134 :         CheckConsistency();
     229             :     }
     230         138 : }
     231             : 
     232             : 
     233             : 
     234             : 
     235         268 : void PageSelector::CheckConsistency (void) const
     236             : {
     237         268 :     int nSelectionCount (0);
     238         544 :     for (int nPageIndex=0,nPageCount=mrModel.GetPageCount(); nPageIndex<nPageCount; nPageIndex++)
     239             :     {
     240         276 :         SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(nPageIndex));
     241             :         assert(pDescriptor);
     242         276 :         if (pDescriptor->HasState(PageDescriptor::ST_Selected))
     243         134 :             ++nSelectionCount;
     244         276 :     }
     245         268 :     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         268 : }
     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         402 : int PageSelector::GetPageCount (void) const
     271             : {
     272         402 :     return mrModel.GetPageCount();
     273             : }
     274             : 
     275             : 
     276             : 
     277             : 
     278         134 : int PageSelector::GetSelectedPageCount (void) const
     279             : {
     280         134 :     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         130 : void PageSelector::CountSelectedPages (void)
     295             : {
     296         130 :     mnSelectedPageCount = 0;
     297             :     model::PageEnumeration aSelectedPages (
     298         130 :         model::PageEnumerationProvider::CreateSelectedPagesEnumeration(mrModel));
     299         325 :     while (aSelectedPages.HasMoreElements())
     300             :     {
     301          65 :         mnSelectedPageCount++;
     302          65 :         aSelectedPages.GetNextElement();
     303         130 :     }
     304         130 : }
     305             : 
     306             : 
     307             : 
     308             : 
     309          65 : void PageSelector::EnableBroadcasting (void)
     310             : {
     311          65 :     if (mnBroadcastDisableLevel > 0)
     312          65 :         mnBroadcastDisableLevel --;
     313          65 :     if (mnBroadcastDisableLevel==0 && mbSelectionChangeBroadcastPending)
     314             :     {
     315          65 :         mrController.GetSelectionManager()->SelectionHasChanged();
     316          65 :         mbSelectionChangeBroadcastPending = false;
     317             :     }
     318          65 : }
     319             : 
     320             : 
     321             : 
     322             : 
     323          65 : void PageSelector::DisableBroadcasting (void)
     324             : {
     325          65 :     mnBroadcastDisableLevel ++;
     326          65 : }
     327             : 
     328             : 
     329             : 
     330             : 
     331         134 : ::boost::shared_ptr<PageSelector::PageSelection> PageSelector::GetPageSelection (void) const
     332             : {
     333         134 :     ::boost::shared_ptr<PageSelection> pSelection (new PageSelection());
     334         134 :     pSelection->reserve(GetSelectedPageCount());
     335             : 
     336         134 :     int nPageCount = GetPageCount();
     337         272 :     for (int nIndex=0; nIndex<nPageCount; nIndex++)
     338             :     {
     339         138 :         SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(nIndex));
     340         138 :         if (pDescriptor.get()!=NULL && pDescriptor->HasState(PageDescriptor::ST_Selected))
     341         134 :             pSelection->push_back(pDescriptor->GetPage());
     342         138 :     }
     343             : 
     344         134 :     return pSelection;
     345             : }
     346             : 
     347             : 
     348             : 
     349             : 
     350         134 : void PageSelector::SetPageSelection (
     351             :     const ::boost::shared_ptr<PageSelection>& rpSelection,
     352             :     const bool bUpdateCurrentPage)
     353             : {
     354         134 :     PageSelection::const_iterator iPage;
     355         268 :     for (iPage=rpSelection->begin(); iPage!=rpSelection->end(); ++iPage)
     356         134 :         SelectPage(*iPage);
     357         134 :     if (bUpdateCurrentPage)
     358           0 :         UpdateCurrentPage();
     359         134 : }
     360             : 
     361             : 
     362             : 
     363             : 
     364         467 : void PageSelector::UpdateCurrentPage (const bool bUpdateOnlyWhenPending)
     365             : {
     366         467 :     if (mnUpdateLockCount > 0)
     367             :     {
     368         134 :         mbIsUpdateCurrentPagePending = true;
     369         134 :         return;
     370             :     }
     371             : 
     372         333 :     if ( ! mbIsUpdateCurrentPagePending && bUpdateOnlyWhenPending)
     373          65 :         return;
     374             : 
     375         268 :     mbIsUpdateCurrentPagePending = false;
     376             : 
     377             :     // Make the first selected page the current page.
     378         268 :     const sal_Int32 nPageCount (GetPageCount());
     379         408 :     for (sal_Int32 nIndex=0; nIndex<nPageCount; ++nIndex)
     380             :     {
     381         274 :         SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(nIndex));
     382         274 :         if (pDescriptor && pDescriptor->HasState(PageDescriptor::ST_Selected))
     383             :         {
     384             :             // Switching the current slide normally sets also the selection
     385             :             // to just the new current slide.  To prevent that, we store
     386             :             // (and at the end of this scope restore) the current selection.
     387         134 :             ::boost::shared_ptr<PageSelection> pSelection (GetPageSelection());
     388             : 
     389         134 :             mrController.GetCurrentSlideManager()->SwitchCurrentSlide(pDescriptor);
     390             : 
     391             :             // Restore the selection and prevent a recursive call to
     392             :             // UpdateCurrentPage().
     393         134 :             SetPageSelection(pSelection, false);
     394         134 :             return;
     395             :         }
     396         140 :     }
     397             : 
     398             :     // No page is selected.  Do not change the current slide.
     399             : }
     400             : 
     401             : 
     402             : 
     403             : 
     404             : //===== PageSelector::UpdateLock ==============================================
     405             : 
     406           0 : PageSelector::UpdateLock::UpdateLock (SlideSorter& rSlideSorter)
     407           0 :     : mpSelector(&rSlideSorter.GetController().GetPageSelector())
     408             : {
     409           0 :     ++mpSelector->mnUpdateLockCount;
     410           0 : }
     411             : 
     412             : 
     413             : 
     414             : 
     415         199 : PageSelector::UpdateLock::UpdateLock (PageSelector& rSelector)
     416         199 :     : mpSelector(&rSelector)
     417             : {
     418         199 :     ++mpSelector->mnUpdateLockCount;
     419         199 : }
     420             : 
     421             : 
     422             : 
     423             : 
     424         199 : PageSelector::UpdateLock::~UpdateLock (void)
     425             : {
     426         199 :     Release();
     427         199 : }
     428             : 
     429         199 : void PageSelector::UpdateLock::Release (void)
     430             : {
     431         199 :     if (mpSelector != NULL)
     432             :     {
     433         199 :         --mpSelector->mnUpdateLockCount;
     434             :         OSL_ASSERT(mpSelector->mnUpdateLockCount >= 0);
     435         199 :         if (mpSelector->mnUpdateLockCount == 0)
     436         199 :             mpSelector->UpdateCurrentPage(true);
     437             : 
     438         199 :         mpSelector = NULL;
     439             :     }
     440         199 : }
     441             : 
     442             : 
     443             : 
     444             : 
     445             : //===== PageSelector::BroadcastLock ==============================================
     446             : 
     447           0 : PageSelector::BroadcastLock::BroadcastLock (SlideSorter& rSlideSorter)
     448           0 :     : mrSelector(rSlideSorter.GetController().GetPageSelector())
     449             : {
     450           0 :     mrSelector.DisableBroadcasting();
     451           0 : }
     452             : 
     453             : 
     454             : 
     455             : 
     456          65 : PageSelector::BroadcastLock::BroadcastLock (PageSelector& rSelector)
     457          65 :     : mrSelector(rSelector)
     458             : {
     459          65 :     mrSelector.DisableBroadcasting();
     460          65 : }
     461             : 
     462             : 
     463             : 
     464             : 
     465          65 : PageSelector::BroadcastLock::~BroadcastLock (void)
     466             : {
     467          65 :     mrSelector.EnableBroadcasting();
     468          65 : }
     469             : 
     470          33 : } } } // end of namespace ::sd::slidesorter::controller
     471             : 
     472             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10