1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
24 #include "controller/SlsVisibleAreaManager.hxx"
25 #include "controller/SlideSorterController.hxx"
26 #include "controller/SlsProperties.hxx"
27 #include "controller/SlsAnimationFunction.hxx"
28 #include "controller/SlsScrollBarManager.hxx"
29 #include "controller/SlsCurrentSlideManager.hxx"
31 namespace sd
{ namespace slidesorter
{ namespace controller
{
34 class VisibleAreaScroller
38 SlideSorter
& rSlideSorter
,
41 void operator() (const double nValue
);
43 SlideSorter
& mrSlideSorter
;
46 const ::boost::function
<double(double)> maAccelerationFunction
;
49 } // end of anonymous namespace
51 VisibleAreaManager::VisibleAreaManager (SlideSorter
& rSlideSorter
)
52 : mrSlideSorter(rSlideSorter
),
54 mnScrollAnimationId(Animator::NotAnAnimationId
),
55 maRequestedVisibleTopLeft(),
56 meRequestedAnimationMode(Animator::AM_Immediate
),
57 mbIsCurrentSlideTrackingActive(true),
62 VisibleAreaManager::~VisibleAreaManager()
66 void VisibleAreaManager::ActivateCurrentSlideTracking()
68 mbIsCurrentSlideTrackingActive
= true;
71 void VisibleAreaManager::DeactivateCurrentSlideTracking()
73 mbIsCurrentSlideTrackingActive
= false;
76 void VisibleAreaManager::RequestVisible (
77 const model::SharedPageDescriptor
& rpDescriptor
,
82 if (mnDisableCount
== 0)
84 maVisibleRequests
.push_back(
85 mrSlideSorter
.GetView().GetLayouter().GetPageObjectBox(
86 rpDescriptor
->GetPageIndex(),
89 if (bForce
&& ! mbIsCurrentSlideTrackingActive
)
90 ActivateCurrentSlideTracking();
95 void VisibleAreaManager::RequestCurrentSlideVisible()
97 if (mbIsCurrentSlideTrackingActive
&& mnDisableCount
==0)
99 mrSlideSorter
.GetController().GetCurrentSlideManager()->GetCurrentSlide());
102 void VisibleAreaManager::MakeVisible()
104 if (maVisibleRequests
.empty())
107 sd::Window
*pWindow (mrSlideSorter
.GetContentWindow());
110 const Point
aCurrentTopLeft (pWindow
->PixelToLogic(Point(0,0)));
112 const ::boost::optional
<Point
> aNewVisibleTopLeft (GetRequestedTopLeft());
113 maVisibleRequests
.clear();
114 if ( ! aNewVisibleTopLeft
)
117 // We now know what the visible area shall be. Scroll accordingly
118 // unless that is not already the visible area or a running scroll
119 // animation has it as its target area.
120 if (mnScrollAnimationId
!=Animator::NotAnAnimationId
121 && maRequestedVisibleTopLeft
==aNewVisibleTopLeft
)
124 // Stop a running animation.
125 if (mnScrollAnimationId
!= Animator::NotAnAnimationId
)
126 mrSlideSorter
.GetController().GetAnimator()->RemoveAnimation(mnScrollAnimationId
);
128 maRequestedVisibleTopLeft
= aNewVisibleTopLeft
.get();
129 VisibleAreaScroller
aAnimation(
132 maRequestedVisibleTopLeft
);
133 if (meRequestedAnimationMode
==Animator::AM_Animated
134 && mrSlideSorter
.GetProperties()->IsSmoothSelectionScrolling())
136 mnScrollAnimationId
= mrSlideSorter
.GetController().GetAnimator()->AddAnimation(
143 // Execute the animation at its final value.
146 meRequestedAnimationMode
= Animator::AM_Immediate
;
149 ::boost::optional
<Point
> VisibleAreaManager::GetRequestedTopLeft() const
151 sd::Window
*pWindow (mrSlideSorter
.GetContentWindow());
153 return ::boost::optional
<Point
>();
155 // Get the currently visible area and the model area.
156 const Rectangle
aVisibleArea (pWindow
->PixelToLogic(
159 pWindow
->GetOutputSizePixel())));
160 const Rectangle
aModelArea (mrSlideSorter
.GetView().GetModelArea());
162 sal_Int32
nVisibleTop (aVisibleArea
.Top());
163 const sal_Int32
nVisibleWidth (aVisibleArea
.GetWidth());
164 sal_Int32
nVisibleLeft (aVisibleArea
.Left());
165 const sal_Int32
nVisibleHeight (aVisibleArea
.GetHeight());
167 // Find the longest run of boxes whose union fits into the visible area.
168 for (::std::vector
<Rectangle
>::const_iterator
169 iBox(maVisibleRequests
.begin()),
170 iEnd(maVisibleRequests
.end());
174 if (nVisibleTop
+nVisibleHeight
<= iBox
->Bottom())
175 nVisibleTop
= iBox
->Bottom()-nVisibleHeight
;
176 if (nVisibleTop
> iBox
->Top())
177 nVisibleTop
= iBox
->Top();
179 if (nVisibleLeft
+nVisibleWidth
<= iBox
->Right())
180 nVisibleLeft
= iBox
->Right()-nVisibleWidth
;
181 if (nVisibleLeft
> iBox
->Left())
182 nVisibleLeft
= iBox
->Left();
184 // Make sure the visible area does not move outside the model area.
185 if (nVisibleTop
+ nVisibleHeight
> aModelArea
.Bottom())
186 nVisibleTop
= aModelArea
.Bottom() - nVisibleHeight
;
187 if (nVisibleTop
< aModelArea
.Top())
188 nVisibleTop
= aModelArea
.Top();
190 if (nVisibleLeft
+ nVisibleWidth
> aModelArea
.Right())
191 nVisibleLeft
= aModelArea
.Right() - nVisibleWidth
;
192 if (nVisibleLeft
< aModelArea
.Left())
193 nVisibleLeft
= aModelArea
.Left();
196 const Point
aRequestedTopLeft (nVisibleLeft
, nVisibleTop
);
197 if (aRequestedTopLeft
== aVisibleArea
.TopLeft())
198 return ::boost::optional
<Point
>();
200 return ::boost::optional
<Point
>(aRequestedTopLeft
);
203 //===== VisibleAreaManager::TemporaryDisabler =================================
205 VisibleAreaManager::TemporaryDisabler::TemporaryDisabler (SlideSorter
& rSlideSorter
)
206 : mrVisibleAreaManager(rSlideSorter
.GetController().GetVisibleAreaManager())
208 ++mrVisibleAreaManager
.mnDisableCount
;
211 VisibleAreaManager::TemporaryDisabler::~TemporaryDisabler()
213 --mrVisibleAreaManager
.mnDisableCount
;
216 //===== VerticalVisibleAreaScroller ===========================================
220 const static sal_Int32 gnMaxScrollDistance
= 300;
222 VisibleAreaScroller::VisibleAreaScroller (
223 SlideSorter
& rSlideSorter
,
226 : mrSlideSorter(rSlideSorter
),
229 maAccelerationFunction(
230 controller::AnimationParametricFunction(
231 controller::AnimationBezierFunction (0.1,0.6)))
233 // When the distance to scroll is larger than a threshold then first
234 // jump to within this distance of the final value and start the
235 // animation from there.
236 if (std::abs(rStart
.X()-rEnd
.X()) > gnMaxScrollDistance
)
238 if (rStart
.X() < rEnd
.X())
239 maStart
.X() = rEnd
.X()-gnMaxScrollDistance
;
241 maStart
.X() = rEnd
.X()+gnMaxScrollDistance
;
243 if (std::abs(rStart
.Y()-rEnd
.Y()) > gnMaxScrollDistance
)
245 if (rStart
.Y() < rEnd
.Y())
246 maStart
.Y() = rEnd
.Y()-gnMaxScrollDistance
;
248 maStart
.Y() = rEnd
.Y()+gnMaxScrollDistance
;
252 void VisibleAreaScroller::operator() (const double nTime
)
254 const double nLocalTime (maAccelerationFunction(nTime
));
255 mrSlideSorter
.GetController().GetScrollBarManager().SetTopLeft(
257 sal_Int32(0.5 + maStart
.X() * (1.0 - nLocalTime
) + maEnd
.X() * nLocalTime
),
258 sal_Int32 (0.5 + maStart
.Y() * (1.0 - nLocalTime
) + maEnd
.Y() * nLocalTime
)));
261 } // end of anonymous namespace
263 } } } // end of namespace ::sd::slidesorter::controller
265 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */