1facb16e7SArmin Le Grand /**************************************************************
2facb16e7SArmin Le Grand  *
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
10facb16e7SArmin Le Grand  *
11facb16e7SArmin Le Grand  *   http://www.apache.org/licenses/LICENSE-2.0
12facb16e7SArmin Le Grand  *
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.
19facb16e7SArmin Le Grand  *
20facb16e7SArmin Le Grand  *************************************************************/
21facb16e7SArmin Le Grand 
22facb16e7SArmin Le Grand #include "precompiled_sc.hxx"
23facb16e7SArmin Le Grand 
24facb16e7SArmin Le Grand #include "ScPanelFactory.hxx"
25facb16e7SArmin Le Grand 
26facb16e7SArmin Le Grand #include <AlignmentPropertyPanel.hxx>
27facb16e7SArmin Le Grand #include <CellAppearancePropertyPanel.hxx>
28*4e8031e0SArmin Le Grand #include <NumberFormatPropertyPanel.hxx>
29facb16e7SArmin Le Grand 
30facb16e7SArmin Le Grand #include <sfx2/sidebar/SidebarPanelBase.hxx>
31facb16e7SArmin Le Grand #include <sfx2/sfxbasecontroller.hxx>
32facb16e7SArmin Le Grand #include <toolkit/helper/vclunohelper.hxx>
33facb16e7SArmin Le Grand #include <vcl/window.hxx>
34facb16e7SArmin Le Grand #include <rtl/ref.hxx>
35facb16e7SArmin Le Grand #include <comphelper/namedvaluecollection.hxx>
36facb16e7SArmin Le Grand 
37facb16e7SArmin Le Grand #include <boost/bind.hpp>
38facb16e7SArmin Le Grand 
39facb16e7SArmin Le Grand 
40facb16e7SArmin Le Grand using namespace css;
41facb16e7SArmin Le Grand using namespace cssu;
42facb16e7SArmin Le Grand using ::rtl::OUString;
43facb16e7SArmin Le Grand 
44facb16e7SArmin Le Grand 
45facb16e7SArmin Le Grand namespace sc { namespace sidebar {
46facb16e7SArmin Le Grand 
47facb16e7SArmin Le Grand #define A2S(s) ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
48facb16e7SArmin Le Grand #define IMPLEMENTATION_NAME "org.apache.openoffice.comp.sc.sidebar.ScPanelFactory"
49facb16e7SArmin Le Grand #define SERVICE_NAME "com.sun.star.ui.UIElementFactory"
50facb16e7SArmin Le Grand 
51facb16e7SArmin Le Grand 
52facb16e7SArmin Le Grand ::rtl::OUString SAL_CALL ScPanelFactory::getImplementationName (void)
53facb16e7SArmin Le Grand {
54facb16e7SArmin Le Grand     return A2S(IMPLEMENTATION_NAME);
55facb16e7SArmin Le Grand }
56facb16e7SArmin Le Grand 
57facb16e7SArmin Le Grand 
58facb16e7SArmin Le Grand cssu::Reference<cssu::XInterface> SAL_CALL ScPanelFactory::createInstance(
59facb16e7SArmin Le Grand     const uno::Reference<lang::XMultiServiceFactory>& )
60facb16e7SArmin Le Grand {
61facb16e7SArmin Le Grand     ::rtl::Reference<ScPanelFactory> pPanelFactory (new ScPanelFactory());
62facb16e7SArmin Le Grand     cssu::Reference<cssu::XInterface> xService (static_cast<XWeak*>(pPanelFactory.get()), cssu::UNO_QUERY);
63facb16e7SArmin Le Grand     return xService;
64facb16e7SArmin Le Grand }
65facb16e7SArmin Le Grand 
66facb16e7SArmin Le Grand 
67facb16e7SArmin Le Grand cssu::Sequence<OUString> SAL_CALL ScPanelFactory::getSupportedServiceNames (void)
68facb16e7SArmin Le Grand {
69facb16e7SArmin Le Grand     cssu::Sequence<OUString> aServiceNames (1);
70facb16e7SArmin Le Grand     aServiceNames[0] = A2S(SERVICE_NAME);
71facb16e7SArmin Le Grand     return aServiceNames;
72facb16e7SArmin Le Grand 
73facb16e7SArmin Le Grand }
74facb16e7SArmin Le Grand 
75facb16e7SArmin Le Grand 
76facb16e7SArmin Le Grand ScPanelFactory::ScPanelFactory (void)
77facb16e7SArmin Le Grand     : PanelFactoryInterfaceBase(m_aMutex)
78facb16e7SArmin Le Grand {
79facb16e7SArmin Le Grand }
80facb16e7SArmin Le Grand 
81facb16e7SArmin Le Grand 
82facb16e7SArmin Le Grand ScPanelFactory::~ScPanelFactory (void)
83facb16e7SArmin Le Grand {
84facb16e7SArmin Le Grand }
85facb16e7SArmin Le Grand 
86facb16e7SArmin Le Grand 
87facb16e7SArmin Le Grand Reference<ui::XUIElement> SAL_CALL ScPanelFactory::createUIElement (
88facb16e7SArmin Le Grand     const ::rtl::OUString& rsResourceURL,
89facb16e7SArmin Le Grand     const ::cssu::Sequence<css::beans::PropertyValue>& rArguments)
90facb16e7SArmin Le Grand     throw(
91facb16e7SArmin Le Grand         container::NoSuchElementException,
92facb16e7SArmin Le Grand         lang::IllegalArgumentException,
93facb16e7SArmin Le Grand         RuntimeException)
94facb16e7SArmin Le Grand {
95facb16e7SArmin Le Grand     Reference<ui::XUIElement> xElement;
96facb16e7SArmin Le Grand 
97facb16e7SArmin Le Grand     const ::comphelper::NamedValueCollection aArguments (rArguments);
98facb16e7SArmin Le Grand     Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>()));
99facb16e7SArmin Le Grand     Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>()));
100facb16e7SArmin Le Grand     const sal_uInt64 nBindingsValue (aArguments.getOrDefault("SfxBindings", sal_uInt64(0)));
101facb16e7SArmin Le Grand     SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue);
102facb16e7SArmin Le Grand 
103facb16e7SArmin Le Grand     ::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
104facb16e7SArmin Le Grand     if ( ! xParentWindow.is() || pParentWindow==NULL)
105facb16e7SArmin Le Grand         throw RuntimeException(
106facb16e7SArmin Le Grand             A2S("PanelFactory::createUIElement called without ParentWindow"),
107facb16e7SArmin Le Grand             NULL);
108facb16e7SArmin Le Grand     if ( ! xFrame.is())
109facb16e7SArmin Le Grand         throw RuntimeException(
110facb16e7SArmin Le Grand             A2S("PanelFactory::createUIElement called without Frame"),
111facb16e7SArmin Le Grand             NULL);
112facb16e7SArmin Le Grand     if (pBindings == NULL)
113facb16e7SArmin Le Grand         throw RuntimeException(
114facb16e7SArmin Le Grand             A2S("PanelFactory::createUIElement called without SfxBindings"),
115facb16e7SArmin Le Grand             NULL);
116facb16e7SArmin Le Grand 
117facb16e7SArmin Le Grand #define DoesResourceEndWith(s) rsResourceURL.endsWithAsciiL(s,strlen(s))
118facb16e7SArmin Le Grand     if (DoesResourceEndWith("/AlignmentPropertyPanel"))
119facb16e7SArmin Le Grand     {
120facb16e7SArmin Le Grand         AlignmentPropertyPanel* pPanel = AlignmentPropertyPanel::Create( pParentWindow, xFrame, pBindings );
121facb16e7SArmin Le Grand         xElement = sfx2::sidebar::SidebarPanelBase::Create(
122facb16e7SArmin Le Grand             rsResourceURL,
123facb16e7SArmin Le Grand             xFrame,
124facb16e7SArmin Le Grand             pPanel,
125facb16e7SArmin Le Grand             ui::LayoutSize(-1,-1,-1));
126facb16e7SArmin Le Grand     }
127*4e8031e0SArmin Le Grand     else if (DoesResourceEndWith("/CellAppearancePropertyPanel"))
128facb16e7SArmin Le Grand     {
129facb16e7SArmin Le Grand         CellAppearancePropertyPanel* pPanel = CellAppearancePropertyPanel::Create( pParentWindow, xFrame, pBindings );
130facb16e7SArmin Le Grand         xElement = sfx2::sidebar::SidebarPanelBase::Create(
131facb16e7SArmin Le Grand             rsResourceURL,
132facb16e7SArmin Le Grand             xFrame,
133facb16e7SArmin Le Grand             pPanel,
134facb16e7SArmin Le Grand             ui::LayoutSize(-1,-1,-1));
135facb16e7SArmin Le Grand     }
136*4e8031e0SArmin Le Grand     else if (DoesResourceEndWith("/NumberFormatPropertyPanel"))
137*4e8031e0SArmin Le Grand     {
138*4e8031e0SArmin Le Grand         NumberFormatPropertyPanel* pPanel = NumberFormatPropertyPanel::Create( pParentWindow, xFrame, pBindings );
139*4e8031e0SArmin Le Grand         xElement = sfx2::sidebar::SidebarPanelBase::Create(
140*4e8031e0SArmin Le Grand             rsResourceURL,
141*4e8031e0SArmin Le Grand             xFrame,
142*4e8031e0SArmin Le Grand             pPanel,
143*4e8031e0SArmin Le Grand             ui::LayoutSize(-1,-1,-1));
144*4e8031e0SArmin Le Grand     }
145facb16e7SArmin Le Grand #undef DoesResourceEndWith
146facb16e7SArmin Le Grand 
147facb16e7SArmin Le Grand     return xElement;
148facb16e7SArmin Le Grand }
149facb16e7SArmin Le Grand 
150facb16e7SArmin Le Grand } } // end of namespace sc::sidebar
151facb16e7SArmin Le Grand 
152facb16e7SArmin Le Grand // eof
153