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