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