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