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