1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef SDEXT_PRESENTER_PRESENTER_SCROLL_BAR_HXX 29 #define SDEXT_PRESENTER_PRESENTER_SCROLL_BAR_HXX 30 31 #include "PresenterBitmapContainer.hxx" 32 #include <com/sun/star/awt/Point.hpp> 33 #include <com/sun/star/awt/XWindow.hpp> 34 #include <com/sun/star/drawing/XPresenterHelper.hpp> 35 #include <com/sun/star/rendering/XCanvas.hpp> 36 #include <com/sun/star/uno/XComponentContext.hpp> 37 #include <cppuhelper/basemutex.hxx> 38 #include <cppuhelper/compbase4.hxx> 39 #include <boost/function.hpp> 40 #include <boost/noncopyable.hpp> 41 #include <boost/shared_ptr.hpp> 42 43 namespace css = ::com::sun::star; 44 45 namespace sdext { namespace presenter { 46 47 class PresenterCanvasHelper; 48 class PresenterPaintManager; 49 50 namespace { 51 typedef ::cppu::WeakComponentImplHelper4 < 52 css::awt::XWindowListener, 53 css::awt::XPaintListener, 54 css::awt::XMouseListener, 55 css::awt::XMouseMotionListener 56 > PresenterScrollBarInterfaceBase; 57 } 58 59 /** Base class of horizontal and vertical scroll bars. 60 */ 61 class PresenterScrollBar 62 : private ::boost::noncopyable, 63 private ::cppu::BaseMutex, 64 public PresenterScrollBarInterfaceBase 65 { 66 public: 67 typedef ::boost::function<void(double)> ThumbMotionListener; 68 virtual ~PresenterScrollBar (void); 69 70 virtual void SAL_CALL disposing (void); 71 72 void SetVisible (const bool bIsVisible); 73 74 /** Set the bounding box of the scroll bar. 75 */ 76 void SetPosSize (const css::geometry::RealRectangle2D& rBox); 77 78 /** Set the position of the movable thumb. 79 @param nPosition 80 A value between 0 and the last value given to SetTotalSize() 81 minus the last value given to SetThumbSize(). 82 */ 83 void SetThumbPosition ( 84 double nPosition, 85 const bool bAsynchronousRepaint); 86 87 double GetThumbPosition (void) const; 88 89 /** Set the upper border of the slider range. 90 */ 91 void SetTotalSize (const double nTotalSize); 92 93 double GetTotalSize (void) const; 94 95 /** Set the size of the movable thumb. 96 @param nThumbSize 97 A value not larger than the last value given to SetTotalSize(). 98 */ 99 void SetThumbSize (const double nThumbSize); 100 double GetThumbSize (void) const; 101 102 void SetLineHeight (const double nLineHeight); 103 double GetLineHeight (void) const; 104 105 /** Set the canvas that is used for painting the scroll bar. 106 */ 107 void SetCanvas (const css::uno::Reference<css::rendering::XCanvas>& rxCanvas); 108 109 void SetBackground (const SharedBitmapDescriptor& rpBackgroundBitmap); 110 111 /** Call this after changing total size or thumb position or size to 112 move the thumb to a valid position. 113 */ 114 void CheckValues (void); 115 116 /** On some occasions it is necessary to trigger the painting of a 117 scrollbar from the outside. 118 */ 119 virtual void Paint ( 120 const css::awt::Rectangle& rUpdateBox, 121 bool bNoClip = false); 122 123 virtual sal_Int32 GetSize (void) const = 0; 124 125 // XWindowListener 126 127 virtual void SAL_CALL windowResized (const css::awt::WindowEvent& rEvent) 128 throw (css::uno::RuntimeException); 129 130 virtual void SAL_CALL windowMoved (const css::awt::WindowEvent& rEvent) 131 throw (css::uno::RuntimeException); 132 133 virtual void SAL_CALL windowShown (const css::lang::EventObject& rEvent) 134 throw (css::uno::RuntimeException); 135 136 virtual void SAL_CALL windowHidden (const css::lang::EventObject& rEvent) 137 throw (css::uno::RuntimeException); 138 139 140 // XPaintListener 141 142 virtual void SAL_CALL windowPaint (const css::awt::PaintEvent& rEvent) 143 throw (css::uno::RuntimeException); 144 145 146 // XMouseListener 147 148 virtual void SAL_CALL mousePressed (const css::awt::MouseEvent& rEvent) 149 throw(css::uno::RuntimeException); 150 151 virtual void SAL_CALL mouseReleased (const css::awt::MouseEvent& rEvent) 152 throw(css::uno::RuntimeException); 153 154 virtual void SAL_CALL mouseEntered (const css::awt::MouseEvent& rEvent) 155 throw(css::uno::RuntimeException); 156 157 virtual void SAL_CALL mouseExited (const css::awt::MouseEvent& rEvent) 158 throw(css::uno::RuntimeException); 159 160 161 // XMouseMotionListener 162 163 virtual void SAL_CALL mouseMoved (const css::awt::MouseEvent& rEvent) 164 throw (css::uno::RuntimeException); 165 166 virtual void SAL_CALL mouseDragged (const css::awt::MouseEvent& rEvent) 167 throw (css::uno::RuntimeException); 168 169 170 // lang::XEventListener 171 virtual void SAL_CALL disposing (const css::lang::EventObject& rEvent) 172 throw (css::uno::RuntimeException); 173 174 175 enum Area { Total, Pager, Thumb, PagerUp, PagerDown, PrevButton, NextButton, None, 176 __AreaCount__ = None }; 177 178 protected: 179 css::uno::Reference<css::uno::XComponentContext> mxComponentContext; 180 css::uno::Reference<css::awt::XWindow> mxParentWindow; 181 css::uno::Reference<css::awt::XWindow> mxWindow; 182 css::uno::Reference<css::rendering::XCanvas> mxCanvas; 183 css::uno::Reference<css::drawing::XPresenterHelper> mxPresenterHelper; 184 ::boost::shared_ptr<PresenterPaintManager> mpPaintManager; 185 double mnThumbPosition; 186 double mnTotalSize; 187 double mnThumbSize; 188 double mnLineHeight; 189 css::geometry::RealPoint2D maDragAnchor; 190 ::boost::function<void(double)> maThumbMotionListener; 191 Area meButtonDownArea; 192 Area meMouseMoveArea; 193 css::geometry::RealRectangle2D maBox[__AreaCount__]; 194 bool mbIsNotificationActive; 195 static boost::weak_ptr<PresenterBitmapContainer> mpSharedBitmaps; 196 boost::shared_ptr<PresenterBitmapContainer> mpBitmaps; 197 SharedBitmapDescriptor mpPrevButtonDescriptor; 198 SharedBitmapDescriptor mpNextButtonDescriptor; 199 SharedBitmapDescriptor mpPagerStartDescriptor; 200 SharedBitmapDescriptor mpPagerCenterDescriptor; 201 SharedBitmapDescriptor mpPagerEndDescriptor; 202 SharedBitmapDescriptor mpThumbStartDescriptor; 203 SharedBitmapDescriptor mpThumbCenterDescriptor; 204 SharedBitmapDescriptor mpThumbEndDescriptor; 205 bool maEnabledState[__AreaCount__]; 206 207 virtual css::geometry::RealRectangle2D GetRectangle (const Area eArea) const; 208 virtual double GetDragDistance (const sal_Int32 nX, const sal_Int32 nY) const = 0; 209 virtual void UpdateDragAnchor (const double nDragDistance) = 0; 210 virtual css::geometry::RealPoint2D GetPoint (const double nMajor, const double nMinor) const = 0; 211 virtual double GetMajor (const double nX, const double nY) const = 0; 212 virtual double GetMinor (const double nX, const double nY) const = 0; 213 virtual void UpdateBorders (void) = 0; 214 virtual void UpdateBitmaps (void) = 0; 215 virtual void PaintComposite( 216 const css::awt::Rectangle& rRepaintBox, 217 const Area eArea, 218 const SharedBitmapDescriptor& rpStartBitmaps, 219 const SharedBitmapDescriptor& rpCenterBitmaps, 220 const SharedBitmapDescriptor& rpEndBitmaps) = 0; 221 222 PresenterScrollBar ( 223 const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext, 224 const css::uno::Reference<css::awt::XWindow>& rxParentWindow, 225 const ::boost::shared_ptr<PresenterPaintManager>& rpPaintManager, 226 const ::boost::function<void(double)>& rThumbMotionListener); 227 228 void Repaint ( 229 const css::geometry::RealRectangle2D aBox, 230 const bool bAsynchronous); 231 void PaintBackground ( 232 const css::awt::Rectangle& rRepaintBox); 233 void PaintBitmap( 234 const css::awt::Rectangle& rRepaintBox, 235 const Area eArea, 236 const SharedBitmapDescriptor& rpBitmaps); 237 void NotifyThumbPositionChange (void); 238 void UpdateWidthOrHeight (sal_Int32& rSize, 239 const SharedBitmapDescriptor& rpDescriptor); 240 css::uno::Reference<css::rendering::XBitmap> GetBitmap ( 241 const Area eArea, 242 const SharedBitmapDescriptor& rpBitmaps) const; 243 PresenterBitmapContainer::BitmapDescriptor::Mode GetBitmapMode ( 244 const Area eArea) const; 245 bool IsDisabled (const Area eArea) const; 246 double ValidateThumbPosition (double nPosition); 247 void SetThumbPosition ( 248 double nPosition, 249 const bool bAsynchronousRepaint, 250 const bool bValidate, 251 const bool bNotify); 252 253 private: 254 class MousePressRepeater; 255 ::boost::shared_ptr<MousePressRepeater> mpMousePressRepeater; 256 SharedBitmapDescriptor mpBackgroundBitmap; 257 ::boost::scoped_ptr<PresenterCanvasHelper> mpCanvasHelper; 258 259 Area GetArea (const double nX, const double nY) const; 260 }; 261 262 263 264 265 /** A vertical scroll bar. 266 */ 267 class PresenterVerticalScrollBar : public PresenterScrollBar 268 { 269 public: 270 PresenterVerticalScrollBar ( 271 const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext, 272 const css::uno::Reference<css::awt::XWindow>& rxParentWindow, 273 const ::boost::shared_ptr<PresenterPaintManager>& rpPaintManager, 274 const ::boost::function<void(double)>& rThumbMotionListener); 275 virtual ~PresenterVerticalScrollBar (void); 276 virtual sal_Int32 GetSize (void) const; 277 278 protected: 279 virtual double GetDragDistance (const sal_Int32 nX, const sal_Int32 nY) const; 280 virtual void UpdateDragAnchor (const double nDragDistance); 281 virtual css::geometry::RealPoint2D GetPoint (const double nMajor, const double nMinor) const; 282 virtual double GetMinor (const double nX, const double nY) const; 283 virtual double GetMajor (const double nX, const double nY) const; 284 virtual void UpdateBorders (void); 285 virtual void UpdateBitmaps (void); 286 virtual void PaintComposite( 287 const css::awt::Rectangle& rRepaintBox, 288 const Area eArea, 289 const SharedBitmapDescriptor& rpStartBitmaps, 290 const SharedBitmapDescriptor& rpCenterBitmaps, 291 const SharedBitmapDescriptor& rpEndBitmaps); 292 293 private: 294 sal_Int32 mnScrollBarWidth; 295 }; 296 297 298 299 300 /** A horizontal scroll bar. 301 */ 302 class PresenterHorizontalScrollBar : public PresenterScrollBar 303 { 304 public: 305 PresenterHorizontalScrollBar ( 306 const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext, 307 const css::uno::Reference<css::awt::XWindow>& rxParentWindow, 308 const ::boost::shared_ptr<PresenterPaintManager>& rpPaintManager, 309 const ::boost::function<void(double)>& rThumbMotionListener); 310 virtual ~PresenterHorizontalScrollBar (void); 311 virtual sal_Int32 GetSize (void) const; 312 313 protected: 314 virtual double GetDragDistance (const sal_Int32 nX, const sal_Int32 nY) const; 315 virtual void UpdateDragAnchor (const double nDragDistance); 316 virtual css::geometry::RealPoint2D GetPoint (const double nMajor, const double nMinor) const; 317 virtual double GetMinor (const double nX, const double nY) const; 318 virtual double GetMajor (const double nX, const double nY) const; 319 virtual void UpdateBorders (void); 320 virtual void UpdateBitmaps (void); 321 virtual void PaintComposite( 322 const css::awt::Rectangle& rRepaintBox, 323 const Area eArea, 324 const SharedBitmapDescriptor& rpStartBitmaps, 325 const SharedBitmapDescriptor& rpCenterBitmaps, 326 const SharedBitmapDescriptor& rpEndBitmaps); 327 328 private: 329 sal_Int32 mnScrollBarHeight; 330 }; 331 332 333 334 335 } } // end of namespace ::sdext::presenter 336 337 #endif 338