bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / slidesorter / inc / controller / SlsScrollBarManager.hxx
blob3c0761d33f96de1fc226707e89ecbd764e2fcda7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #ifndef INCLUDED_SD_SOURCE_UI_SLIDESORTER_INC_CONTROLLER_SLSSCROLLBARMANAGER_HXX
21 #define INCLUDED_SD_SOURCE_UI_SLIDESORTER_INC_CONTROLLER_SLSSCROLLBARMANAGER_HXX
23 #include "SlideSorter.hxx"
25 #include <tools/link.hxx>
26 #include <tools/gen.hxx>
27 #include <vcl/timer.hxx>
28 #include <boost/function.hpp>
30 class ScrollBar;
31 class ScrollBarBox;
33 namespace sd { namespace slidesorter { class SlideSorter; } }
35 namespace sd { namespace slidesorter { namespace controller {
37 /** Manage the horizontal and vertical scroll bars. Listen for events, set
38 their sizes, place them in the window, determine their visibilities.
40 <p>Handle auto scrolling, i.e. the scrolling of the window when the
41 mouse comes near the window border while dragging a selection.</p>
43 <p>In order to make the slide sorter be used in the task pane with its
44 own vertical scrollbars the vertical scrollbar of the use of the slide
45 sorter is optional. When using it the available area in a window is
46 used and the vertical scrollbar is displayed when that area is not large
47 enough. When the vertical scrollbar is not used then the available area
48 is assumed to be modifiable. In that case the PlaceScrollBars() method
49 may return an area larger than the one given.<p>
51 class ScrollBarManager
53 public:
54 /** Create a new scroll bar manager that manages three controls: the
55 horizontal scroll bar, the vertical scroll bar, and the little
56 window that fills the gap at the bottom right corner that is left
57 between the two scroll bars. Call LateInitialization() after
58 constructing a new object.
60 ScrollBarManager (SlideSorter& rSlideSorter);
62 ~ScrollBarManager();
64 /** Register listeners at the scroll bars. This method is called after
65 startup of a new slide sorter object or after a reactivation of a
66 slide sorter that for example is taken from a cache.
68 void Connect();
70 /** Remove listeners from the scroll bars. This method is called when
71 the slide sorter is destroyed or when it is suspended, e.g. put
72 into a cache for later reuse.
74 void Disconnect();
76 /** Set up the scroll bar, i.e. thumb size and position. Call this
77 method when the content of the browser window changed, i.e. pages
78 were inserted or deleted, the layout or the zoom factor has
79 changed.
80 @param bResetThumbPosition
81 When <TRUE/> then set the thumb position to position 0. This is
82 done when e.g. switching between master page mode and draw mode.
83 @param bScrollToCurrentPosition
84 When <TRUE/> then scroll the window to the new offset that is
85 defined by the scroll bars. Otherwise the new offset is simply
86 set and the whole window is repainted.
88 void UpdateScrollBars (
89 bool bResetThumbPosition = false,
90 bool bScrollToCurrentPosition = true);
92 /** Place the scroll bars inside the given area. When the available
93 area is not large enough for the content to display the horizontal
94 and/or vertical scroll bar is enabled.
95 @param rAvailableArea
96 The scroll bars will be placed inside this rectangle. It is
97 expected to be given in pixel relative to its parent.
98 @param bIsHorizontalScrollBarAllowed
99 Only when this flag is <TRUE/> the horizontal scroll may be
100 displayed.
101 @param bIsVerticalScrollBarAllowed
102 Only when this flag is <TRUE/> the horizontal scroll may be
103 displayed.
104 @return
105 Returns the space that remains after the scroll bars are
106 placed.
108 Rectangle PlaceScrollBars (
109 const Rectangle& rAvailableArea,
110 const bool bIsHorizontalScrollBarAllowed,
111 const bool bIsVerticalScrollBarAllowed);
113 /** Update the vertical and horizontal scroll bars so that the visible
114 area has the given top and left values.
116 void SetTopLeft (const Point& rNewTopLeft);
118 /** Return the width of the vertical scroll bar, which--when
119 shown--should be fixed in contrast to its height.
120 @return
121 Returns 0 when the vertical scroll bar is not shown or does not
122 exist, otherwise its width in pixel is returned.
124 int GetVerticalScrollBarWidth() const;
126 /** Return the height of the horizontal scroll bar, which--when
127 shown--should be fixed in contrast to its width.
128 @return
129 Returns 0 when the vertical scroll bar is not shown or does not
130 exist, otherwise its height in pixel is returned.
132 int GetHorizontalScrollBarHeight() const;
134 /** Call this method to scroll a window while the mouse is in dragging a
135 selection. If the mouse is near the window border or is outside the
136 window then scroll the window accordingly.
137 @param rMouseWindowPosition
138 The mouse position for which the scroll amount is calculated.
139 @param rAutoScrollFunctor
140 Every time when the window is scrolled then this functor is executed.
141 @return
142 When the window is scrolled then this method returns <TRUE/>.
143 When the window is not changed then <FALSE/> is returned.
145 bool AutoScroll (
146 const Point& rMouseWindowPosition,
147 const ::boost::function<void()>& rAutoScrollFunctor);
149 void StopAutoScroll();
151 void clearAutoScrollFunctor();
153 enum Orientation { Orientation_Horizontal, Orientation_Vertical };
154 enum Unit { Unit_Pixel, Unit_Slide };
155 /** Scroll the slide sorter by setting the thumbs of the scroll bars and
156 by moving the content of the content window.
157 @param eOrientation
158 Defines whether to scroll horizontally or vertically.
159 @param eUnit
160 Defines whether the distance is a pixel value or the number of
161 slides to scroll.
163 void Scroll(
164 const Orientation eOrientation,
165 const Unit eUnit,
166 const sal_Int32 nDistance);
168 private:
169 SlideSorter& mrSlideSorter;
171 /** The horizontal scroll bar. Note that is used but not owned by
172 objects of this class. It is given to the constructor.
174 VclPtr<ScrollBar> mpHorizontalScrollBar;
176 /** The vertical scroll bar. Note that is used but not owned by
177 objects of this class. It is given to the constructor.
179 VclPtr<ScrollBar> mpVerticalScrollBar;
181 /// Relative horizontal position of the visible area in the view.
182 double mnHorizontalPosition;
183 /// Relative vertical position of the visible area in the view.
184 double mnVerticalPosition;
185 /** The width and height of the border at the inside of the window which
186 when entered while in drag mode leads to a scrolling of the window.
188 Size maScrollBorder;
189 double mnHorizontalScrollFactor;
190 double mnVerticalScrollFactor;
191 /** The only task of this little window is to paint the little square at
192 the bottom right corner left by the two scroll bars (when both are
193 visible).
195 VclPtr<ScrollBarBox> mpScrollBarFiller;
197 /** The auto scroll timer is used for keep scrolling the window when the
198 mouse reaches its border while dragging a selection. When the mouse
199 is not moved the timer issues events to keep scrolling.
201 Timer maAutoScrollTimer;
202 Size maAutoScrollOffset;
203 bool mbIsAutoScrollActive;
205 /** The content window is the one whose view port is controlled by the
206 scroll bars.
208 VclPtr<sd::Window> mpContentWindow;
210 ::boost::function<void()> maAutoScrollFunctor;
212 void SetWindowOrigin (
213 double nHorizontalPosition,
214 double nVerticalPosition);
216 /** Determine the visibility of the scroll bars so that the window
217 content is not clipped in any dimension without showing a scroll
218 bar.
219 @param rAvailableArea
220 The area in which the scroll bars, the scroll bar filler, and
221 the SlideSorterView will be placed.
222 @return
223 The area that is enclosed by the scroll bars is returned. It
224 will be filled with the SlideSorterView.
226 Rectangle DetermineScrollBarVisibilities(
227 const Rectangle& rAvailableArea,
228 const bool bIsHorizontalScrollBarAllowed,
229 const bool bIsVerticalScrollBarAllowed);
231 /** Typically called by DetermineScrollBarVisibilities() this method
232 tests a specific configuration of the two scroll bars being visible
233 or hidden.
234 @return
235 When the window content can be shown with only being clipped in
236 an orientation where the scroll bar would be shown then <TRUE/>
237 is returned.
239 bool TestScrollBarVisibilities (
240 bool bHorizontalScrollBarVisible,
241 bool bVerticalScrollBarVisible,
242 const Rectangle& rAvailableArea);
244 void CalcAutoScrollOffset (const Point& rMouseWindowPosition);
245 bool RepeatAutoScroll();
247 DECL_LINK(HorizontalScrollBarHandler, ScrollBar*);
248 DECL_LINK(VerticalScrollBarHandler, ScrollBar*);
249 DECL_LINK_TYPED(AutoScrollTimeoutHandler, Timer *, void);
251 void PlaceHorizontalScrollBar (const Rectangle& aArea);
252 void PlaceVerticalScrollBar (const Rectangle& aArea);
253 void PlaceFiller (const Rectangle& aArea);
256 } } } // end of namespace ::sd::slidesorter::controller
258 #endif
260 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */