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