cid#1607171 Data race condition
[LibreOffice.git] / sd / source / ui / framework / factories / BasicToolBarFactory.cxx
blob0265fe3e12343a8e2f5c1dccd57ef32a4ac1c2dd
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/factories/BasicToolBarFactory.hxx>
22 #include <ViewTabBar.hxx>
23 #include <framework/FrameworkHelper.hxx>
24 #include <DrawController.hxx>
25 #include <unotools/mediadescriptor.hxx>
27 #include <com/sun/star/lang/IllegalArgumentException.hpp>
28 #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
29 #include <com/sun/star/frame/XController.hpp>
30 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
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;
37 namespace sd::framework {
39 //===== BasicToolBarFactory ===================================================
41 BasicToolBarFactory::BasicToolBarFactory(const rtl::Reference<::sd::DrawController>& rxController)
43 try
45 mxController = rxController;
47 utl::MediaDescriptor aDescriptor (mxController->getModel()->getArgs());
48 if ( ! aDescriptor.getUnpackedValueOrDefault(
49 utl::MediaDescriptor::PROP_PREVIEW,
50 false))
52 // Register the factory for its supported tool bars.
53 mxConfigurationController = mxController->getConfigurationController();
54 if (mxConfigurationController.is())
56 mxConfigurationController->addResourceFactory(
57 FrameworkHelper::msViewTabBarURL, this);
60 Reference<lang::XComponent> xComponent (mxConfigurationController, UNO_QUERY);
61 if (xComponent.is())
62 xComponent->addEventListener(static_cast<lang::XEventListener*>(this));
64 else
66 // The view shell is in preview mode and thus does not need
67 // the view tab bar.
68 mxConfigurationController = nullptr;
71 catch (RuntimeException&)
73 Shutdown();
74 throw;
79 BasicToolBarFactory::~BasicToolBarFactory()
83 void BasicToolBarFactory::disposing(std::unique_lock<std::mutex>&)
85 Shutdown();
88 void BasicToolBarFactory::Shutdown()
90 Reference<lang::XComponent> xComponent (mxConfigurationController, UNO_QUERY);
91 if (xComponent.is())
92 xComponent->removeEventListener(static_cast<lang::XEventListener*>(this));
93 if (mxConfigurationController.is())
95 mxConfigurationController->removeResourceFactoryForReference(this);
96 mxConfigurationController = nullptr;
100 //----- lang::XEventListener --------------------------------------------------
102 void SAL_CALL BasicToolBarFactory::disposing (
103 const lang::EventObject& rEventObject)
105 if (rEventObject.Source == mxConfigurationController)
106 mxConfigurationController = nullptr;
109 //===== XPaneFactory ==========================================================
111 Reference<XResource> SAL_CALL BasicToolBarFactory::createResource (
112 const Reference<XResourceId>& rxToolBarId)
114 ThrowIfDisposed();
116 if (rxToolBarId->getResourceURL() != FrameworkHelper::msViewTabBarURL)
117 throw lang::IllegalArgumentException();
119 Reference<XResource> xToolBar = new ViewTabBar(rxToolBarId, mxController);
120 return xToolBar;
123 void SAL_CALL BasicToolBarFactory::releaseResource (
124 const Reference<XResource>& rxToolBar)
126 ThrowIfDisposed();
128 Reference<XComponent> xComponent (rxToolBar, UNO_QUERY);
129 if (xComponent.is())
130 xComponent->dispose();
133 void BasicToolBarFactory::ThrowIfDisposed() const
135 if (m_bDisposed)
137 throw lang::DisposedException (u"BasicToolBarFactory object has already been disposed"_ustr,
138 const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
142 } // end of namespace sd::framework
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */