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