fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sdext / source / presenter / PresenterScrollBar.cxx
blobbfcccdc6260796cc0535a819d3ee1bed1fc0a3ad
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/WindowAttribute.hpp>
29 #include <com/sun/star/awt/XWindowPeer.hpp>
30 #include <com/sun/star/awt/XToolkit.hpp>
31 #include <com/sun/star/rendering/CompositeOperation.hpp>
32 #include <com/sun/star/rendering/TexturingMode.hpp>
33 #include <com/sun/star/rendering/XPolyPolygon2D.hpp>
34 #include <boost/bind.hpp>
35 #include <boost/enable_shared_from_this.hpp>
36 #include <boost/weak_ptr.hpp>
37 #include <math.h>
39 using namespace ::com::sun::star;
40 using namespace ::com::sun::star::uno;
42 const static double gnScrollBarGap (10);
44 namespace sdext { namespace presenter {
46 //===== PresenterScrollBar::MousePressRepeater ================================
48 class PresenterScrollBar::MousePressRepeater
49 : public ::boost::enable_shared_from_this<MousePressRepeater>
51 public:
52 MousePressRepeater (const ::rtl::Reference<PresenterScrollBar>& rpScrollBar);
53 void Dispose();
54 void Start (const PresenterScrollBar::Area& reArea);
55 void Stop();
56 void SetMouseArea (const PresenterScrollBar::Area& reArea);
58 private:
59 void Callback (const TimeValue& rCurrentTime);
60 void Execute();
62 sal_Int32 mnMousePressRepeaterTaskId;
63 ::rtl::Reference<PresenterScrollBar> mpScrollBar;
64 PresenterScrollBar::Area meMouseArea;
67 //===== PresenterScrollBar ====================================================
69 boost::weak_ptr<PresenterBitmapContainer> PresenterScrollBar::mpSharedBitmaps;
71 PresenterScrollBar::PresenterScrollBar (
72 const Reference<XComponentContext>& rxComponentContext,
73 const Reference<awt::XWindow>& rxParentWindow,
74 const ::boost::shared_ptr<PresenterPaintManager>& rpPaintManager,
75 const ::boost::function<void(double)>& rThumbMotionListener)
76 : PresenterScrollBarInterfaceBase(m_aMutex),
77 mxComponentContext(rxComponentContext),
78 mxParentWindow(rxParentWindow),
79 mxWindow(),
80 mxCanvas(),
81 mxPresenterHelper(),
82 mpPaintManager(rpPaintManager),
83 mnThumbPosition(0),
84 mnTotalSize(0),
85 mnThumbSize(0),
86 mnLineHeight(10),
87 maDragAnchor(-1,-1),
88 maThumbMotionListener(rThumbMotionListener),
89 meButtonDownArea(None),
90 meMouseMoveArea(None),
91 mbIsNotificationActive(false),
92 mpBitmaps(),
93 mpPrevButtonDescriptor(),
94 mpNextButtonDescriptor(),
95 mpPagerStartDescriptor(),
96 mpPagerCenterDescriptor(),
97 mpPagerEndDescriptor(),
98 mpThumbStartDescriptor(),
99 mpThumbCenterDescriptor(),
100 mpThumbEndDescriptor(),
101 mpMousePressRepeater(new MousePressRepeater(this)),
102 mpBackgroundBitmap(),
103 mpCanvasHelper(new PresenterCanvasHelper())
107 Reference<lang::XMultiComponentFactory> xFactory (rxComponentContext->getServiceManager());
108 if ( ! xFactory.is())
109 throw RuntimeException();
111 mxPresenterHelper = Reference<drawing::XPresenterHelper>(
112 xFactory->createInstanceWithContext(
113 OUString("com.sun.star.comp.Draw.PresenterHelper"),
114 rxComponentContext),
115 UNO_QUERY_THROW);
117 if (mxPresenterHelper.is())
118 mxWindow = mxPresenterHelper->createWindow(rxParentWindow,
119 sal_False,
120 sal_False,
121 sal_False,
122 sal_False);
124 // Make the background transparent. The slide show paints its own background.
125 Reference<awt::XWindowPeer> xPeer (mxWindow, UNO_QUERY_THROW);
126 if (xPeer.is())
128 xPeer->setBackground(0xff000000);
131 mxWindow->setVisible(sal_True);
132 mxWindow->addWindowListener(this);
133 mxWindow->addPaintListener(this);
134 mxWindow->addMouseListener(this);
135 mxWindow->addMouseMotionListener(this);
137 catch (RuntimeException&)
142 PresenterScrollBar::~PresenterScrollBar()
146 void SAL_CALL PresenterScrollBar::disposing()
148 mpMousePressRepeater->Dispose();
150 if (mxWindow.is())
152 mxWindow->removeWindowListener(this);
153 mxWindow->removePaintListener(this);
154 mxWindow->removeMouseListener(this);
155 mxWindow->removeMouseMotionListener(this);
157 Reference<lang::XComponent> xComponent (mxWindow, UNO_QUERY);
158 mxWindow = NULL;
159 if (xComponent.is())
160 xComponent->dispose();
163 mpBitmaps.reset();
166 void PresenterScrollBar::SetVisible (const bool bIsVisible)
168 if (mxWindow.is())
169 mxWindow->setVisible(bIsVisible);
172 void PresenterScrollBar::SetPosSize (const css::geometry::RealRectangle2D& rBox)
174 if (mxWindow.is())
176 mxWindow->setPosSize(
177 sal_Int32(floor(rBox.X1)),
178 sal_Int32(ceil(rBox.Y1)),
179 sal_Int32(ceil(rBox.X2-rBox.X1)),
180 sal_Int32(floor(rBox.Y2-rBox.Y1)),
181 awt::PosSize::POSSIZE);
182 UpdateBorders();
186 void PresenterScrollBar::SetThumbPosition (
187 double nPosition,
188 const bool bAsynchronousUpdate)
190 SetThumbPosition(nPosition, bAsynchronousUpdate, true, true);
193 void PresenterScrollBar::SetThumbPosition (
194 double nPosition,
195 const bool bAsynchronousUpdate,
196 const bool bValidate,
197 const bool bNotify)
199 if (bValidate)
200 nPosition = ValidateThumbPosition(nPosition);
202 if (nPosition != mnThumbPosition && ! mbIsNotificationActive)
204 mnThumbPosition = nPosition;
206 UpdateBorders();
207 Repaint(GetRectangle(Total), bAsynchronousUpdate);
208 if (bNotify)
209 NotifyThumbPositionChange();
214 void PresenterScrollBar::SetTotalSize (const double nTotalSize)
216 if (mnTotalSize != nTotalSize)
218 mnTotalSize = nTotalSize + 1;
219 UpdateBorders();
220 Repaint(GetRectangle(Total), false);
224 void PresenterScrollBar::SetThumbSize (const double nThumbSize)
226 OSL_ASSERT(nThumbSize>=0);
227 if (mnThumbSize != nThumbSize)
229 mnThumbSize = nThumbSize;
230 UpdateBorders();
231 Repaint(GetRectangle(Total), false);
236 void PresenterScrollBar::SetLineHeight (const double nLineHeight)
238 mnLineHeight = nLineHeight;
242 void PresenterScrollBar::SetCanvas (const Reference<css::rendering::XCanvas>& rxCanvas)
244 if (mxCanvas != rxCanvas)
246 mxCanvas = rxCanvas;
247 if (mxCanvas.is())
249 if (mpBitmaps.get()==NULL)
251 if (mpSharedBitmaps.expired())
255 mpBitmaps.reset(new PresenterBitmapContainer(
256 OUString("PresenterScreenSettings/ScrollBar/Bitmaps"),
257 ::boost::shared_ptr<PresenterBitmapContainer>(),
258 mxComponentContext,
259 mxCanvas));
260 mpSharedBitmaps = mpBitmaps;
262 catch(Exception&)
264 OSL_ASSERT(false);
267 else
268 mpBitmaps = ::boost::shared_ptr<PresenterBitmapContainer>(mpSharedBitmaps);
269 UpdateBitmaps();
270 UpdateBorders();
273 Repaint(GetRectangle(Total), false);
278 void PresenterScrollBar::SetBackground (const SharedBitmapDescriptor& rpBackgroundBitmap)
280 mpBackgroundBitmap = rpBackgroundBitmap;
283 void PresenterScrollBar::CheckValues()
285 mnThumbPosition = ValidateThumbPosition(mnThumbPosition);
288 double PresenterScrollBar::ValidateThumbPosition (double nPosition)
290 if (nPosition + mnThumbSize > mnTotalSize)
291 nPosition = mnTotalSize - mnThumbSize;
292 if (nPosition < 0)
293 nPosition = 0;
294 return nPosition;
297 void PresenterScrollBar::Paint (
298 const awt::Rectangle& rUpdateBox,
299 const bool bNoClip)
301 if ( ! mxCanvas.is() || ! mxWindow.is())
303 OSL_ASSERT(mxCanvas.is());
304 OSL_ASSERT(mxWindow.is());
305 return;
308 if ( ! bNoClip)
310 if (PresenterGeometryHelper::AreRectanglesDisjoint (rUpdateBox, mxWindow->getPosSize()))
311 return;
314 PaintBackground(rUpdateBox);
315 PaintComposite(rUpdateBox, PagerUp,
316 mpPagerStartDescriptor, mpPagerCenterDescriptor, SharedBitmapDescriptor());
317 PaintComposite(rUpdateBox, PagerDown,
318 SharedBitmapDescriptor(), mpPagerCenterDescriptor, mpPagerEndDescriptor);
319 PaintComposite(rUpdateBox, Thumb,
320 mpThumbStartDescriptor, mpThumbCenterDescriptor, mpThumbEndDescriptor);
321 PaintBitmap(rUpdateBox, PrevButton, mpPrevButtonDescriptor);
322 PaintBitmap(rUpdateBox, NextButton, mpNextButtonDescriptor);
324 Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxCanvas, UNO_QUERY);
325 if (xSpriteCanvas.is())
326 xSpriteCanvas->updateScreen(sal_False);
329 //----- XWindowListener -------------------------------------------------------
331 void SAL_CALL PresenterScrollBar::windowResized (const css::awt::WindowEvent& rEvent)
332 throw (css::uno::RuntimeException, std::exception)
334 (void)rEvent;
337 void SAL_CALL PresenterScrollBar::windowMoved (const css::awt::WindowEvent& rEvent)
338 throw (css::uno::RuntimeException, std::exception)
340 (void)rEvent;
343 void SAL_CALL PresenterScrollBar::windowShown (const css::lang::EventObject& rEvent)
344 throw (css::uno::RuntimeException, std::exception)
346 (void)rEvent;
349 void SAL_CALL PresenterScrollBar::windowHidden (const css::lang::EventObject& rEvent)
350 throw (css::uno::RuntimeException, std::exception)
352 (void)rEvent;
355 //----- XPaintListener --------------------------------------------------------
357 void SAL_CALL PresenterScrollBar::windowPaint (const css::awt::PaintEvent& rEvent)
358 throw (css::uno::RuntimeException, std::exception)
360 if (mxWindow.is())
362 awt::Rectangle aRepaintBox (rEvent.UpdateRect);
363 const awt::Rectangle aWindowBox (mxWindow->getPosSize());
364 aRepaintBox.X += aWindowBox.X;
365 aRepaintBox.Y += aWindowBox.Y;
366 Paint(aRepaintBox);
368 Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxCanvas, UNO_QUERY);
369 if (xSpriteCanvas.is())
370 xSpriteCanvas->updateScreen(sal_False);
374 //----- XMouseListener --------------------------------------------------------
376 void SAL_CALL PresenterScrollBar::mousePressed (const css::awt::MouseEvent& rEvent)
377 throw(css::uno::RuntimeException, std::exception)
379 maDragAnchor.X = rEvent.X;
380 maDragAnchor.Y = rEvent.Y;
381 meButtonDownArea = GetArea(rEvent.X, rEvent.Y);
383 mpMousePressRepeater->Start(meButtonDownArea);
386 void SAL_CALL PresenterScrollBar::mouseReleased (const css::awt::MouseEvent& rEvent)
387 throw(css::uno::RuntimeException, std::exception)
389 (void)rEvent;
391 mpMousePressRepeater->Stop();
393 if (mxPresenterHelper.is())
394 mxPresenterHelper->releaseMouse(mxWindow);
397 void SAL_CALL PresenterScrollBar::mouseEntered (const css::awt::MouseEvent& rEvent)
398 throw(css::uno::RuntimeException, std::exception)
400 (void)rEvent;
403 void SAL_CALL PresenterScrollBar::mouseExited (const css::awt::MouseEvent& rEvent)
404 throw(css::uno::RuntimeException, std::exception)
406 (void)rEvent;
407 if (meMouseMoveArea != None)
409 const Area eOldMouseMoveArea (meMouseMoveArea);
410 meMouseMoveArea = None;
411 Repaint(GetRectangle(eOldMouseMoveArea), true);
413 meButtonDownArea = None;
414 meMouseMoveArea = None;
416 mpMousePressRepeater->Stop();
419 //----- XMouseMotionListener --------------------------------------------------
421 void SAL_CALL PresenterScrollBar::mouseMoved (const css::awt::MouseEvent& rEvent)
422 throw (css::uno::RuntimeException, std::exception)
424 const Area eArea (GetArea(rEvent.X, rEvent.Y));
425 if (eArea != meMouseMoveArea)
427 const Area eOldMouseMoveArea (meMouseMoveArea);
428 meMouseMoveArea = eArea;
429 if (eOldMouseMoveArea != None)
430 Repaint(GetRectangle(eOldMouseMoveArea), meMouseMoveArea==None);
431 if (meMouseMoveArea != None)
432 Repaint(GetRectangle(meMouseMoveArea), true);
434 mpMousePressRepeater->SetMouseArea(eArea);
437 void SAL_CALL PresenterScrollBar::mouseDragged (const css::awt::MouseEvent& rEvent)
438 throw (css::uno::RuntimeException, std::exception)
440 if (meButtonDownArea != Thumb)
441 return;
443 mpMousePressRepeater->Stop();
445 if (mxPresenterHelper.is())
446 mxPresenterHelper->captureMouse(mxWindow);
448 const double nDragDistance (GetDragDistance(rEvent.X,rEvent.Y));
449 UpdateDragAnchor(nDragDistance);
450 if (nDragDistance != 0)
452 SetThumbPosition(mnThumbPosition + nDragDistance, false, true, true);
456 //----- lang::XEventListener --------------------------------------------------
458 void SAL_CALL PresenterScrollBar::disposing (const css::lang::EventObject& rEvent)
459 throw (css::uno::RuntimeException, std::exception)
461 if (rEvent.Source == mxWindow)
462 mxWindow = NULL;
467 geometry::RealRectangle2D PresenterScrollBar::GetRectangle (const Area eArea) const
469 OSL_ASSERT(eArea>=0 && eArea<__AreaCount__);
471 return maBox[eArea];
474 void PresenterScrollBar::Repaint (
475 const geometry::RealRectangle2D& rBox,
476 const bool bAsynchronousUpdate)
478 if (mpPaintManager.get() != NULL)
479 mpPaintManager->Invalidate(
480 mxWindow,
481 PresenterGeometryHelper::ConvertRectangle(rBox),
482 bAsynchronousUpdate);
485 void PresenterScrollBar::PaintBackground(
486 const css::awt::Rectangle& rUpdateBox)
488 if (mpBackgroundBitmap.get() == NULL)
489 return;
491 const awt::Rectangle aWindowBox (mxWindow->getPosSize());
492 mpCanvasHelper->Paint(
493 mpBackgroundBitmap,
494 mxCanvas,
495 rUpdateBox,
496 aWindowBox,
497 awt::Rectangle());
500 void PresenterScrollBar::PaintBitmap(
501 const css::awt::Rectangle& rUpdateBox,
502 const Area eArea,
503 const SharedBitmapDescriptor& rpBitmaps)
505 const geometry::RealRectangle2D aLocalBox (GetRectangle(eArea));
506 const awt::Rectangle aWindowBox (mxWindow->getPosSize());
507 geometry::RealRectangle2D aBox (aLocalBox);
508 aBox.X1 += aWindowBox.X;
509 aBox.Y1 += aWindowBox.Y;
510 aBox.X2 += aWindowBox.X;
511 aBox.Y2 += aWindowBox.Y;
513 Reference<rendering::XBitmap> xBitmap (GetBitmap(eArea,rpBitmaps));
515 if (xBitmap.is())
517 Reference<rendering::XPolyPolygon2D> xClipPolygon (
518 PresenterGeometryHelper::CreatePolygon(
519 PresenterGeometryHelper::Intersection(rUpdateBox,
520 PresenterGeometryHelper::ConvertRectangle(aBox)),
521 mxCanvas->getDevice()));
523 const rendering::ViewState aViewState (
524 geometry::AffineMatrix2D(1,0,0, 0,1,0),
525 xClipPolygon);
527 const geometry::IntegerSize2D aBitmapSize (xBitmap->getSize());
528 rendering::RenderState aRenderState (
529 geometry::AffineMatrix2D(
530 1,0,aBox.X1 + (aBox.X2-aBox.X1 - aBitmapSize.Width)/2,
531 0,1,aBox.Y1 + (aBox.Y2-aBox.Y1 - aBitmapSize.Height)/2),
532 NULL,
533 Sequence<double>(4),
534 rendering::CompositeOperation::SOURCE);
536 mxCanvas->drawBitmap(
537 xBitmap,
538 aViewState,
539 aRenderState);
543 void PresenterScrollBar::NotifyThumbPositionChange()
545 if ( ! mbIsNotificationActive)
547 mbIsNotificationActive = true;
551 maThumbMotionListener(mnThumbPosition);
553 catch (Exception&)
557 mbIsNotificationActive = false;
561 PresenterScrollBar::Area PresenterScrollBar::GetArea (const double nX, const double nY) const
563 const geometry::RealPoint2D aPoint(nX, nY);
565 if (PresenterGeometryHelper::IsInside(GetRectangle(Pager), aPoint))
567 if (PresenterGeometryHelper::IsInside(GetRectangle(Thumb), aPoint))
568 return Thumb;
569 else if (PresenterGeometryHelper::IsInside(GetRectangle(PagerUp), aPoint))
570 return PagerUp;
571 else if (PresenterGeometryHelper::IsInside(GetRectangle(PagerDown), aPoint))
572 return PagerDown;
574 else if (PresenterGeometryHelper::IsInside(GetRectangle(PrevButton), aPoint))
575 return PrevButton;
576 else if (PresenterGeometryHelper::IsInside(GetRectangle(NextButton), aPoint))
577 return NextButton;
579 return None;
582 void PresenterScrollBar::UpdateWidthOrHeight (
583 sal_Int32& rSize,
584 const SharedBitmapDescriptor& rpDescriptor)
586 if (rpDescriptor.get() != NULL)
588 Reference<rendering::XBitmap> xBitmap (rpDescriptor->GetNormalBitmap());
589 if (xBitmap.is())
591 const geometry::IntegerSize2D aBitmapSize (xBitmap->getSize());
592 const sal_Int32 nBitmapSize = (sal_Int32)GetMinor(aBitmapSize.Width, aBitmapSize.Height);
593 if (nBitmapSize > rSize)
594 rSize = nBitmapSize;
599 css::uno::Reference<css::rendering::XBitmap> PresenterScrollBar::GetBitmap (
600 const Area eArea,
601 const SharedBitmapDescriptor& rpBitmaps) const
603 if (rpBitmaps.get() == NULL)
604 return NULL;
605 else
606 return rpBitmaps->GetBitmap(GetBitmapMode(eArea));
609 PresenterBitmapContainer::BitmapDescriptor::Mode PresenterScrollBar::GetBitmapMode (
610 const Area eArea) const
612 if (IsDisabled(eArea))
613 return PresenterBitmapContainer::BitmapDescriptor::Disabled;
614 else if (eArea == meMouseMoveArea)
615 return PresenterBitmapContainer::BitmapDescriptor::MouseOver;
616 else
617 return PresenterBitmapContainer::BitmapDescriptor::Normal;
620 bool PresenterScrollBar::IsDisabled (const Area eArea) const
622 OSL_ASSERT(eArea>=0 && eArea<__AreaCount__);
624 return ! maEnabledState[eArea];
627 //===== PresenterVerticalScrollBar ============================================
629 PresenterVerticalScrollBar::PresenterVerticalScrollBar (
630 const Reference<XComponentContext>& rxComponentContext,
631 const Reference<awt::XWindow>& rxParentWindow,
632 const ::boost::shared_ptr<PresenterPaintManager>& rpPaintManager,
633 const ::boost::function<void(double)>& rThumbMotionListener)
634 : PresenterScrollBar(rxComponentContext, rxParentWindow, rpPaintManager, rThumbMotionListener),
635 mnScrollBarWidth(0)
639 PresenterVerticalScrollBar::~PresenterVerticalScrollBar()
643 double PresenterVerticalScrollBar::GetDragDistance (const sal_Int32 nX, const sal_Int32 nY) const
645 (void)nX;
646 const double nDistance (nY - maDragAnchor.Y);
647 if (nDistance == 0)
648 return 0;
649 else
651 const awt::Rectangle aWindowBox (mxWindow->getPosSize());
652 const double nBarWidth (aWindowBox.Width);
653 const double nPagerHeight (aWindowBox.Height - 2*nBarWidth);
654 const double nDragDistance (mnTotalSize / nPagerHeight * nDistance);
655 if (nDragDistance + mnThumbPosition < 0)
656 return -mnThumbPosition;
657 else if (mnThumbPosition + nDragDistance > mnTotalSize-mnThumbSize)
658 return mnTotalSize-mnThumbSize-mnThumbPosition;
659 else
660 return nDragDistance;
664 void PresenterVerticalScrollBar::UpdateDragAnchor (const double nDragDistance)
666 const awt::Rectangle aWindowBox (mxWindow->getPosSize());
667 const double nBarWidth (aWindowBox.Width);
668 const double nPagerHeight (aWindowBox.Height - 2*nBarWidth);
669 maDragAnchor.Y += nDragDistance * nPagerHeight / mnTotalSize;
672 sal_Int32 PresenterVerticalScrollBar::GetSize() const
674 return mnScrollBarWidth;
677 geometry::RealPoint2D PresenterVerticalScrollBar::GetPoint (
678 const double nMajor, const double nMinor) const
680 return geometry::RealPoint2D(nMinor, nMajor);
683 double PresenterVerticalScrollBar::GetMinor (const double nX, const double nY) const
685 (void)nY;
686 return nX;
689 void PresenterVerticalScrollBar::UpdateBorders()
691 const awt::Rectangle aWindowBox (mxWindow->getPosSize());
692 double nBottom = aWindowBox.Height;
694 if (mpNextButtonDescriptor.get() != NULL)
696 Reference<rendering::XBitmap> xBitmap (mpNextButtonDescriptor->GetNormalBitmap());
697 if (xBitmap.is())
699 geometry::IntegerSize2D aSize (xBitmap->getSize());
700 maBox[NextButton] = geometry::RealRectangle2D(
701 0, nBottom - aSize.Height, aWindowBox.Width, nBottom);
702 nBottom -= aSize.Height + gnScrollBarGap;
705 if (mpPrevButtonDescriptor.get() != NULL)
707 Reference<rendering::XBitmap> xBitmap (mpPrevButtonDescriptor->GetNormalBitmap());
708 if (xBitmap.is())
710 geometry::IntegerSize2D aSize (xBitmap->getSize());
711 maBox[PrevButton] = geometry::RealRectangle2D(
712 0, nBottom - aSize.Height, aWindowBox.Width, nBottom);
713 nBottom -= aSize.Height + gnScrollBarGap;
716 const double nPagerHeight (nBottom);
717 maBox[Pager] = geometry::RealRectangle2D(
718 0,0, aWindowBox.Width, nBottom);
719 if (mnTotalSize < 1)
721 maBox[Thumb] = maBox[Pager];
723 // Set up the enabled/disabled states.
724 maEnabledState[PrevButton] = false;
725 maEnabledState[PagerUp] = false;
726 maEnabledState[NextButton] = false;
727 maEnabledState[PagerDown] = false;
728 maEnabledState[Thumb] = false;
730 else
732 const double nThumbSize = ::std::min(mnThumbSize,mnTotalSize);
733 const double nThumbPosition = ::std::min(::std::max(0.0,mnThumbPosition), mnTotalSize - nThumbSize);
734 maBox[Thumb] = geometry::RealRectangle2D(
735 0, nThumbPosition / mnTotalSize * nPagerHeight,
736 aWindowBox.Width,
737 (nThumbPosition+nThumbSize) / mnTotalSize * nPagerHeight);
739 // Set up the enabled/disabled states.
740 maEnabledState[PrevButton] = nThumbPosition>0;
741 maEnabledState[PagerUp] = nThumbPosition>0;
742 maEnabledState[NextButton] = nThumbPosition+nThumbSize < mnTotalSize;
743 maEnabledState[PagerDown] = nThumbPosition+nThumbSize < mnTotalSize;
744 maEnabledState[Thumb] = nThumbSize < mnTotalSize;
746 maBox[PagerUp] = geometry::RealRectangle2D(
747 maBox[Pager].X1, maBox[Pager].Y1, maBox[Pager].X2, maBox[Thumb].Y1-1);
748 maBox[PagerDown] = geometry::RealRectangle2D(
749 maBox[Pager].X1, maBox[Thumb].Y2+1, maBox[Pager].X2, maBox[Pager].Y2);
750 maBox[Total] = PresenterGeometryHelper::Union(
751 PresenterGeometryHelper::Union(maBox[PrevButton], maBox[NextButton]),
752 maBox[Pager]);
755 void PresenterVerticalScrollBar::UpdateBitmaps()
757 if (mpBitmaps.get() != NULL)
759 mpPrevButtonDescriptor = mpBitmaps->GetBitmap("Up");
760 mpNextButtonDescriptor = mpBitmaps->GetBitmap("Down");
761 mpPagerStartDescriptor = mpBitmaps->GetBitmap("PagerTop");
762 mpPagerCenterDescriptor = mpBitmaps->GetBitmap("PagerVertical");
763 mpPagerEndDescriptor = mpBitmaps->GetBitmap("PagerBottom");
764 mpThumbStartDescriptor = mpBitmaps->GetBitmap("ThumbTop");
765 mpThumbCenterDescriptor = mpBitmaps->GetBitmap("ThumbVertical");
766 mpThumbEndDescriptor = mpBitmaps->GetBitmap("ThumbBottom");
768 mnScrollBarWidth = 0;
769 UpdateWidthOrHeight(mnScrollBarWidth, mpPrevButtonDescriptor);
770 UpdateWidthOrHeight(mnScrollBarWidth, mpNextButtonDescriptor);
771 UpdateWidthOrHeight(mnScrollBarWidth, mpPagerStartDescriptor);
772 UpdateWidthOrHeight(mnScrollBarWidth, mpPagerCenterDescriptor);
773 UpdateWidthOrHeight(mnScrollBarWidth, mpPagerEndDescriptor);
774 UpdateWidthOrHeight(mnScrollBarWidth, mpThumbStartDescriptor);
775 UpdateWidthOrHeight(mnScrollBarWidth, mpThumbCenterDescriptor);
776 UpdateWidthOrHeight(mnScrollBarWidth, mpThumbEndDescriptor);
777 if (mnScrollBarWidth == 0)
778 mnScrollBarWidth = 20;
782 void PresenterVerticalScrollBar::PaintComposite(
783 const css::awt::Rectangle& rUpdateBox,
784 const Area eArea,
785 const SharedBitmapDescriptor& rpStartBitmaps,
786 const SharedBitmapDescriptor& rpCenterBitmaps,
787 const SharedBitmapDescriptor& rpEndBitmaps)
789 const awt::Rectangle aWindowBox (mxWindow->getPosSize());
790 geometry::RealRectangle2D aBox (GetRectangle(eArea));
791 aBox.X1 += aWindowBox.X;
792 aBox.Y1 += aWindowBox.Y;
793 aBox.X2 += aWindowBox.X;
794 aBox.Y2 += aWindowBox.Y;
796 // Get bitmaps and sizes.
798 PresenterUIPainter::PaintVerticalBitmapComposite(
799 mxCanvas,
800 rUpdateBox,
801 (eArea == Thumb
802 ? PresenterGeometryHelper::ConvertRectangleWithConstantSize(aBox)
803 : PresenterGeometryHelper::ConvertRectangle(aBox)),
804 GetBitmap(eArea, rpStartBitmaps),
805 GetBitmap(eArea, rpCenterBitmaps),
806 GetBitmap(eArea, rpEndBitmaps));
809 //===== PresenterScrollBar::MousePressRepeater ================================
811 PresenterScrollBar::MousePressRepeater::MousePressRepeater (
812 const ::rtl::Reference<PresenterScrollBar>& rpScrollBar)
813 : mnMousePressRepeaterTaskId(PresenterTimer::NotAValidTaskId),
814 mpScrollBar(rpScrollBar),
815 meMouseArea(PresenterScrollBar::None)
819 void PresenterScrollBar::MousePressRepeater::Dispose()
821 Stop();
822 mpScrollBar = NULL;
825 void PresenterScrollBar::MousePressRepeater::Start (const PresenterScrollBar::Area& reArea)
827 meMouseArea = reArea;
829 if (mnMousePressRepeaterTaskId == PresenterTimer::NotAValidTaskId)
831 // Execute key press operation at least this one time.
832 Execute();
834 // Schedule repeated executions.
835 mnMousePressRepeaterTaskId = PresenterTimer::ScheduleRepeatedTask (
836 ::boost::bind(&PresenterScrollBar::MousePressRepeater::Callback, shared_from_this(), _1),
837 500000000,
838 250000000);
840 else
842 // There is already an active repeating task.
846 void PresenterScrollBar::MousePressRepeater::Stop()
848 if (mnMousePressRepeaterTaskId != PresenterTimer::NotAValidTaskId)
850 const sal_Int32 nTaskId (mnMousePressRepeaterTaskId);
851 mnMousePressRepeaterTaskId = PresenterTimer::NotAValidTaskId;
852 PresenterTimer::CancelTask(nTaskId);
856 void PresenterScrollBar::MousePressRepeater::SetMouseArea(const PresenterScrollBar::Area& reArea)
858 if (meMouseArea != reArea)
860 if (mnMousePressRepeaterTaskId != PresenterTimer::NotAValidTaskId)
862 Stop();
867 void PresenterScrollBar::MousePressRepeater::Callback (const TimeValue& rCurrentTime)
869 (void)rCurrentTime;
871 if (mpScrollBar.get() == NULL)
873 Stop();
874 return;
877 Execute();
880 void PresenterScrollBar::MousePressRepeater::Execute()
882 const double nThumbPosition (mpScrollBar->GetThumbPosition());
883 switch (meMouseArea)
885 case PrevButton:
886 mpScrollBar->SetThumbPosition(nThumbPosition - mpScrollBar->GetLineHeight(), true);
887 break;
889 case NextButton:
890 mpScrollBar->SetThumbPosition(nThumbPosition + mpScrollBar->GetLineHeight(), true);
891 break;
893 case PagerUp:
894 mpScrollBar->SetThumbPosition(nThumbPosition - mpScrollBar->GetThumbSize()*0.8, true);
895 break;
897 case PagerDown:
898 mpScrollBar->SetThumbPosition(nThumbPosition + mpScrollBar->GetThumbSize()*0.8, true);
899 break;
901 default:
902 break;
906 } } // end of namespace ::sdext::presenter
908 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */