Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "PresenterScrollBar.hxx"
30 : : #include "PresenterBitmapContainer.hxx"
31 : : #include "PresenterCanvasHelper.hxx"
32 : : #include "PresenterComponent.hxx"
33 : : #include "PresenterGeometryHelper.hxx"
34 : : #include "PresenterPaintManager.hxx"
35 : : #include "PresenterTimer.hxx"
36 : : #include "PresenterUIPainter.hxx"
37 : : #include <com/sun/star/awt/PosSize.hpp>
38 : : #include <com/sun/star/awt/WindowAttribute.hpp>
39 : : #include <com/sun/star/awt/XWindowPeer.hpp>
40 : : #include <com/sun/star/awt/XToolkit.hpp>
41 : : #include <com/sun/star/rendering/CompositeOperation.hpp>
42 : : #include <com/sun/star/rendering/TexturingMode.hpp>
43 : : #include <com/sun/star/rendering/XPolyPolygon2D.hpp>
44 : : #include <boost/bind.hpp>
45 : : #include <boost/enable_shared_from_this.hpp>
46 : : #include <boost/weak_ptr.hpp>
47 : : #include <math.h>
48 : :
49 : : using namespace ::com::sun::star;
50 : : using namespace ::com::sun::star::uno;
51 : : using ::rtl::OUString;
52 : :
53 : : #define A2S(pString) (::rtl::OUString(pString))
54 : :
55 : : const static double gnScrollBarGap (10);
56 : :
57 : : namespace sdext { namespace presenter {
58 : :
59 : : //===== PresenterScrollBar::MousePressRepeater ================================
60 : :
61 : 0 : class PresenterScrollBar::MousePressRepeater
62 : : : public ::boost::enable_shared_from_this<MousePressRepeater>
63 : : {
64 : : public:
65 : : MousePressRepeater (const ::rtl::Reference<PresenterScrollBar>& rpScrollBar);
66 : : void Dispose (void);
67 : : void Start (const PresenterScrollBar::Area& reArea);
68 : : void Stop (void);
69 : : void SetMouseArea (const PresenterScrollBar::Area& reArea);
70 : :
71 : : private:
72 : : void Callback (const TimeValue& rCurrentTime);
73 : : void Execute (void);
74 : :
75 : : sal_Int32 mnMousePressRepeaterTaskId;
76 : : ::rtl::Reference<PresenterScrollBar> mpScrollBar;
77 : : PresenterScrollBar::Area meMouseArea;
78 : : };
79 : :
80 : : //===== PresenterScrollBar ====================================================
81 : :
82 : 8 : boost::weak_ptr<PresenterBitmapContainer> PresenterScrollBar::mpSharedBitmaps;
83 : :
84 : 0 : PresenterScrollBar::PresenterScrollBar (
85 : : const Reference<XComponentContext>& rxComponentContext,
86 : : const Reference<awt::XWindow>& rxParentWindow,
87 : : const ::boost::shared_ptr<PresenterPaintManager>& rpPaintManager,
88 : : const ::boost::function<void(double)>& rThumbMotionListener)
89 : : : PresenterScrollBarInterfaceBase(m_aMutex),
90 : : mxComponentContext(rxComponentContext),
91 : : mxParentWindow(rxParentWindow),
92 : : mxWindow(),
93 : : mxCanvas(),
94 : : mxPresenterHelper(),
95 : : mpPaintManager(rpPaintManager),
96 : : mnThumbPosition(0),
97 : : mnTotalSize(0),
98 : : mnThumbSize(0),
99 : : mnLineHeight(10),
100 : : maDragAnchor(-1,-1),
101 : : maThumbMotionListener(rThumbMotionListener),
102 : : meButtonDownArea(None),
103 : : meMouseMoveArea(None),
104 : : mbIsNotificationActive(false),
105 : : mpBitmaps(),
106 : : mpPrevButtonDescriptor(),
107 : : mpNextButtonDescriptor(),
108 : : mpPagerStartDescriptor(),
109 : : mpPagerCenterDescriptor(),
110 : : mpPagerEndDescriptor(),
111 : : mpThumbStartDescriptor(),
112 : : mpThumbCenterDescriptor(),
113 : : mpThumbEndDescriptor(),
114 [ # # ]: 0 : mpMousePressRepeater(new MousePressRepeater(this)),
115 : : mpBackgroundBitmap(),
116 [ # # ][ # # ]: 0 : mpCanvasHelper(new PresenterCanvasHelper())
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
117 : : {
118 : : try
119 : : {
120 [ # # ][ # # ]: 0 : Reference<lang::XMultiComponentFactory> xFactory (rxComponentContext->getServiceManager());
121 [ # # ]: 0 : if ( ! xFactory.is())
122 [ # # ]: 0 : throw RuntimeException();
123 : :
124 : : mxPresenterHelper = Reference<drawing::XPresenterHelper>(
125 [ # # ]: 0 : xFactory->createInstanceWithContext(
126 : : OUString("com.sun.star.comp.Draw.PresenterHelper"),
127 : 0 : rxComponentContext),
128 [ # # ][ # # ]: 0 : UNO_QUERY_THROW);
[ # # ]
129 : :
130 [ # # ]: 0 : if (mxPresenterHelper.is())
131 [ # # ]: 0 : mxWindow = mxPresenterHelper->createWindow(rxParentWindow,
132 : : sal_False,
133 : : sal_False,
134 : : sal_False,
135 [ # # ][ # # ]: 0 : sal_False);
136 : :
137 : : // Make the background transparent. The slide show paints its own background.
138 [ # # ]: 0 : Reference<awt::XWindowPeer> xPeer (mxWindow, UNO_QUERY_THROW);
139 [ # # ]: 0 : if (xPeer.is())
140 : : {
141 [ # # ][ # # ]: 0 : xPeer->setBackground(0xff000000);
142 : : }
143 : :
144 [ # # ][ # # ]: 0 : mxWindow->setVisible(sal_True);
145 [ # # ][ # # ]: 0 : mxWindow->addWindowListener(this);
[ # # ]
146 [ # # ][ # # ]: 0 : mxWindow->addPaintListener(this);
[ # # ]
147 [ # # ][ # # ]: 0 : mxWindow->addMouseListener(this);
[ # # ]
148 [ # # ][ # # ]: 0 : mxWindow->addMouseMotionListener(this);
[ # # ][ # # ]
149 : : }
150 [ # # ]: 0 : catch (RuntimeException&)
151 : : {
152 : : }
153 : 0 : }
154 : :
155 [ # # ][ # # ]: 0 : PresenterScrollBar::~PresenterScrollBar (void)
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
156 : : {
157 [ # # ]: 0 : }
158 : :
159 : 0 : void SAL_CALL PresenterScrollBar::disposing (void)
160 : : {
161 : 0 : mpMousePressRepeater->Dispose();
162 : :
163 [ # # ]: 0 : if (mxWindow.is())
164 : : {
165 [ # # ][ # # ]: 0 : mxWindow->removeWindowListener(this);
[ # # ]
166 [ # # ][ # # ]: 0 : mxWindow->removePaintListener(this);
[ # # ]
167 [ # # ][ # # ]: 0 : mxWindow->removeMouseListener(this);
[ # # ]
168 [ # # ][ # # ]: 0 : mxWindow->removeMouseMotionListener(this);
[ # # ]
169 : :
170 [ # # ]: 0 : Reference<lang::XComponent> xComponent (mxWindow, UNO_QUERY);
171 [ # # ]: 0 : mxWindow = NULL;
172 [ # # ]: 0 : if (xComponent.is())
173 [ # # ][ # # ]: 0 : xComponent->dispose();
174 : : }
175 : :
176 : 0 : mpBitmaps.reset();
177 : 0 : }
178 : :
179 : 0 : void PresenterScrollBar::SetVisible (const bool bIsVisible)
180 : : {
181 [ # # ]: 0 : if (mxWindow.is())
182 : 0 : mxWindow->setVisible(bIsVisible);
183 : 0 : }
184 : :
185 : 0 : void PresenterScrollBar::SetPosSize (const css::geometry::RealRectangle2D& rBox)
186 : : {
187 [ # # ]: 0 : if (mxWindow.is())
188 : : {
189 : 0 : mxWindow->setPosSize(
190 : 0 : sal_Int32(floor(rBox.X1)),
191 : 0 : sal_Int32(ceil(rBox.Y1)),
192 : 0 : sal_Int32(ceil(rBox.X2-rBox.X1)),
193 : 0 : sal_Int32(floor(rBox.Y2-rBox.Y1)),
194 : 0 : awt::PosSize::POSSIZE);
195 : 0 : UpdateBorders();
196 : : }
197 : 0 : }
198 : :
199 : 0 : void PresenterScrollBar::SetThumbPosition (
200 : : double nPosition,
201 : : const bool bAsynchronousUpdate)
202 : : {
203 : 0 : SetThumbPosition(nPosition, bAsynchronousUpdate, true, true);
204 : 0 : }
205 : :
206 : 0 : void PresenterScrollBar::SetThumbPosition (
207 : : double nPosition,
208 : : const bool bAsynchronousUpdate,
209 : : const bool bValidate,
210 : : const bool bNotify)
211 : : {
212 [ # # ]: 0 : if (bValidate)
213 : 0 : nPosition = ValidateThumbPosition(nPosition);
214 : :
215 [ # # ][ # # ]: 0 : if (nPosition != mnThumbPosition && ! mbIsNotificationActive)
216 : : {
217 : 0 : mnThumbPosition = nPosition;
218 : :
219 : 0 : UpdateBorders();
220 : 0 : Repaint(GetRectangle(Total), bAsynchronousUpdate);
221 [ # # ]: 0 : if (bNotify)
222 : 0 : NotifyThumbPositionChange();
223 : : }
224 : 0 : }
225 : :
226 : 0 : double PresenterScrollBar::GetThumbPosition (void) const
227 : : {
228 : 0 : return mnThumbPosition;
229 : : }
230 : :
231 : 0 : void PresenterScrollBar::SetTotalSize (const double nTotalSize)
232 : : {
233 [ # # ]: 0 : if (mnTotalSize != nTotalSize)
234 : : {
235 : 0 : mnTotalSize = nTotalSize + 1;
236 : 0 : UpdateBorders();
237 : 0 : Repaint(GetRectangle(Total), false);
238 : : }
239 : 0 : }
240 : :
241 : 0 : void PresenterScrollBar::SetThumbSize (const double nThumbSize)
242 : : {
243 : : OSL_ASSERT(nThumbSize>=0);
244 [ # # ]: 0 : if (mnThumbSize != nThumbSize)
245 : : {
246 : 0 : mnThumbSize = nThumbSize;
247 : 0 : UpdateBorders();
248 : 0 : Repaint(GetRectangle(Total), false);
249 : : }
250 : 0 : }
251 : :
252 : 0 : double PresenterScrollBar::GetThumbSize (void) const
253 : : {
254 : 0 : return mnThumbSize;
255 : : }
256 : :
257 : 0 : void PresenterScrollBar::SetLineHeight (const double nLineHeight)
258 : : {
259 : 0 : mnLineHeight = nLineHeight;
260 : 0 : }
261 : :
262 : 0 : double PresenterScrollBar::GetLineHeight (void) const
263 : : {
264 : 0 : return mnLineHeight;
265 : : }
266 : :
267 : 0 : void PresenterScrollBar::SetCanvas (const Reference<css::rendering::XCanvas>& rxCanvas)
268 : : {
269 [ # # ]: 0 : if (mxCanvas != rxCanvas)
270 : : {
271 : 0 : mxCanvas = rxCanvas;
272 [ # # ]: 0 : if (mxCanvas.is())
273 : : {
274 [ # # ]: 0 : if (mpBitmaps.get()==NULL)
275 : : {
276 [ # # ]: 0 : if (mpSharedBitmaps.expired())
277 : : {
278 : : try
279 : : {
280 : : mpBitmaps.reset(new PresenterBitmapContainer(
281 : : OUString("PresenterScreenSettings/ScrollBar/Bitmaps"),
282 : : ::boost::shared_ptr<PresenterBitmapContainer>(),
283 : : mxComponentContext,
284 : : mxCanvas,
285 [ # # ][ # # ]: 0 : PresenterComponent::GetBasePath(mxComponentContext)));
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
286 [ # # ]: 0 : mpSharedBitmaps = mpBitmaps;
287 : : }
288 : 0 : catch(Exception&)
289 : : {
290 : : OSL_ASSERT(false);
291 : : }
292 : : }
293 : : else
294 [ # # ]: 0 : mpBitmaps = ::boost::shared_ptr<PresenterBitmapContainer>(mpSharedBitmaps);
295 : 0 : UpdateBitmaps();
296 : 0 : UpdateBorders();
297 : : }
298 : :
299 : 0 : Repaint(GetRectangle(Total), false);
300 : : }
301 : : }
302 : 0 : }
303 : :
304 : 0 : void PresenterScrollBar::SetBackground (const SharedBitmapDescriptor& rpBackgroundBitmap)
305 : : {
306 : 0 : mpBackgroundBitmap = rpBackgroundBitmap;
307 : 0 : }
308 : :
309 : 0 : void PresenterScrollBar::CheckValues (void)
310 : : {
311 : 0 : mnThumbPosition = ValidateThumbPosition(mnThumbPosition);
312 : 0 : }
313 : :
314 : 0 : double PresenterScrollBar::ValidateThumbPosition (double nPosition)
315 : : {
316 [ # # ]: 0 : if (nPosition + mnThumbSize > mnTotalSize)
317 : 0 : nPosition = mnTotalSize - mnThumbSize;
318 [ # # ]: 0 : if (nPosition < 0)
319 : 0 : nPosition = 0;
320 : 0 : return nPosition;
321 : : }
322 : :
323 : 0 : void PresenterScrollBar::Paint (
324 : : const awt::Rectangle& rUpdateBox,
325 : : const bool bNoClip)
326 : : {
327 [ # # ][ # # ]: 0 : if ( ! mxCanvas.is() || ! mxWindow.is())
[ # # ]
328 : : {
329 : : OSL_ASSERT(mxCanvas.is());
330 : : OSL_ASSERT(mxWindow.is());
331 : : return;
332 : : }
333 : :
334 [ # # ]: 0 : if ( ! bNoClip)
335 : : {
336 [ # # ][ # # ]: 0 : if (PresenterGeometryHelper::AreRectanglesDisjoint (rUpdateBox, mxWindow->getPosSize()))
[ # # ][ # # ]
337 : : return;
338 : : }
339 : :
340 [ # # ]: 0 : PaintBackground(rUpdateBox);
341 : : PaintComposite(rUpdateBox, PagerUp,
342 [ # # ][ # # ]: 0 : mpPagerStartDescriptor, mpPagerCenterDescriptor, SharedBitmapDescriptor());
[ # # ]
343 : : PaintComposite(rUpdateBox, PagerDown,
344 [ # # ][ # # ]: 0 : SharedBitmapDescriptor(), mpPagerCenterDescriptor, mpPagerEndDescriptor);
[ # # ]
345 : : PaintComposite(rUpdateBox, Thumb,
346 [ # # ]: 0 : mpThumbStartDescriptor, mpThumbCenterDescriptor, mpThumbEndDescriptor);
347 [ # # ]: 0 : PaintBitmap(rUpdateBox, PrevButton, mpPrevButtonDescriptor);
348 [ # # ]: 0 : PaintBitmap(rUpdateBox, NextButton, mpNextButtonDescriptor);
349 : :
350 [ # # ]: 0 : Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxCanvas, UNO_QUERY);
351 [ # # ]: 0 : if (xSpriteCanvas.is())
352 [ # # ][ # # ]: 0 : xSpriteCanvas->updateScreen(sal_False);
353 : : }
354 : :
355 : : //----- XWindowListener -------------------------------------------------------
356 : :
357 : 0 : void SAL_CALL PresenterScrollBar::windowResized (const css::awt::WindowEvent& rEvent)
358 : : throw (css::uno::RuntimeException)
359 : : {
360 : : (void)rEvent;
361 : 0 : }
362 : :
363 : 0 : void SAL_CALL PresenterScrollBar::windowMoved (const css::awt::WindowEvent& rEvent)
364 : : throw (css::uno::RuntimeException)
365 : : {
366 : : (void)rEvent;
367 : 0 : }
368 : :
369 : 0 : void SAL_CALL PresenterScrollBar::windowShown (const css::lang::EventObject& rEvent)
370 : : throw (css::uno::RuntimeException)
371 : : {
372 : : (void)rEvent;
373 : 0 : }
374 : :
375 : 0 : void SAL_CALL PresenterScrollBar::windowHidden (const css::lang::EventObject& rEvent)
376 : : throw (css::uno::RuntimeException)
377 : : {
378 : : (void)rEvent;
379 : 0 : }
380 : :
381 : : //----- XPaintListener --------------------------------------------------------
382 : :
383 : 0 : void SAL_CALL PresenterScrollBar::windowPaint (const css::awt::PaintEvent& rEvent)
384 : : throw (css::uno::RuntimeException)
385 : : {
386 [ # # ]: 0 : if (mxWindow.is())
387 : : {
388 : 0 : awt::Rectangle aRepaintBox (rEvent.UpdateRect);
389 [ # # ][ # # ]: 0 : const awt::Rectangle aWindowBox (mxWindow->getPosSize());
390 : 0 : aRepaintBox.X += aWindowBox.X;
391 : 0 : aRepaintBox.Y += aWindowBox.Y;
392 [ # # ]: 0 : Paint(aRepaintBox);
393 : :
394 [ # # ]: 0 : Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxCanvas, UNO_QUERY);
395 [ # # ]: 0 : if (xSpriteCanvas.is())
396 [ # # ][ # # ]: 0 : xSpriteCanvas->updateScreen(sal_False);
397 : : }
398 : 0 : }
399 : :
400 : : //----- XMouseListener --------------------------------------------------------
401 : :
402 : 0 : void SAL_CALL PresenterScrollBar::mousePressed (const css::awt::MouseEvent& rEvent)
403 : : throw(css::uno::RuntimeException)
404 : : {
405 : 0 : maDragAnchor.X = rEvent.X;
406 : 0 : maDragAnchor.Y = rEvent.Y;
407 : 0 : meButtonDownArea = GetArea(rEvent.X, rEvent.Y);
408 : :
409 : 0 : mpMousePressRepeater->Start(meButtonDownArea);
410 : 0 : }
411 : :
412 : 0 : void SAL_CALL PresenterScrollBar::mouseReleased (const css::awt::MouseEvent& rEvent)
413 : : throw(css::uno::RuntimeException)
414 : : {
415 : : (void)rEvent;
416 : :
417 : 0 : mpMousePressRepeater->Stop();
418 : :
419 [ # # ]: 0 : if (mxPresenterHelper.is())
420 : 0 : mxPresenterHelper->releaseMouse(mxWindow);
421 : 0 : }
422 : :
423 : 0 : void SAL_CALL PresenterScrollBar::mouseEntered (const css::awt::MouseEvent& rEvent)
424 : : throw(css::uno::RuntimeException)
425 : : {
426 : : (void)rEvent;
427 : 0 : }
428 : :
429 : 0 : void SAL_CALL PresenterScrollBar::mouseExited (const css::awt::MouseEvent& rEvent)
430 : : throw(css::uno::RuntimeException)
431 : : {
432 : : (void)rEvent;
433 [ # # ]: 0 : if (meMouseMoveArea != None)
434 : : {
435 : 0 : const Area eOldMouseMoveArea (meMouseMoveArea);
436 : 0 : meMouseMoveArea = None;
437 : 0 : Repaint(GetRectangle(eOldMouseMoveArea), true);
438 : : }
439 : 0 : meButtonDownArea = None;
440 : 0 : meMouseMoveArea = None;
441 : :
442 : 0 : mpMousePressRepeater->Stop();
443 : 0 : }
444 : :
445 : : //----- XMouseMotionListener --------------------------------------------------
446 : :
447 : 0 : void SAL_CALL PresenterScrollBar::mouseMoved (const css::awt::MouseEvent& rEvent)
448 : : throw (css::uno::RuntimeException)
449 : : {
450 [ # # ]: 0 : const Area eArea (GetArea(rEvent.X, rEvent.Y));
451 [ # # ]: 0 : if (eArea != meMouseMoveArea)
452 : : {
453 : 0 : const Area eOldMouseMoveArea (meMouseMoveArea);
454 : 0 : meMouseMoveArea = eArea;
455 [ # # ]: 0 : if (eOldMouseMoveArea != None)
456 [ # # ][ # # ]: 0 : Repaint(GetRectangle(eOldMouseMoveArea), meMouseMoveArea==None);
457 [ # # ]: 0 : if (meMouseMoveArea != None)
458 [ # # ][ # # ]: 0 : Repaint(GetRectangle(meMouseMoveArea), true);
459 : : }
460 [ # # ]: 0 : mpMousePressRepeater->SetMouseArea(eArea);
461 : 0 : }
462 : :
463 : 0 : void SAL_CALL PresenterScrollBar::mouseDragged (const css::awt::MouseEvent& rEvent)
464 : : throw (css::uno::RuntimeException)
465 : : {
466 [ # # ]: 0 : if (meButtonDownArea != Thumb)
467 : 0 : return;
468 : :
469 : 0 : mpMousePressRepeater->Stop();
470 : :
471 [ # # ]: 0 : if (mxPresenterHelper.is())
472 : 0 : mxPresenterHelper->captureMouse(mxWindow);
473 : :
474 : 0 : const double nDragDistance (GetDragDistance(rEvent.X,rEvent.Y));
475 : 0 : UpdateDragAnchor(nDragDistance);
476 [ # # ]: 0 : if (nDragDistance != 0)
477 : : {
478 : 0 : SetThumbPosition(mnThumbPosition + nDragDistance, false, true, true);
479 : : }
480 : : }
481 : :
482 : : //----- lang::XEventListener --------------------------------------------------
483 : :
484 : 0 : void SAL_CALL PresenterScrollBar::disposing (const css::lang::EventObject& rEvent)
485 : : throw (css::uno::RuntimeException)
486 : : {
487 [ # # ]: 0 : if (rEvent.Source == mxWindow)
488 : 0 : mxWindow = NULL;
489 : 0 : }
490 : :
491 : : //-----------------------------------------------------------------------------
492 : :
493 : 0 : geometry::RealRectangle2D PresenterScrollBar::GetRectangle (const Area eArea) const
494 : : {
495 : : OSL_ASSERT(eArea>=0 && eArea<__AreaCount__);
496 : :
497 : 0 : return maBox[eArea];
498 : : }
499 : :
500 : 0 : void PresenterScrollBar::Repaint (
501 : : const geometry::RealRectangle2D aBox,
502 : : const bool bAsynchronousUpdate)
503 : : {
504 [ # # ]: 0 : if (mpPaintManager.get() != NULL)
505 : : mpPaintManager->Invalidate(
506 : : mxWindow,
507 : : PresenterGeometryHelper::ConvertRectangle(aBox),
508 [ # # ]: 0 : bAsynchronousUpdate);
509 : 0 : }
510 : :
511 : 0 : void PresenterScrollBar::PaintBackground(
512 : : const css::awt::Rectangle& rUpdateBox)
513 : : {
514 [ # # ]: 0 : if (mpBackgroundBitmap.get() == NULL)
515 : 0 : return;
516 : :
517 [ # # ][ # # ]: 0 : const awt::Rectangle aWindowBox (mxWindow->getPosSize());
518 : : mpCanvasHelper->Paint(
519 : : mpBackgroundBitmap,
520 : : mxCanvas,
521 : : rUpdateBox,
522 : : aWindowBox,
523 [ # # ]: 0 : awt::Rectangle());
524 : : }
525 : :
526 : 0 : void PresenterScrollBar::PaintBitmap(
527 : : const css::awt::Rectangle& rUpdateBox,
528 : : const Area eArea,
529 : : const SharedBitmapDescriptor& rpBitmaps)
530 : : {
531 [ # # ]: 0 : const geometry::RealRectangle2D aLocalBox (GetRectangle(eArea));
532 [ # # ][ # # ]: 0 : const awt::Rectangle aWindowBox (mxWindow->getPosSize());
533 : 0 : geometry::RealRectangle2D aBox (aLocalBox);
534 : 0 : aBox.X1 += aWindowBox.X;
535 : 0 : aBox.Y1 += aWindowBox.Y;
536 : 0 : aBox.X2 += aWindowBox.X;
537 : 0 : aBox.Y2 += aWindowBox.Y;
538 : :
539 [ # # ]: 0 : Reference<rendering::XBitmap> xBitmap (GetBitmap(eArea,rpBitmaps));
540 : :
541 [ # # ]: 0 : if (xBitmap.is())
542 : : {
543 : : Reference<rendering::XPolyPolygon2D> xClipPolygon (
544 : : PresenterGeometryHelper::CreatePolygon(
545 : : PresenterGeometryHelper::Intersection(rUpdateBox,
546 [ # # ]: 0 : PresenterGeometryHelper::ConvertRectangle(aBox)),
547 [ # # ][ # # ]: 0 : mxCanvas->getDevice()));
[ # # ][ # # ]
548 : :
549 : : const rendering::ViewState aViewState (
550 : : geometry::AffineMatrix2D(1,0,0, 0,1,0),
551 [ # # ]: 0 : xClipPolygon);
552 : :
553 [ # # ][ # # ]: 0 : const geometry::IntegerSize2D aBitmapSize (xBitmap->getSize());
554 : : rendering::RenderState aRenderState (
555 : : geometry::AffineMatrix2D(
556 : : 1,0,aBox.X1 + (aBox.X2-aBox.X1 - aBitmapSize.Width)/2,
557 : : 0,1,aBox.Y1 + (aBox.Y2-aBox.Y1 - aBitmapSize.Height)/2),
558 : : NULL,
559 : : Sequence<double>(4),
560 [ # # ][ # # ]: 0 : rendering::CompositeOperation::SOURCE);
[ # # ][ # # ]
561 : :
562 [ # # ]: 0 : mxCanvas->drawBitmap(
563 : : xBitmap,
564 : : aViewState,
565 [ # # ][ # # ]: 0 : aRenderState);
[ # # ]
566 : 0 : }
567 : 0 : }
568 : :
569 : 0 : void PresenterScrollBar::NotifyThumbPositionChange (void)
570 : : {
571 [ # # ]: 0 : if ( ! mbIsNotificationActive)
572 : : {
573 : 0 : mbIsNotificationActive = true;
574 : :
575 : : try
576 : : {
577 [ # # ]: 0 : maThumbMotionListener(mnThumbPosition);
578 : : }
579 : 0 : catch (Exception&)
580 : : {
581 : : }
582 : :
583 : 0 : mbIsNotificationActive = false;
584 : : }
585 [ # # ]: 0 : }
586 : :
587 : 0 : PresenterScrollBar::Area PresenterScrollBar::GetArea (const double nX, const double nY) const
588 : : {
589 : 0 : const geometry::RealPoint2D aPoint(nX, nY);
590 : :
591 [ # # ][ # # ]: 0 : if (PresenterGeometryHelper::IsInside(GetRectangle(Pager), aPoint))
[ # # ]
592 : : {
593 [ # # ][ # # ]: 0 : if (PresenterGeometryHelper::IsInside(GetRectangle(Thumb), aPoint))
[ # # ]
594 : 0 : return Thumb;
595 [ # # ][ # # ]: 0 : else if (PresenterGeometryHelper::IsInside(GetRectangle(PagerUp), aPoint))
[ # # ]
596 : 0 : return PagerUp;
597 [ # # ][ # # ]: 0 : else if (PresenterGeometryHelper::IsInside(GetRectangle(PagerDown), aPoint))
[ # # ]
598 : 0 : return PagerDown;
599 : : }
600 [ # # ][ # # ]: 0 : else if (PresenterGeometryHelper::IsInside(GetRectangle(PrevButton), aPoint))
[ # # ]
601 : 0 : return PrevButton;
602 [ # # ][ # # ]: 0 : else if (PresenterGeometryHelper::IsInside(GetRectangle(NextButton), aPoint))
[ # # ]
603 : 0 : return NextButton;
604 : :
605 : 0 : return None;
606 : : }
607 : :
608 : 0 : void PresenterScrollBar::UpdateWidthOrHeight (
609 : : sal_Int32& rSize,
610 : : const SharedBitmapDescriptor& rpDescriptor)
611 : : {
612 [ # # ]: 0 : if (rpDescriptor.get() != NULL)
613 : : {
614 [ # # ]: 0 : Reference<rendering::XBitmap> xBitmap (rpDescriptor->GetNormalBitmap());
615 [ # # ]: 0 : if (xBitmap.is())
616 : : {
617 [ # # ][ # # ]: 0 : const geometry::IntegerSize2D aBitmapSize (xBitmap->getSize());
618 [ # # ]: 0 : const sal_Int32 nBitmapSize = (sal_Int32)GetMinor(aBitmapSize.Width, aBitmapSize.Height);
619 [ # # ]: 0 : if (nBitmapSize > rSize)
620 : 0 : rSize = nBitmapSize;
621 : 0 : }
622 : : }
623 : 0 : }
624 : :
625 : 0 : css::uno::Reference<css::rendering::XBitmap> PresenterScrollBar::GetBitmap (
626 : : const Area eArea,
627 : : const SharedBitmapDescriptor& rpBitmaps) const
628 : : {
629 [ # # ]: 0 : if (rpBitmaps.get() == NULL)
630 : 0 : return NULL;
631 : : else
632 : 0 : return rpBitmaps->GetBitmap(GetBitmapMode(eArea));
633 : : }
634 : :
635 : 0 : PresenterBitmapContainer::BitmapDescriptor::Mode PresenterScrollBar::GetBitmapMode (
636 : : const Area eArea) const
637 : : {
638 [ # # ]: 0 : if (IsDisabled(eArea))
639 : 0 : return PresenterBitmapContainer::BitmapDescriptor::Disabled;
640 [ # # ]: 0 : else if (eArea == meMouseMoveArea)
641 : 0 : return PresenterBitmapContainer::BitmapDescriptor::MouseOver;
642 : : else
643 : 0 : return PresenterBitmapContainer::BitmapDescriptor::Normal;
644 : : }
645 : :
646 : 0 : bool PresenterScrollBar::IsDisabled (const Area eArea) const
647 : : {
648 : : OSL_ASSERT(eArea>=0 && eArea<__AreaCount__);
649 : :
650 : 0 : return ! maEnabledState[eArea];
651 : : }
652 : :
653 : : //===== PresenterVerticalScrollBar ============================================
654 : :
655 : 0 : PresenterVerticalScrollBar::PresenterVerticalScrollBar (
656 : : const Reference<XComponentContext>& rxComponentContext,
657 : : const Reference<awt::XWindow>& rxParentWindow,
658 : : const ::boost::shared_ptr<PresenterPaintManager>& rpPaintManager,
659 : : const ::boost::function<void(double)>& rThumbMotionListener)
660 : : : PresenterScrollBar(rxComponentContext, rxParentWindow, rpPaintManager, rThumbMotionListener),
661 : 0 : mnScrollBarWidth(0)
662 : : {
663 : 0 : }
664 : :
665 : 0 : PresenterVerticalScrollBar::~PresenterVerticalScrollBar (void)
666 : : {
667 [ # # ]: 0 : }
668 : :
669 : 0 : double PresenterVerticalScrollBar::GetDragDistance (const sal_Int32 nX, const sal_Int32 nY) const
670 : : {
671 : : (void)nX;
672 : 0 : const double nDistance (nY - maDragAnchor.Y);
673 [ # # ]: 0 : if (nDistance == 0)
674 : 0 : return 0;
675 : : else
676 : : {
677 [ # # ][ # # ]: 0 : const awt::Rectangle aWindowBox (mxWindow->getPosSize());
678 : 0 : const double nBarWidth (aWindowBox.Width);
679 : 0 : const double nPagerHeight (aWindowBox.Height - 2*nBarWidth);
680 : 0 : const double nDragDistance (mnTotalSize / nPagerHeight * nDistance);
681 [ # # ]: 0 : if (nDragDistance + mnThumbPosition < 0)
682 : 0 : return -mnThumbPosition;
683 [ # # ]: 0 : else if (mnThumbPosition + nDragDistance > mnTotalSize-mnThumbSize)
684 : 0 : return mnTotalSize-mnThumbSize-mnThumbPosition;
685 : : else
686 : 0 : return nDragDistance;
687 : : }
688 : : }
689 : :
690 : 0 : void PresenterVerticalScrollBar::UpdateDragAnchor (const double nDragDistance)
691 : : {
692 [ # # ][ # # ]: 0 : const awt::Rectangle aWindowBox (mxWindow->getPosSize());
693 : 0 : const double nBarWidth (aWindowBox.Width);
694 : 0 : const double nPagerHeight (aWindowBox.Height - 2*nBarWidth);
695 : 0 : maDragAnchor.Y += nDragDistance * nPagerHeight / mnTotalSize;
696 : 0 : }
697 : :
698 : 0 : sal_Int32 PresenterVerticalScrollBar::GetSize (void) const
699 : : {
700 : 0 : return mnScrollBarWidth;
701 : : }
702 : :
703 : 0 : geometry::RealPoint2D PresenterVerticalScrollBar::GetPoint (
704 : : const double nMajor, const double nMinor) const
705 : : {
706 : 0 : return geometry::RealPoint2D(nMinor, nMajor);
707 : : }
708 : :
709 : 0 : double PresenterVerticalScrollBar::GetMajor (const double nX, const double nY) const
710 : : {
711 : : (void)nX;
712 : 0 : return nY;
713 : : }
714 : :
715 : 0 : double PresenterVerticalScrollBar::GetMinor (const double nX, const double nY) const
716 : : {
717 : : (void)nY;
718 : 0 : return nX;
719 : : }
720 : :
721 : 0 : void PresenterVerticalScrollBar::UpdateBorders (void)
722 : : {
723 [ # # ][ # # ]: 0 : const awt::Rectangle aWindowBox (mxWindow->getPosSize());
724 : 0 : double nBottom = aWindowBox.Height;
725 : :
726 [ # # ]: 0 : if (mpNextButtonDescriptor.get() != NULL)
727 : : {
728 [ # # ]: 0 : Reference<rendering::XBitmap> xBitmap (mpNextButtonDescriptor->GetNormalBitmap());
729 [ # # ]: 0 : if (xBitmap.is())
730 : : {
731 [ # # ][ # # ]: 0 : geometry::IntegerSize2D aSize (xBitmap->getSize());
732 : : maBox[NextButton] = geometry::RealRectangle2D(
733 : 0 : 0, nBottom - aSize.Height, aWindowBox.Width, nBottom);
734 : 0 : nBottom -= aSize.Height + gnScrollBarGap;
735 : 0 : }
736 : : }
737 [ # # ]: 0 : if (mpPrevButtonDescriptor.get() != NULL)
738 : : {
739 [ # # ]: 0 : Reference<rendering::XBitmap> xBitmap (mpPrevButtonDescriptor->GetNormalBitmap());
740 [ # # ]: 0 : if (xBitmap.is())
741 : : {
742 [ # # ][ # # ]: 0 : geometry::IntegerSize2D aSize (xBitmap->getSize());
743 : : maBox[PrevButton] = geometry::RealRectangle2D(
744 : 0 : 0, nBottom - aSize.Height, aWindowBox.Width, nBottom);
745 : 0 : nBottom -= aSize.Height + gnScrollBarGap;
746 : 0 : }
747 : : }
748 : 0 : const double nPagerHeight (nBottom);
749 : : maBox[Pager] = geometry::RealRectangle2D(
750 : 0 : 0,0, aWindowBox.Width, nBottom);
751 [ # # ]: 0 : if (mnTotalSize < 1)
752 : : {
753 : 0 : maBox[Thumb] = maBox[Pager];
754 : :
755 : : // Set up the enabled/disabled states.
756 : 0 : maEnabledState[PrevButton] = false;
757 : 0 : maEnabledState[PagerUp] = false;
758 : 0 : maEnabledState[NextButton] = false;
759 : 0 : maEnabledState[PagerDown] = false;
760 : 0 : maEnabledState[Thumb] = false;
761 : : }
762 : : else
763 : : {
764 [ # # ]: 0 : const double nThumbSize = ::std::min(mnThumbSize,mnTotalSize);
765 [ # # ][ # # ]: 0 : const double nThumbPosition = ::std::min(::std::max(0.0,mnThumbPosition), mnTotalSize - nThumbSize);
766 : : maBox[Thumb] = geometry::RealRectangle2D(
767 : : 0, nThumbPosition / mnTotalSize * nPagerHeight,
768 : : aWindowBox.Width,
769 : 0 : (nThumbPosition+nThumbSize) / mnTotalSize * nPagerHeight);
770 : :
771 : : // Set up the enabled/disabled states.
772 : 0 : maEnabledState[PrevButton] = nThumbPosition>0;
773 : 0 : maEnabledState[PagerUp] = nThumbPosition>0;
774 : 0 : maEnabledState[NextButton] = nThumbPosition+nThumbSize < mnTotalSize;
775 : 0 : maEnabledState[PagerDown] = nThumbPosition+nThumbSize < mnTotalSize;
776 : 0 : maEnabledState[Thumb] = nThumbSize < mnTotalSize;
777 : : }
778 : : maBox[PagerUp] = geometry::RealRectangle2D(
779 : 0 : maBox[Pager].X1, maBox[Pager].Y1, maBox[Pager].X2, maBox[Thumb].Y1-1);
780 : : maBox[PagerDown] = geometry::RealRectangle2D(
781 : 0 : maBox[Pager].X1, maBox[Thumb].Y2+1, maBox[Pager].X2, maBox[Pager].Y2);
782 : : maBox[Total] = PresenterGeometryHelper::Union(
783 : 0 : PresenterGeometryHelper::Union(maBox[PrevButton], maBox[NextButton]),
784 [ # # ][ # # ]: 0 : maBox[Pager]);
785 : 0 : }
786 : :
787 : 0 : void PresenterVerticalScrollBar::UpdateBitmaps (void)
788 : : {
789 [ # # ]: 0 : if (mpBitmaps.get() != NULL)
790 : : {
791 [ # # ][ # # ]: 0 : mpPrevButtonDescriptor = mpBitmaps->GetBitmap(A2S("Up"));
[ # # ]
792 [ # # ][ # # ]: 0 : mpNextButtonDescriptor = mpBitmaps->GetBitmap(A2S("Down"));
[ # # ]
793 [ # # ][ # # ]: 0 : mpPagerStartDescriptor = mpBitmaps->GetBitmap(A2S("PagerTop"));
[ # # ]
794 [ # # ][ # # ]: 0 : mpPagerCenterDescriptor = mpBitmaps->GetBitmap(A2S("PagerVertical"));
[ # # ]
795 [ # # ][ # # ]: 0 : mpPagerEndDescriptor = mpBitmaps->GetBitmap(A2S("PagerBottom"));
[ # # ]
796 [ # # ][ # # ]: 0 : mpThumbStartDescriptor = mpBitmaps->GetBitmap(A2S("ThumbTop"));
[ # # ]
797 [ # # ][ # # ]: 0 : mpThumbCenterDescriptor = mpBitmaps->GetBitmap(A2S("ThumbVertical"));
[ # # ]
798 [ # # ][ # # ]: 0 : mpThumbEndDescriptor = mpBitmaps->GetBitmap(A2S("ThumbBottom"));
[ # # ]
799 : :
800 : 0 : mnScrollBarWidth = 0;
801 : 0 : UpdateWidthOrHeight(mnScrollBarWidth, mpPrevButtonDescriptor);
802 : 0 : UpdateWidthOrHeight(mnScrollBarWidth, mpNextButtonDescriptor);
803 : 0 : UpdateWidthOrHeight(mnScrollBarWidth, mpPagerStartDescriptor);
804 : 0 : UpdateWidthOrHeight(mnScrollBarWidth, mpPagerCenterDescriptor);
805 : 0 : UpdateWidthOrHeight(mnScrollBarWidth, mpPagerEndDescriptor);
806 : 0 : UpdateWidthOrHeight(mnScrollBarWidth, mpThumbStartDescriptor);
807 : 0 : UpdateWidthOrHeight(mnScrollBarWidth, mpThumbCenterDescriptor);
808 : 0 : UpdateWidthOrHeight(mnScrollBarWidth, mpThumbEndDescriptor);
809 [ # # ]: 0 : if (mnScrollBarWidth == 0)
810 : 0 : mnScrollBarWidth = 20;
811 : : }
812 : 0 : }
813 : :
814 : 0 : void PresenterVerticalScrollBar::PaintComposite(
815 : : const css::awt::Rectangle& rUpdateBox,
816 : : const Area eArea,
817 : : const SharedBitmapDescriptor& rpStartBitmaps,
818 : : const SharedBitmapDescriptor& rpCenterBitmaps,
819 : : const SharedBitmapDescriptor& rpEndBitmaps)
820 : : {
821 [ # # ][ # # ]: 0 : const awt::Rectangle aWindowBox (mxWindow->getPosSize());
822 [ # # ]: 0 : geometry::RealRectangle2D aBox (GetRectangle(eArea));
823 : 0 : aBox.X1 += aWindowBox.X;
824 : 0 : aBox.Y1 += aWindowBox.Y;
825 : 0 : aBox.X2 += aWindowBox.X;
826 : 0 : aBox.Y2 += aWindowBox.Y;
827 : :
828 : : // Get bitmaps and sizes.
829 : :
830 : : PresenterUIPainter::PaintVerticalBitmapComposite(
831 : : mxCanvas,
832 : : rUpdateBox,
833 : : (eArea == Thumb
834 : : ? PresenterGeometryHelper::ConvertRectangleWithConstantSize(aBox)
835 : : : PresenterGeometryHelper::ConvertRectangle(aBox)),
836 : : GetBitmap(eArea, rpStartBitmaps),
837 : : GetBitmap(eArea, rpCenterBitmaps),
838 [ # # ][ # # ]: 0 : GetBitmap(eArea, rpEndBitmaps));
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
839 : 0 : }
840 : :
841 : : //===== PresenterScrollBar::MousePressRepeater ================================
842 : :
843 : 0 : PresenterScrollBar::MousePressRepeater::MousePressRepeater (
844 : : const ::rtl::Reference<PresenterScrollBar>& rpScrollBar)
845 : : : mnMousePressRepeaterTaskId(PresenterTimer::NotAValidTaskId),
846 : : mpScrollBar(rpScrollBar),
847 : 0 : meMouseArea(PresenterScrollBar::None)
848 : : {
849 : 0 : }
850 : :
851 : 0 : void PresenterScrollBar::MousePressRepeater::Dispose (void)
852 : : {
853 : 0 : Stop();
854 : 0 : mpScrollBar = NULL;
855 : 0 : }
856 : :
857 : 0 : void PresenterScrollBar::MousePressRepeater::Start (const PresenterScrollBar::Area& reArea)
858 : : {
859 : 0 : meMouseArea = reArea;
860 : :
861 [ # # ]: 0 : if (mnMousePressRepeaterTaskId == PresenterTimer::NotAValidTaskId)
862 : : {
863 : : // Execute key press operation at least this one time.
864 : 0 : Execute();
865 : :
866 : : // Schedule repeated executions.
867 : : mnMousePressRepeaterTaskId = PresenterTimer::ScheduleRepeatedTask (
868 : : ::boost::bind(&PresenterScrollBar::MousePressRepeater::Callback, shared_from_this(), _1),
869 : : 500000000,
870 [ # # ][ # # ]: 0 : 250000000);
[ # # ][ # # ]
[ # # ]
871 : : }
872 : : else
873 : : {
874 : : // There is already an active repeating task.
875 : : }
876 : 0 : }
877 : :
878 : 0 : void PresenterScrollBar::MousePressRepeater::Stop (void)
879 : : {
880 [ # # ]: 0 : if (mnMousePressRepeaterTaskId != PresenterTimer::NotAValidTaskId)
881 : : {
882 : 0 : const sal_Int32 nTaskId (mnMousePressRepeaterTaskId);
883 : 0 : mnMousePressRepeaterTaskId = PresenterTimer::NotAValidTaskId;
884 : 0 : PresenterTimer::CancelTask(nTaskId);
885 : : }
886 : 0 : }
887 : :
888 : 0 : void PresenterScrollBar::MousePressRepeater::SetMouseArea(const PresenterScrollBar::Area& reArea)
889 : : {
890 [ # # ]: 0 : if (meMouseArea != reArea)
891 : : {
892 [ # # ]: 0 : if (mnMousePressRepeaterTaskId != PresenterTimer::NotAValidTaskId)
893 : : {
894 : 0 : Stop();
895 : : }
896 : : }
897 : 0 : }
898 : :
899 : 0 : void PresenterScrollBar::MousePressRepeater::Callback (const TimeValue& rCurrentTime)
900 : : {
901 : : (void)rCurrentTime;
902 : :
903 [ # # ]: 0 : if (mpScrollBar.get() == NULL)
904 : : {
905 : 0 : Stop();
906 : 0 : return;
907 : : }
908 : :
909 : 0 : Execute();
910 : : }
911 : :
912 : 0 : void PresenterScrollBar::MousePressRepeater::Execute (void)
913 : : {
914 : 0 : const double nThumbPosition (mpScrollBar->GetThumbPosition());
915 [ # # # # : 0 : switch (meMouseArea)
# ]
916 : : {
917 : : case PrevButton:
918 : 0 : mpScrollBar->SetThumbPosition(nThumbPosition - mpScrollBar->GetLineHeight(), true);
919 : 0 : break;
920 : :
921 : : case NextButton:
922 : 0 : mpScrollBar->SetThumbPosition(nThumbPosition + mpScrollBar->GetLineHeight(), true);
923 : 0 : break;
924 : :
925 : : case PagerUp:
926 : 0 : mpScrollBar->SetThumbPosition(nThumbPosition - mpScrollBar->GetThumbSize()*0.8, true);
927 : 0 : break;
928 : :
929 : : case PagerDown:
930 : 0 : mpScrollBar->SetThumbPosition(nThumbPosition + mpScrollBar->GetThumbSize()*0.8, true);
931 : 0 : break;
932 : :
933 : : default:
934 : 0 : break;
935 : : }
936 : 0 : }
937 : :
938 [ + - ][ + - ]: 24 : } } // end of namespace ::sdext::presenter
939 : :
940 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|