1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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/drawing/framework/XControllerManager.hpp>
27 #include <com/sun/star/lang/XComponent.hpp>
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
;
34 namespace sdext::presenter
{
36 //===== PresenterPaneFactory ==================================================
38 Reference
<drawing::framework::XResourceFactory
> PresenterPaneFactory::Create (
39 const Reference
<uno::XComponentContext
>& rxContext
,
40 const Reference
<frame::XController
>& rxController
,
41 const ::rtl::Reference
<PresenterController
>& rpPresenterController
)
43 rtl::Reference
<PresenterPaneFactory
> pFactory (
44 new PresenterPaneFactory(rxContext
,rpPresenterController
));
45 pFactory
->Register(rxController
);
46 return Reference
<drawing::framework::XResourceFactory
>(
47 static_cast<XWeak
*>(pFactory
.get()), UNO_QUERY
);
50 PresenterPaneFactory::PresenterPaneFactory (
51 const Reference
<uno::XComponentContext
>& rxContext
,
52 const ::rtl::Reference
<PresenterController
>& rpPresenterController
)
53 : PresenterPaneFactoryInterfaceBase(m_aMutex
),
54 mxComponentContextWeak(rxContext
),
55 mxConfigurationControllerWeak(),
56 mpPresenterController(rpPresenterController
),
61 void PresenterPaneFactory::Register (const Reference
<frame::XController
>& rxController
)
63 Reference
<XConfigurationController
> xCC
;
66 // Get the configuration controller.
67 Reference
<XControllerManager
> xCM (rxController
, UNO_QUERY_THROW
);
68 xCC
.set(xCM
->getConfigurationController());
69 mxConfigurationControllerWeak
= xCC
;
72 throw RuntimeException();
74 xCC
->addResourceFactory(
75 "private:resource/pane/Presenter/*",
78 catch (RuntimeException
&)
82 xCC
->removeResourceFactoryForReference(this);
83 mxConfigurationControllerWeak
= WeakReference
<XConfigurationController
>();
89 PresenterPaneFactory::~PresenterPaneFactory()
93 void SAL_CALL
PresenterPaneFactory::disposing()
95 Reference
<XConfigurationController
> xCC (mxConfigurationControllerWeak
);
97 xCC
->removeResourceFactoryForReference(this);
98 mxConfigurationControllerWeak
= WeakReference
<XConfigurationController
>();
100 // Dispose the panes in the cache.
101 if (mpResourceCache
!= nullptr)
103 for (const auto& rxPane
: *mpResourceCache
)
105 Reference
<lang::XComponent
> xPaneComponent (rxPane
.second
, UNO_QUERY
);
106 if (xPaneComponent
.is())
107 xPaneComponent
->dispose();
109 mpResourceCache
.reset();
113 //----- XPaneFactory ----------------------------------------------------------
115 Reference
<XResource
> SAL_CALL
PresenterPaneFactory::createResource (
116 const Reference
<XResourceId
>& rxPaneId
)
120 if ( ! rxPaneId
.is())
123 const OUString
sPaneURL (rxPaneId
->getResourceURL());
124 if (sPaneURL
.isEmpty())
127 if (mpResourceCache
!= nullptr)
129 // Has the requested resource already been created?
130 ResourceContainer::const_iterator
iResource (mpResourceCache
->find(sPaneURL
));
131 if (iResource
!= mpResourceCache
->end())
133 // Yes. Mark it as active.
134 rtl::Reference
<PresenterPaneContainer
> pPaneContainer(
135 mpPresenterController
->GetPaneContainer());
136 PresenterPaneContainer::SharedPaneDescriptor
pDescriptor (
137 pPaneContainer
->FindPaneURL(sPaneURL
));
140 pDescriptor
->SetActivationState(true);
141 if (pDescriptor
->mxBorderWindow
.is())
142 pDescriptor
->mxBorderWindow
->setVisible(true);
143 pPaneContainer
->StorePane(pDescriptor
->mxPane
);
146 return iResource
->second
;
150 // No. Create a new one.
151 Reference
<XResource
> xResource
= CreatePane(rxPaneId
);
155 void SAL_CALL
PresenterPaneFactory::releaseResource (const Reference
<XResource
>& rxResource
)
159 if ( ! rxResource
.is())
160 throw lang::IllegalArgumentException();
162 // Mark the pane as inactive.
163 rtl::Reference
<PresenterPaneContainer
> pPaneContainer(
164 mpPresenterController
->GetPaneContainer());
165 const OUString
sPaneURL (rxResource
->getResourceId()->getResourceURL());
166 PresenterPaneContainer::SharedPaneDescriptor
pDescriptor (
167 pPaneContainer
->FindPaneURL(sPaneURL
));
171 pDescriptor
->SetActivationState(false);
172 if (pDescriptor
->mxBorderWindow
.is())
173 pDescriptor
->mxBorderWindow
->setVisible(false);
175 if (mpResourceCache
!= nullptr)
177 // Store the pane in the cache.
178 (*mpResourceCache
)[sPaneURL
] = rxResource
;
183 Reference
<lang::XComponent
> xPaneComponent (rxResource
, UNO_QUERY
);
184 if (xPaneComponent
.is())
185 xPaneComponent
->dispose();
190 Reference
<XResource
> PresenterPaneFactory::CreatePane (
191 const Reference
<XResourceId
>& rxPaneId
)
193 if ( ! rxPaneId
.is())
196 Reference
<XConfigurationController
> xCC (mxConfigurationControllerWeak
);
200 Reference
<XComponentContext
> xContext (mxComponentContextWeak
);
201 if ( ! xContext
.is())
204 Reference
<XPane
> xParentPane (xCC
->getResource(rxPaneId
->getAnchor()), UNO_QUERY
);
205 if ( ! xParentPane
.is())
213 rxPaneId
->getFullResourceURL().Arguments
== "Sprite=1");
223 Reference
<XResource
> PresenterPaneFactory::CreatePane (
224 const Reference
<XResourceId
>& rxPaneId
,
225 const Reference
<drawing::framework::XPane
>& rxParentPane
,
226 const bool bIsSpritePane
)
228 Reference
<XComponentContext
> xContext (mxComponentContextWeak
);
229 Reference
<lang::XMultiComponentFactory
> xFactory (
230 xContext
->getServiceManager(), UNO_SET_THROW
);
232 // Create a border window and canvas and store it in the pane
236 ::rtl::Reference
<PresenterPaneBase
> xPane
;
239 xPane
.set( new PresenterSpritePane(xContext
, mpPresenterController
));
243 xPane
.set( new PresenterPane(xContext
, mpPresenterController
));
247 Sequence
<Any
> aArguments (6);
248 aArguments
[0] <<= rxPaneId
;
249 aArguments
[1] <<= rxParentPane
->getWindow();
250 aArguments
[2] <<= rxParentPane
->getCanvas();
251 aArguments
[3] <<= OUString();
252 aArguments
[4] <<= Reference
<drawing::framework::XPaneBorderPainter
>(
253 static_cast<XWeak
*>(mpPresenterController
->GetPaneBorderPainter().get()),
255 aArguments
[5] <<= !bIsSpritePane
;
256 xPane
->initialize(aArguments
);
258 // Store pane and canvases and windows in container.
259 ::rtl::Reference
<PresenterPaneContainer
> pContainer (
260 mpPresenterController
->GetPaneContainer());
261 PresenterPaneContainer::SharedPaneDescriptor
pDescriptor(
262 pContainer
->StoreBorderWindow(rxPaneId
, xPane
->GetBorderWindow()));
263 pContainer
->StorePane(xPane
);
266 pDescriptor
->mbIsSprite
= bIsSpritePane
;
268 // Get the window of the frame and make that visible.
269 Reference
<awt::XWindow
> xWindow (pDescriptor
->mxBorderWindow
, UNO_SET_THROW
);
270 xWindow
->setVisible(true);
273 return Reference
<XResource
>(static_cast<XWeak
*>(xPane
.get()), UNO_QUERY_THROW
);
276 void PresenterPaneFactory::ThrowIfDisposed() const
278 if (rBHelper
.bDisposed
|| rBHelper
.bInDispose
)
280 throw lang::DisposedException (
281 "PresenterPaneFactory object has already been disposed",
282 const_cast<uno::XWeak
*>(static_cast<const uno::XWeak
*>(this)));
286 } // end of namespace sdext::presenter
288 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */