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 "sidebar/PanelFactory.hxx"
23 
24 #include "text/TextPropertyPanel.hxx"
25 #include "paragraph/ParaPropertyPanel.hxx"
26 #include "area/AreaPropertyPanel.hxx"
27 #include "graphic/GraphicPropertyPanel.hxx"
28 #include "line/LinePropertyPanel.hxx"
29 #include "possize/PosSizePropertyPanel.hxx"
30 #include "GalleryControl.hxx"
31 #include "debug/ColorPanel.hxx"
32 #include "debug/ContextPanel.hxx"
33 #include "debug/NotYetImplementedPanel.hxx"
34 #include "EmptyPanel.hxx"
35 #include <sfx2/sidebar/SidebarPanelBase.hxx>
36 #include <sfx2/sfxbasecontroller.hxx>
37 #include <sfx2/templdlg.hxx>
38 #include <toolkit/helper/vclunohelper.hxx>
39 #include <vcl/window.hxx>
40 #include <rtl/ref.hxx>
41 #include <comphelper/namedvaluecollection.hxx>
42 
43 
44 #include <boost/bind.hpp>
45 
46 
47 using namespace css;
48 using namespace cssu;
49 using ::rtl::OUString;
50 
51 
52 namespace svx { namespace sidebar {
53 
54 #define A2S(s) ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
55 #define IMPLEMENTATION_NAME "org.apache.openoffice.comp.svx.sidebar.PanelFactory"
56 #define SERVICE_NAME "com.sun.star.ui.UIElementFactory"
57 
58 
59 ::rtl::OUString SAL_CALL PanelFactory::getImplementationName (void)
60 {
61     return A2S(IMPLEMENTATION_NAME);
62 }
63 
64 
65 
66 
67 cssu::Reference<cssu::XInterface> SAL_CALL PanelFactory::createInstance (
68     const uno::Reference<lang::XMultiServiceFactory>& rxFactory)
69 {
70     (void)rxFactory;
71 
72     ::rtl::Reference<PanelFactory> pPanelFactory (new PanelFactory());
73     cssu::Reference<cssu::XInterface> xService (static_cast<XWeak*>(pPanelFactory.get()), cssu::UNO_QUERY);
74     return xService;
75 }
76 
77 
78 
79 
80 cssu::Sequence<OUString> SAL_CALL PanelFactory::getSupportedServiceNames (void)
81 {
82     cssu::Sequence<OUString> aServiceNames (1);
83     aServiceNames[0] = A2S(SERVICE_NAME);
84     return aServiceNames;
85 
86 }
87 
88 
89 
90 
91 PanelFactory::PanelFactory (void)
92     : PanelFactoryInterfaceBase(m_aMutex)
93 {
94 }
95 
96 
97 
98 
99 PanelFactory::~PanelFactory (void)
100 {
101 }
102 
103 
104 
105 
106 Reference<ui::XUIElement> SAL_CALL PanelFactory::createUIElement (
107     const ::rtl::OUString& rsResourceURL,
108     const ::cssu::Sequence<css::beans::PropertyValue>& rArguments)
109     throw(
110         container::NoSuchElementException,
111         lang::IllegalArgumentException,
112         RuntimeException)
113 {
114     Reference<ui::XUIElement> xElement;
115 
116     const ::comphelper::NamedValueCollection aArguments (rArguments);
117     Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>()));
118     Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>()));
119     const sal_uInt64 nBindingsValue (aArguments.getOrDefault("SfxBindings", sal_uInt64(0)));
120     SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue);
121 
122     ::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
123     if ( ! xParentWindow.is() || pParentWindow==NULL)
124         throw RuntimeException(
125             A2S("PanelFactory::createUIElement called without ParentWindow"),
126             NULL);
127     if ( ! xFrame.is())
128         throw RuntimeException(
129             A2S("PanelFactory::createUIElement called without Frame"),
130             NULL);
131     if (pBindings == NULL)
132         throw RuntimeException(
133             A2S("PanelFactory::createUIElement called without SfxBindings"),
134             NULL);
135 
136 #define DoesResourceEndWith(s) rsResourceURL.endsWithAsciiL(s,strlen(s))
137     if (DoesResourceEndWith("/TextPropertyPanel"))
138     {
139         TextPropertyPanel* pPanel = TextPropertyPanel::Create(pParentWindow, xFrame, pBindings);
140         xElement = sfx2::sidebar::SidebarPanelBase::Create(
141             rsResourceURL,
142             xFrame,
143             pPanel,
144             ui::LayoutSize(-1,-1,-1));
145     }
146     if (DoesResourceEndWith("/ParaPropertyPanel"))
147     {
148         ParaPropertyPanel* pPanel = ParaPropertyPanel::Create(pParentWindow, xFrame, pBindings);
149         xElement = sfx2::sidebar::SidebarPanelBase::Create(
150             rsResourceURL,
151             xFrame,
152             pPanel,
153             //::boost::bind(&ParaPropertyPanel::ShowMenu, pPanel),
154             ui::LayoutSize(-1,-1,-1));
155     }
156     else if (DoesResourceEndWith("/AreaPropertyPanel"))
157     {
158         AreaPropertyPanel* pPanel = AreaPropertyPanel::Create(pParentWindow, xFrame, pBindings);
159         xElement = sfx2::sidebar::SidebarPanelBase::Create(
160             rsResourceURL,
161             xFrame,
162             pPanel,
163             ui::LayoutSize(-1,-1,-1));
164     }
165     else if (DoesResourceEndWith("/GraphicPropertyPanel"))
166     {
167         GraphicPropertyPanel* pPanel = GraphicPropertyPanel::Create(pParentWindow, xFrame, pBindings);
168         xElement = sfx2::sidebar::SidebarPanelBase::Create(
169             rsResourceURL,
170             xFrame,
171             pPanel,
172             ui::LayoutSize(-1,-1,-1));
173     }
174     else if (DoesResourceEndWith("/LinePropertyPanel"))
175     {
176         LinePropertyPanel* pPanel = LinePropertyPanel::Create(pParentWindow, xFrame, pBindings);
177         xElement = sfx2::sidebar::SidebarPanelBase::Create(
178             rsResourceURL,
179             xFrame,
180             pPanel,
181             ui::LayoutSize(-1,-1,-1));
182     }
183     else if (DoesResourceEndWith("/PosSizePropertyPanel"))
184     {
185         PosSizePropertyPanel* pPanel = PosSizePropertyPanel::Create(pParentWindow, xFrame, pBindings);
186         xElement = sfx2::sidebar::SidebarPanelBase::Create(
187             rsResourceURL,
188             xFrame,
189             pPanel,
190             ui::LayoutSize(-1,-1,-1));
191     }
192     else if (DoesResourceEndWith("/GalleryPanel"))
193     {
194         GalleryControl* pGalleryControl = new GalleryControl(
195             pBindings,
196             pParentWindow);
197         xElement = sfx2::sidebar::SidebarPanelBase::Create(
198             rsResourceURL,
199             xFrame,
200             pGalleryControl,
201             ui::LayoutSize(300,-1,400));
202     }
203     else if (DoesResourceEndWith("/StyleListPanel"))
204     {
205         Window* pControl = new SfxTemplatePanelControl(pBindings, pParentWindow);
206         xElement = sfx2::sidebar::SidebarPanelBase::Create(
207             rsResourceURL,
208             xFrame,
209             pControl,
210             ui::LayoutSize(0,-1,-1));
211     }
212     else if (DoesResourceEndWith("/Debug_ColorPanel"))
213     {
214         ColorPanel* pPanel = new ColorPanel(pParentWindow);
215         xElement = sfx2::sidebar::SidebarPanelBase::Create(
216             rsResourceURL,
217             xFrame,
218             pPanel,
219             ui::LayoutSize(300,-1,400));
220     }
221     else if (DoesResourceEndWith("/Debug_ContextPanel"))
222     {
223         ContextPanel* pPanel = new ContextPanel(pParentWindow);
224         xElement = sfx2::sidebar::SidebarPanelBase::Create(
225             rsResourceURL,
226             xFrame,
227             pPanel,
228             ui::LayoutSize(45,45,45));
229     }
230     else if (DoesResourceEndWith("/Debug_NotYetImplementedPanel"))
231     {
232         NotYetImplementedPanel* pPanel = new NotYetImplementedPanel(pParentWindow);
233         xElement = sfx2::sidebar::SidebarPanelBase::Create(
234             rsResourceURL,
235             xFrame,
236             pPanel,
237             ui::LayoutSize(20,25,25));
238     }
239     else if (DoesResourceEndWith("/EmptyPanel"))
240     {
241         EmptyPanel* pPanel = new EmptyPanel(pParentWindow);
242         xElement = sfx2::sidebar::SidebarPanelBase::Create(
243             rsResourceURL,
244             xFrame,
245             pPanel,
246             ui::LayoutSize(20,-1, 50));
247     }
248 #undef DoesResourceEndWith
249 
250     return xElement;
251 }
252 
253 } } // end of namespace svx::sidebar
254 
255 // eof
256