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/compbase.hxx>
35 namespace sdext
{ namespace presenter
{
37 class PresenterCanvasHelper
;
38 class PresenterPaintManager
;
40 typedef ::cppu::WeakComponentImplHelper
<
41 css::awt::XWindowListener
,
42 css::awt::XPaintListener
,
43 css::awt::XMouseListener
,
44 css::awt::XMouseMotionListener
45 > PresenterScrollBarInterfaceBase
;
47 /** Base class of horizontal and vertical scroll bars.
49 class PresenterScrollBar
50 : private ::cppu::BaseMutex
,
51 public PresenterScrollBarInterfaceBase
54 virtual ~PresenterScrollBar() override
;
55 PresenterScrollBar(const PresenterScrollBar
&) = delete;
56 PresenterScrollBar
& operator=(const PresenterScrollBar
&) = delete;
58 virtual void SAL_CALL
disposing() override
;
60 css::uno::Reference
<css::uno::XComponentContext
> const&
61 GetComponentContext() { return mxComponentContext
; }
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
);
111 virtual sal_Int32
GetSize() const = 0;
115 virtual void SAL_CALL
windowResized (const css::awt::WindowEvent
& rEvent
) override
;
117 virtual void SAL_CALL
windowMoved (const css::awt::WindowEvent
& rEvent
) override
;
119 virtual void SAL_CALL
windowShown (const css::lang::EventObject
& rEvent
) override
;
121 virtual void SAL_CALL
windowHidden (const css::lang::EventObject
& rEvent
) override
;
125 virtual void SAL_CALL
windowPaint (const css::awt::PaintEvent
& rEvent
) override
;
129 virtual void SAL_CALL
mousePressed (const css::awt::MouseEvent
& rEvent
) override
;
131 virtual void SAL_CALL
mouseReleased (const css::awt::MouseEvent
& rEvent
) override
;
133 virtual void SAL_CALL
mouseEntered (const css::awt::MouseEvent
& rEvent
) override
;
135 virtual void SAL_CALL
mouseExited (const css::awt::MouseEvent
& rEvent
) override
;
137 // XMouseMotionListener
139 virtual void SAL_CALL
mouseMoved (const css::awt::MouseEvent
& rEvent
) override
;
141 virtual void SAL_CALL
mouseDragged (const css::awt::MouseEvent
& rEvent
) override
;
143 // lang::XEventListener
144 virtual void SAL_CALL
disposing (const css::lang::EventObject
& rEvent
) override
;
146 enum Area
{ Total
, Pager
, Thumb
, PagerUp
, PagerDown
, PrevButton
, NextButton
, None
,
150 css::uno::Reference
<css::uno::XComponentContext
> mxComponentContext
;
151 css::uno::Reference
<css::awt::XWindow
> mxWindow
;
152 css::uno::Reference
<css::rendering::XCanvas
> mxCanvas
;
153 css::uno::Reference
<css::drawing::XPresenterHelper
> mxPresenterHelper
;
154 std::shared_ptr
<PresenterPaintManager
> mpPaintManager
;
155 double mnThumbPosition
;
159 css::geometry::RealPoint2D maDragAnchor
;
160 ::std::function
<void (double)> maThumbMotionListener
;
161 Area meButtonDownArea
;
162 Area meMouseMoveArea
;
163 css::geometry::RealRectangle2D maBox
[AreaCount
];
164 bool mbIsNotificationActive
;
165 static std::weak_ptr
<PresenterBitmapContainer
> mpSharedBitmaps
;
166 std::shared_ptr
<PresenterBitmapContainer
> mpBitmaps
;
167 SharedBitmapDescriptor mpPrevButtonDescriptor
;
168 SharedBitmapDescriptor mpNextButtonDescriptor
;
169 SharedBitmapDescriptor mpPagerStartDescriptor
;
170 SharedBitmapDescriptor mpPagerCenterDescriptor
;
171 SharedBitmapDescriptor mpPagerEndDescriptor
;
172 SharedBitmapDescriptor mpThumbStartDescriptor
;
173 SharedBitmapDescriptor mpThumbCenterDescriptor
;
174 SharedBitmapDescriptor mpThumbEndDescriptor
;
175 bool maEnabledState
[AreaCount
];
177 css::geometry::RealRectangle2D
const & GetRectangle (const Area eArea
) const;
178 virtual double GetDragDistance (const sal_Int32 nX
, const sal_Int32 nY
) const = 0;
179 virtual void UpdateDragAnchor (const double nDragDistance
) = 0;
180 virtual double GetMinor (const double nX
, const double nY
) const = 0;
181 virtual void UpdateBorders() = 0;
182 virtual void UpdateBitmaps() = 0;
183 virtual void PaintComposite(
184 const css::awt::Rectangle
& rRepaintBox
,
186 const SharedBitmapDescriptor
& rpStartBitmaps
,
187 const SharedBitmapDescriptor
& rpCenterBitmaps
,
188 const SharedBitmapDescriptor
& rpEndBitmaps
) = 0;
191 const css::uno::Reference
<css::uno::XComponentContext
>& rxComponentContext
,
192 const css::uno::Reference
<css::awt::XWindow
>& rxParentWindow
,
193 const std::shared_ptr
<PresenterPaintManager
>& rpPaintManager
,
194 const ::std::function
<void (double)>& rThumbMotionListener
);
197 const css::geometry::RealRectangle2D
& rBox
,
198 const bool bAsynchronous
);
199 void PaintBackground (
200 const css::awt::Rectangle
& rRepaintBox
);
202 const css::awt::Rectangle
& rRepaintBox
,
204 const SharedBitmapDescriptor
& rpBitmaps
);
205 void UpdateWidthOrHeight (sal_Int32
& rSize
,
206 const SharedBitmapDescriptor
& rpDescriptor
);
207 css::uno::Reference
<css::rendering::XBitmap
> GetBitmap (
209 const SharedBitmapDescriptor
& rpBitmaps
) const;
210 PresenterBitmapContainer::BitmapDescriptor::Mode
GetBitmapMode (
211 const Area eArea
) const;
212 bool IsDisabled (const Area eArea
) const;
213 double ValidateThumbPosition (double nPosition
);
216 class MousePressRepeater
;
217 std::shared_ptr
<MousePressRepeater
> mpMousePressRepeater
;
218 SharedBitmapDescriptor mpBackgroundBitmap
;
219 std::unique_ptr
<PresenterCanvasHelper
> mpCanvasHelper
;
221 Area
GetArea (const double nX
, const double nY
) const;
224 /** A vertical scroll bar.
226 class PresenterVerticalScrollBar
: public PresenterScrollBar
229 PresenterVerticalScrollBar (
230 const css::uno::Reference
<css::uno::XComponentContext
>& rxComponentContext
,
231 const css::uno::Reference
<css::awt::XWindow
>& rxParentWindow
,
232 const std::shared_ptr
<PresenterPaintManager
>& rpPaintManager
,
233 const ::std::function
<void (double)>& rThumbMotionListener
);
234 virtual ~PresenterVerticalScrollBar() override
;
235 virtual sal_Int32
GetSize() const override
;
238 virtual double GetDragDistance (const sal_Int32 nX
, const sal_Int32 nY
) const override
;
239 virtual void UpdateDragAnchor (const double nDragDistance
) override
;
240 virtual double GetMinor (const double nX
, const double nY
) const override
;
241 virtual void UpdateBorders() override
;
242 virtual void UpdateBitmaps() override
;
243 virtual void PaintComposite(
244 const css::awt::Rectangle
& rRepaintBox
,
246 const SharedBitmapDescriptor
& rpStartBitmaps
,
247 const SharedBitmapDescriptor
& rpCenterBitmaps
,
248 const SharedBitmapDescriptor
& rpEndBitmaps
) override
;
251 sal_Int32 mnScrollBarWidth
;
254 } } // end of namespace ::sdext::presenter
258 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */