1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PresenterScrollBar.cxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sdext.hxx"
35 #include "PresenterScrollBar.hxx"
36 #include "PresenterBitmapContainer.hxx"
37 #include "PresenterCanvasHelper.hxx"
38 #include "PresenterComponent.hxx"
39 #include "PresenterGeometryHelper.hxx"
40 #include "PresenterPaintManager.hxx"
41 #include "PresenterTimer.hxx"
42 #include "PresenterUIPainter.hxx"
43 #include <com/sun/star/awt/PosSize.hpp>
44 #include <com/sun/star/awt/WindowAttribute.hpp>
45 #include <com/sun/star/awt/XWindowPeer.hpp>
46 #include <com/sun/star/awt/XToolkit.hpp>
47 #include <com/sun/star/rendering/CompositeOperation.hpp>
48 #include <com/sun/star/rendering/TexturingMode.hpp>
49 #include <com/sun/star/rendering/XPolyPolygon2D.hpp>
50 #include <boost/bind.hpp>
51 #include <boost/enable_shared_from_this.hpp>
52 #include <boost/weak_ptr.hpp>
55 using namespace ::com::sun::star
;
56 using namespace ::com::sun::star::uno
;
57 using ::rtl::OUString
;
59 #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString)))
61 const static double gnScrollBarGap (10);
63 namespace sdext
{ namespace presenter
{
65 //===== PresenterScrollBar::MousePressRepeater ================================
67 class PresenterScrollBar::MousePressRepeater
68 : public ::boost::enable_shared_from_this
<MousePressRepeater
>
71 MousePressRepeater (const ::rtl::Reference
<PresenterScrollBar
>& rpScrollBar
);
73 void Start (const PresenterScrollBar::Area
& reArea
);
75 void SetMouseArea (const PresenterScrollBar::Area
& reArea
);
78 void Callback (const TimeValue
& rCurrentTime
);
81 sal_Int32 mnMousePressRepeaterTaskId
;
82 ::rtl::Reference
<PresenterScrollBar
> mpScrollBar
;
83 PresenterScrollBar::Area meMouseArea
;
89 //===== PresenterScrollBar ====================================================
91 boost::weak_ptr
<PresenterBitmapContainer
> PresenterScrollBar::mpSharedBitmaps
;
93 PresenterScrollBar::PresenterScrollBar (
94 const Reference
<XComponentContext
>& rxComponentContext
,
95 const Reference
<awt::XWindow
>& rxParentWindow
,
96 const ::boost::shared_ptr
<PresenterPaintManager
>& rpPaintManager
,
97 const ::boost::function
<void(double)>& rThumbMotionListener
)
98 : PresenterScrollBarInterfaceBase(m_aMutex
),
99 mxComponentContext(rxComponentContext
),
100 mxParentWindow(rxParentWindow
),
104 mpPaintManager(rpPaintManager
),
110 maThumbMotionListener(rThumbMotionListener
),
111 meButtonDownArea(None
),
112 meMouseMoveArea(None
),
113 mbIsNotificationActive(false),
115 mpPrevButtonDescriptor(),
116 mpNextButtonDescriptor(),
117 mpPagerStartDescriptor(),
118 mpPagerCenterDescriptor(),
119 mpPagerEndDescriptor(),
120 mpThumbStartDescriptor(),
121 mpThumbCenterDescriptor(),
122 mpThumbEndDescriptor(),
123 mpMousePressRepeater(new MousePressRepeater(this)),
124 mpBackgroundBitmap(),
125 mpCanvasHelper(new PresenterCanvasHelper())
129 Reference
<lang::XMultiComponentFactory
> xFactory (rxComponentContext
->getServiceManager());
130 if ( ! xFactory
.is())
131 throw RuntimeException();
133 mxPresenterHelper
= Reference
<drawing::XPresenterHelper
>(
134 xFactory
->createInstanceWithContext(
135 OUString::createFromAscii("com.sun.star.comp.Draw.PresenterHelper"),
139 if (mxPresenterHelper
.is())
140 mxWindow
= mxPresenterHelper
->createWindow(rxParentWindow
,
146 // Make the background transparent. The slide show paints its own background.
147 Reference
<awt::XWindowPeer
> xPeer (mxWindow
, UNO_QUERY_THROW
);
150 xPeer
->setBackground(0xff000000);
153 mxWindow
->setVisible(sal_True
);
154 mxWindow
->addWindowListener(this);
155 mxWindow
->addPaintListener(this);
156 mxWindow
->addMouseListener(this);
157 mxWindow
->addMouseMotionListener(this);
159 catch (RuntimeException
&)
167 PresenterScrollBar::~PresenterScrollBar (void)
174 void SAL_CALL
PresenterScrollBar::disposing (void)
176 mpMousePressRepeater
->Dispose();
180 mxWindow
->removeWindowListener(this);
181 mxWindow
->removePaintListener(this);
182 mxWindow
->removeMouseListener(this);
183 mxWindow
->removeMouseMotionListener(this);
185 Reference
<lang::XComponent
> xComponent (mxWindow
, UNO_QUERY
);
188 xComponent
->dispose();
197 void PresenterScrollBar::SetVisible (const bool bIsVisible
)
200 mxWindow
->setVisible(bIsVisible
);
206 void PresenterScrollBar::SetPosSize (const css::geometry::RealRectangle2D
& rBox
)
210 mxWindow
->setPosSize(
211 sal_Int32(floor(rBox
.X1
)),
212 sal_Int32(ceil(rBox
.Y1
)),
213 sal_Int32(ceil(rBox
.X2
-rBox
.X1
)),
214 sal_Int32(floor(rBox
.Y2
-rBox
.Y1
)),
215 awt::PosSize::POSSIZE
);
223 void PresenterScrollBar::SetThumbPosition (
225 const bool bAsynchronousUpdate
)
227 SetThumbPosition(nPosition
, bAsynchronousUpdate
, true, true);
233 void PresenterScrollBar::SetThumbPosition (
235 const bool bAsynchronousUpdate
,
236 const bool bValidate
,
240 nPosition
= ValidateThumbPosition(nPosition
);
242 if (nPosition
!= mnThumbPosition
&& ! mbIsNotificationActive
)
244 mnThumbPosition
= nPosition
;
247 Repaint(GetRectangle(Total
), bAsynchronousUpdate
);
249 NotifyThumbPositionChange();
256 double PresenterScrollBar::GetThumbPosition (void) const
258 return mnThumbPosition
;
264 void PresenterScrollBar::SetTotalSize (const double nTotalSize
)
266 if (mnTotalSize
!= nTotalSize
)
268 mnTotalSize
= nTotalSize
+ 1;
270 Repaint(GetRectangle(Total
), false);
277 double PresenterScrollBar::GetTotalSize (void) const
285 void PresenterScrollBar::SetThumbSize (const double nThumbSize
)
287 OSL_ASSERT(nThumbSize
>=0);
288 if (mnThumbSize
!= nThumbSize
)
290 mnThumbSize
= nThumbSize
;
292 Repaint(GetRectangle(Total
), false);
299 double PresenterScrollBar::GetThumbSize (void) const
307 void PresenterScrollBar::SetLineHeight (const double nLineHeight
)
309 mnLineHeight
= nLineHeight
;
315 double PresenterScrollBar::GetLineHeight (void) const
323 void PresenterScrollBar::SetCanvas (const Reference
<css::rendering::XCanvas
>& rxCanvas
)
325 if (mxCanvas
!= rxCanvas
)
330 if (mpBitmaps
.get()==NULL
)
332 if (mpSharedBitmaps
.expired())
336 mpBitmaps
.reset(new PresenterBitmapContainer(
337 OUString::createFromAscii("PresenterScreenSettings/ScrollBar/Bitmaps"),
338 ::boost::shared_ptr
<PresenterBitmapContainer
>(),
341 PresenterComponent::GetBasePath(mxComponentContext
)));
342 mpSharedBitmaps
= mpBitmaps
;
350 mpBitmaps
= ::boost::shared_ptr
<PresenterBitmapContainer
>(mpSharedBitmaps
);
355 Repaint(GetRectangle(Total
), false);
363 void PresenterScrollBar::SetBackground (const SharedBitmapDescriptor
& rpBackgroundBitmap
)
365 mpBackgroundBitmap
= rpBackgroundBitmap
;
370 void PresenterScrollBar::CheckValues (void)
372 mnThumbPosition
= ValidateThumbPosition(mnThumbPosition
);
378 double PresenterScrollBar::ValidateThumbPosition (double nPosition
)
380 if (nPosition
+ mnThumbSize
> mnTotalSize
)
381 nPosition
= mnTotalSize
- mnThumbSize
;
390 void PresenterScrollBar::Paint (
391 const awt::Rectangle
& rUpdateBox
,
394 if ( ! mxCanvas
.is() || ! mxWindow
.is())
396 OSL_ASSERT(mxCanvas
.is());
397 OSL_ASSERT(mxWindow
.is());
403 if (PresenterGeometryHelper::AreRectanglesDisjoint (rUpdateBox
, mxWindow
->getPosSize()))
407 PaintBackground(rUpdateBox
);
408 PaintComposite(rUpdateBox
, PagerUp
,
409 mpPagerStartDescriptor
, mpPagerCenterDescriptor
, SharedBitmapDescriptor());
410 PaintComposite(rUpdateBox
, PagerDown
,
411 SharedBitmapDescriptor(), mpPagerCenterDescriptor
, mpPagerEndDescriptor
);
412 PaintComposite(rUpdateBox
, Thumb
,
413 mpThumbStartDescriptor
, mpThumbCenterDescriptor
, mpThumbEndDescriptor
);
414 PaintBitmap(rUpdateBox
, PrevButton
, mpPrevButtonDescriptor
);
415 PaintBitmap(rUpdateBox
, NextButton
, mpNextButtonDescriptor
);
417 Reference
<rendering::XSpriteCanvas
> xSpriteCanvas (mxCanvas
, UNO_QUERY
);
418 if (xSpriteCanvas
.is())
419 xSpriteCanvas
->updateScreen(sal_False
);
427 //----- XWindowListener -------------------------------------------------------
429 void SAL_CALL
PresenterScrollBar::windowResized (const css::awt::WindowEvent
& rEvent
)
430 throw (css::uno::RuntimeException
)
439 void SAL_CALL
PresenterScrollBar::windowMoved (const css::awt::WindowEvent
& rEvent
)
440 throw (css::uno::RuntimeException
)
448 void SAL_CALL
PresenterScrollBar::windowShown (const css::lang::EventObject
& rEvent
)
449 throw (css::uno::RuntimeException
)
457 void SAL_CALL
PresenterScrollBar::windowHidden (const css::lang::EventObject
& rEvent
)
458 throw (css::uno::RuntimeException
)
466 //----- XPaintListener --------------------------------------------------------
468 void SAL_CALL
PresenterScrollBar::windowPaint (const css::awt::PaintEvent
& rEvent
)
469 throw (css::uno::RuntimeException
)
473 awt::Rectangle
aRepaintBox (rEvent
.UpdateRect
);
474 const awt::Rectangle
aWindowBox (mxWindow
->getPosSize());
475 aRepaintBox
.X
+= aWindowBox
.X
;
476 aRepaintBox
.Y
+= aWindowBox
.Y
;
479 Reference
<rendering::XSpriteCanvas
> xSpriteCanvas (mxCanvas
, UNO_QUERY
);
480 if (xSpriteCanvas
.is())
481 xSpriteCanvas
->updateScreen(sal_False
);
488 //----- XMouseListener --------------------------------------------------------
490 void SAL_CALL
PresenterScrollBar::mousePressed (const css::awt::MouseEvent
& rEvent
)
491 throw(css::uno::RuntimeException
)
493 maDragAnchor
.X
= rEvent
.X
;
494 maDragAnchor
.Y
= rEvent
.Y
;
495 meButtonDownArea
= GetArea(rEvent
.X
, rEvent
.Y
);
497 mpMousePressRepeater
->Start(meButtonDownArea
);
503 void SAL_CALL
PresenterScrollBar::mouseReleased (const css::awt::MouseEvent
& rEvent
)
504 throw(css::uno::RuntimeException
)
508 mpMousePressRepeater
->Stop();
510 if (mxPresenterHelper
.is())
511 mxPresenterHelper
->releaseMouse(mxWindow
);
517 void SAL_CALL
PresenterScrollBar::mouseEntered (const css::awt::MouseEvent
& rEvent
)
518 throw(css::uno::RuntimeException
)
526 void SAL_CALL
PresenterScrollBar::mouseExited (const css::awt::MouseEvent
& rEvent
)
527 throw(css::uno::RuntimeException
)
530 if (meMouseMoveArea
!= None
)
532 const Area
eOldMouseMoveArea (meMouseMoveArea
);
533 meMouseMoveArea
= None
;
534 Repaint(GetRectangle(eOldMouseMoveArea
), true);
536 meButtonDownArea
= None
;
537 meMouseMoveArea
= None
;
539 mpMousePressRepeater
->Stop();
546 //----- XMouseMotionListener --------------------------------------------------
548 void SAL_CALL
PresenterScrollBar::mouseMoved (const css::awt::MouseEvent
& rEvent
)
549 throw (css::uno::RuntimeException
)
551 const Area
eArea (GetArea(rEvent
.X
, rEvent
.Y
));
552 if (eArea
!= meMouseMoveArea
)
554 const Area
eOldMouseMoveArea (meMouseMoveArea
);
555 meMouseMoveArea
= eArea
;
556 if (eOldMouseMoveArea
!= None
)
557 Repaint(GetRectangle(eOldMouseMoveArea
), meMouseMoveArea
==None
);
558 if (meMouseMoveArea
!= None
)
559 Repaint(GetRectangle(meMouseMoveArea
), true);
561 mpMousePressRepeater
->SetMouseArea(eArea
);
567 void SAL_CALL
PresenterScrollBar::mouseDragged (const css::awt::MouseEvent
& rEvent
)
568 throw (css::uno::RuntimeException
)
570 if (meButtonDownArea
!= Thumb
)
573 mpMousePressRepeater
->Stop();
575 if (mxPresenterHelper
.is())
576 mxPresenterHelper
->captureMouse(mxWindow
);
578 const double nDragDistance (GetDragDistance(rEvent
.X
,rEvent
.Y
));
579 UpdateDragAnchor(nDragDistance
);
580 if (nDragDistance
!= 0)
582 SetThumbPosition(mnThumbPosition
+ nDragDistance
, false, true, true);
589 //----- lang::XEventListener --------------------------------------------------
591 void SAL_CALL
PresenterScrollBar::disposing (const css::lang::EventObject
& rEvent
)
592 throw (css::uno::RuntimeException
)
594 if (rEvent
.Source
== mxWindow
)
601 //-----------------------------------------------------------------------------
603 geometry::RealRectangle2D
PresenterScrollBar::GetRectangle (const Area eArea
) const
605 OSL_ASSERT(eArea
>=0 && eArea
<__AreaCount__
);
613 void PresenterScrollBar::Repaint (
614 const geometry::RealRectangle2D aBox
,
615 const bool bAsynchronousUpdate
)
617 if (mpPaintManager
.get() != NULL
)
618 mpPaintManager
->Invalidate(
620 PresenterGeometryHelper::ConvertRectangle(aBox
),
621 bAsynchronousUpdate
);
627 void PresenterScrollBar::PaintBackground(
628 const css::awt::Rectangle
& rUpdateBox
)
630 if (mpBackgroundBitmap
.get() == NULL
)
633 const awt::Rectangle
aWindowBox (mxWindow
->getPosSize());
634 mpCanvasHelper
->Paint(
645 void PresenterScrollBar::PaintBitmap(
646 const css::awt::Rectangle
& rUpdateBox
,
648 const SharedBitmapDescriptor
& rpBitmaps
)
650 const geometry::RealRectangle2D
aLocalBox (GetRectangle(eArea
));
651 const awt::Rectangle
aWindowBox (mxWindow
->getPosSize());
652 geometry::RealRectangle2D
aBox (aLocalBox
);
653 aBox
.X1
+= aWindowBox
.X
;
654 aBox
.Y1
+= aWindowBox
.Y
;
655 aBox
.X2
+= aWindowBox
.X
;
656 aBox
.Y2
+= aWindowBox
.Y
;
658 Reference
<rendering::XBitmap
> xBitmap (GetBitmap(eArea
,rpBitmaps
));
662 Reference
<rendering::XPolyPolygon2D
> xClipPolygon (
663 PresenterGeometryHelper::CreatePolygon(
664 PresenterGeometryHelper::Intersection(rUpdateBox
,
665 PresenterGeometryHelper::ConvertRectangle(aBox
)),
666 mxCanvas
->getDevice()));
668 const rendering::ViewState
aViewState (
669 geometry::AffineMatrix2D(1,0,0, 0,1,0),
672 const geometry::IntegerSize2D
aBitmapSize (xBitmap
->getSize());
673 rendering::RenderState
aRenderState (
674 geometry::AffineMatrix2D(
675 1,0,aBox
.X1
+ (aBox
.X2
-aBox
.X1
- aBitmapSize
.Width
)/2,
676 0,1,aBox
.Y1
+ (aBox
.Y2
-aBox
.Y1
- aBitmapSize
.Height
)/2),
679 rendering::CompositeOperation::SOURCE
);
681 mxCanvas
->drawBitmap(
691 void PresenterScrollBar::NotifyThumbPositionChange (void)
693 if ( ! mbIsNotificationActive
)
695 mbIsNotificationActive
= true;
699 maThumbMotionListener(mnThumbPosition
);
705 mbIsNotificationActive
= false;
712 PresenterScrollBar::Area
PresenterScrollBar::GetArea (const double nX
, const double nY
) const
714 const geometry::RealPoint2D
aPoint(nX
, nY
);
716 if (PresenterGeometryHelper::IsInside(GetRectangle(Pager
), aPoint
))
718 if (PresenterGeometryHelper::IsInside(GetRectangle(Thumb
), aPoint
))
720 else if (PresenterGeometryHelper::IsInside(GetRectangle(PagerUp
), aPoint
))
722 else if (PresenterGeometryHelper::IsInside(GetRectangle(PagerDown
), aPoint
))
725 else if (PresenterGeometryHelper::IsInside(GetRectangle(PrevButton
), aPoint
))
727 else if (PresenterGeometryHelper::IsInside(GetRectangle(NextButton
), aPoint
))
736 void PresenterScrollBar::UpdateWidthOrHeight (
738 const SharedBitmapDescriptor
& rpDescriptor
)
740 if (rpDescriptor
.get() != NULL
)
742 Reference
<rendering::XBitmap
> xBitmap (rpDescriptor
->GetNormalBitmap());
745 const geometry::IntegerSize2D
aBitmapSize (xBitmap
->getSize());
746 const sal_Int32 nBitmapSize
= (sal_Int32
)GetMinor(aBitmapSize
.Width
, aBitmapSize
.Height
);
747 if (nBitmapSize
> rSize
)
756 css::uno::Reference
<css::rendering::XBitmap
> PresenterScrollBar::GetBitmap (
758 const SharedBitmapDescriptor
& rpBitmaps
) const
760 if (rpBitmaps
.get() == NULL
)
763 return rpBitmaps
->GetBitmap(GetBitmapMode(eArea
));
769 PresenterBitmapContainer::BitmapDescriptor::Mode
PresenterScrollBar::GetBitmapMode (
770 const Area eArea
) const
772 if (IsDisabled(eArea
))
773 return PresenterBitmapContainer::BitmapDescriptor::Disabled
;
774 else if (eArea
== meMouseMoveArea
)
775 return PresenterBitmapContainer::BitmapDescriptor::MouseOver
;
777 return PresenterBitmapContainer::BitmapDescriptor::Normal
;
783 bool PresenterScrollBar::IsDisabled (const Area eArea
) const
785 OSL_ASSERT(eArea
>=0 && eArea
<__AreaCount__
);
787 return ! maEnabledState
[eArea
];
793 //===== PresenterVerticalScrollBar ============================================
795 PresenterVerticalScrollBar::PresenterVerticalScrollBar (
796 const Reference
<XComponentContext
>& rxComponentContext
,
797 const Reference
<awt::XWindow
>& rxParentWindow
,
798 const ::boost::shared_ptr
<PresenterPaintManager
>& rpPaintManager
,
799 const ::boost::function
<void(double)>& rThumbMotionListener
)
800 : PresenterScrollBar(rxComponentContext
, rxParentWindow
, rpPaintManager
, rThumbMotionListener
),
808 PresenterVerticalScrollBar::~PresenterVerticalScrollBar (void)
815 double PresenterVerticalScrollBar::GetDragDistance (const sal_Int32 nX
, const sal_Int32 nY
) const
818 const double nDistance (nY
- maDragAnchor
.Y
);
823 const awt::Rectangle
aWindowBox (mxWindow
->getPosSize());
824 const double nBarWidth (aWindowBox
.Width
);
825 const double nPagerHeight (aWindowBox
.Height
- 2*nBarWidth
);
826 const double nDragDistance (mnTotalSize
/ nPagerHeight
* nDistance
);
827 if (nDragDistance
+ mnThumbPosition
< 0)
828 return -mnThumbPosition
;
829 else if (mnThumbPosition
+ nDragDistance
> mnTotalSize
-mnThumbSize
)
830 return mnTotalSize
-mnThumbSize
-mnThumbPosition
;
832 return nDragDistance
;
839 void PresenterVerticalScrollBar::UpdateDragAnchor (const double nDragDistance
)
841 const awt::Rectangle
aWindowBox (mxWindow
->getPosSize());
842 const double nBarWidth (aWindowBox
.Width
);
843 const double nPagerHeight (aWindowBox
.Height
- 2*nBarWidth
);
844 maDragAnchor
.Y
+= nDragDistance
* nPagerHeight
/ mnTotalSize
;
850 sal_Int32
PresenterVerticalScrollBar::GetSize (void) const
852 return mnScrollBarWidth
;
858 geometry::RealPoint2D
PresenterVerticalScrollBar::GetPoint (
859 const double nMajor
, const double nMinor
) const
861 return geometry::RealPoint2D(nMinor
, nMajor
);
867 double PresenterVerticalScrollBar::GetMajor (const double nX
, const double nY
) const
876 double PresenterVerticalScrollBar::GetMinor (const double nX
, const double nY
) const
885 void PresenterVerticalScrollBar::UpdateBorders (void)
887 const awt::Rectangle
aWindowBox (mxWindow
->getPosSize());
888 double nBottom
= aWindowBox
.Height
;
890 if (mpNextButtonDescriptor
.get() != NULL
)
892 Reference
<rendering::XBitmap
> xBitmap (mpNextButtonDescriptor
->GetNormalBitmap());
895 geometry::IntegerSize2D
aSize (xBitmap
->getSize());
896 maBox
[NextButton
] = geometry::RealRectangle2D(
897 0, nBottom
- aSize
.Height
, aWindowBox
.Width
, nBottom
);
898 nBottom
-= aSize
.Height
+ gnScrollBarGap
;
901 if (mpPrevButtonDescriptor
.get() != NULL
)
903 Reference
<rendering::XBitmap
> xBitmap (mpPrevButtonDescriptor
->GetNormalBitmap());
906 geometry::IntegerSize2D
aSize (xBitmap
->getSize());
907 maBox
[PrevButton
] = geometry::RealRectangle2D(
908 0, nBottom
- aSize
.Height
, aWindowBox
.Width
, nBottom
);
909 nBottom
-= aSize
.Height
+ gnScrollBarGap
;
912 const double nPagerHeight (nBottom
);
913 maBox
[Pager
] = geometry::RealRectangle2D(
914 0,0, aWindowBox
.Width
, nBottom
);
917 maBox
[Thumb
] = maBox
[Pager
];
919 // Set up the enabled/disabled states.
920 maEnabledState
[PrevButton
] = false;
921 maEnabledState
[PagerUp
] = false;
922 maEnabledState
[NextButton
] = false;
923 maEnabledState
[PagerDown
] = false;
924 maEnabledState
[Thumb
] = false;
928 const double nThumbSize
= ::std::min(mnThumbSize
,mnTotalSize
);
929 const double nThumbPosition
= ::std::min(::std::max(0.0,mnThumbPosition
), mnTotalSize
- nThumbSize
);
930 maBox
[Thumb
] = geometry::RealRectangle2D(
931 0, nThumbPosition
/ mnTotalSize
* nPagerHeight
,
933 (nThumbPosition
+nThumbSize
) / mnTotalSize
* nPagerHeight
);
935 // Set up the enabled/disabled states.
936 maEnabledState
[PrevButton
] = nThumbPosition
>0;
937 maEnabledState
[PagerUp
] = nThumbPosition
>0;
938 maEnabledState
[NextButton
] = nThumbPosition
+nThumbSize
< mnTotalSize
;
939 maEnabledState
[PagerDown
] = nThumbPosition
+nThumbSize
< mnTotalSize
;
940 maEnabledState
[Thumb
] = nThumbSize
< mnTotalSize
;
942 maBox
[PagerUp
] = geometry::RealRectangle2D(
943 maBox
[Pager
].X1
, maBox
[Pager
].Y1
, maBox
[Pager
].X2
, maBox
[Thumb
].Y1
-1);
944 maBox
[PagerDown
] = geometry::RealRectangle2D(
945 maBox
[Pager
].X1
, maBox
[Thumb
].Y2
+1, maBox
[Pager
].X2
, maBox
[Pager
].Y2
);
946 maBox
[Total
] = PresenterGeometryHelper::Union(
947 PresenterGeometryHelper::Union(maBox
[PrevButton
], maBox
[NextButton
]),
954 void PresenterVerticalScrollBar::UpdateBitmaps (void)
956 if (mpBitmaps
.get() != NULL
)
958 mpPrevButtonDescriptor
= mpBitmaps
->GetBitmap(A2S("Up"));
959 mpNextButtonDescriptor
= mpBitmaps
->GetBitmap(A2S("Down"));
960 mpPagerStartDescriptor
= mpBitmaps
->GetBitmap(A2S("PagerTop"));
961 mpPagerCenterDescriptor
= mpBitmaps
->GetBitmap(A2S("PagerVertical"));
962 mpPagerEndDescriptor
= mpBitmaps
->GetBitmap(A2S("PagerBottom"));
963 mpThumbStartDescriptor
= mpBitmaps
->GetBitmap(A2S("ThumbTop"));
964 mpThumbCenterDescriptor
= mpBitmaps
->GetBitmap(A2S("ThumbVertical"));
965 mpThumbEndDescriptor
= mpBitmaps
->GetBitmap(A2S("ThumbBottom"));
967 mnScrollBarWidth
= 0;
968 UpdateWidthOrHeight(mnScrollBarWidth
, mpPrevButtonDescriptor
);
969 UpdateWidthOrHeight(mnScrollBarWidth
, mpNextButtonDescriptor
);
970 UpdateWidthOrHeight(mnScrollBarWidth
, mpPagerStartDescriptor
);
971 UpdateWidthOrHeight(mnScrollBarWidth
, mpPagerCenterDescriptor
);
972 UpdateWidthOrHeight(mnScrollBarWidth
, mpPagerEndDescriptor
);
973 UpdateWidthOrHeight(mnScrollBarWidth
, mpThumbStartDescriptor
);
974 UpdateWidthOrHeight(mnScrollBarWidth
, mpThumbCenterDescriptor
);
975 UpdateWidthOrHeight(mnScrollBarWidth
, mpThumbEndDescriptor
);
976 if (mnScrollBarWidth
== 0)
977 mnScrollBarWidth
= 20;
984 void PresenterVerticalScrollBar::PaintComposite(
985 const css::awt::Rectangle
& rUpdateBox
,
987 const SharedBitmapDescriptor
& rpStartBitmaps
,
988 const SharedBitmapDescriptor
& rpCenterBitmaps
,
989 const SharedBitmapDescriptor
& rpEndBitmaps
)
991 const awt::Rectangle
aWindowBox (mxWindow
->getPosSize());
992 geometry::RealRectangle2D
aBox (GetRectangle(eArea
));
993 aBox
.X1
+= aWindowBox
.X
;
994 aBox
.Y1
+= aWindowBox
.Y
;
995 aBox
.X2
+= aWindowBox
.X
;
996 aBox
.Y2
+= aWindowBox
.Y
;
998 // Get bitmaps and sizes.
1000 PresenterUIPainter::PaintVerticalBitmapComposite(
1004 ? PresenterGeometryHelper::ConvertRectangleWithConstantSize(aBox
)
1005 : PresenterGeometryHelper::ConvertRectangle(aBox
)),
1006 GetBitmap(eArea
, rpStartBitmaps
),
1007 GetBitmap(eArea
, rpCenterBitmaps
),
1008 GetBitmap(eArea
, rpEndBitmaps
));
1014 //===== PresenterHorizontalScrollBar ============================================
1016 PresenterHorizontalScrollBar::PresenterHorizontalScrollBar (
1017 const Reference
<XComponentContext
>& rxComponentContext
,
1018 const Reference
<awt::XWindow
>& rxParentWindow
,
1019 const ::boost::shared_ptr
<PresenterPaintManager
>& rpPaintManager
,
1020 const ::boost::function
<void(double)>& rThumbMotionListener
)
1021 : PresenterScrollBar(rxComponentContext
, rxParentWindow
, rpPaintManager
, rThumbMotionListener
),
1022 mnScrollBarHeight(0)
1029 PresenterHorizontalScrollBar::~PresenterHorizontalScrollBar (void)
1036 double PresenterHorizontalScrollBar::GetDragDistance (const sal_Int32 nX
, const sal_Int32 nY
) const
1039 const double nDistance (nX
- maDragAnchor
.X
);
1044 const awt::Rectangle
aWindowBox (mxWindow
->getPosSize());
1045 const double nBarHeight (aWindowBox
.Height
);
1046 const double nPagerWidth (aWindowBox
.Width
- 2*nBarHeight
);
1047 const double nDragDistance (mnTotalSize
/ nPagerWidth
* nDistance
);
1048 if (nDragDistance
+ mnThumbPosition
< 0)
1049 return -mnThumbPosition
;
1050 else if (mnThumbPosition
+ nDragDistance
> mnTotalSize
-mnThumbSize
)
1051 return mnTotalSize
-mnThumbSize
-mnThumbPosition
;
1053 return nDragDistance
;
1060 void PresenterHorizontalScrollBar::UpdateDragAnchor (const double nDragDistance
)
1062 const awt::Rectangle
aWindowBox (mxWindow
->getPosSize());
1063 const double nBarHeight (aWindowBox
.Height
);
1064 const double nPagerWidth (aWindowBox
.Width
- 2*nBarHeight
);
1065 maDragAnchor
.X
+= nDragDistance
* nPagerWidth
/ mnTotalSize
;
1071 sal_Int32
PresenterHorizontalScrollBar::GetSize (void) const
1073 return mnScrollBarHeight
;
1080 geometry::RealPoint2D
PresenterHorizontalScrollBar::GetPoint (
1081 const double nMajor
, const double nMinor
) const
1083 return geometry::RealPoint2D(nMajor
, nMinor
);
1089 double PresenterHorizontalScrollBar::GetMajor (const double nX
, const double nY
) const
1098 double PresenterHorizontalScrollBar::GetMinor (const double nX
, const double nY
) const
1107 void PresenterHorizontalScrollBar::UpdateBorders (void)
1109 const awt::Rectangle
aWindowBox (mxWindow
->getPosSize());
1110 double nRight
= aWindowBox
.Width
;
1111 const double nGap (2);
1113 if (mpNextButtonDescriptor
.get() != NULL
)
1115 Reference
<rendering::XBitmap
> xBitmap (mpNextButtonDescriptor
->GetNormalBitmap());
1118 geometry::IntegerSize2D
aSize (xBitmap
->getSize());
1119 maBox
[NextButton
] = geometry::RealRectangle2D(
1120 nRight
- aSize
.Width
,0, nRight
, aWindowBox
.Height
);
1121 nRight
-= aSize
.Width
+ nGap
;
1124 if (mpPrevButtonDescriptor
.get() != NULL
)
1126 Reference
<rendering::XBitmap
> xBitmap (mpPrevButtonDescriptor
->GetNormalBitmap());
1129 geometry::IntegerSize2D
aSize (xBitmap
->getSize());
1130 maBox
[PrevButton
] = geometry::RealRectangle2D(
1131 nRight
- aSize
.Width
,0, nRight
, aWindowBox
.Height
);
1132 nRight
-= aSize
.Width
+ nGap
;
1136 const double nPagerWidth (nRight
);
1137 maBox
[Pager
] = geometry::RealRectangle2D(
1138 0,0, nRight
, aWindowBox
.Height
);
1139 if (mnTotalSize
== 0)
1141 maBox
[Thumb
] = maBox
[Pager
];
1143 // Set up the enabled/disabled states.
1144 maEnabledState
[PrevButton
] = false;
1145 maEnabledState
[PagerUp
] = false;
1146 maEnabledState
[NextButton
] = false;
1147 maEnabledState
[PagerDown
] = false;
1148 maEnabledState
[Thumb
] = false;
1152 const double nThumbSize
= ::std::min(mnThumbSize
,mnTotalSize
);
1153 const double nThumbPosition
= ::std::min(::std::max(0.0,mnThumbPosition
), mnTotalSize
- nThumbSize
);
1154 maBox
[Thumb
] = geometry::RealRectangle2D(
1155 (nThumbPosition
) / mnTotalSize
* nPagerWidth
, 0,
1156 (nThumbPosition
+nThumbSize
) / mnTotalSize
* nPagerWidth
, aWindowBox
.Height
);
1158 // Set up the enabled/disabled states.
1159 maEnabledState
[PrevButton
] = nThumbPosition
>0;
1160 maEnabledState
[PagerUp
] = nThumbPosition
>0;
1161 maEnabledState
[NextButton
] = nThumbPosition
+nThumbSize
< mnTotalSize
;
1162 maEnabledState
[PagerDown
] = nThumbPosition
+nThumbSize
< mnTotalSize
;
1163 maEnabledState
[Thumb
] = nThumbSize
< mnTotalSize
;
1165 maBox
[PagerUp
] = geometry::RealRectangle2D(
1166 maBox
[Pager
].X1
, maBox
[Pager
].Y1
, maBox
[Thumb
].X1
-1, maBox
[Pager
].Y2
);
1167 maBox
[PagerDown
] = geometry::RealRectangle2D(
1168 maBox
[Thumb
].X2
+1, maBox
[Pager
].Y1
, maBox
[Pager
].X2
, maBox
[Pager
].Y2
);
1169 maBox
[Total
] = PresenterGeometryHelper::Union(
1170 PresenterGeometryHelper::Union(maBox
[PrevButton
], maBox
[NextButton
]),
1177 void PresenterHorizontalScrollBar::UpdateBitmaps (void)
1179 if (mpBitmaps
.get() != NULL
)
1181 mpPrevButtonDescriptor
= mpBitmaps
->GetBitmap(A2S("Left"));
1182 mpNextButtonDescriptor
= mpBitmaps
->GetBitmap(A2S("Right"));
1183 mpPagerStartDescriptor
= mpBitmaps
->GetBitmap(A2S("PagerLeft"));
1184 mpPagerCenterDescriptor
= mpBitmaps
->GetBitmap(A2S("PagerHorizontal"));
1185 mpPagerEndDescriptor
= mpBitmaps
->GetBitmap(A2S("PagerRight"));
1186 mpThumbStartDescriptor
= mpBitmaps
->GetBitmap(A2S("ThumbLeft"));
1187 mpThumbCenterDescriptor
= mpBitmaps
->GetBitmap(A2S("ThumbHorizontal"));
1188 mpThumbEndDescriptor
= mpBitmaps
->GetBitmap(A2S("ThumbRight"));
1190 mnScrollBarHeight
= 0;
1191 UpdateWidthOrHeight(mnScrollBarHeight
, mpPrevButtonDescriptor
);
1192 UpdateWidthOrHeight(mnScrollBarHeight
, mpNextButtonDescriptor
);
1193 UpdateWidthOrHeight(mnScrollBarHeight
, mpPagerStartDescriptor
);
1194 UpdateWidthOrHeight(mnScrollBarHeight
, mpPagerCenterDescriptor
);
1195 UpdateWidthOrHeight(mnScrollBarHeight
, mpPagerEndDescriptor
);
1196 UpdateWidthOrHeight(mnScrollBarHeight
, mpThumbStartDescriptor
);
1197 UpdateWidthOrHeight(mnScrollBarHeight
, mpThumbCenterDescriptor
);
1198 UpdateWidthOrHeight(mnScrollBarHeight
, mpThumbEndDescriptor
);
1199 if (mnScrollBarHeight
== 0)
1200 mnScrollBarHeight
= 20;
1206 void PresenterHorizontalScrollBar::PaintComposite(
1207 const css::awt::Rectangle
& rUpdateBox
,
1209 const SharedBitmapDescriptor
& rpStartBitmaps
,
1210 const SharedBitmapDescriptor
& rpCenterBitmaps
,
1211 const SharedBitmapDescriptor
& rpEndBitmaps
)
1213 const awt::Rectangle
aWindowBox (mxWindow
->getPosSize());
1214 geometry::RealRectangle2D
aBox (GetRectangle(eArea
));
1215 aBox
.X1
+= aWindowBox
.X
;
1216 aBox
.Y1
+= aWindowBox
.Y
;
1217 aBox
.X2
+= aWindowBox
.X
;
1218 aBox
.Y2
+= aWindowBox
.Y
;
1220 PresenterUIPainter::PaintHorizontalBitmapComposite(
1223 PresenterGeometryHelper::ConvertRectangle(aBox
),
1224 GetBitmap(eArea
, rpStartBitmaps
),
1225 GetBitmap(eArea
, rpCenterBitmaps
),
1226 GetBitmap(eArea
, rpEndBitmaps
));
1232 //===== PresenterScrollBar::MousePressRepeater ================================
1234 PresenterScrollBar::MousePressRepeater::MousePressRepeater (
1235 const ::rtl::Reference
<PresenterScrollBar
>& rpScrollBar
)
1236 : mnMousePressRepeaterTaskId(PresenterTimer::NotAValidTaskId
),
1237 mpScrollBar(rpScrollBar
),
1238 meMouseArea(PresenterScrollBar::None
)
1245 void PresenterScrollBar::MousePressRepeater::Dispose (void)
1254 void PresenterScrollBar::MousePressRepeater::Start (const PresenterScrollBar::Area
& reArea
)
1256 meMouseArea
= reArea
;
1258 if (mnMousePressRepeaterTaskId
== PresenterTimer::NotAValidTaskId
)
1260 // Execute key press operation at least this one time.
1263 // Schedule repeated executions.
1264 mnMousePressRepeaterTaskId
= PresenterTimer::ScheduleRepeatedTask (
1265 ::boost::bind(&PresenterScrollBar::MousePressRepeater::Callback
, shared_from_this(), _1
),
1271 // There is already an active repeating task.
1278 void PresenterScrollBar::MousePressRepeater::Stop (void)
1280 if (mnMousePressRepeaterTaskId
!= PresenterTimer::NotAValidTaskId
)
1282 const sal_Int32
nTaskId (mnMousePressRepeaterTaskId
);
1283 mnMousePressRepeaterTaskId
= PresenterTimer::NotAValidTaskId
;
1284 PresenterTimer::CancelTask(nTaskId
);
1291 void PresenterScrollBar::MousePressRepeater::SetMouseArea(const PresenterScrollBar::Area
& reArea
)
1293 if (meMouseArea
!= reArea
)
1295 if (mnMousePressRepeaterTaskId
!= PresenterTimer::NotAValidTaskId
)
1305 void PresenterScrollBar::MousePressRepeater::Callback (const TimeValue
& rCurrentTime
)
1309 if (mpScrollBar
.get() == NULL
)
1321 void PresenterScrollBar::MousePressRepeater::Execute (void)
1323 const double nThumbPosition (mpScrollBar
->GetThumbPosition());
1324 switch (meMouseArea
)
1327 mpScrollBar
->SetThumbPosition(nThumbPosition
- mpScrollBar
->GetLineHeight(), true);
1331 mpScrollBar
->SetThumbPosition(nThumbPosition
+ mpScrollBar
->GetLineHeight(), true);
1335 mpScrollBar
->SetThumbPosition(nThumbPosition
- mpScrollBar
->GetThumbSize()*0.8, true);
1339 mpScrollBar
->SetThumbPosition(nThumbPosition
+ mpScrollBar
->GetThumbSize()*0.8, true);
1349 } } // end of namespace ::sdext::presenter