1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SDEXT_SOURCE_PRESENTER_PRESENTERSCROLLBAR_HXX
21 #define INCLUDED_SDEXT_SOURCE_PRESENTER_PRESENTERSCROLLBAR_HXX
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>
36 namespace sdext
{ namespace presenter
{
38 class PresenterCanvasHelper
;
39 class PresenterPaintManager
;
42 typedef ::cppu::WeakComponentImplHelper4
<
43 css::awt::XWindowListener
,
44 css::awt::XPaintListener
,
45 css::awt::XMouseListener
,
46 css::awt::XMouseMotionListener
47 > PresenterScrollBarInterfaceBase
;
50 /** Base class of horizontal and vertical scroll bars.
52 class PresenterScrollBar
53 : private ::boost::noncopyable
,
54 private ::cppu::BaseMutex
,
55 public PresenterScrollBarInterfaceBase
58 typedef ::boost::function
<void(double)> ThumbMotionListener
;
59 virtual ~PresenterScrollBar();
61 virtual void SAL_CALL
disposing() SAL_OVERRIDE
;
63 void SetVisible (const bool bIsVisible
);
65 /** Set the bounding box of the scroll bar.
67 void SetPosSize (const css::geometry::RealRectangle2D
& rBox
);
69 /** Set the position of the movable thumb.
71 A value between 0 and the last value given to SetTotalSize()
72 minus the last value given to SetThumbSize().
74 void SetThumbPosition (
76 const bool bAsynchronousRepaint
);
78 double GetThumbPosition() const { return mnThumbPosition
;}
80 /** Set the upper border of the slider range.
82 void SetTotalSize (const double nTotalSize
);
84 /** Set the size of the movable thumb.
86 A value not larger than the last value given to SetTotalSize().
88 void SetThumbSize (const double nThumbSize
);
89 double GetThumbSize() const { return mnThumbSize
;}
91 void SetLineHeight (const double nLineHeight
);
92 double GetLineHeight() const { return mnLineHeight
;}
94 /** Set the canvas that is used for painting the scroll bar.
96 void SetCanvas (const css::uno::Reference
<css::rendering::XCanvas
>& rxCanvas
);
98 void SetBackground (const SharedBitmapDescriptor
& rpBackgroundBitmap
);
100 /** Call this after changing total size or thumb position or size to
101 move the thumb to a valid position.
105 /** On some occasions it is necessary to trigger the painting of a
106 scrollbar from the outside.
109 const css::awt::Rectangle
& rUpdateBox
,
110 bool bNoClip
= false);
112 virtual sal_Int32
GetSize() const = 0;
116 virtual void SAL_CALL
windowResized (const css::awt::WindowEvent
& rEvent
)
117 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
119 virtual void SAL_CALL
windowMoved (const css::awt::WindowEvent
& rEvent
)
120 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
122 virtual void SAL_CALL
windowShown (const css::lang::EventObject
& rEvent
)
123 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
125 virtual void SAL_CALL
windowHidden (const css::lang::EventObject
& rEvent
)
126 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
130 virtual void SAL_CALL
windowPaint (const css::awt::PaintEvent
& rEvent
)
131 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
135 virtual void SAL_CALL
mousePressed (const css::awt::MouseEvent
& rEvent
)
136 throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
138 virtual void SAL_CALL
mouseReleased (const css::awt::MouseEvent
& rEvent
)
139 throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
141 virtual void SAL_CALL
mouseEntered (const css::awt::MouseEvent
& rEvent
)
142 throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
144 virtual void SAL_CALL
mouseExited (const css::awt::MouseEvent
& rEvent
)
145 throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
147 // XMouseMotionListener
149 virtual void SAL_CALL
mouseMoved (const css::awt::MouseEvent
& rEvent
)
150 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
152 virtual void SAL_CALL
mouseDragged (const css::awt::MouseEvent
& rEvent
)
153 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
155 // lang::XEventListener
156 virtual void SAL_CALL
disposing (const css::lang::EventObject
& rEvent
)
157 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
159 enum Area
{ Total
, Pager
, Thumb
, PagerUp
, PagerDown
, PrevButton
, NextButton
, None
,
160 __AreaCount__
= None
};
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
;
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__
];
191 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() = 0;
197 virtual void UpdateBitmaps() = 0;
198 virtual void PaintComposite(
199 const css::awt::Rectangle
& rRepaintBox
,
201 const SharedBitmapDescriptor
& rpStartBitmaps
,
202 const SharedBitmapDescriptor
& rpCenterBitmaps
,
203 const SharedBitmapDescriptor
& rpEndBitmaps
) = 0;
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
);
212 const css::geometry::RealRectangle2D
& rBox
,
213 const bool bAsynchronous
);
214 void PaintBackground (
215 const css::awt::Rectangle
& rRepaintBox
);
217 const css::awt::Rectangle
& rRepaintBox
,
219 const SharedBitmapDescriptor
& rpBitmaps
);
220 void NotifyThumbPositionChange();
221 void UpdateWidthOrHeight (sal_Int32
& rSize
,
222 const SharedBitmapDescriptor
& rpDescriptor
);
223 css::uno::Reference
<css::rendering::XBitmap
> GetBitmap (
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 (
232 const bool bAsynchronousRepaint
,
233 const bool bValidate
,
237 class MousePressRepeater
;
238 ::boost::shared_ptr
<MousePressRepeater
> mpMousePressRepeater
;
239 SharedBitmapDescriptor mpBackgroundBitmap
;
240 ::boost::scoped_ptr
<PresenterCanvasHelper
> mpCanvasHelper
;
242 Area
GetArea (const double nX
, const double nY
) const;
245 /** A vertical scroll bar.
247 class PresenterVerticalScrollBar
: public PresenterScrollBar
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();
256 virtual sal_Int32
GetSize() const SAL_OVERRIDE
;
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() SAL_OVERRIDE
;
264 virtual void UpdateBitmaps() SAL_OVERRIDE
;
265 virtual void PaintComposite(
266 const css::awt::Rectangle
& rRepaintBox
,
268 const SharedBitmapDescriptor
& rpStartBitmaps
,
269 const SharedBitmapDescriptor
& rpCenterBitmaps
,
270 const SharedBitmapDescriptor
& rpEndBitmaps
) SAL_OVERRIDE
;
273 sal_Int32 mnScrollBarWidth
;
276 } } // end of namespace ::sdext::presenter
280 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */