Update ooo320-m1
[ooovba.git] / sdext / source / presenter / PresenterSlideShowView.cxx
blobcf627267176010c26554a9cd8098a0f140f9f82e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PresenterSlideShowView.cxx,v $
11 * $Revision: 1.7 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sdext.hxx"
35 #include "PresenterSlideShowView.hxx"
37 #include "PresenterCanvasHelper.hxx"
38 #include "PresenterGeometryHelper.hxx"
39 #include "PresenterHelper.hxx"
40 #include "PresenterPaneContainer.hxx"
41 #include <com/sun/star/awt/InvalidateStyle.hpp>
42 #include <com/sun/star/awt/PosSize.hpp>
43 #include <com/sun/star/awt/WindowAttribute.hpp>
44 #include <com/sun/star/awt/XWindow.hpp>
45 #include <com/sun/star/awt/XWindow2.hpp>
46 #include <com/sun/star/awt/XWindowPeer.hpp>
47 #include <com/sun/star/beans/XPropertySet.hpp>
48 #include <com/sun/star/drawing/CanvasFeature.hpp>
49 #include <com/sun/star/drawing/XPresenterHelper.hpp>
50 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
51 #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
52 #include <com/sun/star/rendering/CompositeOperation.hpp>
53 #include <com/sun/star/rendering/TextDirection.hpp>
54 #include <com/sun/star/rendering/TexturingMode.hpp>
55 #include <osl/mutex.hxx>
57 using namespace ::com::sun::star;
58 using namespace ::com::sun::star::uno;
59 using namespace ::com::sun::star::drawing::framework;
60 using ::rtl::OUString;
62 #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString)))
64 namespace sdext { namespace presenter {
66 //===== PresenterSlideShowView ================================================
68 PresenterSlideShowView::PresenterSlideShowView (
69 const css::uno::Reference<css::uno::XComponentContext>& rxContext,
70 const css::uno::Reference<css::drawing::framework::XResourceId>& rxViewId,
71 const css::uno::Reference<css::frame::XController>& rxController,
72 const ::rtl::Reference<PresenterController>& rpPresenterController)
73 : PresenterSlideShowViewInterfaceBase(m_aMutex),
74 mxComponentContext(rxContext),
75 mpPresenterController(rpPresenterController),
76 mxViewId(rxViewId),
77 mxController(rxController),
78 mxSlideShowController(PresenterHelper::GetSlideShowController(rxController)),
79 mxSlideShow(),
80 mxCanvas(),
81 mxViewCanvas(),
82 mxPointer(),
83 mxWindow(),
84 mxViewWindow(),
85 mxTopPane(),
86 mxPresenterHelper(),
87 mxBackgroundPolygon1(),
88 mxBackgroundPolygon2(),
89 mbIsViewAdded(false),
90 mnPageAspectRatio(28.0/21.0),
91 maBroadcaster(m_aMutex),
92 mpBackground(),
93 mbIsInModifyNotification(false),
94 mbIsForcedPaintPending(false),
95 mbIsPaintPending(true),
96 msClickToExitPresentationText(),
97 msClickToExitPresentationTitle(),
98 msTitleTemplate(),
99 mbIsEndSlideVisible(false),
100 mxCurrentSlide()
102 if (mpPresenterController.get() != NULL)
104 mnPageAspectRatio = mpPresenterController->GetSlideAspectRatio();
105 mpBackground = mpPresenterController->GetViewBackground(mxViewId->getResourceURL());
111 void PresenterSlideShowView::LateInit (void)
113 mxSlideShow = Reference<presentation::XSlideShow> (
114 mxSlideShowController->getSlideShow(), UNO_QUERY_THROW);
115 Reference<lang::XComponent> xSlideShowComponent (mxSlideShow, UNO_QUERY);
116 if (xSlideShowComponent.is())
117 xSlideShowComponent->addEventListener(static_cast<awt::XWindowListener*>(this));
119 Reference<lang::XMultiComponentFactory> xFactory (
120 mxComponentContext->getServiceManager(), UNO_QUERY_THROW);
121 mxPresenterHelper.set (xFactory->createInstanceWithContext(
122 OUString::createFromAscii("com.sun.star.comp.Draw.PresenterHelper"),
123 mxComponentContext),
124 UNO_QUERY_THROW);
126 // Use view id and controller to retrieve window and canvas from
127 // configuration controller.
128 Reference<XControllerManager> xCM (mxController, UNO_QUERY_THROW);
129 Reference<XConfigurationController> xCC (xCM->getConfigurationController());
131 if (xCC.is())
133 mxTopPane.set(xCC->getResource(mxViewId->getAnchor()->getAnchor()), UNO_QUERY);
135 Reference<XPane> xPane (xCC->getResource(mxViewId->getAnchor()), UNO_QUERY_THROW);
137 mxWindow = xPane->getWindow();
138 mxCanvas = xPane->getCanvas();
140 if (mxWindow.is())
142 mxWindow->addPaintListener(this);
143 mxWindow->addWindowListener(this);
146 // The window does not have to paint a background. We do
147 // that ourself.
148 Reference<awt::XWindowPeer> xPeer (mxWindow, UNO_QUERY);
149 if (xPeer.is())
150 xPeer->setBackground(util::Color(0xff000000));
153 // Create a window for the actual slide show view. It is places
154 // centered and with maximal size inside the pane.
155 mxViewWindow = CreateViewWindow(mxWindow);
157 mxViewCanvas = CreateViewCanvas(mxViewWindow);
159 if (mxViewWindow.is())
161 // Register listeners at window.
162 mxViewWindow->addPaintListener(this);
163 mxViewWindow->addMouseListener(this);
164 mxViewWindow->addMouseMotionListener(this);
167 if (mxViewWindow.is())
168 Resize();
170 if (mxWindow.is())
171 mxWindow->setVisible(sal_True);
173 // Add the new slide show view to the slide show.
174 if (mxSlideShow.is() && ! mbIsViewAdded)
176 Reference<presentation::XSlideShowView> xView (this);
177 mxSlideShow->addView(xView);
178 // Prevent embeded sounds being played twice at the same time by
179 // disabling sound for the new slide show view.
180 beans::PropertyValue aProperty;
181 aProperty.Name = A2S("IsSoundEnabled");
182 Sequence<Any> aValues (2);
183 aValues[0] <<= xView;
184 aValues[1] <<= sal_False;
185 aProperty.Value <<= aValues;
186 mxSlideShow->setProperty(aProperty);
187 mbIsViewAdded = true;
190 // Read text for one past last slide.
191 PresenterConfigurationAccess aConfiguration (
192 mxComponentContext,
193 PresenterConfigurationAccess::msPresenterScreenRootName,
194 PresenterConfigurationAccess::READ_ONLY);
195 aConfiguration.GetConfigurationNode(
196 A2S("Presenter/Views/CurrentSlidePreview/"
197 "Strings/ClickToExitPresentationText/String"))
198 >>= msClickToExitPresentationText;
199 aConfiguration.GetConfigurationNode(
200 A2S("Presenter/Views/CurrentSlidePreview/"
201 "Strings/ClickToExitPresentationTitle/String"))
202 >>= msClickToExitPresentationTitle;
208 PresenterSlideShowView::~PresenterSlideShowView (void)
215 void PresenterSlideShowView::disposing (void)
217 // Tell all listeners that we are disposed.
218 lang::EventObject aEvent;
219 aEvent.Source = static_cast<XWeak*>(this);
221 ::cppu::OInterfaceContainerHelper* pIterator
222 = maBroadcaster.getContainer(getCppuType((Reference<lang::XEventListener>*)NULL));
223 if (pIterator != NULL)
224 pIterator->disposeAndClear(aEvent);
226 // Do this for
227 // XPaintListener, XModifyListener,XMouseListener,XMouseMotionListener,XWindowListener?
229 if (mxWindow.is())
231 mxWindow->removePaintListener(this);
232 mxWindow->removeMouseListener(this);
233 mxWindow->removeMouseMotionListener(this);
234 mxWindow->removeWindowListener(this);
235 mxWindow = NULL;
237 mxSlideShowController = NULL;
238 mxSlideShow = NULL;
239 if (mxViewCanvas.is())
241 Reference<XComponent> xComponent (mxViewCanvas, UNO_QUERY);
242 mxViewCanvas = NULL;
243 if (xComponent.is())
244 xComponent->dispose();
246 if (mxViewWindow.is())
248 Reference<XComponent> xComponent (mxViewWindow, UNO_QUERY);
249 mxViewWindow = NULL;
250 if (xComponent.is())
251 xComponent->dispose();
253 if (mxPointer.is())
255 Reference<XComponent> xComponent (mxPointer, UNO_QUERY);
256 mxPointer = NULL;
257 if (xComponent.is())
258 xComponent->dispose();
260 if (mxBackgroundPolygon1.is())
262 Reference<XComponent> xComponent (mxBackgroundPolygon1, UNO_QUERY);
263 mxBackgroundPolygon1 = NULL;
264 if (xComponent.is())
265 xComponent->dispose();
267 if (mxBackgroundPolygon2.is())
269 Reference<XComponent> xComponent (mxBackgroundPolygon2, UNO_QUERY);
270 mxBackgroundPolygon2 = NULL;
271 if (xComponent.is())
272 xComponent->dispose();
275 mxComponentContext = NULL;
276 mpPresenterController = NULL;
277 mxViewId = NULL;
278 mxController = NULL;
279 mxCanvas = NULL;
280 mpBackground.reset();
281 msClickToExitPresentationText = OUString();
282 msClickToExitPresentationTitle = OUString();
283 msTitleTemplate = OUString();
284 mxCurrentSlide = NULL;
290 //----- XDrawView -------------------------------------------------------------
292 void SAL_CALL PresenterSlideShowView::setCurrentPage (
293 const css::uno::Reference<css::drawing::XDrawPage>& rxSlide)
294 throw (css::uno::RuntimeException)
296 mxCurrentSlide = rxSlide;
297 if (mpPresenterController.get() != NULL
298 && mxSlideShowController.is()
299 && ! mpPresenterController->GetCurrentSlide().is()
300 && ! mxSlideShowController->isPaused())
302 mbIsEndSlideVisible = true;
303 Reference<awt::XWindowPeer> xPeer (mxViewWindow, UNO_QUERY);
304 if (xPeer.is())
305 xPeer->invalidate(awt::InvalidateStyle::NOTRANSPARENT);
307 // For the end slide we use a special title, without the (n of m)
308 // part. Save the title template for the case that the user goes
309 // backwards.
310 PresenterPaneContainer::SharedPaneDescriptor pDescriptor (
311 mpPresenterController->GetPaneContainer()->FindViewURL(mxViewId->getResourceURL()));
312 if (pDescriptor.get() != NULL)
314 msTitleTemplate = pDescriptor->msTitleTemplate;
315 pDescriptor->msTitleTemplate = msClickToExitPresentationTitle;
316 mpPresenterController->UpdatePaneTitles();
319 else if (mbIsEndSlideVisible)
321 mbIsEndSlideVisible = false;
323 // Restore the title template.
324 PresenterPaneContainer::SharedPaneDescriptor pDescriptor (
325 mpPresenterController->GetPaneContainer()->FindViewURL(mxViewId->getResourceURL()));
326 if (pDescriptor.get() != NULL)
328 pDescriptor->msTitleTemplate = msTitleTemplate;
329 pDescriptor->msTitle = OUString();
330 mpPresenterController->UpdatePaneTitles();
338 css::uno::Reference<css::drawing::XDrawPage> SAL_CALL PresenterSlideShowView::getCurrentPage (void)
339 throw (css::uno::RuntimeException)
341 return mxCurrentSlide;
347 //----- CachablePresenterView -------------------------------------------------
349 void PresenterSlideShowView::ReleaseView (void)
351 if (mxSlideShow.is() && mbIsViewAdded)
353 mxSlideShow->removeView(this);
354 mbIsViewAdded = false;
361 //----- XSlideShowView --------------------------------------------------------
363 Reference<rendering::XSpriteCanvas> SAL_CALL PresenterSlideShowView::getCanvas (void)
364 throw (RuntimeException)
366 ThrowIfDisposed();
368 return Reference<rendering::XSpriteCanvas>(mxViewCanvas, UNO_QUERY);
374 void SAL_CALL PresenterSlideShowView::clear (void)
375 throw (RuntimeException)
377 ThrowIfDisposed();
378 mbIsForcedPaintPending = false;
379 mbIsPaintPending = false;
381 if (mxViewCanvas.is() && mxViewWindow.is())
383 // Create a polygon for the window outline.
384 awt::Rectangle aViewWindowBox (mxViewWindow->getPosSize());
385 Reference<rendering::XPolyPolygon2D> xPolygon (PresenterGeometryHelper::CreatePolygon(
386 awt::Rectangle(0,0, aViewWindowBox.Width,aViewWindowBox.Height),
387 mxViewCanvas->getDevice()));
389 rendering::ViewState aViewState (
390 geometry::AffineMatrix2D(1,0,0, 0,1,0),
391 NULL);
392 double aColor[3] = {0,0,0};
393 rendering::RenderState aRenderState(
394 geometry::AffineMatrix2D(1,0,0, 0,1,0),
395 NULL,
396 Sequence<double>(aColor,4),
397 rendering::CompositeOperation::SOURCE);
398 mxViewCanvas->fillPolyPolygon(xPolygon, aViewState, aRenderState);
405 geometry::AffineMatrix2D SAL_CALL PresenterSlideShowView::getTransformation (void)
406 throw (RuntimeException)
408 ThrowIfDisposed();
410 if (mxViewWindow.is())
412 // When the mbIsInModifyNotification is set then a slightly modifed
413 // version of the transformation is returned in order to get past
414 // optimizations the avoid updates when the transformation is
415 // unchanged (when the window size changes then due to the constant
416 // aspect ratio the size of the preview may remain the same while
417 // the position changes. The position, however, is repesented by
418 // the position of the view window. This transformation is given
419 // relative to the view window and therefore does not contain the
420 // position.)
421 const awt::Rectangle aWindowBox = mxViewWindow->getPosSize();
422 return geometry::AffineMatrix2D(
423 aWindowBox.Width-1, 0, (mbIsInModifyNotification ? 1 : 0),
424 0, aWindowBox.Height-1, 0);
426 else
428 return geometry::AffineMatrix2D(1,0,0, 0,1,0);
435 void SAL_CALL PresenterSlideShowView::addTransformationChangedListener(
436 const Reference<util::XModifyListener>& rxListener)
437 throw (RuntimeException)
439 ThrowIfDisposed();
440 maBroadcaster.addListener(
441 getCppuType((Reference<util::XModifyListener>*)NULL),
442 rxListener);
448 void SAL_CALL PresenterSlideShowView::removeTransformationChangedListener(
449 const Reference<util::XModifyListener>& rxListener)
450 throw (RuntimeException)
452 ThrowIfDisposed();
453 maBroadcaster.removeListener(
454 getCppuType((Reference<util::XModifyListener>*)NULL),
455 rxListener);
461 void SAL_CALL PresenterSlideShowView::addPaintListener(
462 const Reference<awt::XPaintListener>& rxListener)
463 throw (RuntimeException)
465 ThrowIfDisposed();
466 maBroadcaster.addListener(
467 getCppuType((Reference<awt::XPaintListener>*)NULL),
468 rxListener);
474 void SAL_CALL PresenterSlideShowView::removePaintListener(
475 const Reference<awt::XPaintListener>& rxListener)
476 throw (RuntimeException)
478 ThrowIfDisposed();
479 maBroadcaster.removeListener(
480 getCppuType((Reference<awt::XPaintListener>*)NULL),
481 rxListener);
487 void SAL_CALL PresenterSlideShowView::addMouseListener(
488 const Reference<awt::XMouseListener>& rxListener)
489 throw (RuntimeException)
491 ThrowIfDisposed();
492 maBroadcaster.addListener(
493 getCppuType((Reference<awt::XMouseListener>*)NULL),
494 rxListener);
500 void SAL_CALL PresenterSlideShowView::removeMouseListener(
501 const Reference<awt::XMouseListener>& rxListener)
502 throw (RuntimeException)
504 ThrowIfDisposed();
505 maBroadcaster.removeListener(
506 getCppuType((Reference<awt::XMouseListener>*)NULL),
507 rxListener);
513 void SAL_CALL PresenterSlideShowView::addMouseMotionListener(
514 const Reference<awt::XMouseMotionListener>& rxListener)
515 throw (RuntimeException)
517 ThrowIfDisposed();
518 maBroadcaster.addListener(
519 getCppuType((Reference<awt::XMouseMotionListener>*)NULL),
520 rxListener);
526 void SAL_CALL PresenterSlideShowView::removeMouseMotionListener(
527 const Reference<awt::XMouseMotionListener>& rxListener)
528 throw (RuntimeException)
530 ThrowIfDisposed();
531 maBroadcaster.removeListener(
532 getCppuType((Reference<awt::XMouseMotionListener>*)NULL),
533 rxListener);
539 void SAL_CALL PresenterSlideShowView::setMouseCursor(::sal_Int16 nPointerShape)
540 throw (RuntimeException)
542 ThrowIfDisposed();
544 // Create a pointer when it does not yet exist.
545 if ( ! mxPointer.is())
547 Reference<lang::XMultiServiceFactory> xFactory (
548 mxComponentContext, UNO_QUERY);
549 if (xFactory.is())
550 mxPointer = Reference<awt::XPointer>(
551 xFactory->createInstance(OUString::createFromAscii("com.sun.star.awt.Pointer")),
552 UNO_QUERY);
555 // Set the pointer to the given shape and the window(peer) to the
556 // pointer.
557 Reference<awt::XWindowPeer> xPeer (mxViewWindow, UNO_QUERY);
558 if (mxPointer.is() && xPeer.is())
560 mxPointer->setType(nPointerShape);
561 xPeer->setPointer(mxPointer);
567 awt::Rectangle SAL_CALL PresenterSlideShowView::getCanvasArea( ) throw (RuntimeException)
569 if( mxViewWindow.is() && mxTopPane.is() )
570 return mxPresenterHelper->getWindowExtentsRelative( mxViewWindow, mxTopPane->getWindow() );
572 awt::Rectangle aRectangle;
574 aRectangle.X = aRectangle.Y = aRectangle.Width = aRectangle.Height = 0;
576 return aRectangle;
581 //----- lang::XEventListener --------------------------------------------------
583 void SAL_CALL PresenterSlideShowView::disposing (const lang::EventObject& rEvent)
584 throw (RuntimeException)
586 if (rEvent.Source == mxViewWindow)
587 mxViewWindow = NULL;
588 else if (rEvent.Source == mxSlideShow)
589 mxSlideShow = NULL;
595 //----- XPaintListener --------------------------------------------------------
597 void SAL_CALL PresenterSlideShowView::windowPaint (const awt::PaintEvent& rEvent)
598 throw (RuntimeException)
600 // Deactivated views must not be painted.
601 if ( ! mbIsPresenterViewActive)
602 return;
604 awt::Rectangle aViewWindowBox (mxViewWindow->getPosSize());
605 if (aViewWindowBox.Width <= 0 || aViewWindowBox.Height <= 0)
606 return;
608 if (rEvent.Source == mxWindow)
609 PaintOuterWindow(rEvent.UpdateRect);
610 else if (mbIsEndSlideVisible)
611 PaintEndSlide(rEvent.UpdateRect);
612 else
613 PaintInnerWindow(rEvent);
619 //----- XMouseListener --------------------------------------------------------
621 void SAL_CALL PresenterSlideShowView::mousePressed (const awt::MouseEvent& rEvent)
622 throw (RuntimeException)
624 awt::MouseEvent aEvent (rEvent);
625 aEvent.Source = static_cast<XWeak*>(this);
626 ::cppu::OInterfaceContainerHelper* pIterator
627 = maBroadcaster.getContainer(getCppuType((Reference<awt::XMouseListener>*)NULL));
628 if (pIterator != NULL)
630 pIterator->notifyEach(&awt::XMouseListener::mousePressed, aEvent);
633 // Only when the end slide is displayed we forward the mouse event to
634 // the PresenterController so that it switches to the next slide and
635 // ends the presentation.
636 if (mbIsEndSlideVisible)
637 if (mpPresenterController.get() != NULL)
638 mpPresenterController->HandleMouseClick(rEvent);
644 void SAL_CALL PresenterSlideShowView::mouseReleased (const awt::MouseEvent& rEvent)
645 throw (RuntimeException)
647 awt::MouseEvent aEvent (rEvent);
648 aEvent.Source = static_cast<XWeak*>(this);
649 ::cppu::OInterfaceContainerHelper* pIterator
650 = maBroadcaster.getContainer(getCppuType((Reference<awt::XMouseListener>*)NULL));
651 if (pIterator != NULL)
653 pIterator->notifyEach(&awt::XMouseListener::mouseReleased, aEvent);
660 void SAL_CALL PresenterSlideShowView::mouseEntered (const awt::MouseEvent& rEvent)
661 throw (RuntimeException)
663 awt::MouseEvent aEvent (rEvent);
664 aEvent.Source = static_cast<XWeak*>(this);
665 ::cppu::OInterfaceContainerHelper* pIterator
666 = maBroadcaster.getContainer(getCppuType((Reference<awt::XMouseListener>*)NULL));
667 if (pIterator != NULL)
669 pIterator->notifyEach(&awt::XMouseListener::mouseEntered, aEvent);
676 void SAL_CALL PresenterSlideShowView::mouseExited (const awt::MouseEvent& rEvent)
677 throw (RuntimeException)
679 awt::MouseEvent aEvent (rEvent);
680 aEvent.Source = static_cast<XWeak*>(this);
681 ::cppu::OInterfaceContainerHelper* pIterator
682 = maBroadcaster.getContainer(getCppuType((Reference<awt::XMouseListener>*)NULL));
683 if (pIterator != NULL)
685 pIterator->notifyEach(&awt::XMouseListener::mouseExited, aEvent);
692 //----- XMouseMotionListener --------------------------------------------------
694 void SAL_CALL PresenterSlideShowView::mouseDragged (const awt::MouseEvent& rEvent)
695 throw (RuntimeException)
697 awt::MouseEvent aEvent (rEvent);
698 aEvent.Source = static_cast<XWeak*>(this);
699 ::cppu::OInterfaceContainerHelper* pIterator
700 = maBroadcaster.getContainer(getCppuType((Reference<awt::XMouseMotionListener>*)NULL));
701 if (pIterator != NULL)
703 pIterator->notifyEach(&awt::XMouseMotionListener::mouseDragged, aEvent);
710 void SAL_CALL PresenterSlideShowView::mouseMoved (const awt::MouseEvent& rEvent)
711 throw (RuntimeException)
713 awt::MouseEvent aEvent (rEvent);
714 aEvent.Source = static_cast<XWeak*>(this);
715 ::cppu::OInterfaceContainerHelper* pIterator
716 = maBroadcaster.getContainer(getCppuType((Reference<awt::XMouseMotionListener>*)NULL));
717 if (pIterator != NULL)
719 pIterator->notifyEach(&awt::XMouseMotionListener::mouseMoved, aEvent);
726 //----- XWindowListener -------------------------------------------------------
728 void SAL_CALL PresenterSlideShowView::windowResized (const awt::WindowEvent& rEvent)
729 throw (RuntimeException)
731 (void)rEvent;
733 ThrowIfDisposed();
734 ::osl::MutexGuard aGuard (::osl::Mutex::getGlobalMutex());
736 Resize();
743 void SAL_CALL PresenterSlideShowView::windowMoved (const awt::WindowEvent& rEvent)
744 throw (RuntimeException)
746 (void)rEvent;
747 if ( ! mbIsPaintPending)
748 mbIsForcedPaintPending = true;
754 void SAL_CALL PresenterSlideShowView::windowShown (const lang::EventObject& rEvent)
755 throw (RuntimeException)
757 (void)rEvent;
758 Resize();
764 void SAL_CALL PresenterSlideShowView::windowHidden (const lang::EventObject& rEvent)
765 throw (RuntimeException)
767 (void)rEvent;
773 //----- XView -----------------------------------------------------------------
775 Reference<XResourceId> SAL_CALL PresenterSlideShowView::getResourceId (void)
776 throw(RuntimeException)
778 return mxViewId;
784 sal_Bool SAL_CALL PresenterSlideShowView::isAnchorOnly (void)
785 throw (RuntimeException)
787 return false;
793 //----- CachablePresenterView -------------------------------------------------
795 void PresenterSlideShowView::ActivatePresenterView (void)
797 if (mxSlideShow.is() && ! mbIsViewAdded)
799 mxSlideShow->addView(this);
800 mbIsViewAdded = true;
807 void PresenterSlideShowView::DeactivatePresenterView (void)
809 if (mxSlideShow.is() && mbIsViewAdded)
811 mxSlideShow->removeView(this);
812 mbIsViewAdded = false;
819 //-----------------------------------------------------------------------------
821 void PresenterSlideShowView::PaintOuterWindow (const awt::Rectangle& rRepaintBox)
823 if ( ! mxCanvas.is())
824 return;
826 if (mpBackground.get() == NULL)
827 return;
829 const rendering::ViewState aViewState(
830 geometry::AffineMatrix2D(1,0,0, 0,1,0),
831 PresenterGeometryHelper::CreatePolygon(rRepaintBox, mxCanvas->getDevice()));
833 rendering::RenderState aRenderState (
834 geometry::AffineMatrix2D(1,0,0, 0,1,0),
835 NULL,
836 Sequence<double>(4),
837 rendering::CompositeOperation::SOURCE);
839 Reference<rendering::XBitmap> xBackgroundBitmap (mpBackground->GetNormalBitmap());
840 if (xBackgroundBitmap.is())
842 Sequence<rendering::Texture> aTextures (1);
843 const geometry::IntegerSize2D aBitmapSize(xBackgroundBitmap->getSize());
844 aTextures[0] = rendering::Texture (
845 geometry::AffineMatrix2D(
846 aBitmapSize.Width,0,0,
847 0,aBitmapSize.Height,0),
850 xBackgroundBitmap,
851 NULL,
852 NULL,
853 rendering::StrokeAttributes(),
854 rendering::TexturingMode::REPEAT,
855 rendering::TexturingMode::REPEAT);
857 if (mxBackgroundPolygon1.is())
858 mxCanvas->fillTexturedPolyPolygon(
859 mxBackgroundPolygon1,
860 aViewState,
861 aRenderState,
862 aTextures);
863 if (mxBackgroundPolygon2.is())
864 mxCanvas->fillTexturedPolyPolygon(
865 mxBackgroundPolygon2,
866 aViewState,
867 aRenderState,
868 aTextures);
870 else
872 PresenterCanvasHelper::SetDeviceColor(aRenderState, mpBackground->maReplacementColor);
874 if (mxBackgroundPolygon1.is())
875 mxCanvas->fillPolyPolygon(mxBackgroundPolygon1, aViewState, aRenderState);
876 if (mxBackgroundPolygon2.is())
877 mxCanvas->fillPolyPolygon(mxBackgroundPolygon2, aViewState, aRenderState);
884 void PresenterSlideShowView::PaintEndSlide (const awt::Rectangle& rRepaintBox)
886 if ( ! mxCanvas.is())
887 return;
889 const rendering::ViewState aViewState(
890 geometry::AffineMatrix2D(1,0,0, 0,1,0),
891 PresenterGeometryHelper::CreatePolygon(rRepaintBox, mxCanvas->getDevice()));
893 rendering::RenderState aRenderState (
894 geometry::AffineMatrix2D(1,0,0, 0,1,0),
895 NULL,
896 Sequence<double>(4),
897 rendering::CompositeOperation::SOURCE);
898 PresenterCanvasHelper::SetDeviceColor(aRenderState, util::Color(0x00000000));
899 mxCanvas->fillPolyPolygon(
900 PresenterGeometryHelper::CreatePolygon(mxViewWindow->getPosSize(), mxCanvas->getDevice()),
901 aViewState,
902 aRenderState);
906 if (mpPresenterController.get() == NULL)
907 break;
908 ::boost::shared_ptr<PresenterTheme> pTheme (mpPresenterController->GetTheme());
909 if (pTheme.get() == NULL)
910 break;
912 const OUString sViewStyle (pTheme->GetStyleName(mxViewId->getResourceURL()));
913 PresenterTheme::SharedFontDescriptor pFont (pTheme->GetFont(sViewStyle));
914 if (pFont.get() == NULL)
915 break;
917 PresenterCanvasHelper::SetDeviceColor(aRenderState, util::Color(0x00ffffff));
918 aRenderState.AffineTransform.m02 = 20;
919 aRenderState.AffineTransform.m12 = 40;
920 const rendering::StringContext aContext (
921 msClickToExitPresentationText, 0, msClickToExitPresentationText.getLength());
922 pFont->PrepareFont(mxCanvas);
923 mxCanvas->drawText(
924 aContext,
925 pFont->mxFont,
926 aViewState,
927 aRenderState,
928 rendering::TextDirection::WEAK_LEFT_TO_RIGHT);
930 while (false);
932 // Finally, in double buffered environments, request the changes to be
933 // made visible.
934 Reference<rendering::XSpriteCanvas> mxSpriteCanvas (mxCanvas, UNO_QUERY);
935 if (mxSpriteCanvas.is())
936 mxSpriteCanvas->updateScreen(sal_True);
942 void PresenterSlideShowView::PaintInnerWindow (const awt::PaintEvent& rEvent)
944 // Forward window paint to listeners.
945 awt::PaintEvent aEvent (rEvent);
946 aEvent.Source = static_cast<XWeak*>(this);
947 ::cppu::OInterfaceContainerHelper* pIterator
948 = maBroadcaster.getContainer(getCppuType((Reference<awt::XPaintListener>*)NULL));
949 if (pIterator != NULL)
951 pIterator->notifyEach(&awt::XPaintListener::windowPaint, aEvent);
954 if (mbIsForcedPaintPending)
955 ForceRepaint();
957 // Finally, in double buffered environments, request the changes to be
958 // made visible.
959 Reference<rendering::XSpriteCanvas> mxSpriteCanvas (mxCanvas, UNO_QUERY);
960 if (mxSpriteCanvas.is())
961 mxSpriteCanvas->updateScreen(sal_True);
967 Reference<awt::XWindow> PresenterSlideShowView::CreateViewWindow (
968 const Reference<awt::XWindow>& rxParentWindow) const
970 Reference<awt::XWindow> xViewWindow;
973 Reference<lang::XMultiComponentFactory> xFactory (mxComponentContext->getServiceManager());
974 if ( ! xFactory.is())
975 return xViewWindow;
977 Reference<awt::XToolkit> xToolkit (
978 xFactory->createInstanceWithContext(
979 OUString::createFromAscii("com.sun.star.awt.Toolkit"),
980 mxComponentContext),
981 UNO_QUERY_THROW);
982 awt::WindowDescriptor aWindowDescriptor (
983 awt::WindowClass_CONTAINER,
984 OUString(),
985 Reference<awt::XWindowPeer>(rxParentWindow,UNO_QUERY_THROW),
986 -1, // parent index not available
987 awt::Rectangle(0,0,10,10),
988 awt::WindowAttribute::SIZEABLE
989 | awt::WindowAttribute::MOVEABLE
990 | awt::WindowAttribute::NODECORATION);
991 xViewWindow = Reference<awt::XWindow>(
992 xToolkit->createWindow(aWindowDescriptor),UNO_QUERY_THROW);
994 // Make the background transparent. The slide show paints its own background.
995 Reference<awt::XWindowPeer> xPeer (xViewWindow, UNO_QUERY_THROW);
996 if (xPeer.is())
998 xPeer->setBackground(0xff000000);
1001 xViewWindow->setVisible(sal_True);
1003 catch (RuntimeException&)
1006 return xViewWindow;
1012 Reference<rendering::XCanvas> PresenterSlideShowView::CreateViewCanvas (
1013 const Reference<awt::XWindow>& rxViewWindow) const
1015 // Create a canvas for the view window.
1016 return mxPresenterHelper->createSharedCanvas(
1017 Reference<rendering::XSpriteCanvas>(mxTopPane->getCanvas(), UNO_QUERY),
1018 mxTopPane->getWindow(),
1019 mxTopPane->getCanvas(),
1020 mxTopPane->getWindow(),
1021 rxViewWindow);
1027 void PresenterSlideShowView::Resize (void)
1029 if ( ! mxWindow.is() || ! mxViewWindow.is())
1030 return;
1032 const awt::Rectangle aWindowBox (mxWindow->getPosSize());
1033 awt::Rectangle aViewWindowBox;
1034 if (aWindowBox.Height > 0)
1036 const double nWindowAspectRatio (
1037 double(aWindowBox.Width) / double(aWindowBox.Height));
1038 if (nWindowAspectRatio > mnPageAspectRatio)
1040 // Slides will be painted with the full parent window height.
1041 aViewWindowBox.Width = sal_Int32(aWindowBox.Height * mnPageAspectRatio + 0.5);
1042 aViewWindowBox.Height = aWindowBox.Height;
1043 aViewWindowBox.X = (aWindowBox.Width - aViewWindowBox.Width) / 2;
1044 aViewWindowBox.Y = 0;
1046 else
1048 // Slides will be painted with the full parent window width.
1049 aViewWindowBox.Width = aWindowBox.Width;
1050 aViewWindowBox.Height = sal_Int32(aWindowBox.Width / mnPageAspectRatio + 0.5);
1051 aViewWindowBox.X = 0;
1052 aViewWindowBox.Y = (aWindowBox.Height - aViewWindowBox.Height) / 2;
1054 mxViewWindow->setPosSize(
1055 aViewWindowBox.X,
1056 aViewWindowBox.Y,
1057 aViewWindowBox.Width,
1058 aViewWindowBox.Height,
1059 awt::PosSize::POSSIZE);
1062 // Clear the background polygon so that on the next paint it is created
1063 // for the new size.
1064 CreateBackgroundPolygons();
1067 // Due to constant aspect ratio resizing may lead a preview that changes
1068 // its position but not its size. This invalidates the back buffer and
1069 // we have to enforce a complete repaint.
1070 if ( ! mbIsPaintPending)
1071 mbIsForcedPaintPending = true;
1077 void PresenterSlideShowView::ForceRepaint (void)
1079 if (mxSlideShow.is() && mbIsViewAdded)
1081 mxSlideShow->removeView(this);
1082 mxSlideShow->addView(this);
1089 void PresenterSlideShowView::CreateBackgroundPolygons (void)
1091 const awt::Rectangle aWindowBox (mxWindow->getPosSize());
1092 const awt::Rectangle aViewWindowBox (mxViewWindow->getPosSize());
1093 if (aWindowBox.Height == aViewWindowBox.Height && aWindowBox.Width == aViewWindowBox.Width)
1095 mxBackgroundPolygon1 = NULL;
1096 mxBackgroundPolygon2 = NULL;
1098 else if (aWindowBox.Height == aViewWindowBox.Height)
1100 // Paint two boxes to the left and right of the view window.
1101 mxBackgroundPolygon1 = PresenterGeometryHelper::CreatePolygon(
1102 awt::Rectangle(
1105 aViewWindowBox.X,
1106 aWindowBox.Height),
1107 mxCanvas->getDevice());
1108 mxBackgroundPolygon2 = PresenterGeometryHelper::CreatePolygon(
1109 awt::Rectangle(
1110 aViewWindowBox.X + aViewWindowBox.Width,
1112 aWindowBox.Width - aViewWindowBox.X - aViewWindowBox.Width,
1113 aWindowBox.Height),
1114 mxCanvas->getDevice());
1116 else
1118 // Paint two boxes above and below the view window.
1119 mxBackgroundPolygon1 = PresenterGeometryHelper::CreatePolygon(
1120 awt::Rectangle(
1123 aWindowBox.Width,
1124 aViewWindowBox.Y),
1125 mxCanvas->getDevice());
1126 mxBackgroundPolygon2 = PresenterGeometryHelper::CreatePolygon(
1127 awt::Rectangle(
1129 aViewWindowBox.Y + aViewWindowBox.Height,
1130 aWindowBox.Width,
1131 aWindowBox.Height - aViewWindowBox.Y - aViewWindowBox.Height),
1132 mxCanvas->getDevice());
1139 void PresenterSlideShowView::ThrowIfDisposed (void)
1140 throw (::com::sun::star::lang::DisposedException)
1142 if (rBHelper.bDisposed || rBHelper.bInDispose)
1144 throw lang::DisposedException (
1145 OUString::createFromAscii("PresenterSlideShowView object has already been disposed"),
1146 static_cast<uno::XWeak*>(this));
1151 } } // end of namespace ::sd::presenter