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 "framework/PresentationFactory.hxx"
22 #include "framework/FrameworkHelper.hxx"
23 #include "DrawController.hxx"
24 #include "ViewShellBase.hxx"
26 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
27 #include <cppuhelper/compbase1.hxx>
28 #include <tools/diagnose_ex.h>
29 #include "slideshow.hxx"
31 using namespace ::com::sun::star
;
32 using namespace ::com::sun::star::uno
;
33 using namespace ::com::sun::star::lang
;
34 using namespace ::com::sun::star::drawing::framework
;
36 using ::sd::framework::FrameworkHelper
;
38 namespace sd
{ namespace framework
{
42 typedef ::cppu::WeakComponentImplHelper1
<lang::XInitialization
> PresentationFactoryProviderInterfaceBase
;
44 class PresentationFactoryProvider
45 : protected MutexOwner
,
46 public PresentationFactoryProviderInterfaceBase
49 PresentationFactoryProvider (const Reference
<XComponentContext
>& rxContext
);
50 virtual ~PresentationFactoryProvider();
52 virtual void SAL_CALL
disposing() SAL_OVERRIDE
;
56 virtual void SAL_CALL
initialize(
57 const ::com::sun::star::uno::Sequence
<com::sun::star::uno::Any
>& aArguments
)
58 throw (::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
61 typedef ::cppu::WeakComponentImplHelper1
<XView
> PresentationViewInterfaceBase
;
63 /** The PresentationView is not an actual view, it is a marker whose
64 existence in a configuration indicates that a slideshow is running
65 (in another application window).
67 class PresentationView
68 : protected MutexOwner
,
69 public PresentationViewInterfaceBase
72 PresentationView (const Reference
<XResourceId
>& rxViewId
)
73 : PresentationViewInterfaceBase(maMutex
),mxResourceId(rxViewId
) {};
74 virtual ~PresentationView() {};
78 virtual Reference
<XResourceId
> SAL_CALL
getResourceId() throw (RuntimeException
, std::exception
) SAL_OVERRIDE
79 { return mxResourceId
; };
81 virtual sal_Bool SAL_CALL
isAnchorOnly() throw (RuntimeException
, std::exception
) SAL_OVERRIDE
85 Reference
<XResourceId
> mxResourceId
;
88 } // end of anonymous namespace.
90 //===== PresentationFactory ===================================================
92 const OUString
PresentationFactory::msPresentationViewURL("private:resource/view/Presentation");
94 PresentationFactory::PresentationFactory (
95 const Reference
<frame::XController
>& rxController
)
96 : PresentationFactoryInterfaceBase(MutexOwner::maMutex
),
97 mxConfigurationController(),
98 mxController(rxController
)
102 // Get the XController from the first argument.
103 Reference
<XControllerManager
> xControllerManager(rxController
, UNO_QUERY_THROW
);
104 mxConfigurationController
= xControllerManager
->getConfigurationController();
106 catch (RuntimeException
&)
108 DBG_UNHANDLED_EXCEPTION();
112 PresentationFactory::~PresentationFactory()
116 void SAL_CALL
PresentationFactory::disposing()
120 //----- XViewFactory ----------------------------------------------------------
122 Reference
<XResource
> SAL_CALL
PresentationFactory::createResource (
123 const Reference
<XResourceId
>& rxViewId
)
124 throw (RuntimeException
, IllegalArgumentException
, WrappedTargetException
, std::exception
)
129 if ( ! rxViewId
->hasAnchor() && rxViewId
->getResourceURL().equals(msPresentationViewURL
))
130 return new PresentationView(rxViewId
);
132 return Reference
<XResource
>();
135 void SAL_CALL
PresentationFactory::releaseResource (
136 const Reference
<XResource
>& rxView
)
137 throw (RuntimeException
, std::exception
)
142 Reference
<lang::XUnoTunnel
> xTunnel (mxController
, UNO_QUERY
);
145 ::sd::DrawController
* pController
= reinterpret_cast<sd::DrawController
*>(
146 xTunnel
->getSomething(sd::DrawController::getUnoTunnelId()));
147 if (pController
!= NULL
)
149 ViewShellBase
* pBase
= pController
->GetViewShellBase();
151 SlideShow::Stop( *pBase
);
156 //===== XConfigurationChangeListener ==========================================
158 void SAL_CALL
PresentationFactory::notifyConfigurationChange (
159 const ConfigurationChangeEvent
& rEvent
)
160 throw (RuntimeException
, std::exception
)
165 //===== lang::XEventListener ==================================================
167 void SAL_CALL
PresentationFactory::disposing (
168 const lang::EventObject
& rEventObject
)
169 throw (RuntimeException
, std::exception
)
174 void PresentationFactory::ThrowIfDisposed() const
175 throw (lang::DisposedException
)
177 if (rBHelper
.bDisposed
|| rBHelper
.bInDispose
)
179 throw lang::DisposedException ("PresentationFactory object has already been disposed",
180 const_cast<uno::XWeak
*>(static_cast<const uno::XWeak
*>(this)));
186 //===== PresentationFactoryProvider ===========================================
188 PresentationFactoryProvider::PresentationFactoryProvider (
189 const Reference
<XComponentContext
>& rxContext
)
190 : PresentationFactoryProviderInterfaceBase(maMutex
)
195 PresentationFactoryProvider::~PresentationFactoryProvider()
199 void PresentationFactoryProvider::disposing()
205 void SAL_CALL
PresentationFactoryProvider::initialize(
206 const Sequence
<Any
>& aArguments
)
207 throw (Exception
, RuntimeException
, std::exception
)
209 if (aArguments
.getLength() > 0)
213 // Get the XController from the first argument.
214 Reference
<frame::XController
> xController (aArguments
[0], UNO_QUERY_THROW
);
215 Reference
<XControllerManager
> xCM (xController
, UNO_QUERY_THROW
);
216 Reference
<XConfigurationController
> xCC (xCM
->getConfigurationController());
218 xCC
->addResourceFactory(
219 PresentationFactory::msPresentationViewURL
,
220 new PresentationFactory(xController
));
222 catch (RuntimeException
&)
224 DBG_UNHANDLED_EXCEPTION();
229 } // end of anonymous namespace.
231 } } // end of namespace sd::framework
234 extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface
* SAL_CALL
235 com_sun_star_comp_Draw_framework_PresentationFactoryProvider_get_implementation(::com::sun::star::uno::XComponentContext
* context
,
236 ::com::sun::star::uno::Sequence
<css::uno::Any
> const &)
238 return cppu::acquire(new sd::framework::PresentationFactoryProvider(context
));
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */