1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SlsScrollBarManager.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SD_SLIDESORTER_SLIDE_SORTER_SCROLL_BAR_MANAGER_HXX
32 #define SD_SLIDESORTER_SLIDE_SORTER_SCROLL_BAR_MANAGER_HXX
34 #include <tools/link.hxx>
35 #include <tools/gen.hxx>
36 #include <vcl/timer.hxx>
37 #include <boost/shared_ptr.hpp>
49 namespace sd
{ namespace slidesorter
{
54 namespace sd
{ namespace slidesorter
{ namespace controller
{
56 /** Manage the horizontal and vertical scroll bars. Listen for events, set
57 their sizes, place them in the window, determine their visibilities.
59 <p>Handle auto scrolling, i.e. the scrolling of the window when the
60 mouse comes near the window border while dragging a selection.</p>
62 <p>In order to make the slide sorter be used in the task pane with its
63 own vertical scrollbars the vertical scrollbar of the use of the slide
64 sorter is optional. When using it the available area in a window is
65 used and the vertical scrollbar is displayed when that area is not large
66 enough. When the vertical scrollbar is not used then the available area
67 is assumed to be modifiable. In that case the PlaceScrollBars() method
68 may return an area larger than the one given.<p>
70 class ScrollBarManager
73 /** Create a new scroll bar manager that manages three controls: the
74 horizontal scroll bar, the vertical scroll bar, and the little
75 window that fills the gap at the bottom right corner that is left
76 between the two scroll bars. Call LateInitialization() after
77 constructing a new object.
79 ScrollBarManager (SlideSorter
& rSlideSorter
);
81 ~ScrollBarManager (void);
83 /** Call this method after constructing a new object of this class.
85 void LateInitialization (void);
87 /** Register listeners at the scroll bars. This method is called after
88 startup of a new slide sorter object or after a reactivation of a
89 slide sorter that for example is taken from a cache.
93 /** Remove listeners from the scroll bars. This method is called whent
94 the slide sorter is destroyed or when it is suspended, e.g. put
95 into a cache for later reuse.
97 void Disconnect (void);
99 /** Set up the scroll bar, i.e. thumb size and position. Call this
100 method when the content of the browser window changed, i.e. pages
101 were inserted or deleted, the layout or the zoom factor has
103 @param bResetThumbPosition
104 When <TRUE/> then set the thumb position to position 0. This is
105 done when e.g. switching between master page mode and draw mode.
106 @param bScrollToCurrentPosition
107 When <TRUE/> then scroll the window to the new offset that is
108 defined by the scroll bars. Otherwise the new offset is simply
109 set and the whole window is repainted.
111 void UpdateScrollBars (
112 bool bResetThumbPosition
= false,
113 bool bScrollToCurrentPosition
= true);
115 /** Place the scroll bars inside the given area. When the available
116 area is not large enough for the content to display the resulting
117 behaviour depends on the mbUseVerticalScrollBar flag. When it is
118 set to true then a vertical scroll bar is shown. Otherwise the
119 height of the returned area is enlarged so that the content fits
121 @param rAvailableArea
122 The scroll bars will be placed inside this rectangle. It is
123 expected to be given in pixel relative to its parent.
125 Returns the space that remains after the scroll bars are
126 placed. When the mbUseVerticalScrollBar flag is false then the
127 returned rectangle may be larger than the given one.
129 Rectangle
PlaceScrollBars (const Rectangle
& rAvailableArea
);
131 /** Update the vertical scroll bar so that the visible area has the
134 void SetTop (const sal_Int32 nTop
);
136 /** Update the horizontal scroll bar so that the visible area has the
139 void SetLeft (const sal_Int32 nLeft
);
141 /** Return the width of the vertical scroll bar, which--when
142 shown--should be fixed in contrast to its height.
144 Returns 0 when the vertical scroll bar is not shown or does not
145 exist, otherwise its width in pixel is returned.
147 int GetVerticalScrollBarWidth (void) const;
149 /** Return the height of the horizontal scroll bar, which--when
150 shown--should be fixed in contrast to its width.
152 Returns 0 when the vertical scroll bar is not shown or does not
153 exist, otherwise its height in pixel is returned.
155 int GetHorizontalScrollBarHeight (void) const;
157 /** Call this method to scroll a window while the mouse is in dragging a
158 selection. If the mouse is near the window border or is outside the
159 window then scroll the window accordingly.
161 When the window is scrolled then this method returns <TRUE/>.
162 When the window is not changed then <FALSE/> is returned.
164 bool AutoScroll (const Point
& rMouseWindowPosition
);
166 void StopAutoScroll (void);
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 ::boost::shared_ptr
<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 ::boost::shared_ptr
<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.
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
195 ::boost::shared_ptr
<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
;
204 /** The content window is the one whose view port is controlled by the
207 ::boost::shared_ptr
<sd::Window
> mpContentWindow
;
209 void SetWindowOrigin (
210 double nHorizontalPosition
,
211 double nVerticalPosition
);
213 /** Determine the visibility of the scroll bars so that the window
214 content is not clipped in any dimension without showing a scroll
216 @param rAvailableArea
217 The area in which the scroll bars, the scroll bar filler, and
218 the SlideSorterView will be placed.
220 The area that is enclosed by the scroll bars is returned. It
221 will be filled with the SlideSorterView.
223 Rectangle
DetermineScrollBarVisibilities (const Rectangle
& rAvailableArea
);
225 /** Typically called by DetermineScrollBarVisibilities() this method
226 tests a specific configuration of the two scroll bars being visible
229 When the window content can be shown with only being clipped in
230 an orientation where the scroll bar would be shown then <TRUE/>
233 bool TestScrollBarVisibilities (
234 bool bHorizontalScrollBarVisible
,
235 bool bVerticalScrollBarVisible
,
236 const Rectangle
& rAvailableArea
);
238 void CalcAutoScrollOffset (const Point
& rMouseWindowPosition
);
239 bool RepeatAutoScroll (void);
241 DECL_LINK(HorizontalScrollBarHandler
, ScrollBar
*);
242 DECL_LINK(VerticalScrollBarHandler
, ScrollBar
*);
243 DECL_LINK(AutoScrollTimeoutHandler
, Timer
*);
245 void PlaceHorizontalScrollBar (const Rectangle
& aArea
);
246 void PlaceVerticalScrollBar (const Rectangle
& aArea
);
247 void PlaceFiller (const Rectangle
& aArea
);
249 /** Make the height of the content window larger or smaller, so that the
251 content size fits exactly in. This is achieved by changing the size
252 of the parent window and rely on the resulting resize.
254 void AdaptWindowSize (const Rectangle
& rArea
);
257 } } } // end of namespace ::sd::slidesorter::controller