LCOV - code coverage report
Current view: top level - sd/source/ui/slidesorter/controller - SlsSelectionObserver.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 9 57 15.8 %
Date: 2014-11-03 Functions: 6 12 50.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             : #include "SlideSorter.hxx"
      21             : #include "controller/SlideSorterController.hxx"
      22             : #include "controller/SlsSelectionManager.hxx"
      23             : #include "controller/SlsSelectionObserver.hxx"
      24             : #include "controller/SlsPageSelector.hxx"
      25             : #include "controller/SlsFocusManager.hxx"
      26             : #include "model/SlideSorterModel.hxx"
      27             : #include "model/SlsPageDescriptor.hxx"
      28             : #include <svx/svdmodel.hxx>
      29             : #include "drawdoc.hxx"
      30             : 
      31             : namespace sd { namespace slidesorter { namespace controller {
      32             : 
      33           0 : SelectionObserver::Context::Context (SlideSorter& rSlideSorter)
      34             :     : mpSelectionObserver(
      35           0 :         rSlideSorter.GetController().GetSelectionManager()->GetSelectionObserver())
      36             : {
      37           0 :     if (mpSelectionObserver)
      38           0 :         mpSelectionObserver->StartObservation();
      39           0 : }
      40             : 
      41           0 : SelectionObserver::Context::~Context(void)
      42             : {
      43           0 :     if (mpSelectionObserver)
      44           0 :         mpSelectionObserver->EndObservation();
      45           0 : }
      46             : 
      47           0 : void SelectionObserver::Context::Abort(void)
      48             : {
      49           0 :     if (mpSelectionObserver)
      50             :     {
      51           0 :         mpSelectionObserver->AbortObservation();
      52           0 :         mpSelectionObserver.reset();
      53             :     }
      54           0 : }
      55             : 
      56             : //===== SelectionObserver =====================================================
      57             : 
      58         126 : SelectionObserver::SelectionObserver (SlideSorter& rSlideSorter)
      59             :     : mrSlideSorter(rSlideSorter),
      60             :       mbIsOvservationActive(false),
      61             :       maInsertedPages(),
      62         126 :       maDeletedPages()
      63             : {
      64         126 : }
      65             : 
      66         252 : SelectionObserver::~SelectionObserver (void)
      67             : {
      68         252 : }
      69             : 
      70          22 : void SelectionObserver::NotifyPageEvent (const SdrPage* pSdrPage)
      71             : {
      72          22 :     if ( ! mbIsOvservationActive)
      73          44 :         return;
      74             : 
      75           0 :     const SdPage* pPage = dynamic_cast<const SdPage*>(pSdrPage);
      76           0 :     if (pPage == NULL)
      77           0 :         return;
      78             : 
      79           0 :     if (pPage->IsInserted())
      80           0 :         maInsertedPages.push_back(pPage);
      81             :     else
      82             :     {
      83             :         ::std::vector<const SdPage*>::iterator iPage(
      84           0 :             ::std::find(maInsertedPages.begin(), maInsertedPages.end(), pPage));
      85           0 :         if (iPage != maInsertedPages.end())
      86           0 :             maInsertedPages.erase(iPage);
      87             : 
      88           0 :         maDeletedPages.push_back(pPage->GetPageNum());
      89             :     }
      90             : }
      91             : 
      92           0 : void SelectionObserver::StartObservation (void)
      93             : {
      94             :     OSL_ASSERT(!mbIsOvservationActive);
      95           0 :     maInsertedPages.clear();
      96           0 :     maDeletedPages.clear();
      97           0 :     mbIsOvservationActive = true;
      98           0 : }
      99             : 
     100           0 : void SelectionObserver::AbortObservation (void)
     101             : {
     102             :     OSL_ASSERT(mbIsOvservationActive);
     103           0 :     mbIsOvservationActive = false;
     104           0 :     maInsertedPages.clear();
     105           0 :     maDeletedPages.clear();
     106           0 : }
     107             : 
     108           0 : void SelectionObserver::EndObservation (void)
     109             : {
     110             :     OSL_ASSERT(mbIsOvservationActive);
     111           0 :     mbIsOvservationActive = false;
     112             : 
     113           0 :     PageSelector& rSelector (mrSlideSorter.GetController().GetPageSelector());
     114           0 :     PageSelector::UpdateLock aUpdateLock (mrSlideSorter);
     115           0 :     rSelector.DeselectAllPages();
     116           0 :     if ( ! maInsertedPages.empty())
     117             :     {
     118             :         // Select the inserted pages.
     119           0 :         for (::std::vector<const SdPage*>::const_iterator
     120           0 :                  iPage(maInsertedPages.begin()),
     121           0 :                  iEnd(maInsertedPages.end());
     122             :              iPage!=iEnd;
     123             :              ++iPage)
     124             :         {
     125           0 :             rSelector.SelectPage(*iPage);
     126             :         }
     127           0 :         maInsertedPages.clear();
     128             :     }
     129           0 :     maDeletedPages.clear();
     130             : 
     131           0 :     aUpdateLock.Release();
     132           0 :     mrSlideSorter.GetController().GetFocusManager().SetFocusedPageToCurrentPage();
     133             : 
     134           0 : }
     135             : 
     136         114 : } } } // end of namespace ::sd::slidesorter::controller
     137             : 
     138             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10