LCOV - code coverage report
Current view: top level - libreoffice/sd/source/ui/slidesorter/controller - SlsVisibleAreaManager.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 106 0.0 %
Date: 2012-12-27 Functions: 0 15 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/SlsVisibleAreaManager.hxx"
      22             : #include "controller/SlideSorterController.hxx"
      23             : #include "controller/SlsProperties.hxx"
      24             : #include "controller/SlsAnimationFunction.hxx"
      25             : #include "controller/SlsScrollBarManager.hxx"
      26             : #include "controller/SlsCurrentSlideManager.hxx"
      27             : 
      28             : 
      29             : namespace sd { namespace slidesorter { namespace controller {
      30             : 
      31             : namespace {
      32           0 :     class VisibleAreaScroller
      33             :     {
      34             :     public:
      35             :         VisibleAreaScroller (
      36             :             SlideSorter& rSlideSorter,
      37             :             const Point aStart,
      38             :             const Point aEnd);
      39             :         void operator() (const double nValue);
      40             :     private:
      41             :         SlideSorter& mrSlideSorter;
      42             :         Point maStart;
      43             :         const Point maEnd;
      44             :         const ::boost::function<double(double)> maAccelerationFunction;
      45             :     };
      46             : 
      47             : } // end of anonymous namespace
      48             : 
      49             : 
      50             : 
      51           0 : VisibleAreaManager::VisibleAreaManager (SlideSorter& rSlideSorter)
      52             :     : mrSlideSorter(rSlideSorter),
      53             :       maVisibleRequests(),
      54             :       mnScrollAnimationId(Animator::NotAnAnimationId),
      55             :       maRequestedVisibleTopLeft(),
      56             :       meRequestedAnimationMode(Animator::AM_Immediate),
      57             :       mbIsCurrentSlideTrackingActive(true),
      58           0 :       mnDisableCount(0)
      59             : {
      60           0 : }
      61             : 
      62             : 
      63             : 
      64             : 
      65           0 : VisibleAreaManager::~VisibleAreaManager (void)
      66             : {
      67           0 : }
      68             : 
      69             : 
      70             : 
      71             : 
      72           0 : void VisibleAreaManager::ActivateCurrentSlideTracking (void)
      73             : {
      74           0 :     mbIsCurrentSlideTrackingActive = true;
      75           0 : }
      76             : 
      77             : 
      78             : 
      79             : 
      80           0 : void VisibleAreaManager::DeactivateCurrentSlideTracking (void)
      81             : {
      82           0 :     mbIsCurrentSlideTrackingActive = false;
      83           0 : }
      84             : 
      85             : 
      86             : 
      87             : 
      88           0 : bool VisibleAreaManager::IsCurrentSlideTrackingActive (void) const
      89             : {
      90           0 :     return mbIsCurrentSlideTrackingActive;
      91             : }
      92             : 
      93             : 
      94             : 
      95             : 
      96           0 : void VisibleAreaManager::RequestVisible (
      97             :     const model::SharedPageDescriptor& rpDescriptor,
      98             :     const bool bForce)
      99             : {
     100           0 :     if (rpDescriptor)
     101             :     {
     102           0 :         if (mnDisableCount == 0)
     103             :         {
     104             :             maVisibleRequests.push_back(
     105           0 :                 mrSlideSorter.GetView().GetLayouter().GetPageObjectBox(
     106             :                     rpDescriptor->GetPageIndex(),
     107           0 :                     true));
     108             :         }
     109           0 :         if (bForce && ! mbIsCurrentSlideTrackingActive)
     110           0 :             ActivateCurrentSlideTracking();
     111           0 :         MakeVisible();
     112             :     }
     113           0 : }
     114             : 
     115             : 
     116             : 
     117             : 
     118           0 : void VisibleAreaManager::RequestCurrentSlideVisible (void)
     119             : {
     120           0 :     if (mbIsCurrentSlideTrackingActive && mnDisableCount==0)
     121             :         RequestVisible(
     122           0 :             mrSlideSorter.GetController().GetCurrentSlideManager()->GetCurrentSlide());
     123           0 : }
     124             : 
     125             : 
     126             : 
     127             : 
     128           0 : void VisibleAreaManager::MakeVisible (void)
     129             : {
     130           0 :     if (maVisibleRequests.empty())
     131             :         return;
     132             : 
     133           0 :     SharedSdWindow pWindow (mrSlideSorter.GetContentWindow());
     134           0 :     if ( ! pWindow)
     135             :         return;
     136           0 :     const Point aCurrentTopLeft (pWindow->PixelToLogic(Point(0,0)));
     137             : 
     138           0 :     const ::boost::optional<Point> aNewVisibleTopLeft (GetRequestedTopLeft());
     139           0 :     maVisibleRequests.clear();
     140           0 :     if ( ! aNewVisibleTopLeft)
     141             :         return;
     142             : 
     143             :     // We now know what the visible area shall be.  Scroll accordingly
     144             :     // unless that is not already the visible area or a running scroll
     145             :     // animation has it as its target area.
     146           0 :     if (mnScrollAnimationId!=Animator::NotAnAnimationId
     147           0 :         && maRequestedVisibleTopLeft==aNewVisibleTopLeft)
     148             :         return;
     149             : 
     150             :     // Stop a running animation.
     151           0 :     if (mnScrollAnimationId != Animator::NotAnAnimationId)
     152           0 :         mrSlideSorter.GetController().GetAnimator()->RemoveAnimation(mnScrollAnimationId);
     153             : 
     154           0 :     maRequestedVisibleTopLeft = aNewVisibleTopLeft.get();
     155             :     VisibleAreaScroller aAnimation(
     156             :         mrSlideSorter,
     157             :         aCurrentTopLeft,
     158           0 :         maRequestedVisibleTopLeft);
     159           0 :     if (meRequestedAnimationMode==Animator::AM_Animated
     160           0 :         && mrSlideSorter.GetProperties()->IsSmoothSelectionScrolling())
     161             :     {
     162           0 :         mnScrollAnimationId = mrSlideSorter.GetController().GetAnimator()->AddAnimation(
     163             :             aAnimation,
     164             :             0,
     165           0 :             300);
     166             :     }
     167             :     else
     168             :     {
     169             :         // Execute the animation at its final value.
     170           0 :         aAnimation(1.0);
     171             :     }
     172           0 :     meRequestedAnimationMode = Animator::AM_Immediate;
     173             : }
     174             : 
     175             : 
     176             : 
     177             : 
     178           0 : ::boost::optional<Point> VisibleAreaManager::GetRequestedTopLeft (void) const
     179             : {
     180           0 :     SharedSdWindow pWindow (mrSlideSorter.GetContentWindow());
     181           0 :     if ( ! pWindow)
     182           0 :         return ::boost::optional<Point>();
     183             : 
     184             :     // Get the currently visible area and the model area.
     185           0 :     const Rectangle aVisibleArea (pWindow->PixelToLogic(
     186             :         Rectangle(
     187             :             Point(0,0),
     188           0 :             pWindow->GetOutputSizePixel())));
     189           0 :     const Rectangle aModelArea (mrSlideSorter.GetView().GetModelArea());
     190             : 
     191           0 :     sal_Int32 nVisibleTop (aVisibleArea.Top());
     192           0 :     const sal_Int32 nVisibleWidth (aVisibleArea.GetWidth());
     193           0 :     sal_Int32 nVisibleLeft (aVisibleArea.Left());
     194           0 :     const sal_Int32 nVisibleHeight (aVisibleArea.GetHeight());
     195             : 
     196             :     // Find the longest run of boxes whose union fits into the visible area.
     197           0 :     Rectangle aBoundingBox;
     198           0 :     for (::std::vector<Rectangle>::const_iterator
     199           0 :              iBox(maVisibleRequests.begin()),
     200           0 :              iEnd(maVisibleRequests.end());
     201             :          iBox!=iEnd;
     202             :          ++iBox)
     203             :     {
     204           0 :         if (nVisibleTop+nVisibleHeight <= iBox->Bottom())
     205           0 :             nVisibleTop = iBox->Bottom()-nVisibleHeight;
     206           0 :         if (nVisibleTop > iBox->Top())
     207           0 :             nVisibleTop = iBox->Top();
     208             : 
     209           0 :         if (nVisibleLeft+nVisibleWidth <= iBox->Right())
     210           0 :             nVisibleLeft = iBox->Right()-nVisibleWidth;
     211           0 :         if (nVisibleLeft > iBox->Left())
     212           0 :             nVisibleLeft = iBox->Left();
     213             : 
     214             :         // Make sure the visible area does not move outside the model area.
     215           0 :         if (nVisibleTop + nVisibleHeight > aModelArea.Bottom())
     216           0 :             nVisibleTop = aModelArea.Bottom() - nVisibleHeight;
     217           0 :         if (nVisibleTop < aModelArea.Top())
     218           0 :             nVisibleTop = aModelArea.Top();
     219             : 
     220           0 :         if (nVisibleLeft + nVisibleWidth > aModelArea.Right())
     221           0 :             nVisibleLeft = aModelArea.Right() - nVisibleWidth;
     222           0 :         if (nVisibleLeft < aModelArea.Left())
     223           0 :             nVisibleLeft = aModelArea.Left();
     224             :     }
     225             : 
     226           0 :     const Point aRequestedTopLeft (nVisibleLeft, nVisibleTop);
     227           0 :     if (aRequestedTopLeft == aVisibleArea.TopLeft())
     228           0 :         return ::boost::optional<Point>();
     229             :     else
     230           0 :         return ::boost::optional<Point>(aRequestedTopLeft);
     231             : }
     232             : 
     233             : 
     234             : 
     235             : 
     236             : //===== VisibleAreaManager::TemporaryDisabler =================================
     237             : 
     238           0 : VisibleAreaManager::TemporaryDisabler::TemporaryDisabler (SlideSorter& rSlideSorter)
     239           0 :     : mrVisibleAreaManager(rSlideSorter.GetController().GetVisibleAreaManager())
     240             : {
     241           0 :     ++mrVisibleAreaManager.mnDisableCount;
     242           0 : }
     243             : 
     244             : 
     245             : 
     246             : 
     247           0 : VisibleAreaManager::TemporaryDisabler::~TemporaryDisabler (void)
     248             : {
     249           0 :     --mrVisibleAreaManager.mnDisableCount;
     250           0 : }
     251             : 
     252             : 
     253             : 
     254             : //===== VerticalVisibleAreaScroller ===========================================
     255             : 
     256             : namespace {
     257             : 
     258             : const static sal_Int32 gnMaxScrollDistance = 300;
     259             : 
     260           0 : VisibleAreaScroller::VisibleAreaScroller (
     261             :     SlideSorter& rSlideSorter,
     262             :     const Point aStart,
     263             :     const Point aEnd)
     264             :     : mrSlideSorter(rSlideSorter),
     265             :       maStart(aStart),
     266             :       maEnd(aEnd),
     267             :       maAccelerationFunction(
     268             :           controller::AnimationParametricFunction(
     269           0 :               controller::AnimationBezierFunction (0.1,0.6)))
     270             : {
     271             :     // When the distance to scroll is larger than a threshold then first
     272             :     // jump to within this distance of the final value and start the
     273             :     // animation from there.
     274           0 :     if (abs(aStart.X()-aEnd.X()) > gnMaxScrollDistance)
     275             :     {
     276           0 :         if (aStart.X() < aEnd.X())
     277           0 :             maStart.X() = aEnd.X()-gnMaxScrollDistance;
     278             :         else
     279           0 :             maStart.X() = aEnd.X()+gnMaxScrollDistance;
     280             :     }
     281           0 :     if (abs(aStart.Y()-aEnd.Y()) > gnMaxScrollDistance)
     282             :     {
     283           0 :         if (aStart.Y() < aEnd.Y())
     284           0 :             maStart.Y() = aEnd.Y()-gnMaxScrollDistance;
     285             :         else
     286           0 :             maStart.Y() = aEnd.Y()+gnMaxScrollDistance;
     287             :     }
     288           0 : }
     289             : 
     290             : 
     291             : 
     292             : 
     293           0 : void VisibleAreaScroller::operator() (const double nTime)
     294             : {
     295           0 :     const double nLocalTime (maAccelerationFunction(nTime));
     296           0 :     mrSlideSorter.GetController().GetScrollBarManager().SetTopLeft(
     297             :         Point(
     298           0 :             sal_Int32(0.5 + maStart.X() * (1.0 - nLocalTime) + maEnd.X() * nLocalTime),
     299           0 :             sal_Int32 (0.5 + maStart.Y() * (1.0 - nLocalTime) + maEnd.Y() * nLocalTime)));
     300           0 : }
     301             : 
     302             : } // end of anonymous namespace
     303             : 
     304             : } } } // end of namespace ::sd::slidesorter::controller
     305             : 
     306             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10