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 #include "PresenterScrollBar.hxx"
21 #include "PresenterBitmapContainer.hxx"
22 #include "PresenterCanvasHelper.hxx"
23 #include "PresenterGeometryHelper.hxx"
24 #include "PresenterPaintManager.hxx"
25 #include "PresenterTimer.hxx"
26 #include "PresenterUIPainter.hxx"
27 #include <com/sun/star/awt/PosSize.hpp>
28 #include <com/sun/star/awt/XWindowPeer.hpp>
29 #include <com/sun/star/rendering/CompositeOperation.hpp>
30 #include <com/sun/star/rendering/XPolyPolygon2D.hpp>
37 using namespace ::com::sun::star
;
38 using namespace ::com::sun::star::uno
;
40 const double gnScrollBarGap (10);
42 namespace sdext::presenter
{
44 //===== PresenterScrollBar::MousePressRepeater ================================
46 class PresenterScrollBar::MousePressRepeater
47 : public std::enable_shared_from_this
<MousePressRepeater
>
50 explicit MousePressRepeater (::rtl::Reference
<PresenterScrollBar
> xScrollBar
);
52 void Start (const PresenterScrollBar::Area
& reArea
);
54 void SetMouseArea (const PresenterScrollBar::Area
& reArea
);
60 sal_Int32 mnMousePressRepeaterTaskId
;
61 ::rtl::Reference
<PresenterScrollBar
> mpScrollBar
;
62 PresenterScrollBar::Area meMouseArea
;
65 //===== PresenterScrollBar ====================================================
67 std::weak_ptr
<PresenterBitmapContainer
> PresenterScrollBar::mpSharedBitmaps
;
69 PresenterScrollBar::PresenterScrollBar (
70 const Reference
<XComponentContext
>& rxComponentContext
,
71 const Reference
<awt::XWindow
>& rxParentWindow
,
72 std::shared_ptr
<PresenterPaintManager
> xPaintManager
,
73 ::std::function
<void (double)> aThumbMotionListener
)
74 : PresenterScrollBarInterfaceBase(m_aMutex
),
75 mxComponentContext(rxComponentContext
),
76 mpPaintManager(std::move(xPaintManager
)),
82 maThumbMotionListener(std::move(aThumbMotionListener
)),
83 meButtonDownArea(None
),
84 meMouseMoveArea(None
),
85 mbIsNotificationActive(false),
86 mpMousePressRepeater(std::make_shared
<MousePressRepeater
>(this)),
87 mpCanvasHelper(new PresenterCanvasHelper())
91 Reference
<lang::XMultiComponentFactory
> xFactory (rxComponentContext
->getServiceManager());
93 throw RuntimeException();
95 mxPresenterHelper
.set(
96 xFactory
->createInstanceWithContext(
97 u
"com.sun.star.comp.Draw.PresenterHelper"_ustr
,
101 if (mxPresenterHelper
.is())
102 mxWindow
= mxPresenterHelper
->createWindow(rxParentWindow
,
108 // Make the background transparent. The slide show paints its own background.
109 Reference
<awt::XWindowPeer
> xPeer (mxWindow
, UNO_QUERY_THROW
);
110 xPeer
->setBackground(0xff000000);
112 mxWindow
->setVisible(true);
113 mxWindow
->addWindowListener(this);
114 mxWindow
->addPaintListener(this);
115 mxWindow
->addMouseListener(this);
116 mxWindow
->addMouseMotionListener(this);
118 catch (RuntimeException
&)
123 PresenterScrollBar::~PresenterScrollBar()
127 void SAL_CALL
PresenterScrollBar::disposing()
129 mpMousePressRepeater
->Dispose();
133 mxWindow
->removeWindowListener(this);
134 mxWindow
->removePaintListener(this);
135 mxWindow
->removeMouseListener(this);
136 mxWindow
->removeMouseMotionListener(this);
138 Reference
<lang::XComponent
> xComponent
= mxWindow
;
141 xComponent
->dispose();
147 void PresenterScrollBar::SetVisible (const bool bIsVisible
)
150 mxWindow
->setVisible(bIsVisible
);
153 void PresenterScrollBar::SetPosSize (const css::geometry::RealRectangle2D
& rBox
)
157 mxWindow
->setPosSize(
158 sal_Int32(floor(rBox
.X1
)),
159 sal_Int32(ceil(rBox
.Y1
)),
160 sal_Int32(ceil(rBox
.X2
-rBox
.X1
)),
161 sal_Int32(floor(rBox
.Y2
-rBox
.Y1
)),
162 awt::PosSize::POSSIZE
);
167 void PresenterScrollBar::SetThumbPosition (
169 const bool bAsynchronousUpdate
)
171 nPosition
= ValidateThumbPosition(nPosition
);
173 if (nPosition
== mnThumbPosition
|| mbIsNotificationActive
)
176 mnThumbPosition
= nPosition
;
179 Repaint(GetRectangle(Total
), bAsynchronousUpdate
);
181 mbIsNotificationActive
= true;
184 maThumbMotionListener(mnThumbPosition
);
189 mbIsNotificationActive
= false;
193 void PresenterScrollBar::SetTotalSize (const double nTotalSize
)
195 if (mnTotalSize
!= nTotalSize
)
197 mnTotalSize
= nTotalSize
+ 1;
199 Repaint(GetRectangle(Total
), false);
203 void PresenterScrollBar::SetThumbSize (const double nThumbSize
)
205 OSL_ASSERT(nThumbSize
>=0);
206 if (mnThumbSize
!= nThumbSize
)
208 mnThumbSize
= nThumbSize
;
210 Repaint(GetRectangle(Total
), false);
215 void PresenterScrollBar::SetLineHeight (const double nLineHeight
)
217 mnLineHeight
= nLineHeight
;
221 void PresenterScrollBar::SetCanvas (const Reference
<css::rendering::XCanvas
>& rxCanvas
)
223 if (mxCanvas
== rxCanvas
)
230 if (mpBitmaps
== nullptr)
232 mpBitmaps
= mpSharedBitmaps
.lock();
237 mpBitmaps
= std::make_shared
<PresenterBitmapContainer
>(
238 "PresenterScreenSettings/ScrollBar/Bitmaps",
239 std::shared_ptr
<PresenterBitmapContainer
>(),
242 mpSharedBitmaps
= mpBitmaps
;
253 Repaint(GetRectangle(Total
), false);
256 void PresenterScrollBar::SetBackground (const SharedBitmapDescriptor
& rpBackgroundBitmap
)
258 mpBackgroundBitmap
= rpBackgroundBitmap
;
261 void PresenterScrollBar::CheckValues()
263 mnThumbPosition
= ValidateThumbPosition(mnThumbPosition
);
266 double PresenterScrollBar::ValidateThumbPosition (double nPosition
)
268 if (nPosition
+ mnThumbSize
> mnTotalSize
)
269 nPosition
= mnTotalSize
- mnThumbSize
;
275 void PresenterScrollBar::Paint (
276 const awt::Rectangle
& rUpdateBox
)
278 if ( ! mxCanvas
.is() || ! mxWindow
.is())
280 OSL_ASSERT(mxCanvas
.is());
281 OSL_ASSERT(mxWindow
.is());
285 if (PresenterGeometryHelper::AreRectanglesDisjoint (rUpdateBox
, mxWindow
->getPosSize()))
288 PaintBackground(rUpdateBox
);
289 PaintComposite(rUpdateBox
, PagerUp
,
290 mpPagerStartDescriptor
, mpPagerCenterDescriptor
, SharedBitmapDescriptor());
291 PaintComposite(rUpdateBox
, PagerDown
,
292 SharedBitmapDescriptor(), mpPagerCenterDescriptor
, mpPagerEndDescriptor
);
293 PaintComposite(rUpdateBox
, Thumb
,
294 mpThumbStartDescriptor
, mpThumbCenterDescriptor
, mpThumbEndDescriptor
);
295 PaintBitmap(rUpdateBox
, PrevButton
, mpPrevButtonDescriptor
);
296 PaintBitmap(rUpdateBox
, NextButton
, mpNextButtonDescriptor
);
298 Reference
<rendering::XSpriteCanvas
> xSpriteCanvas (mxCanvas
, UNO_QUERY
);
299 if (xSpriteCanvas
.is())
300 xSpriteCanvas
->updateScreen(false);
303 //----- XWindowListener -------------------------------------------------------
305 void SAL_CALL
PresenterScrollBar::windowResized (const css::awt::WindowEvent
&) {}
307 void SAL_CALL
PresenterScrollBar::windowMoved (const css::awt::WindowEvent
&) {}
309 void SAL_CALL
PresenterScrollBar::windowShown (const css::lang::EventObject
&) {}
311 void SAL_CALL
PresenterScrollBar::windowHidden (const css::lang::EventObject
&) {}
313 //----- XPaintListener --------------------------------------------------------
315 void SAL_CALL
PresenterScrollBar::windowPaint (const css::awt::PaintEvent
& rEvent
)
319 awt::Rectangle
aRepaintBox (rEvent
.UpdateRect
);
320 const awt::Rectangle
aWindowBox (mxWindow
->getPosSize());
321 aRepaintBox
.X
+= aWindowBox
.X
;
322 aRepaintBox
.Y
+= aWindowBox
.Y
;
325 Reference
<rendering::XSpriteCanvas
> xSpriteCanvas (mxCanvas
, UNO_QUERY
);
326 if (xSpriteCanvas
.is())
327 xSpriteCanvas
->updateScreen(false);
331 //----- XMouseListener --------------------------------------------------------
333 void SAL_CALL
PresenterScrollBar::mousePressed (const css::awt::MouseEvent
& rEvent
)
335 maDragAnchor
.X
= rEvent
.X
;
336 maDragAnchor
.Y
= rEvent
.Y
;
337 meButtonDownArea
= GetArea(rEvent
.X
, rEvent
.Y
);
339 mpMousePressRepeater
->Start(meButtonDownArea
);
342 void SAL_CALL
PresenterScrollBar::mouseReleased (const css::awt::MouseEvent
&)
344 mpMousePressRepeater
->Stop();
346 if (mxPresenterHelper
.is())
347 mxPresenterHelper
->releaseMouse(mxWindow
);
350 void SAL_CALL
PresenterScrollBar::mouseEntered (const css::awt::MouseEvent
&) {}
352 void SAL_CALL
PresenterScrollBar::mouseExited (const css::awt::MouseEvent
&)
354 if (meMouseMoveArea
!= None
)
356 const Area
eOldMouseMoveArea (meMouseMoveArea
);
357 meMouseMoveArea
= None
;
358 Repaint(GetRectangle(eOldMouseMoveArea
), true);
360 meButtonDownArea
= None
;
361 meMouseMoveArea
= None
;
363 mpMousePressRepeater
->Stop();
366 //----- XMouseMotionListener --------------------------------------------------
368 void SAL_CALL
PresenterScrollBar::mouseMoved (const css::awt::MouseEvent
& rEvent
)
370 const Area
eArea (GetArea(rEvent
.X
, rEvent
.Y
));
371 if (eArea
!= meMouseMoveArea
)
373 const Area
eOldMouseMoveArea (meMouseMoveArea
);
374 meMouseMoveArea
= eArea
;
375 if (eOldMouseMoveArea
!= None
)
376 Repaint(GetRectangle(eOldMouseMoveArea
), meMouseMoveArea
==None
);
377 if (meMouseMoveArea
!= None
)
378 Repaint(GetRectangle(meMouseMoveArea
), true);
380 mpMousePressRepeater
->SetMouseArea(eArea
);
383 void SAL_CALL
PresenterScrollBar::mouseDragged (const css::awt::MouseEvent
& rEvent
)
385 if (meButtonDownArea
!= Thumb
)
388 mpMousePressRepeater
->Stop();
390 if (mxPresenterHelper
.is())
391 mxPresenterHelper
->captureMouse(mxWindow
);
393 const double nDragDistance (GetDragDistance(rEvent
.X
,rEvent
.Y
));
394 UpdateDragAnchor(nDragDistance
);
395 if (nDragDistance
!= 0)
397 SetThumbPosition(mnThumbPosition
+ nDragDistance
, false);
401 //----- lang::XEventListener --------------------------------------------------
403 void SAL_CALL
PresenterScrollBar::disposing (const css::lang::EventObject
& rEvent
)
405 if (rEvent
.Source
== mxWindow
)
410 geometry::RealRectangle2D
const & PresenterScrollBar::GetRectangle (const Area eArea
) const
412 OSL_ASSERT(eArea
>=0 && eArea
<AreaCount
);
417 void PresenterScrollBar::Repaint (
418 const geometry::RealRectangle2D
& rBox
,
419 const bool bAsynchronousUpdate
)
421 if (mpPaintManager
!= nullptr)
422 mpPaintManager
->Invalidate(
424 PresenterGeometryHelper::ConvertRectangle(rBox
),
425 bAsynchronousUpdate
);
428 void PresenterScrollBar::PaintBackground(
429 const css::awt::Rectangle
& rUpdateBox
)
431 if (!mpBackgroundBitmap
)
434 const awt::Rectangle
aWindowBox (mxWindow
->getPosSize());
435 mpCanvasHelper
->Paint(
443 void PresenterScrollBar::PaintBitmap(
444 const css::awt::Rectangle
& rUpdateBox
,
446 const SharedBitmapDescriptor
& rpBitmaps
)
448 const geometry::RealRectangle2D
aLocalBox (GetRectangle(eArea
));
449 const awt::Rectangle
aWindowBox (mxWindow
->getPosSize());
450 geometry::RealRectangle2D
aBox (aLocalBox
);
451 aBox
.X1
+= aWindowBox
.X
;
452 aBox
.Y1
+= aWindowBox
.Y
;
453 aBox
.X2
+= aWindowBox
.X
;
454 aBox
.Y2
+= aWindowBox
.Y
;
456 Reference
<rendering::XBitmap
> xBitmap (GetBitmap(eArea
,rpBitmaps
));
461 Reference
<rendering::XPolyPolygon2D
> xClipPolygon (
462 PresenterGeometryHelper::CreatePolygon(
463 PresenterGeometryHelper::Intersection(rUpdateBox
,
464 PresenterGeometryHelper::ConvertRectangle(aBox
)),
465 mxCanvas
->getDevice()));
467 const rendering::ViewState
aViewState (
468 geometry::AffineMatrix2D(1,0,0, 0,1,0),
471 const geometry::IntegerSize2D
aBitmapSize (xBitmap
->getSize());
472 rendering::RenderState
aRenderState (
473 geometry::AffineMatrix2D(
474 1,0,aBox
.X1
+ (aBox
.X2
-aBox
.X1
- aBitmapSize
.Width
)/2,
475 0,1,aBox
.Y1
+ (aBox
.Y2
-aBox
.Y1
- aBitmapSize
.Height
)/2),
478 rendering::CompositeOperation::SOURCE
);
480 mxCanvas
->drawBitmap(
486 PresenterScrollBar::Area
PresenterScrollBar::GetArea (const double nX
, const double nY
) const
488 const geometry::RealPoint2D
aPoint(nX
, nY
);
490 if (PresenterGeometryHelper::IsInside(GetRectangle(Pager
), aPoint
))
492 if (PresenterGeometryHelper::IsInside(GetRectangle(Thumb
), aPoint
))
494 else if (PresenterGeometryHelper::IsInside(GetRectangle(PagerUp
), aPoint
))
496 else if (PresenterGeometryHelper::IsInside(GetRectangle(PagerDown
), aPoint
))
499 else if (PresenterGeometryHelper::IsInside(GetRectangle(PrevButton
), aPoint
))
501 else if (PresenterGeometryHelper::IsInside(GetRectangle(NextButton
), aPoint
))
507 void PresenterScrollBar::UpdateWidthOrHeight (
509 const SharedBitmapDescriptor
& rpDescriptor
)
513 Reference
<rendering::XBitmap
> xBitmap (rpDescriptor
->GetNormalBitmap());
516 const geometry::IntegerSize2D
aBitmapSize (xBitmap
->getSize());
517 const sal_Int32 nBitmapSize
= static_cast<sal_Int32
>(GetMinor(aBitmapSize
.Width
, aBitmapSize
.Height
));
518 if (nBitmapSize
> rSize
)
524 css::uno::Reference
<css::rendering::XBitmap
> PresenterScrollBar::GetBitmap (
526 const SharedBitmapDescriptor
& rpBitmaps
) const
531 return rpBitmaps
->GetBitmap(GetBitmapMode(eArea
));
534 PresenterBitmapContainer::BitmapDescriptor::Mode
PresenterScrollBar::GetBitmapMode (
535 const Area eArea
) const
537 if (IsDisabled(eArea
))
538 return PresenterBitmapContainer::BitmapDescriptor::Disabled
;
539 else if (eArea
== meMouseMoveArea
)
540 return PresenterBitmapContainer::BitmapDescriptor::MouseOver
;
542 return PresenterBitmapContainer::BitmapDescriptor::Normal
;
545 bool PresenterScrollBar::IsDisabled (const Area eArea
) const
547 OSL_ASSERT(eArea
>=0 && eArea
<AreaCount
);
549 return ! maEnabledState
[eArea
];
552 //===== PresenterVerticalScrollBar ============================================
554 PresenterVerticalScrollBar::PresenterVerticalScrollBar (
555 const Reference
<XComponentContext
>& rxComponentContext
,
556 const Reference
<awt::XWindow
>& rxParentWindow
,
557 const std::shared_ptr
<PresenterPaintManager
>& rpPaintManager
,
558 const ::std::function
<void (double)>& rThumbMotionListener
)
559 : PresenterScrollBar(rxComponentContext
, rxParentWindow
, rpPaintManager
, rThumbMotionListener
),
564 PresenterVerticalScrollBar::~PresenterVerticalScrollBar()
568 double PresenterVerticalScrollBar::GetDragDistance (const sal_Int32
, const sal_Int32 nY
) const
570 const double nDistance (nY
- maDragAnchor
.Y
);
575 const awt::Rectangle
aWindowBox (mxWindow
->getPosSize());
576 const double nBarWidth (aWindowBox
.Width
);
577 const double nPagerHeight (aWindowBox
.Height
- 2*nBarWidth
);
578 const double nDragDistance (mnTotalSize
/ nPagerHeight
* nDistance
);
579 if (nDragDistance
+ mnThumbPosition
< 0)
580 return -mnThumbPosition
;
581 else if (mnThumbPosition
+ nDragDistance
> mnTotalSize
-mnThumbSize
)
582 return mnTotalSize
-mnThumbSize
-mnThumbPosition
;
584 return nDragDistance
;
588 void PresenterVerticalScrollBar::UpdateDragAnchor (const double nDragDistance
)
590 const awt::Rectangle
aWindowBox (mxWindow
->getPosSize());
591 const double nBarWidth (aWindowBox
.Width
);
592 const double nPagerHeight (aWindowBox
.Height
- 2*nBarWidth
);
593 maDragAnchor
.Y
+= nDragDistance
* nPagerHeight
/ mnTotalSize
;
596 sal_Int32
PresenterVerticalScrollBar::GetSize() const
598 return mnScrollBarWidth
;
601 double PresenterVerticalScrollBar::GetMinor (const double nX
, const double) const
606 void PresenterVerticalScrollBar::UpdateBorders()
608 const awt::Rectangle
aWindowBox (mxWindow
->getPosSize());
609 double nBottom
= aWindowBox
.Height
;
611 if (mpNextButtonDescriptor
)
613 Reference
<rendering::XBitmap
> xBitmap (mpNextButtonDescriptor
->GetNormalBitmap());
616 geometry::IntegerSize2D
aSize (xBitmap
->getSize());
617 maBox
[NextButton
] = geometry::RealRectangle2D(
618 0, nBottom
- aSize
.Height
, aWindowBox
.Width
, nBottom
);
619 nBottom
-= aSize
.Height
+ gnScrollBarGap
;
622 if (mpPrevButtonDescriptor
)
624 Reference
<rendering::XBitmap
> xBitmap (mpPrevButtonDescriptor
->GetNormalBitmap());
627 geometry::IntegerSize2D
aSize (xBitmap
->getSize());
628 maBox
[PrevButton
] = geometry::RealRectangle2D(
629 0, nBottom
- aSize
.Height
, aWindowBox
.Width
, nBottom
);
630 nBottom
-= aSize
.Height
+ gnScrollBarGap
;
633 const double nPagerHeight (nBottom
);
634 maBox
[Pager
] = geometry::RealRectangle2D(
635 0,0, aWindowBox
.Width
, nBottom
);
638 maBox
[Thumb
] = maBox
[Pager
];
640 // Set up the enabled/disabled states.
641 maEnabledState
[PrevButton
] = false;
642 maEnabledState
[PagerUp
] = false;
643 maEnabledState
[NextButton
] = false;
644 maEnabledState
[PagerDown
] = false;
645 maEnabledState
[Thumb
] = false;
649 const double nThumbSize
= ::std::min(mnThumbSize
,mnTotalSize
);
650 const double nThumbPosition
= ::std::clamp(mnThumbPosition
, 0.0, mnTotalSize
- nThumbSize
);
651 maBox
[Thumb
] = geometry::RealRectangle2D(
652 0, nThumbPosition
/ mnTotalSize
* nPagerHeight
,
654 (nThumbPosition
+nThumbSize
) / mnTotalSize
* nPagerHeight
);
656 // Set up the enabled/disabled states.
657 maEnabledState
[PrevButton
] = nThumbPosition
>0;
658 maEnabledState
[PagerUp
] = nThumbPosition
>0;
659 maEnabledState
[NextButton
] = nThumbPosition
+nThumbSize
< mnTotalSize
;
660 maEnabledState
[PagerDown
] = nThumbPosition
+nThumbSize
< mnTotalSize
;
661 maEnabledState
[Thumb
] = nThumbSize
< mnTotalSize
;
663 maBox
[PagerUp
] = geometry::RealRectangle2D(
664 maBox
[Pager
].X1
, maBox
[Pager
].Y1
, maBox
[Pager
].X2
, maBox
[Thumb
].Y1
-1);
665 maBox
[PagerDown
] = geometry::RealRectangle2D(
666 maBox
[Pager
].X1
, maBox
[Thumb
].Y2
+1, maBox
[Pager
].X2
, maBox
[Pager
].Y2
);
667 maBox
[Total
] = PresenterGeometryHelper::Union(
668 PresenterGeometryHelper::Union(maBox
[PrevButton
], maBox
[NextButton
]),
672 void PresenterVerticalScrollBar::UpdateBitmaps()
674 if (mpBitmaps
== nullptr)
677 mpPrevButtonDescriptor
= mpBitmaps
->GetBitmap(u
"Up"_ustr
);
678 mpNextButtonDescriptor
= mpBitmaps
->GetBitmap(u
"Down"_ustr
);
679 mpPagerStartDescriptor
= mpBitmaps
->GetBitmap(u
"PagerTop"_ustr
);
680 mpPagerCenterDescriptor
= mpBitmaps
->GetBitmap(u
"PagerVertical"_ustr
);
681 mpPagerEndDescriptor
= mpBitmaps
->GetBitmap(u
"PagerBottom"_ustr
);
682 mpThumbStartDescriptor
= mpBitmaps
->GetBitmap(u
"ThumbTop"_ustr
);
683 mpThumbCenterDescriptor
= mpBitmaps
->GetBitmap(u
"ThumbVertical"_ustr
);
684 mpThumbEndDescriptor
= mpBitmaps
->GetBitmap(u
"ThumbBottom"_ustr
);
686 mnScrollBarWidth
= 0;
687 UpdateWidthOrHeight(mnScrollBarWidth
, mpPrevButtonDescriptor
);
688 UpdateWidthOrHeight(mnScrollBarWidth
, mpNextButtonDescriptor
);
689 UpdateWidthOrHeight(mnScrollBarWidth
, mpPagerStartDescriptor
);
690 UpdateWidthOrHeight(mnScrollBarWidth
, mpPagerCenterDescriptor
);
691 UpdateWidthOrHeight(mnScrollBarWidth
, mpPagerEndDescriptor
);
692 UpdateWidthOrHeight(mnScrollBarWidth
, mpThumbStartDescriptor
);
693 UpdateWidthOrHeight(mnScrollBarWidth
, mpThumbCenterDescriptor
);
694 UpdateWidthOrHeight(mnScrollBarWidth
, mpThumbEndDescriptor
);
695 if (mnScrollBarWidth
== 0)
696 mnScrollBarWidth
= 20;
699 void PresenterVerticalScrollBar::PaintComposite(
700 const css::awt::Rectangle
& rUpdateBox
,
702 const SharedBitmapDescriptor
& rpStartBitmaps
,
703 const SharedBitmapDescriptor
& rpCenterBitmaps
,
704 const SharedBitmapDescriptor
& rpEndBitmaps
)
706 const awt::Rectangle
aWindowBox (mxWindow
->getPosSize());
707 geometry::RealRectangle2D
aBox (GetRectangle(eArea
));
708 aBox
.X1
+= aWindowBox
.X
;
709 aBox
.Y1
+= aWindowBox
.Y
;
710 aBox
.X2
+= aWindowBox
.X
;
711 aBox
.Y2
+= aWindowBox
.Y
;
713 // Get bitmaps and sizes.
715 PresenterUIPainter::PaintVerticalBitmapComposite(
719 ? PresenterGeometryHelper::ConvertRectangleWithConstantSize(aBox
)
720 : PresenterGeometryHelper::ConvertRectangle(aBox
)),
721 GetBitmap(eArea
, rpStartBitmaps
),
722 GetBitmap(eArea
, rpCenterBitmaps
),
723 GetBitmap(eArea
, rpEndBitmaps
));
726 //===== PresenterScrollBar::MousePressRepeater ================================
728 PresenterScrollBar::MousePressRepeater::MousePressRepeater (
729 ::rtl::Reference
<PresenterScrollBar
> xScrollBar
)
730 : mnMousePressRepeaterTaskId(PresenterTimer::NotAValidTaskId
),
731 mpScrollBar(std::move(xScrollBar
)),
732 meMouseArea(PresenterScrollBar::None
)
736 void PresenterScrollBar::MousePressRepeater::Dispose()
739 mpScrollBar
= nullptr;
742 void PresenterScrollBar::MousePressRepeater::Start (const PresenterScrollBar::Area
& reArea
)
744 meMouseArea
= reArea
;
746 if (mnMousePressRepeaterTaskId
== PresenterTimer::NotAValidTaskId
)
748 // Execute key press operation at least this one time.
751 // Schedule repeated executions.
752 auto xSelf(shared_from_this());
753 mnMousePressRepeaterTaskId
= PresenterTimer::ScheduleRepeatedTask (
754 mpScrollBar
->GetComponentContext(),
755 [xSelf
=std::move(xSelf
)] (TimeValue
const&) { return xSelf
->Callback(); },
761 // There is already an active repeating task.
765 void PresenterScrollBar::MousePressRepeater::Stop()
767 if (mnMousePressRepeaterTaskId
!= PresenterTimer::NotAValidTaskId
)
769 const sal_Int32
nTaskId (mnMousePressRepeaterTaskId
);
770 mnMousePressRepeaterTaskId
= PresenterTimer::NotAValidTaskId
;
771 PresenterTimer::CancelTask(nTaskId
);
775 void PresenterScrollBar::MousePressRepeater::SetMouseArea(const PresenterScrollBar::Area
& reArea
)
777 if (meMouseArea
!= reArea
)
779 if (mnMousePressRepeaterTaskId
!= PresenterTimer::NotAValidTaskId
)
786 void PresenterScrollBar::MousePressRepeater::Callback ()
797 void PresenterScrollBar::MousePressRepeater::Execute()
799 const double nThumbPosition (mpScrollBar
->GetThumbPosition());
803 mpScrollBar
->SetThumbPosition(nThumbPosition
- mpScrollBar
->GetLineHeight(), true);
807 mpScrollBar
->SetThumbPosition(nThumbPosition
+ mpScrollBar
->GetLineHeight(), true);
811 mpScrollBar
->SetThumbPosition(nThumbPosition
- mpScrollBar
->GetThumbSize()*0.8, true);
815 mpScrollBar
->SetThumbPosition(nThumbPosition
+ mpScrollBar
->GetThumbSize()*0.8, true);
823 } // end of namespace ::sdext::presenter
825 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */