xref: /AOO41X/main/sd/source/ui/framework/factories/BasicToolBarFactory.cxx (revision 79aad27f7f29270c03e208e3d687e8e3850af11d)
1*5b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5b190011SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5b190011SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5b190011SAndrew Rist  * distributed with this work for additional information
6*5b190011SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5b190011SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5b190011SAndrew Rist  * "License"); you may not use this file except in compliance
9*5b190011SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*5b190011SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*5b190011SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5b190011SAndrew Rist  * software distributed under the License is distributed on an
15*5b190011SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5b190011SAndrew Rist  * KIND, either express or implied.  See the License for the
17*5b190011SAndrew Rist  * specific language governing permissions and limitations
18*5b190011SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*5b190011SAndrew Rist  *************************************************************/
21*5b190011SAndrew Rist 
22*5b190011SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "precompiled_sd.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "BasicToolBarFactory.hxx"
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include "ViewTabBar.hxx"
29cdf0e10cSrcweir #include "framework/FrameworkHelper.hxx"
30cdf0e10cSrcweir #include <comphelper/mediadescriptor.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <com/sun/star/lang/IllegalArgumentException.hpp>
33cdf0e10cSrcweir #include "DrawController.hxx"
34cdf0e10cSrcweir 
35cdf0e10cSrcweir using namespace ::com::sun::star;
36cdf0e10cSrcweir using namespace ::com::sun::star::uno;
37cdf0e10cSrcweir using namespace ::com::sun::star::lang;
38cdf0e10cSrcweir using namespace ::com::sun::star::drawing::framework;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir namespace sd { namespace framework {
41cdf0e10cSrcweir 
42cdf0e10cSrcweir 
BasicToolBarFactory_createInstance(const Reference<XComponentContext> & rxContext)43cdf0e10cSrcweir Reference<XInterface> SAL_CALL BasicToolBarFactory_createInstance (
44cdf0e10cSrcweir     const Reference<XComponentContext>& rxContext)
45cdf0e10cSrcweir {
46cdf0e10cSrcweir     return static_cast<XWeak*>(new BasicToolBarFactory(rxContext));
47cdf0e10cSrcweir }
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 
BasicToolBarFactory_getImplementationName(void)52cdf0e10cSrcweir ::rtl::OUString BasicToolBarFactory_getImplementationName (void) throw(RuntimeException)
53cdf0e10cSrcweir {
54cdf0e10cSrcweir     return ::rtl::OUString(
55cdf0e10cSrcweir         RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Draw.framework.BasicToolBarFactory"));
56cdf0e10cSrcweir }
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 
BasicToolBarFactory_getSupportedServiceNames(void)61cdf0e10cSrcweir Sequence<rtl::OUString> SAL_CALL BasicToolBarFactory_getSupportedServiceNames (void)
62cdf0e10cSrcweir     throw (RuntimeException)
63cdf0e10cSrcweir {
64cdf0e10cSrcweir 	static const ::rtl::OUString sServiceName(
65cdf0e10cSrcweir         ::rtl::OUString::createFromAscii("com.sun.star.drawing.framework.BasicToolBarFactory"));
66cdf0e10cSrcweir 	return Sequence<rtl::OUString>(&sServiceName, 1);
67cdf0e10cSrcweir }
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 
73cdf0e10cSrcweir //===== BasicToolBarFactory ===================================================
74cdf0e10cSrcweir 
BasicToolBarFactory(const Reference<XComponentContext> & rxContext)75cdf0e10cSrcweir BasicToolBarFactory::BasicToolBarFactory (
76cdf0e10cSrcweir     const Reference<XComponentContext>& rxContext)
77cdf0e10cSrcweir     : BasicToolBarFactoryInterfaceBase(m_aMutex),
78cdf0e10cSrcweir       mxConfigurationController(),
79cdf0e10cSrcweir       mxController(),
80cdf0e10cSrcweir       mpViewShellBase(NULL)
81cdf0e10cSrcweir {
82cdf0e10cSrcweir     (void)rxContext;
83cdf0e10cSrcweir }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 
~BasicToolBarFactory(void)88cdf0e10cSrcweir BasicToolBarFactory::~BasicToolBarFactory (void)
89cdf0e10cSrcweir {
90cdf0e10cSrcweir }
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 
disposing(void)95cdf0e10cSrcweir void SAL_CALL BasicToolBarFactory::disposing (void)
96cdf0e10cSrcweir {
97cdf0e10cSrcweir     Shutdown();
98cdf0e10cSrcweir }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 
Shutdown(void)103cdf0e10cSrcweir void BasicToolBarFactory::Shutdown (void)
104cdf0e10cSrcweir {
105cdf0e10cSrcweir     mpViewShellBase = NULL;
106cdf0e10cSrcweir     Reference<lang::XComponent> xComponent (mxConfigurationController, UNO_QUERY);
107cdf0e10cSrcweir     if (xComponent.is())
108cdf0e10cSrcweir         xComponent->removeEventListener(static_cast<lang::XEventListener*>(this));
109cdf0e10cSrcweir     if (mxConfigurationController.is())
110cdf0e10cSrcweir     {
111cdf0e10cSrcweir         mxConfigurationController->removeResourceFactoryForReference(this);
112cdf0e10cSrcweir         mxConfigurationController = NULL;
113cdf0e10cSrcweir     }
114cdf0e10cSrcweir }
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 
119cdf0e10cSrcweir //----- XInitialization -------------------------------------------------------
120cdf0e10cSrcweir 
initialize(const Sequence<Any> & aArguments)121cdf0e10cSrcweir void SAL_CALL BasicToolBarFactory::initialize (const Sequence<Any>& aArguments)
122cdf0e10cSrcweir     throw (Exception, RuntimeException)
123cdf0e10cSrcweir {
124cdf0e10cSrcweir     if (aArguments.getLength() > 0)
125cdf0e10cSrcweir     {
126cdf0e10cSrcweir         try
127cdf0e10cSrcweir         {
128cdf0e10cSrcweir             // Get the XController from the first argument.
129cdf0e10cSrcweir             mxController = Reference<frame::XController>(aArguments[0], UNO_QUERY_THROW);
130cdf0e10cSrcweir 
131cdf0e10cSrcweir             // Tunnel through the controller to obtain a ViewShellBase.
132cdf0e10cSrcweir             Reference<lang::XUnoTunnel> xTunnel (mxController, UNO_QUERY_THROW);
133cdf0e10cSrcweir             ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
134cdf0e10cSrcweir                 xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
135cdf0e10cSrcweir             if (pController != NULL)
136cdf0e10cSrcweir                 mpViewShellBase = pController->GetViewShellBase();
137cdf0e10cSrcweir 
138cdf0e10cSrcweir             ::comphelper::MediaDescriptor aDescriptor (mxController->getModel()->getArgs());
139cdf0e10cSrcweir             if ( ! aDescriptor.getUnpackedValueOrDefault(
140cdf0e10cSrcweir                 ::comphelper::MediaDescriptor::PROP_PREVIEW(),
141cdf0e10cSrcweir                 sal_False))
142cdf0e10cSrcweir             {
143cdf0e10cSrcweir                 // Register the factory for its supported tool bars.
144cdf0e10cSrcweir                 Reference<XControllerManager> xControllerManager(mxController, UNO_QUERY_THROW);
145cdf0e10cSrcweir                 mxConfigurationController = xControllerManager->getConfigurationController();
146cdf0e10cSrcweir                 if (mxConfigurationController.is())
147cdf0e10cSrcweir                 {
148cdf0e10cSrcweir                     mxConfigurationController->addResourceFactory(
149cdf0e10cSrcweir                         FrameworkHelper::msViewTabBarURL, this);
150cdf0e10cSrcweir                 }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir                 Reference<lang::XComponent> xComponent (mxConfigurationController, UNO_QUERY);
153cdf0e10cSrcweir                 if (xComponent.is())
154cdf0e10cSrcweir                     xComponent->addEventListener(static_cast<lang::XEventListener*>(this));
155cdf0e10cSrcweir             }
156cdf0e10cSrcweir             else
157cdf0e10cSrcweir             {
158cdf0e10cSrcweir                 // The view shell is in preview mode and thus does not need
159cdf0e10cSrcweir                 // the view tab bar.
160cdf0e10cSrcweir                 mxConfigurationController = NULL;
161cdf0e10cSrcweir             }
162cdf0e10cSrcweir         }
163cdf0e10cSrcweir         catch (RuntimeException&)
164cdf0e10cSrcweir         {
165cdf0e10cSrcweir             Shutdown();
166cdf0e10cSrcweir             throw;
167cdf0e10cSrcweir         }
168cdf0e10cSrcweir     }
169cdf0e10cSrcweir }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 
172cdf0e10cSrcweir 
173cdf0e10cSrcweir 
174cdf0e10cSrcweir //----- lang::XEventListener --------------------------------------------------
175cdf0e10cSrcweir 
disposing(const lang::EventObject & rEventObject)176cdf0e10cSrcweir void SAL_CALL BasicToolBarFactory::disposing (
177cdf0e10cSrcweir     const lang::EventObject& rEventObject)
178cdf0e10cSrcweir     throw (RuntimeException)
179cdf0e10cSrcweir {
180cdf0e10cSrcweir     if (rEventObject.Source == mxConfigurationController)
181cdf0e10cSrcweir         mxConfigurationController = NULL;
182cdf0e10cSrcweir }
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 
187cdf0e10cSrcweir //===== XPaneFactory ==========================================================
188cdf0e10cSrcweir 
createResource(const Reference<XResourceId> & rxToolBarId)189cdf0e10cSrcweir Reference<XResource> SAL_CALL BasicToolBarFactory::createResource (
190cdf0e10cSrcweir     const Reference<XResourceId>& rxToolBarId)
191cdf0e10cSrcweir     throw (RuntimeException, IllegalArgumentException, WrappedTargetException)
192cdf0e10cSrcweir {
193cdf0e10cSrcweir     ThrowIfDisposed();
194cdf0e10cSrcweir 
195cdf0e10cSrcweir     Reference<XResource> xToolBar;
196cdf0e10cSrcweir 
197cdf0e10cSrcweir     if (rxToolBarId->getResourceURL().equals(FrameworkHelper::msViewTabBarURL))
198cdf0e10cSrcweir     {
199cdf0e10cSrcweir         xToolBar = new ViewTabBar(rxToolBarId, mxController);
200cdf0e10cSrcweir     }
201cdf0e10cSrcweir     else
202cdf0e10cSrcweir         throw lang::IllegalArgumentException();
203cdf0e10cSrcweir 
204cdf0e10cSrcweir 
205cdf0e10cSrcweir     return xToolBar;
206cdf0e10cSrcweir }
207cdf0e10cSrcweir 
208cdf0e10cSrcweir 
209cdf0e10cSrcweir 
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 
releaseResource(const Reference<XResource> & rxToolBar)212cdf0e10cSrcweir void SAL_CALL BasicToolBarFactory::releaseResource (
213cdf0e10cSrcweir     const Reference<XResource>& rxToolBar)
214cdf0e10cSrcweir     throw (RuntimeException)
215cdf0e10cSrcweir {
216cdf0e10cSrcweir     ThrowIfDisposed();
217cdf0e10cSrcweir 
218cdf0e10cSrcweir     Reference<XComponent> xComponent (rxToolBar, UNO_QUERY);
219cdf0e10cSrcweir     if (xComponent.is())
220cdf0e10cSrcweir         xComponent->dispose();
221cdf0e10cSrcweir }
222cdf0e10cSrcweir 
223cdf0e10cSrcweir 
224cdf0e10cSrcweir 
225cdf0e10cSrcweir 
ThrowIfDisposed(void) const226cdf0e10cSrcweir void BasicToolBarFactory::ThrowIfDisposed (void) const
227cdf0e10cSrcweir     throw (lang::DisposedException)
228cdf0e10cSrcweir {
229cdf0e10cSrcweir 	if (rBHelper.bDisposed || rBHelper.bInDispose)
230cdf0e10cSrcweir 	{
231cdf0e10cSrcweir         throw lang::DisposedException (
232cdf0e10cSrcweir             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
233cdf0e10cSrcweir                 "BasicToolBarFactory object has already been disposed")),
234cdf0e10cSrcweir             const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
235cdf0e10cSrcweir     }
236cdf0e10cSrcweir }
237cdf0e10cSrcweir 
238cdf0e10cSrcweir 
239cdf0e10cSrcweir 
240cdf0e10cSrcweir 
241cdf0e10cSrcweir } } // end of namespace sd::framework
242