1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PresenterCanvas.cxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include "precompiled_sd.hxx"
34 #include "PresenterCanvas.hxx"
36 #include <basegfx/matrix/b2dhommatrix.hxx>
37 #include <basegfx/polygon/b2dpolygontools.hxx>
38 #include <basegfx/polygon/b2dpolypolygon.hxx>
39 #include <basegfx/polygon/b2dpolygonclipper.hxx>
40 #include <basegfx/range/b2drectangle.hxx>
41 #include <basegfx/tools/canvastools.hxx>
42 #include <canvas/canvastools.hxx>
43 #include <cppuhelper/basemutex.hxx>
44 #include <cppuhelper/compbase1.hxx>
45 #include <rtl/ref.hxx>
46 #include <toolkit/helper/vclunohelper.hxx>
47 #include <vcl/window.hxx>
48 #include <vcl/svapp.hxx>
50 using namespace ::com::sun::star
;
51 using namespace ::com::sun::star::uno
;
52 using ::rtl::OUString
;
54 namespace sd
{ namespace presenter
{
56 //===== Service ===============================================================
58 Reference
<XInterface
> SAL_CALL
PresenterCanvas_createInstance (
59 const Reference
<XComponentContext
>& rxContext
)
62 return Reference
<XInterface
>(static_cast<XWeak
*>(new PresenterCanvas()));
68 ::rtl::OUString
PresenterCanvas_getImplementationName (void) throw(RuntimeException
)
70 return OUString::createFromAscii("com.sun.star.comp.Draw.PresenterCanvasFactory");
76 Sequence
<rtl::OUString
> SAL_CALL
PresenterCanvas_getSupportedServiceNames (void)
77 throw (RuntimeException
)
79 static const ::rtl::OUString
sServiceName(
80 ::rtl::OUString::createFromAscii("com.sun.star.rendering.Canvas"));
81 return Sequence
<rtl::OUString
>(&sServiceName
, 1);
87 //===== PresenterCustomSprite =================================================
89 /** Wrapper around a sprite that is displayed on a PresenterCanvas.
92 typedef ::cppu::WeakComponentImplHelper1
<
93 css::rendering::XCustomSprite
94 > PresenterCustomSpriteInterfaceBase
;
96 class PresenterCustomSprite
97 : private ::boost::noncopyable
,
98 protected ::cppu::BaseMutex
,
99 public PresenterCustomSpriteInterfaceBase
102 PresenterCustomSprite (
103 const rtl::Reference
<PresenterCanvas
>& rpCanvas
,
104 const Reference
<rendering::XCustomSprite
>& rxSprite
,
105 const Reference
<awt::XWindow
>& rxBaseWindow
,
106 const css::geometry::RealSize2D
& rSpriteSize
);
107 virtual ~PresenterCustomSprite (void);
108 virtual void SAL_CALL
disposing (void)
109 throw (RuntimeException
);
113 virtual void SAL_CALL
setAlpha (double nAlpha
)
114 throw (lang::IllegalArgumentException
,RuntimeException
);
116 virtual void SAL_CALL
move (const geometry::RealPoint2D
& rNewPos
,
117 const rendering::ViewState
& rViewState
,
118 const rendering::RenderState
& rRenderState
)
119 throw (lang::IllegalArgumentException
,RuntimeException
);
121 virtual void SAL_CALL
transform (const geometry::AffineMatrix2D
& rTransformation
)
122 throw (lang::IllegalArgumentException
,RuntimeException
);
124 virtual void SAL_CALL
clip (const Reference
<rendering::XPolyPolygon2D
>& rClip
)
125 throw (RuntimeException
);
127 virtual void SAL_CALL
setPriority (double nPriority
)
128 throw (RuntimeException
);
130 virtual void SAL_CALL
show (void)
131 throw (RuntimeException
);
133 virtual void SAL_CALL
hide (void)
134 throw (RuntimeException
);
139 virtual Reference
<rendering::XCanvas
> SAL_CALL
getContentCanvas (void)
140 throw (RuntimeException
);
143 rtl::Reference
<PresenterCanvas
> mpCanvas
;
144 Reference
<rendering::XCustomSprite
> mxSprite
;
145 Reference
<awt::XWindow
> mxBaseWindow
;
146 geometry::RealPoint2D maPosition
;
147 geometry::RealSize2D maSpriteSize
;
149 void ThrowIfDisposed (void)
150 throw (css::lang::DisposedException
);
156 //===== PresenterCanvas =======================================================
159 PresenterCanvas::PresenterCanvas (void)
160 : PresenterCanvasInterfaceBase(m_aMutex
),
168 mbOffsetUpdatePending(true)
175 PresenterCanvas::PresenterCanvas (
176 const Reference
<rendering::XSpriteCanvas
>& rxUpdateCanvas
,
177 const Reference
<awt::XWindow
>& rxUpdateWindow
,
178 const Reference
<rendering::XCanvas
>& rxSharedCanvas
,
179 const Reference
<awt::XWindow
>& rxSharedWindow
,
180 const Reference
<awt::XWindow
>& rxWindow
)
181 : PresenterCanvasInterfaceBase(m_aMutex
),
182 mxUpdateCanvas(rxUpdateCanvas
),
183 mxUpdateWindow(rxUpdateWindow
),
184 mxSharedCanvas(rxSharedCanvas
),
185 mxSharedWindow(rxSharedWindow
),
190 mbOffsetUpdatePending(true)
193 mxWindow
->addWindowListener(this);
195 if (mxUpdateCanvas
.is())
196 mpUpdateRequester
= CanvasUpdateRequester::Instance(mxUpdateCanvas
);
202 PresenterCanvas::~PresenterCanvas (void)
209 void SAL_CALL
PresenterCanvas::disposing (void)
210 throw (css::uno::RuntimeException
)
213 mxWindow
->removeWindowListener(this);
219 //----- XInitialization -------------------------------------------------------
221 void SAL_CALL
PresenterCanvas::initialize (
222 const Sequence
<Any
>& rArguments
)
223 throw(Exception
, RuntimeException
)
225 if (rBHelper
.bDisposed
|| rBHelper
.bInDispose
)
228 if (rArguments
.getLength() == 5)
232 // First and second argument may be NULL.
233 rArguments
[0] >>= mxUpdateCanvas
;
234 rArguments
[1] >>= mxUpdateWindow
;
236 if ( ! (rArguments
[2] >>= mxSharedWindow
))
238 throw lang::IllegalArgumentException(
239 OUString::createFromAscii("PresenterCanvas: invalid shared window"),
240 static_cast<XWeak
*>(this),
244 if ( ! (rArguments
[3] >>= mxSharedCanvas
))
246 throw lang::IllegalArgumentException(
247 OUString::createFromAscii("PresenterCanvas: invalid shared canvas"),
248 static_cast<XWeak
*>(this),
252 if ( ! (rArguments
[4] >>= mxWindow
))
254 throw lang::IllegalArgumentException(
255 OUString::createFromAscii("PresenterCanvas: invalid window"),
256 static_cast<XWeak
*>(this),
260 mpUpdateRequester
= CanvasUpdateRequester::Instance(mxUpdateCanvas
);
262 mbOffsetUpdatePending
= true;
264 mxWindow
->addWindowListener(this);
266 catch (RuntimeException
&)
268 mxSharedWindow
= NULL
;
275 throw RuntimeException(
276 OUString::createFromAscii("PresenterCanvas: invalid number of arguments"),
277 static_cast<XWeak
*>(this));
284 //----- XCanvas ---------------------------------------------------------------
286 void SAL_CALL
PresenterCanvas::clear (void)
287 throw (css::uno::RuntimeException
)
290 // ToDo: Clear the area covered by the child window. A simple forward
291 // would clear the whole shared canvas.
297 void SAL_CALL
PresenterCanvas::drawPoint (
298 const css::geometry::RealPoint2D
& aPoint
,
299 const css::rendering::ViewState
& aViewState
,
300 const css::rendering::RenderState
& aRenderState
)
301 throw (css::lang::IllegalArgumentException
, css::uno::RuntimeException
)
304 mxSharedCanvas
->drawPoint(aPoint
,MergeViewState(aViewState
),aRenderState
);
310 void SAL_CALL
PresenterCanvas::drawLine (
311 const css::geometry::RealPoint2D
& aStartPoint
,
312 const css::geometry::RealPoint2D
& aEndPoint
,
313 const css::rendering::ViewState
& aViewState
,
314 const css::rendering::RenderState
& aRenderState
)
315 throw (css::lang::IllegalArgumentException
, css::uno::RuntimeException
)
318 mxSharedCanvas
->drawLine(aStartPoint
,aEndPoint
,MergeViewState(aViewState
),aRenderState
);
324 void SAL_CALL
PresenterCanvas::drawBezier (
325 const css::geometry::RealBezierSegment2D
& aBezierSegment
,
326 const css::geometry::RealPoint2D
& aEndPoint
,
327 const css::rendering::ViewState
& aViewState
,
328 const css::rendering::RenderState
& aRenderState
)
329 throw (css::lang::IllegalArgumentException
, css::uno::RuntimeException
)
332 mxSharedCanvas
->drawBezier(aBezierSegment
,aEndPoint
,MergeViewState(aViewState
),aRenderState
);
338 css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
PresenterCanvas::drawPolyPolygon (
339 const css::uno::Reference
< css::rendering::XPolyPolygon2D
>& xPolyPolygon
,
340 const css::rendering::ViewState
& aViewState
,
341 const css::rendering::RenderState
& aRenderState
)
342 throw (css::lang::IllegalArgumentException
, css::uno::RuntimeException
)
345 return mxSharedCanvas
->drawPolyPolygon(
346 xPolyPolygon
, MergeViewState(aViewState
), aRenderState
);
352 css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
PresenterCanvas::strokePolyPolygon (
353 const css::uno::Reference
< css::rendering::XPolyPolygon2D
>& xPolyPolygon
,
354 const css::rendering::ViewState
& aViewState
,
355 const css::rendering::RenderState
& aRenderState
,
356 const css::rendering::StrokeAttributes
& aStrokeAttributes
)
357 throw (css::lang::IllegalArgumentException
, css::uno::RuntimeException
)
360 return mxSharedCanvas
->strokePolyPolygon(
361 xPolyPolygon
, MergeViewState(aViewState
), aRenderState
, aStrokeAttributes
);
367 css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
368 PresenterCanvas::strokeTexturedPolyPolygon (
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::rendering::StrokeAttributes
& aStrokeAttributes
)
374 throw (css::lang::IllegalArgumentException
,
375 css::rendering::VolatileContentDestroyedException
,
376 css::uno::RuntimeException
)
379 return mxSharedCanvas
->strokeTexturedPolyPolygon(
380 xPolyPolygon
, MergeViewState(aViewState
), aRenderState
, aTextures
, aStrokeAttributes
);
386 css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
387 PresenterCanvas::strokeTextureMappedPolyPolygon(
388 const css::uno::Reference
<css::rendering::XPolyPolygon2D
>& xPolyPolygon
,
389 const css::rendering::ViewState
& aViewState
,
390 const css::rendering::RenderState
& aRenderState
,
391 const css::uno::Sequence
<css::rendering::Texture
>& aTextures
,
392 const css::uno::Reference
<css::geometry::XMapping2D
>& xMapping
,
393 const css::rendering::StrokeAttributes
& aStrokeAttributes
)
394 throw (css::lang::IllegalArgumentException
,
395 css::rendering::VolatileContentDestroyedException
,
396 css::uno::RuntimeException
)
399 return mxSharedCanvas
->strokeTextureMappedPolyPolygon(
401 MergeViewState(aViewState
),
411 css::uno::Reference
<css::rendering::XPolyPolygon2D
> SAL_CALL
412 PresenterCanvas::queryStrokeShapes(
413 const css::uno::Reference
<css::rendering::XPolyPolygon2D
>& xPolyPolygon
,
414 const css::rendering::ViewState
& aViewState
,
415 const css::rendering::RenderState
& aRenderState
,
416 const css::rendering::StrokeAttributes
& aStrokeAttributes
)
417 throw (css::lang::IllegalArgumentException
, css::uno::RuntimeException
)
420 return mxSharedCanvas
->queryStrokeShapes(
421 xPolyPolygon
, MergeViewState(aViewState
), aRenderState
, aStrokeAttributes
);
427 css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
428 PresenterCanvas::fillPolyPolygon(
429 const css::uno::Reference
<css::rendering::XPolyPolygon2D
>& xPolyPolygon
,
430 const css::rendering::ViewState
& aViewState
,
431 const css::rendering::RenderState
& aRenderState
)
432 throw (css::lang::IllegalArgumentException
,
433 css::uno::RuntimeException
)
436 return mxSharedCanvas
->fillPolyPolygon(
437 xPolyPolygon
, MergeViewState(aViewState
), aRenderState
);
443 css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
444 PresenterCanvas::fillTexturedPolyPolygon(
445 const css::uno::Reference
<css::rendering::XPolyPolygon2D
>& xPolyPolygon
,
446 const css::rendering::ViewState
& aViewState
,
447 const css::rendering::RenderState
& aRenderState
,
448 const css::uno::Sequence
<css::rendering::Texture
>& xTextures
)
449 throw (css::lang::IllegalArgumentException
,
450 css::rendering::VolatileContentDestroyedException
,
451 css::uno::RuntimeException
)
454 return mxSharedCanvas
->fillTexturedPolyPolygon(
455 xPolyPolygon
, MergeViewState(aViewState
), aRenderState
, xTextures
);
461 css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
462 PresenterCanvas::fillTextureMappedPolyPolygon(
463 const css::uno::Reference
< css::rendering::XPolyPolygon2D
>& xPolyPolygon
,
464 const css::rendering::ViewState
& aViewState
,
465 const css::rendering::RenderState
& aRenderState
,
466 const css::uno::Sequence
< css::rendering::Texture
>& xTextures
,
467 const css::uno::Reference
< css::geometry::XMapping2D
>& xMapping
)
468 throw (css::lang::IllegalArgumentException
,
469 css::rendering::VolatileContentDestroyedException
,
470 css::uno::RuntimeException
)
473 return mxSharedCanvas
->fillTextureMappedPolyPolygon(
474 xPolyPolygon
, MergeViewState(aViewState
), aRenderState
, xTextures
, xMapping
);
480 css::uno::Reference
<css::rendering::XCanvasFont
> SAL_CALL
481 PresenterCanvas::createFont(
482 const css::rendering::FontRequest
& aFontRequest
,
483 const css::uno::Sequence
< css::beans::PropertyValue
>& aExtraFontProperties
,
484 const css::geometry::Matrix2D
& aFontMatrix
)
485 throw (css::lang::IllegalArgumentException
,
486 css::uno::RuntimeException
)
489 return mxSharedCanvas
->createFont(
490 aFontRequest
, aExtraFontProperties
, aFontMatrix
);
496 css::uno::Sequence
<css::rendering::FontInfo
> SAL_CALL
497 PresenterCanvas::queryAvailableFonts(
498 const css::rendering::FontInfo
& aFilter
,
499 const css::uno::Sequence
< css::beans::PropertyValue
>& aFontProperties
)
500 throw (css::lang::IllegalArgumentException
, css::uno::RuntimeException
)
503 return mxSharedCanvas
->queryAvailableFonts(aFilter
, aFontProperties
);
509 css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
510 PresenterCanvas::drawText(
511 const css::rendering::StringContext
& aText
,
512 const css::uno::Reference
< css::rendering::XCanvasFont
>& xFont
,
513 const css::rendering::ViewState
& aViewState
,
514 const css::rendering::RenderState
& aRenderState
,
515 ::sal_Int8 nTextDirection
)
516 throw (css::lang::IllegalArgumentException
, css::uno::RuntimeException
)
519 return mxSharedCanvas
->drawText(
520 aText
, xFont
, MergeViewState(aViewState
), aRenderState
, nTextDirection
);
526 css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
527 PresenterCanvas::drawTextLayout(
528 const css::uno::Reference
< css::rendering::XTextLayout
>& xLayoutetText
,
529 const css::rendering::ViewState
& aViewState
,
530 const css::rendering::RenderState
& aRenderState
)
531 throw (css::lang::IllegalArgumentException
, css::uno::RuntimeException
)
534 return mxSharedCanvas
->drawTextLayout(
535 xLayoutetText
, MergeViewState(aViewState
), aRenderState
);
541 css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
542 PresenterCanvas::drawBitmap(
543 const css::uno::Reference
< css::rendering::XBitmap
>& xBitmap
,
544 const css::rendering::ViewState
& aViewState
,
545 const css::rendering::RenderState
& aRenderState
)
546 throw (css::lang::IllegalArgumentException
,
547 css::rendering::VolatileContentDestroyedException
,
548 css::uno::RuntimeException
)
551 return mxSharedCanvas
->drawBitmap(
552 xBitmap
, MergeViewState(aViewState
), aRenderState
);
558 css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
559 PresenterCanvas::drawBitmapModulated(
560 const css::uno::Reference
< css::rendering::XBitmap
>& xBitmap
,
561 const css::rendering::ViewState
& aViewState
,
562 const css::rendering::RenderState
& aRenderState
)
563 throw (css::lang::IllegalArgumentException
,
564 css::rendering::VolatileContentDestroyedException
,
565 css::uno::RuntimeException
)
568 return mxSharedCanvas
->drawBitmapModulated(
569 xBitmap
, MergeViewState(aViewState
), aRenderState
);
575 css::uno::Reference
<css::rendering::XGraphicDevice
> SAL_CALL
576 PresenterCanvas::getDevice (void)
577 throw (css::uno::RuntimeException
)
580 return mxSharedCanvas
->getDevice();
586 //----- XBitmapCanvas ---------------------------------------------------------
588 void SAL_CALL
PresenterCanvas::copyRect(
589 const css::uno::Reference
<css::rendering::XBitmapCanvas
>& rxSourceCanvas
,
590 const css::geometry::RealRectangle2D
& rSourceRect
,
591 const css::rendering::ViewState
& rSourceViewState
,
592 const css::rendering::RenderState
& rSourceRenderState
,
593 const css::geometry::RealRectangle2D
& rDestRect
,
594 const css::rendering::ViewState
& rDestViewState
,
595 const css::rendering::RenderState
& rDestRenderState
)
596 throw (css::lang::IllegalArgumentException
,
597 css::rendering::VolatileContentDestroyedException
,
598 css::uno::RuntimeException
)
602 Reference
<rendering::XBitmapCanvas
> xBitmapCanvas (mxSharedCanvas
, UNO_QUERY
);
603 if (xBitmapCanvas
.is())
605 rendering::ViewState
aSourceViewState (rSourceViewState
);
606 if (rxSourceCanvas
== Reference
<rendering::XCanvas
>(this))
607 aSourceViewState
= MergeViewState(aSourceViewState
);
608 xBitmapCanvas
->copyRect(
609 rxSourceCanvas
, rSourceRect
, aSourceViewState
, rSourceRenderState
,
610 rDestRect
, MergeViewState(rDestViewState
), rDestRenderState
);
617 //----- XSpriteCanvas ---------------------------------------------------------
619 Reference
<rendering::XAnimatedSprite
> SAL_CALL
620 PresenterCanvas::createSpriteFromAnimation (
621 const css::uno::Reference
<css::rendering::XAnimation
>& rAnimation
)
622 throw (css::lang::IllegalArgumentException
, css::uno::RuntimeException
)
626 Reference
<rendering::XSpriteCanvas
> xSpriteCanvas (mxSharedCanvas
, UNO_QUERY
);
627 if (xSpriteCanvas
.is())
628 return xSpriteCanvas
->createSpriteFromAnimation(rAnimation
);
636 Reference
<rendering::XAnimatedSprite
> SAL_CALL
637 PresenterCanvas::createSpriteFromBitmaps (
638 const css::uno::Sequence
<
639 css::uno::Reference
< css::rendering::XBitmap
> >& rAnimationBitmaps
,
640 ::sal_Int8 nInterpolationMode
)
641 throw (css::lang::IllegalArgumentException
,
642 css::rendering::VolatileContentDestroyedException
,
643 css::uno::RuntimeException
)
647 Reference
<rendering::XSpriteCanvas
> xSpriteCanvas (mxSharedCanvas
, UNO_QUERY
);
648 if (xSpriteCanvas
.is())
649 return xSpriteCanvas
->createSpriteFromBitmaps(rAnimationBitmaps
, nInterpolationMode
);
657 Reference
<rendering::XCustomSprite
> SAL_CALL
658 PresenterCanvas::createCustomSprite (
659 const css::geometry::RealSize2D
& rSpriteSize
)
660 throw (css::lang::IllegalArgumentException
, css::uno::RuntimeException
)
664 Reference
<rendering::XSpriteCanvas
> xSpriteCanvas (mxSharedCanvas
, UNO_QUERY
);
665 if (xSpriteCanvas
.is())
666 return new PresenterCustomSprite(
668 xSpriteCanvas
->createCustomSprite(rSpriteSize
),
671 else if (mxUpdateCanvas
.is())
672 return new PresenterCustomSprite(
674 mxUpdateCanvas
->createCustomSprite(rSpriteSize
),
684 Reference
<rendering::XSprite
> SAL_CALL
685 PresenterCanvas::createClonedSprite (
686 const css::uno::Reference
< css::rendering::XSprite
>& rxOriginal
)
687 throw (css::lang::IllegalArgumentException
, css::uno::RuntimeException
)
691 Reference
<rendering::XSpriteCanvas
> xSpriteCanvas (mxSharedCanvas
, UNO_QUERY
);
692 if (xSpriteCanvas
.is())
693 return xSpriteCanvas
->createClonedSprite(rxOriginal
);
694 if (mxUpdateCanvas
.is())
695 return mxUpdateCanvas
->createClonedSprite(rxOriginal
);
702 ::sal_Bool SAL_CALL
PresenterCanvas::updateScreen (::sal_Bool bUpdateAll
)
703 throw (css::uno::RuntimeException
)
707 mbOffsetUpdatePending
= true;
708 if (mpUpdateRequester
.get() != NULL
)
710 mpUpdateRequester
->RequestUpdate(bUpdateAll
);
722 //----- XEventListener --------------------------------------------------------
724 void SAL_CALL
PresenterCanvas::disposing (const css::lang::EventObject
& rEvent
)
725 throw (css::uno::RuntimeException
)
728 if (rEvent
.Source
== mxWindow
)
735 //----- XWindowListener -------------------------------------------------------
737 void SAL_CALL
PresenterCanvas::windowResized (const css::awt::WindowEvent
& rEvent
)
738 throw (css::uno::RuntimeException
)
742 mbOffsetUpdatePending
= true;
748 void SAL_CALL
PresenterCanvas::windowMoved (const css::awt::WindowEvent
& rEvent
)
749 throw (css::uno::RuntimeException
)
753 mbOffsetUpdatePending
= true;
759 void SAL_CALL
PresenterCanvas::windowShown (const css::lang::EventObject
& rEvent
)
760 throw (css::uno::RuntimeException
)
764 mbOffsetUpdatePending
= true;
770 void SAL_CALL
PresenterCanvas::windowHidden (const css::lang::EventObject
& rEvent
)
771 throw (css::uno::RuntimeException
)
780 //----- XBitmap ---------------------------------------------------------------
782 geometry::IntegerSize2D SAL_CALL
PresenterCanvas::getSize (void)
783 throw (RuntimeException
)
789 const awt::Rectangle
aWindowBox (mxWindow
->getPosSize());
790 return geometry::IntegerSize2D(aWindowBox
.Width
, aWindowBox
.Height
);
793 return geometry::IntegerSize2D(0,0);
799 sal_Bool SAL_CALL
PresenterCanvas::hasAlpha (void)
800 throw (RuntimeException
)
802 Reference
<rendering::XBitmap
> xBitmap (mxSharedCanvas
, UNO_QUERY
);
804 return xBitmap
->hasAlpha();
812 Reference
<rendering::XBitmapCanvas
> SAL_CALL
PresenterCanvas::queryBitmapCanvas (void)
813 throw (RuntimeException
)
823 Reference
<rendering::XBitmap
> SAL_CALL
PresenterCanvas::getScaledBitmap(
824 const css::geometry::RealSize2D
& rNewSize
,
826 throw (css::uno::RuntimeException
,
827 css::lang::IllegalArgumentException
,
828 css::rendering::VolatileContentDestroyedException
)
843 //-----------------------------------------------------------------------------
845 rendering::ViewState
PresenterCanvas::MergeViewState (
846 const rendering::ViewState
& rViewState
)
848 // Make sure the offset is up-to-date.
849 if (mbOffsetUpdatePending
)
850 maOffset
= GetOffset(mxSharedWindow
);
851 return MergeViewState(rViewState
, maOffset
);
857 css::rendering::ViewState
PresenterCanvas::MergeViewState (
858 const css::rendering::ViewState
& rViewState
,
859 const css::awt::Point
& rOffset
)
862 if ( ! mxSharedCanvas
.is())
865 Reference
<rendering::XGraphicDevice
> xDevice (mxSharedCanvas
->getDevice());
869 // Create a modifiable copy of the given view state.
870 rendering::ViewState
aViewState (rViewState
);
872 // Prepare the local clip rectangle.
873 ::basegfx::B2DRectangle
aWindowRange (GetClipRectangle(aViewState
.AffineTransform
, rOffset
));
875 // Adapt the offset of the view state.
876 aViewState
.AffineTransform
.m02
+= rOffset
.X
;
877 aViewState
.AffineTransform
.m12
+= rOffset
.Y
;
879 // Adapt the clip polygon.
880 if ( ! aViewState
.Clip
.is())
882 // Cancel out the later multiplication with the view state
884 aViewState
.Clip
= ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
886 ::basegfx::B2DPolyPolygon(::basegfx::tools::createPolygonFromRect(aWindowRange
)));
890 // Have to compute the intersection of the given clipping polygon in
891 // the view state and the local clip rectangle.
893 // Clip the view state clipping polygon against the local clip rectangle.
894 const ::basegfx::B2DPolyPolygon
aClipPolygon (
895 ::basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(
897 const ::basegfx::B2DPolyPolygon
aClippedClipPolygon (
898 ::basegfx::tools::clipPolyPolygonOnRange(
902 false /* bStroke */));
904 aViewState
.Clip
= ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
906 aClippedClipPolygon
);
915 Reference
<rendering::XCanvas
> PresenterCanvas::GetSharedCanvas (void) const
917 return mxSharedCanvas
;
923 void PresenterCanvas::SetClip (const awt::Rectangle
& rClipRectangle
)
925 maClipRectangle
= rClipRectangle
;
931 awt::Point
PresenterCanvas::GetOffset (const Reference
<awt::XWindow
>& rxBaseWindow
)
933 mbOffsetUpdatePending
= false;
934 if (mxWindow
.is() && rxBaseWindow
.is())
936 ::Window
* pWindow
= VCLUnoHelper::GetWindow(mxWindow
);
937 ::Window
* pSharedWindow
= VCLUnoHelper::GetWindow(rxBaseWindow
);
938 if (pWindow
!=NULL
&& pSharedWindow
!=NULL
)
940 Rectangle aBox
= pWindow
->GetWindowExtentsRelative(pSharedWindow
);
942 // Calculate offset of this canvas with respect to the shared
944 return awt::Point(aBox
.Left(), aBox
.Top());
948 return awt::Point(0, 0);
954 ::basegfx::B2DRectangle
PresenterCanvas::GetClipRectangle (
955 const css::geometry::AffineMatrix2D
& rViewTransform
,
956 const awt::Point
& rOffset
)
958 ::basegfx::B2DRectangle aClipRectangle
;
960 ::Window
* pWindow
= VCLUnoHelper::GetWindow(mxWindow
);
962 return ::basegfx::B2DRectangle();
964 ::Window
* pSharedWindow
= VCLUnoHelper::GetWindow(mxSharedWindow
);
965 if (pSharedWindow
== NULL
)
966 return ::basegfx::B2DRectangle();
968 // Get the bounding box of the window and create a range in the
969 // coordinate system of the child window.
970 Rectangle aLocalClip
;
971 if (maClipRectangle
.Width
<= 0 || maClipRectangle
.Height
<= 0)
973 // No clip rectangle has been set via SetClip by the pane.
974 // Use the window extents instead.
975 aLocalClip
= pWindow
->GetWindowExtentsRelative(pSharedWindow
);
979 // Use a previously given clip rectangle.
980 aLocalClip
= Rectangle(
981 maClipRectangle
.X
+ rOffset
.X
,
982 maClipRectangle
.Y
+ rOffset
.Y
,
983 maClipRectangle
.X
+ maClipRectangle
.Width
+ rOffset
.X
,
984 maClipRectangle
.Y
+ maClipRectangle
.Height
+ rOffset
.Y
);
987 // The local clip rectangle is used to clip the view state clipping
989 ::basegfx::B2DRectangle
aWindowRectangle (
990 aLocalClip
.Left() - rOffset
.X
,
991 aLocalClip
.Top() - rOffset
.Y
,
992 aLocalClip
.Right() - rOffset
.X
+ 1,
993 aLocalClip
.Bottom() - rOffset
.Y
+ 1);
995 // Calculate the inverted view state transformation to cancel out a
996 // later transformation of the local clip polygon with the view state
998 ::basegfx::B2DHomMatrix aInvertedViewStateTransformation
;
999 ::basegfx::unotools::homMatrixFromAffineMatrix(
1000 aInvertedViewStateTransformation
,
1002 if (aInvertedViewStateTransformation
.invert())
1004 // Cancel out the later multiplication with the view state
1006 aWindowRectangle
.transform(aInvertedViewStateTransformation
);
1009 return aWindowRectangle
;
1014 Reference
<rendering::XPolyPolygon2D
> PresenterCanvas::UpdateSpriteClip (
1015 const Reference
<rendering::XPolyPolygon2D
>& rxOriginalClip
,
1016 const geometry::RealPoint2D
& rLocation
,
1017 const geometry::RealSize2D
& rSize
)
1021 // Check used resources and just return the original clip when not
1022 // every one of them is available.
1023 if ( ! mxWindow
.is())
1024 return rxOriginalClip
;
1026 Reference
<rendering::XGraphicDevice
> xDevice (mxSharedCanvas
->getDevice());
1027 if ( ! xDevice
.is())
1028 return rxOriginalClip
;
1030 // Determine the bounds of the clip rectangle (the window border) in the
1031 // coordinate system of the sprite.
1032 const awt::Rectangle
aWindowBox (mxWindow
->getPosSize());
1033 const double nMinX (-rLocation
.X
);
1034 const double nMinY (-rLocation
.Y
);
1035 const double nMaxX (aWindowBox
.Width
-rLocation
.X
);
1036 const double nMaxY (aWindowBox
.Height
-rLocation
.Y
);
1038 // Create a clip polygon.
1039 Reference
<rendering::XPolyPolygon2D
> xPolygon
;
1040 if (rxOriginalClip
.is())
1042 // Combine the original clip with the window clip.
1043 const ::basegfx::B2DPolyPolygon
aOriginalClip (
1044 ::basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(rxOriginalClip
));
1045 ::basegfx::B2DRectangle
aWindowRange (nMinX
, nMinY
, nMaxX
, nMaxY
);
1046 const ::basegfx::B2DPolyPolygon
aClippedClipPolygon (
1047 ::basegfx::tools::clipPolyPolygonOnRange(
1051 false /* bStroke */));
1052 xPolygon
= ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
1054 aClippedClipPolygon
);
1058 // Create a new clip polygon from the window clip rectangle.
1059 Sequence
<Sequence
<geometry::RealPoint2D
> > aPoints (1);
1060 aPoints
[0] = Sequence
<geometry::RealPoint2D
>(4);
1061 aPoints
[0][0] = geometry::RealPoint2D(nMinX
,nMinY
);
1062 aPoints
[0][1] = geometry::RealPoint2D(nMaxX
,nMinY
);
1063 aPoints
[0][2] = geometry::RealPoint2D(nMaxX
,nMaxY
);
1064 aPoints
[0][3] = geometry::RealPoint2D(nMinX
,nMaxY
);
1065 Reference
<rendering::XLinePolyPolygon2D
> xLinePolygon(
1066 xDevice
->createCompatibleLinePolyPolygon(aPoints
));
1067 if (xLinePolygon
.is())
1068 xLinePolygon
->setClosed(0, sal_True
);
1069 xPolygon
= Reference
<rendering::XPolyPolygon2D
>(xLinePolygon
, UNO_QUERY
);
1078 void PresenterCanvas::ThrowIfDisposed (void)
1079 throw (css::lang::DisposedException
)
1081 if (rBHelper
.bDisposed
|| rBHelper
.bInDispose
|| ! mxSharedCanvas
.is())
1083 throw lang::DisposedException (
1084 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1085 "PresenterCanvas object has already been disposed")),
1086 static_cast<uno::XWeak
*>(this));
1093 //===== PresenterCustomSprite =================================================
1096 PresenterCustomSprite::PresenterCustomSprite (
1097 const rtl::Reference
<PresenterCanvas
>& rpCanvas
,
1098 const Reference
<rendering::XCustomSprite
>& rxSprite
,
1099 const Reference
<awt::XWindow
>& rxBaseWindow
,
1100 const css::geometry::RealSize2D
& rSpriteSize
)
1101 : PresenterCustomSpriteInterfaceBase(m_aMutex
),
1104 mxBaseWindow(rxBaseWindow
),
1106 maSpriteSize(rSpriteSize
)
1113 PresenterCustomSprite::~PresenterCustomSprite (void)
1120 void SAL_CALL
PresenterCustomSprite::disposing (void)
1121 throw (RuntimeException
)
1123 Reference
<XComponent
> xComponent (mxSprite
, UNO_QUERY
);
1125 if (xComponent
.is())
1126 xComponent
->dispose();
1127 mpCanvas
= rtl::Reference
<PresenterCanvas
>();
1133 //----- XSprite ---------------------------------------------------------------
1135 void SAL_CALL
PresenterCustomSprite::setAlpha (const double nAlpha
)
1136 throw (lang::IllegalArgumentException
,RuntimeException
)
1139 mxSprite
->setAlpha(nAlpha
);
1145 void SAL_CALL
PresenterCustomSprite::move (
1146 const geometry::RealPoint2D
& rNewPos
,
1147 const rendering::ViewState
& rViewState
,
1148 const rendering::RenderState
& rRenderState
)
1149 throw (lang::IllegalArgumentException
,RuntimeException
)
1152 maPosition
= rNewPos
;
1155 mpCanvas
->MergeViewState(rViewState
, mpCanvas
->GetOffset(mxBaseWindow
)),
1157 // Clip sprite against window bounds. This call is necessary because
1158 // sprite clipping is done in the corrdinate system of the sprite.
1159 // Therefore, after each change of the sprites location the window
1160 // bounds have to be transformed into the sprites coordinate system.
1167 void SAL_CALL
PresenterCustomSprite::transform (const geometry::AffineMatrix2D
& rTransformation
)
1168 throw (lang::IllegalArgumentException
,RuntimeException
)
1171 mxSprite
->transform(rTransformation
);
1177 void SAL_CALL
PresenterCustomSprite::clip (const Reference
<rendering::XPolyPolygon2D
>& rxClip
)
1178 throw (RuntimeException
)
1181 // The clip region is expected in the coordinate system of the sprite.
1182 // UpdateSpriteClip() integrates the window bounds, transformed into the
1183 // sprites coordinate system, with the given clip.
1184 mxSprite
->clip(mpCanvas
->UpdateSpriteClip(rxClip
, maPosition
, maSpriteSize
));
1190 void SAL_CALL
PresenterCustomSprite::setPriority (const double nPriority
)
1191 throw (RuntimeException
)
1194 mxSprite
->setPriority(nPriority
);
1199 void SAL_CALL
PresenterCustomSprite::show (void)
1200 throw (RuntimeException
)
1209 void SAL_CALL
PresenterCustomSprite::hide (void)
1210 throw (RuntimeException
)
1219 //----- XCustomSprite ---------------------------------------------------------
1221 Reference
<rendering::XCanvas
> PresenterCustomSprite::getContentCanvas (void)
1222 throw (RuntimeException
)
1225 return mxSprite
->getContentCanvas();
1231 //-----------------------------------------------------------------------------
1233 void PresenterCustomSprite::ThrowIfDisposed (void)
1234 throw (css::lang::DisposedException
)
1236 if (rBHelper
.bDisposed
|| rBHelper
.bInDispose
|| ! mxSprite
.is())
1238 throw lang::DisposedException (
1239 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1240 "PresenterCustomSprite object has already been disposed")),
1241 static_cast<uno::XWeak
*>(this));
1248 } } // end of namespace ::sd::presenter