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