bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / presenter / PresenterCanvas.cxx
blob5a9908026519179735f6d1c1445b961f610d1be6
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 "CanvasUpdateRequester.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/utils/canvastools.hxx>
29 #include <com/sun/star/awt/XWindow.hpp>
30 #include <canvas/canvastools.hxx>
31 #include <cppuhelper/basemutex.hxx>
32 #include <cppuhelper/compbase.hxx>
33 #include <rtl/ref.hxx>
34 #include <toolkit/helper/vclunohelper.hxx>
35 #include <vcl/window.hxx>
36 #include <vcl/svapp.hxx>
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::uno;
41 namespace sd { namespace presenter {
43 //===== PresenterCustomSprite =================================================
45 /** Wrapper around a sprite that is displayed on a PresenterCanvas.
47 namespace {
48 typedef ::cppu::WeakComponentImplHelper <
49 css::rendering::XCustomSprite
50 > PresenterCustomSpriteInterfaceBase;
52 class PresenterCustomSprite
53 : protected ::cppu::BaseMutex,
54 public PresenterCustomSpriteInterfaceBase
56 public:
57 PresenterCustomSprite (
58 const rtl::Reference<PresenterCanvas>& rpCanvas,
59 const Reference<rendering::XCustomSprite>& rxSprite,
60 const Reference<awt::XWindow>& rxBaseWindow);
61 PresenterCustomSprite(const PresenterCustomSprite&) = delete;
62 PresenterCustomSprite& operator=(const PresenterCustomSprite&) = delete;
63 virtual void SAL_CALL disposing() override;
65 // XSprite
67 virtual void SAL_CALL setAlpha (double nAlpha) override;
69 virtual void SAL_CALL move (const geometry::RealPoint2D& rNewPos,
70 const rendering::ViewState& rViewState,
71 const rendering::RenderState& rRenderState) override;
73 virtual void SAL_CALL transform (const geometry::AffineMatrix2D& rTransformation) override;
75 virtual void SAL_CALL clip (const Reference<rendering::XPolyPolygon2D>& rClip) override;
77 virtual void SAL_CALL setPriority (double nPriority) override;
79 virtual void SAL_CALL show() override;
81 virtual void SAL_CALL hide() override;
83 // XCustomSprite
85 virtual Reference<rendering::XCanvas> SAL_CALL getContentCanvas() override;
87 private:
88 rtl::Reference<PresenterCanvas> mpCanvas;
89 Reference<rendering::XCustomSprite> mxSprite;
90 Reference<awt::XWindow> mxBaseWindow;
91 geometry::RealPoint2D maPosition;
93 /// @throws css::lang::DisposedException
94 void ThrowIfDisposed();
97 //===== PresenterCanvas =======================================================
99 PresenterCanvas::PresenterCanvas (
100 const Reference<rendering::XSpriteCanvas>& rxUpdateCanvas,
101 const Reference<awt::XWindow>& rxUpdateWindow,
102 const Reference<rendering::XCanvas>& rxSharedCanvas,
103 const Reference<awt::XWindow>& rxSharedWindow,
104 const Reference<awt::XWindow>& rxWindow)
105 : PresenterCanvasInterfaceBase(m_aMutex),
106 mxUpdateCanvas(rxUpdateCanvas),
107 mxUpdateWindow(rxUpdateWindow),
108 mxSharedCanvas(rxSharedCanvas),
109 mxSharedWindow(rxSharedWindow),
110 mxWindow(rxWindow),
111 maOffset(),
112 mbOffsetUpdatePending(true)
114 if (mxWindow.is())
115 mxWindow->addWindowListener(this);
117 if (mxUpdateCanvas.is())
119 m_pUpdateRequester = CanvasUpdateRequester::Instance(mxUpdateCanvas);
123 PresenterCanvas::~PresenterCanvas()
127 void SAL_CALL PresenterCanvas::disposing()
129 if (mxWindow.is())
130 mxWindow->removeWindowListener(this);
133 //----- XCanvas ---------------------------------------------------------------
135 void SAL_CALL PresenterCanvas::clear()
137 ThrowIfDisposed();
138 // ToDo: Clear the area covered by the child window. A simple forward
139 // would clear the whole shared canvas.
142 void SAL_CALL PresenterCanvas::drawPoint (
143 const css::geometry::RealPoint2D& aPoint,
144 const css::rendering::ViewState& aViewState,
145 const css::rendering::RenderState& aRenderState)
147 ThrowIfDisposed();
148 mxSharedCanvas->drawPoint(aPoint,MergeViewState(aViewState),aRenderState);
151 void SAL_CALL PresenterCanvas::drawLine (
152 const css::geometry::RealPoint2D& aStartPoint,
153 const css::geometry::RealPoint2D& aEndPoint,
154 const css::rendering::ViewState& aViewState,
155 const css::rendering::RenderState& aRenderState)
157 ThrowIfDisposed();
158 mxSharedCanvas->drawLine(aStartPoint,aEndPoint,MergeViewState(aViewState),aRenderState);
161 void SAL_CALL PresenterCanvas::drawBezier (
162 const css::geometry::RealBezierSegment2D& aBezierSegment,
163 const css::geometry::RealPoint2D& aEndPoint,
164 const css::rendering::ViewState& aViewState,
165 const css::rendering::RenderState& aRenderState)
167 ThrowIfDisposed();
168 mxSharedCanvas->drawBezier(aBezierSegment,aEndPoint,MergeViewState(aViewState),aRenderState);
171 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL PresenterCanvas::drawPolyPolygon (
172 const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
173 const css::rendering::ViewState& aViewState,
174 const css::rendering::RenderState& aRenderState)
176 ThrowIfDisposed();
177 return mxSharedCanvas->drawPolyPolygon(
178 xPolyPolygon, MergeViewState(aViewState), aRenderState);
181 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL PresenterCanvas::strokePolyPolygon (
182 const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
183 const css::rendering::ViewState& aViewState,
184 const css::rendering::RenderState& aRenderState,
185 const css::rendering::StrokeAttributes& aStrokeAttributes)
187 ThrowIfDisposed();
188 return mxSharedCanvas->strokePolyPolygon(
189 xPolyPolygon, MergeViewState(aViewState), aRenderState, aStrokeAttributes);
192 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
193 PresenterCanvas::strokeTexturedPolyPolygon (
194 const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
195 const css::rendering::ViewState& aViewState,
196 const css::rendering::RenderState& aRenderState,
197 const css::uno::Sequence< css::rendering::Texture >& aTextures,
198 const css::rendering::StrokeAttributes& aStrokeAttributes)
200 ThrowIfDisposed();
201 return mxSharedCanvas->strokeTexturedPolyPolygon(
202 xPolyPolygon, MergeViewState(aViewState), aRenderState, aTextures, aStrokeAttributes);
205 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
206 PresenterCanvas::strokeTextureMappedPolyPolygon(
207 const css::uno::Reference<css::rendering::XPolyPolygon2D >& xPolyPolygon,
208 const css::rendering::ViewState& aViewState,
209 const css::rendering::RenderState& aRenderState,
210 const css::uno::Sequence<css::rendering::Texture>& aTextures,
211 const css::uno::Reference<css::geometry::XMapping2D>& xMapping,
212 const css::rendering::StrokeAttributes& aStrokeAttributes)
214 ThrowIfDisposed();
215 return mxSharedCanvas->strokeTextureMappedPolyPolygon(
216 xPolyPolygon,
217 MergeViewState(aViewState),
218 aRenderState,
219 aTextures,
220 xMapping,
221 aStrokeAttributes);
224 css::uno::Reference<css::rendering::XPolyPolygon2D> SAL_CALL
225 PresenterCanvas::queryStrokeShapes(
226 const css::uno::Reference<css::rendering::XPolyPolygon2D>& xPolyPolygon,
227 const css::rendering::ViewState& aViewState,
228 const css::rendering::RenderState& aRenderState,
229 const css::rendering::StrokeAttributes& aStrokeAttributes)
231 ThrowIfDisposed();
232 return mxSharedCanvas->queryStrokeShapes(
233 xPolyPolygon, MergeViewState(aViewState), aRenderState, aStrokeAttributes);
236 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
237 PresenterCanvas::fillPolyPolygon(
238 const css::uno::Reference<css::rendering::XPolyPolygon2D>& xPolyPolygon,
239 const css::rendering::ViewState& aViewState,
240 const css::rendering::RenderState& aRenderState)
242 ThrowIfDisposed();
243 return mxSharedCanvas->fillPolyPolygon(
244 xPolyPolygon, MergeViewState(aViewState), aRenderState);
247 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
248 PresenterCanvas::fillTexturedPolyPolygon(
249 const css::uno::Reference<css::rendering::XPolyPolygon2D>& xPolyPolygon,
250 const css::rendering::ViewState& aViewState,
251 const css::rendering::RenderState& aRenderState,
252 const css::uno::Sequence<css::rendering::Texture>& xTextures)
254 ThrowIfDisposed();
255 return mxSharedCanvas->fillTexturedPolyPolygon(
256 xPolyPolygon, MergeViewState(aViewState), aRenderState, xTextures);
259 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
260 PresenterCanvas::fillTextureMappedPolyPolygon(
261 const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
262 const css::rendering::ViewState& aViewState,
263 const css::rendering::RenderState& aRenderState,
264 const css::uno::Sequence< css::rendering::Texture >& xTextures,
265 const css::uno::Reference< css::geometry::XMapping2D >& xMapping)
267 ThrowIfDisposed();
268 return mxSharedCanvas->fillTextureMappedPolyPolygon(
269 xPolyPolygon, MergeViewState(aViewState), aRenderState, xTextures, xMapping);
272 css::uno::Reference<css::rendering::XCanvasFont> SAL_CALL
273 PresenterCanvas::createFont(
274 const css::rendering::FontRequest& aFontRequest,
275 const css::uno::Sequence< css::beans::PropertyValue >& aExtraFontProperties,
276 const css::geometry::Matrix2D& aFontMatrix)
278 ThrowIfDisposed();
279 return mxSharedCanvas->createFont(
280 aFontRequest, aExtraFontProperties, aFontMatrix);
283 css::uno::Sequence<css::rendering::FontInfo> SAL_CALL
284 PresenterCanvas::queryAvailableFonts(
285 const css::rendering::FontInfo& aFilter,
286 const css::uno::Sequence< css::beans::PropertyValue >& aFontProperties)
288 ThrowIfDisposed();
289 return mxSharedCanvas->queryAvailableFonts(aFilter, aFontProperties);
292 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
293 PresenterCanvas::drawText(
294 const css::rendering::StringContext& aText,
295 const css::uno::Reference< css::rendering::XCanvasFont >& xFont,
296 const css::rendering::ViewState& aViewState,
297 const css::rendering::RenderState& aRenderState,
298 ::sal_Int8 nTextDirection)
300 ThrowIfDisposed();
301 return mxSharedCanvas->drawText(
302 aText, xFont, MergeViewState(aViewState), aRenderState, nTextDirection);
305 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
306 PresenterCanvas::drawTextLayout(
307 const css::uno::Reference< css::rendering::XTextLayout >& xLayoutetText,
308 const css::rendering::ViewState& aViewState,
309 const css::rendering::RenderState& aRenderState)
311 ThrowIfDisposed();
312 return mxSharedCanvas->drawTextLayout(
313 xLayoutetText, MergeViewState(aViewState), aRenderState);
316 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
317 PresenterCanvas::drawBitmap(
318 const css::uno::Reference< css::rendering::XBitmap >& xBitmap,
319 const css::rendering::ViewState& aViewState,
320 const css::rendering::RenderState& aRenderState)
322 ThrowIfDisposed();
323 return mxSharedCanvas->drawBitmap(
324 xBitmap, MergeViewState(aViewState), aRenderState);
327 css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
328 PresenterCanvas::drawBitmapModulated(
329 const css::uno::Reference< css::rendering::XBitmap>& xBitmap,
330 const css::rendering::ViewState& aViewState,
331 const css::rendering::RenderState& aRenderState)
333 ThrowIfDisposed();
334 return mxSharedCanvas->drawBitmapModulated(
335 xBitmap, MergeViewState(aViewState), aRenderState);
338 css::uno::Reference<css::rendering::XGraphicDevice> SAL_CALL
339 PresenterCanvas::getDevice()
341 ThrowIfDisposed();
342 return mxSharedCanvas->getDevice();
345 //----- XSpriteCanvas ---------------------------------------------------------
347 Reference<rendering::XAnimatedSprite> SAL_CALL
348 PresenterCanvas::createSpriteFromAnimation (
349 const css::uno::Reference<css::rendering::XAnimation>& rAnimation)
351 ThrowIfDisposed();
353 Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxSharedCanvas, UNO_QUERY);
354 if (xSpriteCanvas.is())
355 return xSpriteCanvas->createSpriteFromAnimation(rAnimation);
356 else
357 return nullptr;
360 Reference<rendering::XAnimatedSprite> SAL_CALL
361 PresenterCanvas::createSpriteFromBitmaps (
362 const css::uno::Sequence<
363 css::uno::Reference< css::rendering::XBitmap > >& rAnimationBitmaps,
364 ::sal_Int8 nInterpolationMode)
366 ThrowIfDisposed();
368 Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxSharedCanvas, UNO_QUERY);
369 if (xSpriteCanvas.is())
370 return xSpriteCanvas->createSpriteFromBitmaps(rAnimationBitmaps, nInterpolationMode);
371 else
372 return nullptr;
375 Reference<rendering::XCustomSprite> SAL_CALL
376 PresenterCanvas::createCustomSprite (
377 const css::geometry::RealSize2D& rSpriteSize)
379 ThrowIfDisposed();
381 Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxSharedCanvas, UNO_QUERY);
382 if (xSpriteCanvas.is())
383 return new PresenterCustomSprite(
384 this,
385 xSpriteCanvas->createCustomSprite(rSpriteSize),
386 mxSharedWindow);
387 else if (mxUpdateCanvas.is())
388 return new PresenterCustomSprite(
389 this,
390 mxUpdateCanvas->createCustomSprite(rSpriteSize),
391 mxUpdateWindow);
392 else
393 return nullptr;
396 Reference<rendering::XSprite> SAL_CALL
397 PresenterCanvas::createClonedSprite (
398 const css::uno::Reference< css::rendering::XSprite >& rxOriginal)
400 ThrowIfDisposed();
402 Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxSharedCanvas, UNO_QUERY);
403 if (xSpriteCanvas.is())
404 return xSpriteCanvas->createClonedSprite(rxOriginal);
405 if (mxUpdateCanvas.is())
406 return mxUpdateCanvas->createClonedSprite(rxOriginal);
407 return nullptr;
410 sal_Bool SAL_CALL PresenterCanvas::updateScreen (sal_Bool bUpdateAll)
412 ThrowIfDisposed();
414 mbOffsetUpdatePending = true;
415 if (m_pUpdateRequester != nullptr)
417 m_pUpdateRequester->RequestUpdate(bUpdateAll);
418 return true;
420 else
422 return false;
426 //----- XEventListener --------------------------------------------------------
428 void SAL_CALL PresenterCanvas::disposing (const css::lang::EventObject& rEvent)
430 ThrowIfDisposed();
431 if (rEvent.Source == mxWindow)
432 mxWindow = nullptr;
435 //----- XWindowListener -------------------------------------------------------
437 void SAL_CALL PresenterCanvas::windowResized (const css::awt::WindowEvent&)
439 ThrowIfDisposed();
440 mbOffsetUpdatePending = true;
443 void SAL_CALL PresenterCanvas::windowMoved (const css::awt::WindowEvent&)
445 ThrowIfDisposed();
446 mbOffsetUpdatePending = true;
449 void SAL_CALL PresenterCanvas::windowShown (const css::lang::EventObject&)
451 ThrowIfDisposed();
452 mbOffsetUpdatePending = true;
455 void SAL_CALL PresenterCanvas::windowHidden (const css::lang::EventObject&)
457 ThrowIfDisposed();
460 //----- XBitmap ---------------------------------------------------------------
462 geometry::IntegerSize2D SAL_CALL PresenterCanvas::getSize()
464 ThrowIfDisposed();
466 if (mxWindow.is())
468 const awt::Rectangle aWindowBox (mxWindow->getPosSize());
469 return geometry::IntegerSize2D(aWindowBox.Width, aWindowBox.Height);
471 else
472 return geometry::IntegerSize2D(0,0);
475 sal_Bool SAL_CALL PresenterCanvas::hasAlpha()
477 Reference<rendering::XBitmap> xBitmap (mxSharedCanvas, UNO_QUERY);
478 if (xBitmap.is())
479 return xBitmap->hasAlpha();
480 else
481 return false;
484 Reference<rendering::XBitmap> SAL_CALL PresenterCanvas::getScaledBitmap(
485 const css::geometry::RealSize2D&,
486 sal_Bool)
488 ThrowIfDisposed();
490 // Not implemented.
492 return nullptr;
495 rendering::ViewState PresenterCanvas::MergeViewState (
496 const rendering::ViewState& rViewState)
498 // Make sure the offset is up-to-date.
499 if (mbOffsetUpdatePending)
500 maOffset = GetOffset(mxSharedWindow);
501 return MergeViewState(rViewState, maOffset);
504 css::rendering::ViewState PresenterCanvas::MergeViewState (
505 const css::rendering::ViewState& rViewState,
506 const css::awt::Point& rOffset)
508 // Early rejects.
509 if ( ! mxSharedCanvas.is())
510 return rViewState;
512 Reference<rendering::XGraphicDevice> xDevice (mxSharedCanvas->getDevice());
513 if ( ! xDevice.is())
514 return rViewState;
516 // Create a modifiable copy of the given view state.
517 rendering::ViewState aViewState (rViewState);
519 // Prepare the local clip rectangle.
520 ::basegfx::B2DRectangle aWindowRange (GetClipRectangle(aViewState.AffineTransform, rOffset));
522 // Adapt the offset of the view state.
523 aViewState.AffineTransform.m02 += rOffset.X;
524 aViewState.AffineTransform.m12 += rOffset.Y;
526 // Adapt the clip polygon.
527 if ( ! aViewState.Clip.is())
529 // Cancel out the later multiplication with the view state
530 // transformation.
531 aViewState.Clip = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
532 xDevice,
533 ::basegfx::B2DPolyPolygon(::basegfx::utils::createPolygonFromRect(aWindowRange)));
535 else
537 // Have to compute the intersection of the given clipping polygon in
538 // the view state and the local clip rectangle.
540 // Clip the view state clipping polygon against the local clip rectangle.
541 const ::basegfx::B2DPolyPolygon aClipPolygon (
542 ::basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(
543 aViewState.Clip));
544 const ::basegfx::B2DPolyPolygon aClippedClipPolygon (
545 ::basegfx::utils::clipPolyPolygonOnRange(
546 aClipPolygon,
547 aWindowRange,
548 true, /* bInside */
549 false /* bStroke */));
551 aViewState.Clip = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
552 xDevice,
553 aClippedClipPolygon);
556 return aViewState;
559 awt::Point PresenterCanvas::GetOffset (const Reference<awt::XWindow>& rxBaseWindow)
561 mbOffsetUpdatePending = false;
562 if (mxWindow.is() && rxBaseWindow.is())
564 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(mxWindow);
565 VclPtr<vcl::Window> pSharedWindow = VCLUnoHelper::GetWindow(rxBaseWindow);
566 if (pWindow && pSharedWindow)
568 ::tools::Rectangle aBox = pWindow->GetWindowExtentsRelative(pSharedWindow);
570 // Calculate offset of this canvas with respect to the shared
571 // canvas.
572 return awt::Point(aBox.Left(), aBox.Top());
576 return awt::Point(0, 0);
579 ::basegfx::B2DRectangle PresenterCanvas::GetClipRectangle (
580 const css::geometry::AffineMatrix2D& rViewTransform,
581 const awt::Point& rOffset)
583 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(mxWindow);
584 if (!pWindow)
585 return ::basegfx::B2DRectangle();
587 VclPtr<vcl::Window> pSharedWindow = VCLUnoHelper::GetWindow(mxSharedWindow);
588 if (!pSharedWindow)
589 return ::basegfx::B2DRectangle();
591 // Get the bounding box of the window and create a range in the
592 // coordinate system of the child window.
593 // Use the window extents.
594 ::tools::Rectangle aLocalClip = pWindow->GetWindowExtentsRelative(pSharedWindow);
596 // The local clip rectangle is used to clip the view state clipping
597 // polygon.
598 ::basegfx::B2DRectangle aWindowRectangle (
599 aLocalClip.Left() - rOffset.X,
600 aLocalClip.Top() - rOffset.Y,
601 aLocalClip.Right() - rOffset.X + 1,
602 aLocalClip.Bottom() - rOffset.Y + 1);
604 // Calculate the inverted view state transformation to cancel out a
605 // later transformation of the local clip polygon with the view state
606 // transformation.
607 ::basegfx::B2DHomMatrix aInvertedViewStateTransformation;
608 ::basegfx::unotools::homMatrixFromAffineMatrix(
609 aInvertedViewStateTransformation,
610 rViewTransform);
611 if (aInvertedViewStateTransformation.invert())
613 // Cancel out the later multiplication with the view state
614 // transformation.
615 aWindowRectangle.transform(aInvertedViewStateTransformation);
618 return aWindowRectangle;
621 Reference<rendering::XPolyPolygon2D> PresenterCanvas::UpdateSpriteClip (
622 const Reference<rendering::XPolyPolygon2D>& rxOriginalClip,
623 const geometry::RealPoint2D& rLocation)
625 // Check used resources and just return the original clip when not
626 // every one of them is available.
627 if ( ! mxWindow.is())
628 return rxOriginalClip;
630 Reference<rendering::XGraphicDevice> xDevice (mxSharedCanvas->getDevice());
631 if ( ! xDevice.is())
632 return rxOriginalClip;
634 // Determine the bounds of the clip rectangle (the window border) in the
635 // coordinate system of the sprite.
636 const awt::Rectangle aWindowBox (mxWindow->getPosSize());
637 const double nMinX (-rLocation.X);
638 const double nMinY (-rLocation.Y);
639 const double nMaxX (aWindowBox.Width-rLocation.X);
640 const double nMaxY (aWindowBox.Height-rLocation.Y);
642 // Create a clip polygon.
643 Reference<rendering::XPolyPolygon2D> xPolygon;
644 if (rxOriginalClip.is())
646 // Combine the original clip with the window clip.
647 const ::basegfx::B2DPolyPolygon aOriginalClip (
648 ::basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(rxOriginalClip));
649 ::basegfx::B2DRectangle aWindowRange (nMinX, nMinY, nMaxX, nMaxY);
650 const ::basegfx::B2DPolyPolygon aClippedClipPolygon (
651 ::basegfx::utils::clipPolyPolygonOnRange(
652 aOriginalClip,
653 aWindowRange,
654 true, /* bInside */
655 false /* bStroke */));
656 xPolygon = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
657 xDevice,
658 aClippedClipPolygon);
660 else
662 // Create a new clip polygon from the window clip rectangle.
663 Sequence<Sequence<geometry::RealPoint2D> > aPoints (1);
664 aPoints[0] = Sequence<geometry::RealPoint2D>(4);
665 aPoints[0][0] = geometry::RealPoint2D(nMinX,nMinY);
666 aPoints[0][1] = geometry::RealPoint2D(nMaxX,nMinY);
667 aPoints[0][2] = geometry::RealPoint2D(nMaxX,nMaxY);
668 aPoints[0][3] = geometry::RealPoint2D(nMinX,nMaxY);
669 Reference<rendering::XLinePolyPolygon2D> xLinePolygon(
670 xDevice->createCompatibleLinePolyPolygon(aPoints));
671 if (xLinePolygon.is())
672 xLinePolygon->setClosed(0, true);
673 xPolygon.set(xLinePolygon, UNO_QUERY);
676 return xPolygon;
679 void PresenterCanvas::ThrowIfDisposed()
681 if (rBHelper.bDisposed || rBHelper.bInDispose || ! mxSharedCanvas.is())
683 throw lang::DisposedException ("PresenterCanvas object has already been disposed",
684 static_cast<uno::XWeak*>(this));
688 //===== PresenterCustomSprite =================================================
690 PresenterCustomSprite::PresenterCustomSprite (
691 const rtl::Reference<PresenterCanvas>& rpCanvas,
692 const Reference<rendering::XCustomSprite>& rxSprite,
693 const Reference<awt::XWindow>& rxBaseWindow)
694 : PresenterCustomSpriteInterfaceBase(m_aMutex),
695 mpCanvas(rpCanvas),
696 mxSprite(rxSprite),
697 mxBaseWindow(rxBaseWindow),
698 maPosition(0,0)
702 void SAL_CALL PresenterCustomSprite::disposing()
704 Reference<XComponent> xComponent (mxSprite, UNO_QUERY);
705 mxSprite = nullptr;
706 if (xComponent.is())
707 xComponent->dispose();
708 mpCanvas.clear();
711 //----- XSprite ---------------------------------------------------------------
713 void SAL_CALL PresenterCustomSprite::setAlpha (const double nAlpha)
715 ThrowIfDisposed();
716 mxSprite->setAlpha(nAlpha);
719 void SAL_CALL PresenterCustomSprite::move (
720 const geometry::RealPoint2D& rNewPos,
721 const rendering::ViewState& rViewState,
722 const rendering::RenderState& rRenderState)
724 ThrowIfDisposed();
725 maPosition = rNewPos;
726 mxSprite->move(
727 rNewPos,
728 mpCanvas->MergeViewState(rViewState, mpCanvas->GetOffset(mxBaseWindow)),
729 rRenderState);
730 // Clip sprite against window bounds. This call is necessary because
731 // sprite clipping is done in the coordinate system of the sprite.
732 // Therefore, after each change of the sprites location the window
733 // bounds have to be transformed into the sprites coordinate system.
734 clip(nullptr);
737 void SAL_CALL PresenterCustomSprite::transform (const geometry::AffineMatrix2D& rTransformation)
739 ThrowIfDisposed();
740 mxSprite->transform(rTransformation);
743 void SAL_CALL PresenterCustomSprite::clip (const Reference<rendering::XPolyPolygon2D>& rxClip)
745 ThrowIfDisposed();
746 // The clip region is expected in the coordinate system of the sprite.
747 // UpdateSpriteClip() integrates the window bounds, transformed into the
748 // sprites coordinate system, with the given clip.
749 mxSprite->clip(mpCanvas->UpdateSpriteClip(rxClip, maPosition));
752 void SAL_CALL PresenterCustomSprite::setPriority (const double nPriority)
754 ThrowIfDisposed();
755 mxSprite->setPriority(nPriority);
758 void SAL_CALL PresenterCustomSprite::show()
760 ThrowIfDisposed();
761 mxSprite->show();
764 void SAL_CALL PresenterCustomSprite::hide()
766 ThrowIfDisposed();
767 mxSprite->hide();
770 //----- XCustomSprite ---------------------------------------------------------
772 Reference<rendering::XCanvas> PresenterCustomSprite::getContentCanvas()
774 ThrowIfDisposed();
775 return mxSprite->getContentCanvas();
778 void PresenterCustomSprite::ThrowIfDisposed()
780 if (rBHelper.bDisposed || rBHelper.bInDispose || ! mxSprite.is())
782 throw lang::DisposedException ("PresenterCustomSprite object has already been disposed",
783 static_cast<uno::XWeak*>(this));
787 } } // end of namespace ::sd::presenter
789 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */