Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include "BasicToolBarFactory.hxx"
22 :
23 : #include "ViewTabBar.hxx"
24 : #include "framework/FrameworkHelper.hxx"
25 : #include <unotools/mediadescriptor.hxx>
26 :
27 : #include <com/sun/star/lang/IllegalArgumentException.hpp>
28 : #include "DrawController.hxx"
29 :
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;
34 :
35 : namespace sd { namespace framework {
36 :
37 :
38 21 : Reference<XInterface> SAL_CALL BasicToolBarFactory_createInstance (
39 : const Reference<XComponentContext>& rxContext)
40 : {
41 21 : return static_cast<XWeak*>(new BasicToolBarFactory(rxContext));
42 : }
43 :
44 :
45 :
46 :
47 21 : OUString BasicToolBarFactory_getImplementationName (void) throw(RuntimeException)
48 : {
49 21 : return OUString("com.sun.star.comp.Draw.framework.BasicToolBarFactory");
50 : }
51 :
52 :
53 :
54 :
55 6 : Sequence<OUString> SAL_CALL BasicToolBarFactory_getSupportedServiceNames (void)
56 : throw (RuntimeException)
57 : {
58 6 : const OUString sServiceName("com.sun.star.drawing.framework.BasicToolBarFactory");
59 6 : return Sequence<OUString>(&sServiceName, 1);
60 : }
61 :
62 :
63 :
64 :
65 :
66 : //===== BasicToolBarFactory ===================================================
67 :
68 21 : BasicToolBarFactory::BasicToolBarFactory (
69 : const Reference<XComponentContext>& rxContext)
70 : : BasicToolBarFactoryInterfaceBase(m_aMutex),
71 : mxConfigurationController(),
72 : mxController(),
73 21 : mpViewShellBase(NULL)
74 : {
75 : (void)rxContext;
76 21 : }
77 :
78 :
79 :
80 :
81 42 : BasicToolBarFactory::~BasicToolBarFactory (void)
82 : {
83 42 : }
84 :
85 :
86 :
87 :
88 21 : void SAL_CALL BasicToolBarFactory::disposing (void)
89 : {
90 21 : Shutdown();
91 21 : }
92 :
93 :
94 :
95 :
96 21 : void BasicToolBarFactory::Shutdown (void)
97 : {
98 21 : mpViewShellBase = NULL;
99 21 : Reference<lang::XComponent> xComponent (mxConfigurationController, UNO_QUERY);
100 21 : if (xComponent.is())
101 0 : xComponent->removeEventListener(static_cast<lang::XEventListener*>(this));
102 21 : if (mxConfigurationController.is())
103 : {
104 0 : mxConfigurationController->removeResourceFactoryForReference(this);
105 0 : mxConfigurationController = NULL;
106 21 : }
107 21 : }
108 :
109 :
110 :
111 :
112 : //----- XInitialization -------------------------------------------------------
113 :
114 21 : void SAL_CALL BasicToolBarFactory::initialize (const Sequence<Any>& aArguments)
115 : throw (Exception, RuntimeException, std::exception)
116 : {
117 21 : if (aArguments.getLength() > 0)
118 : {
119 : try
120 : {
121 : // Get the XController from the first argument.
122 21 : mxController = Reference<frame::XController>(aArguments[0], UNO_QUERY_THROW);
123 :
124 : // Tunnel through the controller to obtain a ViewShellBase.
125 21 : Reference<lang::XUnoTunnel> xTunnel (mxController, UNO_QUERY_THROW);
126 : ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
127 21 : xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
128 21 : if (pController != NULL)
129 21 : mpViewShellBase = pController->GetViewShellBase();
130 :
131 42 : utl::MediaDescriptor aDescriptor (mxController->getModel()->getArgs());
132 42 : if ( ! aDescriptor.getUnpackedValueOrDefault(
133 21 : utl::MediaDescriptor::PROP_PREVIEW(),
134 63 : sal_False))
135 : {
136 : // Register the factory for its supported tool bars.
137 21 : Reference<XControllerManager> xControllerManager(mxController, UNO_QUERY_THROW);
138 21 : mxConfigurationController = xControllerManager->getConfigurationController();
139 21 : if (mxConfigurationController.is())
140 : {
141 21 : mxConfigurationController->addResourceFactory(
142 21 : FrameworkHelper::msViewTabBarURL, this);
143 : }
144 :
145 42 : Reference<lang::XComponent> xComponent (mxConfigurationController, UNO_QUERY);
146 21 : if (xComponent.is())
147 42 : xComponent->addEventListener(static_cast<lang::XEventListener*>(this));
148 : }
149 : else
150 : {
151 : // The view shell is in preview mode and thus does not need
152 : // the view tab bar.
153 0 : mxConfigurationController = NULL;
154 21 : }
155 : }
156 0 : catch (RuntimeException&)
157 : {
158 0 : Shutdown();
159 0 : throw;
160 : }
161 : }
162 21 : }
163 :
164 :
165 :
166 :
167 : //----- lang::XEventListener --------------------------------------------------
168 :
169 21 : void SAL_CALL BasicToolBarFactory::disposing (
170 : const lang::EventObject& rEventObject)
171 : throw (RuntimeException, std::exception)
172 : {
173 21 : if (rEventObject.Source == mxConfigurationController)
174 21 : mxConfigurationController = NULL;
175 21 : }
176 :
177 :
178 :
179 :
180 : //===== XPaneFactory ==========================================================
181 :
182 21 : Reference<XResource> SAL_CALL BasicToolBarFactory::createResource (
183 : const Reference<XResourceId>& rxToolBarId)
184 : throw (RuntimeException, IllegalArgumentException, WrappedTargetException, std::exception)
185 : {
186 21 : ThrowIfDisposed();
187 :
188 21 : Reference<XResource> xToolBar;
189 :
190 21 : if (rxToolBarId->getResourceURL().equals(FrameworkHelper::msViewTabBarURL))
191 : {
192 21 : xToolBar = new ViewTabBar(rxToolBarId, mxController);
193 : }
194 : else
195 0 : throw lang::IllegalArgumentException();
196 :
197 :
198 21 : return xToolBar;
199 : }
200 :
201 :
202 :
203 :
204 :
205 21 : void SAL_CALL BasicToolBarFactory::releaseResource (
206 : const Reference<XResource>& rxToolBar)
207 : throw (RuntimeException, std::exception)
208 : {
209 21 : ThrowIfDisposed();
210 :
211 21 : Reference<XComponent> xComponent (rxToolBar, UNO_QUERY);
212 21 : if (xComponent.is())
213 21 : xComponent->dispose();
214 21 : }
215 :
216 :
217 :
218 :
219 42 : void BasicToolBarFactory::ThrowIfDisposed (void) const
220 : throw (lang::DisposedException)
221 : {
222 42 : if (rBHelper.bDisposed || rBHelper.bInDispose)
223 : {
224 : throw lang::DisposedException ("BasicToolBarFactory object has already been disposed",
225 0 : const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
226 : }
227 42 : }
228 :
229 :
230 :
231 :
232 : } } // end of namespace sd::framework
233 :
234 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|