LCOV - code coverage report
Current view: top level - sd/source/ui/slidesorter/controller - SlsSelectionObserver.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 9 57 15.8 %
Date: 2015-06-13 12:38:46 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()
      42             : {
      43           0 :     if (mpSelectionObserver)
      44           0 :         mpSelectionObserver->EndObservation();
      45           0 : }
      46             : 
      47           0 : void SelectionObserver::Context::Abort()
      48             : {
      49           0 :     if (mpSelectionObserver)
      50             :     {
      51           0 :         mpSelectionObserver->AbortObservation();
      52           0 :         mpSelectionObserver.reset();
      53             :     }
      54           0 : }
      55             : 
      56             : //===== SelectionObserver =====================================================
      57             : 
      58          64 : SelectionObserver::SelectionObserver (SlideSorter& rSlideSorter)
      59             :     : mrSlideSorter(rSlideSorter),
      60             :       mbIsOvservationActive(false),
      61             :       maInsertedPages(),
      62          64 :       maDeletedPages()
      63             : {
      64          64 : }
      65             : 
      66         128 : SelectionObserver::~SelectionObserver()
      67             : {
      68         128 : }
      69             : 
      70          11 : void SelectionObserver::NotifyPageEvent (const SdrPage* pSdrPage)
      71             : {
      72          11 :     if ( ! mbIsOvservationActive)
      73          22 :         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()
      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()
     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()
     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          66 : } } } // end of namespace ::sd::slidesorter::controller
     137             : 
     138             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11