bump product version to 4.1.6.2
[LibreOffice.git] / sd / source / ui / presenter / PresenterCanvas.cxx
blobf93cade9dec411958c3ab928c1a1852d25241ded
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "PresenterCanvas.hxx"
23 #include <basegfx/matrix/b2dhommatrix.hxx>
24 #include <basegfx/polygon/b2dpolygontools.hxx>
25 #include <basegfx/polygon/b2dpolypolygon.hxx>
26 #include <basegfx/polygon/b2dpolygonclipper.hxx>
27 #include <basegfx/range/b2drectangle.hxx>
28 #include <basegfx/tools/canvastools.hxx>
29 #include <canvas/canvastools.hxx>
30 #include <cppuhelper/basemutex.hxx>
31 #include <cppuhelper/compbase1.hxx>
32 #include <rtl/ref.hxx>
33 #include <toolkit/helper/vclunohelper.hxx>
34 #include <vcl/window.hxx>
35 #include <vcl/svapp.hxx>
37 using namespace ::com::sun::star;
38 using namespace ::com::sun::star::uno;
40 namespace sd { namespace presenter {
42 //===== Service ===============================================================
44 Reference<XInterface> SAL_CALL PresenterCanvas_createInstance (
45 const Reference<XComponentContext>& rxContext)
47 (void)rxContext;
48 return Reference<XInterface>(static_cast<XWeak*>(new PresenterCanvas()));
54 OUString PresenterCanvas_getImplementationName (void) throw(RuntimeException)
56 return OUString("com.sun.star.comp.Draw.PresenterCanvasFactory");
62 Sequence<OUString> SAL_CALL PresenterCanvas_getSupportedServiceNames (void)
63 throw (RuntimeException)
65 static const OUString sServiceName("com.sun.star.rendering.Canvas");
66 return Sequence<OUString>(&sServiceName, 1);
72 //===== PresenterCustomSprite =================================================
74 /** Wrapper around a sprite that is displayed on a PresenterCanvas.
76 namespace {
77 typedef ::cppu::WeakComponentImplHelper1 <
78 css::rendering::XCustomSprite
79 > PresenterCustomSpriteInterfaceBase;
81 class PresenterCustomSprite
82 : private ::boost::noncopyable,
83 protected ::cppu::BaseMutex,
84 public PresenterCustomSpriteInterfaceBase
86 public:
87 PresenterCustomSprite (
88 const rtl::Reference<PresenterCanvas>& rpCanvas,
89 const Reference<rendering::XCustomSprite>& rxSprite,
90 const Reference<awt::XWindow>& rxBaseWindow,
91 const css::geometry::RealSize2D& rSpriteSize);
92 virtual ~PresenterCustomSprite (void);
93 virtual void SAL_CALL disposing (void)
94 throw (RuntimeException);
96 // XSprite
98 virtual void SAL_CALL setAlpha (double nAlpha)
99 throw (lang::IllegalArgumentException,RuntimeException);
101 virtual void SAL_CALL move (const geometry::RealPoint2D& rNewPos,
102 const rendering::ViewState& rViewState,
103 const rendering::RenderState& rRenderState)
104 throw (lang::IllegalArgumentException,RuntimeException);
106 virtual void SAL_CALL transform (const geometry::AffineMatrix2D& rTransformation)
107 throw (lang::IllegalArgumentException,RuntimeException);
109 virtual void SAL_CALL clip (const Reference<rendering::XPolyPolygon2D>& rClip)
110 throw (RuntimeException);
112 virtual void SAL_CALL setPriority (double nPriority)
113 throw (RuntimeException);
115 virtual void SAL_CALL show (void)
116 throw (RuntimeException);
118 virtual void SAL_CALL hide (void)
119 throw (RuntimeException);
122 // XCustomSprite
124 virtual Reference<rendering::XCanvas> SAL_CALL getContentCanvas (void)
125 throw (RuntimeException);
127 private:
128 rtl::Reference<PresenterCanvas> mpCanvas;
129 Reference<rendering::XCustomSprite> mxSprite;
130 Reference<awt::XWindow> mxBaseWindow;
131 geometry::RealPoint2D maPosition;
132 geometry::RealSize2D maSpriteSize;
134 void ThrowIfDisposed (void)
135 throw (css::lang::DisposedException);
141 //===== PresenterCanvas =======================================================
144 PresenterCanvas::PresenterCanvas (void)
145 : PresenterCanvasInterfaceBase(m_aMutex),
146 mxUpdateCanvas(),
147 mxSharedCanvas(),
148 mxSharedWindow(),
149 mxWindow(),
150 maOffset(),
151 mpUpdateRequester(),
152 maClipRectangle(),
153 mbOffsetUpdatePending(true)
160 PresenterCanvas::PresenterCanvas (
161 const Reference<rendering::XSpriteCanvas>& rxUpdateCanvas,
162 const Reference<awt::XWindow>& rxUpdateWindow,
163 const Reference<rendering::XCanvas>& rxSharedCanvas,
164 const Reference<awt::XWindow>& rxSharedWindow,
165 const Reference<awt::XWindow>& rxWindow)
166 : PresenterCanvasInterfaceBase(m_aMutex),
167 mxUpdateCanvas(rxUpdateCanvas),
168 mxUpdateWindow(rxUpdateWindow),
169 mxSharedCanvas(rxSharedCanvas),
170 mxSharedWindow(rxSharedWindow),
171 mxWindow(rxWindow),
172 maOffset(),
173 mpUpdateRequester(),
174 maClipRectangle(),
175 mbOffsetUpdatePending(true)
177 if (mxWindow.is())
178 mxWindow->addWindowListener(this);
180 if (mxUpdateCanvas.is())
181 mpUpdateRequester = CanvasUpdateRequester::Instance(mxUpdateCanvas);
187 PresenterCanvas::~PresenterCanvas (void)
194 void SAL_CALL PresenterCanvas::disposing (void)
195 throw (css::uno::RuntimeException)
197 if (mxWindow.is())
198 mxWindow->removeWindowListener(this);
204 //----- XInitialization -------------------------------------------------------
206 void SAL_CALL PresenterCanvas::initialize (
207 const Sequence<Any>& rArguments)
208 throw(Exception, RuntimeException)
210 if (rBHelper.bDisposed || rBHelper.bInDispose)
211 ThrowIfDisposed();
213 if (rArguments.getLength() == 5)
217 // First and second argument may be NULL.
218 rArguments[0] >>= mxUpdateCanvas;
219 rArguments[1] >>= mxUpdateWindow;
221 if ( ! (rArguments[2] >>= mxSharedWindow))
223 throw lang::IllegalArgumentException("PresenterCanvas: invalid shared window",
224 static_cast<XWeak*>(this),
228 if ( ! (rArguments[3] >>= mxSharedCanvas))
230 throw lang::IllegalArgumentException("PresenterCanvas: invalid shared canvas",
231 static_cast<XWeak*>(this),
235 if ( ! (rArguments[4] >>= mxWindow))
237 throw lang::IllegalArgumentException("PresenterCanvas: invalid window",
238 static_cast<XWeak*>(this),
242 mpUpdateRequester = CanvasUpdateRequester::Instance(mxUpdateCanvas);
244 mbOffsetUpdatePending = true;
245 if (mxWindow.is())
246 mxWindow->addWindowListener(this);
248 catch (RuntimeException&)
250 mxSharedWindow = NULL;
251 mxWindow = NULL;
252 throw;
255 else
257 throw RuntimeException("PresenterCanvas: invalid number of arguments",
258 static_cast<XWeak*>(this));
265 //----- XCanvas ---------------------------------------------------------------
267 void SAL_CALL PresenterCanvas::clear (void)
268 throw (css::uno::RuntimeException)
270 ThrowIfDisposed();
271 // ToDo: Clear the area covered by the child window. A simple forward
272 // would clear the whole shared canvas.
278 void SAL_CALL PresenterCanvas::drawPoint (
279 const css::geometry::RealPoint2D& aPoint,
280 const css::rendering::ViewState& aViewState,
281 const css::rendering::RenderState& aRenderState)
282 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException)
284 ThrowIfDisposed();
285 mxSharedCanvas->drawPoint(aPoint,MergeViewState(aViewState),aRenderState);
291 void SAL_CALL PresenterCanvas::drawLine (
292 const css::geometry::RealPoint2D& aStartPoint,
293 const css::geometry::RealPoint2D& aEndPoint,
294 const css::rendering::ViewState& aViewState,
295 const css::rendering::RenderState& aRenderState)
296 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException)
298 ThrowIfDisposed();
299 mxSharedCanvas->drawLine(aStartPoint,aEndPoint,MergeViewState(aViewState),aRenderState);
305 void SAL_CALL PresenterCanvas::drawBezier (
306 const css::geometry::RealBezierSegment2D& aBezierSegment,
307 const css::geometry::RealPoint2D& aEndPoint,
308 const css::rendering::ViewState& aViewState,
309 const css::rendering::RenderState& aRenderState)
310 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException)
312 ThrowIfDisposed();
313 mxSharedCanvas->drawBezier(aBezierSegment,aEndPoint,MergeViewState(aViewState),aRenderState);
319 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL PresenterCanvas::drawPolyPolygon (
320 const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
321 const css::rendering::ViewState& aViewState,
322 const css::rendering::RenderState& aRenderState)
323 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException)
325 ThrowIfDisposed();
326 return mxSharedCanvas->drawPolyPolygon(
327 xPolyPolygon, MergeViewState(aViewState), aRenderState);
333 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL PresenterCanvas::strokePolyPolygon (
334 const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
335 const css::rendering::ViewState& aViewState,
336 const css::rendering::RenderState& aRenderState,
337 const css::rendering::StrokeAttributes& aStrokeAttributes)
338 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException)
340 ThrowIfDisposed();
341 return mxSharedCanvas->strokePolyPolygon(
342 xPolyPolygon, MergeViewState(aViewState), aRenderState, aStrokeAttributes);
348 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
349 PresenterCanvas::strokeTexturedPolyPolygon (
350 const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
351 const css::rendering::ViewState& aViewState,
352 const css::rendering::RenderState& aRenderState,
353 const css::uno::Sequence< css::rendering::Texture >& aTextures,
354 const css::rendering::StrokeAttributes& aStrokeAttributes)
355 throw (css::lang::IllegalArgumentException,
356 css::rendering::VolatileContentDestroyedException,
357 css::uno::RuntimeException)
359 ThrowIfDisposed();
360 return mxSharedCanvas->strokeTexturedPolyPolygon(
361 xPolyPolygon, MergeViewState(aViewState), aRenderState, aTextures, aStrokeAttributes);
367 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
368 PresenterCanvas::strokeTextureMappedPolyPolygon(
369 const css::uno::Reference<css::rendering::XPolyPolygon2D >& xPolyPolygon,
370 const css::rendering::ViewState& aViewState,
371 const css::rendering::RenderState& aRenderState,
372 const css::uno::Sequence<css::rendering::Texture>& aTextures,
373 const css::uno::Reference<css::geometry::XMapping2D>& xMapping,
374 const css::rendering::StrokeAttributes& aStrokeAttributes)
375 throw (css::lang::IllegalArgumentException,
376 css::rendering::VolatileContentDestroyedException,
377 css::uno::RuntimeException)
379 ThrowIfDisposed();
380 return mxSharedCanvas->strokeTextureMappedPolyPolygon(
381 xPolyPolygon,
382 MergeViewState(aViewState),
383 aRenderState,
384 aTextures,
385 xMapping,
386 aStrokeAttributes);
392 css::uno::Reference<css::rendering::XPolyPolygon2D> SAL_CALL
393 PresenterCanvas::queryStrokeShapes(
394 const css::uno::Reference<css::rendering::XPolyPolygon2D>& xPolyPolygon,
395 const css::rendering::ViewState& aViewState,
396 const css::rendering::RenderState& aRenderState,
397 const css::rendering::StrokeAttributes& aStrokeAttributes)
398 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException)
400 ThrowIfDisposed();
401 return mxSharedCanvas->queryStrokeShapes(
402 xPolyPolygon, MergeViewState(aViewState), aRenderState, aStrokeAttributes);
408 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
409 PresenterCanvas::fillPolyPolygon(
410 const css::uno::Reference<css::rendering::XPolyPolygon2D>& xPolyPolygon,
411 const css::rendering::ViewState& aViewState,
412 const css::rendering::RenderState& aRenderState)
413 throw (css::lang::IllegalArgumentException,
414 css::uno::RuntimeException)
416 ThrowIfDisposed();
417 return mxSharedCanvas->fillPolyPolygon(
418 xPolyPolygon, MergeViewState(aViewState), aRenderState);
424 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
425 PresenterCanvas::fillTexturedPolyPolygon(
426 const css::uno::Reference<css::rendering::XPolyPolygon2D>& xPolyPolygon,
427 const css::rendering::ViewState& aViewState,
428 const css::rendering::RenderState& aRenderState,
429 const css::uno::Sequence<css::rendering::Texture>& xTextures)
430 throw (css::lang::IllegalArgumentException,
431 css::rendering::VolatileContentDestroyedException,
432 css::uno::RuntimeException)
434 ThrowIfDisposed();
435 return mxSharedCanvas->fillTexturedPolyPolygon(
436 xPolyPolygon, MergeViewState(aViewState), aRenderState, xTextures);
442 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
443 PresenterCanvas::fillTextureMappedPolyPolygon(
444 const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
445 const css::rendering::ViewState& aViewState,
446 const css::rendering::RenderState& aRenderState,
447 const css::uno::Sequence< css::rendering::Texture >& xTextures,
448 const css::uno::Reference< css::geometry::XMapping2D >& xMapping)
449 throw (css::lang::IllegalArgumentException,
450 css::rendering::VolatileContentDestroyedException,
451 css::uno::RuntimeException)
453 ThrowIfDisposed();
454 return mxSharedCanvas->fillTextureMappedPolyPolygon(
455 xPolyPolygon, MergeViewState(aViewState), aRenderState, xTextures, xMapping);
461 css::uno::Reference<css::rendering::XCanvasFont> SAL_CALL
462 PresenterCanvas::createFont(
463 const css::rendering::FontRequest& aFontRequest,
464 const css::uno::Sequence< css::beans::PropertyValue >& aExtraFontProperties,
465 const css::geometry::Matrix2D& aFontMatrix)
466 throw (css::lang::IllegalArgumentException,
467 css::uno::RuntimeException)
469 ThrowIfDisposed();
470 return mxSharedCanvas->createFont(
471 aFontRequest, aExtraFontProperties, aFontMatrix);
477 css::uno::Sequence<css::rendering::FontInfo> SAL_CALL
478 PresenterCanvas::queryAvailableFonts(
479 const css::rendering::FontInfo& aFilter,
480 const css::uno::Sequence< css::beans::PropertyValue >& aFontProperties)
481 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException)
483 ThrowIfDisposed();
484 return mxSharedCanvas->queryAvailableFonts(aFilter, aFontProperties);
490 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
491 PresenterCanvas::drawText(
492 const css::rendering::StringContext& aText,
493 const css::uno::Reference< css::rendering::XCanvasFont >& xFont,
494 const css::rendering::ViewState& aViewState,
495 const css::rendering::RenderState& aRenderState,
496 ::sal_Int8 nTextDirection)
497 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException)
499 ThrowIfDisposed();
500 return mxSharedCanvas->drawText(
501 aText, xFont, MergeViewState(aViewState), aRenderState, nTextDirection);
507 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
508 PresenterCanvas::drawTextLayout(
509 const css::uno::Reference< css::rendering::XTextLayout >& xLayoutetText,
510 const css::rendering::ViewState& aViewState,
511 const css::rendering::RenderState& aRenderState)
512 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException)
514 ThrowIfDisposed();
515 return mxSharedCanvas->drawTextLayout(
516 xLayoutetText, MergeViewState(aViewState), aRenderState);
522 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
523 PresenterCanvas::drawBitmap(
524 const css::uno::Reference< css::rendering::XBitmap >& xBitmap,
525 const css::rendering::ViewState& aViewState,
526 const css::rendering::RenderState& aRenderState)
527 throw (css::lang::IllegalArgumentException,
528 css::rendering::VolatileContentDestroyedException,
529 css::uno::RuntimeException)
531 ThrowIfDisposed();
532 return mxSharedCanvas->drawBitmap(
533 xBitmap, MergeViewState(aViewState), aRenderState);
539 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
540 PresenterCanvas::drawBitmapModulated(
541 const css::uno::Reference< css::rendering::XBitmap>& xBitmap,
542 const css::rendering::ViewState& aViewState,
543 const css::rendering::RenderState& aRenderState)
544 throw (css::lang::IllegalArgumentException,
545 css::rendering::VolatileContentDestroyedException,
546 css::uno::RuntimeException)
548 ThrowIfDisposed();
549 return mxSharedCanvas->drawBitmapModulated(
550 xBitmap, MergeViewState(aViewState), aRenderState);
556 css::uno::Reference<css::rendering::XGraphicDevice> SAL_CALL
557 PresenterCanvas::getDevice (void)
558 throw (css::uno::RuntimeException)
560 ThrowIfDisposed();
561 return mxSharedCanvas->getDevice();
567 //----- XBitmapCanvas ---------------------------------------------------------
569 void SAL_CALL PresenterCanvas::copyRect(
570 const css::uno::Reference<css::rendering::XBitmapCanvas>& rxSourceCanvas,
571 const css::geometry::RealRectangle2D& rSourceRect,
572 const css::rendering::ViewState& rSourceViewState,
573 const css::rendering::RenderState& rSourceRenderState,
574 const css::geometry::RealRectangle2D& rDestRect,
575 const css::rendering::ViewState& rDestViewState,
576 const css::rendering::RenderState& rDestRenderState)
577 throw (css::lang::IllegalArgumentException,
578 css::rendering::VolatileContentDestroyedException,
579 css::uno::RuntimeException)
581 ThrowIfDisposed();
583 Reference<rendering::XBitmapCanvas> xBitmapCanvas (mxSharedCanvas, UNO_QUERY);
584 if (xBitmapCanvas.is())
586 rendering::ViewState aSourceViewState (rSourceViewState);
587 if (rxSourceCanvas == Reference<rendering::XCanvas>(this))
588 aSourceViewState = MergeViewState(aSourceViewState);
589 xBitmapCanvas->copyRect(
590 rxSourceCanvas, rSourceRect, aSourceViewState, rSourceRenderState,
591 rDestRect, MergeViewState(rDestViewState), rDestRenderState);
598 //----- XSpriteCanvas ---------------------------------------------------------
600 Reference<rendering::XAnimatedSprite> SAL_CALL
601 PresenterCanvas::createSpriteFromAnimation (
602 const css::uno::Reference<css::rendering::XAnimation>& rAnimation)
603 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException)
605 ThrowIfDisposed();
607 Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxSharedCanvas, UNO_QUERY);
608 if (xSpriteCanvas.is())
609 return xSpriteCanvas->createSpriteFromAnimation(rAnimation);
610 else
611 return NULL;
617 Reference<rendering::XAnimatedSprite> SAL_CALL
618 PresenterCanvas::createSpriteFromBitmaps (
619 const css::uno::Sequence<
620 css::uno::Reference< css::rendering::XBitmap > >& rAnimationBitmaps,
621 ::sal_Int8 nInterpolationMode)
622 throw (css::lang::IllegalArgumentException,
623 css::rendering::VolatileContentDestroyedException,
624 css::uno::RuntimeException)
626 ThrowIfDisposed();
628 Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxSharedCanvas, UNO_QUERY);
629 if (xSpriteCanvas.is())
630 return xSpriteCanvas->createSpriteFromBitmaps(rAnimationBitmaps, nInterpolationMode);
631 else
632 return NULL;
638 Reference<rendering::XCustomSprite> SAL_CALL
639 PresenterCanvas::createCustomSprite (
640 const css::geometry::RealSize2D& rSpriteSize)
641 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException)
643 ThrowIfDisposed();
645 Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxSharedCanvas, UNO_QUERY);
646 if (xSpriteCanvas.is())
647 return new PresenterCustomSprite(
648 this,
649 xSpriteCanvas->createCustomSprite(rSpriteSize),
650 mxSharedWindow,
651 rSpriteSize);
652 else if (mxUpdateCanvas.is())
653 return new PresenterCustomSprite(
654 this,
655 mxUpdateCanvas->createCustomSprite(rSpriteSize),
656 mxUpdateWindow,
657 rSpriteSize);
658 else
659 return NULL;
665 Reference<rendering::XSprite> SAL_CALL
666 PresenterCanvas::createClonedSprite (
667 const css::uno::Reference< css::rendering::XSprite >& rxOriginal)
668 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException)
670 ThrowIfDisposed();
672 Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxSharedCanvas, UNO_QUERY);
673 if (xSpriteCanvas.is())
674 return xSpriteCanvas->createClonedSprite(rxOriginal);
675 if (mxUpdateCanvas.is())
676 return mxUpdateCanvas->createClonedSprite(rxOriginal);
677 return NULL;
683 ::sal_Bool SAL_CALL PresenterCanvas::updateScreen (::sal_Bool bUpdateAll)
684 throw (css::uno::RuntimeException)
686 ThrowIfDisposed();
688 mbOffsetUpdatePending = true;
689 if (mpUpdateRequester.get() != NULL)
691 mpUpdateRequester->RequestUpdate(bUpdateAll);
692 return sal_True;
694 else
696 return sal_False;
703 //----- XEventListener --------------------------------------------------------
705 void SAL_CALL PresenterCanvas::disposing (const css::lang::EventObject& rEvent)
706 throw (css::uno::RuntimeException)
708 ThrowIfDisposed();
709 if (rEvent.Source == mxWindow)
710 mxWindow = NULL;
716 //----- XWindowListener -------------------------------------------------------
718 void SAL_CALL PresenterCanvas::windowResized (const css::awt::WindowEvent& rEvent)
719 throw (css::uno::RuntimeException)
721 (void)rEvent;
722 ThrowIfDisposed();
723 mbOffsetUpdatePending = true;
729 void SAL_CALL PresenterCanvas::windowMoved (const css::awt::WindowEvent& rEvent)
730 throw (css::uno::RuntimeException)
732 (void)rEvent;
733 ThrowIfDisposed();
734 mbOffsetUpdatePending = true;
740 void SAL_CALL PresenterCanvas::windowShown (const css::lang::EventObject& rEvent)
741 throw (css::uno::RuntimeException)
743 (void)rEvent;
744 ThrowIfDisposed();
745 mbOffsetUpdatePending = true;
751 void SAL_CALL PresenterCanvas::windowHidden (const css::lang::EventObject& rEvent)
752 throw (css::uno::RuntimeException)
754 (void)rEvent;
755 ThrowIfDisposed();
761 //----- XBitmap ---------------------------------------------------------------
763 geometry::IntegerSize2D SAL_CALL PresenterCanvas::getSize (void)
764 throw (RuntimeException)
766 ThrowIfDisposed();
768 if (mxWindow.is())
770 const awt::Rectangle aWindowBox (mxWindow->getPosSize());
771 return geometry::IntegerSize2D(aWindowBox.Width, aWindowBox.Height);
773 else
774 return geometry::IntegerSize2D(0,0);
780 sal_Bool SAL_CALL PresenterCanvas::hasAlpha (void)
781 throw (RuntimeException)
783 Reference<rendering::XBitmap> xBitmap (mxSharedCanvas, UNO_QUERY);
784 if (xBitmap.is())
785 return xBitmap->hasAlpha();
786 else
787 return sal_False;
793 Reference<rendering::XBitmapCanvas> SAL_CALL PresenterCanvas::queryBitmapCanvas (void)
794 throw (RuntimeException)
796 ThrowIfDisposed();
798 return this;
804 Reference<rendering::XBitmap> SAL_CALL PresenterCanvas::getScaledBitmap(
805 const css::geometry::RealSize2D& rNewSize,
806 sal_Bool bFast)
807 throw (css::uno::RuntimeException,
808 css::lang::IllegalArgumentException,
809 css::rendering::VolatileContentDestroyedException)
811 (void)rNewSize;
812 (void)bFast;
814 ThrowIfDisposed();
816 // Not implemented.
818 return NULL;
824 //-----------------------------------------------------------------------------
826 rendering::ViewState PresenterCanvas::MergeViewState (
827 const rendering::ViewState& rViewState)
829 // Make sure the offset is up-to-date.
830 if (mbOffsetUpdatePending)
831 maOffset = GetOffset(mxSharedWindow);
832 return MergeViewState(rViewState, maOffset);
838 css::rendering::ViewState PresenterCanvas::MergeViewState (
839 const css::rendering::ViewState& rViewState,
840 const css::awt::Point& rOffset)
842 // Early rejects.
843 if ( ! mxSharedCanvas.is())
844 return rViewState;
846 Reference<rendering::XGraphicDevice> xDevice (mxSharedCanvas->getDevice());
847 if ( ! xDevice.is())
848 return rViewState;
850 // Create a modifiable copy of the given view state.
851 rendering::ViewState aViewState (rViewState);
853 // Prepare the local clip rectangle.
854 ::basegfx::B2DRectangle aWindowRange (GetClipRectangle(aViewState.AffineTransform, rOffset));
856 // Adapt the offset of the view state.
857 aViewState.AffineTransform.m02 += rOffset.X;
858 aViewState.AffineTransform.m12 += rOffset.Y;
860 // Adapt the clip polygon.
861 if ( ! aViewState.Clip.is())
863 // Cancel out the later multiplication with the view state
864 // transformation.
865 aViewState.Clip = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
866 xDevice,
867 ::basegfx::B2DPolyPolygon(::basegfx::tools::createPolygonFromRect(aWindowRange)));
869 else
871 // Have to compute the intersection of the given clipping polygon in
872 // the view state and the local clip rectangle.
874 // Clip the view state clipping polygon against the local clip rectangle.
875 const ::basegfx::B2DPolyPolygon aClipPolygon (
876 ::basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(
877 aViewState.Clip));
878 const ::basegfx::B2DPolyPolygon aClippedClipPolygon (
879 ::basegfx::tools::clipPolyPolygonOnRange(
880 aClipPolygon,
881 aWindowRange,
882 true, /* bInside */
883 false /* bStroke */));
885 aViewState.Clip = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
886 xDevice,
887 aClippedClipPolygon);
890 return aViewState;
896 awt::Point PresenterCanvas::GetOffset (const Reference<awt::XWindow>& rxBaseWindow)
898 mbOffsetUpdatePending = false;
899 if (mxWindow.is() && rxBaseWindow.is())
901 ::Window* pWindow = VCLUnoHelper::GetWindow(mxWindow);
902 ::Window* pSharedWindow = VCLUnoHelper::GetWindow(rxBaseWindow);
903 if (pWindow!=NULL && pSharedWindow!=NULL)
905 Rectangle aBox = pWindow->GetWindowExtentsRelative(pSharedWindow);
907 // Calculate offset of this canvas with respect to the shared
908 // canvas.
909 return awt::Point(aBox.Left(), aBox.Top());
913 return awt::Point(0, 0);
919 ::basegfx::B2DRectangle PresenterCanvas::GetClipRectangle (
920 const css::geometry::AffineMatrix2D& rViewTransform,
921 const awt::Point& rOffset)
923 ::basegfx::B2DRectangle aClipRectangle;
925 ::Window* pWindow = VCLUnoHelper::GetWindow(mxWindow);
926 if (pWindow == NULL)
927 return ::basegfx::B2DRectangle();
929 ::Window* pSharedWindow = VCLUnoHelper::GetWindow(mxSharedWindow);
930 if (pSharedWindow == NULL)
931 return ::basegfx::B2DRectangle();
933 // Get the bounding box of the window and create a range in the
934 // coordinate system of the child window.
935 Rectangle aLocalClip;
936 if (maClipRectangle.Width <= 0 || maClipRectangle.Height <= 0)
938 // No clip rectangle has been set via SetClip by the pane.
939 // Use the window extents instead.
940 aLocalClip = pWindow->GetWindowExtentsRelative(pSharedWindow);
942 else
944 // Use a previously given clip rectangle.
945 aLocalClip = Rectangle(
946 maClipRectangle.X + rOffset.X,
947 maClipRectangle.Y + rOffset.Y,
948 maClipRectangle.X + maClipRectangle.Width + rOffset.X,
949 maClipRectangle.Y + maClipRectangle.Height + rOffset.Y);
952 // The local clip rectangle is used to clip the view state clipping
953 // polygon.
954 ::basegfx::B2DRectangle aWindowRectangle (
955 aLocalClip.Left() - rOffset.X,
956 aLocalClip.Top() - rOffset.Y,
957 aLocalClip.Right() - rOffset.X + 1,
958 aLocalClip.Bottom() - rOffset.Y + 1);
960 // Calculate the inverted view state transformation to cancel out a
961 // later transformation of the local clip polygon with the view state
962 // transformation.
963 ::basegfx::B2DHomMatrix aInvertedViewStateTransformation;
964 ::basegfx::unotools::homMatrixFromAffineMatrix(
965 aInvertedViewStateTransformation,
966 rViewTransform);
967 if (aInvertedViewStateTransformation.invert())
969 // Cancel out the later multiplication with the view state
970 // transformation.
971 aWindowRectangle.transform(aInvertedViewStateTransformation);
974 return aWindowRectangle;
979 Reference<rendering::XPolyPolygon2D> PresenterCanvas::UpdateSpriteClip (
980 const Reference<rendering::XPolyPolygon2D>& rxOriginalClip,
981 const geometry::RealPoint2D& rLocation,
982 const geometry::RealSize2D& rSize)
984 (void)rSize;
986 // Check used resources and just return the original clip when not
987 // every one of them is available.
988 if ( ! mxWindow.is())
989 return rxOriginalClip;
991 Reference<rendering::XGraphicDevice> xDevice (mxSharedCanvas->getDevice());
992 if ( ! xDevice.is())
993 return rxOriginalClip;
995 // Determine the bounds of the clip rectangle (the window border) in the
996 // coordinate system of the sprite.
997 const awt::Rectangle aWindowBox (mxWindow->getPosSize());
998 const double nMinX (-rLocation.X);
999 const double nMinY (-rLocation.Y);
1000 const double nMaxX (aWindowBox.Width-rLocation.X);
1001 const double nMaxY (aWindowBox.Height-rLocation.Y);
1003 // Create a clip polygon.
1004 Reference<rendering::XPolyPolygon2D> xPolygon;
1005 if (rxOriginalClip.is())
1007 // Combine the original clip with the window clip.
1008 const ::basegfx::B2DPolyPolygon aOriginalClip (
1009 ::basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(rxOriginalClip));
1010 ::basegfx::B2DRectangle aWindowRange (nMinX, nMinY, nMaxX, nMaxY);
1011 const ::basegfx::B2DPolyPolygon aClippedClipPolygon (
1012 ::basegfx::tools::clipPolyPolygonOnRange(
1013 aOriginalClip,
1014 aWindowRange,
1015 true, /* bInside */
1016 false /* bStroke */));
1017 xPolygon = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
1018 xDevice,
1019 aClippedClipPolygon);
1021 else
1023 // Create a new clip polygon from the window clip rectangle.
1024 Sequence<Sequence<geometry::RealPoint2D> > aPoints (1);
1025 aPoints[0] = Sequence<geometry::RealPoint2D>(4);
1026 aPoints[0][0] = geometry::RealPoint2D(nMinX,nMinY);
1027 aPoints[0][1] = geometry::RealPoint2D(nMaxX,nMinY);
1028 aPoints[0][2] = geometry::RealPoint2D(nMaxX,nMaxY);
1029 aPoints[0][3] = geometry::RealPoint2D(nMinX,nMaxY);
1030 Reference<rendering::XLinePolyPolygon2D> xLinePolygon(
1031 xDevice->createCompatibleLinePolyPolygon(aPoints));
1032 if (xLinePolygon.is())
1033 xLinePolygon->setClosed(0, sal_True);
1034 xPolygon = Reference<rendering::XPolyPolygon2D>(xLinePolygon, UNO_QUERY);
1037 return xPolygon;
1043 void PresenterCanvas::ThrowIfDisposed (void)
1044 throw (css::lang::DisposedException)
1046 if (rBHelper.bDisposed || rBHelper.bInDispose || ! mxSharedCanvas.is())
1048 throw lang::DisposedException ("PresenterCanvas object has already been disposed",
1049 static_cast<uno::XWeak*>(this));
1056 //===== PresenterCustomSprite =================================================
1059 PresenterCustomSprite::PresenterCustomSprite (
1060 const rtl::Reference<PresenterCanvas>& rpCanvas,
1061 const Reference<rendering::XCustomSprite>& rxSprite,
1062 const Reference<awt::XWindow>& rxBaseWindow,
1063 const css::geometry::RealSize2D& rSpriteSize)
1064 : PresenterCustomSpriteInterfaceBase(m_aMutex),
1065 mpCanvas(rpCanvas),
1066 mxSprite(rxSprite),
1067 mxBaseWindow(rxBaseWindow),
1068 maPosition(0,0),
1069 maSpriteSize(rSpriteSize)
1076 PresenterCustomSprite::~PresenterCustomSprite (void)
1083 void SAL_CALL PresenterCustomSprite::disposing (void)
1084 throw (RuntimeException)
1086 Reference<XComponent> xComponent (mxSprite, UNO_QUERY);
1087 mxSprite = NULL;
1088 if (xComponent.is())
1089 xComponent->dispose();
1090 mpCanvas = rtl::Reference<PresenterCanvas>();
1096 //----- XSprite ---------------------------------------------------------------
1098 void SAL_CALL PresenterCustomSprite::setAlpha (const double nAlpha)
1099 throw (lang::IllegalArgumentException,RuntimeException)
1101 ThrowIfDisposed();
1102 mxSprite->setAlpha(nAlpha);
1108 void SAL_CALL PresenterCustomSprite::move (
1109 const geometry::RealPoint2D& rNewPos,
1110 const rendering::ViewState& rViewState,
1111 const rendering::RenderState& rRenderState)
1112 throw (lang::IllegalArgumentException,RuntimeException)
1114 ThrowIfDisposed();
1115 maPosition = rNewPos;
1116 mxSprite->move(
1117 rNewPos,
1118 mpCanvas->MergeViewState(rViewState, mpCanvas->GetOffset(mxBaseWindow)),
1119 rRenderState);
1120 // Clip sprite against window bounds. This call is necessary because
1121 // sprite clipping is done in the corrdinate system of the sprite.
1122 // Therefore, after each change of the sprites location the window
1123 // bounds have to be transformed into the sprites coordinate system.
1124 clip(NULL);
1130 void SAL_CALL PresenterCustomSprite::transform (const geometry::AffineMatrix2D& rTransformation)
1131 throw (lang::IllegalArgumentException,RuntimeException)
1133 ThrowIfDisposed();
1134 mxSprite->transform(rTransformation);
1140 void SAL_CALL PresenterCustomSprite::clip (const Reference<rendering::XPolyPolygon2D>& rxClip)
1141 throw (RuntimeException)
1143 ThrowIfDisposed();
1144 // The clip region is expected in the coordinate system of the sprite.
1145 // UpdateSpriteClip() integrates the window bounds, transformed into the
1146 // sprites coordinate system, with the given clip.
1147 mxSprite->clip(mpCanvas->UpdateSpriteClip(rxClip, maPosition, maSpriteSize));
1153 void SAL_CALL PresenterCustomSprite::setPriority (const double nPriority)
1154 throw (RuntimeException)
1156 ThrowIfDisposed();
1157 mxSprite->setPriority(nPriority);
1162 void SAL_CALL PresenterCustomSprite::show (void)
1163 throw (RuntimeException)
1165 ThrowIfDisposed();
1166 mxSprite->show();
1172 void SAL_CALL PresenterCustomSprite::hide (void)
1173 throw (RuntimeException)
1175 ThrowIfDisposed();
1176 mxSprite->hide();
1182 //----- XCustomSprite ---------------------------------------------------------
1184 Reference<rendering::XCanvas> PresenterCustomSprite::getContentCanvas (void)
1185 throw (RuntimeException)
1187 ThrowIfDisposed();
1188 return mxSprite->getContentCanvas();
1194 //-----------------------------------------------------------------------------
1196 void PresenterCustomSprite::ThrowIfDisposed (void)
1197 throw (css::lang::DisposedException)
1199 if (rBHelper.bDisposed || rBHelper.bInDispose || ! mxSprite.is())
1201 throw lang::DisposedException ("PresenterCustomSprite object has already been disposed",
1202 static_cast<uno::XWeak*>(this));
1209 } } // end of namespace ::sd::presenter
1211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */