LCOV - code coverage report
Current view: top level - sd/source/ui/slidesorter/controller - SlsCurrentSlideManager.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 51 104 49.0 %
Date: 2014-11-03 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         126 : CurrentSlideManager::CurrentSlideManager (SlideSorter& rSlideSorter)
      43             :     : mrSlideSorter(rSlideSorter),
      44             :       mnCurrentSlideIndex(-1),
      45             :       mpCurrentSlide(),
      46         126 :       maSwitchPageDelayTimer()
      47             : {
      48         126 :     maSwitchPageDelayTimer.SetTimeout(100);
      49         126 :     maSwitchPageDelayTimer.SetTimeoutHdl(LINK(this,CurrentSlideManager,SwitchPageCallback));
      50         126 : }
      51             : 
      52         126 : CurrentSlideManager::~CurrentSlideManager (void)
      53             : {
      54         126 : }
      55             : 
      56         378 : void CurrentSlideManager::NotifyCurrentSlideChange (const SdPage* pPage)
      57             : {
      58         378 :     if (pPage != NULL)
      59             :         NotifyCurrentSlideChange(
      60         378 :             mrSlideSorter.GetModel().GetIndex(
      61             :                 Reference<drawing::XDrawPage>(
      62             :                     const_cast<SdPage*>(pPage)->getUnoPage(),
      63         756 :                     UNO_QUERY)));
      64             :     else
      65           0 :         NotifyCurrentSlideChange(-1);
      66         378 : }
      67             : 
      68         512 : void CurrentSlideManager::NotifyCurrentSlideChange (const sal_Int32 nSlideIndex)
      69             : {
      70         512 :     if (mnCurrentSlideIndex != nSlideIndex)
      71             :     {
      72         134 :         PageSelector::BroadcastLock aBroadcastLock (mrSlideSorter.GetController().GetPageSelector());
      73             : 
      74         134 :         mrSlideSorter.GetController().GetPageSelector().DeselectAllPages();
      75             : 
      76         134 :         ReleaseCurrentSlide();
      77         134 :         AcquireCurrentSlide(nSlideIndex);
      78             : 
      79             :         // Update the selection.
      80         134 :         if (mpCurrentSlide)
      81             :         {
      82         134 :             mrSlideSorter.GetController().GetPageSelector().SelectPage(mpCurrentSlide);
      83         134 :             mrSlideSorter.GetController().GetFocusManager().SetFocusedPage(mpCurrentSlide);
      84         134 :         }
      85             :     }
      86         512 : }
      87             : 
      88         134 : void CurrentSlideManager::ReleaseCurrentSlide (void)
      89             : {
      90         134 :     if (mpCurrentSlide.get() != NULL)
      91           8 :         mrSlideSorter.GetView().SetState(mpCurrentSlide, PageDescriptor::ST_Current, false);
      92             : 
      93         134 :     mpCurrentSlide.reset();
      94         134 :     mnCurrentSlideIndex = -1;
      95         134 : }
      96             : 
      97         134 : bool CurrentSlideManager::IsCurrentSlideIsValid (void)
      98             : {
      99         134 :     return mnCurrentSlideIndex >= 0 && mnCurrentSlideIndex<mrSlideSorter.GetModel().GetPageCount();
     100             : }
     101             : 
     102         134 : void CurrentSlideManager::AcquireCurrentSlide (const sal_Int32 nSlideIndex)
     103             : {
     104         134 :     mnCurrentSlideIndex = nSlideIndex;
     105             : 
     106         134 :     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         134 :         mpCurrentSlide = mrSlideSorter.GetModel().GetPageDescriptor(mnCurrentSlideIndex);
     112         134 :         if (mpCurrentSlide.get() != NULL)
     113         134 :             mrSlideSorter.GetView().SetState(mpCurrentSlide, PageDescriptor::ST_Current, true);
     114             :     }
     115         134 : }
     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         134 : void CurrentSlideManager::SwitchCurrentSlide (
     125             :     const SharedPageDescriptor& rpDescriptor,
     126             :     const bool bUpdateSelection)
     127             : {
     128         134 :     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         134 : }
     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         158 : void CurrentSlideManager::PrepareModelChange (void)
     228             : {
     229         158 :     mpCurrentSlide.reset();
     230         158 : }
     231             : 
     232         158 : void CurrentSlideManager::HandleModelChange (void)
     233             : {
     234         158 :     if (mnCurrentSlideIndex >= 0)
     235             :     {
     236         158 :         mpCurrentSlide = mrSlideSorter.GetModel().GetPageDescriptor(mnCurrentSlideIndex);
     237         158 :         if (mpCurrentSlide.get() != NULL)
     238         158 :             mrSlideSorter.GetView().SetState(mpCurrentSlide, PageDescriptor::ST_Current, true);
     239             :     }
     240         158 : }
     241             : 
     242           0 : IMPL_LINK_NOARG(CurrentSlideManager, SwitchPageCallback)
     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             : 
     257           0 :     return 1;
     258             : }
     259             : 
     260         114 : } } } // end of namespace ::sd::slidesorter::controller
     261             : 
     262             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10