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