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/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>
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
>
52 MousePressRepeater (const ::rtl::Reference
<PresenterScrollBar
>& rpScrollBar
);
54 void Start (const PresenterScrollBar::Area
& reArea
);
56 void SetMouseArea (const PresenterScrollBar::Area
& reArea
);
59 void Callback (const TimeValue
& rCurrentTime
);
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
),
82 mpPaintManager(rpPaintManager
),
88 maThumbMotionListener(rThumbMotionListener
),
89 meButtonDownArea(None
),
90 meMouseMoveArea(None
),
91 mbIsNotificationActive(false),
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"),
117 if (mxPresenterHelper
.is())
118 mxWindow
= mxPresenterHelper
->createWindow(rxParentWindow
,
124 // Make the background transparent. The slide show paints its own background.
125 Reference
<awt::XWindowPeer
> xPeer (mxWindow
, UNO_QUERY_THROW
);
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();
152 mxWindow
->removeWindowListener(this);
153 mxWindow
->removePaintListener(this);
154 mxWindow
->removeMouseListener(this);
155 mxWindow
->removeMouseMotionListener(this);
157 Reference
<lang::XComponent
> xComponent (mxWindow
, UNO_QUERY
);
160 xComponent
->dispose();
166 void PresenterScrollBar::SetVisible (const bool bIsVisible
)
169 mxWindow
->setVisible(bIsVisible
);
172 void PresenterScrollBar::SetPosSize (const css::geometry::RealRectangle2D
& rBox
)
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
);
186 void PresenterScrollBar::SetThumbPosition (
188 const bool bAsynchronousUpdate
)
190 SetThumbPosition(nPosition
, bAsynchronousUpdate
, true, true);
193 void PresenterScrollBar::SetThumbPosition (
195 const bool bAsynchronousUpdate
,
196 const bool bValidate
,
200 nPosition
= ValidateThumbPosition(nPosition
);
202 if (nPosition
!= mnThumbPosition
&& ! mbIsNotificationActive
)
204 mnThumbPosition
= nPosition
;
207 Repaint(GetRectangle(Total
), bAsynchronousUpdate
);
209 NotifyThumbPositionChange();
214 void PresenterScrollBar::SetTotalSize (const double nTotalSize
)
216 if (mnTotalSize
!= nTotalSize
)
218 mnTotalSize
= nTotalSize
+ 1;
220 Repaint(GetRectangle(Total
), false);
224 void PresenterScrollBar::SetThumbSize (const double nThumbSize
)
226 OSL_ASSERT(nThumbSize
>=0);
227 if (mnThumbSize
!= nThumbSize
)
229 mnThumbSize
= nThumbSize
;
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
)
249 if (mpBitmaps
.get()==NULL
)
251 if (mpSharedBitmaps
.expired())
255 mpBitmaps
.reset(new PresenterBitmapContainer(
256 OUString("PresenterScreenSettings/ScrollBar/Bitmaps"),
257 ::boost::shared_ptr
<PresenterBitmapContainer
>(),
260 mpSharedBitmaps
= mpBitmaps
;
268 mpBitmaps
= ::boost::shared_ptr
<PresenterBitmapContainer
>(mpSharedBitmaps
);
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
;
297 void PresenterScrollBar::Paint (
298 const awt::Rectangle
& rUpdateBox
,
301 if ( ! mxCanvas
.is() || ! mxWindow
.is())
303 OSL_ASSERT(mxCanvas
.is());
304 OSL_ASSERT(mxWindow
.is());
310 if (PresenterGeometryHelper::AreRectanglesDisjoint (rUpdateBox
, mxWindow
->getPosSize()))
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
)
337 void SAL_CALL
PresenterScrollBar::windowMoved (const css::awt::WindowEvent
& rEvent
)
338 throw (css::uno::RuntimeException
, std::exception
)
343 void SAL_CALL
PresenterScrollBar::windowShown (const css::lang::EventObject
& rEvent
)
344 throw (css::uno::RuntimeException
, std::exception
)
349 void SAL_CALL
PresenterScrollBar::windowHidden (const css::lang::EventObject
& rEvent
)
350 throw (css::uno::RuntimeException
, std::exception
)
355 //----- XPaintListener --------------------------------------------------------
357 void SAL_CALL
PresenterScrollBar::windowPaint (const css::awt::PaintEvent
& rEvent
)
358 throw (css::uno::RuntimeException
, std::exception
)
362 awt::Rectangle
aRepaintBox (rEvent
.UpdateRect
);
363 const awt::Rectangle
aWindowBox (mxWindow
->getPosSize());
364 aRepaintBox
.X
+= aWindowBox
.X
;
365 aRepaintBox
.Y
+= aWindowBox
.Y
;
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
)
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
)
403 void SAL_CALL
PresenterScrollBar::mouseExited (const css::awt::MouseEvent
& rEvent
)
404 throw(css::uno::RuntimeException
, std::exception
)
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
)
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
)
467 geometry::RealRectangle2D
PresenterScrollBar::GetRectangle (const Area eArea
) const
469 OSL_ASSERT(eArea
>=0 && eArea
<__AreaCount__
);
474 void PresenterScrollBar::Repaint (
475 const geometry::RealRectangle2D
& rBox
,
476 const bool bAsynchronousUpdate
)
478 if (mpPaintManager
.get() != NULL
)
479 mpPaintManager
->Invalidate(
481 PresenterGeometryHelper::ConvertRectangle(rBox
),
482 bAsynchronousUpdate
);
485 void PresenterScrollBar::PaintBackground(
486 const css::awt::Rectangle
& rUpdateBox
)
488 if (mpBackgroundBitmap
.get() == NULL
)
491 const awt::Rectangle
aWindowBox (mxWindow
->getPosSize());
492 mpCanvasHelper
->Paint(
500 void PresenterScrollBar::PaintBitmap(
501 const css::awt::Rectangle
& rUpdateBox
,
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
));
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),
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),
534 rendering::CompositeOperation::SOURCE
);
536 mxCanvas
->drawBitmap(
543 void PresenterScrollBar::NotifyThumbPositionChange()
545 if ( ! mbIsNotificationActive
)
547 mbIsNotificationActive
= true;
551 maThumbMotionListener(mnThumbPosition
);
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
))
569 else if (PresenterGeometryHelper::IsInside(GetRectangle(PagerUp
), aPoint
))
571 else if (PresenterGeometryHelper::IsInside(GetRectangle(PagerDown
), aPoint
))
574 else if (PresenterGeometryHelper::IsInside(GetRectangle(PrevButton
), aPoint
))
576 else if (PresenterGeometryHelper::IsInside(GetRectangle(NextButton
), aPoint
))
582 void PresenterScrollBar::UpdateWidthOrHeight (
584 const SharedBitmapDescriptor
& rpDescriptor
)
586 if (rpDescriptor
.get() != NULL
)
588 Reference
<rendering::XBitmap
> xBitmap (rpDescriptor
->GetNormalBitmap());
591 const geometry::IntegerSize2D
aBitmapSize (xBitmap
->getSize());
592 const sal_Int32 nBitmapSize
= (sal_Int32
)GetMinor(aBitmapSize
.Width
, aBitmapSize
.Height
);
593 if (nBitmapSize
> rSize
)
599 css::uno::Reference
<css::rendering::XBitmap
> PresenterScrollBar::GetBitmap (
601 const SharedBitmapDescriptor
& rpBitmaps
) const
603 if (rpBitmaps
.get() == NULL
)
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
;
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
),
639 PresenterVerticalScrollBar::~PresenterVerticalScrollBar()
643 double PresenterVerticalScrollBar::GetDragDistance (const sal_Int32 nX
, const sal_Int32 nY
) const
646 const double nDistance (nY
- maDragAnchor
.Y
);
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
;
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
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());
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());
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
);
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;
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
,
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
]),
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
,
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(
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()
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.
834 // Schedule repeated executions.
835 mnMousePressRepeaterTaskId
= PresenterTimer::ScheduleRepeatedTask (
836 ::boost::bind(&PresenterScrollBar::MousePressRepeater::Callback
, shared_from_this(), _1
),
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
)
867 void PresenterScrollBar::MousePressRepeater::Callback (const TimeValue
& rCurrentTime
)
871 if (mpScrollBar
.get() == NULL
)
880 void PresenterScrollBar::MousePressRepeater::Execute()
882 const double nThumbPosition (mpScrollBar
->GetThumbPosition());
886 mpScrollBar
->SetThumbPosition(nThumbPosition
- mpScrollBar
->GetLineHeight(), true);
890 mpScrollBar
->SetThumbPosition(nThumbPosition
+ mpScrollBar
->GetLineHeight(), true);
894 mpScrollBar
->SetThumbPosition(nThumbPosition
- mpScrollBar
->GetThumbSize()*0.8, true);
898 mpScrollBar
->SetThumbPosition(nThumbPosition
+ mpScrollBar
->GetThumbSize()*0.8, true);
906 } } // end of namespace ::sdext::presenter
908 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */