1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sdext.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "PresenterViewFactory.hxx"
32*cdf0e10cSrcweir #include "PresenterPaneContainer.hxx"
33*cdf0e10cSrcweir #include "PresenterHelper.hxx"
34*cdf0e10cSrcweir #include "PresenterHelpView.hxx"
35*cdf0e10cSrcweir #include "PresenterNotesView.hxx"
36*cdf0e10cSrcweir #include "PresenterSlideShowView.hxx"
37*cdf0e10cSrcweir #include "PresenterSlidePreview.hxx"
38*cdf0e10cSrcweir #include "PresenterSlideSorter.hxx"
39*cdf0e10cSrcweir #include "PresenterToolBar.hxx"
40*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/drawing/framework/ResourceId.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/drawing/framework/XControllerManager.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/drawing/XDrawPages.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/drawing/XSlideSorterBase.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/presentation/XSlideShow.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/presentation/XSlideShowView.hpp>
49*cdf0e10cSrcweir #include <cppuhelper/compbase1.hxx>
50*cdf0e10cSrcweir #include <boost/bind.hpp>
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir using namespace ::com::sun::star;
53*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
54*cdf0e10cSrcweir using namespace ::com::sun::star::drawing::framework;
55*cdf0e10cSrcweir using ::rtl::OUString;
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString)))
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir namespace sdext { namespace presenter {
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir const ::rtl::OUString PresenterViewFactory::msCurrentSlidePreviewViewURL(
62*cdf0e10cSrcweir     A2S("private:resource/view/Presenter/CurrentSlidePreview"));
63*cdf0e10cSrcweir const ::rtl::OUString PresenterViewFactory::msNextSlidePreviewViewURL(
64*cdf0e10cSrcweir     A2S("private:resource/view/Presenter/NextSlidePreview"));
65*cdf0e10cSrcweir const ::rtl::OUString PresenterViewFactory::msNotesViewURL(
66*cdf0e10cSrcweir     A2S("private:resource/view/Presenter/Notes"));
67*cdf0e10cSrcweir const ::rtl::OUString PresenterViewFactory::msToolBarViewURL(
68*cdf0e10cSrcweir     A2S("private:resource/view/Presenter/ToolBar"));
69*cdf0e10cSrcweir const ::rtl::OUString PresenterViewFactory::msSlideSorterURL(
70*cdf0e10cSrcweir     A2S("private:resource/view/Presenter/SlideSorter"));
71*cdf0e10cSrcweir const ::rtl::OUString PresenterViewFactory::msHelpViewURL(
72*cdf0e10cSrcweir     A2S("private:resource/view/Presenter/Help"));
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir //===== SimpleView ============================================================
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir namespace {
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir typedef ::cppu::WeakComponentImplHelper1 <XView> SimpleViewInterfaceBase;
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir class SimpleView
83*cdf0e10cSrcweir     : private ::cppu::BaseMutex,
84*cdf0e10cSrcweir       public SimpleViewInterfaceBase
85*cdf0e10cSrcweir {
86*cdf0e10cSrcweir public:
87*cdf0e10cSrcweir     SimpleView (const Reference<XResourceId>& rxViewId)
88*cdf0e10cSrcweir         : SimpleViewInterfaceBase(m_aMutex),mxResourceId(rxViewId) {};
89*cdf0e10cSrcweir     virtual ~SimpleView (void) {};
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir     // XView
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir     virtual Reference<XResourceId> SAL_CALL getResourceId (void) throw (RuntimeException)
94*cdf0e10cSrcweir     { return mxResourceId; };
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir private:
97*cdf0e10cSrcweir     Reference<XResourceId> mxResourceId;
98*cdf0e10cSrcweir };
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir /** By default the PresenterSlidePreview shows the preview of the current
103*cdf0e10cSrcweir     slide.  This adapter class makes it display the preview of the next
104*cdf0e10cSrcweir     slide.
105*cdf0e10cSrcweir */
106*cdf0e10cSrcweir class NextSlidePreview : public PresenterSlidePreview
107*cdf0e10cSrcweir {
108*cdf0e10cSrcweir public:
109*cdf0e10cSrcweir     NextSlidePreview (
110*cdf0e10cSrcweir         const css::uno::Reference<css::uno::XComponentContext>& rxContext,
111*cdf0e10cSrcweir         const css::uno::Reference<css::drawing::framework::XResourceId>& rxViewId,
112*cdf0e10cSrcweir         const css::uno::Reference<css::drawing::framework::XPane>& rxAnchorPane,
113*cdf0e10cSrcweir         const ::rtl::Reference<PresenterController>& rpPresenterController)
114*cdf0e10cSrcweir         : PresenterSlidePreview(rxContext, rxViewId, rxAnchorPane, rpPresenterController)
115*cdf0e10cSrcweir     {
116*cdf0e10cSrcweir     }
117*cdf0e10cSrcweir     virtual ~NextSlidePreview (void) {}
118*cdf0e10cSrcweir     virtual void SAL_CALL setCurrentPage (
119*cdf0e10cSrcweir         const css::uno::Reference<css::drawing::XDrawPage>& rxSlide)
120*cdf0e10cSrcweir         throw (css::uno::RuntimeException)
121*cdf0e10cSrcweir     {
122*cdf0e10cSrcweir         Reference<presentation::XSlideShowController> xSlideShowController (
123*cdf0e10cSrcweir             mpPresenterController->GetSlideShowController());
124*cdf0e10cSrcweir         Reference<drawing::XDrawPage> xSlide;
125*cdf0e10cSrcweir         if (xSlideShowController.is())
126*cdf0e10cSrcweir         {
127*cdf0e10cSrcweir             const sal_Int32 nCount (xSlideShowController->getSlideCount());
128*cdf0e10cSrcweir             sal_Int32 nNextSlideIndex (-1);
129*cdf0e10cSrcweir             if (xSlideShowController->getCurrentSlide() == rxSlide)
130*cdf0e10cSrcweir             {
131*cdf0e10cSrcweir                 nNextSlideIndex = xSlideShowController->getNextSlideIndex();
132*cdf0e10cSrcweir             }
133*cdf0e10cSrcweir             else
134*cdf0e10cSrcweir             {
135*cdf0e10cSrcweir                 for (sal_Int32 nIndex=0; nIndex<nCount; ++nIndex)
136*cdf0e10cSrcweir                 {
137*cdf0e10cSrcweir                     if (rxSlide == Reference<drawing::XDrawPage>(
138*cdf0e10cSrcweir                         xSlideShowController->getSlideByIndex(nIndex), UNO_QUERY))
139*cdf0e10cSrcweir                     {
140*cdf0e10cSrcweir                         nNextSlideIndex = nIndex + 1;
141*cdf0e10cSrcweir                     }
142*cdf0e10cSrcweir                 }
143*cdf0e10cSrcweir             }
144*cdf0e10cSrcweir             if (nNextSlideIndex >= 0)
145*cdf0e10cSrcweir             {
146*cdf0e10cSrcweir                 if (nNextSlideIndex < nCount)
147*cdf0e10cSrcweir                 {
148*cdf0e10cSrcweir                     xSlide = Reference<drawing::XDrawPage>(
149*cdf0e10cSrcweir                         xSlideShowController->getSlideByIndex(nNextSlideIndex),
150*cdf0e10cSrcweir                          UNO_QUERY);
151*cdf0e10cSrcweir                 }
152*cdf0e10cSrcweir             }
153*cdf0e10cSrcweir         }
154*cdf0e10cSrcweir         PresenterSlidePreview::setCurrentPage(xSlide);
155*cdf0e10cSrcweir     }
156*cdf0e10cSrcweir };
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir } // end of anonymous namespace
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir //===== PresenterViewFactory ==============================================
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir PresenterViewFactory::PresenterViewFactory (
166*cdf0e10cSrcweir     const Reference<uno::XComponentContext>& rxContext,
167*cdf0e10cSrcweir     const Reference<frame::XController>& rxController,
168*cdf0e10cSrcweir     const ::rtl::Reference<PresenterController>& rpPresenterController)
169*cdf0e10cSrcweir     : PresenterViewFactoryInterfaceBase(m_aMutex),
170*cdf0e10cSrcweir       mxComponentContext(rxContext),
171*cdf0e10cSrcweir       mxConfigurationController(),
172*cdf0e10cSrcweir       mxControllerWeak(rxController),
173*cdf0e10cSrcweir       mpPresenterController(rpPresenterController),
174*cdf0e10cSrcweir       mpResourceCache()
175*cdf0e10cSrcweir {
176*cdf0e10cSrcweir }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir Reference<drawing::framework::XResourceFactory> PresenterViewFactory::Create (
182*cdf0e10cSrcweir     const Reference<uno::XComponentContext>& rxContext,
183*cdf0e10cSrcweir     const Reference<frame::XController>& rxController,
184*cdf0e10cSrcweir     const ::rtl::Reference<PresenterController>& rpPresenterController)
185*cdf0e10cSrcweir {
186*cdf0e10cSrcweir     rtl::Reference<PresenterViewFactory> pFactory (
187*cdf0e10cSrcweir         new PresenterViewFactory(rxContext,rxController,rpPresenterController));
188*cdf0e10cSrcweir     pFactory->Register(rxController);
189*cdf0e10cSrcweir     return Reference<drawing::framework::XResourceFactory>(
190*cdf0e10cSrcweir         static_cast<XWeak*>(pFactory.get()), UNO_QUERY);
191*cdf0e10cSrcweir }
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir void PresenterViewFactory::Register (const Reference<frame::XController>& rxController)
197*cdf0e10cSrcweir {
198*cdf0e10cSrcweir     try
199*cdf0e10cSrcweir     {
200*cdf0e10cSrcweir         // Get the configuration controller.
201*cdf0e10cSrcweir         Reference<XControllerManager> xCM (rxController, UNO_QUERY_THROW);
202*cdf0e10cSrcweir         mxConfigurationController = xCM->getConfigurationController();
203*cdf0e10cSrcweir         if ( ! mxConfigurationController.is())
204*cdf0e10cSrcweir         {
205*cdf0e10cSrcweir             throw RuntimeException();
206*cdf0e10cSrcweir         }
207*cdf0e10cSrcweir         else
208*cdf0e10cSrcweir         {
209*cdf0e10cSrcweir             mxConfigurationController->addResourceFactory(msCurrentSlidePreviewViewURL, this);
210*cdf0e10cSrcweir             mxConfigurationController->addResourceFactory(msNextSlidePreviewViewURL, this);
211*cdf0e10cSrcweir             mxConfigurationController->addResourceFactory(msNotesViewURL, this);
212*cdf0e10cSrcweir             mxConfigurationController->addResourceFactory(msToolBarViewURL, this);
213*cdf0e10cSrcweir             mxConfigurationController->addResourceFactory(msSlideSorterURL, this);
214*cdf0e10cSrcweir             mxConfigurationController->addResourceFactory(msHelpViewURL, this);
215*cdf0e10cSrcweir         }
216*cdf0e10cSrcweir     }
217*cdf0e10cSrcweir     catch (RuntimeException&)
218*cdf0e10cSrcweir     {
219*cdf0e10cSrcweir         OSL_ASSERT(false);
220*cdf0e10cSrcweir         if (mxConfigurationController.is())
221*cdf0e10cSrcweir             mxConfigurationController->removeResourceFactoryForReference(this);
222*cdf0e10cSrcweir         mxConfigurationController = NULL;
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir         throw;
225*cdf0e10cSrcweir     }
226*cdf0e10cSrcweir }
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir PresenterViewFactory::~PresenterViewFactory (void)
232*cdf0e10cSrcweir {
233*cdf0e10cSrcweir }
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir void SAL_CALL PresenterViewFactory::disposing (void)
239*cdf0e10cSrcweir     throw (RuntimeException)
240*cdf0e10cSrcweir {
241*cdf0e10cSrcweir     if (mxConfigurationController.is())
242*cdf0e10cSrcweir         mxConfigurationController->removeResourceFactoryForReference(this);
243*cdf0e10cSrcweir     mxConfigurationController = NULL;
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir     if (mpResourceCache.get() != NULL)
246*cdf0e10cSrcweir     {
247*cdf0e10cSrcweir         // Dispose all views in the cache.
248*cdf0e10cSrcweir         ResourceContainer::const_iterator iView (mpResourceCache->begin());
249*cdf0e10cSrcweir         ResourceContainer::const_iterator iEnd (mpResourceCache->end());
250*cdf0e10cSrcweir         for ( ; iView!=iEnd; ++iView)
251*cdf0e10cSrcweir         {
252*cdf0e10cSrcweir             try
253*cdf0e10cSrcweir             {
254*cdf0e10cSrcweir                 Reference<lang::XComponent> xComponent (iView->second.first, UNO_QUERY);
255*cdf0e10cSrcweir                 if (xComponent.is())
256*cdf0e10cSrcweir                     xComponent->dispose();
257*cdf0e10cSrcweir             }
258*cdf0e10cSrcweir             catch (lang::DisposedException&)
259*cdf0e10cSrcweir             {
260*cdf0e10cSrcweir             }
261*cdf0e10cSrcweir         }
262*cdf0e10cSrcweir         mpResourceCache.reset();
263*cdf0e10cSrcweir     }
264*cdf0e10cSrcweir }
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir //----- XViewFactory ----------------------------------------------------------
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir Reference<XResource> SAL_CALL PresenterViewFactory::createResource (
272*cdf0e10cSrcweir     const Reference<XResourceId>& rxViewId)
273*cdf0e10cSrcweir     throw (RuntimeException)
274*cdf0e10cSrcweir {
275*cdf0e10cSrcweir     ThrowIfDisposed();
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir     Reference<XResource> xView;
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir     if (rxViewId.is())
280*cdf0e10cSrcweir     {
281*cdf0e10cSrcweir         Reference<XPane> xAnchorPane (
282*cdf0e10cSrcweir             mxConfigurationController->getResource(rxViewId->getAnchor()),
283*cdf0e10cSrcweir             UNO_QUERY_THROW);
284*cdf0e10cSrcweir         xView = GetViewFromCache(rxViewId, xAnchorPane);
285*cdf0e10cSrcweir         if (xView == NULL)
286*cdf0e10cSrcweir             xView = CreateView(rxViewId, xAnchorPane);
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir         // Activate the view.
289*cdf0e10cSrcweir         PresenterPaneContainer::SharedPaneDescriptor pDescriptor (
290*cdf0e10cSrcweir             mpPresenterController->GetPaneContainer()->FindPaneId(rxViewId->getAnchor()));
291*cdf0e10cSrcweir         if (pDescriptor.get() != NULL)
292*cdf0e10cSrcweir             pDescriptor->SetActivationState(true);
293*cdf0e10cSrcweir     }
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir     return xView;
296*cdf0e10cSrcweir }
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir void SAL_CALL PresenterViewFactory::releaseResource (const Reference<XResource>& rxView)
302*cdf0e10cSrcweir     throw (RuntimeException)
303*cdf0e10cSrcweir {
304*cdf0e10cSrcweir     ThrowIfDisposed();
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir     if ( ! rxView.is())
307*cdf0e10cSrcweir         return;
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir     // Deactivate the view.
310*cdf0e10cSrcweir     PresenterPaneContainer::SharedPaneDescriptor pDescriptor (
311*cdf0e10cSrcweir         mpPresenterController->GetPaneContainer()->FindPaneId(
312*cdf0e10cSrcweir             rxView->getResourceId()->getAnchor()));
313*cdf0e10cSrcweir     if (pDescriptor.get() != NULL)
314*cdf0e10cSrcweir         pDescriptor->SetActivationState(false);
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir     // Dispose only views that we can not put into the cache.
317*cdf0e10cSrcweir     CachablePresenterView* pView = dynamic_cast<CachablePresenterView*>(rxView.get());
318*cdf0e10cSrcweir     if (pView == NULL || mpResourceCache.get()==NULL)
319*cdf0e10cSrcweir     {
320*cdf0e10cSrcweir         try
321*cdf0e10cSrcweir         {
322*cdf0e10cSrcweir             if (pView != NULL)
323*cdf0e10cSrcweir                 pView->ReleaseView();
324*cdf0e10cSrcweir             Reference<lang::XComponent> xComponent (rxView, UNO_QUERY);
325*cdf0e10cSrcweir             if (xComponent.is())
326*cdf0e10cSrcweir                 xComponent->dispose();
327*cdf0e10cSrcweir         }
328*cdf0e10cSrcweir         catch (lang::DisposedException&)
329*cdf0e10cSrcweir         {
330*cdf0e10cSrcweir             // Do not let disposed exceptions get out.  It might be interpreted
331*cdf0e10cSrcweir             // as coming from the factory, which would then be removed from the
332*cdf0e10cSrcweir             // drawing framework.
333*cdf0e10cSrcweir         }
334*cdf0e10cSrcweir     }
335*cdf0e10cSrcweir     else
336*cdf0e10cSrcweir     {
337*cdf0e10cSrcweir         // Put cachable views in the cache.
338*cdf0e10cSrcweir         Reference<XResourceId> xViewId (rxView->getResourceId());
339*cdf0e10cSrcweir         if (xViewId.is())
340*cdf0e10cSrcweir         {
341*cdf0e10cSrcweir             Reference<XPane> xAnchorPane (
342*cdf0e10cSrcweir                 mxConfigurationController->getResource(xViewId->getAnchor()),
343*cdf0e10cSrcweir                 UNO_QUERY_THROW);
344*cdf0e10cSrcweir             (*mpResourceCache)[xViewId->getResourceURL()]
345*cdf0e10cSrcweir                 = ViewResourceDescriptor(Reference<XView>(rxView, UNO_QUERY), xAnchorPane);
346*cdf0e10cSrcweir             pView->DeactivatePresenterView();
347*cdf0e10cSrcweir         }
348*cdf0e10cSrcweir     }
349*cdf0e10cSrcweir }
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir 
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir //-----------------------------------------------------------------------------
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir Reference<XResource> PresenterViewFactory::GetViewFromCache(
357*cdf0e10cSrcweir     const Reference<XResourceId>& rxViewId,
358*cdf0e10cSrcweir     const Reference<XPane>& rxAnchorPane) const
359*cdf0e10cSrcweir {
360*cdf0e10cSrcweir     if (mpResourceCache.get() == NULL)
361*cdf0e10cSrcweir         return NULL;
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir     try
364*cdf0e10cSrcweir     {
365*cdf0e10cSrcweir         const OUString sResourceURL (rxViewId->getResourceURL());
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir         // Can we use a view from the cache?
368*cdf0e10cSrcweir         ResourceContainer::const_iterator iView (mpResourceCache->find(sResourceURL));
369*cdf0e10cSrcweir         if (iView != mpResourceCache->end())
370*cdf0e10cSrcweir         {
371*cdf0e10cSrcweir             // The view is in the container but it can only be used if
372*cdf0e10cSrcweir             // the anchor pane is the same now as it was at creation of
373*cdf0e10cSrcweir             // the view.
374*cdf0e10cSrcweir             if (iView->second.second == rxAnchorPane)
375*cdf0e10cSrcweir             {
376*cdf0e10cSrcweir                 CachablePresenterView* pView
377*cdf0e10cSrcweir                     = dynamic_cast<CachablePresenterView*>(iView->second.first.get());
378*cdf0e10cSrcweir                 if (pView != NULL)
379*cdf0e10cSrcweir                     pView->ActivatePresenterView();
380*cdf0e10cSrcweir                 return Reference<XResource>(iView->second.first, UNO_QUERY);
381*cdf0e10cSrcweir             }
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir             // Right view, wrong pane.  Create a new view.
384*cdf0e10cSrcweir         }
385*cdf0e10cSrcweir     }
386*cdf0e10cSrcweir     catch (RuntimeException&)
387*cdf0e10cSrcweir     {
388*cdf0e10cSrcweir     }
389*cdf0e10cSrcweir     return NULL;
390*cdf0e10cSrcweir }
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir 
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir Reference<XResource> PresenterViewFactory::CreateView(
396*cdf0e10cSrcweir     const Reference<XResourceId>& rxViewId,
397*cdf0e10cSrcweir     const Reference<XPane>& rxAnchorPane)
398*cdf0e10cSrcweir {
399*cdf0e10cSrcweir     Reference<XView> xView;
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir     try
402*cdf0e10cSrcweir     {
403*cdf0e10cSrcweir         const OUString sResourceURL (rxViewId->getResourceURL());
404*cdf0e10cSrcweir 
405*cdf0e10cSrcweir         if (sResourceURL.equals(msCurrentSlidePreviewViewURL))
406*cdf0e10cSrcweir         {
407*cdf0e10cSrcweir             xView = CreateSlideShowView(rxViewId);
408*cdf0e10cSrcweir         }
409*cdf0e10cSrcweir         else if (sResourceURL.equals(msNotesViewURL))
410*cdf0e10cSrcweir         {
411*cdf0e10cSrcweir             xView = CreateNotesView(rxViewId, rxAnchorPane);
412*cdf0e10cSrcweir         }
413*cdf0e10cSrcweir         else if (sResourceURL.equals(msNextSlidePreviewViewURL))
414*cdf0e10cSrcweir         {
415*cdf0e10cSrcweir             xView = CreateSlidePreviewView(rxViewId, rxAnchorPane);
416*cdf0e10cSrcweir         }
417*cdf0e10cSrcweir         else if (sResourceURL.equals(msToolBarViewURL))
418*cdf0e10cSrcweir         {
419*cdf0e10cSrcweir             xView = CreateToolBarView(rxViewId);
420*cdf0e10cSrcweir         }
421*cdf0e10cSrcweir         else if (sResourceURL.equals(msSlideSorterURL))
422*cdf0e10cSrcweir         {
423*cdf0e10cSrcweir             xView = CreateSlideSorterView(rxViewId);
424*cdf0e10cSrcweir         }
425*cdf0e10cSrcweir         else if (sResourceURL.equals(msHelpViewURL))
426*cdf0e10cSrcweir         {
427*cdf0e10cSrcweir             xView = CreateHelpView(rxViewId);
428*cdf0e10cSrcweir         }
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir         // Activate it.
431*cdf0e10cSrcweir         CachablePresenterView* pView = dynamic_cast<CachablePresenterView*>(xView.get());
432*cdf0e10cSrcweir         if (pView != NULL)
433*cdf0e10cSrcweir             pView->ActivatePresenterView();
434*cdf0e10cSrcweir     }
435*cdf0e10cSrcweir     catch (RuntimeException&)
436*cdf0e10cSrcweir     {
437*cdf0e10cSrcweir         xView = NULL;
438*cdf0e10cSrcweir     }
439*cdf0e10cSrcweir 
440*cdf0e10cSrcweir     return Reference<XResource>(xView, UNO_QUERY);
441*cdf0e10cSrcweir }
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir 
446*cdf0e10cSrcweir Reference<XView> PresenterViewFactory::CreateSlideShowView(
447*cdf0e10cSrcweir     const Reference<XResourceId>& rxViewId) const
448*cdf0e10cSrcweir {
449*cdf0e10cSrcweir     Reference<XView> xView;
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir     if ( ! mxConfigurationController.is())
452*cdf0e10cSrcweir         return xView;
453*cdf0e10cSrcweir     if ( ! mxComponentContext.is())
454*cdf0e10cSrcweir         return xView;
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir     try
457*cdf0e10cSrcweir     {
458*cdf0e10cSrcweir         rtl::Reference<PresenterSlideShowView> pShowView (
459*cdf0e10cSrcweir             new PresenterSlideShowView(
460*cdf0e10cSrcweir                 mxComponentContext,
461*cdf0e10cSrcweir                 rxViewId,
462*cdf0e10cSrcweir                 Reference<frame::XController>(mxControllerWeak),
463*cdf0e10cSrcweir                 mpPresenterController));
464*cdf0e10cSrcweir         pShowView->LateInit();
465*cdf0e10cSrcweir         xView = Reference<XView>(pShowView.get());
466*cdf0e10cSrcweir     }
467*cdf0e10cSrcweir     catch (RuntimeException&)
468*cdf0e10cSrcweir     {
469*cdf0e10cSrcweir         xView = NULL;
470*cdf0e10cSrcweir     }
471*cdf0e10cSrcweir 
472*cdf0e10cSrcweir     return xView;
473*cdf0e10cSrcweir }
474*cdf0e10cSrcweir 
475*cdf0e10cSrcweir 
476*cdf0e10cSrcweir 
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir Reference<XView> PresenterViewFactory::CreateSlidePreviewView(
479*cdf0e10cSrcweir     const Reference<XResourceId>& rxViewId,
480*cdf0e10cSrcweir     const Reference<XPane>& rxAnchorPane) const
481*cdf0e10cSrcweir {
482*cdf0e10cSrcweir     Reference<XView> xView;
483*cdf0e10cSrcweir 
484*cdf0e10cSrcweir     if ( ! mxConfigurationController.is())
485*cdf0e10cSrcweir         return xView;
486*cdf0e10cSrcweir     if ( ! mxComponentContext.is())
487*cdf0e10cSrcweir         return xView;
488*cdf0e10cSrcweir 
489*cdf0e10cSrcweir     try
490*cdf0e10cSrcweir     {
491*cdf0e10cSrcweir         xView = Reference<XView>(
492*cdf0e10cSrcweir             static_cast<XWeak*>(new NextSlidePreview(
493*cdf0e10cSrcweir                 mxComponentContext,
494*cdf0e10cSrcweir                 rxViewId,
495*cdf0e10cSrcweir                 rxAnchorPane,
496*cdf0e10cSrcweir                 mpPresenterController)),
497*cdf0e10cSrcweir             UNO_QUERY_THROW);
498*cdf0e10cSrcweir     }
499*cdf0e10cSrcweir     catch (RuntimeException&)
500*cdf0e10cSrcweir     {
501*cdf0e10cSrcweir         xView = NULL;
502*cdf0e10cSrcweir     }
503*cdf0e10cSrcweir 
504*cdf0e10cSrcweir     return xView;
505*cdf0e10cSrcweir }
506*cdf0e10cSrcweir 
507*cdf0e10cSrcweir 
508*cdf0e10cSrcweir 
509*cdf0e10cSrcweir 
510*cdf0e10cSrcweir Reference<XView> PresenterViewFactory::CreateToolBarView(
511*cdf0e10cSrcweir     const Reference<XResourceId>& rxViewId) const
512*cdf0e10cSrcweir {
513*cdf0e10cSrcweir     return new PresenterToolBarView(
514*cdf0e10cSrcweir         mxComponentContext,
515*cdf0e10cSrcweir         rxViewId,
516*cdf0e10cSrcweir         Reference<frame::XController>(mxControllerWeak),
517*cdf0e10cSrcweir         mpPresenterController);
518*cdf0e10cSrcweir }
519*cdf0e10cSrcweir 
520*cdf0e10cSrcweir 
521*cdf0e10cSrcweir 
522*cdf0e10cSrcweir 
523*cdf0e10cSrcweir Reference<XView> PresenterViewFactory::CreateNotesView(
524*cdf0e10cSrcweir     const Reference<XResourceId>& rxViewId,
525*cdf0e10cSrcweir     const Reference<XPane>& rxAnchorPane) const
526*cdf0e10cSrcweir {
527*cdf0e10cSrcweir     (void)rxAnchorPane;
528*cdf0e10cSrcweir     Reference<XView> xView;
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir     if ( ! mxConfigurationController.is())
531*cdf0e10cSrcweir         return xView;
532*cdf0e10cSrcweir     if ( ! mxComponentContext.is())
533*cdf0e10cSrcweir         return xView;
534*cdf0e10cSrcweir 
535*cdf0e10cSrcweir     try
536*cdf0e10cSrcweir     {
537*cdf0e10cSrcweir         xView = Reference<XView>(static_cast<XWeak*>(
538*cdf0e10cSrcweir             new PresenterNotesView(
539*cdf0e10cSrcweir                 mxComponentContext,
540*cdf0e10cSrcweir                 rxViewId,
541*cdf0e10cSrcweir                 Reference<frame::XController>(mxControllerWeak),
542*cdf0e10cSrcweir                 mpPresenterController)),
543*cdf0e10cSrcweir             UNO_QUERY_THROW);
544*cdf0e10cSrcweir     }
545*cdf0e10cSrcweir     catch (RuntimeException&)
546*cdf0e10cSrcweir     {
547*cdf0e10cSrcweir         xView = NULL;
548*cdf0e10cSrcweir     }
549*cdf0e10cSrcweir 
550*cdf0e10cSrcweir     return xView;
551*cdf0e10cSrcweir }
552*cdf0e10cSrcweir 
553*cdf0e10cSrcweir 
554*cdf0e10cSrcweir 
555*cdf0e10cSrcweir 
556*cdf0e10cSrcweir Reference<XView> PresenterViewFactory::CreateSlideSorterView(
557*cdf0e10cSrcweir     const Reference<XResourceId>& rxViewId) const
558*cdf0e10cSrcweir {
559*cdf0e10cSrcweir     Reference<XView> xView;
560*cdf0e10cSrcweir 
561*cdf0e10cSrcweir     if ( ! mxConfigurationController.is())
562*cdf0e10cSrcweir         return xView;
563*cdf0e10cSrcweir     if ( ! mxComponentContext.is())
564*cdf0e10cSrcweir         return xView;
565*cdf0e10cSrcweir 
566*cdf0e10cSrcweir     try
567*cdf0e10cSrcweir     {
568*cdf0e10cSrcweir         rtl::Reference<PresenterSlideSorter> pView (
569*cdf0e10cSrcweir             new PresenterSlideSorter(
570*cdf0e10cSrcweir                 mxComponentContext,
571*cdf0e10cSrcweir                 rxViewId,
572*cdf0e10cSrcweir                 Reference<frame::XController>(mxControllerWeak),
573*cdf0e10cSrcweir                 mpPresenterController));
574*cdf0e10cSrcweir         PresenterPaneContainer::SharedPaneDescriptor pDescriptor (
575*cdf0e10cSrcweir             mpPresenterController->GetPaneContainer()->FindPaneId(rxViewId->getAnchor()));
576*cdf0e10cSrcweir         if (pDescriptor.get() != NULL)
577*cdf0e10cSrcweir             pDescriptor->maActivator = ::boost::bind(
578*cdf0e10cSrcweir                 &PresenterSlideSorter::SetActiveState, pView.get(), _1);
579*cdf0e10cSrcweir         xView = pView.get();
580*cdf0e10cSrcweir     }
581*cdf0e10cSrcweir     catch (RuntimeException&)
582*cdf0e10cSrcweir     {
583*cdf0e10cSrcweir         xView = NULL;
584*cdf0e10cSrcweir     }
585*cdf0e10cSrcweir 
586*cdf0e10cSrcweir     return xView;
587*cdf0e10cSrcweir }
588*cdf0e10cSrcweir 
589*cdf0e10cSrcweir 
590*cdf0e10cSrcweir 
591*cdf0e10cSrcweir 
592*cdf0e10cSrcweir Reference<XView> PresenterViewFactory::CreateHelpView(
593*cdf0e10cSrcweir     const Reference<XResourceId>& rxViewId) const
594*cdf0e10cSrcweir {
595*cdf0e10cSrcweir     return Reference<XView>(new PresenterHelpView(
596*cdf0e10cSrcweir         mxComponentContext,
597*cdf0e10cSrcweir         rxViewId,
598*cdf0e10cSrcweir         Reference<frame::XController>(mxControllerWeak),
599*cdf0e10cSrcweir         mpPresenterController));
600*cdf0e10cSrcweir }
601*cdf0e10cSrcweir 
602*cdf0e10cSrcweir 
603*cdf0e10cSrcweir 
604*cdf0e10cSrcweir 
605*cdf0e10cSrcweir 
606*cdf0e10cSrcweir void PresenterViewFactory::ThrowIfDisposed (void) const
607*cdf0e10cSrcweir     throw (::com::sun::star::lang::DisposedException)
608*cdf0e10cSrcweir {
609*cdf0e10cSrcweir 	if (rBHelper.bDisposed || rBHelper.bInDispose)
610*cdf0e10cSrcweir 	{
611*cdf0e10cSrcweir         throw lang::DisposedException (
612*cdf0e10cSrcweir             OUString(RTL_CONSTASCII_USTRINGPARAM(
613*cdf0e10cSrcweir                 "PresenterViewFactory object has already been disposed")),
614*cdf0e10cSrcweir             const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
615*cdf0e10cSrcweir     }
616*cdf0e10cSrcweir }
617*cdf0e10cSrcweir 
618*cdf0e10cSrcweir 
619*cdf0e10cSrcweir 
620*cdf0e10cSrcweir 
621*cdf0e10cSrcweir //===== CachablePresenterView =================================================
622*cdf0e10cSrcweir 
623*cdf0e10cSrcweir CachablePresenterView::CachablePresenterView (void)
624*cdf0e10cSrcweir     : mbIsPresenterViewActive(true)
625*cdf0e10cSrcweir {
626*cdf0e10cSrcweir }
627*cdf0e10cSrcweir 
628*cdf0e10cSrcweir 
629*cdf0e10cSrcweir 
630*cdf0e10cSrcweir 
631*cdf0e10cSrcweir void CachablePresenterView::ActivatePresenterView (void)
632*cdf0e10cSrcweir {
633*cdf0e10cSrcweir     mbIsPresenterViewActive = true;
634*cdf0e10cSrcweir }
635*cdf0e10cSrcweir 
636*cdf0e10cSrcweir 
637*cdf0e10cSrcweir 
638*cdf0e10cSrcweir 
639*cdf0e10cSrcweir void CachablePresenterView::DeactivatePresenterView (void)
640*cdf0e10cSrcweir {
641*cdf0e10cSrcweir     mbIsPresenterViewActive = false;
642*cdf0e10cSrcweir }
643*cdf0e10cSrcweir 
644*cdf0e10cSrcweir 
645*cdf0e10cSrcweir 
646*cdf0e10cSrcweir 
647*cdf0e10cSrcweir void CachablePresenterView::ReleaseView (void)
648*cdf0e10cSrcweir {
649*cdf0e10cSrcweir }
650*cdf0e10cSrcweir 
651*cdf0e10cSrcweir 
652*cdf0e10cSrcweir 
653*cdf0e10cSrcweir } }
654