Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "PresenterCanvas.hxx"
21 : #include "facreg.hxx"
22 :
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 <rtl/ref.hxx>
34 : #include <toolkit/helper/vclunohelper.hxx>
35 : #include <vcl/window.hxx>
36 : #include <vcl/svapp.hxx>
37 :
38 : using namespace ::com::sun::star;
39 : using namespace ::com::sun::star::uno;
40 :
41 : namespace sd { namespace presenter {
42 :
43 : //===== Service ===============================================================
44 :
45 2 : Reference<XInterface> SAL_CALL PresenterCanvas_createInstance (
46 : const Reference<XComponentContext>& rxContext) throw (css::uno::Exception)
47 : {
48 : (void)rxContext;
49 2 : return Reference<XInterface>(static_cast<XWeak*>(new PresenterCanvas()));
50 : }
51 :
52 36 : OUString PresenterCanvas_getImplementationName (void) throw(RuntimeException)
53 : {
54 36 : return OUString("com.sun.star.comp.Draw.PresenterCanvasFactory");
55 : }
56 :
57 2 : Sequence<OUString> SAL_CALL PresenterCanvas_getSupportedServiceNames (void)
58 : throw (RuntimeException)
59 : {
60 2 : static const OUString sServiceName("com.sun.star.rendering.Canvas");
61 2 : return Sequence<OUString>(&sServiceName, 1);
62 : }
63 :
64 : //===== PresenterCustomSprite =================================================
65 :
66 : /** Wrapper around a sprite that is displayed on a PresenterCanvas.
67 : */
68 : namespace {
69 : typedef ::cppu::WeakComponentImplHelper1 <
70 : css::rendering::XCustomSprite
71 : > PresenterCustomSpriteInterfaceBase;
72 : }
73 : class PresenterCustomSprite
74 : : private ::boost::noncopyable,
75 : protected ::cppu::BaseMutex,
76 : public PresenterCustomSpriteInterfaceBase
77 : {
78 : public:
79 : PresenterCustomSprite (
80 : const rtl::Reference<PresenterCanvas>& rpCanvas,
81 : const Reference<rendering::XCustomSprite>& rxSprite,
82 : const Reference<awt::XWindow>& rxBaseWindow,
83 : const css::geometry::RealSize2D& rSpriteSize);
84 : virtual ~PresenterCustomSprite (void);
85 : virtual void SAL_CALL disposing (void)
86 : throw (RuntimeException) SAL_OVERRIDE;
87 :
88 : // XSprite
89 :
90 : virtual void SAL_CALL setAlpha (double nAlpha)
91 : throw (lang::IllegalArgumentException,RuntimeException, std::exception) SAL_OVERRIDE;
92 :
93 : virtual void SAL_CALL move (const geometry::RealPoint2D& rNewPos,
94 : const rendering::ViewState& rViewState,
95 : const rendering::RenderState& rRenderState)
96 : throw (lang::IllegalArgumentException,RuntimeException, std::exception) SAL_OVERRIDE;
97 :
98 : virtual void SAL_CALL transform (const geometry::AffineMatrix2D& rTransformation)
99 : throw (lang::IllegalArgumentException,RuntimeException, std::exception) SAL_OVERRIDE;
100 :
101 : virtual void SAL_CALL clip (const Reference<rendering::XPolyPolygon2D>& rClip)
102 : throw (RuntimeException, std::exception) SAL_OVERRIDE;
103 :
104 : virtual void SAL_CALL setPriority (double nPriority)
105 : throw (RuntimeException, std::exception) SAL_OVERRIDE;
106 :
107 : virtual void SAL_CALL show (void)
108 : throw (RuntimeException, std::exception) SAL_OVERRIDE;
109 :
110 : virtual void SAL_CALL hide (void)
111 : throw (RuntimeException, std::exception) SAL_OVERRIDE;
112 :
113 : // XCustomSprite
114 :
115 : virtual Reference<rendering::XCanvas> SAL_CALL getContentCanvas (void)
116 : throw (RuntimeException, std::exception) SAL_OVERRIDE;
117 :
118 : private:
119 : rtl::Reference<PresenterCanvas> mpCanvas;
120 : Reference<rendering::XCustomSprite> mxSprite;
121 : Reference<awt::XWindow> mxBaseWindow;
122 : geometry::RealPoint2D maPosition;
123 : geometry::RealSize2D maSpriteSize;
124 :
125 : void ThrowIfDisposed (void)
126 : throw (css::lang::DisposedException);
127 : };
128 :
129 : //===== PresenterCanvas =======================================================
130 :
131 2 : PresenterCanvas::PresenterCanvas (void)
132 : : PresenterCanvasInterfaceBase(m_aMutex),
133 : mxUpdateCanvas(),
134 : mxSharedCanvas(),
135 : mxSharedWindow(),
136 : mxWindow(),
137 : maOffset(),
138 : mpUpdateRequester(),
139 : maClipRectangle(),
140 2 : mbOffsetUpdatePending(true)
141 : {
142 2 : }
143 :
144 0 : PresenterCanvas::PresenterCanvas (
145 : const Reference<rendering::XSpriteCanvas>& rxUpdateCanvas,
146 : const Reference<awt::XWindow>& rxUpdateWindow,
147 : const Reference<rendering::XCanvas>& rxSharedCanvas,
148 : const Reference<awt::XWindow>& rxSharedWindow,
149 : const Reference<awt::XWindow>& rxWindow)
150 : : PresenterCanvasInterfaceBase(m_aMutex),
151 : mxUpdateCanvas(rxUpdateCanvas),
152 : mxUpdateWindow(rxUpdateWindow),
153 : mxSharedCanvas(rxSharedCanvas),
154 : mxSharedWindow(rxSharedWindow),
155 : mxWindow(rxWindow),
156 : maOffset(),
157 : mpUpdateRequester(),
158 : maClipRectangle(),
159 0 : mbOffsetUpdatePending(true)
160 : {
161 0 : if (mxWindow.is())
162 0 : mxWindow->addWindowListener(this);
163 :
164 0 : if (mxUpdateCanvas.is())
165 0 : mpUpdateRequester = CanvasUpdateRequester::Instance(mxUpdateCanvas);
166 0 : }
167 :
168 4 : PresenterCanvas::~PresenterCanvas (void)
169 : {
170 4 : }
171 :
172 2 : void SAL_CALL PresenterCanvas::disposing (void)
173 : throw (css::uno::RuntimeException)
174 : {
175 2 : if (mxWindow.is())
176 0 : mxWindow->removeWindowListener(this);
177 2 : }
178 :
179 : //----- XInitialization -------------------------------------------------------
180 :
181 0 : void SAL_CALL PresenterCanvas::initialize (
182 : const Sequence<Any>& rArguments)
183 : throw(Exception, RuntimeException, std::exception)
184 : {
185 0 : if (rBHelper.bDisposed || rBHelper.bInDispose)
186 0 : ThrowIfDisposed();
187 :
188 0 : if (rArguments.getLength() == 5)
189 : {
190 : try
191 : {
192 : // First and second argument may be NULL.
193 0 : rArguments[0] >>= mxUpdateCanvas;
194 0 : rArguments[1] >>= mxUpdateWindow;
195 :
196 0 : if ( ! (rArguments[2] >>= mxSharedWindow))
197 : {
198 : throw lang::IllegalArgumentException("PresenterCanvas: invalid shared window",
199 : static_cast<XWeak*>(this),
200 0 : 1);
201 : }
202 :
203 0 : if ( ! (rArguments[3] >>= mxSharedCanvas))
204 : {
205 : throw lang::IllegalArgumentException("PresenterCanvas: invalid shared canvas",
206 : static_cast<XWeak*>(this),
207 0 : 2);
208 : }
209 :
210 0 : if ( ! (rArguments[4] >>= mxWindow))
211 : {
212 : throw lang::IllegalArgumentException("PresenterCanvas: invalid window",
213 : static_cast<XWeak*>(this),
214 0 : 3);
215 : }
216 :
217 0 : mpUpdateRequester = CanvasUpdateRequester::Instance(mxUpdateCanvas);
218 :
219 0 : mbOffsetUpdatePending = true;
220 0 : if (mxWindow.is())
221 0 : mxWindow->addWindowListener(this);
222 : }
223 0 : catch (RuntimeException&)
224 : {
225 0 : mxSharedWindow = NULL;
226 0 : mxWindow = NULL;
227 0 : throw;
228 : }
229 : }
230 : else
231 : {
232 : throw RuntimeException("PresenterCanvas: invalid number of arguments",
233 0 : static_cast<XWeak*>(this));
234 : }
235 0 : }
236 :
237 : //----- XCanvas ---------------------------------------------------------------
238 :
239 0 : void SAL_CALL PresenterCanvas::clear (void)
240 : throw (css::uno::RuntimeException, std::exception)
241 : {
242 0 : ThrowIfDisposed();
243 : // ToDo: Clear the area covered by the child window. A simple forward
244 : // would clear the whole shared canvas.
245 0 : }
246 :
247 0 : void SAL_CALL PresenterCanvas::drawPoint (
248 : const css::geometry::RealPoint2D& aPoint,
249 : const css::rendering::ViewState& aViewState,
250 : const css::rendering::RenderState& aRenderState)
251 : throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception)
252 : {
253 0 : ThrowIfDisposed();
254 0 : mxSharedCanvas->drawPoint(aPoint,MergeViewState(aViewState),aRenderState);
255 0 : }
256 :
257 0 : void SAL_CALL PresenterCanvas::drawLine (
258 : const css::geometry::RealPoint2D& aStartPoint,
259 : const css::geometry::RealPoint2D& aEndPoint,
260 : const css::rendering::ViewState& aViewState,
261 : const css::rendering::RenderState& aRenderState)
262 : throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception)
263 : {
264 0 : ThrowIfDisposed();
265 0 : mxSharedCanvas->drawLine(aStartPoint,aEndPoint,MergeViewState(aViewState),aRenderState);
266 0 : }
267 :
268 0 : void SAL_CALL PresenterCanvas::drawBezier (
269 : const css::geometry::RealBezierSegment2D& aBezierSegment,
270 : const css::geometry::RealPoint2D& aEndPoint,
271 : const css::rendering::ViewState& aViewState,
272 : const css::rendering::RenderState& aRenderState)
273 : throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception)
274 : {
275 0 : ThrowIfDisposed();
276 0 : mxSharedCanvas->drawBezier(aBezierSegment,aEndPoint,MergeViewState(aViewState),aRenderState);
277 0 : }
278 :
279 0 : css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL PresenterCanvas::drawPolyPolygon (
280 : const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
281 : const css::rendering::ViewState& aViewState,
282 : const css::rendering::RenderState& aRenderState)
283 : throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception)
284 : {
285 0 : ThrowIfDisposed();
286 0 : return mxSharedCanvas->drawPolyPolygon(
287 0 : xPolyPolygon, MergeViewState(aViewState), aRenderState);
288 : }
289 :
290 0 : css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL PresenterCanvas::strokePolyPolygon (
291 : const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
292 : const css::rendering::ViewState& aViewState,
293 : const css::rendering::RenderState& aRenderState,
294 : const css::rendering::StrokeAttributes& aStrokeAttributes)
295 : throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception)
296 : {
297 0 : ThrowIfDisposed();
298 0 : return mxSharedCanvas->strokePolyPolygon(
299 0 : xPolyPolygon, MergeViewState(aViewState), aRenderState, aStrokeAttributes);
300 : }
301 :
302 : css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
303 0 : PresenterCanvas::strokeTexturedPolyPolygon (
304 : const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
305 : const css::rendering::ViewState& aViewState,
306 : const css::rendering::RenderState& aRenderState,
307 : const css::uno::Sequence< css::rendering::Texture >& aTextures,
308 : const css::rendering::StrokeAttributes& aStrokeAttributes)
309 : throw (css::lang::IllegalArgumentException,
310 : css::rendering::VolatileContentDestroyedException,
311 : css::uno::RuntimeException, std::exception)
312 : {
313 0 : ThrowIfDisposed();
314 0 : return mxSharedCanvas->strokeTexturedPolyPolygon(
315 0 : xPolyPolygon, MergeViewState(aViewState), aRenderState, aTextures, aStrokeAttributes);
316 : }
317 :
318 : css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
319 0 : PresenterCanvas::strokeTextureMappedPolyPolygon(
320 : const css::uno::Reference<css::rendering::XPolyPolygon2D >& xPolyPolygon,
321 : const css::rendering::ViewState& aViewState,
322 : const css::rendering::RenderState& aRenderState,
323 : const css::uno::Sequence<css::rendering::Texture>& aTextures,
324 : const css::uno::Reference<css::geometry::XMapping2D>& xMapping,
325 : const css::rendering::StrokeAttributes& aStrokeAttributes)
326 : throw (css::lang::IllegalArgumentException,
327 : css::rendering::VolatileContentDestroyedException,
328 : css::uno::RuntimeException, std::exception)
329 : {
330 0 : ThrowIfDisposed();
331 0 : return mxSharedCanvas->strokeTextureMappedPolyPolygon(
332 : xPolyPolygon,
333 : MergeViewState(aViewState),
334 : aRenderState,
335 : aTextures,
336 : xMapping,
337 0 : aStrokeAttributes);
338 : }
339 :
340 : css::uno::Reference<css::rendering::XPolyPolygon2D> SAL_CALL
341 0 : PresenterCanvas::queryStrokeShapes(
342 : const css::uno::Reference<css::rendering::XPolyPolygon2D>& xPolyPolygon,
343 : const css::rendering::ViewState& aViewState,
344 : const css::rendering::RenderState& aRenderState,
345 : const css::rendering::StrokeAttributes& aStrokeAttributes)
346 : throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception)
347 : {
348 0 : ThrowIfDisposed();
349 0 : return mxSharedCanvas->queryStrokeShapes(
350 0 : xPolyPolygon, MergeViewState(aViewState), aRenderState, aStrokeAttributes);
351 : }
352 :
353 : css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
354 0 : PresenterCanvas::fillPolyPolygon(
355 : const css::uno::Reference<css::rendering::XPolyPolygon2D>& xPolyPolygon,
356 : const css::rendering::ViewState& aViewState,
357 : const css::rendering::RenderState& aRenderState)
358 : throw (css::lang::IllegalArgumentException,
359 : css::uno::RuntimeException, std::exception)
360 : {
361 0 : ThrowIfDisposed();
362 0 : return mxSharedCanvas->fillPolyPolygon(
363 0 : xPolyPolygon, MergeViewState(aViewState), aRenderState);
364 : }
365 :
366 : css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
367 0 : PresenterCanvas::fillTexturedPolyPolygon(
368 : const css::uno::Reference<css::rendering::XPolyPolygon2D>& xPolyPolygon,
369 : const css::rendering::ViewState& aViewState,
370 : const css::rendering::RenderState& aRenderState,
371 : const css::uno::Sequence<css::rendering::Texture>& xTextures)
372 : throw (css::lang::IllegalArgumentException,
373 : css::rendering::VolatileContentDestroyedException,
374 : css::uno::RuntimeException, std::exception)
375 : {
376 0 : ThrowIfDisposed();
377 0 : return mxSharedCanvas->fillTexturedPolyPolygon(
378 0 : xPolyPolygon, MergeViewState(aViewState), aRenderState, xTextures);
379 : }
380 :
381 : css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
382 0 : PresenterCanvas::fillTextureMappedPolyPolygon(
383 : const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
384 : const css::rendering::ViewState& aViewState,
385 : const css::rendering::RenderState& aRenderState,
386 : const css::uno::Sequence< css::rendering::Texture >& xTextures,
387 : const css::uno::Reference< css::geometry::XMapping2D >& xMapping)
388 : throw (css::lang::IllegalArgumentException,
389 : css::rendering::VolatileContentDestroyedException,
390 : css::uno::RuntimeException, std::exception)
391 : {
392 0 : ThrowIfDisposed();
393 0 : return mxSharedCanvas->fillTextureMappedPolyPolygon(
394 0 : xPolyPolygon, MergeViewState(aViewState), aRenderState, xTextures, xMapping);
395 : }
396 :
397 : css::uno::Reference<css::rendering::XCanvasFont> SAL_CALL
398 0 : PresenterCanvas::createFont(
399 : const css::rendering::FontRequest& aFontRequest,
400 : const css::uno::Sequence< css::beans::PropertyValue >& aExtraFontProperties,
401 : const css::geometry::Matrix2D& aFontMatrix)
402 : throw (css::lang::IllegalArgumentException,
403 : css::uno::RuntimeException, std::exception)
404 : {
405 0 : ThrowIfDisposed();
406 0 : return mxSharedCanvas->createFont(
407 0 : aFontRequest, aExtraFontProperties, aFontMatrix);
408 : }
409 :
410 : css::uno::Sequence<css::rendering::FontInfo> SAL_CALL
411 0 : PresenterCanvas::queryAvailableFonts(
412 : const css::rendering::FontInfo& aFilter,
413 : const css::uno::Sequence< css::beans::PropertyValue >& aFontProperties)
414 : throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception)
415 : {
416 0 : ThrowIfDisposed();
417 0 : return mxSharedCanvas->queryAvailableFonts(aFilter, aFontProperties);
418 : }
419 :
420 : css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
421 0 : PresenterCanvas::drawText(
422 : const css::rendering::StringContext& aText,
423 : const css::uno::Reference< css::rendering::XCanvasFont >& xFont,
424 : const css::rendering::ViewState& aViewState,
425 : const css::rendering::RenderState& aRenderState,
426 : ::sal_Int8 nTextDirection)
427 : throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception)
428 : {
429 0 : ThrowIfDisposed();
430 0 : return mxSharedCanvas->drawText(
431 0 : aText, xFont, MergeViewState(aViewState), aRenderState, nTextDirection);
432 : }
433 :
434 : css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
435 0 : PresenterCanvas::drawTextLayout(
436 : const css::uno::Reference< css::rendering::XTextLayout >& xLayoutetText,
437 : const css::rendering::ViewState& aViewState,
438 : const css::rendering::RenderState& aRenderState)
439 : throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception)
440 : {
441 0 : ThrowIfDisposed();
442 0 : return mxSharedCanvas->drawTextLayout(
443 0 : xLayoutetText, MergeViewState(aViewState), aRenderState);
444 : }
445 :
446 : css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
447 0 : PresenterCanvas::drawBitmap(
448 : const css::uno::Reference< css::rendering::XBitmap >& xBitmap,
449 : const css::rendering::ViewState& aViewState,
450 : const css::rendering::RenderState& aRenderState)
451 : throw (css::lang::IllegalArgumentException,
452 : css::rendering::VolatileContentDestroyedException,
453 : css::uno::RuntimeException, std::exception)
454 : {
455 0 : ThrowIfDisposed();
456 0 : return mxSharedCanvas->drawBitmap(
457 0 : xBitmap, MergeViewState(aViewState), aRenderState);
458 : }
459 :
460 : css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
461 0 : PresenterCanvas::drawBitmapModulated(
462 : const css::uno::Reference< css::rendering::XBitmap>& xBitmap,
463 : const css::rendering::ViewState& aViewState,
464 : const css::rendering::RenderState& aRenderState)
465 : throw (css::lang::IllegalArgumentException,
466 : css::rendering::VolatileContentDestroyedException,
467 : css::uno::RuntimeException, std::exception)
468 : {
469 0 : ThrowIfDisposed();
470 0 : return mxSharedCanvas->drawBitmapModulated(
471 0 : xBitmap, MergeViewState(aViewState), aRenderState);
472 : }
473 :
474 : css::uno::Reference<css::rendering::XGraphicDevice> SAL_CALL
475 0 : PresenterCanvas::getDevice (void)
476 : throw (css::uno::RuntimeException, std::exception)
477 : {
478 0 : ThrowIfDisposed();
479 0 : return mxSharedCanvas->getDevice();
480 : }
481 :
482 : //----- XSpriteCanvas ---------------------------------------------------------
483 :
484 : Reference<rendering::XAnimatedSprite> SAL_CALL
485 0 : PresenterCanvas::createSpriteFromAnimation (
486 : const css::uno::Reference<css::rendering::XAnimation>& rAnimation)
487 : throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception)
488 : {
489 0 : ThrowIfDisposed();
490 :
491 0 : Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxSharedCanvas, UNO_QUERY);
492 0 : if (xSpriteCanvas.is())
493 0 : return xSpriteCanvas->createSpriteFromAnimation(rAnimation);
494 : else
495 0 : return NULL;
496 : }
497 :
498 : Reference<rendering::XAnimatedSprite> SAL_CALL
499 0 : PresenterCanvas::createSpriteFromBitmaps (
500 : const css::uno::Sequence<
501 : css::uno::Reference< css::rendering::XBitmap > >& rAnimationBitmaps,
502 : ::sal_Int8 nInterpolationMode)
503 : throw (css::lang::IllegalArgumentException,
504 : css::rendering::VolatileContentDestroyedException,
505 : css::uno::RuntimeException, std::exception)
506 : {
507 0 : ThrowIfDisposed();
508 :
509 0 : Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxSharedCanvas, UNO_QUERY);
510 0 : if (xSpriteCanvas.is())
511 0 : return xSpriteCanvas->createSpriteFromBitmaps(rAnimationBitmaps, nInterpolationMode);
512 : else
513 0 : return NULL;
514 : }
515 :
516 : Reference<rendering::XCustomSprite> SAL_CALL
517 0 : PresenterCanvas::createCustomSprite (
518 : const css::geometry::RealSize2D& rSpriteSize)
519 : throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception)
520 : {
521 0 : ThrowIfDisposed();
522 :
523 0 : Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxSharedCanvas, UNO_QUERY);
524 0 : if (xSpriteCanvas.is())
525 : return new PresenterCustomSprite(
526 : this,
527 0 : xSpriteCanvas->createCustomSprite(rSpriteSize),
528 : mxSharedWindow,
529 0 : rSpriteSize);
530 0 : else if (mxUpdateCanvas.is())
531 : return new PresenterCustomSprite(
532 : this,
533 0 : mxUpdateCanvas->createCustomSprite(rSpriteSize),
534 : mxUpdateWindow,
535 0 : rSpriteSize);
536 : else
537 0 : return NULL;
538 : }
539 :
540 : Reference<rendering::XSprite> SAL_CALL
541 0 : PresenterCanvas::createClonedSprite (
542 : const css::uno::Reference< css::rendering::XSprite >& rxOriginal)
543 : throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception)
544 : {
545 0 : ThrowIfDisposed();
546 :
547 0 : Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxSharedCanvas, UNO_QUERY);
548 0 : if (xSpriteCanvas.is())
549 0 : return xSpriteCanvas->createClonedSprite(rxOriginal);
550 0 : if (mxUpdateCanvas.is())
551 0 : return mxUpdateCanvas->createClonedSprite(rxOriginal);
552 0 : return NULL;
553 : }
554 :
555 0 : sal_Bool SAL_CALL PresenterCanvas::updateScreen (sal_Bool bUpdateAll)
556 : throw (css::uno::RuntimeException, std::exception)
557 : {
558 0 : ThrowIfDisposed();
559 :
560 0 : mbOffsetUpdatePending = true;
561 0 : if (mpUpdateRequester.get() != NULL)
562 : {
563 0 : mpUpdateRequester->RequestUpdate(bUpdateAll);
564 0 : return sal_True;
565 : }
566 : else
567 : {
568 0 : return sal_False;
569 : }
570 : }
571 :
572 : //----- XEventListener --------------------------------------------------------
573 :
574 0 : void SAL_CALL PresenterCanvas::disposing (const css::lang::EventObject& rEvent)
575 : throw (css::uno::RuntimeException, std::exception)
576 : {
577 0 : ThrowIfDisposed();
578 0 : if (rEvent.Source == mxWindow)
579 0 : mxWindow = NULL;
580 0 : }
581 :
582 : //----- XWindowListener -------------------------------------------------------
583 :
584 0 : void SAL_CALL PresenterCanvas::windowResized (const css::awt::WindowEvent& rEvent)
585 : throw (css::uno::RuntimeException, std::exception)
586 : {
587 : (void)rEvent;
588 0 : ThrowIfDisposed();
589 0 : mbOffsetUpdatePending = true;
590 0 : }
591 :
592 0 : void SAL_CALL PresenterCanvas::windowMoved (const css::awt::WindowEvent& rEvent)
593 : throw (css::uno::RuntimeException, std::exception)
594 : {
595 : (void)rEvent;
596 0 : ThrowIfDisposed();
597 0 : mbOffsetUpdatePending = true;
598 0 : }
599 :
600 0 : void SAL_CALL PresenterCanvas::windowShown (const css::lang::EventObject& rEvent)
601 : throw (css::uno::RuntimeException, std::exception)
602 : {
603 : (void)rEvent;
604 0 : ThrowIfDisposed();
605 0 : mbOffsetUpdatePending = true;
606 0 : }
607 :
608 0 : void SAL_CALL PresenterCanvas::windowHidden (const css::lang::EventObject& rEvent)
609 : throw (css::uno::RuntimeException, std::exception)
610 : {
611 : (void)rEvent;
612 0 : ThrowIfDisposed();
613 0 : }
614 :
615 : //----- XBitmap ---------------------------------------------------------------
616 :
617 0 : geometry::IntegerSize2D SAL_CALL PresenterCanvas::getSize (void)
618 : throw (RuntimeException, std::exception)
619 : {
620 0 : ThrowIfDisposed();
621 :
622 0 : if (mxWindow.is())
623 : {
624 0 : const awt::Rectangle aWindowBox (mxWindow->getPosSize());
625 0 : return geometry::IntegerSize2D(aWindowBox.Width, aWindowBox.Height);
626 : }
627 : else
628 0 : return geometry::IntegerSize2D(0,0);
629 : }
630 :
631 0 : sal_Bool SAL_CALL PresenterCanvas::hasAlpha (void)
632 : throw (RuntimeException, std::exception)
633 : {
634 0 : Reference<rendering::XBitmap> xBitmap (mxSharedCanvas, UNO_QUERY);
635 0 : if (xBitmap.is())
636 0 : return xBitmap->hasAlpha();
637 : else
638 0 : return sal_False;
639 : }
640 :
641 0 : Reference<rendering::XBitmap> SAL_CALL PresenterCanvas::getScaledBitmap(
642 : const css::geometry::RealSize2D& rNewSize,
643 : sal_Bool bFast)
644 : throw (css::uno::RuntimeException,
645 : css::lang::IllegalArgumentException,
646 : css::rendering::VolatileContentDestroyedException, std::exception)
647 : {
648 : (void)rNewSize;
649 : (void)bFast;
650 :
651 0 : ThrowIfDisposed();
652 :
653 : // Not implemented.
654 :
655 0 : return NULL;
656 : }
657 :
658 0 : rendering::ViewState PresenterCanvas::MergeViewState (
659 : const rendering::ViewState& rViewState)
660 : {
661 : // Make sure the offset is up-to-date.
662 0 : if (mbOffsetUpdatePending)
663 0 : maOffset = GetOffset(mxSharedWindow);
664 0 : return MergeViewState(rViewState, maOffset);
665 : }
666 :
667 0 : css::rendering::ViewState PresenterCanvas::MergeViewState (
668 : const css::rendering::ViewState& rViewState,
669 : const css::awt::Point& rOffset)
670 : {
671 : // Early rejects.
672 0 : if ( ! mxSharedCanvas.is())
673 0 : return rViewState;
674 :
675 0 : Reference<rendering::XGraphicDevice> xDevice (mxSharedCanvas->getDevice());
676 0 : if ( ! xDevice.is())
677 0 : return rViewState;
678 :
679 : // Create a modifiable copy of the given view state.
680 0 : rendering::ViewState aViewState (rViewState);
681 :
682 : // Prepare the local clip rectangle.
683 0 : ::basegfx::B2DRectangle aWindowRange (GetClipRectangle(aViewState.AffineTransform, rOffset));
684 :
685 : // Adapt the offset of the view state.
686 0 : aViewState.AffineTransform.m02 += rOffset.X;
687 0 : aViewState.AffineTransform.m12 += rOffset.Y;
688 :
689 : // Adapt the clip polygon.
690 0 : if ( ! aViewState.Clip.is())
691 : {
692 : // Cancel out the later multiplication with the view state
693 : // transformation.
694 0 : aViewState.Clip = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
695 : xDevice,
696 0 : ::basegfx::B2DPolyPolygon(::basegfx::tools::createPolygonFromRect(aWindowRange)));
697 : }
698 : else
699 : {
700 : // Have to compute the intersection of the given clipping polygon in
701 : // the view state and the local clip rectangle.
702 :
703 : // Clip the view state clipping polygon against the local clip rectangle.
704 : const ::basegfx::B2DPolyPolygon aClipPolygon (
705 : ::basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(
706 0 : aViewState.Clip));
707 : const ::basegfx::B2DPolyPolygon aClippedClipPolygon (
708 : ::basegfx::tools::clipPolyPolygonOnRange(
709 : aClipPolygon,
710 : aWindowRange,
711 : true, /* bInside */
712 0 : false /* bStroke */));
713 :
714 0 : aViewState.Clip = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
715 : xDevice,
716 0 : aClippedClipPolygon);
717 : }
718 :
719 0 : return aViewState;
720 : }
721 :
722 0 : awt::Point PresenterCanvas::GetOffset (const Reference<awt::XWindow>& rxBaseWindow)
723 : {
724 0 : mbOffsetUpdatePending = false;
725 0 : if (mxWindow.is() && rxBaseWindow.is())
726 : {
727 0 : vcl::Window* pWindow = VCLUnoHelper::GetWindow(mxWindow);
728 0 : vcl::Window* pSharedWindow = VCLUnoHelper::GetWindow(rxBaseWindow);
729 0 : if (pWindow!=NULL && pSharedWindow!=NULL)
730 : {
731 0 : Rectangle aBox = pWindow->GetWindowExtentsRelative(pSharedWindow);
732 :
733 : // Calculate offset of this canvas with respect to the shared
734 : // canvas.
735 0 : return awt::Point(aBox.Left(), aBox.Top());
736 : }
737 : }
738 :
739 0 : return awt::Point(0, 0);
740 : }
741 :
742 0 : ::basegfx::B2DRectangle PresenterCanvas::GetClipRectangle (
743 : const css::geometry::AffineMatrix2D& rViewTransform,
744 : const awt::Point& rOffset)
745 : {
746 0 : ::basegfx::B2DRectangle aClipRectangle;
747 :
748 0 : vcl::Window* pWindow = VCLUnoHelper::GetWindow(mxWindow);
749 0 : if (pWindow == NULL)
750 0 : return ::basegfx::B2DRectangle();
751 :
752 0 : vcl::Window* pSharedWindow = VCLUnoHelper::GetWindow(mxSharedWindow);
753 0 : if (pSharedWindow == NULL)
754 0 : return ::basegfx::B2DRectangle();
755 :
756 : // Get the bounding box of the window and create a range in the
757 : // coordinate system of the child window.
758 0 : Rectangle aLocalClip;
759 0 : if (maClipRectangle.Width <= 0 || maClipRectangle.Height <= 0)
760 : {
761 : // No clip rectangle has been set via SetClip by the pane.
762 : // Use the window extents instead.
763 0 : aLocalClip = pWindow->GetWindowExtentsRelative(pSharedWindow);
764 : }
765 : else
766 : {
767 : // Use a previously given clip rectangle.
768 : aLocalClip = Rectangle(
769 0 : maClipRectangle.X + rOffset.X,
770 0 : maClipRectangle.Y + rOffset.Y,
771 0 : maClipRectangle.X + maClipRectangle.Width + rOffset.X,
772 0 : maClipRectangle.Y + maClipRectangle.Height + rOffset.Y);
773 : }
774 :
775 : // The local clip rectangle is used to clip the view state clipping
776 : // polygon.
777 : ::basegfx::B2DRectangle aWindowRectangle (
778 0 : aLocalClip.Left() - rOffset.X,
779 0 : aLocalClip.Top() - rOffset.Y,
780 0 : aLocalClip.Right() - rOffset.X + 1,
781 0 : aLocalClip.Bottom() - rOffset.Y + 1);
782 :
783 : // Calculate the inverted view state transformation to cancel out a
784 : // later transformation of the local clip polygon with the view state
785 : // transformation.
786 0 : ::basegfx::B2DHomMatrix aInvertedViewStateTransformation;
787 : ::basegfx::unotools::homMatrixFromAffineMatrix(
788 : aInvertedViewStateTransformation,
789 0 : rViewTransform);
790 0 : if (aInvertedViewStateTransformation.invert())
791 : {
792 : // Cancel out the later multiplication with the view state
793 : // transformation.
794 0 : aWindowRectangle.transform(aInvertedViewStateTransformation);
795 : }
796 :
797 0 : return aWindowRectangle;
798 : }
799 :
800 0 : Reference<rendering::XPolyPolygon2D> PresenterCanvas::UpdateSpriteClip (
801 : const Reference<rendering::XPolyPolygon2D>& rxOriginalClip,
802 : const geometry::RealPoint2D& rLocation,
803 : const geometry::RealSize2D& rSize)
804 : {
805 : (void)rSize;
806 :
807 : // Check used resources and just return the original clip when not
808 : // every one of them is available.
809 0 : if ( ! mxWindow.is())
810 0 : return rxOriginalClip;
811 :
812 0 : Reference<rendering::XGraphicDevice> xDevice (mxSharedCanvas->getDevice());
813 0 : if ( ! xDevice.is())
814 0 : return rxOriginalClip;
815 :
816 : // Determine the bounds of the clip rectangle (the window border) in the
817 : // coordinate system of the sprite.
818 0 : const awt::Rectangle aWindowBox (mxWindow->getPosSize());
819 0 : const double nMinX (-rLocation.X);
820 0 : const double nMinY (-rLocation.Y);
821 0 : const double nMaxX (aWindowBox.Width-rLocation.X);
822 0 : const double nMaxY (aWindowBox.Height-rLocation.Y);
823 :
824 : // Create a clip polygon.
825 0 : Reference<rendering::XPolyPolygon2D> xPolygon;
826 0 : if (rxOriginalClip.is())
827 : {
828 : // Combine the original clip with the window clip.
829 : const ::basegfx::B2DPolyPolygon aOriginalClip (
830 0 : ::basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(rxOriginalClip));
831 0 : ::basegfx::B2DRectangle aWindowRange (nMinX, nMinY, nMaxX, nMaxY);
832 : const ::basegfx::B2DPolyPolygon aClippedClipPolygon (
833 : ::basegfx::tools::clipPolyPolygonOnRange(
834 : aOriginalClip,
835 : aWindowRange,
836 : true, /* bInside */
837 0 : false /* bStroke */));
838 0 : xPolygon = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
839 : xDevice,
840 0 : aClippedClipPolygon);
841 : }
842 : else
843 : {
844 : // Create a new clip polygon from the window clip rectangle.
845 0 : Sequence<Sequence<geometry::RealPoint2D> > aPoints (1);
846 0 : aPoints[0] = Sequence<geometry::RealPoint2D>(4);
847 0 : aPoints[0][0] = geometry::RealPoint2D(nMinX,nMinY);
848 0 : aPoints[0][1] = geometry::RealPoint2D(nMaxX,nMinY);
849 0 : aPoints[0][2] = geometry::RealPoint2D(nMaxX,nMaxY);
850 0 : aPoints[0][3] = geometry::RealPoint2D(nMinX,nMaxY);
851 : Reference<rendering::XLinePolyPolygon2D> xLinePolygon(
852 0 : xDevice->createCompatibleLinePolyPolygon(aPoints));
853 0 : if (xLinePolygon.is())
854 0 : xLinePolygon->setClosed(0, sal_True);
855 0 : xPolygon = Reference<rendering::XPolyPolygon2D>(xLinePolygon, UNO_QUERY);
856 : }
857 :
858 0 : return xPolygon;
859 : }
860 :
861 0 : void PresenterCanvas::ThrowIfDisposed (void)
862 : throw (css::lang::DisposedException)
863 : {
864 0 : if (rBHelper.bDisposed || rBHelper.bInDispose || ! mxSharedCanvas.is())
865 : {
866 : throw lang::DisposedException ("PresenterCanvas object has already been disposed",
867 0 : static_cast<uno::XWeak*>(this));
868 : }
869 0 : }
870 :
871 : //===== PresenterCustomSprite =================================================
872 :
873 0 : PresenterCustomSprite::PresenterCustomSprite (
874 : const rtl::Reference<PresenterCanvas>& rpCanvas,
875 : const Reference<rendering::XCustomSprite>& rxSprite,
876 : const Reference<awt::XWindow>& rxBaseWindow,
877 : const css::geometry::RealSize2D& rSpriteSize)
878 : : PresenterCustomSpriteInterfaceBase(m_aMutex),
879 : mpCanvas(rpCanvas),
880 : mxSprite(rxSprite),
881 : mxBaseWindow(rxBaseWindow),
882 : maPosition(0,0),
883 0 : maSpriteSize(rSpriteSize)
884 : {
885 0 : }
886 :
887 0 : PresenterCustomSprite::~PresenterCustomSprite (void)
888 : {
889 0 : }
890 :
891 0 : void SAL_CALL PresenterCustomSprite::disposing (void)
892 : throw (RuntimeException)
893 : {
894 0 : Reference<XComponent> xComponent (mxSprite, UNO_QUERY);
895 0 : mxSprite = NULL;
896 0 : if (xComponent.is())
897 0 : xComponent->dispose();
898 0 : mpCanvas = rtl::Reference<PresenterCanvas>();
899 0 : }
900 :
901 : //----- XSprite ---------------------------------------------------------------
902 :
903 0 : void SAL_CALL PresenterCustomSprite::setAlpha (const double nAlpha)
904 : throw (lang::IllegalArgumentException,RuntimeException, std::exception)
905 : {
906 0 : ThrowIfDisposed();
907 0 : mxSprite->setAlpha(nAlpha);
908 0 : }
909 :
910 0 : void SAL_CALL PresenterCustomSprite::move (
911 : const geometry::RealPoint2D& rNewPos,
912 : const rendering::ViewState& rViewState,
913 : const rendering::RenderState& rRenderState)
914 : throw (lang::IllegalArgumentException,RuntimeException, std::exception)
915 : {
916 0 : ThrowIfDisposed();
917 0 : maPosition = rNewPos;
918 0 : mxSprite->move(
919 : rNewPos,
920 0 : mpCanvas->MergeViewState(rViewState, mpCanvas->GetOffset(mxBaseWindow)),
921 0 : rRenderState);
922 : // Clip sprite against window bounds. This call is necessary because
923 : // sprite clipping is done in the corrdinate system of the sprite.
924 : // Therefore, after each change of the sprites location the window
925 : // bounds have to be transformed into the sprites coordinate system.
926 0 : clip(NULL);
927 0 : }
928 :
929 0 : void SAL_CALL PresenterCustomSprite::transform (const geometry::AffineMatrix2D& rTransformation)
930 : throw (lang::IllegalArgumentException,RuntimeException, std::exception)
931 : {
932 0 : ThrowIfDisposed();
933 0 : mxSprite->transform(rTransformation);
934 0 : }
935 :
936 0 : void SAL_CALL PresenterCustomSprite::clip (const Reference<rendering::XPolyPolygon2D>& rxClip)
937 : throw (RuntimeException, std::exception)
938 : {
939 0 : ThrowIfDisposed();
940 : // The clip region is expected in the coordinate system of the sprite.
941 : // UpdateSpriteClip() integrates the window bounds, transformed into the
942 : // sprites coordinate system, with the given clip.
943 0 : mxSprite->clip(mpCanvas->UpdateSpriteClip(rxClip, maPosition, maSpriteSize));
944 0 : }
945 :
946 0 : void SAL_CALL PresenterCustomSprite::setPriority (const double nPriority)
947 : throw (RuntimeException, std::exception)
948 : {
949 0 : ThrowIfDisposed();
950 0 : mxSprite->setPriority(nPriority);
951 0 : }
952 :
953 0 : void SAL_CALL PresenterCustomSprite::show (void)
954 : throw (RuntimeException, std::exception)
955 : {
956 0 : ThrowIfDisposed();
957 0 : mxSprite->show();
958 0 : }
959 :
960 0 : void SAL_CALL PresenterCustomSprite::hide (void)
961 : throw (RuntimeException, std::exception)
962 : {
963 0 : ThrowIfDisposed();
964 0 : mxSprite->hide();
965 0 : }
966 :
967 : //----- XCustomSprite ---------------------------------------------------------
968 :
969 0 : Reference<rendering::XCanvas> PresenterCustomSprite::getContentCanvas (void)
970 : throw (RuntimeException, std::exception)
971 : {
972 0 : ThrowIfDisposed();
973 0 : return mxSprite->getContentCanvas();
974 : }
975 :
976 0 : void PresenterCustomSprite::ThrowIfDisposed (void)
977 : throw (css::lang::DisposedException)
978 : {
979 0 : if (rBHelper.bDisposed || rBHelper.bInDispose || ! mxSprite.is())
980 : {
981 : throw lang::DisposedException ("PresenterCustomSprite object has already been disposed",
982 0 : static_cast<uno::XWeak*>(this));
983 : }
984 0 : }
985 :
986 114 : } } // end of namespace ::sd::presenter
987 :
988 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|