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 #include <com/sun/star/ui/XSidebar.hpp>
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     const ::comphelper::NamedValueCollection aArguments (rArguments);
115     Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>()));
116     Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>()));
117     Reference<ui::XSidebar> xSidebar (aArguments.getOrDefault("Sidebar", Reference<ui::XSidebar>()));
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     Window* pControl = NULL;
136     ui::LayoutSize aLayoutSize (-1,-1,-1);
137 
138 #define DoesResourceEndWith(s) rsResourceURL.endsWithAsciiL(s,strlen(s))
139     if (DoesResourceEndWith("/TextPropertyPanel"))
140     {
141         pControl = TextPropertyPanel::Create(pParentWindow, xFrame, pBindings, xSidebar);
142     }
143     else if (DoesResourceEndWith("/ParaPropertyPanel"))
144     {
145         pControl = ParaPropertyPanel::Create(pParentWindow, xFrame, pBindings, xSidebar);
146     }
147     else if (DoesResourceEndWith("/AreaPropertyPanel"))
148     {
149         pControl = AreaPropertyPanel::Create(pParentWindow, xFrame, pBindings);
150     }
151     else if (DoesResourceEndWith("/GraphicPropertyPanel"))
152     {
153         pControl = GraphicPropertyPanel::Create(pParentWindow, xFrame, pBindings);
154     }
155     else if (DoesResourceEndWith("/LinePropertyPanel"))
156     {
157         pControl = LinePropertyPanel::Create(pParentWindow, xFrame, pBindings);
158     }
159     else if (DoesResourceEndWith("/PosSizePropertyPanel"))
160     {
161         pControl = PosSizePropertyPanel::Create(pParentWindow, xFrame, pBindings, xSidebar);
162     }
163     else if (DoesResourceEndWith("/GalleryPanel"))
164     {
165         pControl = new GalleryControl(pBindings, pParentWindow);
166         aLayoutSize = ui::LayoutSize(300,-1,400);
167     }
168     else if (DoesResourceEndWith("/StyleListPanel"))
169     {
170         pControl = new SfxTemplatePanelControl(pBindings, pParentWindow);
171         aLayoutSize = ui::LayoutSize(0,-1,-1);
172     }
173     else if (DoesResourceEndWith("/Debug_ColorPanel"))
174     {
175         pControl = new ColorPanel(pParentWindow);
176         aLayoutSize = ui::LayoutSize(300,-1,400);
177     }
178     else if (DoesResourceEndWith("/Debug_ContextPanel"))
179     {
180         pControl = new ContextPanel(pParentWindow);
181         aLayoutSize = ui::LayoutSize(45,45,45);
182     }
183     else if (DoesResourceEndWith("/Debug_NotYetImplementedPanel"))
184     {
185         pControl = new NotYetImplementedPanel(pParentWindow);
186         aLayoutSize = ui::LayoutSize(20,25,25);
187     }
188     else if (DoesResourceEndWith("/EmptyPanel"))
189     {
190         pControl = new EmptyPanel(pParentWindow);
191         aLayoutSize = ui::LayoutSize(20,-1, 50);
192     }
193 #undef DoesResourceEndWith
194 
195     if (pControl != NULL)
196     {
197         return sfx2::sidebar::SidebarPanelBase::Create(
198             rsResourceURL,
199             xFrame,
200             pControl,
201             aLayoutSize);
202     }
203     else
204         return Reference<ui::XUIElement>();
205 }
206 
207 } } // end of namespace svx::sidebar
208 
209 // eof
210