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