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

Generated by: LCOV version 1.10