tdf#85428: Clip strokes
[LibreOffice.git] / sd / source / ui / slidesorter / inc / controller / SlsScrollBarManager.hxx
blobdf04a3b5952f3ca64e8a1a6f0f5b25d1b60fead5
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 #pragma once
22 #include <tools/link.hxx>
23 #include <tools/gen.hxx>
24 #include <svtools/scrolladaptor.hxx>
25 #include <vcl/timer.hxx>
26 #include <vcl/vclptr.hxx>
28 #include <functional>
30 namespace sd { class Window; }
32 namespace sd::slidesorter { class SlideSorter; }
34 namespace sd::slidesorter::controller {
36 /** Manage the horizontal and vertical scroll bars. Listen for events, set
37 their sizes, place them in the window, determine their visibilities.
39 <p>Handle auto scrolling, i.e. the scrolling of the window when the
40 mouse comes near the window border while dragging a selection.</p>
42 <p>In order to make the slide sorter be used in the task pane with its
43 own vertical scrollbars the vertical scrollbar of the use of the slide
44 sorter is optional. When using it the available area in a window is
45 used and the vertical scrollbar is displayed when that area is not large
46 enough. When the vertical scrollbar is not used then the available area
47 is assumed to be modifiable. In that case the PlaceScrollBars() method
48 may return an area larger than the one given.<p>
50 class ScrollBarManager
52 public:
53 /** Create a new scroll bar manager that manages three controls: the
54 horizontal scroll bar, the vertical scroll bar, and the little
55 window that fills the gap at the bottom right corner that is left
56 between the two scroll bars. Call LateInitialization() after
57 constructing a new object.
59 ScrollBarManager (SlideSorter& rSlideSorter);
61 ~ScrollBarManager();
63 /** Register listeners at the scroll bars. This method is called after
64 startup of a new slide sorter object or after a reactivation of a
65 slide sorter that for example is taken from a cache.
67 void Connect();
69 /** Remove listeners from the scroll bars. This method is called when
70 the slide sorter is destroyed or when it is suspended, e.g. put
71 into a cache for later reuse.
73 void Disconnect();
75 /** Set up the scroll bar, i.e. thumb size and position. Call this
76 method when the content of the browser window changed, i.e. pages
77 were inserted or deleted, the layout or the zoom factor has
78 changed.
79 @param bScrollToCurrentPosition
80 When <TRUE/> then scroll the window to the new offset that is
81 defined by the scroll bars. Otherwise the new offset is simply
82 set and the whole window is repainted.
84 void UpdateScrollBars (
85 bool bScrollToCurrentPosition);
87 /** Place the scroll bars inside the given area. When the available
88 area is not large enough for the content to display the horizontal
89 and/or vertical scroll bar is enabled.
90 @param rAvailableArea
91 The scroll bars will be placed inside this rectangle. It is
92 expected to be given in pixel relative to its parent.
93 @param bIsHorizontalScrollBarAllowed
94 Only when this flag is <TRUE/> the horizontal scroll may be
95 displayed.
96 @param bIsVerticalScrollBarAllowed
97 Only when this flag is <TRUE/> the horizontal scroll may be
98 displayed.
99 @return
100 Returns the space that remains after the scroll bars are
101 placed.
103 ::tools::Rectangle PlaceScrollBars (
104 const ::tools::Rectangle& rAvailableArea,
105 const bool bIsHorizontalScrollBarAllowed,
106 const bool bIsVerticalScrollBarAllowed);
108 /** Update the vertical and horizontal scroll bars so that the visible
109 area has the given top and left values.
111 void SetTopLeft (const Point& rNewTopLeft);
113 /** Return the width of the vertical scroll bar, which--when
114 shown--should be fixed in contrast to its height.
115 @return
116 Returns 0 when the vertical scroll bar is not shown or does not
117 exist, otherwise its width in pixel is returned.
119 int GetVerticalScrollBarWidth() const;
121 /** Return the height of the horizontal scroll bar, which--when
122 shown--should be fixed in contrast to its width.
123 @return
124 Returns 0 when the vertical scroll bar is not shown or does not
125 exist, otherwise its height in pixel is returned.
127 int GetHorizontalScrollBarHeight() const;
129 /** Call this method to scroll a window while the mouse is in dragging a
130 selection. If the mouse is near the window border or is outside the
131 window then scroll the window accordingly.
132 @param rMouseWindowPosition
133 The mouse position for which the scroll amount is calculated.
134 @param rAutoScrollFunctor
135 Every time when the window is scrolled then this functor is executed.
136 @return
137 When the window is scrolled then this method returns <TRUE/>.
138 When the window is not changed then <FALSE/> is returned.
140 bool AutoScroll (
141 const Point& rMouseWindowPosition,
142 const ::std::function<void ()>& rAutoScrollFunctor);
144 void StopAutoScroll();
146 void clearAutoScrollFunctor();
148 enum Orientation { Orientation_Horizontal, Orientation_Vertical };
149 /** Scroll the slide sorter by setting the thumbs of the scroll bars and
150 by moving the content of the content window.
151 @param eOrientation
152 Defines whether to scroll horizontally or vertically.
153 @param nDistance
154 distance in slides.
156 void Scroll(
157 const Orientation eOrientation,
158 const sal_Int32 nDistance);
160 private:
161 SlideSorter& mrSlideSorter;
163 /** The horizontal scroll bar. Note that is used but not owned by
164 objects of this class. It is given to the constructor.
166 VclPtr<ScrollAdaptor> mpHorizontalScrollBar;
168 /** The vertical scroll bar. Note that is used but not owned by
169 objects of this class. It is given to the constructor.
171 VclPtr<ScrollAdaptor> mpVerticalScrollBar;
173 /// Relative horizontal position of the visible area in the view.
174 double mnHorizontalPosition;
175 /// Relative vertical position of the visible area in the view.
176 double mnVerticalPosition;
177 /** The width and height of the border at the inside of the window which
178 when entered while in drag mode leads to a scrolling of the window.
180 Size maScrollBorder;
182 /** The auto scroll timer is used for keep scrolling the window when the
183 mouse reaches its border while dragging a selection. When the mouse
184 is not moved the timer issues events to keep scrolling.
186 Timer maAutoScrollTimer;
187 Size maAutoScrollOffset;
188 bool mbIsAutoScrollActive;
190 /** The content window is the one whose view port is controlled by the
191 scroll bars.
193 VclPtr<sd::Window> mpContentWindow;
195 ::std::function<void ()> maAutoScrollFunctor;
197 void SetWindowOrigin (
198 double nHorizontalPosition,
199 double nVerticalPosition);
201 /** Determine the visibility of the scroll bars so that the window
202 content is not clipped in any dimension without showing a scroll
203 bar.
204 @param rAvailableArea
205 The area in which the scroll bars, the scroll bar filler, and
206 the SlideSorterView will be placed.
207 @return
208 The area that is enclosed by the scroll bars is returned. It
209 will be filled with the SlideSorterView.
211 ::tools::Rectangle DetermineScrollBarVisibilities(
212 const ::tools::Rectangle& rAvailableArea,
213 const bool bIsHorizontalScrollBarAllowed,
214 const bool bIsVerticalScrollBarAllowed);
216 /** Typically called by DetermineScrollBarVisibilities() this method
217 tests a specific configuration of the two scroll bars being visible
218 or hidden.
219 @return
220 When the window content can be shown with only being clipped in
221 an orientation where the scroll bar would be shown then <TRUE/>
222 is returned.
224 bool TestScrollBarVisibilities (
225 bool bHorizontalScrollBarVisible,
226 bool bVerticalScrollBarVisible,
227 const ::tools::Rectangle& rAvailableArea);
229 void CalcAutoScrollOffset (const Point& rMouseWindowPosition);
230 bool RepeatAutoScroll();
232 DECL_LINK(HorizontalScrollBarHandler, weld::Scrollbar&, void);
233 DECL_LINK(VerticalScrollBarHandler, weld::Scrollbar&, void);
234 DECL_LINK(AutoScrollTimeoutHandler, Timer *, void);
236 void PlaceHorizontalScrollBar (const ::tools::Rectangle& aArea);
237 void PlaceVerticalScrollBar (const ::tools::Rectangle& aArea);
240 } // end of namespace ::sd::slidesorter::controller
242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */