Update ooo320-m1
[ooovba.git] / sd / source / ui / presenter / PresenterCanvas.cxx
blob5b481a8e375b13a69072802a1686443d1a979bce
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PresenterCanvas.cxx,v $
11 * $Revision: 1.6 $
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)
61 (void)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.
91 namespace {
92 typedef ::cppu::WeakComponentImplHelper1 <
93 css::rendering::XCustomSprite
94 > PresenterCustomSpriteInterfaceBase;
96 class PresenterCustomSprite
97 : private ::boost::noncopyable,
98 protected ::cppu::BaseMutex,
99 public PresenterCustomSpriteInterfaceBase
101 public:
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);
111 // XSprite
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);
137 // XCustomSprite
139 virtual Reference<rendering::XCanvas> SAL_CALL getContentCanvas (void)
140 throw (RuntimeException);
142 private:
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),
161 mxUpdateCanvas(),
162 mxSharedCanvas(),
163 mxSharedWindow(),
164 mxWindow(),
165 maOffset(),
166 mpUpdateRequester(),
167 maClipRectangle(),
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),
186 mxWindow(rxWindow),
187 maOffset(),
188 mpUpdateRequester(),
189 maClipRectangle(),
190 mbOffsetUpdatePending(true)
192 if (mxWindow.is())
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)
212 if (mxWindow.is())
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)
226 ThrowIfDisposed();
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;
263 if (mxWindow.is())
264 mxWindow->addWindowListener(this);
266 catch (RuntimeException&)
268 mxSharedWindow = NULL;
269 mxWindow = NULL;
270 throw;
273 else
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)
289 ThrowIfDisposed();
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)
303 ThrowIfDisposed();
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)
317 ThrowIfDisposed();
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)
331 ThrowIfDisposed();
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)
344 ThrowIfDisposed();
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)
359 ThrowIfDisposed();
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)
378 ThrowIfDisposed();
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)
398 ThrowIfDisposed();
399 return mxSharedCanvas->strokeTextureMappedPolyPolygon(
400 xPolyPolygon,
401 MergeViewState(aViewState),
402 aRenderState,
403 aTextures,
404 xMapping,
405 aStrokeAttributes);
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)
419 ThrowIfDisposed();
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)
435 ThrowIfDisposed();
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)
453 ThrowIfDisposed();
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)
472 ThrowIfDisposed();
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)
488 ThrowIfDisposed();
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)
502 ThrowIfDisposed();
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)
518 ThrowIfDisposed();
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)
533 ThrowIfDisposed();
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)
550 ThrowIfDisposed();
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)
567 ThrowIfDisposed();
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)
579 ThrowIfDisposed();
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)
600 ThrowIfDisposed();
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)
624 ThrowIfDisposed();
626 Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxSharedCanvas, UNO_QUERY);
627 if (xSpriteCanvas.is())
628 return xSpriteCanvas->createSpriteFromAnimation(rAnimation);
629 else
630 return NULL;
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)
645 ThrowIfDisposed();
647 Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxSharedCanvas, UNO_QUERY);
648 if (xSpriteCanvas.is())
649 return xSpriteCanvas->createSpriteFromBitmaps(rAnimationBitmaps, nInterpolationMode);
650 else
651 return NULL;
657 Reference<rendering::XCustomSprite> SAL_CALL
658 PresenterCanvas::createCustomSprite (
659 const css::geometry::RealSize2D& rSpriteSize)
660 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException)
662 ThrowIfDisposed();
664 Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxSharedCanvas, UNO_QUERY);
665 if (xSpriteCanvas.is())
666 return new PresenterCustomSprite(
667 this,
668 xSpriteCanvas->createCustomSprite(rSpriteSize),
669 mxSharedWindow,
670 rSpriteSize);
671 else if (mxUpdateCanvas.is())
672 return new PresenterCustomSprite(
673 this,
674 mxUpdateCanvas->createCustomSprite(rSpriteSize),
675 mxUpdateWindow,
676 rSpriteSize);
677 else
678 return NULL;
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)
689 ThrowIfDisposed();
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);
696 return NULL;
702 ::sal_Bool SAL_CALL PresenterCanvas::updateScreen (::sal_Bool bUpdateAll)
703 throw (css::uno::RuntimeException)
705 ThrowIfDisposed();
707 mbOffsetUpdatePending = true;
708 if (mpUpdateRequester.get() != NULL)
710 mpUpdateRequester->RequestUpdate(bUpdateAll);
711 return sal_True;
713 else
715 return sal_False;
722 //----- XEventListener --------------------------------------------------------
724 void SAL_CALL PresenterCanvas::disposing (const css::lang::EventObject& rEvent)
725 throw (css::uno::RuntimeException)
727 ThrowIfDisposed();
728 if (rEvent.Source == mxWindow)
729 mxWindow = NULL;
735 //----- XWindowListener -------------------------------------------------------
737 void SAL_CALL PresenterCanvas::windowResized (const css::awt::WindowEvent& rEvent)
738 throw (css::uno::RuntimeException)
740 (void)rEvent;
741 ThrowIfDisposed();
742 mbOffsetUpdatePending = true;
748 void SAL_CALL PresenterCanvas::windowMoved (const css::awt::WindowEvent& rEvent)
749 throw (css::uno::RuntimeException)
751 (void)rEvent;
752 ThrowIfDisposed();
753 mbOffsetUpdatePending = true;
759 void SAL_CALL PresenterCanvas::windowShown (const css::lang::EventObject& rEvent)
760 throw (css::uno::RuntimeException)
762 (void)rEvent;
763 ThrowIfDisposed();
764 mbOffsetUpdatePending = true;
770 void SAL_CALL PresenterCanvas::windowHidden (const css::lang::EventObject& rEvent)
771 throw (css::uno::RuntimeException)
773 (void)rEvent;
774 ThrowIfDisposed();
780 //----- XBitmap ---------------------------------------------------------------
782 geometry::IntegerSize2D SAL_CALL PresenterCanvas::getSize (void)
783 throw (RuntimeException)
785 ThrowIfDisposed();
787 if (mxWindow.is())
789 const awt::Rectangle aWindowBox (mxWindow->getPosSize());
790 return geometry::IntegerSize2D(aWindowBox.Width, aWindowBox.Height);
792 else
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);
803 if (xBitmap.is())
804 return xBitmap->hasAlpha();
805 else
806 return sal_False;
812 Reference<rendering::XBitmapCanvas> SAL_CALL PresenterCanvas::queryBitmapCanvas (void)
813 throw (RuntimeException)
815 ThrowIfDisposed();
817 return this;
823 Reference<rendering::XBitmap> SAL_CALL PresenterCanvas::getScaledBitmap(
824 const css::geometry::RealSize2D& rNewSize,
825 sal_Bool bFast)
826 throw (css::uno::RuntimeException,
827 css::lang::IllegalArgumentException,
828 css::rendering::VolatileContentDestroyedException)
830 (void)rNewSize;
831 (void)bFast;
833 ThrowIfDisposed();
835 // Not implemented.
837 return NULL;
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)
861 // Early rejects.
862 if ( ! mxSharedCanvas.is())
863 return rViewState;
865 Reference<rendering::XGraphicDevice> xDevice (mxSharedCanvas->getDevice());
866 if ( ! xDevice.is())
867 return rViewState;
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
883 // transformation.
884 aViewState.Clip = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
885 xDevice,
886 ::basegfx::B2DPolyPolygon(::basegfx::tools::createPolygonFromRect(aWindowRange)));
888 else
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(
896 aViewState.Clip));
897 const ::basegfx::B2DPolyPolygon aClippedClipPolygon (
898 ::basegfx::tools::clipPolyPolygonOnRange(
899 aClipPolygon,
900 aWindowRange,
901 true, /* bInside */
902 false /* bStroke */));
904 aViewState.Clip = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
905 xDevice,
906 aClippedClipPolygon);
909 return aViewState;
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
943 // canvas.
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);
961 if (pWindow == NULL)
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);
977 else
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
988 // polygon.
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
997 // transformation.
998 ::basegfx::B2DHomMatrix aInvertedViewStateTransformation;
999 ::basegfx::unotools::homMatrixFromAffineMatrix(
1000 aInvertedViewStateTransformation,
1001 rViewTransform);
1002 if (aInvertedViewStateTransformation.invert())
1004 // Cancel out the later multiplication with the view state
1005 // transformation.
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)
1019 (void)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(
1048 aOriginalClip,
1049 aWindowRange,
1050 true, /* bInside */
1051 false /* bStroke */));
1052 xPolygon = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
1053 xDevice,
1054 aClippedClipPolygon);
1056 else
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);
1072 return xPolygon;
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),
1102 mpCanvas(rpCanvas),
1103 mxSprite(rxSprite),
1104 mxBaseWindow(rxBaseWindow),
1105 maPosition(0,0),
1106 maSpriteSize(rSpriteSize)
1113 PresenterCustomSprite::~PresenterCustomSprite (void)
1120 void SAL_CALL PresenterCustomSprite::disposing (void)
1121 throw (RuntimeException)
1123 Reference<XComponent> xComponent (mxSprite, UNO_QUERY);
1124 mxSprite = NULL;
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)
1138 ThrowIfDisposed();
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)
1151 ThrowIfDisposed();
1152 maPosition = rNewPos;
1153 mxSprite->move(
1154 rNewPos,
1155 mpCanvas->MergeViewState(rViewState, mpCanvas->GetOffset(mxBaseWindow)),
1156 rRenderState);
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.
1161 clip(NULL);
1167 void SAL_CALL PresenterCustomSprite::transform (const geometry::AffineMatrix2D& rTransformation)
1168 throw (lang::IllegalArgumentException,RuntimeException)
1170 ThrowIfDisposed();
1171 mxSprite->transform(rTransformation);
1177 void SAL_CALL PresenterCustomSprite::clip (const Reference<rendering::XPolyPolygon2D>& rxClip)
1178 throw (RuntimeException)
1180 ThrowIfDisposed();
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)
1193 ThrowIfDisposed();
1194 mxSprite->setPriority(nPriority);
1199 void SAL_CALL PresenterCustomSprite::show (void)
1200 throw (RuntimeException)
1202 ThrowIfDisposed();
1203 mxSprite->show();
1209 void SAL_CALL PresenterCustomSprite::hide (void)
1210 throw (RuntimeException)
1212 ThrowIfDisposed();
1213 mxSprite->hide();
1219 //----- XCustomSprite ---------------------------------------------------------
1221 Reference<rendering::XCanvas> PresenterCustomSprite::getContentCanvas (void)
1222 throw (RuntimeException)
1224 ThrowIfDisposed();
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