1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PresenterViewFactory.cxx,v $
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 "PresenterViewFactory.hxx"
36 #include "PresenterPaneContainer.hxx"
37 #include "PresenterHelper.hxx"
38 #include "PresenterHelpView.hxx"
39 #include "PresenterNotesView.hxx"
40 #include "PresenterSlideShowView.hxx"
41 #include "PresenterSlidePreview.hxx"
42 #include "PresenterSlideSorter.hxx"
43 #include "PresenterToolBar.hxx"
44 #include <com/sun/star/beans/XPropertySet.hpp>
45 #include <com/sun/star/drawing/framework/ResourceId.hpp>
46 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
47 #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
48 #include <com/sun/star/drawing/XDrawPages.hpp>
49 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
50 #include <com/sun/star/drawing/XSlideSorterBase.hpp>
51 #include <com/sun/star/presentation/XSlideShow.hpp>
52 #include <com/sun/star/presentation/XSlideShowView.hpp>
53 #include <cppuhelper/compbase1.hxx>
54 #include <boost/bind.hpp>
56 using namespace ::com::sun::star
;
57 using namespace ::com::sun::star::uno
;
58 using namespace ::com::sun::star::drawing::framework
;
59 using ::rtl::OUString
;
61 #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString)))
63 namespace sdext
{ namespace presenter
{
65 const ::rtl::OUString
PresenterViewFactory::msCurrentSlidePreviewViewURL(
66 A2S("private:resource/view/Presenter/CurrentSlidePreview"));
67 const ::rtl::OUString
PresenterViewFactory::msNextSlidePreviewViewURL(
68 A2S("private:resource/view/Presenter/NextSlidePreview"));
69 const ::rtl::OUString
PresenterViewFactory::msNotesViewURL(
70 A2S("private:resource/view/Presenter/Notes"));
71 const ::rtl::OUString
PresenterViewFactory::msToolBarViewURL(
72 A2S("private:resource/view/Presenter/ToolBar"));
73 const ::rtl::OUString
PresenterViewFactory::msSlideSorterURL(
74 A2S("private:resource/view/Presenter/SlideSorter"));
75 const ::rtl::OUString
PresenterViewFactory::msHelpViewURL(
76 A2S("private:resource/view/Presenter/Help"));
80 //===== SimpleView ============================================================
84 typedef ::cppu::WeakComponentImplHelper1
<XView
> SimpleViewInterfaceBase
;
87 : private ::cppu::BaseMutex
,
88 public SimpleViewInterfaceBase
91 SimpleView (const Reference
<XResourceId
>& rxViewId
)
92 : SimpleViewInterfaceBase(m_aMutex
),mxResourceId(rxViewId
) {};
93 virtual ~SimpleView (void) {};
97 virtual Reference
<XResourceId
> SAL_CALL
getResourceId (void) throw (RuntimeException
)
98 { return mxResourceId
; };
101 Reference
<XResourceId
> mxResourceId
;
106 /** By default the PresenterSlidePreview shows the preview of the current
107 slide. This adapter class makes it display the preview of the next
110 class NextSlidePreview
: public PresenterSlidePreview
114 const css::uno::Reference
<css::uno::XComponentContext
>& rxContext
,
115 const css::uno::Reference
<css::drawing::framework::XResourceId
>& rxViewId
,
116 const css::uno::Reference
<css::drawing::framework::XPane
>& rxAnchorPane
,
117 const ::rtl::Reference
<PresenterController
>& rpPresenterController
)
118 : PresenterSlidePreview(rxContext
, rxViewId
, rxAnchorPane
, rpPresenterController
)
121 virtual ~NextSlidePreview (void) {}
122 virtual void SAL_CALL
setCurrentPage (
123 const css::uno::Reference
<css::drawing::XDrawPage
>& rxSlide
)
124 throw (css::uno::RuntimeException
)
126 Reference
<presentation::XSlideShowController
> xSlideShowController (
127 mpPresenterController
->GetSlideShowController());
128 Reference
<drawing::XDrawPage
> xSlide
;
129 if (xSlideShowController
.is())
131 const sal_Int32
nCount (xSlideShowController
->getSlideCount());
132 sal_Int32
nNextSlideIndex (-1);
133 if (xSlideShowController
->getCurrentSlide() == rxSlide
)
135 nNextSlideIndex
= xSlideShowController
->getNextSlideIndex();
139 for (sal_Int32 nIndex
=0; nIndex
<nCount
; ++nIndex
)
141 if (rxSlide
== Reference
<drawing::XDrawPage
>(
142 xSlideShowController
->getSlideByIndex(nIndex
), UNO_QUERY
))
144 nNextSlideIndex
= nIndex
+ 1;
148 if (nNextSlideIndex
>= 0)
150 if (nNextSlideIndex
< nCount
)
152 xSlide
= Reference
<drawing::XDrawPage
>(
153 xSlideShowController
->getSlideByIndex(nNextSlideIndex
),
158 PresenterSlidePreview::setCurrentPage(xSlide
);
162 } // end of anonymous namespace
167 //===== PresenterViewFactory ==============================================
169 PresenterViewFactory::PresenterViewFactory (
170 const Reference
<uno::XComponentContext
>& rxContext
,
171 const Reference
<frame::XController
>& rxController
,
172 const ::rtl::Reference
<PresenterController
>& rpPresenterController
)
173 : PresenterViewFactoryInterfaceBase(m_aMutex
),
174 mxComponentContext(rxContext
),
175 mxConfigurationController(),
176 mxControllerWeak(rxController
),
177 mpPresenterController(rpPresenterController
),
185 Reference
<drawing::framework::XResourceFactory
> PresenterViewFactory::Create (
186 const Reference
<uno::XComponentContext
>& rxContext
,
187 const Reference
<frame::XController
>& rxController
,
188 const ::rtl::Reference
<PresenterController
>& rpPresenterController
)
190 rtl::Reference
<PresenterViewFactory
> pFactory (
191 new PresenterViewFactory(rxContext
,rxController
,rpPresenterController
));
192 pFactory
->Register(rxController
);
193 return Reference
<drawing::framework::XResourceFactory
>(
194 static_cast<XWeak
*>(pFactory
.get()), UNO_QUERY
);
200 void PresenterViewFactory::Register (const Reference
<frame::XController
>& rxController
)
204 // Get the configuration controller.
205 Reference
<XControllerManager
> xCM (rxController
, UNO_QUERY_THROW
);
206 mxConfigurationController
= xCM
->getConfigurationController();
207 if ( ! mxConfigurationController
.is())
209 throw RuntimeException();
213 mxConfigurationController
->addResourceFactory(msCurrentSlidePreviewViewURL
, this);
214 mxConfigurationController
->addResourceFactory(msNextSlidePreviewViewURL
, this);
215 mxConfigurationController
->addResourceFactory(msNotesViewURL
, this);
216 mxConfigurationController
->addResourceFactory(msToolBarViewURL
, this);
217 mxConfigurationController
->addResourceFactory(msSlideSorterURL
, this);
218 mxConfigurationController
->addResourceFactory(msHelpViewURL
, this);
221 catch (RuntimeException
&)
224 if (mxConfigurationController
.is())
225 mxConfigurationController
->removeResourceFactoryForReference(this);
226 mxConfigurationController
= NULL
;
235 PresenterViewFactory::~PresenterViewFactory (void)
242 void SAL_CALL
PresenterViewFactory::disposing (void)
243 throw (RuntimeException
)
245 if (mxConfigurationController
.is())
246 mxConfigurationController
->removeResourceFactoryForReference(this);
247 mxConfigurationController
= NULL
;
249 if (mpResourceCache
.get() != NULL
)
251 // Dispose all views in the cache.
252 ResourceContainer::const_iterator
iView (mpResourceCache
->begin());
253 ResourceContainer::const_iterator
iEnd (mpResourceCache
->end());
254 for ( ; iView
!=iEnd
; ++iView
)
258 Reference
<lang::XComponent
> xComponent (iView
->second
.first
, UNO_QUERY
);
260 xComponent
->dispose();
262 catch (lang::DisposedException
&)
266 mpResourceCache
.reset();
273 //----- XViewFactory ----------------------------------------------------------
275 Reference
<XResource
> SAL_CALL
PresenterViewFactory::createResource (
276 const Reference
<XResourceId
>& rxViewId
)
277 throw (RuntimeException
)
281 Reference
<XResource
> xView
;
285 Reference
<XPane
> xAnchorPane (
286 mxConfigurationController
->getResource(rxViewId
->getAnchor()),
288 xView
= GetViewFromCache(rxViewId
, xAnchorPane
);
290 xView
= CreateView(rxViewId
, xAnchorPane
);
292 // Activate the view.
293 PresenterPaneContainer::SharedPaneDescriptor
pDescriptor (
294 mpPresenterController
->GetPaneContainer()->FindPaneId(rxViewId
->getAnchor()));
295 if (pDescriptor
.get() != NULL
)
296 pDescriptor
->SetActivationState(true);
305 void SAL_CALL
PresenterViewFactory::releaseResource (const Reference
<XResource
>& rxView
)
306 throw (RuntimeException
)
313 // Deactivate the view.
314 PresenterPaneContainer::SharedPaneDescriptor
pDescriptor (
315 mpPresenterController
->GetPaneContainer()->FindPaneId(
316 rxView
->getResourceId()->getAnchor()));
317 if (pDescriptor
.get() != NULL
)
318 pDescriptor
->SetActivationState(false);
320 // Dispose only views that we can not put into the cache.
321 CachablePresenterView
* pView
= dynamic_cast<CachablePresenterView
*>(rxView
.get());
322 if (pView
== NULL
|| mpResourceCache
.get()==NULL
)
327 pView
->ReleaseView();
328 Reference
<lang::XComponent
> xComponent (rxView
, UNO_QUERY
);
330 xComponent
->dispose();
332 catch (lang::DisposedException
&)
334 // Do not let disposed exceptions get out. It might be interpreted
335 // as coming from the factory, which would then be removed from the
336 // drawing framework.
341 // Put cachable views in the cache.
342 Reference
<XResourceId
> xViewId (rxView
->getResourceId());
345 Reference
<XPane
> xAnchorPane (
346 mxConfigurationController
->getResource(xViewId
->getAnchor()),
348 (*mpResourceCache
)[xViewId
->getResourceURL()]
349 = ViewResourceDescriptor(Reference
<XView
>(rxView
, UNO_QUERY
), xAnchorPane
);
350 pView
->DeactivatePresenterView();
358 //-----------------------------------------------------------------------------
360 Reference
<XResource
> PresenterViewFactory::GetViewFromCache(
361 const Reference
<XResourceId
>& rxViewId
,
362 const Reference
<XPane
>& rxAnchorPane
) const
364 if (mpResourceCache
.get() == NULL
)
369 const OUString
sResourceURL (rxViewId
->getResourceURL());
371 // Can we use a view from the cache?
372 ResourceContainer::const_iterator
iView (mpResourceCache
->find(sResourceURL
));
373 if (iView
!= mpResourceCache
->end())
375 // The view is in the container but it can only be used if
376 // the anchor pane is the same now as it was at creation of
378 if (iView
->second
.second
== rxAnchorPane
)
380 CachablePresenterView
* pView
381 = dynamic_cast<CachablePresenterView
*>(iView
->second
.first
.get());
383 pView
->ActivatePresenterView();
384 return Reference
<XResource
>(iView
->second
.first
, UNO_QUERY
);
387 // Right view, wrong pane. Create a new view.
390 catch (RuntimeException
&)
399 Reference
<XResource
> PresenterViewFactory::CreateView(
400 const Reference
<XResourceId
>& rxViewId
,
401 const Reference
<XPane
>& rxAnchorPane
)
403 Reference
<XView
> xView
;
407 const OUString
sResourceURL (rxViewId
->getResourceURL());
409 if (sResourceURL
.equals(msCurrentSlidePreviewViewURL
))
411 xView
= CreateSlideShowView(rxViewId
);
413 else if (sResourceURL
.equals(msNotesViewURL
))
415 xView
= CreateNotesView(rxViewId
, rxAnchorPane
);
417 else if (sResourceURL
.equals(msNextSlidePreviewViewURL
))
419 xView
= CreateSlidePreviewView(rxViewId
, rxAnchorPane
);
421 else if (sResourceURL
.equals(msToolBarViewURL
))
423 xView
= CreateToolBarView(rxViewId
);
425 else if (sResourceURL
.equals(msSlideSorterURL
))
427 xView
= CreateSlideSorterView(rxViewId
);
429 else if (sResourceURL
.equals(msHelpViewURL
))
431 xView
= CreateHelpView(rxViewId
);
435 CachablePresenterView
* pView
= dynamic_cast<CachablePresenterView
*>(xView
.get());
437 pView
->ActivatePresenterView();
439 catch (RuntimeException
&)
444 return Reference
<XResource
>(xView
, UNO_QUERY
);
450 Reference
<XView
> PresenterViewFactory::CreateSlideShowView(
451 const Reference
<XResourceId
>& rxViewId
) const
453 Reference
<XView
> xView
;
455 if ( ! mxConfigurationController
.is())
457 if ( ! mxComponentContext
.is())
462 rtl::Reference
<PresenterSlideShowView
> pShowView (
463 new PresenterSlideShowView(
466 Reference
<frame::XController
>(mxControllerWeak
),
467 mpPresenterController
));
468 pShowView
->LateInit();
469 xView
= Reference
<XView
>(pShowView
.get());
471 catch (RuntimeException
&)
482 Reference
<XView
> PresenterViewFactory::CreateSlidePreviewView(
483 const Reference
<XResourceId
>& rxViewId
,
484 const Reference
<XPane
>& rxAnchorPane
) const
486 Reference
<XView
> xView
;
488 if ( ! mxConfigurationController
.is())
490 if ( ! mxComponentContext
.is())
495 xView
= Reference
<XView
>(
496 static_cast<XWeak
*>(new NextSlidePreview(
500 mpPresenterController
)),
503 catch (RuntimeException
&)
514 Reference
<XView
> PresenterViewFactory::CreateToolBarView(
515 const Reference
<XResourceId
>& rxViewId
) const
517 return new PresenterToolBarView(
520 Reference
<frame::XController
>(mxControllerWeak
),
521 mpPresenterController
);
527 Reference
<XView
> PresenterViewFactory::CreateNotesView(
528 const Reference
<XResourceId
>& rxViewId
,
529 const Reference
<XPane
>& rxAnchorPane
) const
532 Reference
<XView
> xView
;
534 if ( ! mxConfigurationController
.is())
536 if ( ! mxComponentContext
.is())
541 xView
= Reference
<XView
>(static_cast<XWeak
*>(
542 new PresenterNotesView(
545 Reference
<frame::XController
>(mxControllerWeak
),
546 mpPresenterController
)),
549 catch (RuntimeException
&)
560 Reference
<XView
> PresenterViewFactory::CreateSlideSorterView(
561 const Reference
<XResourceId
>& rxViewId
) const
563 Reference
<XView
> xView
;
565 if ( ! mxConfigurationController
.is())
567 if ( ! mxComponentContext
.is())
572 rtl::Reference
<PresenterSlideSorter
> pView (
573 new PresenterSlideSorter(
576 Reference
<frame::XController
>(mxControllerWeak
),
577 mpPresenterController
));
578 PresenterPaneContainer::SharedPaneDescriptor
pDescriptor (
579 mpPresenterController
->GetPaneContainer()->FindPaneId(rxViewId
->getAnchor()));
580 if (pDescriptor
.get() != NULL
)
581 pDescriptor
->maActivator
= ::boost::bind(
582 &PresenterSlideSorter::SetActiveState
, pView
.get(), _1
);
585 catch (RuntimeException
&)
596 Reference
<XView
> PresenterViewFactory::CreateHelpView(
597 const Reference
<XResourceId
>& rxViewId
) const
599 return Reference
<XView
>(new PresenterHelpView(
602 Reference
<frame::XController
>(mxControllerWeak
),
603 mpPresenterController
));
610 void PresenterViewFactory::ThrowIfDisposed (void) const
611 throw (::com::sun::star::lang::DisposedException
)
613 if (rBHelper
.bDisposed
|| rBHelper
.bInDispose
)
615 throw lang::DisposedException (
616 OUString(RTL_CONSTASCII_USTRINGPARAM(
617 "PresenterViewFactory object has already been disposed")),
618 const_cast<uno::XWeak
*>(static_cast<const uno::XWeak
*>(this)));
625 //===== CachablePresenterView =================================================
627 CachablePresenterView::CachablePresenterView (void)
628 : mbIsPresenterViewActive(true)
635 void CachablePresenterView::ActivatePresenterView (void)
637 mbIsPresenterViewActive
= true;
643 void CachablePresenterView::DeactivatePresenterView (void)
645 mbIsPresenterViewActive
= false;
651 void CachablePresenterView::ReleaseView (void)