LibreOffice Module sdext (master)  1
PresenterScrollBar.hxx
Go to the documentation of this file.
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 
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>
30 
31 #include <functional>
32 #include <memory>
33 
34 namespace sdext { namespace presenter {
35 
36 class PresenterCanvasHelper;
38 
39 typedef ::cppu::WeakComponentImplHelper <
40  css::awt::XWindowListener,
41  css::awt::XPaintListener,
42  css::awt::XMouseListener,
43  css::awt::XMouseMotionListener
45 
49  : private ::cppu::BaseMutex,
50  public PresenterScrollBarInterfaceBase
51 {
52 public:
53  virtual ~PresenterScrollBar() override;
54  PresenterScrollBar(const PresenterScrollBar&) = delete;
56 
57  virtual void SAL_CALL disposing() override;
58 
59  css::uno::Reference<css::uno::XComponentContext> const&
61 
62  void SetVisible (const bool bIsVisible);
63 
66  void SetPosSize (const css::geometry::RealRectangle2D& rBox);
67 
73  void SetThumbPosition (
74  double nPosition,
75  const bool bAsynchronousRepaint);
76 
77  double GetThumbPosition() const { return mnThumbPosition;}
78 
81  void SetTotalSize (const double nTotalSize);
82 
87  void SetThumbSize (const double nThumbSize);
88  double GetThumbSize() const { return mnThumbSize;}
89 
90  void SetLineHeight (const double nLineHeight);
91  double GetLineHeight() const { return mnLineHeight;}
92 
95  void SetCanvas (const css::uno::Reference<css::rendering::XCanvas>& rxCanvas);
96 
97  void SetBackground (const SharedBitmapDescriptor& rpBackgroundBitmap);
98 
102  void CheckValues();
103 
107  void Paint (
108  const css::awt::Rectangle& rUpdateBox);
109 
110  virtual sal_Int32 GetSize() const = 0;
111 
112  // XWindowListener
113 
114  virtual void SAL_CALL windowResized (const css::awt::WindowEvent& rEvent) override;
115 
116  virtual void SAL_CALL windowMoved (const css::awt::WindowEvent& rEvent) override;
117 
118  virtual void SAL_CALL windowShown (const css::lang::EventObject& rEvent) override;
119 
120  virtual void SAL_CALL windowHidden (const css::lang::EventObject& rEvent) override;
121 
122  // XPaintListener
123 
124  virtual void SAL_CALL windowPaint (const css::awt::PaintEvent& rEvent) override;
125 
126  // XMouseListener
127 
128  virtual void SAL_CALL mousePressed (const css::awt::MouseEvent& rEvent) override;
129 
130  virtual void SAL_CALL mouseReleased (const css::awt::MouseEvent& rEvent) override;
131 
132  virtual void SAL_CALL mouseEntered (const css::awt::MouseEvent& rEvent) override;
133 
134  virtual void SAL_CALL mouseExited (const css::awt::MouseEvent& rEvent) override;
135 
136  // XMouseMotionListener
137 
138  virtual void SAL_CALL mouseMoved (const css::awt::MouseEvent& rEvent) override;
139 
140  virtual void SAL_CALL mouseDragged (const css::awt::MouseEvent& rEvent) override;
141 
142  // lang::XEventListener
143  virtual void SAL_CALL disposing (const css::lang::EventObject& rEvent) override;
144 
146  AreaCount = None };
147 
148 protected:
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;
155  double mnTotalSize;
156  double mnThumbSize;
157  double mnLineHeight;
158  css::geometry::RealPoint2D maDragAnchor;
159  ::std::function<void (double)> const maThumbMotionListener;
162  css::geometry::RealRectangle2D maBox[AreaCount];
164  static std::weak_ptr<PresenterBitmapContainer> mpSharedBitmaps;
165  std::shared_ptr<PresenterBitmapContainer> mpBitmaps;
175 
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,
184  const Area eArea,
185  const SharedBitmapDescriptor& rpStartBitmaps,
186  const SharedBitmapDescriptor& rpCenterBitmaps,
187  const SharedBitmapDescriptor& rpEndBitmaps) = 0;
188 
190  const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
191  const css::uno::Reference<css::awt::XWindow>& rxParentWindow,
192  const std::shared_ptr<PresenterPaintManager>& rpPaintManager,
193  const ::std::function<void (double)>& rThumbMotionListener);
194 
195  void Repaint (
196  const css::geometry::RealRectangle2D& rBox,
197  const bool bAsynchronous);
198  void PaintBackground (
199  const css::awt::Rectangle& rRepaintBox);
200  void PaintBitmap(
201  const css::awt::Rectangle& rRepaintBox,
202  const Area eArea,
203  const SharedBitmapDescriptor& rpBitmaps);
204  void UpdateWidthOrHeight (sal_Int32& rSize,
205  const SharedBitmapDescriptor& rpDescriptor);
206  css::uno::Reference<css::rendering::XBitmap> GetBitmap (
207  const Area eArea,
208  const SharedBitmapDescriptor& rpBitmaps) const;
210  const Area eArea) const;
211  bool IsDisabled (const Area eArea) const;
212  double ValidateThumbPosition (double nPosition);
213 
214 private:
216  std::shared_ptr<MousePressRepeater> mpMousePressRepeater;
218  std::unique_ptr<PresenterCanvasHelper> mpCanvasHelper;
219 
220  Area GetArea (const double nX, const double nY) const;
221 };
222 
226 {
227 public:
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;
235 
236 protected:
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,
244  const Area eArea,
245  const SharedBitmapDescriptor& rpStartBitmaps,
246  const SharedBitmapDescriptor& rpCenterBitmaps,
247  const SharedBitmapDescriptor& rpEndBitmaps) override;
248 
249 private:
250  sal_Int32 mnScrollBarWidth;
251 };
252 
253 } } // end of namespace ::sdext::presenter
254 
255 #endif
256 
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< PresenterBitmapContainer > mpBitmaps
virtual void UpdateDragAnchor(const double nDragDistance) override
virtual void SAL_CALL mouseMoved(const css::awt::MouseEvent &rEvent) override
void PaintBackground(const css::awt::Rectangle &rRepaintBox)
std::unique_ptr< PresenterCanvasHelper > mpCanvasHelper
void CheckValues()
Call this after changing total size or thumb position or size to move the thumb to a valid position...
virtual void SAL_CALL windowHidden(const css::lang::EventObject &rEvent) override
css::uno::Reference< css::rendering::XCanvas > mxCanvas
virtual void SAL_CALL mouseDragged(const css::awt::MouseEvent &rEvent) override
virtual double GetDragDistance(const sal_Int32 nX, const sal_Int32 nY) const =0
Area GetArea(const double nX, const double nY) const
Base class of horizontal and vertical scroll bars.
static std::weak_ptr< PresenterBitmapContainer > mpSharedBitmaps
css::uno::Reference< css::uno::XComponentContext > mxComponentContext
void PaintBitmap(const css::awt::Rectangle &rRepaintBox, const Area eArea, const SharedBitmapDescriptor &rpBitmaps)
virtual sal_Int32 GetSize() const =0
void SetLineHeight(const double nLineHeight)
PresenterBitmapContainer::BitmapDescriptor::Mode GetBitmapMode(const Area eArea) const
PresenterScrollBar(const PresenterScrollBar &)=delete
std::shared_ptr< PresenterBitmapContainer::BitmapDescriptor > SharedBitmapDescriptor
Synchronize painting of windows and canvases.
void SetPosSize(const css::geometry::RealRectangle2D &rBox)
Set the bounding box of the scroll bar.
css::uno::Reference< css::rendering::XBitmap > GetBitmap(const Area eArea, const SharedBitmapDescriptor &rpBitmaps) const
css::geometry::RealRectangle2D const & GetRectangle(const Area eArea) const
void Paint(const css::awt::Rectangle &rUpdateBox)
On some occasions it is necessary to trigger the painting of a scrollbar from the outside...
void SetBackground(const SharedBitmapDescriptor &rpBackgroundBitmap)
void SetCanvas(const css::uno::Reference< css::rendering::XCanvas > &rxCanvas)
Set the canvas that is used for painting the scroll bar.
css::geometry::RealRectangle2D maBox[AreaCount]
SharedBitmapDescriptor mpThumbCenterDescriptor
std::shared_ptr< PresenterPaintManager > mpPaintManager
virtual void PaintComposite(const css::awt::Rectangle &rRepaintBox, const Area eArea, const SharedBitmapDescriptor &rpStartBitmaps, const SharedBitmapDescriptor &rpCenterBitmaps, const SharedBitmapDescriptor &rpEndBitmaps)=0
void UpdateWidthOrHeight(sal_Int32 &rSize, const SharedBitmapDescriptor &rpDescriptor)
void SetTotalSize(const double nTotalSize)
Set the upper border of the slider range.
css::geometry::RealPoint2D maDragAnchor
::std::function< void(double)> const maThumbMotionListener
virtual void SAL_CALL windowResized(const css::awt::WindowEvent &rEvent) override
void SetVisible(const bool bIsVisible)
virtual void SAL_CALL windowPaint(const css::awt::PaintEvent &rEvent) override
bool IsDisabled(const Area eArea) const
void SetThumbPosition(double nPosition, const bool bAsynchronousRepaint)
Set the position of the movable thumb.
SharedBitmapDescriptor mpPagerCenterDescriptor
double ValidateThumbPosition(double nPosition)
virtual void SAL_CALL mouseReleased(const css::awt::MouseEvent &rEvent) override
void SetThumbSize(const double nThumbSize)
Set the size of the movable thumb.
css::uno::Reference< css::drawing::XPresenterHelper > mxPresenterHelper
virtual void UpdateDragAnchor(const double nDragDistance)=0
virtual double GetMinor(const double nX, const double nY) const override
virtual void SAL_CALL mouseEntered(const css::awt::MouseEvent &rEvent) override
virtual double GetMinor(const double nX, const double nY) const =0
virtual void SAL_CALL mousePressed(const css::awt::MouseEvent &rEvent) override
void Repaint(const css::geometry::RealRectangle2D &rBox, const bool bAsynchronous)
std::shared_ptr< MousePressRepeater > mpMousePressRepeater
virtual double GetDragDistance(const sal_Int32 nX, const sal_Int32 nY) const override
virtual void SAL_CALL mouseExited(const css::awt::MouseEvent &rEvent) override
virtual void PaintComposite(const css::awt::Rectangle &rRepaintBox, const Area eArea, const SharedBitmapDescriptor &rpStartBitmaps, const SharedBitmapDescriptor &rpCenterBitmaps, const SharedBitmapDescriptor &rpEndBitmaps) override
virtual void SAL_CALL disposing() override
virtual sal_Int32 GetSize() const override
virtual void SAL_CALL windowShown(const css::lang::EventObject &rEvent) override
css::uno::Reference< css::uno::XComponentContext > const & GetComponentContext() const
css::uno::Reference< css::awt::XWindow > mxWindow
::cppu::WeakComponentImplHelper< css::awt::XWindowListener, css::awt::XPaintListener, css::awt::XMouseListener, css::awt::XMouseMotionListener > PresenterScrollBarInterfaceBase
PresenterScrollBar & operator=(const PresenterScrollBar &)=delete
virtual void SAL_CALL windowMoved(const css::awt::WindowEvent &rEvent) override
PresenterVerticalScrollBar(const css::uno::Reference< css::uno::XComponentContext > &rxComponentContext, const css::uno::Reference< css::awt::XWindow > &rxParentWindow, const std::shared_ptr< PresenterPaintManager > &rpPaintManager, const ::std::function< void(double)> &rThumbMotionListener)