merge the formfield patch from ooo-build
[ooovba.git] / sdext / source / presenter / PresenterScrollBar.hxx
blob1fca7b2196c47f405e6a85c8a672caf06588330d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PresenterScrollBar.hxx,v $
11 * $Revision: 1.5 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #ifndef SDEXT_PRESENTER_PRESENTER_SCROLL_BAR_HXX
33 #define SDEXT_PRESENTER_PRESENTER_SCROLL_BAR_HXX
35 #include "PresenterBitmapContainer.hxx"
36 #include <com/sun/star/awt/Point.hpp>
37 #include <com/sun/star/awt/XWindow.hpp>
38 #include <com/sun/star/drawing/XPresenterHelper.hpp>
39 #include <com/sun/star/rendering/XCanvas.hpp>
40 #include <com/sun/star/uno/XComponentContext.hpp>
41 #include <cppuhelper/basemutex.hxx>
42 #include <cppuhelper/compbase4.hxx>
43 #include <boost/function.hpp>
44 #include <boost/noncopyable.hpp>
45 #include <boost/shared_ptr.hpp>
47 namespace css = ::com::sun::star;
49 namespace sdext { namespace presenter {
51 class PresenterCanvasHelper;
52 class PresenterPaintManager;
54 namespace {
55 typedef ::cppu::WeakComponentImplHelper4 <
56 css::awt::XWindowListener,
57 css::awt::XPaintListener,
58 css::awt::XMouseListener,
59 css::awt::XMouseMotionListener
60 > PresenterScrollBarInterfaceBase;
63 /** Base class of horizontal and vertical scroll bars.
65 class PresenterScrollBar
66 : private ::boost::noncopyable,
67 private ::cppu::BaseMutex,
68 public PresenterScrollBarInterfaceBase
70 public:
71 typedef ::boost::function<void(double)> ThumbMotionListener;
72 virtual ~PresenterScrollBar (void);
74 virtual void SAL_CALL disposing (void);
76 void SetVisible (const bool bIsVisible);
78 /** Set the bounding box of the scroll bar.
80 void SetPosSize (const css::geometry::RealRectangle2D& rBox);
82 /** Set the position of the movable thumb.
83 @param nPosition
84 A value between 0 and the last value given to SetTotalSize()
85 minus the last value given to SetThumbSize().
87 void SetThumbPosition (
88 double nPosition,
89 const bool bAsynchronousRepaint);
91 double GetThumbPosition (void) const;
93 /** Set the upper border of the slider range.
95 void SetTotalSize (const double nTotalSize);
97 double GetTotalSize (void) const;
99 /** Set the size of the movable thumb.
100 @param nThumbSize
101 A value not larger than the last value given to SetTotalSize().
103 void SetThumbSize (const double nThumbSize);
104 double GetThumbSize (void) const;
106 void SetLineHeight (const double nLineHeight);
107 double GetLineHeight (void) const;
109 /** Set the canvas that is used for painting the scroll bar.
111 void SetCanvas (const css::uno::Reference<css::rendering::XCanvas>& rxCanvas);
113 void SetBackground (const SharedBitmapDescriptor& rpBackgroundBitmap);
115 /** Call this after changing total size or thumb position or size to
116 move the thumb to a valid position.
118 void CheckValues (void);
120 /** On some occasions it is necessary to trigger the painting of a
121 scrollbar from the outside.
123 virtual void Paint (
124 const css::awt::Rectangle& rUpdateBox,
125 bool bNoClip = false);
127 virtual sal_Int32 GetSize (void) const = 0;
129 // XWindowListener
131 virtual void SAL_CALL windowResized (const css::awt::WindowEvent& rEvent)
132 throw (css::uno::RuntimeException);
134 virtual void SAL_CALL windowMoved (const css::awt::WindowEvent& rEvent)
135 throw (css::uno::RuntimeException);
137 virtual void SAL_CALL windowShown (const css::lang::EventObject& rEvent)
138 throw (css::uno::RuntimeException);
140 virtual void SAL_CALL windowHidden (const css::lang::EventObject& rEvent)
141 throw (css::uno::RuntimeException);
144 // XPaintListener
146 virtual void SAL_CALL windowPaint (const css::awt::PaintEvent& rEvent)
147 throw (css::uno::RuntimeException);
150 // XMouseListener
152 virtual void SAL_CALL mousePressed (const css::awt::MouseEvent& rEvent)
153 throw(css::uno::RuntimeException);
155 virtual void SAL_CALL mouseReleased (const css::awt::MouseEvent& rEvent)
156 throw(css::uno::RuntimeException);
158 virtual void SAL_CALL mouseEntered (const css::awt::MouseEvent& rEvent)
159 throw(css::uno::RuntimeException);
161 virtual void SAL_CALL mouseExited (const css::awt::MouseEvent& rEvent)
162 throw(css::uno::RuntimeException);
165 // XMouseMotionListener
167 virtual void SAL_CALL mouseMoved (const css::awt::MouseEvent& rEvent)
168 throw (css::uno::RuntimeException);
170 virtual void SAL_CALL mouseDragged (const css::awt::MouseEvent& rEvent)
171 throw (css::uno::RuntimeException);
174 // lang::XEventListener
175 virtual void SAL_CALL disposing (const css::lang::EventObject& rEvent)
176 throw (css::uno::RuntimeException);
179 enum Area { Total, Pager, Thumb, PagerUp, PagerDown, PrevButton, NextButton, None,
180 __AreaCount__ = None };
182 protected:
183 css::uno::Reference<css::uno::XComponentContext> mxComponentContext;
184 css::uno::Reference<css::awt::XWindow> mxParentWindow;
185 css::uno::Reference<css::awt::XWindow> mxWindow;
186 css::uno::Reference<css::rendering::XCanvas> mxCanvas;
187 css::uno::Reference<css::drawing::XPresenterHelper> mxPresenterHelper;
188 ::boost::shared_ptr<PresenterPaintManager> mpPaintManager;
189 double mnThumbPosition;
190 double mnTotalSize;
191 double mnThumbSize;
192 double mnLineHeight;
193 css::geometry::RealPoint2D maDragAnchor;
194 ::boost::function<void(double)> maThumbMotionListener;
195 Area meButtonDownArea;
196 Area meMouseMoveArea;
197 css::geometry::RealRectangle2D maBox[__AreaCount__];
198 bool mbIsNotificationActive;
199 static boost::weak_ptr<PresenterBitmapContainer> mpSharedBitmaps;
200 boost::shared_ptr<PresenterBitmapContainer> mpBitmaps;
201 SharedBitmapDescriptor mpPrevButtonDescriptor;
202 SharedBitmapDescriptor mpNextButtonDescriptor;
203 SharedBitmapDescriptor mpPagerStartDescriptor;
204 SharedBitmapDescriptor mpPagerCenterDescriptor;
205 SharedBitmapDescriptor mpPagerEndDescriptor;
206 SharedBitmapDescriptor mpThumbStartDescriptor;
207 SharedBitmapDescriptor mpThumbCenterDescriptor;
208 SharedBitmapDescriptor mpThumbEndDescriptor;
209 bool maEnabledState[__AreaCount__];
211 virtual css::geometry::RealRectangle2D GetRectangle (const Area eArea) const;
212 virtual double GetDragDistance (const sal_Int32 nX, const sal_Int32 nY) const = 0;
213 virtual void UpdateDragAnchor (const double nDragDistance) = 0;
214 virtual css::geometry::RealPoint2D GetPoint (const double nMajor, const double nMinor) const = 0;
215 virtual double GetMajor (const double nX, const double nY) const = 0;
216 virtual double GetMinor (const double nX, const double nY) const = 0;
217 virtual void UpdateBorders (void) = 0;
218 virtual void UpdateBitmaps (void) = 0;
219 virtual void PaintComposite(
220 const css::awt::Rectangle& rRepaintBox,
221 const Area eArea,
222 const SharedBitmapDescriptor& rpStartBitmaps,
223 const SharedBitmapDescriptor& rpCenterBitmaps,
224 const SharedBitmapDescriptor& rpEndBitmaps) = 0;
226 PresenterScrollBar (
227 const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
228 const css::uno::Reference<css::awt::XWindow>& rxParentWindow,
229 const ::boost::shared_ptr<PresenterPaintManager>& rpPaintManager,
230 const ::boost::function<void(double)>& rThumbMotionListener);
232 void Repaint (
233 const css::geometry::RealRectangle2D aBox,
234 const bool bAsynchronous);
235 void PaintBackground (
236 const css::awt::Rectangle& rRepaintBox);
237 void PaintBitmap(
238 const css::awt::Rectangle& rRepaintBox,
239 const Area eArea,
240 const SharedBitmapDescriptor& rpBitmaps);
241 void NotifyThumbPositionChange (void);
242 void UpdateWidthOrHeight (sal_Int32& rSize,
243 const SharedBitmapDescriptor& rpDescriptor);
244 css::uno::Reference<css::rendering::XBitmap> GetBitmap (
245 const Area eArea,
246 const SharedBitmapDescriptor& rpBitmaps) const;
247 PresenterBitmapContainer::BitmapDescriptor::Mode GetBitmapMode (
248 const Area eArea) const;
249 bool IsDisabled (const Area eArea) const;
250 double ValidateThumbPosition (double nPosition);
251 void SetThumbPosition (
252 double nPosition,
253 const bool bAsynchronousRepaint,
254 const bool bValidate,
255 const bool bNotify);
257 private:
258 class MousePressRepeater;
259 ::boost::shared_ptr<MousePressRepeater> mpMousePressRepeater;
260 SharedBitmapDescriptor mpBackgroundBitmap;
261 ::boost::scoped_ptr<PresenterCanvasHelper> mpCanvasHelper;
263 Area GetArea (const double nX, const double nY) const;
269 /** A vertical scroll bar.
271 class PresenterVerticalScrollBar : public PresenterScrollBar
273 public:
274 PresenterVerticalScrollBar (
275 const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
276 const css::uno::Reference<css::awt::XWindow>& rxParentWindow,
277 const ::boost::shared_ptr<PresenterPaintManager>& rpPaintManager,
278 const ::boost::function<void(double)>& rThumbMotionListener);
279 virtual ~PresenterVerticalScrollBar (void);
280 virtual sal_Int32 GetSize (void) const;
282 protected:
283 virtual double GetDragDistance (const sal_Int32 nX, const sal_Int32 nY) const;
284 virtual void UpdateDragAnchor (const double nDragDistance);
285 virtual css::geometry::RealPoint2D GetPoint (const double nMajor, const double nMinor) const;
286 virtual double GetMinor (const double nX, const double nY) const;
287 virtual double GetMajor (const double nX, const double nY) const;
288 virtual void UpdateBorders (void);
289 virtual void UpdateBitmaps (void);
290 virtual void PaintComposite(
291 const css::awt::Rectangle& rRepaintBox,
292 const Area eArea,
293 const SharedBitmapDescriptor& rpStartBitmaps,
294 const SharedBitmapDescriptor& rpCenterBitmaps,
295 const SharedBitmapDescriptor& rpEndBitmaps);
297 private:
298 sal_Int32 mnScrollBarWidth;
304 /** A horizontal scroll bar.
306 class PresenterHorizontalScrollBar : public PresenterScrollBar
308 public:
309 PresenterHorizontalScrollBar (
310 const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
311 const css::uno::Reference<css::awt::XWindow>& rxParentWindow,
312 const ::boost::shared_ptr<PresenterPaintManager>& rpPaintManager,
313 const ::boost::function<void(double)>& rThumbMotionListener);
314 virtual ~PresenterHorizontalScrollBar (void);
315 virtual sal_Int32 GetSize (void) const;
317 protected:
318 virtual double GetDragDistance (const sal_Int32 nX, const sal_Int32 nY) const;
319 virtual void UpdateDragAnchor (const double nDragDistance);
320 virtual css::geometry::RealPoint2D GetPoint (const double nMajor, const double nMinor) const;
321 virtual double GetMinor (const double nX, const double nY) const;
322 virtual double GetMajor (const double nX, const double nY) const;
323 virtual void UpdateBorders (void);
324 virtual void UpdateBitmaps (void);
325 virtual void PaintComposite(
326 const css::awt::Rectangle& rRepaintBox,
327 const Area eArea,
328 const SharedBitmapDescriptor& rpStartBitmaps,
329 const SharedBitmapDescriptor& rpCenterBitmaps,
330 const SharedBitmapDescriptor& rpEndBitmaps);
332 private:
333 sal_Int32 mnScrollBarHeight;
339 } } // end of namespace ::sdext::presenter
341 #endif