LCOV - code coverage report
Current view: top level - sd/source/ui/slidesorter/controller - SlsCurrentSlideManager.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 51 104 49.0 %
Date: 2015-06-13 12:38:46 Functions: 12 18 66.7 %
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 "model/SlideSorterModel.hxx"
      22             : #include "model/SlsPageDescriptor.hxx"
      23             : #include "controller/SlsPageSelector.hxx"
      24             : #include "controller/SlideSorterController.hxx"
      25             : #include "controller/SlsCurrentSlideManager.hxx"
      26             : #include "controller/SlsFocusManager.hxx"
      27             : #include "view/SlideSorterView.hxx"
      28             : #include "ViewShellBase.hxx"
      29             : #include "ViewShell.hxx"
      30             : #include "DrawViewShell.hxx"
      31             : #include "sdpage.hxx"
      32             : #include "FrameView.hxx"
      33             : #include <com/sun/star/beans/XPropertySet.hpp>
      34             : 
      35             : using namespace ::com::sun::star;
      36             : using namespace ::com::sun::star::uno;
      37             : 
      38             : using namespace ::sd::slidesorter::model;
      39             : 
      40             : namespace sd { namespace slidesorter { namespace controller {
      41             : 
      42          64 : CurrentSlideManager::CurrentSlideManager (SlideSorter& rSlideSorter)
      43             :     : mrSlideSorter(rSlideSorter),
      44             :       mnCurrentSlideIndex(-1),
      45             :       mpCurrentSlide(),
      46          64 :       maSwitchPageDelayTimer()
      47             : {
      48          64 :     maSwitchPageDelayTimer.SetTimeout(100);
      49          64 :     maSwitchPageDelayTimer.SetTimeoutHdl(LINK(this,CurrentSlideManager,SwitchPageCallback));
      50          64 : }
      51             : 
      52          64 : CurrentSlideManager::~CurrentSlideManager()
      53             : {
      54          64 : }
      55             : 
      56         206 : void CurrentSlideManager::NotifyCurrentSlideChange (const SdPage* pPage)
      57             : {
      58         206 :     if (pPage != NULL)
      59             :         NotifyCurrentSlideChange(
      60         206 :             mrSlideSorter.GetModel().GetIndex(
      61             :                 Reference<drawing::XDrawPage>(
      62             :                     const_cast<SdPage*>(pPage)->getUnoPage(),
      63         412 :                     UNO_QUERY)));
      64             :     else
      65           0 :         NotifyCurrentSlideChange(-1);
      66         206 : }
      67             : 
      68         298 : void CurrentSlideManager::NotifyCurrentSlideChange (const sal_Int32 nSlideIndex)
      69             : {
      70         298 :     if (mnCurrentSlideIndex != nSlideIndex)
      71             :     {
      72          97 :         PageSelector::BroadcastLock aBroadcastLock (mrSlideSorter.GetController().GetPageSelector());
      73             : 
      74          97 :         mrSlideSorter.GetController().GetPageSelector().DeselectAllPages();
      75             : 
      76          97 :         ReleaseCurrentSlide();
      77          97 :         AcquireCurrentSlide(nSlideIndex);
      78             : 
      79             :         // Update the selection.
      80          97 :         if (mpCurrentSlide)
      81             :         {
      82          85 :             mrSlideSorter.GetController().GetPageSelector().SelectPage(mpCurrentSlide);
      83          85 :             mrSlideSorter.GetController().GetFocusManager().SetFocusedPage(mpCurrentSlide);
      84          97 :         }
      85             :     }
      86         298 : }
      87             : 
      88          97 : void CurrentSlideManager::ReleaseCurrentSlide()
      89             : {
      90          97 :     if (mpCurrentSlide.get() != NULL)
      91          15 :         mrSlideSorter.GetView().SetState(mpCurrentSlide, PageDescriptor::ST_Current, false);
      92             : 
      93          97 :     mpCurrentSlide.reset();
      94          97 :     mnCurrentSlideIndex = -1;
      95          97 : }
      96             : 
      97          97 : bool CurrentSlideManager::IsCurrentSlideIsValid()
      98             : {
      99          97 :     return mnCurrentSlideIndex >= 0 && mnCurrentSlideIndex<mrSlideSorter.GetModel().GetPageCount();
     100             : }
     101             : 
     102          97 : void CurrentSlideManager::AcquireCurrentSlide (const sal_Int32 nSlideIndex)
     103             : {
     104          97 :     mnCurrentSlideIndex = nSlideIndex;
     105             : 
     106          97 :     if (IsCurrentSlideIsValid())
     107             :     {
     108             :         // Get a descriptor for the XDrawPage reference.  Note that the
     109             :         // given XDrawPage may or may not be member of the slide sorter
     110             :         // document.
     111          85 :         mpCurrentSlide = mrSlideSorter.GetModel().GetPageDescriptor(mnCurrentSlideIndex);
     112          85 :         if (mpCurrentSlide.get() != NULL)
     113          85 :             mrSlideSorter.GetView().SetState(mpCurrentSlide, PageDescriptor::ST_Current, true);
     114             :     }
     115          97 : }
     116             : 
     117           0 : void CurrentSlideManager::SwitchCurrentSlide (
     118             :     const sal_Int32 nSlideIndex,
     119             :     const bool bUpdateSelection)
     120             : {
     121           0 :     SwitchCurrentSlide(mrSlideSorter.GetModel().GetPageDescriptor(nSlideIndex), bUpdateSelection);
     122           0 : }
     123             : 
     124          85 : void CurrentSlideManager::SwitchCurrentSlide (
     125             :     const SharedPageDescriptor& rpDescriptor,
     126             :     const bool bUpdateSelection)
     127             : {
     128          85 :     if (rpDescriptor.get() != NULL && mpCurrentSlide!=rpDescriptor)
     129             :     {
     130           0 :         ReleaseCurrentSlide();
     131           0 :         AcquireCurrentSlide((rpDescriptor->GetPage()->GetPageNum()-1)/2);
     132             : 
     133           0 :         ViewShell* pViewShell = mrSlideSorter.GetViewShell();
     134           0 :         if (pViewShell != NULL && pViewShell->IsMainViewShell())
     135             :         {
     136             :             // The slide sorter is the main view.
     137           0 :             FrameView* pFrameView = pViewShell->GetFrameView();
     138           0 :             if (pFrameView != NULL)
     139           0 :                 pFrameView->SetSelectedPage(sal::static_int_cast<sal_uInt16>(mnCurrentSlideIndex));
     140           0 :             mrSlideSorter.GetController().GetPageSelector().SetCoreSelection();
     141             :         }
     142             : 
     143             :         // We do not tell the XController/ViewShellBase about the new
     144             :         // slide right away.  This is done asynchronously after a short
     145             :         // delay to allow for more slide switches in the slide sorter.
     146             :         // This goes under the assumption that slide switching inside
     147             :         // the slide sorter is fast (no expensive redraw of the new page
     148             :         // (unless the preview of the new slide is not yet preset)) and
     149             :         // that slide switching in the edit view is slow (all shapes of
     150             :         // the new slide have to be repainted.)
     151           0 :         maSwitchPageDelayTimer.Start();
     152             : 
     153             :         // We have to store the (index of the) new current slide at
     154             :         // the tab control because there are other asynchronous
     155             :         // notifications of the slide switching that otherwise
     156             :         // overwrite the correct value.
     157           0 :         SetCurrentSlideAtTabControl(mpCurrentSlide);
     158             : 
     159           0 :         if (bUpdateSelection)
     160             :         {
     161           0 :             mrSlideSorter.GetController().GetPageSelector().DeselectAllPages();
     162           0 :             mrSlideSorter.GetController().GetPageSelector().SelectPage(rpDescriptor);
     163             :         }
     164           0 :         mrSlideSorter.GetController().GetFocusManager().SetFocusedPage(rpDescriptor);
     165             :     }
     166          85 : }
     167             : 
     168           0 : void CurrentSlideManager::SetCurrentSlideAtViewShellBase (const SharedPageDescriptor& rpDescriptor)
     169             : {
     170             :     OSL_ASSERT(rpDescriptor.get() != NULL);
     171             : 
     172           0 :     ViewShellBase* pBase = mrSlideSorter.GetViewShellBase();
     173           0 :     if (pBase != NULL)
     174             :     {
     175             :         DrawViewShell* pDrawViewShell = dynamic_cast<DrawViewShell*>(
     176           0 :             pBase->GetMainViewShell().get());
     177           0 :         if (pDrawViewShell != NULL)
     178             :         {
     179           0 :             sal_uInt16 nPageNumber = (rpDescriptor->GetPage()->GetPageNum()-1)/2;
     180           0 :             pDrawViewShell->SwitchPage(nPageNumber);
     181           0 :             pDrawViewShell->GetPageTabControl().SetCurPageId(nPageNumber+1);
     182             :         }
     183             :     }
     184           0 : }
     185             : 
     186           0 : void CurrentSlideManager::SetCurrentSlideAtTabControl (const SharedPageDescriptor& rpDescriptor)
     187             : {
     188             :     OSL_ASSERT(rpDescriptor.get() != NULL);
     189             : 
     190           0 :     ViewShellBase* pBase = mrSlideSorter.GetViewShellBase();
     191           0 :     if (pBase != NULL)
     192             :     {
     193             :         ::boost::shared_ptr<DrawViewShell> pDrawViewShell (
     194           0 :             ::boost::dynamic_pointer_cast<DrawViewShell>(pBase->GetMainViewShell()));
     195           0 :         if (pDrawViewShell)
     196             :         {
     197           0 :             sal_uInt16 nPageNumber = (rpDescriptor->GetPage()->GetPageNum()-1)/2;
     198           0 :             pDrawViewShell->GetPageTabControl().SetCurPageId(nPageNumber+1);
     199           0 :         }
     200             :     }
     201           0 : }
     202             : 
     203           0 : void CurrentSlideManager::SetCurrentSlideAtXController (const SharedPageDescriptor& rpDescriptor)
     204             : {
     205             :     OSL_ASSERT(rpDescriptor.get() != NULL);
     206             : 
     207             :     try
     208             :     {
     209           0 :         Reference<beans::XPropertySet> xSet (mrSlideSorter.GetXController(), UNO_QUERY);
     210           0 :         if (xSet.is())
     211             :         {
     212           0 :             Any aPage;
     213           0 :             aPage <<= rpDescriptor->GetPage()->getUnoPage();
     214           0 :             xSet->setPropertyValue (
     215             :                 OUString("CurrentPage"),
     216           0 :                 aPage);
     217           0 :         }
     218             :     }
     219           0 :     catch (const Exception&)
     220             :     {
     221             :         // We have not been able to set the current page at the main view.
     222             :         // This is sad but still leaves us in a valid state.  Therefore,
     223             :         // this exception is silently ignored.
     224             :     }
     225           0 : }
     226             : 
     227          88 : void CurrentSlideManager::PrepareModelChange()
     228             : {
     229          88 :     mpCurrentSlide.reset();
     230          88 : }
     231             : 
     232          88 : void CurrentSlideManager::HandleModelChange()
     233             : {
     234          88 :     if (mnCurrentSlideIndex >= 0)
     235             :     {
     236          83 :         mpCurrentSlide = mrSlideSorter.GetModel().GetPageDescriptor(mnCurrentSlideIndex);
     237          83 :         if (mpCurrentSlide.get() != NULL)
     238          83 :             mrSlideSorter.GetView().SetState(mpCurrentSlide, PageDescriptor::ST_Current, true);
     239             :     }
     240          88 : }
     241             : 
     242           0 : IMPL_LINK_NOARG_TYPED(CurrentSlideManager, SwitchPageCallback, Timer *, void)
     243             : {
     244           0 :     if (mpCurrentSlide)
     245             :     {
     246             :         // Set current page.  At the moment we have to do this in two
     247             :         // different ways.  The UNO way is the preferable one but, alas,
     248             :         // it does not work always correctly (after some kinds of model
     249             :         // changes).  Therefore, we call DrawViewShell::SwitchPage(),
     250             :         // too.
     251           0 :         ViewShell* pViewShell = mrSlideSorter.GetViewShell();
     252           0 :         if (pViewShell==NULL || ! pViewShell->IsMainViewShell())
     253           0 :             SetCurrentSlideAtViewShellBase(mpCurrentSlide);
     254           0 :         SetCurrentSlideAtXController(mpCurrentSlide);
     255             :     }
     256           0 : }
     257             : 
     258          66 : } } } // end of namespace ::sd::slidesorter::controller
     259             : 
     260             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11