xref: /trunk/main/sdext/source/presenter/PresenterScrollBar.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SDEXT_PRESENTER_PRESENTER_SCROLL_BAR_HXX
25 #define SDEXT_PRESENTER_PRESENTER_SCROLL_BAR_HXX
26 
27 #include "PresenterBitmapContainer.hxx"
28 #include <com/sun/star/awt/Point.hpp>
29 #include <com/sun/star/awt/XWindow.hpp>
30 #include <com/sun/star/drawing/XPresenterHelper.hpp>
31 #include <com/sun/star/rendering/XCanvas.hpp>
32 #include <com/sun/star/uno/XComponentContext.hpp>
33 #include <cppuhelper/basemutex.hxx>
34 #include <cppuhelper/compbase4.hxx>
35 #include <boost/function.hpp>
36 #include <boost/noncopyable.hpp>
37 #include <boost/shared_ptr.hpp>
38 
39 namespace css = ::com::sun::star;
40 
41 namespace sdext { namespace presenter {
42 
43 class PresenterCanvasHelper;
44 class PresenterPaintManager;
45 
46 namespace {
47     typedef ::cppu::WeakComponentImplHelper4 <
48         css::awt::XWindowListener,
49         css::awt::XPaintListener,
50         css::awt::XMouseListener,
51         css::awt::XMouseMotionListener
52     > PresenterScrollBarInterfaceBase;
53 }
54 
55 /** Base class of horizontal and vertical scroll bars.
56 */
57 class PresenterScrollBar
58     : private ::boost::noncopyable,
59       private ::cppu::BaseMutex,
60       public PresenterScrollBarInterfaceBase
61 {
62 public:
63     typedef ::boost::function<void(double)> ThumbMotionListener;
64     virtual ~PresenterScrollBar (void);
65 
66     virtual void SAL_CALL disposing (void);
67 
68     void SetVisible (const bool bIsVisible);
69 
70     /** Set the bounding box of the scroll bar.
71     */
72     void SetPosSize (const css::geometry::RealRectangle2D& rBox);
73 
74     /** Set the position of the movable thumb.
75         @param nPosition
76             A value between 0 and the last value given to SetTotalSize()
77             minus the last value given to SetThumbSize().
78     */
79     void SetThumbPosition (
80         double nPosition,
81         const bool bAsynchronousRepaint);
82 
83     double GetThumbPosition (void) const;
84 
85     /** Set the upper border of the slider range.
86     */
87     void SetTotalSize (const double nTotalSize);
88 
89     double GetTotalSize (void) const;
90 
91     /** Set the size of the movable thumb.
92         @param nThumbSize
93             A value not larger than the last value given to SetTotalSize().
94     */
95     void SetThumbSize (const double nThumbSize);
96     double GetThumbSize (void) const;
97 
98     void SetLineHeight (const double nLineHeight);
99     double GetLineHeight (void) const;
100 
101     /** Set the canvas that is used for painting the scroll bar.
102     */
103     void SetCanvas (const css::uno::Reference<css::rendering::XCanvas>& rxCanvas);
104 
105     void SetBackground (const SharedBitmapDescriptor& rpBackgroundBitmap);
106 
107     /** Call this after changing total size or thumb position or size to
108         move the thumb to a valid position.
109     */
110     void CheckValues (void);
111 
112     /** On some occasions it is necessary to trigger the painting of a
113         scrollbar from the outside.
114     */
115     virtual void Paint (
116         const css::awt::Rectangle& rUpdateBox,
117         bool bNoClip = false);
118 
119     virtual sal_Int32 GetSize (void) const = 0;
120 
121     // XWindowListener
122 
123     virtual void SAL_CALL windowResized (const css::awt::WindowEvent& rEvent);
124 
125     virtual void SAL_CALL windowMoved (const css::awt::WindowEvent& rEvent);
126 
127     virtual void SAL_CALL windowShown (const css::lang::EventObject& rEvent);
128 
129     virtual void SAL_CALL windowHidden (const css::lang::EventObject& rEvent);
130 
131 
132     // XPaintListener
133 
134     virtual void SAL_CALL windowPaint (const css::awt::PaintEvent& rEvent);
135 
136 
137     // XMouseListener
138 
139     virtual void SAL_CALL mousePressed (const css::awt::MouseEvent& rEvent);
140 
141     virtual void SAL_CALL mouseReleased (const css::awt::MouseEvent& rEvent);
142 
143     virtual void SAL_CALL mouseEntered (const css::awt::MouseEvent& rEvent);
144 
145     virtual void SAL_CALL mouseExited (const css::awt::MouseEvent& rEvent);
146 
147 
148     // XMouseMotionListener
149 
150     virtual void SAL_CALL mouseMoved (const css::awt::MouseEvent& rEvent);
151 
152     virtual void SAL_CALL mouseDragged (const css::awt::MouseEvent& rEvent);
153 
154 
155     // lang::XEventListener
156     virtual void SAL_CALL disposing (const css::lang::EventObject& rEvent);
157 
158 
159     enum Area { Total, Pager, Thumb, PagerUp, PagerDown, PrevButton, NextButton, None,
160                 __AreaCount__ = None };
161 
162 protected:
163     css::uno::Reference<css::uno::XComponentContext> mxComponentContext;
164     css::uno::Reference<css::awt::XWindow> mxParentWindow;
165     css::uno::Reference<css::awt::XWindow> mxWindow;
166     css::uno::Reference<css::rendering::XCanvas> mxCanvas;
167     css::uno::Reference<css::drawing::XPresenterHelper> mxPresenterHelper;
168     ::boost::shared_ptr<PresenterPaintManager> mpPaintManager;
169     double mnThumbPosition;
170     double mnTotalSize;
171     double mnThumbSize;
172     double mnLineHeight;
173     css::geometry::RealPoint2D maDragAnchor;
174     ::boost::function<void(double)> maThumbMotionListener;
175     Area meButtonDownArea;
176     Area meMouseMoveArea;
177     css::geometry::RealRectangle2D maBox[__AreaCount__];
178     bool mbIsNotificationActive;
179     static boost::weak_ptr<PresenterBitmapContainer> mpSharedBitmaps;
180     boost::shared_ptr<PresenterBitmapContainer> mpBitmaps;
181     SharedBitmapDescriptor mpPrevButtonDescriptor;
182     SharedBitmapDescriptor mpNextButtonDescriptor;
183     SharedBitmapDescriptor mpPagerStartDescriptor;
184     SharedBitmapDescriptor mpPagerCenterDescriptor;
185     SharedBitmapDescriptor mpPagerEndDescriptor;
186     SharedBitmapDescriptor mpThumbStartDescriptor;
187     SharedBitmapDescriptor mpThumbCenterDescriptor;
188     SharedBitmapDescriptor mpThumbEndDescriptor;
189     bool maEnabledState[__AreaCount__];
190 
191     virtual css::geometry::RealRectangle2D GetRectangle (const Area eArea) const;
192     virtual double GetDragDistance (const sal_Int32 nX, const sal_Int32 nY) const = 0;
193     virtual void UpdateDragAnchor (const double nDragDistance) = 0;
194     virtual css::geometry::RealPoint2D GetPoint (const double nMajor, const double nMinor) const = 0;
195     virtual double GetMajor (const double nX, const double nY) const = 0;
196     virtual double GetMinor (const double nX, const double nY) const = 0;
197     virtual void UpdateBorders (void) = 0;
198     virtual void UpdateBitmaps (void) = 0;
199     virtual void PaintComposite(
200         const css::awt::Rectangle& rRepaintBox,
201         const Area eArea,
202         const SharedBitmapDescriptor& rpStartBitmaps,
203         const SharedBitmapDescriptor& rpCenterBitmaps,
204         const SharedBitmapDescriptor& rpEndBitmaps) = 0;
205 
206     PresenterScrollBar (
207         const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
208         const css::uno::Reference<css::awt::XWindow>& rxParentWindow,
209         const ::boost::shared_ptr<PresenterPaintManager>& rpPaintManager,
210         const ::boost::function<void(double)>& rThumbMotionListener);
211 
212     void Repaint (
213         const css::geometry::RealRectangle2D aBox,
214         const bool bAsynchronous);
215     void PaintBackground (
216         const css::awt::Rectangle& rRepaintBox);
217     void PaintBitmap(
218         const css::awt::Rectangle& rRepaintBox,
219         const Area eArea,
220         const SharedBitmapDescriptor& rpBitmaps);
221     void NotifyThumbPositionChange (void);
222     void UpdateWidthOrHeight (sal_Int32& rSize,
223         const SharedBitmapDescriptor& rpDescriptor);
224     css::uno::Reference<css::rendering::XBitmap> GetBitmap (
225         const Area eArea,
226         const SharedBitmapDescriptor& rpBitmaps) const;
227     PresenterBitmapContainer::BitmapDescriptor::Mode GetBitmapMode (
228         const Area eArea) const;
229     bool IsDisabled (const Area eArea) const;
230     double ValidateThumbPosition (double nPosition);
231     void SetThumbPosition (
232         double nPosition,
233         const bool bAsynchronousRepaint,
234         const bool bValidate,
235         const bool bNotify);
236 
237 private:
238     class MousePressRepeater;
239     ::boost::shared_ptr<MousePressRepeater> mpMousePressRepeater;
240     SharedBitmapDescriptor mpBackgroundBitmap;
241     ::boost::scoped_ptr<PresenterCanvasHelper> mpCanvasHelper;
242 
243     Area GetArea (const double nX, const double nY) const;
244 };
245 
246 
247 
248 
249 /** A vertical scroll bar.
250 */
251 class PresenterVerticalScrollBar : public PresenterScrollBar
252 {
253 public:
254     PresenterVerticalScrollBar (
255         const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
256         const css::uno::Reference<css::awt::XWindow>& rxParentWindow,
257         const ::boost::shared_ptr<PresenterPaintManager>& rpPaintManager,
258         const ::boost::function<void(double)>& rThumbMotionListener);
259     virtual ~PresenterVerticalScrollBar (void);
260     virtual sal_Int32 GetSize (void) const;
261 
262 protected:
263     virtual double GetDragDistance (const sal_Int32 nX, const sal_Int32 nY) const;
264     virtual void UpdateDragAnchor (const double nDragDistance);
265     virtual css::geometry::RealPoint2D GetPoint (const double nMajor, const double nMinor) const;
266     virtual double GetMinor (const double nX, const double nY) const;
267     virtual double GetMajor (const double nX, const double nY) const;
268     virtual void UpdateBorders (void);
269     virtual void UpdateBitmaps (void);
270     virtual void PaintComposite(
271         const css::awt::Rectangle& rRepaintBox,
272         const Area eArea,
273         const SharedBitmapDescriptor& rpStartBitmaps,
274         const SharedBitmapDescriptor& rpCenterBitmaps,
275         const SharedBitmapDescriptor& rpEndBitmaps);
276 
277 private:
278     sal_Int32 mnScrollBarWidth;
279 };
280 
281 
282 
283 
284 /** A horizontal scroll bar.
285 */
286 class PresenterHorizontalScrollBar : public PresenterScrollBar
287 {
288 public:
289     PresenterHorizontalScrollBar (
290         const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
291         const css::uno::Reference<css::awt::XWindow>& rxParentWindow,
292         const ::boost::shared_ptr<PresenterPaintManager>& rpPaintManager,
293         const ::boost::function<void(double)>& rThumbMotionListener);
294     virtual ~PresenterHorizontalScrollBar (void);
295     virtual sal_Int32 GetSize (void) const;
296 
297 protected:
298     virtual double GetDragDistance (const sal_Int32 nX, const sal_Int32 nY) const;
299     virtual void UpdateDragAnchor (const double nDragDistance);
300     virtual css::geometry::RealPoint2D GetPoint (const double nMajor, const double nMinor) const;
301     virtual double GetMinor (const double nX, const double nY) const;
302     virtual double GetMajor (const double nX, const double nY) const;
303     virtual void UpdateBorders (void);
304     virtual void UpdateBitmaps (void);
305     virtual void PaintComposite(
306         const css::awt::Rectangle& rRepaintBox,
307         const Area eArea,
308         const SharedBitmapDescriptor& rpStartBitmaps,
309         const SharedBitmapDescriptor& rpCenterBitmaps,
310         const SharedBitmapDescriptor& rpEndBitmaps);
311 
312 private:
313     sal_Int32 mnScrollBarHeight;
314 };
315 
316 
317 
318 
319 } } // end of namespace ::sdext::presenter
320 
321 #endif
322