LibreOffice Module sdext (master)  1
PresenterScrollBar.cxx
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 #include "PresenterScrollBar.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>
31 
32 #include <algorithm>
33 #include <memory>
34 #include <math.h>
35 
36 using namespace ::com::sun::star;
37 using namespace ::com::sun::star::uno;
38 
39 const double gnScrollBarGap (10);
40 
41 namespace sdext::presenter {
42 
43 //===== PresenterScrollBar::MousePressRepeater ================================
44 
46  : public std::enable_shared_from_this<MousePressRepeater>
47 {
48 public:
49  explicit MousePressRepeater (const ::rtl::Reference<PresenterScrollBar>& rpScrollBar);
50  void Dispose();
51  void Start (const PresenterScrollBar::Area& reArea);
52  void Stop();
53  void SetMouseArea (const PresenterScrollBar::Area& reArea);
54 
55 private:
56  void Callback ();
57  void Execute();
58 
62 };
63 
64 //===== PresenterScrollBar ====================================================
65 
66 std::weak_ptr<PresenterBitmapContainer> PresenterScrollBar::mpSharedBitmaps;
67 
69  const Reference<XComponentContext>& rxComponentContext,
70  const Reference<awt::XWindow>& rxParentWindow,
71  const std::shared_ptr<PresenterPaintManager>& rpPaintManager,
72  const ::std::function<void (double)>& rThumbMotionListener)
74  mxComponentContext(rxComponentContext),
75  mpPaintManager(rpPaintManager),
76  mnThumbPosition(0),
77  mnTotalSize(0),
78  mnThumbSize(0),
79  mnLineHeight(10),
80  maDragAnchor(-1,-1),
81  maThumbMotionListener(rThumbMotionListener),
82  meButtonDownArea(None),
83  meMouseMoveArea(None),
84  mbIsNotificationActive(false),
85  mpMousePressRepeater(std::make_shared<MousePressRepeater>(this)),
86  mpCanvasHelper(new PresenterCanvasHelper())
87 {
88  try
89  {
90  Reference<lang::XMultiComponentFactory> xFactory (rxComponentContext->getServiceManager());
91  if ( ! xFactory.is())
92  throw RuntimeException();
93 
95  xFactory->createInstanceWithContext(
96  "com.sun.star.comp.Draw.PresenterHelper",
97  rxComponentContext),
98  UNO_QUERY_THROW);
99 
100  if (mxPresenterHelper.is())
101  mxWindow = mxPresenterHelper->createWindow(rxParentWindow,
102  false,
103  false,
104  false,
105  false);
106 
107  // Make the background transparent. The slide show paints its own background.
108  Reference<awt::XWindowPeer> xPeer (mxWindow, UNO_QUERY_THROW);
109  xPeer->setBackground(0xff000000);
110 
111  mxWindow->setVisible(true);
112  mxWindow->addWindowListener(this);
113  mxWindow->addPaintListener(this);
114  mxWindow->addMouseListener(this);
115  mxWindow->addMouseMotionListener(this);
116  }
117  catch (RuntimeException&)
118  {
119  }
120 }
121 
123 {
124 }
125 
127 {
128  mpMousePressRepeater->Dispose();
129 
130  if (mxWindow.is())
131  {
132  mxWindow->removeWindowListener(this);
133  mxWindow->removePaintListener(this);
134  mxWindow->removeMouseListener(this);
135  mxWindow->removeMouseMotionListener(this);
136 
138  mxWindow = nullptr;
139  if (xComponent.is())
140  xComponent->dispose();
141  }
142 
143  mpBitmaps.reset();
144 }
145 
146 void PresenterScrollBar::SetVisible (const bool bIsVisible)
147 {
148  if (mxWindow.is())
149  mxWindow->setVisible(bIsVisible);
150 }
151 
152 void PresenterScrollBar::SetPosSize (const css::geometry::RealRectangle2D& rBox)
153 {
154  if (mxWindow.is())
155  {
156  mxWindow->setPosSize(
157  sal_Int32(floor(rBox.X1)),
158  sal_Int32(ceil(rBox.Y1)),
159  sal_Int32(ceil(rBox.X2-rBox.X1)),
160  sal_Int32(floor(rBox.Y2-rBox.Y1)),
161  awt::PosSize::POSSIZE);
162  UpdateBorders();
163  }
164 }
165 
167  double nPosition,
168  const bool bAsynchronousUpdate)
169 {
170  nPosition = ValidateThumbPosition(nPosition);
171 
172  if (nPosition == mnThumbPosition || mbIsNotificationActive)
173  return;
174 
175  mnThumbPosition = nPosition;
176 
177  UpdateBorders();
178  Repaint(GetRectangle(Total), bAsynchronousUpdate);
179 
180  mbIsNotificationActive = true;
181  try
182  {
184  }
185  catch (Exception&)
186  {
187  }
188  mbIsNotificationActive = false;
189 }
190 
191 
192 void PresenterScrollBar::SetTotalSize (const double nTotalSize)
193 {
194  if (mnTotalSize != nTotalSize)
195  {
196  mnTotalSize = nTotalSize + 1;
197  UpdateBorders();
198  Repaint(GetRectangle(Total), false);
199  }
200 }
201 
202 void PresenterScrollBar::SetThumbSize (const double nThumbSize)
203 {
204  OSL_ASSERT(nThumbSize>=0);
205  if (mnThumbSize != nThumbSize)
206  {
207  mnThumbSize = nThumbSize;
208  UpdateBorders();
209  Repaint(GetRectangle(Total), false);
210  }
211 }
212 
213 
214 void PresenterScrollBar::SetLineHeight (const double nLineHeight)
215 {
216  mnLineHeight = nLineHeight;
217 }
218 
219 
220 void PresenterScrollBar::SetCanvas (const Reference<css::rendering::XCanvas>& rxCanvas)
221 {
222  if (mxCanvas == rxCanvas)
223  return;
224 
225  mxCanvas = rxCanvas;
226  if (!mxCanvas.is())
227  return;
228 
229  if (mpBitmaps == nullptr)
230  {
231  mpBitmaps = mpSharedBitmaps.lock();
232  if (!mpBitmaps)
233  {
234  try
235  {
236  mpBitmaps = std::make_shared<PresenterBitmapContainer>(
237  "PresenterScreenSettings/ScrollBar/Bitmaps",
238  std::shared_ptr<PresenterBitmapContainer>(),
240  mxCanvas);
242  }
243  catch(Exception&)
244  {
245  OSL_ASSERT(false);
246  }
247  }
248  UpdateBitmaps();
249  UpdateBorders();
250  }
251 
252  Repaint(GetRectangle(Total), false);
253 }
254 
256 {
257  mpBackgroundBitmap = rpBackgroundBitmap;
258 }
259 
261 {
263 }
264 
266 {
267  if (nPosition + mnThumbSize > mnTotalSize)
268  nPosition = mnTotalSize - mnThumbSize;
269  if (nPosition < 0)
270  nPosition = 0;
271  return nPosition;
272 }
273 
275  const awt::Rectangle& rUpdateBox)
276 {
277  if ( ! mxCanvas.is() || ! mxWindow.is())
278  {
279  OSL_ASSERT(mxCanvas.is());
280  OSL_ASSERT(mxWindow.is());
281  return;
282  }
283 
284  if (PresenterGeometryHelper::AreRectanglesDisjoint (rUpdateBox, mxWindow->getPosSize()))
285  return;
286 
287  PaintBackground(rUpdateBox);
288  PaintComposite(rUpdateBox, PagerUp,
290  PaintComposite(rUpdateBox, PagerDown,
292  PaintComposite(rUpdateBox, Thumb,
296 
297  Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxCanvas, UNO_QUERY);
298  if (xSpriteCanvas.is())
299  xSpriteCanvas->updateScreen(false);
300 }
301 
302 //----- XWindowListener -------------------------------------------------------
303 
304 void SAL_CALL PresenterScrollBar::windowResized (const css::awt::WindowEvent&) {}
305 
306 void SAL_CALL PresenterScrollBar::windowMoved (const css::awt::WindowEvent&) {}
307 
308 void SAL_CALL PresenterScrollBar::windowShown (const css::lang::EventObject&) {}
309 
310 void SAL_CALL PresenterScrollBar::windowHidden (const css::lang::EventObject&) {}
311 
312 //----- XPaintListener --------------------------------------------------------
313 
314 void SAL_CALL PresenterScrollBar::windowPaint (const css::awt::PaintEvent& rEvent)
315 {
316  if (mxWindow.is())
317  {
318  awt::Rectangle aRepaintBox (rEvent.UpdateRect);
319  const awt::Rectangle aWindowBox (mxWindow->getPosSize());
320  aRepaintBox.X += aWindowBox.X;
321  aRepaintBox.Y += aWindowBox.Y;
322  Paint(aRepaintBox);
323 
324  Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxCanvas, UNO_QUERY);
325  if (xSpriteCanvas.is())
326  xSpriteCanvas->updateScreen(false);
327  }
328 }
329 
330 //----- XMouseListener --------------------------------------------------------
331 
332 void SAL_CALL PresenterScrollBar::mousePressed (const css::awt::MouseEvent& rEvent)
333 {
334  maDragAnchor.X = rEvent.X;
335  maDragAnchor.Y = rEvent.Y;
336  meButtonDownArea = GetArea(rEvent.X, rEvent.Y);
337 
339 }
340 
341 void SAL_CALL PresenterScrollBar::mouseReleased (const css::awt::MouseEvent&)
342 {
343  mpMousePressRepeater->Stop();
344 
345  if (mxPresenterHelper.is())
346  mxPresenterHelper->releaseMouse(mxWindow);
347 }
348 
349 void SAL_CALL PresenterScrollBar::mouseEntered (const css::awt::MouseEvent&) {}
350 
351 void SAL_CALL PresenterScrollBar::mouseExited (const css::awt::MouseEvent&)
352 {
353  if (meMouseMoveArea != None)
354  {
355  const Area eOldMouseMoveArea (meMouseMoveArea);
357  Repaint(GetRectangle(eOldMouseMoveArea), true);
358  }
361 
362  mpMousePressRepeater->Stop();
363 }
364 
365 //----- XMouseMotionListener --------------------------------------------------
366 
367 void SAL_CALL PresenterScrollBar::mouseMoved (const css::awt::MouseEvent& rEvent)
368 {
369  const Area eArea (GetArea(rEvent.X, rEvent.Y));
370  if (eArea != meMouseMoveArea)
371  {
372  const Area eOldMouseMoveArea (meMouseMoveArea);
373  meMouseMoveArea = eArea;
374  if (eOldMouseMoveArea != None)
375  Repaint(GetRectangle(eOldMouseMoveArea), meMouseMoveArea==None);
376  if (meMouseMoveArea != None)
378  }
379  mpMousePressRepeater->SetMouseArea(eArea);
380 }
381 
382 void SAL_CALL PresenterScrollBar::mouseDragged (const css::awt::MouseEvent& rEvent)
383 {
384  if (meButtonDownArea != Thumb)
385  return;
386 
387  mpMousePressRepeater->Stop();
388 
389  if (mxPresenterHelper.is())
390  mxPresenterHelper->captureMouse(mxWindow);
391 
392  const double nDragDistance (GetDragDistance(rEvent.X,rEvent.Y));
393  UpdateDragAnchor(nDragDistance);
394  if (nDragDistance != 0)
395  {
396  SetThumbPosition(mnThumbPosition + nDragDistance, false);
397  }
398 }
399 
400 //----- lang::XEventListener --------------------------------------------------
401 
402 void SAL_CALL PresenterScrollBar::disposing (const css::lang::EventObject& rEvent)
403 {
404  if (rEvent.Source == mxWindow)
405  mxWindow = nullptr;
406 }
407 
408 
409 geometry::RealRectangle2D const & PresenterScrollBar::GetRectangle (const Area eArea) const
410 {
411  OSL_ASSERT(eArea>=0 && eArea<AreaCount);
412 
413  return maBox[eArea];
414 }
415 
417  const geometry::RealRectangle2D& rBox,
418  const bool bAsynchronousUpdate)
419 {
420  if (mpPaintManager != nullptr)
421  mpPaintManager->Invalidate(
422  mxWindow,
424  bAsynchronousUpdate);
425 }
426 
428  const css::awt::Rectangle& rUpdateBox)
429 {
430  if (!mpBackgroundBitmap)
431  return;
432 
433  const awt::Rectangle aWindowBox (mxWindow->getPosSize());
434  mpCanvasHelper->Paint(
436  mxCanvas,
437  rUpdateBox,
438  aWindowBox,
439  awt::Rectangle());
440 }
441 
443  const css::awt::Rectangle& rUpdateBox,
444  const Area eArea,
445  const SharedBitmapDescriptor& rpBitmaps)
446 {
447  const geometry::RealRectangle2D aLocalBox (GetRectangle(eArea));
448  const awt::Rectangle aWindowBox (mxWindow->getPosSize());
449  geometry::RealRectangle2D aBox (aLocalBox);
450  aBox.X1 += aWindowBox.X;
451  aBox.Y1 += aWindowBox.Y;
452  aBox.X2 += aWindowBox.X;
453  aBox.Y2 += aWindowBox.Y;
454 
455  Reference<rendering::XBitmap> xBitmap (GetBitmap(eArea,rpBitmaps));
456 
457  if (!xBitmap.is())
458  return;
459 
460  Reference<rendering::XPolyPolygon2D> xClipPolygon (
464  mxCanvas->getDevice()));
465 
466  const rendering::ViewState aViewState (
467  geometry::AffineMatrix2D(1,0,0, 0,1,0),
468  xClipPolygon);
469 
470  const geometry::IntegerSize2D aBitmapSize (xBitmap->getSize());
471  rendering::RenderState aRenderState (
472  geometry::AffineMatrix2D(
473  1,0,aBox.X1 + (aBox.X2-aBox.X1 - aBitmapSize.Width)/2,
474  0,1,aBox.Y1 + (aBox.Y2-aBox.Y1 - aBitmapSize.Height)/2),
475  nullptr,
476  Sequence<double>(4),
477  rendering::CompositeOperation::SOURCE);
478 
479  mxCanvas->drawBitmap(
480  xBitmap,
481  aViewState,
482  aRenderState);
483 }
484 
485 PresenterScrollBar::Area PresenterScrollBar::GetArea (const double nX, const double nY) const
486 {
487  const geometry::RealPoint2D aPoint(nX, nY);
488 
490  {
492  return Thumb;
494  return PagerUp;
496  return PagerDown;
497  }
499  return PrevButton;
501  return NextButton;
502 
503  return None;
504 }
505 
507  sal_Int32& rSize,
508  const SharedBitmapDescriptor& rpDescriptor)
509 {
510  if (rpDescriptor)
511  {
512  Reference<rendering::XBitmap> xBitmap (rpDescriptor->GetNormalBitmap());
513  if (xBitmap.is())
514  {
515  const geometry::IntegerSize2D aBitmapSize (xBitmap->getSize());
516  const sal_Int32 nBitmapSize = static_cast<sal_Int32>(GetMinor(aBitmapSize.Width, aBitmapSize.Height));
517  if (nBitmapSize > rSize)
518  rSize = nBitmapSize;
519  }
520  }
521 }
522 
523 css::uno::Reference<css::rendering::XBitmap> PresenterScrollBar::GetBitmap (
524  const Area eArea,
525  const SharedBitmapDescriptor& rpBitmaps) const
526 {
527  if (!rpBitmaps)
528  return nullptr;
529  else
530  return rpBitmaps->GetBitmap(GetBitmapMode(eArea));
531 }
532 
534  const Area eArea) const
535 {
536  if (IsDisabled(eArea))
538  else if (eArea == meMouseMoveArea)
540  else
542 }
543 
544 bool PresenterScrollBar::IsDisabled (const Area eArea) const
545 {
546  OSL_ASSERT(eArea>=0 && eArea<AreaCount);
547 
548  return ! maEnabledState[eArea];
549 }
550 
551 //===== PresenterVerticalScrollBar ============================================
552 
554  const Reference<XComponentContext>& rxComponentContext,
555  const Reference<awt::XWindow>& rxParentWindow,
556  const std::shared_ptr<PresenterPaintManager>& rpPaintManager,
557  const ::std::function<void (double)>& rThumbMotionListener)
558  : PresenterScrollBar(rxComponentContext, rxParentWindow, rpPaintManager, rThumbMotionListener),
559  mnScrollBarWidth(0)
560 {
561 }
562 
564 {
565 }
566 
567 double PresenterVerticalScrollBar::GetDragDistance (const sal_Int32, const sal_Int32 nY) const
568 {
569  const double nDistance (nY - maDragAnchor.Y);
570  if (nDistance == 0)
571  return 0;
572  else
573  {
574  const awt::Rectangle aWindowBox (mxWindow->getPosSize());
575  const double nBarWidth (aWindowBox.Width);
576  const double nPagerHeight (aWindowBox.Height - 2*nBarWidth);
577  const double nDragDistance (mnTotalSize / nPagerHeight * nDistance);
578  if (nDragDistance + mnThumbPosition < 0)
579  return -mnThumbPosition;
580  else if (mnThumbPosition + nDragDistance > mnTotalSize-mnThumbSize)
582  else
583  return nDragDistance;
584  }
585 }
586 
587 void PresenterVerticalScrollBar::UpdateDragAnchor (const double nDragDistance)
588 {
589  const awt::Rectangle aWindowBox (mxWindow->getPosSize());
590  const double nBarWidth (aWindowBox.Width);
591  const double nPagerHeight (aWindowBox.Height - 2*nBarWidth);
592  maDragAnchor.Y += nDragDistance * nPagerHeight / mnTotalSize;
593 }
594 
596 {
597  return mnScrollBarWidth;
598 }
599 
600 double PresenterVerticalScrollBar::GetMinor (const double nX, const double) const
601 {
602  return nX;
603 }
604 
606 {
607  const awt::Rectangle aWindowBox (mxWindow->getPosSize());
608  double nBottom = aWindowBox.Height;
609 
611  {
612  Reference<rendering::XBitmap> xBitmap (mpNextButtonDescriptor->GetNormalBitmap());
613  if (xBitmap.is())
614  {
615  geometry::IntegerSize2D aSize (xBitmap->getSize());
616  maBox[NextButton] = geometry::RealRectangle2D(
617  0, nBottom - aSize.Height, aWindowBox.Width, nBottom);
618  nBottom -= aSize.Height + gnScrollBarGap;
619  }
620  }
622  {
623  Reference<rendering::XBitmap> xBitmap (mpPrevButtonDescriptor->GetNormalBitmap());
624  if (xBitmap.is())
625  {
626  geometry::IntegerSize2D aSize (xBitmap->getSize());
627  maBox[PrevButton] = geometry::RealRectangle2D(
628  0, nBottom - aSize.Height, aWindowBox.Width, nBottom);
629  nBottom -= aSize.Height + gnScrollBarGap;
630  }
631  }
632  const double nPagerHeight (nBottom);
633  maBox[Pager] = geometry::RealRectangle2D(
634  0,0, aWindowBox.Width, nBottom);
635  if (mnTotalSize < 1)
636  {
637  maBox[Thumb] = maBox[Pager];
638 
639  // Set up the enabled/disabled states.
640  maEnabledState[PrevButton] = false;
641  maEnabledState[PagerUp] = false;
642  maEnabledState[NextButton] = false;
643  maEnabledState[PagerDown] = false;
644  maEnabledState[Thumb] = false;
645  }
646  else
647  {
648  const double nThumbSize = ::std::min(mnThumbSize,mnTotalSize);
649  const double nThumbPosition = ::std::clamp(mnThumbPosition, 0.0, mnTotalSize - nThumbSize);
650  maBox[Thumb] = geometry::RealRectangle2D(
651  0, nThumbPosition / mnTotalSize * nPagerHeight,
652  aWindowBox.Width,
653  (nThumbPosition+nThumbSize) / mnTotalSize * nPagerHeight);
654 
655  // Set up the enabled/disabled states.
656  maEnabledState[PrevButton] = nThumbPosition>0;
657  maEnabledState[PagerUp] = nThumbPosition>0;
658  maEnabledState[NextButton] = nThumbPosition+nThumbSize < mnTotalSize;
659  maEnabledState[PagerDown] = nThumbPosition+nThumbSize < mnTotalSize;
660  maEnabledState[Thumb] = nThumbSize < mnTotalSize;
661  }
662  maBox[PagerUp] = geometry::RealRectangle2D(
663  maBox[Pager].X1, maBox[Pager].Y1, maBox[Pager].X2, maBox[Thumb].Y1-1);
664  maBox[PagerDown] = geometry::RealRectangle2D(
665  maBox[Pager].X1, maBox[Thumb].Y2+1, maBox[Pager].X2, maBox[Pager].Y2);
668  maBox[Pager]);
669 }
670 
672 {
673  if (mpBitmaps == nullptr)
674  return;
675 
676  mpPrevButtonDescriptor = mpBitmaps->GetBitmap("Up");
677  mpNextButtonDescriptor = mpBitmaps->GetBitmap("Down");
678  mpPagerStartDescriptor = mpBitmaps->GetBitmap("PagerTop");
679  mpPagerCenterDescriptor = mpBitmaps->GetBitmap("PagerVertical");
680  mpPagerEndDescriptor = mpBitmaps->GetBitmap("PagerBottom");
681  mpThumbStartDescriptor = mpBitmaps->GetBitmap("ThumbTop");
682  mpThumbCenterDescriptor = mpBitmaps->GetBitmap("ThumbVertical");
683  mpThumbEndDescriptor = mpBitmaps->GetBitmap("ThumbBottom");
684 
685  mnScrollBarWidth = 0;
694  if (mnScrollBarWidth == 0)
695  mnScrollBarWidth = 20;
696 }
697 
699  const css::awt::Rectangle& rUpdateBox,
700  const Area eArea,
701  const SharedBitmapDescriptor& rpStartBitmaps,
702  const SharedBitmapDescriptor& rpCenterBitmaps,
703  const SharedBitmapDescriptor& rpEndBitmaps)
704 {
705  const awt::Rectangle aWindowBox (mxWindow->getPosSize());
706  geometry::RealRectangle2D aBox (GetRectangle(eArea));
707  aBox.X1 += aWindowBox.X;
708  aBox.Y1 += aWindowBox.Y;
709  aBox.X2 += aWindowBox.X;
710  aBox.Y2 += aWindowBox.Y;
711 
712  // Get bitmaps and sizes.
713 
715  mxCanvas,
716  rUpdateBox,
717  (eArea == Thumb
720  GetBitmap(eArea, rpStartBitmaps),
721  GetBitmap(eArea, rpCenterBitmaps),
722  GetBitmap(eArea, rpEndBitmaps));
723 }
724 
725 //===== PresenterScrollBar::MousePressRepeater ================================
726 
728  const ::rtl::Reference<PresenterScrollBar>& rpScrollBar)
729  : mnMousePressRepeaterTaskId(PresenterTimer::NotAValidTaskId),
730  mpScrollBar(rpScrollBar),
731  meMouseArea(PresenterScrollBar::None)
732 {
733 }
734 
736 {
737  Stop();
738  mpScrollBar = nullptr;
739 }
740 
742 {
743  meMouseArea = reArea;
744 
745  if (mnMousePressRepeaterTaskId == PresenterTimer::NotAValidTaskId)
746  {
747  // Execute key press operation at least this one time.
748  Execute();
749 
750  // Schedule repeated executions.
751  auto pThis(shared_from_this());
752  mnMousePressRepeaterTaskId = PresenterTimer::ScheduleRepeatedTask (
753  mpScrollBar->GetComponentContext(),
754  [pThis] (TimeValue const&) { return pThis->Callback(); },
755  500000000,
756  250000000);
757  }
758  else
759  {
760  // There is already an active repeating task.
761  }
762 }
763 
765 {
766  if (mnMousePressRepeaterTaskId != PresenterTimer::NotAValidTaskId)
767  {
768  const sal_Int32 nTaskId (mnMousePressRepeaterTaskId);
769  mnMousePressRepeaterTaskId = PresenterTimer::NotAValidTaskId;
771  }
772 }
773 
775 {
776  if (meMouseArea != reArea)
777  {
778  if (mnMousePressRepeaterTaskId != PresenterTimer::NotAValidTaskId)
779  {
780  Stop();
781  }
782  }
783 }
784 
786 {
787  if (!mpScrollBar)
788  {
789  Stop();
790  return;
791  }
792 
793  Execute();
794 }
795 
797 {
798  const double nThumbPosition (mpScrollBar->GetThumbPosition());
799  switch (meMouseArea)
800  {
801  case PrevButton:
802  mpScrollBar->SetThumbPosition(nThumbPosition - mpScrollBar->GetLineHeight(), true);
803  break;
804 
805  case NextButton:
806  mpScrollBar->SetThumbPosition(nThumbPosition + mpScrollBar->GetLineHeight(), true);
807  break;
808 
809  case PagerUp:
810  mpScrollBar->SetThumbPosition(nThumbPosition - mpScrollBar->GetThumbSize()*0.8, true);
811  break;
812 
813  case PagerDown:
814  mpScrollBar->SetThumbPosition(nThumbPosition + mpScrollBar->GetThumbSize()*0.8, true);
815  break;
816 
817  default:
818  break;
819  }
820 }
821 
822 } // end of namespace ::sdext::presenter
823 
824 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< PresenterBitmapContainer > mpBitmaps
virtual void UpdateDragAnchor(const double nDragDistance) override
static sal_Int32 ScheduleRepeatedTask(const css::uno::Reference< css::uno::XComponentContext > &xContext, const Task &rTask, const sal_Int64 nFirst, const sal_Int64 nInterval)
Schedule a task to be executed repeatedly.
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
static bool AreRectanglesDisjoint(const css::awt::Rectangle &rBox1, const css::awt::Rectangle &rBox2)
::std::function< void(double)> maThumbMotionListener
virtual void SAL_CALL mouseDragged(const css::awt::MouseEvent &rEvent) override
virtual double GetDragDistance(const sal_Int32 nX, const sal_Int32 nY) const =0
const ::avmedia::MediaItem * Execute(const SdrMarkView *pSdrView, SfxRequest const &rReq)
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)
std::shared_ptr< T > make_shared(Args &&...args)
None
void SetLineHeight(const double nLineHeight)
static css::geometry::RealRectangle2D Union(const css::geometry::RealRectangle2D &rBox1, const css::geometry::RealRectangle2D &rBox2)
PresenterBitmapContainer::BitmapDescriptor::Mode GetBitmapMode(const Area eArea) const
PresenterScrollBar(const PresenterScrollBar &)=delete
std::shared_ptr< PresenterBitmapContainer::BitmapDescriptor > SharedBitmapDescriptor
Collection of functions to ease the life of a canvas user.
std::mutex m_aMutex
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 Start(const PresenterScrollBar::Area &reArea)
static void CancelTask(const sal_Int32 nTaskId)
void Paint(const css::awt::Rectangle &rUpdateBox)
On some occasions it is necessary to trigger the painting of a scrollbar from the outside...
MousePressRepeater(const ::rtl::Reference< PresenterScrollBar > &rpScrollBar)
css::uno::Reference< css::uno::XComponentContext > mxComponentContext
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]
static void PaintVerticalBitmapComposite(const css::uno::Reference< css::rendering::XCanvas > &rxCanvas, const css::awt::Rectangle &rRepaintBox, const css::awt::Rectangle &rBoundingBox, const css::uno::Reference< css::rendering::XBitmap > &rxTopBitmap, const css::uno::Reference< css::rendering::XBitmap > &rxRepeatableCenterBitmap, const css::uno::Reference< css::rendering::XBitmap > &rxBottomBitmap)
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.
static css::awt::Rectangle ConvertRectangleWithConstantSize(const css::geometry::RealRectangle2D &rBox)
Convert the given rectangle to integer coordinates so that width and height remain constant when only...
css::geometry::RealPoint2D maDragAnchor
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.
static css::awt::Rectangle ConvertRectangle(const css::geometry::RealRectangle2D &rBox)
Return the bounding box with integer coordinates of the given rectangle.
static css::uno::Reference< css::rendering::XPolyPolygon2D > CreatePolygon(const css::awt::Rectangle &rBox, const css::uno::Reference< css::rendering::XGraphicDevice > &rxDevice)
const double gnScrollBarGap(10)
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
static css::awt::Rectangle Intersection(const css::awt::Rectangle &rBox1, const css::awt::Rectangle &rBox2)
virtual void SAL_CALL mousePressed(const css::awt::MouseEvent &rEvent) override
void Repaint(const css::geometry::RealRectangle2D &rBox, const bool bAsynchronous)
void SetMouseArea(const PresenterScrollBar::Area &reArea)
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
static const sal_Int32 NotAValidTaskId
Reference< XSingleServiceFactory > xFactory
aCursorMoveIdle Stop()
static bool IsInside(const css::geometry::RealRectangle2D &rBox, const css::geometry::RealPoint2D &rPoint)
The timer allows tasks to be scheduled for execution at a specified time in the future.
css::uno::Reference< css::awt::XWindow > mxWindow
::cppu::WeakComponentImplHelper< css::awt::XWindowListener, css::awt::XPaintListener, css::awt::XMouseListener, css::awt::XMouseMotionListener > PresenterScrollBarInterfaceBase
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)