1*5b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*5b190011SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*5b190011SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*5b190011SAndrew Rist * distributed with this work for additional information
6*5b190011SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*5b190011SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*5b190011SAndrew Rist * "License"); you may not use this file except in compliance
9*5b190011SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*5b190011SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*5b190011SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*5b190011SAndrew Rist * software distributed under the License is distributed on an
15*5b190011SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5b190011SAndrew Rist * KIND, either express or implied. See the License for the
17*5b190011SAndrew Rist * specific language governing permissions and limitations
18*5b190011SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*5b190011SAndrew Rist *************************************************************/
21*5b190011SAndrew Rist
22*5b190011SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include "precompiled_sd.hxx"
25cdf0e10cSrcweir
26cdf0e10cSrcweir #include "controller/SlsVisibleAreaManager.hxx"
27cdf0e10cSrcweir #include "controller/SlideSorterController.hxx"
28cdf0e10cSrcweir #include "controller/SlsProperties.hxx"
29cdf0e10cSrcweir #include "controller/SlsAnimationFunction.hxx"
30cdf0e10cSrcweir #include "controller/SlsScrollBarManager.hxx"
31cdf0e10cSrcweir #include "controller/SlsCurrentSlideManager.hxx"
32cdf0e10cSrcweir
33cdf0e10cSrcweir
34cdf0e10cSrcweir namespace sd { namespace slidesorter { namespace controller {
35cdf0e10cSrcweir
36cdf0e10cSrcweir namespace {
37cdf0e10cSrcweir class VisibleAreaScroller
38cdf0e10cSrcweir {
39cdf0e10cSrcweir public:
40cdf0e10cSrcweir VisibleAreaScroller (
41cdf0e10cSrcweir SlideSorter& rSlideSorter,
42cdf0e10cSrcweir const Point aStart,
43cdf0e10cSrcweir const Point aEnd);
44cdf0e10cSrcweir void operator() (const double nValue);
45cdf0e10cSrcweir private:
46cdf0e10cSrcweir SlideSorter& mrSlideSorter;
47cdf0e10cSrcweir Point maStart;
48cdf0e10cSrcweir const Point maEnd;
49cdf0e10cSrcweir const ::boost::function<double(double)> maAccelerationFunction;
50cdf0e10cSrcweir };
51cdf0e10cSrcweir
52cdf0e10cSrcweir } // end of anonymous namespace
53cdf0e10cSrcweir
54cdf0e10cSrcweir
55cdf0e10cSrcweir
VisibleAreaManager(SlideSorter & rSlideSorter)56cdf0e10cSrcweir VisibleAreaManager::VisibleAreaManager (SlideSorter& rSlideSorter)
57cdf0e10cSrcweir : mrSlideSorter(rSlideSorter),
58cdf0e10cSrcweir maVisibleRequests(),
59cdf0e10cSrcweir mnScrollAnimationId(Animator::NotAnAnimationId),
60cdf0e10cSrcweir maRequestedVisibleTopLeft(),
61cdf0e10cSrcweir meRequestedAnimationMode(Animator::AM_Immediate),
62cdf0e10cSrcweir mbIsCurrentSlideTrackingActive(true),
63cdf0e10cSrcweir mnDisableCount(0)
64cdf0e10cSrcweir {
65cdf0e10cSrcweir }
66cdf0e10cSrcweir
67cdf0e10cSrcweir
68cdf0e10cSrcweir
69cdf0e10cSrcweir
~VisibleAreaManager(void)70cdf0e10cSrcweir VisibleAreaManager::~VisibleAreaManager (void)
71cdf0e10cSrcweir {
72cdf0e10cSrcweir }
73cdf0e10cSrcweir
74cdf0e10cSrcweir
75cdf0e10cSrcweir
76cdf0e10cSrcweir
ActivateCurrentSlideTracking(void)77cdf0e10cSrcweir void VisibleAreaManager::ActivateCurrentSlideTracking (void)
78cdf0e10cSrcweir {
79cdf0e10cSrcweir mbIsCurrentSlideTrackingActive = true;
80cdf0e10cSrcweir }
81cdf0e10cSrcweir
82cdf0e10cSrcweir
83cdf0e10cSrcweir
84cdf0e10cSrcweir
DeactivateCurrentSlideTracking(void)85cdf0e10cSrcweir void VisibleAreaManager::DeactivateCurrentSlideTracking (void)
86cdf0e10cSrcweir {
87cdf0e10cSrcweir mbIsCurrentSlideTrackingActive = false;
88cdf0e10cSrcweir }
89cdf0e10cSrcweir
90cdf0e10cSrcweir
91cdf0e10cSrcweir
92cdf0e10cSrcweir
IsCurrentSlideTrackingActive(void) const930a9dddb7SMichael Stahl bool VisibleAreaManager::IsCurrentSlideTrackingActive (void) const
940a9dddb7SMichael Stahl {
950a9dddb7SMichael Stahl return mbIsCurrentSlideTrackingActive;
960a9dddb7SMichael Stahl }
970a9dddb7SMichael Stahl
980a9dddb7SMichael Stahl
990a9dddb7SMichael Stahl
1000a9dddb7SMichael Stahl
RequestVisible(const model::SharedPageDescriptor & rpDescriptor,const bool bForce)101cdf0e10cSrcweir void VisibleAreaManager::RequestVisible (
102cdf0e10cSrcweir const model::SharedPageDescriptor& rpDescriptor,
103cdf0e10cSrcweir const bool bForce)
104cdf0e10cSrcweir {
105cdf0e10cSrcweir if (rpDescriptor)
106cdf0e10cSrcweir {
107cdf0e10cSrcweir if (mnDisableCount == 0)
108cdf0e10cSrcweir {
109cdf0e10cSrcweir maVisibleRequests.push_back(
110cdf0e10cSrcweir mrSlideSorter.GetView().GetLayouter().GetPageObjectBox(
111cdf0e10cSrcweir rpDescriptor->GetPageIndex(),
112cdf0e10cSrcweir true));
113cdf0e10cSrcweir }
114cdf0e10cSrcweir if (bForce && ! mbIsCurrentSlideTrackingActive)
115cdf0e10cSrcweir ActivateCurrentSlideTracking();
116cdf0e10cSrcweir MakeVisible();
117cdf0e10cSrcweir }
118cdf0e10cSrcweir }
119cdf0e10cSrcweir
120cdf0e10cSrcweir
121cdf0e10cSrcweir
122cdf0e10cSrcweir
RequestCurrentSlideVisible(void)123cdf0e10cSrcweir void VisibleAreaManager::RequestCurrentSlideVisible (void)
124cdf0e10cSrcweir {
125cdf0e10cSrcweir if (mbIsCurrentSlideTrackingActive && mnDisableCount==0)
126cdf0e10cSrcweir RequestVisible(
127cdf0e10cSrcweir mrSlideSorter.GetController().GetCurrentSlideManager()->GetCurrentSlide());
128cdf0e10cSrcweir }
129cdf0e10cSrcweir
130cdf0e10cSrcweir
131cdf0e10cSrcweir
132cdf0e10cSrcweir
MakeVisible(void)133cdf0e10cSrcweir void VisibleAreaManager::MakeVisible (void)
134cdf0e10cSrcweir {
135cdf0e10cSrcweir if (maVisibleRequests.empty())
136cdf0e10cSrcweir return;
137cdf0e10cSrcweir
138cdf0e10cSrcweir SharedSdWindow pWindow (mrSlideSorter.GetContentWindow());
139cdf0e10cSrcweir if ( ! pWindow)
140cdf0e10cSrcweir return;
141cdf0e10cSrcweir const Point aCurrentTopLeft (pWindow->PixelToLogic(Point(0,0)));
142cdf0e10cSrcweir
143cdf0e10cSrcweir const ::boost::optional<Point> aNewVisibleTopLeft (GetRequestedTopLeft());
144cdf0e10cSrcweir maVisibleRequests.clear();
145cdf0e10cSrcweir if ( ! aNewVisibleTopLeft)
146cdf0e10cSrcweir return;
147cdf0e10cSrcweir
148cdf0e10cSrcweir // We now know what the visible area shall be. Scroll accordingly
149cdf0e10cSrcweir // unless that is not already the visible area or a running scroll
150cdf0e10cSrcweir // animation has it as its target area.
151cdf0e10cSrcweir if (mnScrollAnimationId!=Animator::NotAnAnimationId
152cdf0e10cSrcweir && maRequestedVisibleTopLeft==aNewVisibleTopLeft)
153cdf0e10cSrcweir return;
154cdf0e10cSrcweir
155cdf0e10cSrcweir // Stop a running animation.
156cdf0e10cSrcweir if (mnScrollAnimationId != Animator::NotAnAnimationId)
157cdf0e10cSrcweir mrSlideSorter.GetController().GetAnimator()->RemoveAnimation(mnScrollAnimationId);
158cdf0e10cSrcweir
159cdf0e10cSrcweir maRequestedVisibleTopLeft = aNewVisibleTopLeft.get();
160cdf0e10cSrcweir VisibleAreaScroller aAnimation(
161cdf0e10cSrcweir mrSlideSorter,
162cdf0e10cSrcweir aCurrentTopLeft,
163cdf0e10cSrcweir maRequestedVisibleTopLeft);
164cdf0e10cSrcweir if (meRequestedAnimationMode==Animator::AM_Animated
165cdf0e10cSrcweir && mrSlideSorter.GetProperties()->IsSmoothSelectionScrolling())
166cdf0e10cSrcweir {
167cdf0e10cSrcweir mnScrollAnimationId = mrSlideSorter.GetController().GetAnimator()->AddAnimation(
168cdf0e10cSrcweir aAnimation,
169cdf0e10cSrcweir 0,
170cdf0e10cSrcweir 300);
171cdf0e10cSrcweir }
172cdf0e10cSrcweir else
173cdf0e10cSrcweir {
174cdf0e10cSrcweir // Execute the animation at its final value.
175cdf0e10cSrcweir aAnimation(1.0);
176cdf0e10cSrcweir }
177cdf0e10cSrcweir meRequestedAnimationMode = Animator::AM_Immediate;
178cdf0e10cSrcweir }
179cdf0e10cSrcweir
180cdf0e10cSrcweir
181cdf0e10cSrcweir
182cdf0e10cSrcweir
GetRequestedTopLeft(void) const183cdf0e10cSrcweir ::boost::optional<Point> VisibleAreaManager::GetRequestedTopLeft (void) const
184cdf0e10cSrcweir {
185cdf0e10cSrcweir SharedSdWindow pWindow (mrSlideSorter.GetContentWindow());
186cdf0e10cSrcweir if ( ! pWindow)
187cdf0e10cSrcweir return ::boost::optional<Point>();
188cdf0e10cSrcweir
189cdf0e10cSrcweir // Get the currently visible area and the model area.
190cdf0e10cSrcweir const Rectangle aVisibleArea (pWindow->PixelToLogic(
191cdf0e10cSrcweir Rectangle(
192cdf0e10cSrcweir Point(0,0),
193cdf0e10cSrcweir pWindow->GetOutputSizePixel())));
194cdf0e10cSrcweir const Rectangle aModelArea (mrSlideSorter.GetView().GetModelArea());
195cdf0e10cSrcweir
196cdf0e10cSrcweir sal_Int32 nVisibleTop (aVisibleArea.Top());
197cdf0e10cSrcweir const sal_Int32 nVisibleWidth (aVisibleArea.GetWidth());
198cdf0e10cSrcweir sal_Int32 nVisibleLeft (aVisibleArea.Left());
199cdf0e10cSrcweir const sal_Int32 nVisibleHeight (aVisibleArea.GetHeight());
200cdf0e10cSrcweir
201cdf0e10cSrcweir // Find the longest run of boxes whose union fits into the visible area.
202cdf0e10cSrcweir Rectangle aBoundingBox;
203cdf0e10cSrcweir for (::std::vector<Rectangle>::const_iterator
204cdf0e10cSrcweir iBox(maVisibleRequests.begin()),
205cdf0e10cSrcweir iEnd(maVisibleRequests.end());
206cdf0e10cSrcweir iBox!=iEnd;
207cdf0e10cSrcweir ++iBox)
208cdf0e10cSrcweir {
209cdf0e10cSrcweir if (nVisibleTop+nVisibleHeight <= iBox->Bottom())
210cdf0e10cSrcweir nVisibleTop = iBox->Bottom()-nVisibleHeight;
211cdf0e10cSrcweir if (nVisibleTop > iBox->Top())
212cdf0e10cSrcweir nVisibleTop = iBox->Top();
213cdf0e10cSrcweir
214cdf0e10cSrcweir if (nVisibleLeft+nVisibleWidth <= iBox->Right())
215cdf0e10cSrcweir nVisibleLeft = iBox->Right()-nVisibleWidth;
216cdf0e10cSrcweir if (nVisibleLeft > iBox->Left())
217cdf0e10cSrcweir nVisibleLeft = iBox->Left();
218cdf0e10cSrcweir
219cdf0e10cSrcweir // Make sure the visible area does not move outside the model area.
220cdf0e10cSrcweir if (nVisibleTop + nVisibleHeight > aModelArea.Bottom())
221cdf0e10cSrcweir nVisibleTop = aModelArea.Bottom() - nVisibleHeight;
222cdf0e10cSrcweir if (nVisibleTop < aModelArea.Top())
223cdf0e10cSrcweir nVisibleTop = aModelArea.Top();
224cdf0e10cSrcweir
225cdf0e10cSrcweir if (nVisibleLeft + nVisibleWidth > aModelArea.Right())
226cdf0e10cSrcweir nVisibleLeft = aModelArea.Right() - nVisibleWidth;
227cdf0e10cSrcweir if (nVisibleLeft < aModelArea.Left())
228cdf0e10cSrcweir nVisibleLeft = aModelArea.Left();
229cdf0e10cSrcweir }
230cdf0e10cSrcweir
231cdf0e10cSrcweir const Point aRequestedTopLeft (nVisibleLeft, nVisibleTop);
232cdf0e10cSrcweir if (aRequestedTopLeft == aVisibleArea.TopLeft())
233cdf0e10cSrcweir return ::boost::optional<Point>();
234cdf0e10cSrcweir else
235cdf0e10cSrcweir return ::boost::optional<Point>(aRequestedTopLeft);
236cdf0e10cSrcweir }
237cdf0e10cSrcweir
238cdf0e10cSrcweir
239cdf0e10cSrcweir
240cdf0e10cSrcweir
241cdf0e10cSrcweir //===== VisibleAreaManager::TemporaryDisabler =================================
242cdf0e10cSrcweir
TemporaryDisabler(SlideSorter & rSlideSorter)243cdf0e10cSrcweir VisibleAreaManager::TemporaryDisabler::TemporaryDisabler (SlideSorter& rSlideSorter)
244cdf0e10cSrcweir : mrVisibleAreaManager(rSlideSorter.GetController().GetVisibleAreaManager())
245cdf0e10cSrcweir {
246cdf0e10cSrcweir ++mrVisibleAreaManager.mnDisableCount;
247cdf0e10cSrcweir }
248cdf0e10cSrcweir
249cdf0e10cSrcweir
250cdf0e10cSrcweir
251cdf0e10cSrcweir
~TemporaryDisabler(void)252cdf0e10cSrcweir VisibleAreaManager::TemporaryDisabler::~TemporaryDisabler (void)
253cdf0e10cSrcweir {
254cdf0e10cSrcweir --mrVisibleAreaManager.mnDisableCount;
255cdf0e10cSrcweir }
256cdf0e10cSrcweir
257cdf0e10cSrcweir
258cdf0e10cSrcweir
259cdf0e10cSrcweir //===== VerticalVisibleAreaScroller ===========================================
260cdf0e10cSrcweir
261cdf0e10cSrcweir namespace {
262cdf0e10cSrcweir
263cdf0e10cSrcweir const static sal_Int32 gnMaxScrollDistance = 300;
264cdf0e10cSrcweir
VisibleAreaScroller(SlideSorter & rSlideSorter,const Point aStart,const Point aEnd)265cdf0e10cSrcweir VisibleAreaScroller::VisibleAreaScroller (
266cdf0e10cSrcweir SlideSorter& rSlideSorter,
267cdf0e10cSrcweir const Point aStart,
268cdf0e10cSrcweir const Point aEnd)
269cdf0e10cSrcweir : mrSlideSorter(rSlideSorter),
270cdf0e10cSrcweir maStart(aStart),
271cdf0e10cSrcweir maEnd(aEnd),
272cdf0e10cSrcweir maAccelerationFunction(
273cdf0e10cSrcweir controller::AnimationParametricFunction(
274cdf0e10cSrcweir controller::AnimationBezierFunction (0.1,0.6)))
275cdf0e10cSrcweir {
276cdf0e10cSrcweir // When the distance to scroll is larger than a threshold then first
277cdf0e10cSrcweir // jump to within this distance of the final value and start the
278cdf0e10cSrcweir // animation from there.
279cdf0e10cSrcweir if (abs(aStart.X()-aEnd.X()) > gnMaxScrollDistance)
280cdf0e10cSrcweir {
281cdf0e10cSrcweir if (aStart.X() < aEnd.X())
282cdf0e10cSrcweir maStart.X() = aEnd.X()-gnMaxScrollDistance;
283cdf0e10cSrcweir else
284cdf0e10cSrcweir maStart.X() = aEnd.X()+gnMaxScrollDistance;
285cdf0e10cSrcweir }
286cdf0e10cSrcweir if (abs(aStart.Y()-aEnd.Y()) > gnMaxScrollDistance)
287cdf0e10cSrcweir {
288cdf0e10cSrcweir if (aStart.Y() < aEnd.Y())
289cdf0e10cSrcweir maStart.Y() = aEnd.Y()-gnMaxScrollDistance;
290cdf0e10cSrcweir else
291cdf0e10cSrcweir maStart.Y() = aEnd.Y()+gnMaxScrollDistance;
292cdf0e10cSrcweir }
293cdf0e10cSrcweir }
294cdf0e10cSrcweir
295cdf0e10cSrcweir
296cdf0e10cSrcweir
297cdf0e10cSrcweir
operator ()(const double nTime)298cdf0e10cSrcweir void VisibleAreaScroller::operator() (const double nTime)
299cdf0e10cSrcweir {
300cdf0e10cSrcweir const double nLocalTime (maAccelerationFunction(nTime));
301cdf0e10cSrcweir mrSlideSorter.GetController().GetScrollBarManager().SetTopLeft(
302cdf0e10cSrcweir Point(
303cdf0e10cSrcweir sal_Int32(0.5 + maStart.X() * (1.0 - nLocalTime) + maEnd.X() * nLocalTime),
304cdf0e10cSrcweir sal_Int32 (0.5 + maStart.Y() * (1.0 - nLocalTime) + maEnd.Y() * nLocalTime)));
305cdf0e10cSrcweir }
306cdf0e10cSrcweir
307cdf0e10cSrcweir } // end of anonymous namespace
308cdf0e10cSrcweir
309cdf0e10cSrcweir } } } // end of namespace ::sd::slidesorter::controller
310