bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / framework / factories / BasicToolBarFactory.cxx
blobcba8afb1d346dd81af01e74f68b042571476293b
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 "BasicToolBarFactory.hxx"
22 #include "ViewTabBar.hxx"
23 #include "facreg.hxx"
24 #include "framework/FrameworkHelper.hxx"
25 #include <unotools/mediadescriptor.hxx>
27 #include <com/sun/star/lang/IllegalArgumentException.hpp>
28 #include "DrawController.hxx"
30 using namespace ::com::sun::star;
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::lang;
33 using namespace ::com::sun::star::drawing::framework;
35 namespace sd { namespace framework {
37 //===== BasicToolBarFactory ===================================================
39 BasicToolBarFactory::BasicToolBarFactory (
40 const Reference<XComponentContext>& rxContext)
41 : BasicToolBarFactoryInterfaceBase(m_aMutex),
42 mxConfigurationController(),
43 mxController(),
44 mpViewShellBase(NULL)
46 (void)rxContext;
49 BasicToolBarFactory::~BasicToolBarFactory()
53 void SAL_CALL BasicToolBarFactory::disposing()
55 Shutdown();
58 void BasicToolBarFactory::Shutdown()
60 mpViewShellBase = NULL;
61 Reference<lang::XComponent> xComponent (mxConfigurationController, UNO_QUERY);
62 if (xComponent.is())
63 xComponent->removeEventListener(static_cast<lang::XEventListener*>(this));
64 if (mxConfigurationController.is())
66 mxConfigurationController->removeResourceFactoryForReference(this);
67 mxConfigurationController = NULL;
71 //----- XInitialization -------------------------------------------------------
73 void SAL_CALL BasicToolBarFactory::initialize (const Sequence<Any>& aArguments)
74 throw (Exception, RuntimeException, std::exception)
76 if (aArguments.getLength() > 0)
78 try
80 // Get the XController from the first argument.
81 mxController = Reference<frame::XController>(aArguments[0], UNO_QUERY_THROW);
83 // Tunnel through the controller to obtain a ViewShellBase.
84 Reference<lang::XUnoTunnel> xTunnel (mxController, UNO_QUERY_THROW);
85 ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
86 xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
87 if (pController != NULL)
88 mpViewShellBase = pController->GetViewShellBase();
90 utl::MediaDescriptor aDescriptor (mxController->getModel()->getArgs());
91 if ( ! aDescriptor.getUnpackedValueOrDefault(
92 utl::MediaDescriptor::PROP_PREVIEW(),
93 false))
95 // Register the factory for its supported tool bars.
96 Reference<XControllerManager> xControllerManager(mxController, UNO_QUERY_THROW);
97 mxConfigurationController = xControllerManager->getConfigurationController();
98 if (mxConfigurationController.is())
100 mxConfigurationController->addResourceFactory(
101 FrameworkHelper::msViewTabBarURL, this);
104 Reference<lang::XComponent> xComponent (mxConfigurationController, UNO_QUERY);
105 if (xComponent.is())
106 xComponent->addEventListener(static_cast<lang::XEventListener*>(this));
108 else
110 // The view shell is in preview mode and thus does not need
111 // the view tab bar.
112 mxConfigurationController = NULL;
115 catch (RuntimeException&)
117 Shutdown();
118 throw;
123 //----- lang::XEventListener --------------------------------------------------
125 void SAL_CALL BasicToolBarFactory::disposing (
126 const lang::EventObject& rEventObject)
127 throw (RuntimeException, std::exception)
129 if (rEventObject.Source == mxConfigurationController)
130 mxConfigurationController = NULL;
133 //===== XPaneFactory ==========================================================
135 Reference<XResource> SAL_CALL BasicToolBarFactory::createResource (
136 const Reference<XResourceId>& rxToolBarId)
137 throw (RuntimeException, IllegalArgumentException, WrappedTargetException, std::exception)
139 ThrowIfDisposed();
141 Reference<XResource> xToolBar;
143 if (rxToolBarId->getResourceURL().equals(FrameworkHelper::msViewTabBarURL))
145 xToolBar = new ViewTabBar(rxToolBarId, mxController);
147 else
148 throw lang::IllegalArgumentException();
150 return xToolBar;
153 void SAL_CALL BasicToolBarFactory::releaseResource (
154 const Reference<XResource>& rxToolBar)
155 throw (RuntimeException, std::exception)
157 ThrowIfDisposed();
159 Reference<XComponent> xComponent (rxToolBar, UNO_QUERY);
160 if (xComponent.is())
161 xComponent->dispose();
164 void BasicToolBarFactory::ThrowIfDisposed() const
165 throw (lang::DisposedException)
167 if (rBHelper.bDisposed || rBHelper.bInDispose)
169 throw lang::DisposedException ("BasicToolBarFactory object has already been disposed",
170 const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
174 } } // end of namespace sd::framework
176 extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
177 com_sun_star_comp_Draw_framework_BasicToolBarFactory_get_implementation(::com::sun::star::uno::XComponentContext* context,
178 ::com::sun::star::uno::Sequence<css::uno::Any> const &)
180 return cppu::acquire(new sd::framework::BasicToolBarFactory(context));
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */