Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_SDEXT_SOURCE_PRESENTER_PRESENTERSCROLLBAR_HXX
21 : #define INCLUDED_SDEXT_SOURCE_PRESENTER_PRESENTERSCROLLBAR_HXX
22 :
23 : #include "PresenterBitmapContainer.hxx"
24 : #include <com/sun/star/awt/Point.hpp>
25 : #include <com/sun/star/awt/XWindow.hpp>
26 : #include <com/sun/star/drawing/XPresenterHelper.hpp>
27 : #include <com/sun/star/rendering/XCanvas.hpp>
28 : #include <com/sun/star/uno/XComponentContext.hpp>
29 : #include <cppuhelper/basemutex.hxx>
30 : #include <cppuhelper/compbase4.hxx>
31 : #include <boost/function.hpp>
32 : #include <boost/noncopyable.hpp>
33 : #include <boost/scoped_ptr.hpp>
34 : #include <boost/shared_ptr.hpp>
35 :
36 : namespace sdext { namespace presenter {
37 :
38 : class PresenterCanvasHelper;
39 : class PresenterPaintManager;
40 :
41 : namespace {
42 : typedef ::cppu::WeakComponentImplHelper4 <
43 : css::awt::XWindowListener,
44 : css::awt::XPaintListener,
45 : css::awt::XMouseListener,
46 : css::awt::XMouseMotionListener
47 : > PresenterScrollBarInterfaceBase;
48 : }
49 :
50 : /** Base class of horizontal and vertical scroll bars.
51 : */
52 : class PresenterScrollBar
53 : : private ::boost::noncopyable,
54 : private ::cppu::BaseMutex,
55 : public PresenterScrollBarInterfaceBase
56 : {
57 : public:
58 : typedef ::boost::function<void(double)> ThumbMotionListener;
59 : virtual ~PresenterScrollBar (void);
60 :
61 : virtual void SAL_CALL disposing (void) SAL_OVERRIDE;
62 :
63 : void SetVisible (const bool bIsVisible);
64 :
65 : /** Set the bounding box of the scroll bar.
66 : */
67 : void SetPosSize (const css::geometry::RealRectangle2D& rBox);
68 :
69 : /** Set the position of the movable thumb.
70 : @param nPosition
71 : A value between 0 and the last value given to SetTotalSize()
72 : minus the last value given to SetThumbSize().
73 : */
74 : void SetThumbPosition (
75 : double nPosition,
76 : const bool bAsynchronousRepaint);
77 :
78 0 : double GetThumbPosition (void) const { return mnThumbPosition;}
79 :
80 : /** Set the upper border of the slider range.
81 : */
82 : void SetTotalSize (const double nTotalSize);
83 :
84 : /** Set the size of the movable thumb.
85 : @param nThumbSize
86 : A value not larger than the last value given to SetTotalSize().
87 : */
88 : void SetThumbSize (const double nThumbSize);
89 0 : double GetThumbSize (void) const { return mnThumbSize;}
90 :
91 : void SetLineHeight (const double nLineHeight);
92 0 : double GetLineHeight (void) const { return mnLineHeight;}
93 :
94 : /** Set the canvas that is used for painting the scroll bar.
95 : */
96 : void SetCanvas (const css::uno::Reference<css::rendering::XCanvas>& rxCanvas);
97 :
98 : void SetBackground (const SharedBitmapDescriptor& rpBackgroundBitmap);
99 :
100 : /** Call this after changing total size or thumb position or size to
101 : move the thumb to a valid position.
102 : */
103 : void CheckValues (void);
104 :
105 : /** On some occasions it is necessary to trigger the painting of a
106 : scrollbar from the outside.
107 : */
108 : virtual void Paint (
109 : const css::awt::Rectangle& rUpdateBox,
110 : bool bNoClip = false);
111 :
112 : virtual sal_Int32 GetSize (void) const = 0;
113 :
114 : // XWindowListener
115 :
116 : virtual void SAL_CALL windowResized (const css::awt::WindowEvent& rEvent)
117 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
118 :
119 : virtual void SAL_CALL windowMoved (const css::awt::WindowEvent& rEvent)
120 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
121 :
122 : virtual void SAL_CALL windowShown (const css::lang::EventObject& rEvent)
123 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
124 :
125 : virtual void SAL_CALL windowHidden (const css::lang::EventObject& rEvent)
126 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
127 :
128 : // XPaintListener
129 :
130 : virtual void SAL_CALL windowPaint (const css::awt::PaintEvent& rEvent)
131 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
132 :
133 : // XMouseListener
134 :
135 : virtual void SAL_CALL mousePressed (const css::awt::MouseEvent& rEvent)
136 : throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
137 :
138 : virtual void SAL_CALL mouseReleased (const css::awt::MouseEvent& rEvent)
139 : throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
140 :
141 : virtual void SAL_CALL mouseEntered (const css::awt::MouseEvent& rEvent)
142 : throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
143 :
144 : virtual void SAL_CALL mouseExited (const css::awt::MouseEvent& rEvent)
145 : throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
146 :
147 : // XMouseMotionListener
148 :
149 : virtual void SAL_CALL mouseMoved (const css::awt::MouseEvent& rEvent)
150 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
151 :
152 : virtual void SAL_CALL mouseDragged (const css::awt::MouseEvent& rEvent)
153 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
154 :
155 : // lang::XEventListener
156 : virtual void SAL_CALL disposing (const css::lang::EventObject& rEvent)
157 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
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 GetMinor (const double nX, const double nY) const = 0;
196 : virtual void UpdateBorders (void) = 0;
197 : virtual void UpdateBitmaps (void) = 0;
198 : virtual void PaintComposite(
199 : const css::awt::Rectangle& rRepaintBox,
200 : const Area eArea,
201 : const SharedBitmapDescriptor& rpStartBitmaps,
202 : const SharedBitmapDescriptor& rpCenterBitmaps,
203 : const SharedBitmapDescriptor& rpEndBitmaps) = 0;
204 :
205 : PresenterScrollBar (
206 : const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
207 : const css::uno::Reference<css::awt::XWindow>& rxParentWindow,
208 : const ::boost::shared_ptr<PresenterPaintManager>& rpPaintManager,
209 : const ::boost::function<void(double)>& rThumbMotionListener);
210 :
211 : void Repaint (
212 : const css::geometry::RealRectangle2D aBox,
213 : const bool bAsynchronous);
214 : void PaintBackground (
215 : const css::awt::Rectangle& rRepaintBox);
216 : void PaintBitmap(
217 : const css::awt::Rectangle& rRepaintBox,
218 : const Area eArea,
219 : const SharedBitmapDescriptor& rpBitmaps);
220 : void NotifyThumbPositionChange (void);
221 : void UpdateWidthOrHeight (sal_Int32& rSize,
222 : const SharedBitmapDescriptor& rpDescriptor);
223 : css::uno::Reference<css::rendering::XBitmap> GetBitmap (
224 : const Area eArea,
225 : const SharedBitmapDescriptor& rpBitmaps) const;
226 : PresenterBitmapContainer::BitmapDescriptor::Mode GetBitmapMode (
227 : const Area eArea) const;
228 : bool IsDisabled (const Area eArea) const;
229 : double ValidateThumbPosition (double nPosition);
230 : void SetThumbPosition (
231 : double nPosition,
232 : const bool bAsynchronousRepaint,
233 : const bool bValidate,
234 : const bool bNotify);
235 :
236 : private:
237 : class MousePressRepeater;
238 : ::boost::shared_ptr<MousePressRepeater> mpMousePressRepeater;
239 : SharedBitmapDescriptor mpBackgroundBitmap;
240 : ::boost::scoped_ptr<PresenterCanvasHelper> mpCanvasHelper;
241 :
242 : Area GetArea (const double nX, const double nY) const;
243 : };
244 :
245 : /** A vertical scroll bar.
246 : */
247 : class PresenterVerticalScrollBar : public PresenterScrollBar
248 : {
249 : public:
250 : PresenterVerticalScrollBar (
251 : const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
252 : const css::uno::Reference<css::awt::XWindow>& rxParentWindow,
253 : const ::boost::shared_ptr<PresenterPaintManager>& rpPaintManager,
254 : const ::boost::function<void(double)>& rThumbMotionListener);
255 : virtual ~PresenterVerticalScrollBar (void);
256 : virtual sal_Int32 GetSize (void) const SAL_OVERRIDE;
257 :
258 : protected:
259 : virtual double GetDragDistance (const sal_Int32 nX, const sal_Int32 nY) const SAL_OVERRIDE;
260 : virtual void UpdateDragAnchor (const double nDragDistance) SAL_OVERRIDE;
261 : virtual css::geometry::RealPoint2D GetPoint (const double nMajor, const double nMinor) const SAL_OVERRIDE;
262 : virtual double GetMinor (const double nX, const double nY) const SAL_OVERRIDE;
263 : virtual void UpdateBorders (void) SAL_OVERRIDE;
264 : virtual void UpdateBitmaps (void) SAL_OVERRIDE;
265 : virtual void PaintComposite(
266 : const css::awt::Rectangle& rRepaintBox,
267 : const Area eArea,
268 : const SharedBitmapDescriptor& rpStartBitmaps,
269 : const SharedBitmapDescriptor& rpCenterBitmaps,
270 : const SharedBitmapDescriptor& rpEndBitmaps) SAL_OVERRIDE;
271 :
272 : private:
273 : sal_Int32 mnScrollBarWidth;
274 : };
275 :
276 : } } // end of namespace ::sdext::presenter
277 :
278 : #endif
279 :
280 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|