bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / presenter / PresenterCanvas.cxx
blobdd38320f3c7c75c7fa69b00e64944acc5391a6f1
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 .
20 #include "PresenterCanvas.hxx"
21 #include "facreg.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 <com/sun/star/uno/XComponentContext.hpp>
31 #include <cppuhelper/basemutex.hxx>
32 #include <cppuhelper/compbase1.hxx>
33 #include <cppuhelper/supportsservice.hxx>
34 #include <rtl/ref.hxx>
35 #include <toolkit/helper/vclunohelper.hxx>
36 #include <vcl/window.hxx>
37 #include <vcl/svapp.hxx>
39 using namespace ::com::sun::star;
40 using namespace ::com::sun::star::uno;
42 namespace sd { namespace presenter {
44 //===== PresenterCustomSprite =================================================
46 /** Wrapper around a sprite that is displayed on a PresenterCanvas.
48 namespace {
49 typedef ::cppu::WeakComponentImplHelper1 <
50 css::rendering::XCustomSprite
51 > PresenterCustomSpriteInterfaceBase;
53 class PresenterCustomSprite
54 : private ::boost::noncopyable,
55 protected ::cppu::BaseMutex,
56 public PresenterCustomSpriteInterfaceBase
58 public:
59 PresenterCustomSprite (
60 const rtl::Reference<PresenterCanvas>& rpCanvas,
61 const Reference<rendering::XCustomSprite>& rxSprite,
62 const Reference<awt::XWindow>& rxBaseWindow,
63 const css::geometry::RealSize2D& rSpriteSize);
64 virtual ~PresenterCustomSprite();
65 virtual void SAL_CALL disposing()
66 throw (RuntimeException) SAL_OVERRIDE;
68 // XSprite
70 virtual void SAL_CALL setAlpha (double nAlpha)
71 throw (lang::IllegalArgumentException,RuntimeException, std::exception) SAL_OVERRIDE;
73 virtual void SAL_CALL move (const geometry::RealPoint2D& rNewPos,
74 const rendering::ViewState& rViewState,
75 const rendering::RenderState& rRenderState)
76 throw (lang::IllegalArgumentException,RuntimeException, std::exception) SAL_OVERRIDE;
78 virtual void SAL_CALL transform (const geometry::AffineMatrix2D& rTransformation)
79 throw (lang::IllegalArgumentException,RuntimeException, std::exception) SAL_OVERRIDE;
81 virtual void SAL_CALL clip (const Reference<rendering::XPolyPolygon2D>& rClip)
82 throw (RuntimeException, std::exception) SAL_OVERRIDE;
84 virtual void SAL_CALL setPriority (double nPriority)
85 throw (RuntimeException, std::exception) SAL_OVERRIDE;
87 virtual void SAL_CALL show()
88 throw (RuntimeException, std::exception) SAL_OVERRIDE;
90 virtual void SAL_CALL hide()
91 throw (RuntimeException, std::exception) SAL_OVERRIDE;
93 // XCustomSprite
95 virtual Reference<rendering::XCanvas> SAL_CALL getContentCanvas()
96 throw (RuntimeException, std::exception) SAL_OVERRIDE;
98 private:
99 rtl::Reference<PresenterCanvas> mpCanvas;
100 Reference<rendering::XCustomSprite> mxSprite;
101 Reference<awt::XWindow> mxBaseWindow;
102 geometry::RealPoint2D maPosition;
103 geometry::RealSize2D maSpriteSize;
105 void ThrowIfDisposed()
106 throw (css::lang::DisposedException);
109 //===== PresenterCanvas =======================================================
111 PresenterCanvas::PresenterCanvas()
112 : PresenterCanvasInterfaceBase(m_aMutex),
113 mxUpdateCanvas(),
114 mxSharedCanvas(),
115 mxSharedWindow(),
116 mxWindow(),
117 maOffset(),
118 mpUpdateRequester(),
119 maClipRectangle(),
120 mbOffsetUpdatePending(true)
124 PresenterCanvas::PresenterCanvas (
125 const Reference<rendering::XSpriteCanvas>& rxUpdateCanvas,
126 const Reference<awt::XWindow>& rxUpdateWindow,
127 const Reference<rendering::XCanvas>& rxSharedCanvas,
128 const Reference<awt::XWindow>& rxSharedWindow,
129 const Reference<awt::XWindow>& rxWindow)
130 : PresenterCanvasInterfaceBase(m_aMutex),
131 mxUpdateCanvas(rxUpdateCanvas),
132 mxUpdateWindow(rxUpdateWindow),
133 mxSharedCanvas(rxSharedCanvas),
134 mxSharedWindow(rxSharedWindow),
135 mxWindow(rxWindow),
136 maOffset(),
137 mpUpdateRequester(),
138 maClipRectangle(),
139 mbOffsetUpdatePending(true)
141 if (mxWindow.is())
142 mxWindow->addWindowListener(this);
144 if (mxUpdateCanvas.is())
145 mpUpdateRequester = CanvasUpdateRequester::Instance(mxUpdateCanvas);
148 PresenterCanvas::~PresenterCanvas()
152 void SAL_CALL PresenterCanvas::disposing()
153 throw (css::uno::RuntimeException)
155 if (mxWindow.is())
156 mxWindow->removeWindowListener(this);
159 //----- XInitialization -------------------------------------------------------
161 void SAL_CALL PresenterCanvas::initialize (
162 const Sequence<Any>& rArguments)
163 throw(Exception, RuntimeException, std::exception)
165 if (rBHelper.bDisposed || rBHelper.bInDispose)
166 ThrowIfDisposed();
168 if (rArguments.getLength() == 5)
172 // First and second argument may be NULL.
173 rArguments[0] >>= mxUpdateCanvas;
174 rArguments[1] >>= mxUpdateWindow;
176 if ( ! (rArguments[2] >>= mxSharedWindow))
178 throw lang::IllegalArgumentException("PresenterCanvas: invalid shared window",
179 static_cast<XWeak*>(this),
183 if ( ! (rArguments[3] >>= mxSharedCanvas))
185 throw lang::IllegalArgumentException("PresenterCanvas: invalid shared canvas",
186 static_cast<XWeak*>(this),
190 if ( ! (rArguments[4] >>= mxWindow))
192 throw lang::IllegalArgumentException("PresenterCanvas: invalid window",
193 static_cast<XWeak*>(this),
197 mpUpdateRequester = CanvasUpdateRequester::Instance(mxUpdateCanvas);
199 mbOffsetUpdatePending = true;
200 if (mxWindow.is())
201 mxWindow->addWindowListener(this);
203 catch (RuntimeException&)
205 mxSharedWindow = NULL;
206 mxWindow = NULL;
207 throw;
210 else
212 throw RuntimeException("PresenterCanvas: invalid number of arguments",
213 static_cast<XWeak*>(this));
217 OUString PresenterCanvas::getImplementationName()
218 throw (css::uno::RuntimeException, std::exception)
220 return OUString("com.sun.star.comp.Draw.PresenterCanvasFactory");
223 sal_Bool PresenterCanvas::supportsService(OUString const & ServiceName)
224 throw (css::uno::RuntimeException, std::exception)
226 return cppu::supportsService(this, ServiceName);
229 css::uno::Sequence<OUString> PresenterCanvas::getSupportedServiceNames()
230 throw (css::uno::RuntimeException, std::exception)
232 return css::uno::Sequence<OUString>{"com.sun.star.rendering.Canvas"};
235 //----- XCanvas ---------------------------------------------------------------
237 void SAL_CALL PresenterCanvas::clear()
238 throw (css::uno::RuntimeException, std::exception)
240 ThrowIfDisposed();
241 // ToDo: Clear the area covered by the child window. A simple forward
242 // would clear the whole shared canvas.
245 void SAL_CALL PresenterCanvas::drawPoint (
246 const css::geometry::RealPoint2D& aPoint,
247 const css::rendering::ViewState& aViewState,
248 const css::rendering::RenderState& aRenderState)
249 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception)
251 ThrowIfDisposed();
252 mxSharedCanvas->drawPoint(aPoint,MergeViewState(aViewState),aRenderState);
255 void SAL_CALL PresenterCanvas::drawLine (
256 const css::geometry::RealPoint2D& aStartPoint,
257 const css::geometry::RealPoint2D& aEndPoint,
258 const css::rendering::ViewState& aViewState,
259 const css::rendering::RenderState& aRenderState)
260 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception)
262 ThrowIfDisposed();
263 mxSharedCanvas->drawLine(aStartPoint,aEndPoint,MergeViewState(aViewState),aRenderState);
266 void SAL_CALL PresenterCanvas::drawBezier (
267 const css::geometry::RealBezierSegment2D& aBezierSegment,
268 const css::geometry::RealPoint2D& aEndPoint,
269 const css::rendering::ViewState& aViewState,
270 const css::rendering::RenderState& aRenderState)
271 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception)
273 ThrowIfDisposed();
274 mxSharedCanvas->drawBezier(aBezierSegment,aEndPoint,MergeViewState(aViewState),aRenderState);
277 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL PresenterCanvas::drawPolyPolygon (
278 const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
279 const css::rendering::ViewState& aViewState,
280 const css::rendering::RenderState& aRenderState)
281 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception)
283 ThrowIfDisposed();
284 return mxSharedCanvas->drawPolyPolygon(
285 xPolyPolygon, MergeViewState(aViewState), aRenderState);
288 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL PresenterCanvas::strokePolyPolygon (
289 const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
290 const css::rendering::ViewState& aViewState,
291 const css::rendering::RenderState& aRenderState,
292 const css::rendering::StrokeAttributes& aStrokeAttributes)
293 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception)
295 ThrowIfDisposed();
296 return mxSharedCanvas->strokePolyPolygon(
297 xPolyPolygon, MergeViewState(aViewState), aRenderState, aStrokeAttributes);
300 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
301 PresenterCanvas::strokeTexturedPolyPolygon (
302 const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
303 const css::rendering::ViewState& aViewState,
304 const css::rendering::RenderState& aRenderState,
305 const css::uno::Sequence< css::rendering::Texture >& aTextures,
306 const css::rendering::StrokeAttributes& aStrokeAttributes)
307 throw (css::lang::IllegalArgumentException,
308 css::rendering::VolatileContentDestroyedException,
309 css::uno::RuntimeException, std::exception)
311 ThrowIfDisposed();
312 return mxSharedCanvas->strokeTexturedPolyPolygon(
313 xPolyPolygon, MergeViewState(aViewState), aRenderState, aTextures, aStrokeAttributes);
316 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
317 PresenterCanvas::strokeTextureMappedPolyPolygon(
318 const css::uno::Reference<css::rendering::XPolyPolygon2D >& xPolyPolygon,
319 const css::rendering::ViewState& aViewState,
320 const css::rendering::RenderState& aRenderState,
321 const css::uno::Sequence<css::rendering::Texture>& aTextures,
322 const css::uno::Reference<css::geometry::XMapping2D>& xMapping,
323 const css::rendering::StrokeAttributes& aStrokeAttributes)
324 throw (css::lang::IllegalArgumentException,
325 css::rendering::VolatileContentDestroyedException,
326 css::uno::RuntimeException, std::exception)
328 ThrowIfDisposed();
329 return mxSharedCanvas->strokeTextureMappedPolyPolygon(
330 xPolyPolygon,
331 MergeViewState(aViewState),
332 aRenderState,
333 aTextures,
334 xMapping,
335 aStrokeAttributes);
338 css::uno::Reference<css::rendering::XPolyPolygon2D> SAL_CALL
339 PresenterCanvas::queryStrokeShapes(
340 const css::uno::Reference<css::rendering::XPolyPolygon2D>& xPolyPolygon,
341 const css::rendering::ViewState& aViewState,
342 const css::rendering::RenderState& aRenderState,
343 const css::rendering::StrokeAttributes& aStrokeAttributes)
344 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception)
346 ThrowIfDisposed();
347 return mxSharedCanvas->queryStrokeShapes(
348 xPolyPolygon, MergeViewState(aViewState), aRenderState, aStrokeAttributes);
351 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
352 PresenterCanvas::fillPolyPolygon(
353 const css::uno::Reference<css::rendering::XPolyPolygon2D>& xPolyPolygon,
354 const css::rendering::ViewState& aViewState,
355 const css::rendering::RenderState& aRenderState)
356 throw (css::lang::IllegalArgumentException,
357 css::uno::RuntimeException, std::exception)
359 ThrowIfDisposed();
360 return mxSharedCanvas->fillPolyPolygon(
361 xPolyPolygon, MergeViewState(aViewState), aRenderState);
364 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
365 PresenterCanvas::fillTexturedPolyPolygon(
366 const css::uno::Reference<css::rendering::XPolyPolygon2D>& xPolyPolygon,
367 const css::rendering::ViewState& aViewState,
368 const css::rendering::RenderState& aRenderState,
369 const css::uno::Sequence<css::rendering::Texture>& xTextures)
370 throw (css::lang::IllegalArgumentException,
371 css::rendering::VolatileContentDestroyedException,
372 css::uno::RuntimeException, std::exception)
374 ThrowIfDisposed();
375 return mxSharedCanvas->fillTexturedPolyPolygon(
376 xPolyPolygon, MergeViewState(aViewState), aRenderState, xTextures);
379 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
380 PresenterCanvas::fillTextureMappedPolyPolygon(
381 const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
382 const css::rendering::ViewState& aViewState,
383 const css::rendering::RenderState& aRenderState,
384 const css::uno::Sequence< css::rendering::Texture >& xTextures,
385 const css::uno::Reference< css::geometry::XMapping2D >& xMapping)
386 throw (css::lang::IllegalArgumentException,
387 css::rendering::VolatileContentDestroyedException,
388 css::uno::RuntimeException, std::exception)
390 ThrowIfDisposed();
391 return mxSharedCanvas->fillTextureMappedPolyPolygon(
392 xPolyPolygon, MergeViewState(aViewState), aRenderState, xTextures, xMapping);
395 css::uno::Reference<css::rendering::XCanvasFont> SAL_CALL
396 PresenterCanvas::createFont(
397 const css::rendering::FontRequest& aFontRequest,
398 const css::uno::Sequence< css::beans::PropertyValue >& aExtraFontProperties,
399 const css::geometry::Matrix2D& aFontMatrix)
400 throw (css::lang::IllegalArgumentException,
401 css::uno::RuntimeException, std::exception)
403 ThrowIfDisposed();
404 return mxSharedCanvas->createFont(
405 aFontRequest, aExtraFontProperties, aFontMatrix);
408 css::uno::Sequence<css::rendering::FontInfo> SAL_CALL
409 PresenterCanvas::queryAvailableFonts(
410 const css::rendering::FontInfo& aFilter,
411 const css::uno::Sequence< css::beans::PropertyValue >& aFontProperties)
412 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception)
414 ThrowIfDisposed();
415 return mxSharedCanvas->queryAvailableFonts(aFilter, aFontProperties);
418 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
419 PresenterCanvas::drawText(
420 const css::rendering::StringContext& aText,
421 const css::uno::Reference< css::rendering::XCanvasFont >& xFont,
422 const css::rendering::ViewState& aViewState,
423 const css::rendering::RenderState& aRenderState,
424 ::sal_Int8 nTextDirection)
425 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception)
427 ThrowIfDisposed();
428 return mxSharedCanvas->drawText(
429 aText, xFont, MergeViewState(aViewState), aRenderState, nTextDirection);
432 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
433 PresenterCanvas::drawTextLayout(
434 const css::uno::Reference< css::rendering::XTextLayout >& xLayoutetText,
435 const css::rendering::ViewState& aViewState,
436 const css::rendering::RenderState& aRenderState)
437 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception)
439 ThrowIfDisposed();
440 return mxSharedCanvas->drawTextLayout(
441 xLayoutetText, MergeViewState(aViewState), aRenderState);
444 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
445 PresenterCanvas::drawBitmap(
446 const css::uno::Reference< css::rendering::XBitmap >& xBitmap,
447 const css::rendering::ViewState& aViewState,
448 const css::rendering::RenderState& aRenderState)
449 throw (css::lang::IllegalArgumentException,
450 css::rendering::VolatileContentDestroyedException,
451 css::uno::RuntimeException, std::exception)
453 ThrowIfDisposed();
454 return mxSharedCanvas->drawBitmap(
455 xBitmap, MergeViewState(aViewState), aRenderState);
458 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
459 PresenterCanvas::drawBitmapModulated(
460 const css::uno::Reference< css::rendering::XBitmap>& xBitmap,
461 const css::rendering::ViewState& aViewState,
462 const css::rendering::RenderState& aRenderState)
463 throw (css::lang::IllegalArgumentException,
464 css::rendering::VolatileContentDestroyedException,
465 css::uno::RuntimeException, std::exception)
467 ThrowIfDisposed();
468 return mxSharedCanvas->drawBitmapModulated(
469 xBitmap, MergeViewState(aViewState), aRenderState);
472 css::uno::Reference<css::rendering::XGraphicDevice> SAL_CALL
473 PresenterCanvas::getDevice()
474 throw (css::uno::RuntimeException, std::exception)
476 ThrowIfDisposed();
477 return mxSharedCanvas->getDevice();
480 //----- XSpriteCanvas ---------------------------------------------------------
482 Reference<rendering::XAnimatedSprite> SAL_CALL
483 PresenterCanvas::createSpriteFromAnimation (
484 const css::uno::Reference<css::rendering::XAnimation>& rAnimation)
485 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception)
487 ThrowIfDisposed();
489 Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxSharedCanvas, UNO_QUERY);
490 if (xSpriteCanvas.is())
491 return xSpriteCanvas->createSpriteFromAnimation(rAnimation);
492 else
493 return NULL;
496 Reference<rendering::XAnimatedSprite> SAL_CALL
497 PresenterCanvas::createSpriteFromBitmaps (
498 const css::uno::Sequence<
499 css::uno::Reference< css::rendering::XBitmap > >& rAnimationBitmaps,
500 ::sal_Int8 nInterpolationMode)
501 throw (css::lang::IllegalArgumentException,
502 css::rendering::VolatileContentDestroyedException,
503 css::uno::RuntimeException, std::exception)
505 ThrowIfDisposed();
507 Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxSharedCanvas, UNO_QUERY);
508 if (xSpriteCanvas.is())
509 return xSpriteCanvas->createSpriteFromBitmaps(rAnimationBitmaps, nInterpolationMode);
510 else
511 return NULL;
514 Reference<rendering::XCustomSprite> SAL_CALL
515 PresenterCanvas::createCustomSprite (
516 const css::geometry::RealSize2D& rSpriteSize)
517 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception)
519 ThrowIfDisposed();
521 Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxSharedCanvas, UNO_QUERY);
522 if (xSpriteCanvas.is())
523 return new PresenterCustomSprite(
524 this,
525 xSpriteCanvas->createCustomSprite(rSpriteSize),
526 mxSharedWindow,
527 rSpriteSize);
528 else if (mxUpdateCanvas.is())
529 return new PresenterCustomSprite(
530 this,
531 mxUpdateCanvas->createCustomSprite(rSpriteSize),
532 mxUpdateWindow,
533 rSpriteSize);
534 else
535 return NULL;
538 Reference<rendering::XSprite> SAL_CALL
539 PresenterCanvas::createClonedSprite (
540 const css::uno::Reference< css::rendering::XSprite >& rxOriginal)
541 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception)
543 ThrowIfDisposed();
545 Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxSharedCanvas, UNO_QUERY);
546 if (xSpriteCanvas.is())
547 return xSpriteCanvas->createClonedSprite(rxOriginal);
548 if (mxUpdateCanvas.is())
549 return mxUpdateCanvas->createClonedSprite(rxOriginal);
550 return NULL;
553 sal_Bool SAL_CALL PresenterCanvas::updateScreen (sal_Bool bUpdateAll)
554 throw (css::uno::RuntimeException, std::exception)
556 ThrowIfDisposed();
558 mbOffsetUpdatePending = true;
559 if (mpUpdateRequester.get() != NULL)
561 mpUpdateRequester->RequestUpdate(bUpdateAll);
562 return sal_True;
564 else
566 return sal_False;
570 //----- XEventListener --------------------------------------------------------
572 void SAL_CALL PresenterCanvas::disposing (const css::lang::EventObject& rEvent)
573 throw (css::uno::RuntimeException, std::exception)
575 ThrowIfDisposed();
576 if (rEvent.Source == mxWindow)
577 mxWindow = NULL;
580 //----- XWindowListener -------------------------------------------------------
582 void SAL_CALL PresenterCanvas::windowResized (const css::awt::WindowEvent& rEvent)
583 throw (css::uno::RuntimeException, std::exception)
585 (void)rEvent;
586 ThrowIfDisposed();
587 mbOffsetUpdatePending = true;
590 void SAL_CALL PresenterCanvas::windowMoved (const css::awt::WindowEvent& rEvent)
591 throw (css::uno::RuntimeException, std::exception)
593 (void)rEvent;
594 ThrowIfDisposed();
595 mbOffsetUpdatePending = true;
598 void SAL_CALL PresenterCanvas::windowShown (const css::lang::EventObject& rEvent)
599 throw (css::uno::RuntimeException, std::exception)
601 (void)rEvent;
602 ThrowIfDisposed();
603 mbOffsetUpdatePending = true;
606 void SAL_CALL PresenterCanvas::windowHidden (const css::lang::EventObject& rEvent)
607 throw (css::uno::RuntimeException, std::exception)
609 (void)rEvent;
610 ThrowIfDisposed();
613 //----- XBitmap ---------------------------------------------------------------
615 geometry::IntegerSize2D SAL_CALL PresenterCanvas::getSize()
616 throw (RuntimeException, std::exception)
618 ThrowIfDisposed();
620 if (mxWindow.is())
622 const awt::Rectangle aWindowBox (mxWindow->getPosSize());
623 return geometry::IntegerSize2D(aWindowBox.Width, aWindowBox.Height);
625 else
626 return geometry::IntegerSize2D(0,0);
629 sal_Bool SAL_CALL PresenterCanvas::hasAlpha()
630 throw (RuntimeException, std::exception)
632 Reference<rendering::XBitmap> xBitmap (mxSharedCanvas, UNO_QUERY);
633 if (xBitmap.is())
634 return xBitmap->hasAlpha();
635 else
636 return sal_False;
639 Reference<rendering::XBitmap> SAL_CALL PresenterCanvas::getScaledBitmap(
640 const css::geometry::RealSize2D& rNewSize,
641 sal_Bool bFast)
642 throw (css::uno::RuntimeException,
643 css::lang::IllegalArgumentException,
644 css::rendering::VolatileContentDestroyedException, std::exception)
646 (void)rNewSize;
647 (void)bFast;
649 ThrowIfDisposed();
651 // Not implemented.
653 return NULL;
656 rendering::ViewState PresenterCanvas::MergeViewState (
657 const rendering::ViewState& rViewState)
659 // Make sure the offset is up-to-date.
660 if (mbOffsetUpdatePending)
661 maOffset = GetOffset(mxSharedWindow);
662 return MergeViewState(rViewState, maOffset);
665 css::rendering::ViewState PresenterCanvas::MergeViewState (
666 const css::rendering::ViewState& rViewState,
667 const css::awt::Point& rOffset)
669 // Early rejects.
670 if ( ! mxSharedCanvas.is())
671 return rViewState;
673 Reference<rendering::XGraphicDevice> xDevice (mxSharedCanvas->getDevice());
674 if ( ! xDevice.is())
675 return rViewState;
677 // Create a modifiable copy of the given view state.
678 rendering::ViewState aViewState (rViewState);
680 // Prepare the local clip rectangle.
681 ::basegfx::B2DRectangle aWindowRange (GetClipRectangle(aViewState.AffineTransform, rOffset));
683 // Adapt the offset of the view state.
684 aViewState.AffineTransform.m02 += rOffset.X;
685 aViewState.AffineTransform.m12 += rOffset.Y;
687 // Adapt the clip polygon.
688 if ( ! aViewState.Clip.is())
690 // Cancel out the later multiplication with the view state
691 // transformation.
692 aViewState.Clip = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
693 xDevice,
694 ::basegfx::B2DPolyPolygon(::basegfx::tools::createPolygonFromRect(aWindowRange)));
696 else
698 // Have to compute the intersection of the given clipping polygon in
699 // the view state and the local clip rectangle.
701 // Clip the view state clipping polygon against the local clip rectangle.
702 const ::basegfx::B2DPolyPolygon aClipPolygon (
703 ::basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(
704 aViewState.Clip));
705 const ::basegfx::B2DPolyPolygon aClippedClipPolygon (
706 ::basegfx::tools::clipPolyPolygonOnRange(
707 aClipPolygon,
708 aWindowRange,
709 true, /* bInside */
710 false /* bStroke */));
712 aViewState.Clip = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
713 xDevice,
714 aClippedClipPolygon);
717 return aViewState;
720 awt::Point PresenterCanvas::GetOffset (const Reference<awt::XWindow>& rxBaseWindow)
722 mbOffsetUpdatePending = false;
723 if (mxWindow.is() && rxBaseWindow.is())
725 vcl::Window* pWindow = VCLUnoHelper::GetWindow(mxWindow);
726 vcl::Window* pSharedWindow = VCLUnoHelper::GetWindow(rxBaseWindow);
727 if (pWindow!=NULL && pSharedWindow!=NULL)
729 Rectangle aBox = pWindow->GetWindowExtentsRelative(pSharedWindow);
731 // Calculate offset of this canvas with respect to the shared
732 // canvas.
733 return awt::Point(aBox.Left(), aBox.Top());
737 return awt::Point(0, 0);
740 ::basegfx::B2DRectangle PresenterCanvas::GetClipRectangle (
741 const css::geometry::AffineMatrix2D& rViewTransform,
742 const awt::Point& rOffset)
744 ::basegfx::B2DRectangle aClipRectangle;
746 vcl::Window* pWindow = VCLUnoHelper::GetWindow(mxWindow);
747 if (pWindow == NULL)
748 return ::basegfx::B2DRectangle();
750 vcl::Window* pSharedWindow = VCLUnoHelper::GetWindow(mxSharedWindow);
751 if (pSharedWindow == NULL)
752 return ::basegfx::B2DRectangle();
754 // Get the bounding box of the window and create a range in the
755 // coordinate system of the child window.
756 Rectangle aLocalClip;
757 if (maClipRectangle.Width <= 0 || maClipRectangle.Height <= 0)
759 // No clip rectangle has been set via SetClip by the pane.
760 // Use the window extents instead.
761 aLocalClip = pWindow->GetWindowExtentsRelative(pSharedWindow);
763 else
765 // Use a previously given clip rectangle.
766 aLocalClip = Rectangle(
767 maClipRectangle.X + rOffset.X,
768 maClipRectangle.Y + rOffset.Y,
769 maClipRectangle.X + maClipRectangle.Width + rOffset.X,
770 maClipRectangle.Y + maClipRectangle.Height + rOffset.Y);
773 // The local clip rectangle is used to clip the view state clipping
774 // polygon.
775 ::basegfx::B2DRectangle aWindowRectangle (
776 aLocalClip.Left() - rOffset.X,
777 aLocalClip.Top() - rOffset.Y,
778 aLocalClip.Right() - rOffset.X + 1,
779 aLocalClip.Bottom() - rOffset.Y + 1);
781 // Calculate the inverted view state transformation to cancel out a
782 // later transformation of the local clip polygon with the view state
783 // transformation.
784 ::basegfx::B2DHomMatrix aInvertedViewStateTransformation;
785 ::basegfx::unotools::homMatrixFromAffineMatrix(
786 aInvertedViewStateTransformation,
787 rViewTransform);
788 if (aInvertedViewStateTransformation.invert())
790 // Cancel out the later multiplication with the view state
791 // transformation.
792 aWindowRectangle.transform(aInvertedViewStateTransformation);
795 return aWindowRectangle;
798 Reference<rendering::XPolyPolygon2D> PresenterCanvas::UpdateSpriteClip (
799 const Reference<rendering::XPolyPolygon2D>& rxOriginalClip,
800 const geometry::RealPoint2D& rLocation,
801 const geometry::RealSize2D& rSize)
803 (void)rSize;
805 // Check used resources and just return the original clip when not
806 // every one of them is available.
807 if ( ! mxWindow.is())
808 return rxOriginalClip;
810 Reference<rendering::XGraphicDevice> xDevice (mxSharedCanvas->getDevice());
811 if ( ! xDevice.is())
812 return rxOriginalClip;
814 // Determine the bounds of the clip rectangle (the window border) in the
815 // coordinate system of the sprite.
816 const awt::Rectangle aWindowBox (mxWindow->getPosSize());
817 const double nMinX (-rLocation.X);
818 const double nMinY (-rLocation.Y);
819 const double nMaxX (aWindowBox.Width-rLocation.X);
820 const double nMaxY (aWindowBox.Height-rLocation.Y);
822 // Create a clip polygon.
823 Reference<rendering::XPolyPolygon2D> xPolygon;
824 if (rxOriginalClip.is())
826 // Combine the original clip with the window clip.
827 const ::basegfx::B2DPolyPolygon aOriginalClip (
828 ::basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(rxOriginalClip));
829 ::basegfx::B2DRectangle aWindowRange (nMinX, nMinY, nMaxX, nMaxY);
830 const ::basegfx::B2DPolyPolygon aClippedClipPolygon (
831 ::basegfx::tools::clipPolyPolygonOnRange(
832 aOriginalClip,
833 aWindowRange,
834 true, /* bInside */
835 false /* bStroke */));
836 xPolygon = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
837 xDevice,
838 aClippedClipPolygon);
840 else
842 // Create a new clip polygon from the window clip rectangle.
843 Sequence<Sequence<geometry::RealPoint2D> > aPoints (1);
844 aPoints[0] = Sequence<geometry::RealPoint2D>(4);
845 aPoints[0][0] = geometry::RealPoint2D(nMinX,nMinY);
846 aPoints[0][1] = geometry::RealPoint2D(nMaxX,nMinY);
847 aPoints[0][2] = geometry::RealPoint2D(nMaxX,nMaxY);
848 aPoints[0][3] = geometry::RealPoint2D(nMinX,nMaxY);
849 Reference<rendering::XLinePolyPolygon2D> xLinePolygon(
850 xDevice->createCompatibleLinePolyPolygon(aPoints));
851 if (xLinePolygon.is())
852 xLinePolygon->setClosed(0, sal_True);
853 xPolygon = Reference<rendering::XPolyPolygon2D>(xLinePolygon, UNO_QUERY);
856 return xPolygon;
859 void PresenterCanvas::ThrowIfDisposed()
860 throw (css::lang::DisposedException)
862 if (rBHelper.bDisposed || rBHelper.bInDispose || ! mxSharedCanvas.is())
864 throw lang::DisposedException ("PresenterCanvas object has already been disposed",
865 static_cast<uno::XWeak*>(this));
869 //===== PresenterCustomSprite =================================================
871 PresenterCustomSprite::PresenterCustomSprite (
872 const rtl::Reference<PresenterCanvas>& rpCanvas,
873 const Reference<rendering::XCustomSprite>& rxSprite,
874 const Reference<awt::XWindow>& rxBaseWindow,
875 const css::geometry::RealSize2D& rSpriteSize)
876 : PresenterCustomSpriteInterfaceBase(m_aMutex),
877 mpCanvas(rpCanvas),
878 mxSprite(rxSprite),
879 mxBaseWindow(rxBaseWindow),
880 maPosition(0,0),
881 maSpriteSize(rSpriteSize)
885 PresenterCustomSprite::~PresenterCustomSprite()
889 void SAL_CALL PresenterCustomSprite::disposing()
890 throw (RuntimeException)
892 Reference<XComponent> xComponent (mxSprite, UNO_QUERY);
893 mxSprite = NULL;
894 if (xComponent.is())
895 xComponent->dispose();
896 mpCanvas = rtl::Reference<PresenterCanvas>();
899 //----- XSprite ---------------------------------------------------------------
901 void SAL_CALL PresenterCustomSprite::setAlpha (const double nAlpha)
902 throw (lang::IllegalArgumentException,RuntimeException, std::exception)
904 ThrowIfDisposed();
905 mxSprite->setAlpha(nAlpha);
908 void SAL_CALL PresenterCustomSprite::move (
909 const geometry::RealPoint2D& rNewPos,
910 const rendering::ViewState& rViewState,
911 const rendering::RenderState& rRenderState)
912 throw (lang::IllegalArgumentException,RuntimeException, std::exception)
914 ThrowIfDisposed();
915 maPosition = rNewPos;
916 mxSprite->move(
917 rNewPos,
918 mpCanvas->MergeViewState(rViewState, mpCanvas->GetOffset(mxBaseWindow)),
919 rRenderState);
920 // Clip sprite against window bounds. This call is necessary because
921 // sprite clipping is done in the corrdinate system of the sprite.
922 // Therefore, after each change of the sprites location the window
923 // bounds have to be transformed into the sprites coordinate system.
924 clip(NULL);
927 void SAL_CALL PresenterCustomSprite::transform (const geometry::AffineMatrix2D& rTransformation)
928 throw (lang::IllegalArgumentException,RuntimeException, std::exception)
930 ThrowIfDisposed();
931 mxSprite->transform(rTransformation);
934 void SAL_CALL PresenterCustomSprite::clip (const Reference<rendering::XPolyPolygon2D>& rxClip)
935 throw (RuntimeException, std::exception)
937 ThrowIfDisposed();
938 // The clip region is expected in the coordinate system of the sprite.
939 // UpdateSpriteClip() integrates the window bounds, transformed into the
940 // sprites coordinate system, with the given clip.
941 mxSprite->clip(mpCanvas->UpdateSpriteClip(rxClip, maPosition, maSpriteSize));
944 void SAL_CALL PresenterCustomSprite::setPriority (const double nPriority)
945 throw (RuntimeException, std::exception)
947 ThrowIfDisposed();
948 mxSprite->setPriority(nPriority);
951 void SAL_CALL PresenterCustomSprite::show()
952 throw (RuntimeException, std::exception)
954 ThrowIfDisposed();
955 mxSprite->show();
958 void SAL_CALL PresenterCustomSprite::hide()
959 throw (RuntimeException, std::exception)
961 ThrowIfDisposed();
962 mxSprite->hide();
965 //----- XCustomSprite ---------------------------------------------------------
967 Reference<rendering::XCanvas> PresenterCustomSprite::getContentCanvas()
968 throw (RuntimeException, std::exception)
970 ThrowIfDisposed();
971 return mxSprite->getContentCanvas();
974 void PresenterCustomSprite::ThrowIfDisposed()
975 throw (css::lang::DisposedException)
977 if (rBHelper.bDisposed || rBHelper.bInDispose || ! mxSprite.is())
979 throw lang::DisposedException ("PresenterCustomSprite object has already been disposed",
980 static_cast<uno::XWeak*>(this));
984 } } // end of namespace ::sd::presenter
987 extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
988 com_sun_star_comp_Draw_PresenterCanvasFactory_get_implementation(::com::sun::star::uno::XComponentContext*,
989 ::com::sun::star::uno::Sequence<css::uno::Any> const &)
991 return cppu::acquire(new sd::presenter::PresenterCanvas());
996 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */