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