LibreOffice Module sd (master) 1
PresenterPaneFactory.cxx
Go to the documentation of this file.
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
22#include "PresenterPane.hxx"
26#include <DrawController.hxx>
27#include <com/sun/star/lang/XComponent.hpp>
28#include <utility>
29
30using namespace ::com::sun::star;
31using namespace ::com::sun::star::uno;
32using namespace ::com::sun::star::lang;
34
35namespace sdext::presenter {
36
37//===== PresenterPaneFactory ==================================================
38
39Reference<drawing::framework::XResourceFactory> PresenterPaneFactory::Create (
40 const Reference<uno::XComponentContext>& rxContext,
41 const rtl::Reference<::sd::DrawController>& rxController,
42 const ::rtl::Reference<PresenterController>& rpPresenterController)
43{
45 new PresenterPaneFactory(rxContext,rpPresenterController));
46 pFactory->Register(rxController);
47 return Reference<drawing::framework::XResourceFactory>(pFactory);
48}
49
51 const Reference<uno::XComponentContext>& rxContext,
52 ::rtl::Reference<PresenterController> xPresenterController)
54 mxComponentContextWeak(rxContext),
55 mpPresenterController(std::move(xPresenterController))
56{
57}
58
60{
61 Reference<XConfigurationController> xCC;
62 try
63 {
64 // Get the configuration controller.
65 xCC.set(rxController->getConfigurationController());
67 if ( ! xCC.is())
68 {
69 throw RuntimeException();
70 }
71 xCC->addResourceFactory(
72 "private:resource/pane/Presenter/*",
73 this);
74 }
75 catch (RuntimeException&)
76 {
77 OSL_ASSERT(false);
78 if (xCC.is())
79 xCC->removeResourceFactoryForReference(this);
80 mxConfigurationControllerWeak = WeakReference<XConfigurationController>();
81
82 throw;
83 }
84}
85
87{
88}
89
91{
92 Reference<XConfigurationController> xCC (mxConfigurationControllerWeak);
93 if (xCC.is())
94 xCC->removeResourceFactoryForReference(this);
95 mxConfigurationControllerWeak = WeakReference<XConfigurationController>();
96
97 // Dispose the panes in the cache.
98 if (mpResourceCache != nullptr)
99 {
100 for (const auto& rxPane : *mpResourceCache)
101 {
102 Reference<lang::XComponent> xPaneComponent (rxPane.second, UNO_QUERY);
103 if (xPaneComponent.is())
104 xPaneComponent->dispose();
105 }
106 mpResourceCache.reset();
107 }
108}
109
110//----- XPaneFactory ----------------------------------------------------------
111
112Reference<XResource> SAL_CALL PresenterPaneFactory::createResource (
113 const Reference<XResourceId>& rxPaneId)
114{
116
117 if ( ! rxPaneId.is())
118 return nullptr;
119
120 const OUString sPaneURL (rxPaneId->getResourceURL());
121 if (sPaneURL.isEmpty())
122 return nullptr;
123
124 if (mpResourceCache != nullptr)
125 {
126 // Has the requested resource already been created?
127 ResourceContainer::const_iterator iResource (mpResourceCache->find(sPaneURL));
128 if (iResource != mpResourceCache->end())
129 {
130 // Yes. Mark it as active.
132 mpPresenterController->GetPaneContainer());
134 pPaneContainer->FindPaneURL(sPaneURL));
135 if (pDescriptor)
136 {
137 pDescriptor->SetActivationState(true);
138 if (pDescriptor->mxBorderWindow.is())
139 pDescriptor->mxBorderWindow->setVisible(true);
140 pPaneContainer->StorePane(pDescriptor->mxPane);
141 }
142
143 return iResource->second;
144 }
145 }
146
147 // No. Create a new one.
148 Reference<XResource> xResource = CreatePane(rxPaneId);
149 return xResource;
150}
151
152void SAL_CALL PresenterPaneFactory::releaseResource (const Reference<XResource>& rxResource)
153{
155
156 if ( ! rxResource.is())
157 throw lang::IllegalArgumentException();
158
159 // Mark the pane as inactive.
161 mpPresenterController->GetPaneContainer());
162 const OUString sPaneURL (rxResource->getResourceId()->getResourceURL());
164 pPaneContainer->FindPaneURL(sPaneURL));
165 if (!pDescriptor)
166 return;
167
168 pDescriptor->SetActivationState(false);
169 if (pDescriptor->mxBorderWindow.is())
170 pDescriptor->mxBorderWindow->setVisible(false);
171
172 if (mpResourceCache != nullptr)
173 {
174 // Store the pane in the cache.
175 (*mpResourceCache)[sPaneURL] = rxResource;
176 }
177 else
178 {
179 // Dispose the pane.
180 Reference<lang::XComponent> xPaneComponent (rxResource, UNO_QUERY);
181 if (xPaneComponent.is())
182 xPaneComponent->dispose();
183 }
184}
185
186
187Reference<XResource> PresenterPaneFactory::CreatePane (
188 const Reference<XResourceId>& rxPaneId)
189{
190 if ( ! rxPaneId.is())
191 return nullptr;
192
193 Reference<XConfigurationController> xCC (mxConfigurationControllerWeak);
194 if ( ! xCC.is())
195 return nullptr;
196
197 Reference<XComponentContext> xContext (mxComponentContextWeak);
198 if ( ! xContext.is())
199 return nullptr;
200
201 Reference<XPane> xParentPane (xCC->getResource(rxPaneId->getAnchor()), UNO_QUERY);
202 if ( ! xParentPane.is())
203 return nullptr;
204
205 try
206 {
207 return CreatePane(
208 rxPaneId,
209 xParentPane,
210 rxPaneId->getFullResourceURL().Arguments == "Sprite=1");
211 }
212 catch (Exception&)
213 {
214 OSL_ASSERT(false);
215 }
216
217 return nullptr;
218}
219
220Reference<XResource> PresenterPaneFactory::CreatePane (
221 const Reference<XResourceId>& rxPaneId,
222 const Reference<drawing::framework::XPane>& rxParentPane,
223 const bool bIsSpritePane)
224{
225 Reference<XComponentContext> xContext (mxComponentContextWeak);
226 Reference<lang::XMultiComponentFactory> xFactory (
227 xContext->getServiceManager(), UNO_SET_THROW);
228
229 // Create a border window and canvas and store it in the pane
230 // container.
231
232 // Create the pane.
234 if (bIsSpritePane)
235 {
236 xPane.set( new PresenterSpritePane(xContext, mpPresenterController));
237 }
238 else
239 {
240 xPane.set( new PresenterPane(xContext, mpPresenterController));
241 }
242
243 // Supply arguments.
244 Sequence<Any> aArguments{ Any(rxPaneId),
245 Any(rxParentPane->getWindow()),
246 Any(rxParentPane->getCanvas()),
247 Any(OUString()),
248 Any(Reference<drawing::framework::XPaneBorderPainter>(
249 mpPresenterController->GetPaneBorderPainter())),
250 Any(!bIsSpritePane) };
251 xPane->initialize(aArguments);
252
253 // Store pane and canvases and windows in container.
255 mpPresenterController->GetPaneContainer());
257 pContainer->StoreBorderWindow(rxPaneId, xPane->GetBorderWindow()));
258 pContainer->StorePane(xPane);
259 if (pDescriptor)
260 {
261 pDescriptor->mbIsSprite = bIsSpritePane;
262
263 // Get the window of the frame and make that visible.
264 Reference<awt::XWindow> xWindow (pDescriptor->mxBorderWindow, UNO_SET_THROW);
265 xWindow->setVisible(true);
266 }
267
268 return Reference<XResource>(static_cast<XWeak*>(xPane.get()), UNO_QUERY_THROW);
269}
270
272{
273 if (rBHelper.bDisposed || rBHelper.bInDispose)
274 {
275 throw lang::DisposedException (
276 "PresenterPaneFactory object has already been disposed",
277 const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
278 }
279}
280
281} // end of namespace sdext::presenter
282
283/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
rtl::Reference< PresenterController > mpPresenterController
std::shared_ptr< PaneDescriptor > SharedPaneDescriptor
virtual void SAL_CALL disposing() override
void Register(const rtl::Reference<::sd::DrawController > &rxController)
std::unique_ptr< ResourceContainer > mpResourceCache
virtual css::uno::Reference< css::drawing::framework::XResource > SAL_CALL createResource(const css::uno::Reference< css::drawing::framework::XResourceId > &rxPaneId) override
virtual void SAL_CALL releaseResource(const css::uno::Reference< css::drawing::framework::XResource > &rxPane) override
::rtl::Reference< PresenterController > mpPresenterController
css::uno::WeakReference< css::uno::XComponentContext > mxComponentContextWeak
css::uno::Reference< css::drawing::framework::XResource > CreatePane(const css::uno::Reference< css::drawing::framework::XResourceId > &rxPaneId)
static css::uno::Reference< css::drawing::framework::XResourceFactory > Create(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const rtl::Reference<::sd::DrawController > &rxController, const ::rtl::Reference< PresenterController > &rpPresenterController)
Create a new instance of this class and register it as resource factory in the drawing framework of t...
css::uno::WeakReference< css::drawing::framework::XConfigurationController > mxConfigurationControllerWeak
PresenterPaneFactory(const css::uno::Reference< css::uno::XComponentContext > &rxContext, ::rtl::Reference< PresenterController > xPresenterController)
Reference< XSingleServiceFactory > xFactory
std::mutex m_aMutex
Sequence< PropertyValue > aArguments
::cppu::WeakComponentImplHelper< css::drawing::framework::XResourceFactory > PresenterPaneFactoryInterfaceBase