1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PresenterPaneFactory.cxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sdext.hxx"
35 #include "PresenterPaneFactory.hxx"
36 #include "PresenterController.hxx"
37 #include "PresenterPane.hxx"
38 #include "PresenterPaneBorderPainter.hxx"
39 #include "PresenterPaneContainer.hxx"
40 #include "PresenterSpritePane.hxx"
41 #include <com/sun/star/container/XChild.hpp>
42 #include <com/sun/star/drawing/framework/ResourceId.hpp>
43 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
44 #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
45 #include <com/sun/star/frame/XController.hpp>
46 #include <com/sun/star/lang/XComponent.hpp>
47 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
48 #include <boost/bind.hpp>
50 using namespace ::com::sun::star
;
51 using namespace ::com::sun::star::uno
;
52 using namespace ::com::sun::star::drawing::framework
;
53 using ::rtl::OUString
;
55 namespace sdext
{ namespace presenter
{
57 const ::rtl::OUString
PresenterPaneFactory::msCurrentSlidePreviewPaneURL(
58 OUString::createFromAscii("private:resource/pane/Presenter/Pane1"));
59 const ::rtl::OUString
PresenterPaneFactory::msNextSlidePreviewPaneURL(
60 OUString::createFromAscii("private:resource/pane/Presenter/Pane2"));
61 const ::rtl::OUString
PresenterPaneFactory::msNotesPaneURL(
62 OUString::createFromAscii("private:resource/pane/Presenter/Pane3"));
63 const ::rtl::OUString
PresenterPaneFactory::msToolBarPaneURL(
64 OUString::createFromAscii("private:resource/pane/Presenter/Pane4"));
65 const ::rtl::OUString
PresenterPaneFactory::msSlideSorterPaneURL(
66 OUString::createFromAscii("private:resource/pane/Presenter/Pane5"));
67 const ::rtl::OUString
PresenterPaneFactory::msHelpPaneURL(
68 OUString::createFromAscii("private:resource/pane/Presenter/Pane6"));
70 const ::rtl::OUString
PresenterPaneFactory::msOverlayPaneURL(
71 OUString::createFromAscii("private:resource/pane/Presenter/Overlay"));
75 //===== PresenterPaneFactory ==================================================
77 Reference
<drawing::framework::XResourceFactory
> PresenterPaneFactory::Create (
78 const Reference
<uno::XComponentContext
>& rxContext
,
79 const Reference
<frame::XController
>& rxController
,
80 const ::rtl::Reference
<PresenterController
>& rpPresenterController
)
82 rtl::Reference
<PresenterPaneFactory
> pFactory (
83 new PresenterPaneFactory(rxContext
,rpPresenterController
));
84 pFactory
->Register(rxController
);
85 return Reference
<drawing::framework::XResourceFactory
>(
86 static_cast<XWeak
*>(pFactory
.get()), UNO_QUERY
);
92 PresenterPaneFactory::PresenterPaneFactory (
93 const Reference
<uno::XComponentContext
>& rxContext
,
94 const ::rtl::Reference
<PresenterController
>& rpPresenterController
)
95 : PresenterPaneFactoryInterfaceBase(m_aMutex
),
96 mxComponentContextWeak(rxContext
),
97 mxConfigurationControllerWeak(),
98 mpPresenterController(rpPresenterController
),
106 void PresenterPaneFactory::Register (const Reference
<frame::XController
>& rxController
)
108 Reference
<XConfigurationController
> xCC
;
111 // Get the configuration controller.
112 Reference
<XControllerManager
> xCM (rxController
, UNO_QUERY_THROW
);
113 xCC
= Reference
<XConfigurationController
>(xCM
->getConfigurationController());
114 mxConfigurationControllerWeak
= xCC
;
117 throw RuntimeException();
121 xCC
->addResourceFactory(
122 OUString::createFromAscii("private:resource/pane/Presenter/*"),
126 catch (RuntimeException
&)
130 xCC
->removeResourceFactoryForReference(this);
131 mxConfigurationControllerWeak
= WeakReference
<XConfigurationController
>();
140 PresenterPaneFactory::~PresenterPaneFactory (void)
147 void SAL_CALL
PresenterPaneFactory::disposing (void)
148 throw (RuntimeException
)
150 Reference
<XConfigurationController
> xCC (mxConfigurationControllerWeak
);
152 xCC
->removeResourceFactoryForReference(this);
153 mxConfigurationControllerWeak
= WeakReference
<XConfigurationController
>();
155 // Dispose the panes in the cache.
156 if (mpResourceCache
.get() != NULL
)
158 ResourceContainer::const_iterator
iPane (mpResourceCache
->begin());
159 ResourceContainer::const_iterator
iEnd (mpResourceCache
->end());
160 for ( ; iPane
!=iEnd
; ++iPane
)
162 Reference
<lang::XComponent
> xPaneComponent (iPane
->second
, UNO_QUERY
);
163 if (xPaneComponent
.is())
164 xPaneComponent
->dispose();
166 mpResourceCache
.reset();
173 //----- XPaneFactory ----------------------------------------------------------
175 Reference
<XResource
> SAL_CALL
PresenterPaneFactory::createResource (
176 const Reference
<XResourceId
>& rxPaneId
)
177 throw (RuntimeException
)
181 if ( ! rxPaneId
.is())
184 const OUString
sPaneURL (rxPaneId
->getResourceURL());
185 if (sPaneURL
.getLength() == 0)
188 if (mpResourceCache
.get() != NULL
)
190 // Has the requested resource already been created?
191 ResourceContainer::const_iterator
iResource (mpResourceCache
->find(sPaneURL
));
192 if (iResource
!= mpResourceCache
->end())
194 // Yes. Mark it as active.
195 rtl::Reference
<PresenterPaneContainer
> pPaneContainer(
196 mpPresenterController
->GetPaneContainer());
197 PresenterPaneContainer::SharedPaneDescriptor
pDescriptor (
198 pPaneContainer
->FindPaneURL(sPaneURL
));
199 if (pDescriptor
.get() != NULL
)
201 pDescriptor
->SetActivationState(true);
202 if (pDescriptor
->mxBorderWindow
.is())
203 pDescriptor
->mxBorderWindow
->setVisible(sal_True
);
204 pPaneContainer
->StorePane(pDescriptor
->mxPane
);
207 return iResource
->second
;
211 // No. Create a new one.
212 Reference
<XResource
> xResource
= CreatePane(rxPaneId
, OUString());
219 void SAL_CALL
PresenterPaneFactory::releaseResource (const Reference
<XResource
>& rxResource
)
220 throw (RuntimeException
)
224 if ( ! rxResource
.is())
225 throw lang::IllegalArgumentException();
227 // Mark the pane as inactive.
228 rtl::Reference
<PresenterPaneContainer
> pPaneContainer(
229 mpPresenterController
->GetPaneContainer());
230 const OUString
sPaneURL (rxResource
->getResourceId()->getResourceURL());
231 PresenterPaneContainer::SharedPaneDescriptor
pDescriptor (
232 pPaneContainer
->FindPaneURL(sPaneURL
));
233 if (pDescriptor
.get() != NULL
)
235 pDescriptor
->SetActivationState(false);
236 if (pDescriptor
->mxBorderWindow
.is())
237 pDescriptor
->mxBorderWindow
->setVisible(sal_False
);
239 if (mpResourceCache
.get() != NULL
)
241 // Store the pane in the cache.
242 (*mpResourceCache
)[sPaneURL
] = rxResource
;
247 Reference
<lang::XComponent
> xPaneComponent (rxResource
, UNO_QUERY
);
248 if (xPaneComponent
.is())
249 xPaneComponent
->dispose();
257 //-----------------------------------------------------------------------------
259 Reference
<XResource
> PresenterPaneFactory::CreatePane (
260 const Reference
<XResourceId
>& rxPaneId
,
261 const OUString
& rsTitle
)
263 if ( ! rxPaneId
.is())
266 Reference
<XConfigurationController
> xCC (mxConfigurationControllerWeak
);
270 Reference
<XComponentContext
> xContext (mxComponentContextWeak
);
271 if ( ! xContext
.is())
274 Reference
<XPane
> xParentPane (xCC
->getResource(rxPaneId
->getAnchor()), UNO_QUERY
);
275 if ( ! xParentPane
.is())
284 rxPaneId
->getFullResourceURL().Arguments
.compareToAscii("Sprite=1") == 0);
297 Reference
<XResource
> PresenterPaneFactory::CreatePane (
298 const Reference
<XResourceId
>& rxPaneId
,
299 const OUString
& rsTitle
,
300 const Reference
<drawing::framework::XPane
>& rxParentPane
,
301 const bool bIsSpritePane
)
303 Reference
<XComponentContext
> xContext (mxComponentContextWeak
);
304 Reference
<lang::XMultiComponentFactory
> xFactory (
305 xContext
->getServiceManager(), UNO_QUERY_THROW
);
307 // Create a border window and canvas and store it in the pane
311 ::rtl::Reference
<PresenterPaneBase
> xPane
;
314 xPane
= ::rtl::Reference
<PresenterPaneBase
>(
315 new PresenterSpritePane(xContext
, mpPresenterController
));
319 xPane
= ::rtl::Reference
<PresenterPaneBase
>(
320 new PresenterPane(xContext
, mpPresenterController
));
324 Sequence
<Any
> aArguments (6);
325 aArguments
[0] <<= rxPaneId
;
326 aArguments
[1] <<= rxParentPane
->getWindow();
327 aArguments
[2] <<= rxParentPane
->getCanvas();
328 aArguments
[3] <<= rsTitle
;
329 aArguments
[4] <<= Reference
<drawing::framework::XPaneBorderPainter
>(
330 static_cast<XWeak
*>(mpPresenterController
->GetPaneBorderPainter().get()),
332 aArguments
[5] <<= bIsSpritePane
? false : true;
333 xPane
->initialize(aArguments
);
335 // Store pane and canvases and windows in container.
336 ::rtl::Reference
<PresenterPaneContainer
> pContainer (
337 mpPresenterController
->GetPaneContainer());
338 PresenterPaneContainer::SharedPaneDescriptor
pDescriptor(
339 pContainer
->StoreBorderWindow(rxPaneId
, xPane
->GetBorderWindow()));
340 pContainer
->StorePane(xPane
);
341 if (pDescriptor
.get() != NULL
)
345 pDescriptor
->maSpriteProvider
= ::boost::bind(
346 &PresenterSpritePane::GetSprite
,
347 dynamic_cast<PresenterSpritePane
*>(xPane
.get()));
348 pDescriptor
->mbIsSprite
= true;
349 pDescriptor
->mbNeedsClipping
= false;
353 pDescriptor
->mbIsSprite
= false;
354 pDescriptor
->mbNeedsClipping
= true;
357 // Get the window of the frame and make that visible.
358 Reference
<awt::XWindow
> xWindow (pDescriptor
->mxBorderWindow
, UNO_QUERY_THROW
);
359 xWindow
->setVisible(sal_True
);
362 return Reference
<XResource
>(static_cast<XWeak
*>(xPane
.get()), UNO_QUERY_THROW
);
368 void PresenterPaneFactory::ThrowIfDisposed (void) const
369 throw (::com::sun::star::lang::DisposedException
)
371 if (rBHelper
.bDisposed
|| rBHelper
.bInDispose
)
373 throw lang::DisposedException (
374 OUString(RTL_CONSTASCII_USTRINGPARAM(
375 "PresenterPaneFactory object has already been disposed")),
376 const_cast<uno::XWeak
*>(static_cast<const uno::XWeak
*>(this)));
381 } } // end of namespace sdext::presenter