1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: BasicToolBarFactory.cxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include "precompiled_sd.hxx"
34 #include "BasicToolBarFactory.hxx"
36 #include "ViewTabBar.hxx"
37 #include "framework/FrameworkHelper.hxx"
38 #include <comphelper/mediadescriptor.hxx>
40 #include <com/sun/star/lang/IllegalArgumentException.hpp>
41 #include "DrawController.hxx"
43 using namespace ::com::sun::star
;
44 using namespace ::com::sun::star::uno
;
45 using namespace ::com::sun::star::drawing::framework
;
47 namespace sd
{ namespace framework
{
50 Reference
<XInterface
> SAL_CALL
BasicToolBarFactory_createInstance (
51 const Reference
<XComponentContext
>& rxContext
)
53 return static_cast<XWeak
*>(new BasicToolBarFactory(rxContext
));
59 ::rtl::OUString
BasicToolBarFactory_getImplementationName (void) throw(RuntimeException
)
61 return ::rtl::OUString(
62 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Draw.framework.BasicToolBarFactory"));
68 Sequence
<rtl::OUString
> SAL_CALL
BasicToolBarFactory_getSupportedServiceNames (void)
69 throw (RuntimeException
)
71 static const ::rtl::OUString
sServiceName(
72 ::rtl::OUString::createFromAscii("com.sun.star.drawing.framework.BasicToolBarFactory"));
73 return Sequence
<rtl::OUString
>(&sServiceName
, 1);
80 //===== BasicToolBarFactory ===================================================
82 BasicToolBarFactory::BasicToolBarFactory (
83 const Reference
<XComponentContext
>& rxContext
)
84 : BasicToolBarFactoryInterfaceBase(m_aMutex
),
85 mxConfigurationController(),
95 BasicToolBarFactory::~BasicToolBarFactory (void)
102 void SAL_CALL
BasicToolBarFactory::disposing (void)
110 void BasicToolBarFactory::Shutdown (void)
112 mpViewShellBase
= NULL
;
113 Reference
<lang::XComponent
> xComponent (mxConfigurationController
, UNO_QUERY
);
115 xComponent
->removeEventListener(static_cast<lang::XEventListener
*>(this));
116 if (mxConfigurationController
.is())
118 mxConfigurationController
->removeResourceFactoryForReference(this);
119 mxConfigurationController
= NULL
;
126 //----- XInitialization -------------------------------------------------------
128 void SAL_CALL
BasicToolBarFactory::initialize (const Sequence
<Any
>& aArguments
)
129 throw (Exception
, RuntimeException
)
131 if (aArguments
.getLength() > 0)
135 // Get the XController from the first argument.
136 mxController
= Reference
<frame::XController
>(aArguments
[0], UNO_QUERY_THROW
);
138 // Tunnel through the controller to obtain a ViewShellBase.
139 Reference
<lang::XUnoTunnel
> xTunnel (mxController
, UNO_QUERY_THROW
);
140 ::sd::DrawController
* pController
= reinterpret_cast<sd::DrawController
*>(
141 xTunnel
->getSomething(sd::DrawController::getUnoTunnelId()));
142 if (pController
!= NULL
)
143 mpViewShellBase
= pController
->GetViewShellBase();
145 ::comphelper::MediaDescriptor
aDescriptor (mxController
->getModel()->getArgs());
146 if ( ! aDescriptor
.getUnpackedValueOrDefault(
147 ::comphelper::MediaDescriptor::PROP_PREVIEW(),
150 // Register the factory for its supported tool bars.
151 Reference
<XControllerManager
> xControllerManager(mxController
, UNO_QUERY_THROW
);
152 mxConfigurationController
= xControllerManager
->getConfigurationController();
153 if (mxConfigurationController
.is())
155 mxConfigurationController
->addResourceFactory(
156 FrameworkHelper::msViewTabBarURL
, this);
159 Reference
<lang::XComponent
> xComponent (mxConfigurationController
, UNO_QUERY
);
161 xComponent
->addEventListener(static_cast<lang::XEventListener
*>(this));
165 // The view shell is in preview mode and thus does not need
167 mxConfigurationController
= NULL
;
170 catch (RuntimeException
&)
181 //----- lang::XEventListener --------------------------------------------------
183 void SAL_CALL
BasicToolBarFactory::disposing (
184 const lang::EventObject
& rEventObject
)
185 throw (RuntimeException
)
187 if (rEventObject
.Source
== mxConfigurationController
)
188 mxConfigurationController
= NULL
;
194 //===== XPaneFactory ==========================================================
196 Reference
<XResource
> SAL_CALL
BasicToolBarFactory::createResource (
197 const Reference
<XResourceId
>& rxToolBarId
)
198 throw (RuntimeException
)
202 Reference
<XResource
> xToolBar
;
204 if (rxToolBarId
->getResourceURL().equals(FrameworkHelper::msViewTabBarURL
))
206 xToolBar
= new ViewTabBar(rxToolBarId
, mxController
);
209 throw lang::IllegalArgumentException();
219 void SAL_CALL
BasicToolBarFactory::releaseResource (
220 const Reference
<XResource
>& rxToolBar
)
221 throw (RuntimeException
)
225 Reference
<XComponent
> xComponent (rxToolBar
, UNO_QUERY
);
227 xComponent
->dispose();
233 void BasicToolBarFactory::ThrowIfDisposed (void) const
234 throw (lang::DisposedException
)
236 if (rBHelper
.bDisposed
|| rBHelper
.bInDispose
)
238 throw lang::DisposedException (
239 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
240 "BasicToolBarFactory object has already been disposed")),
241 const_cast<uno::XWeak
*>(static_cast<const uno::XWeak
*>(this)));
248 } } // end of namespace sd::framework