1facb16e7SArmin Le Grand /**************************************************************
2*d1e7c34dSmseidel  *
3facb16e7SArmin Le Grand  * Licensed to the Apache Software Foundation (ASF) under one
4facb16e7SArmin Le Grand  * or more contributor license agreements.  See the NOTICE file
5facb16e7SArmin Le Grand  * distributed with this work for additional information
6facb16e7SArmin Le Grand  * regarding copyright ownership.  The ASF licenses this file
7facb16e7SArmin Le Grand  * to you under the Apache License, Version 2.0 (the
8facb16e7SArmin Le Grand  * "License"); you may not use this file except in compliance
9facb16e7SArmin Le Grand  * with the License.  You may obtain a copy of the License at
10*d1e7c34dSmseidel  *
11facb16e7SArmin Le Grand  *   http://www.apache.org/licenses/LICENSE-2.0
12*d1e7c34dSmseidel  *
13facb16e7SArmin Le Grand  * Unless required by applicable law or agreed to in writing,
14facb16e7SArmin Le Grand  * software distributed under the License is distributed on an
15facb16e7SArmin Le Grand  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16facb16e7SArmin Le Grand  * KIND, either express or implied.  See the License for the
17facb16e7SArmin Le Grand  * specific language governing permissions and limitations
18facb16e7SArmin Le Grand  * under the License.
19*d1e7c34dSmseidel  *
20facb16e7SArmin Le Grand  *************************************************************/
21facb16e7SArmin Le Grand 
22*d1e7c34dSmseidel 
23*d1e7c34dSmseidel 
24facb16e7SArmin Le Grand #include "precompiled_sc.hxx"
25facb16e7SArmin Le Grand 
26facb16e7SArmin Le Grand #include "ScPanelFactory.hxx"
27facb16e7SArmin Le Grand 
28facb16e7SArmin Le Grand #include <AlignmentPropertyPanel.hxx>
29facb16e7SArmin Le Grand #include <CellAppearancePropertyPanel.hxx>
304e8031e0SArmin Le Grand #include <NumberFormatPropertyPanel.hxx>
313c226292SAndre Fischer #include <navipi.hxx>
324847afebSAndre Fischer #include <dwfunctr.hxx>
334847afebSAndre Fischer #include "sc.hrc"
34facb16e7SArmin Le Grand 
35facb16e7SArmin Le Grand #include <sfx2/sidebar/SidebarPanelBase.hxx>
36facb16e7SArmin Le Grand #include <sfx2/sfxbasecontroller.hxx>
37facb16e7SArmin Le Grand #include <toolkit/helper/vclunohelper.hxx>
38facb16e7SArmin Le Grand #include <vcl/window.hxx>
39facb16e7SArmin Le Grand #include <rtl/ref.hxx>
40facb16e7SArmin Le Grand #include <comphelper/namedvaluecollection.hxx>
41facb16e7SArmin Le Grand 
42facb16e7SArmin Le Grand #include <boost/bind.hpp>
43facb16e7SArmin Le Grand 
44facb16e7SArmin Le Grand 
45facb16e7SArmin Le Grand using namespace css;
46facb16e7SArmin Le Grand using namespace cssu;
47facb16e7SArmin Le Grand using ::rtl::OUString;
48facb16e7SArmin Le Grand 
49facb16e7SArmin Le Grand 
50facb16e7SArmin Le Grand namespace sc { namespace sidebar {
51facb16e7SArmin Le Grand 
52facb16e7SArmin Le Grand #define A2S(s) ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
53facb16e7SArmin Le Grand #define IMPLEMENTATION_NAME "org.apache.openoffice.comp.sc.sidebar.ScPanelFactory"
54facb16e7SArmin Le Grand #define SERVICE_NAME "com.sun.star.ui.UIElementFactory"
55facb16e7SArmin Le Grand 
56facb16e7SArmin Le Grand 
getImplementationName(void)57facb16e7SArmin Le Grand ::rtl::OUString SAL_CALL ScPanelFactory::getImplementationName (void)
58facb16e7SArmin Le Grand {
59*d1e7c34dSmseidel 	return A2S(IMPLEMENTATION_NAME);
60facb16e7SArmin Le Grand }
61facb16e7SArmin Le Grand 
62facb16e7SArmin Le Grand 
createInstance(const uno::Reference<lang::XMultiServiceFactory> &)63facb16e7SArmin Le Grand cssu::Reference<cssu::XInterface> SAL_CALL ScPanelFactory::createInstance(
64*d1e7c34dSmseidel 	const uno::Reference<lang::XMultiServiceFactory>& )
65facb16e7SArmin Le Grand {
66*d1e7c34dSmseidel 	::rtl::Reference<ScPanelFactory> pPanelFactory (new ScPanelFactory());
67*d1e7c34dSmseidel 	cssu::Reference<cssu::XInterface> xService (static_cast<XWeak*>(pPanelFactory.get()), cssu::UNO_QUERY);
68*d1e7c34dSmseidel 	return xService;
69facb16e7SArmin Le Grand }
70facb16e7SArmin Le Grand 
71facb16e7SArmin Le Grand 
getSupportedServiceNames(void)72facb16e7SArmin Le Grand cssu::Sequence<OUString> SAL_CALL ScPanelFactory::getSupportedServiceNames (void)
73facb16e7SArmin Le Grand {
74*d1e7c34dSmseidel 	cssu::Sequence<OUString> aServiceNames (1);
75*d1e7c34dSmseidel 	aServiceNames[0] = A2S(SERVICE_NAME);
76*d1e7c34dSmseidel 	return aServiceNames;
77facb16e7SArmin Le Grand 
78facb16e7SArmin Le Grand }
79facb16e7SArmin Le Grand 
80facb16e7SArmin Le Grand 
ScPanelFactory(void)81facb16e7SArmin Le Grand ScPanelFactory::ScPanelFactory (void)
82*d1e7c34dSmseidel 	: PanelFactoryInterfaceBase(m_aMutex)
83facb16e7SArmin Le Grand {
84facb16e7SArmin Le Grand }
85facb16e7SArmin Le Grand 
86facb16e7SArmin Le Grand 
~ScPanelFactory(void)87facb16e7SArmin Le Grand ScPanelFactory::~ScPanelFactory (void)
88facb16e7SArmin Le Grand {
89facb16e7SArmin Le Grand }
90facb16e7SArmin Le Grand 
91facb16e7SArmin Le Grand 
createUIElement(const::rtl::OUString & rsResourceURL,const::cssu::Sequence<css::beans::PropertyValue> & rArguments)92facb16e7SArmin Le Grand Reference<ui::XUIElement> SAL_CALL ScPanelFactory::createUIElement (
93*d1e7c34dSmseidel 	const ::rtl::OUString& rsResourceURL,
94*d1e7c34dSmseidel 	const ::cssu::Sequence<css::beans::PropertyValue>& rArguments)
95*d1e7c34dSmseidel 	throw(
96*d1e7c34dSmseidel 		container::NoSuchElementException,
97*d1e7c34dSmseidel 		lang::IllegalArgumentException,
98*d1e7c34dSmseidel 		RuntimeException)
99facb16e7SArmin Le Grand {
100*d1e7c34dSmseidel 	Reference<ui::XUIElement> xElement;
101*d1e7c34dSmseidel 
102*d1e7c34dSmseidel 	const ::comphelper::NamedValueCollection aArguments (rArguments);
103*d1e7c34dSmseidel 	Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>()));
104*d1e7c34dSmseidel 	Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>()));
105*d1e7c34dSmseidel 	const sal_uInt64 nBindingsValue (aArguments.getOrDefault("SfxBindings", sal_uInt64(0)));
106*d1e7c34dSmseidel 	SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue);
107*d1e7c34dSmseidel 
108*d1e7c34dSmseidel 	::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
109*d1e7c34dSmseidel 	if ( ! xParentWindow.is() || pParentWindow==NULL)
110*d1e7c34dSmseidel 		throw RuntimeException(
111*d1e7c34dSmseidel 			A2S("PanelFactory::createUIElement called without ParentWindow"),
112*d1e7c34dSmseidel 			NULL);
113*d1e7c34dSmseidel 	if ( ! xFrame.is())
114*d1e7c34dSmseidel 		throw RuntimeException(
115*d1e7c34dSmseidel 			A2S("PanelFactory::createUIElement called without Frame"),
116*d1e7c34dSmseidel 			NULL);
117*d1e7c34dSmseidel 	if (pBindings == NULL)
118*d1e7c34dSmseidel 		throw RuntimeException(
119*d1e7c34dSmseidel 			A2S("PanelFactory::createUIElement called without SfxBindings"),
120*d1e7c34dSmseidel 			NULL);
121facb16e7SArmin Le Grand 
122facb16e7SArmin Le Grand #define DoesResourceEndWith(s) rsResourceURL.endsWithAsciiL(s,strlen(s))
123*d1e7c34dSmseidel 	if (DoesResourceEndWith("/AlignmentPropertyPanel"))
124*d1e7c34dSmseidel 	{
125*d1e7c34dSmseidel 		AlignmentPropertyPanel* pPanel = AlignmentPropertyPanel::Create( pParentWindow, xFrame, pBindings );
126*d1e7c34dSmseidel 		xElement = sfx2::sidebar::SidebarPanelBase::Create(
127*d1e7c34dSmseidel 			rsResourceURL,
128*d1e7c34dSmseidel 			xFrame,
129*d1e7c34dSmseidel 			pPanel,
130*d1e7c34dSmseidel 			ui::LayoutSize(-1,-1,-1));
131*d1e7c34dSmseidel 	}
132*d1e7c34dSmseidel 	else if (DoesResourceEndWith("/CellAppearancePropertyPanel"))
133*d1e7c34dSmseidel 	{
134*d1e7c34dSmseidel 		CellAppearancePropertyPanel* pPanel = CellAppearancePropertyPanel::Create( pParentWindow, xFrame, pBindings );
135*d1e7c34dSmseidel 		xElement = sfx2::sidebar::SidebarPanelBase::Create(
136*d1e7c34dSmseidel 			rsResourceURL,
137*d1e7c34dSmseidel 			xFrame,
138*d1e7c34dSmseidel 			pPanel,
139*d1e7c34dSmseidel 			ui::LayoutSize(-1,-1,-1));
140*d1e7c34dSmseidel 	}
141*d1e7c34dSmseidel 	else if (DoesResourceEndWith("/NumberFormatPropertyPanel"))
142*d1e7c34dSmseidel 	{
143*d1e7c34dSmseidel 		NumberFormatPropertyPanel* pPanel = NumberFormatPropertyPanel::Create( pParentWindow, xFrame, pBindings );
144*d1e7c34dSmseidel 		xElement = sfx2::sidebar::SidebarPanelBase::Create(
145*d1e7c34dSmseidel 			rsResourceURL,
146*d1e7c34dSmseidel 			xFrame,
147*d1e7c34dSmseidel 			pPanel,
148*d1e7c34dSmseidel 			ui::LayoutSize(-1,-1,-1));
149*d1e7c34dSmseidel 	}
150*d1e7c34dSmseidel 	else if (DoesResourceEndWith("/NavigatorPanel"))
151*d1e7c34dSmseidel 	{
152*d1e7c34dSmseidel 		Window* pPanel = new ScNavigatorDlg(pBindings, NULL, pParentWindow, false);
153*d1e7c34dSmseidel 		xElement = sfx2::sidebar::SidebarPanelBase::Create(
154*d1e7c34dSmseidel 			rsResourceURL,
155*d1e7c34dSmseidel 			xFrame,
156*d1e7c34dSmseidel 			pPanel,
157*d1e7c34dSmseidel 			ui::LayoutSize(0,-1,-1));
158*d1e7c34dSmseidel 	}
159*d1e7c34dSmseidel 	else if (DoesResourceEndWith("/FunctionsPanel"))
160*d1e7c34dSmseidel 	{
161*d1e7c34dSmseidel 		Window* pPanel = new ScFunctionDockWin(pBindings, NULL, pParentWindow, ScResId(FID_FUNCTION_BOX));
162*d1e7c34dSmseidel 		xElement = sfx2::sidebar::SidebarPanelBase::Create(
163*d1e7c34dSmseidel 			rsResourceURL,
164*d1e7c34dSmseidel 			xFrame,
165*d1e7c34dSmseidel 			pPanel,
166*d1e7c34dSmseidel 			ui::LayoutSize(0,-1,-1));
167*d1e7c34dSmseidel 	}
168facb16e7SArmin Le Grand #undef DoesResourceEndWith
169facb16e7SArmin Le Grand 
170*d1e7c34dSmseidel 	return xElement;
171facb16e7SArmin Le Grand }
172facb16e7SArmin Le Grand 
173facb16e7SArmin Le Grand } } // end of namespace sc::sidebar
174facb16e7SArmin Le Grand 
175*d1e7c34dSmseidel /* vim: set noet sw=4 ts=4: */
176