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/XWindow.hpp>
25 #include <com/sun/star/drawing/XPresenterHelper.hpp>
26 #include <com/sun/star/rendering/XCanvas.hpp>
27 #include <com/sun/star/uno/XComponentContext.hpp>
28 #include <cppuhelper/basemutex.hxx>
29 #include <cppuhelper/compbase.hxx>
34 namespace sdext::presenter
{
36 class PresenterCanvasHelper
;
37 class PresenterPaintManager
;
39 typedef ::cppu::WeakComponentImplHelper
<
40 css::awt::XWindowListener
,
41 css::awt::XPaintListener
,
42 css::awt::XMouseListener
,
43 css::awt::XMouseMotionListener
44 > PresenterScrollBarInterfaceBase
;
46 /** Base class of horizontal and vertical scroll bars.
48 class PresenterScrollBar
49 : private ::cppu::BaseMutex
,
50 public PresenterScrollBarInterfaceBase
53 virtual ~PresenterScrollBar() override
;
54 PresenterScrollBar(const PresenterScrollBar
&) = delete;
55 PresenterScrollBar
& operator=(const PresenterScrollBar
&) = delete;
57 virtual void SAL_CALL
disposing() override
;
59 css::uno::Reference
<css::uno::XComponentContext
> const&
60 GetComponentContext() const { return mxComponentContext
; }
62 void SetVisible (const bool bIsVisible
);
64 /** Set the bounding box of the scroll bar.
66 void SetPosSize (const css::geometry::RealRectangle2D
& rBox
);
68 /** Set the position of the movable thumb.
70 A value between 0 and the last value given to SetTotalSize()
71 minus the last value given to SetThumbSize().
73 void SetThumbPosition (
75 const bool bAsynchronousRepaint
);
77 double GetThumbPosition() const { return mnThumbPosition
;}
79 /** Set the upper border of the slider range.
81 void SetTotalSize (const double nTotalSize
);
83 /** Set the size of the movable thumb.
85 A value not larger than the last value given to SetTotalSize().
87 void SetThumbSize (const double nThumbSize
);
88 double GetThumbSize() const { return mnThumbSize
;}
90 void SetLineHeight (const double nLineHeight
);
91 double GetLineHeight() const { return mnLineHeight
;}
93 /** Set the canvas that is used for painting the scroll bar.
95 void SetCanvas (const css::uno::Reference
<css::rendering::XCanvas
>& rxCanvas
);
97 void SetBackground (const SharedBitmapDescriptor
& rpBackgroundBitmap
);
99 /** Call this after changing total size or thumb position or size to
100 move the thumb to a valid position.
104 /** On some occasions it is necessary to trigger the painting of a
105 scrollbar from the outside.
108 const css::awt::Rectangle
& rUpdateBox
);
110 virtual sal_Int32
GetSize() const = 0;
114 virtual void SAL_CALL
windowResized (const css::awt::WindowEvent
& rEvent
) override
;
116 virtual void SAL_CALL
windowMoved (const css::awt::WindowEvent
& rEvent
) override
;
118 virtual void SAL_CALL
windowShown (const css::lang::EventObject
& rEvent
) override
;
120 virtual void SAL_CALL
windowHidden (const css::lang::EventObject
& rEvent
) override
;
124 virtual void SAL_CALL
windowPaint (const css::awt::PaintEvent
& rEvent
) override
;
128 virtual void SAL_CALL
mousePressed (const css::awt::MouseEvent
& rEvent
) override
;
130 virtual void SAL_CALL
mouseReleased (const css::awt::MouseEvent
& rEvent
) override
;
132 virtual void SAL_CALL
mouseEntered (const css::awt::MouseEvent
& rEvent
) override
;
134 virtual void SAL_CALL
mouseExited (const css::awt::MouseEvent
& rEvent
) override
;
136 // XMouseMotionListener
138 virtual void SAL_CALL
mouseMoved (const css::awt::MouseEvent
& rEvent
) override
;
140 virtual void SAL_CALL
mouseDragged (const css::awt::MouseEvent
& rEvent
) override
;
142 // lang::XEventListener
143 virtual void SAL_CALL
disposing (const css::lang::EventObject
& rEvent
) override
;
145 enum Area
{ Total
, Pager
, Thumb
, PagerUp
, PagerDown
, PrevButton
, NextButton
, None
,
149 css::uno::Reference
<css::uno::XComponentContext
> mxComponentContext
;
150 css::uno::Reference
<css::awt::XWindow
> mxWindow
;
151 css::uno::Reference
<css::rendering::XCanvas
> mxCanvas
;
152 css::uno::Reference
<css::drawing::XPresenterHelper
> mxPresenterHelper
;
153 std::shared_ptr
<PresenterPaintManager
> mpPaintManager
;
154 double mnThumbPosition
;
158 css::geometry::RealPoint2D maDragAnchor
;
159 ::std::function
<void (double)> maThumbMotionListener
;
160 Area meButtonDownArea
;
161 Area meMouseMoveArea
;
162 css::geometry::RealRectangle2D maBox
[AreaCount
];
163 bool mbIsNotificationActive
;
164 static std::weak_ptr
<PresenterBitmapContainer
> mpSharedBitmaps
;
165 std::shared_ptr
<PresenterBitmapContainer
> mpBitmaps
;
166 SharedBitmapDescriptor mpPrevButtonDescriptor
;
167 SharedBitmapDescriptor mpNextButtonDescriptor
;
168 SharedBitmapDescriptor mpPagerStartDescriptor
;
169 SharedBitmapDescriptor mpPagerCenterDescriptor
;
170 SharedBitmapDescriptor mpPagerEndDescriptor
;
171 SharedBitmapDescriptor mpThumbStartDescriptor
;
172 SharedBitmapDescriptor mpThumbCenterDescriptor
;
173 SharedBitmapDescriptor mpThumbEndDescriptor
;
174 bool maEnabledState
[AreaCount
];
176 css::geometry::RealRectangle2D
const & GetRectangle (const Area eArea
) const;
177 virtual double GetDragDistance (const sal_Int32 nX
, const sal_Int32 nY
) const = 0;
178 virtual void UpdateDragAnchor (const double nDragDistance
) = 0;
179 virtual double GetMinor (const double nX
, const double nY
) const = 0;
180 virtual void UpdateBorders() = 0;
181 virtual void UpdateBitmaps() = 0;
182 virtual void PaintComposite(
183 const css::awt::Rectangle
& rRepaintBox
,
185 const SharedBitmapDescriptor
& rpStartBitmaps
,
186 const SharedBitmapDescriptor
& rpCenterBitmaps
,
187 const SharedBitmapDescriptor
& rpEndBitmaps
) = 0;
190 const css::uno::Reference
<css::uno::XComponentContext
>& rxComponentContext
,
191 const css::uno::Reference
<css::awt::XWindow
>& rxParentWindow
,
192 std::shared_ptr
<PresenterPaintManager
> xPaintManager
,
193 ::std::function
<void (double)> aThumbMotionListener
);
196 const css::geometry::RealRectangle2D
& rBox
,
197 const bool bAsynchronous
);
198 void PaintBackground (
199 const css::awt::Rectangle
& rRepaintBox
);
201 const css::awt::Rectangle
& rRepaintBox
,
203 const SharedBitmapDescriptor
& rpBitmaps
);
204 void UpdateWidthOrHeight (sal_Int32
& rSize
,
205 const SharedBitmapDescriptor
& rpDescriptor
);
206 css::uno::Reference
<css::rendering::XBitmap
> GetBitmap (
208 const SharedBitmapDescriptor
& rpBitmaps
) const;
209 PresenterBitmapContainer::BitmapDescriptor::Mode
GetBitmapMode (
210 const Area eArea
) const;
211 bool IsDisabled (const Area eArea
) const;
212 double ValidateThumbPosition (double nPosition
);
215 class MousePressRepeater
;
216 std::shared_ptr
<MousePressRepeater
> mpMousePressRepeater
;
217 SharedBitmapDescriptor mpBackgroundBitmap
;
218 std::unique_ptr
<PresenterCanvasHelper
> mpCanvasHelper
;
220 Area
GetArea (const double nX
, const double nY
) const;
223 /** A vertical scroll bar.
225 class PresenterVerticalScrollBar
: public PresenterScrollBar
228 PresenterVerticalScrollBar (
229 const css::uno::Reference
<css::uno::XComponentContext
>& rxComponentContext
,
230 const css::uno::Reference
<css::awt::XWindow
>& rxParentWindow
,
231 const std::shared_ptr
<PresenterPaintManager
>& rpPaintManager
,
232 const ::std::function
<void (double)>& rThumbMotionListener
);
233 virtual ~PresenterVerticalScrollBar() override
;
234 virtual sal_Int32
GetSize() const override
;
237 virtual double GetDragDistance (const sal_Int32 nX
, const sal_Int32 nY
) const override
;
238 virtual void UpdateDragAnchor (const double nDragDistance
) override
;
239 virtual double GetMinor (const double nX
, const double nY
) const override
;
240 virtual void UpdateBorders() override
;
241 virtual void UpdateBitmaps() override
;
242 virtual void PaintComposite(
243 const css::awt::Rectangle
& rRepaintBox
,
245 const SharedBitmapDescriptor
& rpStartBitmaps
,
246 const SharedBitmapDescriptor
& rpCenterBitmaps
,
247 const SharedBitmapDescriptor
& rpEndBitmaps
) override
;
250 sal_Int32 mnScrollBarWidth
;
253 } // end of namespace ::sdext::presenter
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */