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