update dev300-m58
[ooovba.git] / sdext / source / presenter / PresenterController.cxx
blobda3a35efc4a10fbd6053334e6e8598f9beb6350d
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: PresenterController.cxx,v $
11 * $Revision: 1.5 $
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 "PresenterController.hxx"
37 #include "PresenterAnimator.hxx"
38 #include "PresenterCanvasHelper.hxx"
39 #include "PresenterCurrentSlideObserver.hxx"
40 #include "PresenterFrameworkObserver.hxx"
41 #include "PresenterHelper.hxx"
42 #include "PresenterPaintManager.hxx"
43 #include "PresenterPaneAnimator.hxx"
44 #include "PresenterPaneBase.hxx"
45 #include "PresenterPaneContainer.hxx"
46 #include "PresenterPaneBorderPainter.hxx"
47 #include "PresenterPaneFactory.hxx"
48 #include "PresenterTheme.hxx"
49 #include "PresenterViewFactory.hxx"
50 #include "PresenterWindowManager.hxx"
52 #include <com/sun/star/awt/Key.hpp>
53 #include <com/sun/star/awt/KeyModifier.hpp>
54 #include <com/sun/star/awt/MouseButton.hpp>
55 #include <com/sun/star/awt/XWindowPeer.hpp>
56 #include <com/sun/star/drawing/XDrawView.hpp>
57 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
58 #include <com/sun/star/drawing/framework/ResourceId.hpp>
59 #include <com/sun/star/drawing/framework/ResourceActivationMode.hpp>
60 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
61 #include <com/sun/star/frame/FrameSearchFlag.hpp>
62 #include <com/sun/star/frame/XDispatchProvider.hpp>
63 #include <com/sun/star/presentation/XPresentation.hpp>
64 #include <com/sun/star/presentation/XPresentationSupplier.hpp>
65 #include <com/sun/star/rendering/CompositeOperation.hpp>
66 #include <com/sun/star/rendering/TextDirection.hpp>
68 #include <rtl/ustrbuf.hxx>
69 #include <boost/bind.hpp>
71 using namespace ::com::sun::star;
72 using namespace ::com::sun::star::uno;
73 using namespace ::com::sun::star::presentation;
74 using namespace ::com::sun::star::drawing::framework;
75 using ::rtl::OUString;
76 using ::rtl::OUStringBuffer;
78 namespace {
79 const sal_Int32 ResourceActivationEventType = 0;
80 const sal_Int32 ResourceDeactivationEventType = 1;
84 #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString)))
87 namespace sdext { namespace presenter {
89 PresenterController::InstanceContainer PresenterController::maInstances;
91 ::rtl::Reference<PresenterController> PresenterController::Instance (
92 const css::uno::Reference<css::frame::XFrame>& rxFrame)
94 InstanceContainer::const_iterator iInstance (maInstances.find(rxFrame));
95 if (iInstance != maInstances.end())
96 return iInstance->second;
97 else
98 return ::rtl::Reference<PresenterController>();
104 PresenterController::PresenterController (
105 const Reference<XComponentContext>& rxContext,
106 const Reference<frame::XController>& rxController,
107 const Reference<presentation::XSlideShowController>& rxSlideShowController,
108 const rtl::Reference<PresenterPaneContainer>& rpPaneContainer,
109 const Reference<XResourceId>& rxMainPaneId)
110 : PresenterControllerInterfaceBase(m_aMutex),
111 mxComponentContext(rxContext),
112 mxController(rxController),
113 mxConfigurationController(),
114 mxSlideShowController(rxSlideShowController),
115 mxMainPaneId(rxMainPaneId),
116 mpPaneContainer(rpPaneContainer),
117 mnCurrentSlideIndex(-1),
118 mxCurrentSlide(),
119 mxNextSlide(),
120 mpWindowManager(new PresenterWindowManager(rxContext,mpPaneContainer,this)),
121 mpCurrentPaneAnimation(),
122 mnWindowBackgroundColor(0x00ffffff),
123 mpTheme(),
124 mxMainWindow(),
125 mpPaneBorderPainter(),
126 mpAnimator(new PresenterAnimator()),
127 mpCanvasHelper(new PresenterCanvasHelper()),
128 mxPresenterHelper(),
129 mpPaintManager(),
130 mnPendingSlideNumber(-1),
131 mxUrlTransformer()
133 OSL_ASSERT(mxController.is());
135 if ( ! mxSlideShowController.is())
136 throw new lang::IllegalArgumentException(
137 A2S("missing slide show controller"),
138 static_cast<XWeak*>(this),
141 new PresenterCurrentSlideObserver(this,rxSlideShowController);
143 // Listen for configuration changes.
144 Reference<XControllerManager> xCM (mxController, UNO_QUERY_THROW);
145 mxConfigurationController = xCM->getConfigurationController();
146 if (mxConfigurationController.is())
148 mxConfigurationController->addConfigurationChangeListener(
149 this,
150 A2S("ResourceActivation"),
151 Any(ResourceActivationEventType));
152 mxConfigurationController->addConfigurationChangeListener(
153 this,
154 A2S("ResourceDeactivation"),
155 Any(ResourceDeactivationEventType));
158 // Listen for the frame being activated.
159 Reference<frame::XFrame> xFrame (mxController->getFrame());
160 if (xFrame.is())
161 xFrame->addFrameActionListener(this);
163 // Create the border painter.
164 mpPaneBorderPainter = new PresenterPaneBorderPainter(rxContext);
165 mpWindowManager->SetPaneBorderPainter(mpPaneBorderPainter);
167 // Create an object that is able to load the bitmaps in a format that is
168 // supported by the canvas.
169 Reference<lang::XMultiComponentFactory> xFactory (
170 rxContext->getServiceManager(), UNO_QUERY);
171 if ( ! xFactory.is())
172 return;
173 mxPresenterHelper = Reference<drawing::XPresenterHelper>(
174 xFactory->createInstanceWithContext(
175 A2S("com.sun.star.drawing.PresenterHelper"),
176 rxContext),
177 UNO_QUERY_THROW);
179 if (mxSlideShowController.is())
181 mxSlideShowController->activate();
182 Reference<beans::XPropertySet> xProperties (mxSlideShowController, UNO_QUERY);
183 if (xProperties.is())
185 Reference<awt::XWindow> xWindow (
186 xProperties->getPropertyValue(A2S("ParentWindow")), UNO_QUERY);
187 if (xWindow.is())
188 xWindow->addKeyListener(this);
192 UpdateCurrentSlide(0);
194 maInstances[mxController->getFrame()] = this;
196 // Create a URLTransformer.
197 if (xFactory.is())
199 mxUrlTransformer = Reference<util::XURLTransformer>(
200 xFactory->createInstanceWithContext(
201 A2S("com.sun.star.util.URLTransformer"),
202 mxComponentContext),
203 UNO_QUERY);
210 PresenterController::~PresenterController (void)
217 void PresenterController::disposing (void)
219 maInstances.erase(mxController->getFrame());
221 if (mxMainWindow.is())
223 mxMainWindow->removeKeyListener(this);
224 mxMainWindow->removeFocusListener(this);
225 mxMainWindow->removeMouseListener(this);
226 mxMainWindow->removeMouseMotionListener(this);
227 mxMainWindow = NULL;
229 if (mxConfigurationController.is())
230 mxConfigurationController->removeConfigurationChangeListener(this);
232 Reference<XComponent> xWindowManagerComponent (
233 static_cast<XWeak*>(mpWindowManager.get()), UNO_QUERY);
234 mpWindowManager = NULL;
235 if (xWindowManagerComponent.is())
236 xWindowManagerComponent->dispose();
238 if (mxController.is())
240 Reference<frame::XFrame> xFrame (mxController->getFrame());
241 if (xFrame.is())
242 xFrame->removeFrameActionListener(this);
243 mxController = NULL;
246 mxComponentContext = NULL;
247 mxConfigurationController = NULL;
248 mxSlideShowController = NULL;
249 mxMainPaneId = NULL;
250 mpPaneContainer = NULL;
251 mnCurrentSlideIndex = -1;
252 mxCurrentSlide = NULL;
253 mxNextSlide = NULL;
254 mpCurrentPaneAnimation.reset();
255 mpTheme.reset();
257 Reference<lang::XComponent> xComponent (
258 static_cast<XWeak*>(mpPaneBorderPainter.get()), UNO_QUERY);
259 mpPaneBorderPainter = NULL;
260 if (xComponent.is())
261 xComponent->dispose();
263 mpAnimator.reset();
264 mpCanvasHelper.reset();
266 Reference<lang::XComponent> xComponent (mxPresenterHelper, UNO_QUERY);
267 mxPresenterHelper = NULL;
268 if (xComponent.is())
269 xComponent->dispose();
271 mpPaintManager.reset();
272 mnPendingSlideNumber = -1;
274 Reference<lang::XComponent> xComponent (mxUrlTransformer, UNO_QUERY);
275 mxUrlTransformer = NULL;
276 if (xComponent.is())
277 xComponent->dispose();
284 void PresenterController::UpdateCurrentSlide (const sal_Int32 nOffset)
286 GetSlides(nOffset);
287 UpdatePaneTitles();
288 UpdateViews();
294 void PresenterController::GetSlides (const sal_Int32 nOffset)
296 if ( ! mxSlideShowController.is())
297 return;
299 // Get the current slide from the slide show controller.
300 mxCurrentSlide = NULL;
301 Reference<container::XIndexAccess> xIndexAccess(mxSlideShowController, UNO_QUERY);
302 sal_Int32 nSlideIndex = -1;
305 nSlideIndex = mxSlideShowController->getCurrentSlideIndex() + nOffset;
306 if (mxSlideShowController->isPaused())
307 nSlideIndex = -1;
309 if (xIndexAccess.is() && nSlideIndex>=0)
311 if (nSlideIndex < xIndexAccess->getCount())
313 mnCurrentSlideIndex = nSlideIndex;
314 mxCurrentSlide = Reference<drawing::XDrawPage>(
315 xIndexAccess->getByIndex(nSlideIndex), UNO_QUERY);
319 catch (RuntimeException&)
323 // Get the next slide.
324 mxNextSlide = NULL;
327 const sal_Int32 nNextSlideIndex (mxSlideShowController->getNextSlideIndex()+nOffset);
328 if (nNextSlideIndex >= 0)
330 if (xIndexAccess.is())
332 if (nNextSlideIndex < xIndexAccess->getCount())
333 mxNextSlide = Reference<drawing::XDrawPage>(
334 xIndexAccess->getByIndex(nNextSlideIndex), UNO_QUERY);
338 catch (RuntimeException&)
346 void PresenterController::UpdatePaneTitles (void)
348 if ( ! mxSlideShowController.is())
349 return;
351 // Get placeholders and their values.
352 const OUString sCurrentSlidePlaceholder (A2S("CURRENT_SLIDE_NUMBER"));
353 const OUString sSlideCountPlaceholder (A2S("SLIDE_COUNT"));
355 // Get string for slide count.
356 OUString sSlideCount (A2S("---"));
357 Reference<container::XIndexAccess> xIndexAccess(mxSlideShowController, UNO_QUERY);
358 if (xIndexAccess.is())
359 sSlideCount = OUString::valueOf(xIndexAccess->getCount());
361 // Get string for current slide index.
362 OUString sCurrentSlide (OUString::valueOf(mnCurrentSlideIndex + 1));
364 // Replace the placeholders with their current values.
365 PresenterPaneContainer::PaneList::const_iterator iPane;
366 for (iPane=mpPaneContainer->maPanes.begin(); iPane!=mpPaneContainer->maPanes.end(); ++iPane)
368 OSL_ASSERT((*iPane).get() != NULL);
370 OUString sTemplate ((*iPane)->msTitleTemplate);
371 if (sTemplate.getLength() <= 0)
372 continue;
374 OUStringBuffer sResult;
375 sResult.ensureCapacity(sTemplate.getLength());
377 sal_Int32 nIndex (0);
378 while (true)
380 sal_Int32 nStartIndex = sTemplate.indexOf('%', nIndex);
381 if (nStartIndex < 0)
383 // Add the remaining part of the string.
384 sResult.append(sTemplate.copy(nIndex, sTemplate.getLength()-nIndex));
385 break;
387 else
389 // Add the part preceding the next %.
390 sResult.append(sTemplate.copy(nIndex, nStartIndex-nIndex));
392 // Get the placeholder
393 ++nIndex;
394 ++nStartIndex;
395 const sal_Int32 nEndIndex (sTemplate.indexOf('%', nStartIndex+1));
396 const OUString sPlaceholder (sTemplate.copy(nStartIndex, nEndIndex-nStartIndex));
397 nIndex = nEndIndex+1;
399 // Replace the placeholder with its current value.
400 if (sPlaceholder == sCurrentSlidePlaceholder)
401 sResult.append(sCurrentSlide);
402 else if (sPlaceholder == sSlideCountPlaceholder)
403 sResult.append(sSlideCount);
407 (*iPane)->msTitle = sResult.makeStringAndClear();
408 if ((*iPane)->mxPane.is())
409 (*iPane)->mxPane->SetTitle((*iPane)->msTitle);
416 void PresenterController::UpdateViews (void)
418 // Tell all views about the slides they should display.
419 PresenterPaneContainer::PaneList::const_iterator iPane;
420 for (iPane=mpPaneContainer->maPanes.begin(); iPane!=mpPaneContainer->maPanes.end(); ++iPane)
422 Reference<drawing::XDrawView> xDrawView ((*iPane)->mxView, UNO_QUERY);
423 if (xDrawView.is())
424 xDrawView->setCurrentPage(mxCurrentSlide);
431 SharedBitmapDescriptor
432 PresenterController::GetViewBackground (const ::rtl::OUString& rsViewURL) const
434 if (mpTheme.get() != NULL)
436 const OUString sStyleName (mpTheme->GetStyleName(rsViewURL));
437 return mpTheme->GetBitmap(sStyleName, A2S("Background"));
439 return SharedBitmapDescriptor();
445 PresenterTheme::SharedFontDescriptor
446 PresenterController::GetViewFont (const ::rtl::OUString& rsViewURL) const
448 if (mpTheme.get() != NULL)
450 const OUString sStyleName (mpTheme->GetStyleName(rsViewURL));
451 return mpTheme->GetFont(sStyleName);
453 return PresenterTheme::SharedFontDescriptor();
459 ::boost::shared_ptr<PresenterTheme> PresenterController::GetTheme (void) const
461 return mpTheme;
467 ::rtl::Reference<PresenterWindowManager> PresenterController::GetWindowManager (void) const
469 return mpWindowManager;
475 Reference<presentation::XSlideShowController>
476 PresenterController::GetSlideShowController(void) const
478 return mxSlideShowController;
484 rtl::Reference<PresenterPaneContainer> PresenterController::GetPaneContainer (void) const
486 return mpPaneContainer;
492 ::rtl::Reference<PresenterPaneBorderPainter> PresenterController::GetPaneBorderPainter (void) const
494 return mpPaneBorderPainter;
500 ::boost::shared_ptr<PresenterAnimator> PresenterController::GetAnimator (void) const
502 return mpAnimator;
508 ::boost::shared_ptr<PresenterCanvasHelper> PresenterController::GetCanvasHelper (void) const
510 return mpCanvasHelper;
516 Reference<drawing::XPresenterHelper> PresenterController::GetPresenterHelper (void) const
518 return mxPresenterHelper;
524 ::boost::shared_ptr<PresenterPaintManager> PresenterController::GetPaintManager (void) const
526 return mpPaintManager;
532 void PresenterController::HideSlideSorter (void)
534 if (mpCurrentPaneAnimation.get() != NULL)
536 mpCurrentPaneAnimation->HidePane();
537 mpCurrentPaneAnimation.reset();
544 void PresenterController::ShowView (const OUString& rsViewURL)
546 PresenterPaneContainer::SharedPaneDescriptor pDescriptor (
547 mpPaneContainer->FindViewURL(rsViewURL));
548 if (pDescriptor.get() != NULL)
550 pDescriptor->mbIsActive = true;
551 mxConfigurationController->requestResourceActivation(
552 pDescriptor->mxPaneId,
553 ResourceActivationMode_ADD);
554 mxConfigurationController->requestResourceActivation(
555 ResourceId::createWithAnchor(
556 mxComponentContext,
557 rsViewURL,
558 pDescriptor->mxPaneId),
559 ResourceActivationMode_REPLACE);
566 void PresenterController::HideView (const OUString& rsViewURL)
568 PresenterPaneContainer::SharedPaneDescriptor pDescriptor (
569 mpPaneContainer->FindViewURL(rsViewURL));
570 if (pDescriptor.get() != NULL)
572 mxConfigurationController->requestResourceDeactivation(
573 ResourceId::createWithAnchor(
574 mxComponentContext,
575 rsViewURL,
576 pDescriptor->mxPaneId));
583 bool PresenterController::IsViewVisible (const OUString& rsViewURL) const
585 PresenterPaneContainer::SharedPaneDescriptor pDescriptor (
586 mpPaneContainer->FindViewURL(rsViewURL));
587 if (pDescriptor.get() != NULL)
589 return mxConfigurationController->getResource(
590 ResourceId::createWithAnchor(
591 mxComponentContext,
592 rsViewURL,
593 pDescriptor->mxPaneId)).is();
595 return false;
601 void PresenterController::DispatchUnoCommand (const OUString& rsCommand) const
603 if ( ! mxUrlTransformer.is())
604 return;
606 util::URL aURL;
607 aURL.Complete = rsCommand;
608 mxUrlTransformer->parseStrict(aURL);
610 Reference<frame::XDispatch> xDispatch (GetDispatch(aURL));
611 if ( ! xDispatch.is())
612 return;
614 xDispatch->dispatch(aURL, Sequence<beans::PropertyValue>());
620 Reference<css::frame::XDispatch> PresenterController::GetDispatch (const util::URL& rURL) const
622 if ( ! mxController.is())
623 return NULL;
625 Reference<frame::XDispatchProvider> xDispatchProvider (mxController->getFrame(), UNO_QUERY);
626 if ( ! xDispatchProvider.is())
627 return NULL;
629 return xDispatchProvider->queryDispatch(
630 rURL,
631 OUString(),
632 frame::FrameSearchFlag::SELF);
638 util::URL PresenterController::CreateURLFromString (const ::rtl::OUString& rsURL) const
640 util::URL aURL;
642 if (mxUrlTransformer.is())
644 aURL.Complete = rsURL;
645 mxUrlTransformer->parseStrict(aURL);
648 return aURL;
654 Reference<drawing::framework::XConfigurationController>
655 PresenterController::GetConfigurationController (void) const
657 return mxConfigurationController;
663 css::uno::Reference<css::drawing::XDrawPage> PresenterController::GetCurrentSlide (void) const
665 return mxCurrentSlide;
671 void PresenterController::HandleMouseClick (const awt::MouseEvent& rEvent)
673 if (mxSlideShowController.is())
675 switch (rEvent.Buttons)
677 case awt::MouseButton::LEFT:
678 if (rEvent.Modifiers == awt::KeyModifier::MOD2)
679 mxSlideShowController->gotoNextSlide();
680 else
681 mxSlideShowController->gotoNextEffect();
682 break;
684 case awt::MouseButton::RIGHT:
685 mxSlideShowController->gotoPreviousSlide();
686 break;
688 default:
689 // Other or multiple buttons.
690 break;
698 void PresenterController::RequestViews (
699 const bool bIsSlideSorterActive,
700 const bool bIsNotesViewActive,
701 const bool bIsHelpViewActive)
703 PresenterPaneContainer::PaneList::const_iterator iPane;
704 PresenterPaneContainer::PaneList::const_iterator iEnd (mpPaneContainer->maPanes.end());
705 for (iPane=mpPaneContainer->maPanes.begin(); iPane!=iEnd; ++iPane)
707 bool bActivate (true);
708 const OUString sViewURL ((*iPane)->msViewURL);
709 if (sViewURL == PresenterViewFactory::msNotesViewURL)
711 bActivate = bIsNotesViewActive && !bIsSlideSorterActive && !bIsHelpViewActive;
713 else if (sViewURL == PresenterViewFactory::msSlideSorterURL)
715 bActivate = bIsSlideSorterActive;
717 else if (sViewURL == PresenterViewFactory::msCurrentSlidePreviewViewURL
718 || sViewURL == PresenterViewFactory::msNextSlidePreviewViewURL)
720 bActivate = !bIsSlideSorterActive && ! bIsHelpViewActive;
722 else if (sViewURL == PresenterViewFactory::msToolBarViewURL)
724 bActivate = true;
726 else if (sViewURL == PresenterViewFactory::msHelpViewURL)
728 bActivate = bIsHelpViewActive;
731 if (bActivate)
732 ShowView(sViewURL);
733 else
734 HideView(sViewURL);
741 //----- XConfigurationChangeListener ------------------------------------------
743 void SAL_CALL PresenterController::notifyConfigurationChange (
744 const ConfigurationChangeEvent& rEvent)
745 throw (RuntimeException)
747 ThrowIfDisposed();
749 sal_Int32 nType (0);
750 if ( ! (rEvent.UserData >>= nType))
751 return;
753 switch (nType)
755 case ResourceActivationEventType:
756 if (rEvent.ResourceId->compareTo(mxMainPaneId) == 0)
758 InitializeMainPane(Reference<XPane>(rEvent.ResourceObject,UNO_QUERY));
760 else if (rEvent.ResourceId->isBoundTo(mxMainPaneId,AnchorBindingMode_DIRECT))
762 // A pane bound to the main pane has been created and is
763 // stored in the pane container.
764 Reference<XPane> xPane (rEvent.ResourceObject,UNO_QUERY);
765 if (xPane.is())
767 PresenterPaneContainer::SharedPaneDescriptor pDescriptor (
768 mpPaneContainer->FindPaneId(xPane->getResourceId()));
769 mpWindowManager->NotifyPaneCreation(pDescriptor);
771 // When there is a call out anchor location set then tell the
772 // window about it.
773 if (pDescriptor->mbHasCalloutAnchor)
774 pDescriptor->mxPane->SetCalloutAnchor(
775 pDescriptor->maCalloutAnchorLocation);
778 else if (rEvent.ResourceId->isBoundTo(mxMainPaneId,AnchorBindingMode_INDIRECT))
780 // A view bound to one of the panes has been created and is
781 // stored in the pane container along with its pane.
782 Reference<XView> xView (rEvent.ResourceObject,UNO_QUERY);
783 if (xView.is())
785 SharedBitmapDescriptor pViewBackground(
786 GetViewBackground(xView->getResourceId()->getResourceURL()));
787 mpPaneContainer->StoreView(xView, pViewBackground);
788 UpdateViews();
789 mpWindowManager->NotifyViewCreation(xView);
792 break;
794 case ResourceDeactivationEventType:
795 if (rEvent.ResourceId->isBoundTo(mxMainPaneId,AnchorBindingMode_INDIRECT))
797 // If this is a view then remove it from the pane container.
798 Reference<XView> xView (rEvent.ResourceObject,UNO_QUERY);
799 if (xView.is())
801 PresenterPaneContainer::SharedPaneDescriptor pDescriptor(
802 mpPaneContainer->RemoveView(xView));
804 // A possibly opaque view has been removed. Update()
805 // updates the clip polygon.
806 mpWindowManager->Update();
807 // Request the repainting of the area previously
808 // occupied by the view.
809 if (pDescriptor.get() != NULL)
810 GetPaintManager()->Invalidate(pDescriptor->mxBorderWindow);
813 break;
820 //----- XEventListener --------------------------------------------------------
822 void SAL_CALL PresenterController::disposing (
823 const lang::EventObject& rEvent)
824 throw (RuntimeException)
826 if (rEvent.Source == mxController)
827 mxController = NULL;
828 else if (rEvent.Source == mxConfigurationController)
829 mxConfigurationController = NULL;
830 else if (rEvent.Source == mxSlideShowController)
831 mxSlideShowController = NULL;
832 else if (rEvent.Source == mxMainWindow)
833 mxMainWindow = NULL;
839 //----- XFrameActionListener --------------------------------------------------
841 void SAL_CALL PresenterController::frameAction (
842 const frame::FrameActionEvent& rEvent)
843 throw (RuntimeException)
845 if (rEvent.Action == frame::FrameAction_FRAME_ACTIVATED)
847 if (mxSlideShowController.is())
848 mxSlideShowController->activate();
855 //----- XKeyListener ----------------------------------------------------------
857 void SAL_CALL PresenterController::keyPressed (const awt::KeyEvent& rEvent)
858 throw (RuntimeException)
860 // Tell all views about the unhandled key event.
861 PresenterPaneContainer::PaneList::const_iterator iPane;
862 for (iPane=mpPaneContainer->maPanes.begin(); iPane!=mpPaneContainer->maPanes.end(); ++iPane)
864 if ( ! (*iPane)->mbIsActive)
865 continue;
867 Reference<awt::XKeyListener> xKeyListener ((*iPane)->mxView, UNO_QUERY);
868 if (xKeyListener.is())
869 xKeyListener->keyPressed(rEvent);
876 void SAL_CALL PresenterController::keyReleased (const awt::KeyEvent& rEvent)
877 throw (RuntimeException)
879 if (rEvent.Source != mxMainWindow)
880 return;
882 switch (rEvent.KeyCode)
884 case awt::Key::ESCAPE:
885 case awt::Key::SUBTRACT:
887 if( mxController.is() )
889 Reference< XPresentationSupplier > xPS( mxController->getModel(), UNO_QUERY );
890 if( xPS.is() )
892 Reference< XPresentation > xP( xPS->getPresentation() );
893 if( xP.is() )
894 xP->end();
898 break;
900 case awt::Key::PAGEDOWN:
901 if (mxSlideShowController.is())
903 if (rEvent.Modifiers == awt::KeyModifier::MOD2)
904 mxSlideShowController->gotoNextSlide();
905 else
906 mxSlideShowController->gotoNextEffect();
908 break;
910 case awt::Key::SPACE:
911 case awt::Key::RIGHT:
912 case awt::Key::DOWN:
913 case awt::Key::N:
914 if (mxSlideShowController.is())
916 mxSlideShowController->gotoNextEffect();
918 break;
920 case awt::Key::PAGEUP:
921 if (mxSlideShowController.is())
923 if (rEvent.Modifiers == awt::KeyModifier::MOD2)
924 mxSlideShowController->gotoPreviousSlide();
925 else
926 mxSlideShowController->gotoPreviousEffect();
928 break;
930 case awt::Key::LEFT:
931 case awt::Key::UP:
932 case awt::Key::P:
933 case awt::Key::BACKSPACE:
934 if (mxSlideShowController.is())
936 mxSlideShowController->gotoPreviousEffect();
938 break;
940 case awt::Key::HOME:
941 if (mxSlideShowController.is())
943 mxSlideShowController->gotoFirstSlide();
945 break;
947 case awt::Key::END:
948 if (mxSlideShowController.is())
950 mxSlideShowController->gotoLastSlide();
952 break;
954 case awt::Key::W:
955 case awt::Key::COMMA:
956 if (mxSlideShowController.is())
958 if (mxSlideShowController->isPaused())
959 mxSlideShowController->resume();
960 else
961 mxSlideShowController->blankScreen(0x00ffffff);
963 break;
965 case awt::Key::B:
966 case awt::Key::POINT:
967 if (mxSlideShowController.is())
969 if (mxSlideShowController->isPaused())
970 mxSlideShowController->resume();
971 else
972 mxSlideShowController->blankScreen(0x00000000);
974 break;
976 case awt::Key::NUM0:
977 case awt::Key::NUM1:
978 case awt::Key::NUM2:
979 case awt::Key::NUM3:
980 case awt::Key::NUM4:
981 case awt::Key::NUM5:
982 case awt::Key::NUM6:
983 case awt::Key::NUM7:
984 case awt::Key::NUM8:
985 case awt::Key::NUM9:
986 HandleNumericKeyPress(rEvent.KeyCode-awt::Key::NUM0, rEvent.Modifiers);
987 break;
989 case awt::Key::RETURN:
990 if (mnPendingSlideNumber > 0)
992 if (mxSlideShowController.is())
993 mxSlideShowController->gotoSlideIndex(mnPendingSlideNumber - 1);
994 mnPendingSlideNumber = -1;
996 else
998 if (mxSlideShowController.is())
999 mxSlideShowController->gotoNextEffect();
1002 break;
1004 case awt::Key::F1:
1005 // Toggle the help view.
1006 if (mpWindowManager.get() != NULL)
1007 mpWindowManager->SetHelpViewState( ! mpWindowManager->IsHelpViewActive());
1008 break;
1010 default:
1011 // Tell all views about the unhandled key event.
1012 PresenterPaneContainer::PaneList::const_iterator iPane;
1013 for (iPane=mpPaneContainer->maPanes.begin(); iPane!=mpPaneContainer->maPanes.end(); ++iPane)
1015 if ( ! (*iPane)->mbIsActive)
1016 continue;
1018 Reference<awt::XKeyListener> xKeyListener ((*iPane)->mxView, UNO_QUERY);
1019 if (xKeyListener.is())
1020 xKeyListener->keyReleased(rEvent);
1022 break;
1029 void PresenterController::HandleNumericKeyPress (
1030 const sal_Int32 nKey,
1031 const sal_Int32 nModifiers)
1033 switch (nModifiers)
1035 case 0:
1036 if (mnPendingSlideNumber == -1)
1037 mnPendingSlideNumber = 0;
1038 UpdatePendingSlideNumber(mnPendingSlideNumber * 10 + nKey);
1039 break;
1041 case awt::KeyModifier::MOD1:
1042 // Ctrl-1, Ctrl-2, and Ctrl-3 are used to switch between views
1043 // (slide view, notes view, normal)
1044 mnPendingSlideNumber = -1;
1045 if (mpWindowManager.get() == NULL)
1046 return;
1047 switch(nKey)
1049 case 1:
1050 mpWindowManager->SetSlideSorterState(false);
1051 mpWindowManager->SetHelpViewState(false);
1052 mpWindowManager->SetLayoutMode(PresenterWindowManager::Standard);
1053 break;
1054 case 2:
1055 mpWindowManager->SetSlideSorterState(false);
1056 mpWindowManager->SetHelpViewState(false);
1057 mpWindowManager->SetLayoutMode(PresenterWindowManager::Notes);
1058 break;
1059 case 3:
1060 mpWindowManager->SetHelpViewState(false);
1061 mpWindowManager->SetSlideSorterState(true);
1062 break;
1063 default:
1064 // Ignore unsupported key.
1065 break;
1068 default:
1069 // Ignore unsupported modifiers.
1070 break;
1077 //----- XFocusListener --------------------------------------------------------
1079 void SAL_CALL PresenterController::focusGained (const css::awt::FocusEvent& rEvent)
1080 throw (css::uno::RuntimeException)
1082 (void)rEvent;
1088 void SAL_CALL PresenterController::focusLost (const css::awt::FocusEvent& rEvent)
1089 throw (css::uno::RuntimeException)
1091 (void)rEvent;
1097 //----- XMouseListener --------------------------------------------------------
1099 void SAL_CALL PresenterController::mousePressed (const css::awt::MouseEvent& rEvent)
1100 throw (css::uno::RuntimeException)
1102 (void)rEvent;
1103 if (mxMainWindow.is())
1104 mxMainWindow->setFocus();
1110 void SAL_CALL PresenterController::mouseReleased (const css::awt::MouseEvent& rEvent)
1111 throw (css::uno::RuntimeException)
1113 (void)rEvent;
1119 void SAL_CALL PresenterController::mouseEntered (const css::awt::MouseEvent& rEvent)
1120 throw (css::uno::RuntimeException)
1122 (void)rEvent;
1128 void SAL_CALL PresenterController::mouseExited (const css::awt::MouseEvent& rEvent)
1129 throw (css::uno::RuntimeException)
1131 (void)rEvent;
1137 //----- XMouseMotionListener --------------------------------------------------
1139 void SAL_CALL PresenterController::mouseMoved (const css::awt::MouseEvent& rEvent)
1140 throw (css::uno::RuntimeException)
1142 (void)rEvent;
1148 void SAL_CALL PresenterController::mouseDragged (const css::awt::MouseEvent& rEvent)
1149 throw (css::uno::RuntimeException)
1151 (void)rEvent;
1157 //-----------------------------------------------------------------------------
1159 void PresenterController::InitializeMainPane (const Reference<XPane>& rxPane)
1161 if ( ! rxPane.is())
1162 return;
1164 LoadTheme(rxPane);
1166 // Main pane has been created and is now observed by the window
1167 // manager.
1168 mpWindowManager->SetParentPane(rxPane);
1169 mpWindowManager->SetTheme(mpTheme);
1171 if (mpPaneBorderPainter.get() != NULL)
1172 mpPaneBorderPainter->SetTheme(mpTheme);
1174 // Add key listener
1175 mxMainWindow = rxPane->getWindow();
1176 if (mxMainWindow.is())
1178 mxMainWindow->addKeyListener(this);
1179 mxMainWindow->addFocusListener(this);
1180 mxMainWindow->addMouseListener(this);
1181 mxMainWindow->addMouseMotionListener(this);
1184 mpPaintManager.reset(new PresenterPaintManager(mxMainWindow, mxPresenterHelper, mpPaneContainer));
1186 mxCanvas = Reference<rendering::XSpriteCanvas>(rxPane->getCanvas(), UNO_QUERY);
1188 if (mxSlideShowController.is())
1189 mxSlideShowController->activate();
1195 void PresenterController::LoadTheme (const Reference<XPane>& rxPane)
1197 // Create (load) the current theme.
1198 if (rxPane.is())
1199 mpTheme.reset(new PresenterTheme(mxComponentContext, OUString(), rxPane->getCanvas()));
1205 double PresenterController::GetSlideAspectRatio (void) const
1207 double nSlideAspectRatio (28.0/21.0);
1211 if (mxController.is())
1213 Reference<drawing::XDrawPagesSupplier> xSlideSupplier (
1214 mxController->getModel(), UNO_QUERY_THROW);
1215 Reference<drawing::XDrawPages> xSlides (xSlideSupplier->getDrawPages());
1216 if (xSlides.is() && xSlides->getCount()>0)
1218 Reference<beans::XPropertySet> xProperties(xSlides->getByIndex(0),UNO_QUERY_THROW);
1219 sal_Int32 nWidth (28000);
1220 sal_Int32 nHeight (21000);
1221 if ((xProperties->getPropertyValue(OUString::createFromAscii("Width")) >>= nWidth)
1222 && (xProperties->getPropertyValue(OUString::createFromAscii("Height")) >>= nHeight)
1223 && nHeight > 0)
1225 nSlideAspectRatio = double(nWidth) / double(nHeight);
1230 catch (RuntimeException&)
1232 OSL_ASSERT(false);
1235 return nSlideAspectRatio;
1241 void PresenterController::UpdatePendingSlideNumber (const sal_Int32 nPendingSlideNumber)
1243 mnPendingSlideNumber = nPendingSlideNumber;
1245 if (mpTheme.get() == NULL)
1246 return;
1248 if ( ! mxMainWindow.is())
1249 return;
1251 PresenterTheme::SharedFontDescriptor pFont (
1252 mpTheme->GetFont(A2S("PendingSlideNumberFont")));
1253 if (pFont.get() == NULL)
1254 return;
1256 pFont->PrepareFont(Reference<rendering::XCanvas>(mxCanvas, UNO_QUERY));
1257 if ( ! pFont->mxFont.is())
1258 return;
1260 const OUString sText (OUString::valueOf(mnPendingSlideNumber));
1261 rendering::StringContext aContext (sText, 0, sText.getLength());
1262 Reference<rendering::XTextLayout> xLayout (
1263 pFont->mxFont->createTextLayout(
1264 aContext,
1265 rendering::TextDirection::WEAK_LEFT_TO_RIGHT,
1266 0));
1272 void PresenterController::ThrowIfDisposed (void) const
1273 throw (::com::sun::star::lang::DisposedException)
1275 if (rBHelper.bDisposed || rBHelper.bInDispose)
1277 throw lang::DisposedException (
1278 OUString(RTL_CONSTASCII_USTRINGPARAM(
1279 "PresenterController object has already been disposed")),
1280 const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
1285 } } // end of namespace ::sdext::presenter