update dev300-m58
[ooovba.git] / sdext / source / presenter / PresenterScrollBar.cxx
blob0f8cbfc98216c9e4e018ed6080dc031783c43300
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PresenterScrollBar.cxx,v $
11 * $Revision: 1.8 $
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>
53 #include <math.h>
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>
70 public:
71 MousePressRepeater (const ::rtl::Reference<PresenterScrollBar>& rpScrollBar);
72 void Dispose (void);
73 void Start (const PresenterScrollBar::Area& reArea);
74 void Stop (void);
75 void SetMouseArea (const PresenterScrollBar::Area& reArea);
77 private:
78 void Callback (const TimeValue& rCurrentTime);
79 void Execute (void);
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),
101 mxWindow(),
102 mxCanvas(),
103 mxPresenterHelper(),
104 mpPaintManager(rpPaintManager),
105 mnThumbPosition(0),
106 mnTotalSize(0),
107 mnThumbSize(0),
108 mnLineHeight(10),
109 maDragAnchor(-1,-1),
110 maThumbMotionListener(rThumbMotionListener),
111 meButtonDownArea(None),
112 meMouseMoveArea(None),
113 mbIsNotificationActive(false),
114 mpBitmaps(),
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"),
136 rxComponentContext),
137 UNO_QUERY_THROW);
139 if (mxPresenterHelper.is())
140 mxWindow = mxPresenterHelper->createWindow(rxParentWindow,
141 sal_False,
142 sal_False,
143 sal_False,
144 sal_False);
146 // Make the background transparent. The slide show paints its own background.
147 Reference<awt::XWindowPeer> xPeer (mxWindow, UNO_QUERY_THROW);
148 if (xPeer.is())
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();
178 if (mxWindow.is())
180 mxWindow->removeWindowListener(this);
181 mxWindow->removePaintListener(this);
182 mxWindow->removeMouseListener(this);
183 mxWindow->removeMouseMotionListener(this);
185 Reference<lang::XComponent> xComponent (mxWindow, UNO_QUERY);
186 mxWindow = NULL;
187 if (xComponent.is())
188 xComponent->dispose();
191 mpBitmaps.reset();
197 void PresenterScrollBar::SetVisible (const bool bIsVisible)
199 if (mxWindow.is())
200 mxWindow->setVisible(bIsVisible);
206 void PresenterScrollBar::SetPosSize (const css::geometry::RealRectangle2D& rBox)
208 if (mxWindow.is())
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);
216 UpdateBorders();
223 void PresenterScrollBar::SetThumbPosition (
224 double nPosition,
225 const bool bAsynchronousUpdate)
227 SetThumbPosition(nPosition, bAsynchronousUpdate, true, true);
233 void PresenterScrollBar::SetThumbPosition (
234 double nPosition,
235 const bool bAsynchronousUpdate,
236 const bool bValidate,
237 const bool bNotify)
239 if (bValidate)
240 nPosition = ValidateThumbPosition(nPosition);
242 if (nPosition != mnThumbPosition && ! mbIsNotificationActive)
244 mnThumbPosition = nPosition;
246 UpdateBorders();
247 Repaint(GetRectangle(Total), bAsynchronousUpdate);
248 if (bNotify)
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;
269 UpdateBorders();
270 Repaint(GetRectangle(Total), false);
277 double PresenterScrollBar::GetTotalSize (void) const
279 return mnTotalSize;
285 void PresenterScrollBar::SetThumbSize (const double nThumbSize)
287 OSL_ASSERT(nThumbSize>=0);
288 if (mnThumbSize != nThumbSize)
290 mnThumbSize = nThumbSize;
291 UpdateBorders();
292 Repaint(GetRectangle(Total), false);
299 double PresenterScrollBar::GetThumbSize (void) const
301 return mnThumbSize;
307 void PresenterScrollBar::SetLineHeight (const double nLineHeight)
309 mnLineHeight = nLineHeight;
315 double PresenterScrollBar::GetLineHeight (void) const
317 return mnLineHeight;
323 void PresenterScrollBar::SetCanvas (const Reference<css::rendering::XCanvas>& rxCanvas)
325 if (mxCanvas != rxCanvas)
327 mxCanvas = rxCanvas;
328 if (mxCanvas.is())
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>(),
339 mxComponentContext,
340 mxCanvas,
341 PresenterComponent::GetBasePath(mxComponentContext)));
342 mpSharedBitmaps = mpBitmaps;
344 catch(Exception&)
346 OSL_ASSERT(false);
349 else
350 mpBitmaps = ::boost::shared_ptr<PresenterBitmapContainer>(mpSharedBitmaps);
351 UpdateBitmaps();
352 UpdateBorders();
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;
382 if (nPosition < 0)
383 nPosition = 0;
384 return nPosition;
390 void PresenterScrollBar::Paint (
391 const awt::Rectangle& rUpdateBox,
392 const bool bNoClip)
394 if ( ! mxCanvas.is() || ! mxWindow.is())
396 OSL_ASSERT(mxCanvas.is());
397 OSL_ASSERT(mxWindow.is());
398 return;
401 if ( ! bNoClip)
403 if (PresenterGeometryHelper::AreRectanglesDisjoint (rUpdateBox, mxWindow->getPosSize()))
404 return;
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)
432 (void)rEvent;
439 void SAL_CALL PresenterScrollBar::windowMoved (const css::awt::WindowEvent& rEvent)
440 throw (css::uno::RuntimeException)
442 (void)rEvent;
448 void SAL_CALL PresenterScrollBar::windowShown (const css::lang::EventObject& rEvent)
449 throw (css::uno::RuntimeException)
451 (void)rEvent;
457 void SAL_CALL PresenterScrollBar::windowHidden (const css::lang::EventObject& rEvent)
458 throw (css::uno::RuntimeException)
460 (void)rEvent;
466 //----- XPaintListener --------------------------------------------------------
468 void SAL_CALL PresenterScrollBar::windowPaint (const css::awt::PaintEvent& rEvent)
469 throw (css::uno::RuntimeException)
471 if (mxWindow.is())
473 awt::Rectangle aRepaintBox (rEvent.UpdateRect);
474 const awt::Rectangle aWindowBox (mxWindow->getPosSize());
475 aRepaintBox.X += aWindowBox.X;
476 aRepaintBox.Y += aWindowBox.Y;
477 Paint(aRepaintBox);
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)
506 (void)rEvent;
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)
520 (void)rEvent;
526 void SAL_CALL PresenterScrollBar::mouseExited (const css::awt::MouseEvent& rEvent)
527 throw(css::uno::RuntimeException)
529 (void)rEvent;
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)
571 return;
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)
595 mxWindow = NULL;
601 //-----------------------------------------------------------------------------
603 geometry::RealRectangle2D PresenterScrollBar::GetRectangle (const Area eArea) const
605 OSL_ASSERT(eArea>=0 && eArea<__AreaCount__);
607 return maBox[eArea];
613 void PresenterScrollBar::Repaint (
614 const geometry::RealRectangle2D aBox,
615 const bool bAsynchronousUpdate)
617 if (mpPaintManager.get() != NULL)
618 mpPaintManager->Invalidate(
619 mxWindow,
620 PresenterGeometryHelper::ConvertRectangle(aBox),
621 bAsynchronousUpdate);
627 void PresenterScrollBar::PaintBackground(
628 const css::awt::Rectangle& rUpdateBox)
630 if (mpBackgroundBitmap.get() == NULL)
631 return;
633 const awt::Rectangle aWindowBox (mxWindow->getPosSize());
634 mpCanvasHelper->Paint(
635 mpBackgroundBitmap,
636 mxCanvas,
637 rUpdateBox,
638 aWindowBox,
639 awt::Rectangle());
645 void PresenterScrollBar::PaintBitmap(
646 const css::awt::Rectangle& rUpdateBox,
647 const Area eArea,
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));
660 if (xBitmap.is())
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),
670 xClipPolygon);
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),
677 NULL,
678 Sequence<double>(4),
679 rendering::CompositeOperation::SOURCE);
681 mxCanvas->drawBitmap(
682 xBitmap,
683 aViewState,
684 aRenderState);
691 void PresenterScrollBar::NotifyThumbPositionChange (void)
693 if ( ! mbIsNotificationActive)
695 mbIsNotificationActive = true;
699 maThumbMotionListener(mnThumbPosition);
701 catch (Exception&)
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))
719 return Thumb;
720 else if (PresenterGeometryHelper::IsInside(GetRectangle(PagerUp), aPoint))
721 return PagerUp;
722 else if (PresenterGeometryHelper::IsInside(GetRectangle(PagerDown), aPoint))
723 return PagerDown;
725 else if (PresenterGeometryHelper::IsInside(GetRectangle(PrevButton), aPoint))
726 return PrevButton;
727 else if (PresenterGeometryHelper::IsInside(GetRectangle(NextButton), aPoint))
728 return NextButton;
730 return None;
736 void PresenterScrollBar::UpdateWidthOrHeight (
737 sal_Int32& rSize,
738 const SharedBitmapDescriptor& rpDescriptor)
740 if (rpDescriptor.get() != NULL)
742 Reference<rendering::XBitmap> xBitmap (rpDescriptor->GetNormalBitmap());
743 if (xBitmap.is())
745 const geometry::IntegerSize2D aBitmapSize (xBitmap->getSize());
746 const sal_Int32 nBitmapSize = (sal_Int32)GetMinor(aBitmapSize.Width, aBitmapSize.Height);
747 if (nBitmapSize > rSize)
748 rSize = nBitmapSize;
756 css::uno::Reference<css::rendering::XBitmap> PresenterScrollBar::GetBitmap (
757 const Area eArea,
758 const SharedBitmapDescriptor& rpBitmaps) const
760 if (rpBitmaps.get() == NULL)
761 return NULL;
762 else
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;
776 else
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),
801 mnScrollBarWidth(0)
808 PresenterVerticalScrollBar::~PresenterVerticalScrollBar (void)
815 double PresenterVerticalScrollBar::GetDragDistance (const sal_Int32 nX, const sal_Int32 nY) const
817 (void)nX;
818 const double nDistance (nY - maDragAnchor.Y);
819 if (nDistance == 0)
820 return 0;
821 else
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;
831 else
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
869 (void)nX;
870 return nY;
876 double PresenterVerticalScrollBar::GetMinor (const double nX, const double nY) const
878 (void)nY;
879 return nX;
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());
893 if (xBitmap.is())
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());
904 if (xBitmap.is())
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);
915 if (mnTotalSize < 1)
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;
926 else
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,
932 aWindowBox.Width,
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]),
948 maBox[Pager]);
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,
986 const Area eArea,
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(
1001 mxCanvas,
1002 rUpdateBox,
1003 (eArea == Thumb
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
1038 (void)nY;
1039 const double nDistance (nX - maDragAnchor.X);
1040 if (nDistance == 0)
1041 return 0;
1042 else
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;
1052 else
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
1091 (void)nY;
1092 return nX;
1098 double PresenterHorizontalScrollBar::GetMinor (const double nX, const double nY) const
1100 (void)nX;
1101 return nY;
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());
1116 if (xBitmap.is())
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());
1127 if (xBitmap.is())
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;
1150 else
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]),
1171 maBox[Pager]);
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,
1208 const Area eArea,
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(
1221 mxCanvas,
1222 rUpdateBox,
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)
1247 Stop();
1248 mpScrollBar = NULL;
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.
1261 Execute();
1263 // Schedule repeated executions.
1264 mnMousePressRepeaterTaskId = PresenterTimer::ScheduleRepeatedTask (
1265 ::boost::bind(&PresenterScrollBar::MousePressRepeater::Callback, shared_from_this(), _1),
1266 500000000,
1267 250000000);
1269 else
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)
1297 Stop();
1305 void PresenterScrollBar::MousePressRepeater::Callback (const TimeValue& rCurrentTime)
1307 (void)rCurrentTime;
1309 if (mpScrollBar.get() == NULL)
1311 Stop();
1312 return;
1315 Execute();
1321 void PresenterScrollBar::MousePressRepeater::Execute (void)
1323 const double nThumbPosition (mpScrollBar->GetThumbPosition());
1324 switch (meMouseArea)
1326 case PrevButton:
1327 mpScrollBar->SetThumbPosition(nThumbPosition - mpScrollBar->GetLineHeight(), true);
1328 break;
1330 case NextButton:
1331 mpScrollBar->SetThumbPosition(nThumbPosition + mpScrollBar->GetLineHeight(), true);
1332 break;
1334 case PagerUp:
1335 mpScrollBar->SetThumbPosition(nThumbPosition - mpScrollBar->GetThumbSize()*0.8, true);
1336 break;
1338 case PagerDown:
1339 mpScrollBar->SetThumbPosition(nThumbPosition + mpScrollBar->GetThumbSize()*0.8, true);
1340 break;
1342 default:
1343 break;
1349 } } // end of namespace ::sdext::presenter