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