cid#1607171 Data race condition
[LibreOffice.git] / sd / source / ui / framework / factories / PresentationFactory.cxx
blobce0b168ce803264b39c0fab5e9c40c070513ed7e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <DrawController.hxx>
23 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
24 #include <com/sun/star/drawing/framework/XView.hpp>
25 #include <comphelper/servicehelper.hxx>
26 #include <comphelper/compbase.hxx>
27 #include <comphelper/diagnose_ex.hxx>
28 #include <slideshow.hxx>
30 namespace com::sun::star::uno { class XComponentContext; }
32 using namespace ::com::sun::star;
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::lang;
35 using namespace ::com::sun::star::drawing::framework;
38 namespace sd::framework {
40 namespace {
42 typedef comphelper::WeakComponentImplHelper<XView> PresentationViewInterfaceBase;
44 /** The PresentationView is not an actual view, it is a marker whose
45 existence in a configuration indicates that a slideshow is running
46 (in another application window).
48 class PresentationView
49 : public PresentationViewInterfaceBase
51 public:
52 explicit PresentationView (const Reference<XResourceId>& rxViewId)
53 : mxResourceId(rxViewId) {};
55 // XView
57 virtual Reference<XResourceId> SAL_CALL getResourceId() override
58 { return mxResourceId; };
60 virtual sal_Bool SAL_CALL isAnchorOnly() override
61 { return false; }
63 private:
64 Reference<XResourceId> mxResourceId;
67 } // end of anonymous namespace.
69 //===== PresentationFactory ===================================================
71 constexpr OUString gsPresentationViewURL = u"private:resource/view/Presentation"_ustr;
73 PresentationFactory::PresentationFactory (
74 const rtl::Reference<::sd::DrawController>& rxController)
75 : mxController(rxController)
79 PresentationFactory::~PresentationFactory()
83 //----- XViewFactory ----------------------------------------------------------
85 Reference<XResource> SAL_CALL PresentationFactory::createResource (
86 const Reference<XResourceId>& rxViewId)
88 ThrowIfDisposed();
90 if (rxViewId.is())
91 if ( ! rxViewId->hasAnchor() && rxViewId->getResourceURL() == gsPresentationViewURL)
92 return new PresentationView(rxViewId);
94 return Reference<XResource>();
97 void SAL_CALL PresentationFactory::releaseResource (
98 const Reference<XResource>&)
100 ThrowIfDisposed();
102 if (mxController)
104 ViewShellBase* pBase = mxController->GetViewShellBase();
105 if (pBase != nullptr)
106 SlideShow::Stop( *pBase );
110 //===== XConfigurationChangeListener ==========================================
112 void SAL_CALL PresentationFactory::notifyConfigurationChange (
113 const ConfigurationChangeEvent&)
116 //===== lang::XEventListener ==================================================
118 void SAL_CALL PresentationFactory::disposing (
119 const lang::EventObject&)
122 void PresentationFactory::ThrowIfDisposed() const
124 if (m_bDisposed)
126 throw lang::DisposedException (u"PresentationFactory object has already been disposed"_ustr,
127 const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
131 void PresentationFactory::install(const rtl::Reference<::sd::DrawController>& rxController)
135 Reference<XConfigurationController> xCC (rxController->getConfigurationController());
136 if (xCC.is())
137 xCC->addResourceFactory(
138 gsPresentationViewURL,
139 new PresentationFactory(rxController));
141 catch (RuntimeException&)
143 DBG_UNHANDLED_EXCEPTION("sd");
147 } // end of namespace sd::framework
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */