Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sd / source / console / PresenterScrollBar.cxx
blob3a0891ec5d3c6ae228b09f82118c50e0d2e157a1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
32 #include <algorithm>
33 #include <memory>
34 #include <utility>
35 #include <math.h>
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>
49 public:
50 explicit MousePressRepeater (::rtl::Reference<PresenterScrollBar> xScrollBar);
51 void Dispose();
52 void Start (const PresenterScrollBar::Area& reArea);
53 void Stop();
54 void SetMouseArea (const PresenterScrollBar::Area& reArea);
56 private:
57 void Callback ();
58 void Execute();
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)),
77 mnThumbPosition(0),
78 mnTotalSize(0),
79 mnThumbSize(0),
80 mnLineHeight(10),
81 maDragAnchor(-1,-1),
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())
89 try
91 Reference<lang::XMultiComponentFactory> xFactory (rxComponentContext->getServiceManager());
92 if ( ! xFactory.is())
93 throw RuntimeException();
95 mxPresenterHelper.set(
96 xFactory->createInstanceWithContext(
97 "com.sun.star.comp.Draw.PresenterHelper",
98 rxComponentContext),
99 UNO_QUERY_THROW);
101 if (mxPresenterHelper.is())
102 mxWindow = mxPresenterHelper->createWindow(rxParentWindow,
103 false,
104 false,
105 false,
106 false);
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();
131 if (mxWindow.is())
133 mxWindow->removeWindowListener(this);
134 mxWindow->removePaintListener(this);
135 mxWindow->removeMouseListener(this);
136 mxWindow->removeMouseMotionListener(this);
138 Reference<lang::XComponent> xComponent = mxWindow;
139 mxWindow = nullptr;
140 if (xComponent.is())
141 xComponent->dispose();
144 mpBitmaps.reset();
147 void PresenterScrollBar::SetVisible (const bool bIsVisible)
149 if (mxWindow.is())
150 mxWindow->setVisible(bIsVisible);
153 void PresenterScrollBar::SetPosSize (const css::geometry::RealRectangle2D& rBox)
155 if (mxWindow.is())
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);
163 UpdateBorders();
167 void PresenterScrollBar::SetThumbPosition (
168 double nPosition,
169 const bool bAsynchronousUpdate)
171 nPosition = ValidateThumbPosition(nPosition);
173 if (nPosition == mnThumbPosition || mbIsNotificationActive)
174 return;
176 mnThumbPosition = nPosition;
178 UpdateBorders();
179 Repaint(GetRectangle(Total), bAsynchronousUpdate);
181 mbIsNotificationActive = true;
184 maThumbMotionListener(mnThumbPosition);
186 catch (Exception&)
189 mbIsNotificationActive = false;
193 void PresenterScrollBar::SetTotalSize (const double nTotalSize)
195 if (mnTotalSize != nTotalSize)
197 mnTotalSize = nTotalSize + 1;
198 UpdateBorders();
199 Repaint(GetRectangle(Total), false);
203 void PresenterScrollBar::SetThumbSize (const double nThumbSize)
205 OSL_ASSERT(nThumbSize>=0);
206 if (mnThumbSize != nThumbSize)
208 mnThumbSize = nThumbSize;
209 UpdateBorders();
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)
224 return;
226 mxCanvas = rxCanvas;
227 if (!mxCanvas.is())
228 return;
230 if (mpBitmaps == nullptr)
232 mpBitmaps = mpSharedBitmaps.lock();
233 if (!mpBitmaps)
237 mpBitmaps = std::make_shared<PresenterBitmapContainer>(
238 "PresenterScreenSettings/ScrollBar/Bitmaps",
239 std::shared_ptr<PresenterBitmapContainer>(),
240 mxComponentContext,
241 mxCanvas);
242 mpSharedBitmaps = mpBitmaps;
244 catch(Exception&)
246 OSL_ASSERT(false);
249 UpdateBitmaps();
250 UpdateBorders();
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;
270 if (nPosition < 0)
271 nPosition = 0;
272 return nPosition;
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());
282 return;
285 if (PresenterGeometryHelper::AreRectanglesDisjoint (rUpdateBox, mxWindow->getPosSize()))
286 return;
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)
317 if (mxWindow.is())
319 awt::Rectangle aRepaintBox (rEvent.UpdateRect);
320 const awt::Rectangle aWindowBox (mxWindow->getPosSize());
321 aRepaintBox.X += aWindowBox.X;
322 aRepaintBox.Y += aWindowBox.Y;
323 Paint(aRepaintBox);
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)
386 return;
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)
406 mxWindow = nullptr;
410 geometry::RealRectangle2D const & PresenterScrollBar::GetRectangle (const Area eArea) const
412 OSL_ASSERT(eArea>=0 && eArea<AreaCount);
414 return maBox[eArea];
417 void PresenterScrollBar::Repaint (
418 const geometry::RealRectangle2D& rBox,
419 const bool bAsynchronousUpdate)
421 if (mpPaintManager != nullptr)
422 mpPaintManager->Invalidate(
423 mxWindow,
424 PresenterGeometryHelper::ConvertRectangle(rBox),
425 bAsynchronousUpdate);
428 void PresenterScrollBar::PaintBackground(
429 const css::awt::Rectangle& rUpdateBox)
431 if (!mpBackgroundBitmap)
432 return;
434 const awt::Rectangle aWindowBox (mxWindow->getPosSize());
435 mpCanvasHelper->Paint(
436 mpBackgroundBitmap,
437 mxCanvas,
438 rUpdateBox,
439 aWindowBox,
440 awt::Rectangle());
443 void PresenterScrollBar::PaintBitmap(
444 const css::awt::Rectangle& rUpdateBox,
445 const Area eArea,
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));
458 if (!xBitmap.is())
459 return;
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),
469 xClipPolygon);
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),
476 nullptr,
477 Sequence<double>(4),
478 rendering::CompositeOperation::SOURCE);
480 mxCanvas->drawBitmap(
481 xBitmap,
482 aViewState,
483 aRenderState);
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))
493 return Thumb;
494 else if (PresenterGeometryHelper::IsInside(GetRectangle(PagerUp), aPoint))
495 return PagerUp;
496 else if (PresenterGeometryHelper::IsInside(GetRectangle(PagerDown), aPoint))
497 return PagerDown;
499 else if (PresenterGeometryHelper::IsInside(GetRectangle(PrevButton), aPoint))
500 return PrevButton;
501 else if (PresenterGeometryHelper::IsInside(GetRectangle(NextButton), aPoint))
502 return NextButton;
504 return None;
507 void PresenterScrollBar::UpdateWidthOrHeight (
508 sal_Int32& rSize,
509 const SharedBitmapDescriptor& rpDescriptor)
511 if (rpDescriptor)
513 Reference<rendering::XBitmap> xBitmap (rpDescriptor->GetNormalBitmap());
514 if (xBitmap.is())
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)
519 rSize = nBitmapSize;
524 css::uno::Reference<css::rendering::XBitmap> PresenterScrollBar::GetBitmap (
525 const Area eArea,
526 const SharedBitmapDescriptor& rpBitmaps) const
528 if (!rpBitmaps)
529 return nullptr;
530 else
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;
541 else
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),
560 mnScrollBarWidth(0)
564 PresenterVerticalScrollBar::~PresenterVerticalScrollBar()
568 double PresenterVerticalScrollBar::GetDragDistance (const sal_Int32, const sal_Int32 nY) const
570 const double nDistance (nY - maDragAnchor.Y);
571 if (nDistance == 0)
572 return 0;
573 else
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;
583 else
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
603 return nX;
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());
614 if (xBitmap.is())
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());
625 if (xBitmap.is())
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);
636 if (mnTotalSize < 1)
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;
647 else
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,
653 aWindowBox.Width,
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]),
669 maBox[Pager]);
672 void PresenterVerticalScrollBar::UpdateBitmaps()
674 if (mpBitmaps == nullptr)
675 return;
677 mpPrevButtonDescriptor = mpBitmaps->GetBitmap("Up");
678 mpNextButtonDescriptor = mpBitmaps->GetBitmap("Down");
679 mpPagerStartDescriptor = mpBitmaps->GetBitmap("PagerTop");
680 mpPagerCenterDescriptor = mpBitmaps->GetBitmap("PagerVertical");
681 mpPagerEndDescriptor = mpBitmaps->GetBitmap("PagerBottom");
682 mpThumbStartDescriptor = mpBitmaps->GetBitmap("ThumbTop");
683 mpThumbCenterDescriptor = mpBitmaps->GetBitmap("ThumbVertical");
684 mpThumbEndDescriptor = mpBitmaps->GetBitmap("ThumbBottom");
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,
701 const Area eArea,
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(
716 mxCanvas,
717 rUpdateBox,
718 (eArea == Thumb
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()
738 Stop();
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.
749 Execute();
751 // Schedule repeated executions.
752 auto pThis(shared_from_this());
753 mnMousePressRepeaterTaskId = PresenterTimer::ScheduleRepeatedTask (
754 mpScrollBar->GetComponentContext(),
755 [pThis] (TimeValue const&) { return pThis->Callback(); },
756 500000000,
757 250000000);
759 else
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)
781 Stop();
786 void PresenterScrollBar::MousePressRepeater::Callback ()
788 if (!mpScrollBar)
790 Stop();
791 return;
794 Execute();
797 void PresenterScrollBar::MousePressRepeater::Execute()
799 const double nThumbPosition (mpScrollBar->GetThumbPosition());
800 switch (meMouseArea)
802 case PrevButton:
803 mpScrollBar->SetThumbPosition(nThumbPosition - mpScrollBar->GetLineHeight(), true);
804 break;
806 case NextButton:
807 mpScrollBar->SetThumbPosition(nThumbPosition + mpScrollBar->GetLineHeight(), true);
808 break;
810 case PagerUp:
811 mpScrollBar->SetThumbPosition(nThumbPosition - mpScrollBar->GetThumbSize()*0.8, true);
812 break;
814 case PagerDown:
815 mpScrollBar->SetThumbPosition(nThumbPosition + mpScrollBar->GetThumbSize()*0.8, true);
816 break;
818 default:
819 break;
823 } // end of namespace ::sdext::presenter
825 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */