Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "PresenterPaneFactory.hxx"
30 : : #include "PresenterController.hxx"
31 : : #include "PresenterPane.hxx"
32 : : #include "PresenterPaneBorderPainter.hxx"
33 : : #include "PresenterPaneContainer.hxx"
34 : : #include "PresenterSpritePane.hxx"
35 : : #include <com/sun/star/container/XChild.hpp>
36 : : #include <com/sun/star/drawing/framework/ResourceId.hpp>
37 : : #include <com/sun/star/drawing/framework/XControllerManager.hpp>
38 : : #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
39 : : #include <com/sun/star/frame/XController.hpp>
40 : : #include <com/sun/star/lang/XComponent.hpp>
41 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 : : #include <boost/bind.hpp>
43 : :
44 : : using namespace ::com::sun::star;
45 : : using namespace ::com::sun::star::uno;
46 : : using namespace ::com::sun::star::lang;
47 : : using namespace ::com::sun::star::drawing::framework;
48 : : using ::rtl::OUString;
49 : :
50 : : namespace sdext { namespace presenter {
51 : :
52 : 8 : const ::rtl::OUString PresenterPaneFactory::msCurrentSlidePreviewPaneURL(
53 : 8 : "private:resource/pane/Presenter/Pane1");
54 : 8 : const ::rtl::OUString PresenterPaneFactory::msNextSlidePreviewPaneURL(
55 : 8 : "private:resource/pane/Presenter/Pane2");
56 : 8 : const ::rtl::OUString PresenterPaneFactory::msNotesPaneURL(
57 : 8 : "private:resource/pane/Presenter/Pane3");
58 : 8 : const ::rtl::OUString PresenterPaneFactory::msToolBarPaneURL(
59 : 8 : "private:resource/pane/Presenter/Pane4");
60 : 8 : const ::rtl::OUString PresenterPaneFactory::msSlideSorterPaneURL(
61 : 8 : "private:resource/pane/Presenter/Pane5");
62 : 8 : const ::rtl::OUString PresenterPaneFactory::msHelpPaneURL(
63 : 8 : "private:resource/pane/Presenter/Pane6");
64 : :
65 : 8 : const ::rtl::OUString PresenterPaneFactory::msOverlayPaneURL(
66 : 8 : "private:resource/pane/Presenter/Overlay");
67 : :
68 : : //===== PresenterPaneFactory ==================================================
69 : :
70 : 0 : Reference<drawing::framework::XResourceFactory> PresenterPaneFactory::Create (
71 : : const Reference<uno::XComponentContext>& rxContext,
72 : : const Reference<frame::XController>& rxController,
73 : : const ::rtl::Reference<PresenterController>& rpPresenterController)
74 : : {
75 : : rtl::Reference<PresenterPaneFactory> pFactory (
76 [ # # ]: 0 : new PresenterPaneFactory(rxContext,rpPresenterController));
77 [ # # ]: 0 : pFactory->Register(rxController);
78 : : return Reference<drawing::framework::XResourceFactory>(
79 [ # # ]: 0 : static_cast<XWeak*>(pFactory.get()), UNO_QUERY);
80 : : }
81 : :
82 : 0 : PresenterPaneFactory::PresenterPaneFactory (
83 : : const Reference<uno::XComponentContext>& rxContext,
84 : : const ::rtl::Reference<PresenterController>& rpPresenterController)
85 : : : PresenterPaneFactoryInterfaceBase(m_aMutex),
86 : : mxComponentContextWeak(rxContext),
87 : : mxConfigurationControllerWeak(),
88 : : mpPresenterController(rpPresenterController),
89 [ # # ][ # # ]: 0 : mpResourceCache()
90 : : {
91 : 0 : }
92 : :
93 : 0 : void PresenterPaneFactory::Register (const Reference<frame::XController>& rxController)
94 : : {
95 : 0 : Reference<XConfigurationController> xCC;
96 : : try
97 : : {
98 : : // Get the configuration controller.
99 [ # # ]: 0 : Reference<XControllerManager> xCM (rxController, UNO_QUERY_THROW);
100 [ # # ][ # # ]: 0 : xCC = Reference<XConfigurationController>(xCM->getConfigurationController());
[ # # ]
101 [ # # ]: 0 : mxConfigurationControllerWeak = xCC;
102 [ # # ]: 0 : if ( ! xCC.is())
103 : : {
104 [ # # ]: 0 : throw RuntimeException();
105 : : }
106 : : else
107 : : {
108 [ # # ]: 0 : xCC->addResourceFactory(
109 : : OUString("private:resource/pane/Presenter/*"),
110 [ # # ][ # # ]: 0 : this);
111 : 0 : }
112 : : }
113 [ # # ]: 0 : catch (RuntimeException&)
114 : : {
115 : : OSL_ASSERT(false);
116 [ # # ]: 0 : if (xCC.is())
117 [ # # # # : 0 : xCC->removeResourceFactoryForReference(this);
# # ]
118 [ # # # # : 0 : mxConfigurationControllerWeak = WeakReference<XConfigurationController>();
# # ]
119 : :
120 : 0 : throw;
121 : 0 : }
122 : 0 : }
123 : :
124 [ # # ][ # # ]: 0 : PresenterPaneFactory::~PresenterPaneFactory (void)
[ # # ][ # # ]
125 : : {
126 [ # # ]: 0 : }
127 : :
128 : 0 : void SAL_CALL PresenterPaneFactory::disposing (void)
129 : : throw (RuntimeException)
130 : : {
131 [ # # ]: 0 : Reference<XConfigurationController> xCC (mxConfigurationControllerWeak);
132 [ # # ]: 0 : if (xCC.is())
133 [ # # ][ # # ]: 0 : xCC->removeResourceFactoryForReference(this);
[ # # ]
134 [ # # ][ # # ]: 0 : mxConfigurationControllerWeak = WeakReference<XConfigurationController>();
[ # # ]
135 : :
136 : : // Dispose the panes in the cache.
137 [ # # ]: 0 : if (mpResourceCache.get() != NULL)
138 : : {
139 : 0 : ResourceContainer::const_iterator iPane (mpResourceCache->begin());
140 : 0 : ResourceContainer::const_iterator iEnd (mpResourceCache->end());
141 [ # # ]: 0 : for ( ; iPane!=iEnd; ++iPane)
142 : : {
143 [ # # ]: 0 : Reference<lang::XComponent> xPaneComponent (iPane->second, UNO_QUERY);
144 [ # # ]: 0 : if (xPaneComponent.is())
145 [ # # ][ # # ]: 0 : xPaneComponent->dispose();
146 : 0 : }
147 [ # # ]: 0 : mpResourceCache.reset();
148 : 0 : }
149 : 0 : }
150 : :
151 : : //----- XPaneFactory ----------------------------------------------------------
152 : :
153 : 0 : Reference<XResource> SAL_CALL PresenterPaneFactory::createResource (
154 : : const Reference<XResourceId>& rxPaneId)
155 : : throw (RuntimeException, IllegalArgumentException, WrappedTargetException)
156 : : {
157 [ # # ]: 0 : ThrowIfDisposed();
158 : :
159 [ # # ]: 0 : if ( ! rxPaneId.is())
160 [ # # ]: 0 : return NULL;
161 : :
162 [ # # ][ # # ]: 0 : const OUString sPaneURL (rxPaneId->getResourceURL());
163 [ # # ]: 0 : if (sPaneURL.isEmpty())
164 [ # # ]: 0 : return NULL;
165 : :
166 [ # # ]: 0 : if (mpResourceCache.get() != NULL)
167 : : {
168 : : // Has the requested resource already been created?
169 [ # # ]: 0 : ResourceContainer::const_iterator iResource (mpResourceCache->find(sPaneURL));
170 [ # # ]: 0 : if (iResource != mpResourceCache->end())
171 : : {
172 : : // Yes. Mark it as active.
173 : : rtl::Reference<PresenterPaneContainer> pPaneContainer(
174 [ # # ]: 0 : mpPresenterController->GetPaneContainer());
175 : : PresenterPaneContainer::SharedPaneDescriptor pDescriptor (
176 [ # # ]: 0 : pPaneContainer->FindPaneURL(sPaneURL));
177 [ # # ]: 0 : if (pDescriptor.get() != NULL)
178 : : {
179 [ # # ]: 0 : pDescriptor->SetActivationState(true);
180 [ # # ]: 0 : if (pDescriptor->mxBorderWindow.is())
181 [ # # ][ # # ]: 0 : pDescriptor->mxBorderWindow->setVisible(sal_True);
182 [ # # ][ # # ]: 0 : pPaneContainer->StorePane(pDescriptor->mxPane);
183 : : }
184 : :
185 [ # # ]: 0 : return iResource->second;
186 : : }
187 : : }
188 : :
189 : : // No. Create a new one.
190 [ # # ]: 0 : Reference<XResource> xResource = CreatePane(rxPaneId, OUString());
191 : 0 : return xResource;
192 : : }
193 : :
194 : 0 : void SAL_CALL PresenterPaneFactory::releaseResource (const Reference<XResource>& rxResource)
195 : : throw (RuntimeException)
196 : : {
197 [ # # ]: 0 : ThrowIfDisposed();
198 : :
199 [ # # ]: 0 : if ( ! rxResource.is())
200 [ # # ]: 0 : throw lang::IllegalArgumentException();
201 : :
202 : : // Mark the pane as inactive.
203 : : rtl::Reference<PresenterPaneContainer> pPaneContainer(
204 [ # # ]: 0 : mpPresenterController->GetPaneContainer());
205 [ # # ][ # # ]: 0 : const OUString sPaneURL (rxResource->getResourceId()->getResourceURL());
[ # # ][ # # ]
206 : : PresenterPaneContainer::SharedPaneDescriptor pDescriptor (
207 [ # # ]: 0 : pPaneContainer->FindPaneURL(sPaneURL));
208 [ # # ]: 0 : if (pDescriptor.get() != NULL)
209 : : {
210 [ # # ]: 0 : pDescriptor->SetActivationState(false);
211 [ # # ]: 0 : if (pDescriptor->mxBorderWindow.is())
212 [ # # ][ # # ]: 0 : pDescriptor->mxBorderWindow->setVisible(sal_False);
213 : :
214 [ # # ]: 0 : if (mpResourceCache.get() != NULL)
215 : : {
216 : : // Store the pane in the cache.
217 [ # # ][ # # ]: 0 : (*mpResourceCache)[sPaneURL] = rxResource;
218 : : }
219 : : else
220 : : {
221 : : // Dispose the pane.
222 [ # # ]: 0 : Reference<lang::XComponent> xPaneComponent (rxResource, UNO_QUERY);
223 [ # # ]: 0 : if (xPaneComponent.is())
224 [ # # ][ # # ]: 0 : xPaneComponent->dispose();
225 : : }
226 [ # # ]: 0 : }
227 : 0 : }
228 : :
229 : : //-----------------------------------------------------------------------------
230 : :
231 : 0 : Reference<XResource> PresenterPaneFactory::CreatePane (
232 : : const Reference<XResourceId>& rxPaneId,
233 : : const OUString& rsTitle)
234 : : {
235 [ # # ]: 0 : if ( ! rxPaneId.is())
236 [ # # ]: 0 : return NULL;
237 : :
238 [ # # ]: 0 : Reference<XConfigurationController> xCC (mxConfigurationControllerWeak);
239 [ # # ]: 0 : if ( ! xCC.is())
240 [ # # ]: 0 : return NULL;
241 : :
242 [ # # ]: 0 : Reference<XComponentContext> xContext (mxComponentContextWeak);
243 [ # # ]: 0 : if ( ! xContext.is())
244 [ # # ]: 0 : return NULL;
245 : :
246 [ # # ][ # # ]: 0 : Reference<XPane> xParentPane (xCC->getResource(rxPaneId->getAnchor()), UNO_QUERY);
[ # # ][ # # ]
[ # # ]
247 [ # # ]: 0 : if ( ! xParentPane.is())
248 [ # # ]: 0 : return NULL;
249 : :
250 : : try
251 : : {
252 : : return CreatePane(
253 : : rxPaneId,
254 : : rsTitle,
255 : : xParentPane,
256 [ # # ][ # # ]: 0 : rxPaneId->getFullResourceURL().Arguments.compareToAscii("Sprite=1") == 0);
[ # # ][ # # ]
257 : : }
258 [ # # ]: 0 : catch (Exception&)
259 : : {
260 : : OSL_ASSERT(false);
261 : : }
262 : :
263 [ # # ]: 0 : return NULL;
264 : : }
265 : :
266 : 0 : Reference<XResource> PresenterPaneFactory::CreatePane (
267 : : const Reference<XResourceId>& rxPaneId,
268 : : const OUString& rsTitle,
269 : : const Reference<drawing::framework::XPane>& rxParentPane,
270 : : const bool bIsSpritePane)
271 : : {
272 [ # # ]: 0 : Reference<XComponentContext> xContext (mxComponentContextWeak);
273 : : Reference<lang::XMultiComponentFactory> xFactory (
274 [ # # ][ # # ]: 0 : xContext->getServiceManager(), UNO_QUERY_THROW);
[ # # ]
275 : :
276 : : // Create a border window and canvas and store it in the pane
277 : : // container.
278 : :
279 : : // Create the pane.
280 : 0 : ::rtl::Reference<PresenterPaneBase> xPane;
281 [ # # ]: 0 : if (bIsSpritePane)
282 : : {
283 : : xPane = ::rtl::Reference<PresenterPaneBase>(
284 [ # # ][ # # ]: 0 : new PresenterSpritePane(xContext, mpPresenterController));
285 : : }
286 : : else
287 : : {
288 : : xPane = ::rtl::Reference<PresenterPaneBase>(
289 [ # # ][ # # ]: 0 : new PresenterPane(xContext, mpPresenterController));
290 : : }
291 : :
292 : : // Supply arguments.
293 [ # # ]: 0 : Sequence<Any> aArguments (6);
294 [ # # ][ # # ]: 0 : aArguments[0] <<= rxPaneId;
295 [ # # ][ # # ]: 0 : aArguments[1] <<= rxParentPane->getWindow();
[ # # ][ # # ]
296 [ # # ][ # # ]: 0 : aArguments[2] <<= rxParentPane->getCanvas();
[ # # ][ # # ]
297 [ # # ][ # # ]: 0 : aArguments[3] <<= rsTitle;
298 [ # # ]: 0 : aArguments[4] <<= Reference<drawing::framework::XPaneBorderPainter>(
299 [ # # ]: 0 : static_cast<XWeak*>(mpPresenterController->GetPaneBorderPainter().get()),
300 [ # # ][ # # ]: 0 : UNO_QUERY);
301 [ # # ][ # # ]: 0 : aArguments[5] <<= bIsSpritePane ? false : true;
[ # # ]
302 [ # # ]: 0 : xPane->initialize(aArguments);
303 : :
304 : : // Store pane and canvases and windows in container.
305 : : ::rtl::Reference<PresenterPaneContainer> pContainer (
306 [ # # ]: 0 : mpPresenterController->GetPaneContainer());
307 : : PresenterPaneContainer::SharedPaneDescriptor pDescriptor(
308 [ # # ][ # # ]: 0 : pContainer->StoreBorderWindow(rxPaneId, xPane->GetBorderWindow()));
309 [ # # ][ # # ]: 0 : pContainer->StorePane(xPane);
310 [ # # ]: 0 : if (pDescriptor.get() != NULL)
311 : : {
312 [ # # ]: 0 : if (bIsSpritePane)
313 : : {
314 : 0 : pDescriptor->maSpriteProvider = ::boost::bind(
315 : : &PresenterSpritePane::GetSprite,
316 [ # # ]: 0 : dynamic_cast<PresenterSpritePane*>(xPane.get()));
[ # # # # ]
317 : 0 : pDescriptor->mbIsSprite = true;
318 : 0 : pDescriptor->mbNeedsClipping = false;
319 : : }
320 : : else
321 : : {
322 : 0 : pDescriptor->mbIsSprite = false;
323 : 0 : pDescriptor->mbNeedsClipping = true;
324 : : }
325 : :
326 : : // Get the window of the frame and make that visible.
327 [ # # ]: 0 : Reference<awt::XWindow> xWindow (pDescriptor->mxBorderWindow, UNO_QUERY_THROW);
328 [ # # ][ # # ]: 0 : xWindow->setVisible(sal_True);
329 : : }
330 : :
331 [ # # ][ # # ]: 0 : return Reference<XResource>(static_cast<XWeak*>(xPane.get()), UNO_QUERY_THROW);
[ # # ]
332 : : }
333 : :
334 : 0 : void PresenterPaneFactory::ThrowIfDisposed (void) const
335 : : throw (::com::sun::star::lang::DisposedException)
336 : : {
337 [ # # ][ # # ]: 0 : if (rBHelper.bDisposed || rBHelper.bInDispose)
338 : : {
339 : : throw lang::DisposedException (
340 : : OUString( "PresenterPaneFactory object has already been disposed"),
341 [ # # ][ # # ]: 0 : const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
342 : : }
343 : 0 : }
344 : :
345 [ + - ][ + - ]: 24 : } } // end of namespace sdext::presenter
346 : :
347 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|