LCOV - code coverage report
Current view: top level - sd/source/ui/slidesorter/controller - SlsSelectionManager.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 120 0.0 %
Date: 2014-04-14 Functions: 0 11 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/SlsSelectionManager.hxx"
      22             : 
      23             : #include "SlideSorter.hxx"
      24             : #include "SlsCommand.hxx"
      25             : #include "controller/SlideSorterController.hxx"
      26             : #include "controller/SlsAnimator.hxx"
      27             : #include "controller/SlsAnimationFunction.hxx"
      28             : #include "controller/SlsCurrentSlideManager.hxx"
      29             : #include "controller/SlsFocusManager.hxx"
      30             : #include "controller/SlsPageSelector.hxx"
      31             : #include "controller/SlsProperties.hxx"
      32             : #include "controller/SlsScrollBarManager.hxx"
      33             : #include "controller/SlsSlotManager.hxx"
      34             : #include "controller/SlsSelectionObserver.hxx"
      35             : #include "model/SlideSorterModel.hxx"
      36             : #include "model/SlsPageEnumerationProvider.hxx"
      37             : #include "model/SlsPageDescriptor.hxx"
      38             : #include "view/SlideSorterView.hxx"
      39             : #include "view/SlsLayouter.hxx"
      40             : #include "drawdoc.hxx"
      41             : #include "Window.hxx"
      42             : #include <svx/svxids.hrc>
      43             : #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
      44             : #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
      45             : 
      46             : #include "res_bmp.hrc"
      47             : #include "sdresid.hxx"
      48             : #include "strings.hrc"
      49             : #include "app.hrc"
      50             : #include "glob.hrc"
      51             : 
      52             : 
      53             : using namespace ::com::sun::star;
      54             : using namespace ::com::sun::star::drawing;
      55             : using namespace ::com::sun::star::uno;
      56             : using namespace ::sd::slidesorter::model;
      57             : using namespace ::sd::slidesorter::view;
      58             : using namespace ::sd::slidesorter::controller;
      59             : 
      60             : namespace sd { namespace slidesorter { namespace controller {
      61             : 
      62             : 
      63             : class SelectionManager::PageInsertionListener
      64             :     : public SfxListener
      65             : {
      66             : public:
      67             : 
      68             : };
      69             : 
      70             : 
      71           0 : SelectionManager::SelectionManager (SlideSorter& rSlideSorter)
      72             :     : mrSlideSorter(rSlideSorter),
      73           0 :       mrController(rSlideSorter.GetController()),
      74             :       maSelectionBeforeSwitch(),
      75             :       mbIsMakeSelectionVisiblePending(true),
      76             :       mnInsertionPosition(-1),
      77             :       mnAnimationId(Animator::NotAnAnimationId),
      78             :       maRequestedTopLeft(),
      79             :       mpPageInsertionListener(),
      80           0 :       mpSelectionObserver(new SelectionObserver(rSlideSorter))
      81             : {
      82           0 : }
      83             : 
      84             : 
      85             : 
      86             : 
      87           0 : SelectionManager::~SelectionManager (void)
      88             : {
      89           0 :     if (mnAnimationId != Animator::NotAnAnimationId)
      90           0 :         mrController.GetAnimator()->RemoveAnimation(mnAnimationId);
      91           0 : }
      92             : 
      93             : 
      94             : 
      95             : 
      96           0 : void SelectionManager::DeleteSelectedPages (const bool bSelectFollowingPage)
      97             : {
      98             :     // Create some locks to prevent updates of the model, view, selection
      99             :     // state while modifying any of them.
     100           0 :     SlideSorterController::ModelChangeLock aLock (mrController);
     101           0 :     SlideSorterView::DrawLock aDrawLock (mrSlideSorter);
     102           0 :     PageSelector::UpdateLock aSelectionLock (mrSlideSorter);
     103             : 
     104             :     // Hide focus.
     105           0 :     bool bIsFocusShowing = mrController.GetFocusManager().IsFocusShowing();
     106           0 :     if (bIsFocusShowing)
     107           0 :         mrController.GetFocusManager().ToggleFocus();
     108             : 
     109             :     // Store pointers to all selected page descriptors.  This is necessary
     110             :     // because the pages get deselected when the first one is deleted.
     111             :     model::PageEnumeration aPageEnumeration (
     112           0 :         PageEnumerationProvider::CreateSelectedPagesEnumeration(mrSlideSorter.GetModel()));
     113           0 :     ::std::vector<SdPage*> aSelectedPages;
     114           0 :     sal_Int32 nNewCurrentSlide (-1);
     115           0 :     while (aPageEnumeration.HasMoreElements())
     116             :     {
     117           0 :         SharedPageDescriptor pDescriptor (aPageEnumeration.GetNextElement());
     118           0 :         aSelectedPages.push_back(pDescriptor->GetPage());
     119           0 :         if (bSelectFollowingPage || nNewCurrentSlide<0)
     120           0 :             nNewCurrentSlide = pDescriptor->GetPageIndex();
     121           0 :     }
     122           0 :     if (aSelectedPages.empty())
     123           0 :         return;
     124             : 
     125             :     // Determine the slide to select (and thereby make the current slide)
     126             :     // after the deletion.
     127           0 :     if (bSelectFollowingPage)
     128           0 :         nNewCurrentSlide -= aSelectedPages.size() - 1;
     129             :     else
     130           0 :         --nNewCurrentSlide;
     131             : 
     132             :     // The actual deletion of the selected pages is done in one of two
     133             :     // helper functions.  They are specialized for normal respectively for
     134             :     // master pages.
     135           0 :     mrSlideSorter.GetView().BegUndo (SdResId(STR_UNDO_DELETEPAGES));
     136           0 :     if (mrSlideSorter.GetModel().GetEditMode() == EM_PAGE)
     137           0 :         DeleteSelectedNormalPages(aSelectedPages);
     138             :     else
     139           0 :         DeleteSelectedMasterPages(aSelectedPages);
     140           0 :     mrSlideSorter.GetView().EndUndo ();
     141             : 
     142           0 :     mrController.HandleModelChange();
     143           0 :     aLock.Release();
     144             : 
     145             :     // Show focus and move it to next valid location.
     146           0 :     if (bIsFocusShowing)
     147           0 :         mrController.GetFocusManager().ToggleFocus();
     148             : 
     149             :     // Set the new current slide.
     150           0 :     if (nNewCurrentSlide < 0)
     151           0 :         nNewCurrentSlide = 0;
     152           0 :     else if (nNewCurrentSlide >= mrSlideSorter.GetModel().GetPageCount())
     153           0 :         nNewCurrentSlide = mrSlideSorter.GetModel().GetPageCount()-1;
     154           0 :     mrController.GetPageSelector().CountSelectedPages();
     155           0 :     mrController.GetPageSelector().SelectPage(nNewCurrentSlide);
     156           0 :     mrController.GetFocusManager().SetFocusedPage(nNewCurrentSlide);
     157             : }
     158             : 
     159             : 
     160             : 
     161             : 
     162           0 : void SelectionManager::DeleteSelectedNormalPages (const ::std::vector<SdPage*>& rSelectedPages)
     163             : {
     164             :     // Prepare the deletion via the UNO API.
     165             :     OSL_ASSERT(mrSlideSorter.GetModel().GetEditMode() == EM_PAGE);
     166             : 
     167             :     try
     168             :     {
     169           0 :         Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier( mrSlideSorter.GetModel().GetDocument()->getUnoModel(), UNO_QUERY_THROW );
     170           0 :         Reference<drawing::XDrawPages> xPages( xDrawPagesSupplier->getDrawPages(), UNO_QUERY_THROW );
     171             : 
     172             :         // Iterate over all pages that where seleted when this method was called
     173             :         // and delete the draw page the notes page.  The iteration is done in
     174             :         // reverse order so that when one slide is not deleted (to avoid an
     175             :         // empty document) the remaining slide is the first one.
     176           0 :         ::std::vector<SdPage*>::const_reverse_iterator aI;
     177           0 :         for (aI=rSelectedPages.rbegin(); aI!=rSelectedPages.rend(); ++aI)
     178             :         {
     179             :             // Do not delete the last slide in the document.
     180           0 :             if (xPages->getCount() <= 1)
     181           0 :                 break;
     182             : 
     183           0 :             const sal_uInt16 nPage (model::FromCoreIndex((*aI)->GetPageNum()));
     184             : 
     185           0 :             Reference< XDrawPage > xPage( xPages->getByIndex( nPage ), UNO_QUERY_THROW );
     186           0 :             xPages->remove(xPage);
     187           0 :         }
     188             :     }
     189           0 :     catch( Exception& )
     190             :     {
     191             :         OSL_FAIL("SelectionManager::DeleteSelectedNormalPages(), exception caught!");
     192             :     }
     193           0 : }
     194             : 
     195             : 
     196             : 
     197             : 
     198           0 : void SelectionManager::DeleteSelectedMasterPages (const ::std::vector<SdPage*>& rSelectedPages)
     199             : {
     200             :     // Prepare the deletion via the UNO API.
     201             :     OSL_ASSERT(mrSlideSorter.GetModel().GetEditMode() == EM_MASTERPAGE);
     202             : 
     203             :     try
     204             :     {
     205           0 :         Reference<drawing::XMasterPagesSupplier> xDrawPagesSupplier( mrSlideSorter.GetModel().GetDocument()->getUnoModel(), UNO_QUERY_THROW );
     206           0 :         Reference<drawing::XDrawPages> xPages( xDrawPagesSupplier->getMasterPages(), UNO_QUERY_THROW );
     207             : 
     208             :         // Iterate over all pages that where seleted when this method was called
     209             :         // and delete the draw page the notes page.  The iteration is done in
     210             :         // reverse order so that when one slide is not deleted (to avoid an
     211             :         // empty document) the remaining slide is the first one.
     212           0 :         ::std::vector<SdPage*>::const_reverse_iterator aI;
     213           0 :         for (aI=rSelectedPages.rbegin(); aI!=rSelectedPages.rend(); ++aI)
     214             :         {
     215             :             // Do not delete the last slide in the document.
     216           0 :             if (xPages->getCount() <= 1)
     217           0 :                 break;
     218             : 
     219           0 :             const sal_uInt16 nPage (model::FromCoreIndex((*aI)->GetPageNum()));
     220             : 
     221           0 :             Reference< XDrawPage > xPage( xPages->getByIndex( nPage ), UNO_QUERY_THROW );
     222           0 :             xPages->remove(xPage);
     223           0 :         }
     224             :     }
     225           0 :     catch( Exception& )
     226             :     {
     227             :         OSL_FAIL("SelectionManager::DeleteSelectedMasterPages(), exception caught!");
     228             :     }
     229           0 : }
     230             : 
     231             : 
     232             : 
     233             : 
     234           0 : void SelectionManager::SelectionHasChanged (const bool bMakeSelectionVisible)
     235             : {
     236           0 :     if (bMakeSelectionVisible)
     237           0 :         mbIsMakeSelectionVisiblePending = true;
     238             : 
     239           0 :     ViewShell* pViewShell = mrSlideSorter.GetViewShell();
     240           0 :     if (pViewShell != NULL)
     241             :     {
     242           0 :         pViewShell->Invalidate (SID_EXPAND_PAGE);
     243           0 :         pViewShell->Invalidate (SID_SUMMARY_PAGE);
     244           0 :         pViewShell->Invalidate(SID_SHOW_SLIDE);
     245           0 :         pViewShell->Invalidate(SID_HIDE_SLIDE);
     246           0 :         pViewShell->Invalidate(SID_DELETE_PAGE);
     247           0 :         pViewShell->Invalidate(SID_DELETE_MASTER_PAGE);
     248           0 :         pViewShell->Invalidate(SID_ASSIGN_LAYOUT);
     249             : 
     250             :         // StatusBar
     251           0 :         pViewShell->Invalidate (SID_STATUS_PAGE);
     252           0 :         pViewShell->Invalidate (SID_STATUS_LAYOUT);
     253             : 
     254             :         OSL_ASSERT(mrController.GetCurrentSlideManager());
     255           0 :         SharedPageDescriptor pDescriptor(mrController.GetCurrentSlideManager()->GetCurrentSlide());
     256           0 :         if (pDescriptor.get() != NULL)
     257           0 :             pViewShell->UpdatePreview(pDescriptor->GetPage());
     258             : 
     259             :         // Tell the slection change listeners that the selection has changed.
     260           0 :         ::std::vector<Link>::iterator iListener (maSelectionChangeListeners.begin());
     261           0 :         ::std::vector<Link>::iterator iEnd (maSelectionChangeListeners.end());
     262           0 :         for (; iListener!=iEnd; ++iListener)
     263             :         {
     264           0 :             iListener->Call(NULL);
     265             :         }
     266             : 
     267             :         // Reset the insertion position: until set again it is calculated from
     268             :         // the current selection.
     269           0 :         mnInsertionPosition = -1;
     270             :     }
     271           0 : }
     272             : 
     273             : 
     274             : 
     275             : 
     276           0 : void SelectionManager::AddSelectionChangeListener (const Link& rListener)
     277             : {
     278           0 :     if (::std::find (
     279             :         maSelectionChangeListeners.begin(),
     280             :         maSelectionChangeListeners.end(),
     281           0 :         rListener) == maSelectionChangeListeners.end())
     282             :     {
     283           0 :         maSelectionChangeListeners.push_back (rListener);
     284             :     }
     285           0 : }
     286             : 
     287             : 
     288             : 
     289             : 
     290           0 : void SelectionManager::RemoveSelectionChangeListener(const Link&rListener)
     291             : {
     292             :     maSelectionChangeListeners.erase (
     293             :         ::std::find (
     294             :             maSelectionChangeListeners.begin(),
     295             :             maSelectionChangeListeners.end(),
     296           0 :             rListener));
     297           0 : }
     298             : 
     299             : 
     300             : 
     301             : 
     302           0 : sal_Int32 SelectionManager::GetInsertionPosition (void) const
     303             : {
     304           0 :     sal_Int32 nInsertionPosition (mnInsertionPosition);
     305           0 :     if (nInsertionPosition < 0)
     306             :     {
     307             :         model::PageEnumeration aSelectedPages
     308             :             (model::PageEnumerationProvider::CreateSelectedPagesEnumeration(
     309           0 :                 mrSlideSorter.GetModel()));
     310             :         // Initialize (for the case of an empty selection) with the position
     311             :         // at the end of the document.
     312           0 :         nInsertionPosition = mrSlideSorter.GetModel().GetPageCount();
     313           0 :         while (aSelectedPages.HasMoreElements())
     314             :         {
     315           0 :             const sal_Int32 nPosition (aSelectedPages.GetNextElement()->GetPage()->GetPageNum());
     316             :             // Convert *2+1 index to straight index (n-1)/2 after the page
     317             :             // (+1).
     318           0 :             nInsertionPosition = model::FromCoreIndex(nPosition) + 1;
     319           0 :         }
     320             : 
     321             :     }
     322           0 :     return nInsertionPosition;
     323             : }
     324             : 
     325             : 
     326             : 
     327             : 
     328           0 : void SelectionManager::SetInsertionPosition (const sal_Int32 nInsertionPosition)
     329             : {
     330           0 :     if (nInsertionPosition < 0)
     331           0 :         mnInsertionPosition = -1;
     332           0 :     else if (nInsertionPosition > mrSlideSorter.GetModel().GetPageCount())
     333             :     {
     334             :         // Assert but then ignore invalid values.
     335             :         OSL_ASSERT(nInsertionPosition<=mrSlideSorter.GetModel().GetPageCount());
     336           0 :         return;
     337             :     }
     338             :     else
     339           0 :         mnInsertionPosition = nInsertionPosition;
     340             : }
     341             : 
     342             : 
     343             : 
     344             : 
     345           0 : ::boost::shared_ptr<SelectionObserver> SelectionManager::GetSelectionObserver (void) const
     346             : {
     347           0 :     return mpSelectionObserver;
     348             : }
     349             : 
     350             : } } } // end of namespace ::sd::slidesorter
     351             : 
     352             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10