xref: /trunk/main/svx/source/sidebar/PanelFactory.cxx (revision f35c6d02e275b54a359e950b36624d15e547eb6e)
1b9e67834SAndre Fischer /**************************************************************
2b9e67834SAndre Fischer  *
3b9e67834SAndre Fischer  * Licensed to the Apache Software Foundation (ASF) under one
4b9e67834SAndre Fischer  * or more contributor license agreements.  See the NOTICE file
5b9e67834SAndre Fischer  * distributed with this work for additional information
6b9e67834SAndre Fischer  * regarding copyright ownership.  The ASF licenses this file
7b9e67834SAndre Fischer  * to you under the Apache License, Version 2.0 (the
8b9e67834SAndre Fischer  * "License"); you may not use this file except in compliance
9b9e67834SAndre Fischer  * with the License.  You may obtain a copy of the License at
10b9e67834SAndre Fischer  *
11b9e67834SAndre Fischer  *   http://www.apache.org/licenses/LICENSE-2.0
12b9e67834SAndre Fischer  *
13b9e67834SAndre Fischer  * Unless required by applicable law or agreed to in writing,
14b9e67834SAndre Fischer  * software distributed under the License is distributed on an
15b9e67834SAndre Fischer  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b9e67834SAndre Fischer  * KIND, either express or implied.  See the License for the
17b9e67834SAndre Fischer  * specific language governing permissions and limitations
18b9e67834SAndre Fischer  * under the License.
19b9e67834SAndre Fischer  *
20b9e67834SAndre Fischer  *************************************************************/
21b9e67834SAndre Fischer 
22b9e67834SAndre Fischer #include "sidebar/PanelFactory.hxx"
23b9e67834SAndre Fischer 
2402c50d82SAndre Fischer #include "text/TextPropertyPanel.hxx"
25766ce4d0SZheng Fan #include "paragraph/ParaPropertyPanel.hxx"
268dcb2a10SAndre Fischer #include "area/AreaPropertyPanel.hxx"
278dcb2a10SAndre Fischer #include "graphic/GraphicPropertyPanel.hxx"
288dcb2a10SAndre Fischer #include "line/LinePropertyPanel.hxx"
29ee093554SAndre Fischer #include "possize/PosSizePropertyPanel.hxx"
30*f35c6d02SAndre Fischer #include "insert/InsertPropertyPanel.hxx"
31a8eaca58SAndre Fischer #include "GalleryControl.hxx"
32f120fe41SAndre Fischer #include "debug/ColorPanel.hxx"
33f120fe41SAndre Fischer #include "debug/ContextPanel.hxx"
34f120fe41SAndre Fischer #include "debug/NotYetImplementedPanel.hxx"
35f120fe41SAndre Fischer #include "EmptyPanel.hxx"
3695a18594SAndre Fischer #include <sfx2/sidebar/SidebarPanelBase.hxx>
3795a18594SAndre Fischer #include <sfx2/sfxbasecontroller.hxx>
38bd7afb38SAndre Fischer #include <sfx2/templdlg.hxx>
39b9e67834SAndre Fischer #include <toolkit/helper/vclunohelper.hxx>
40b9e67834SAndre Fischer #include <vcl/window.hxx>
41b9e67834SAndre Fischer #include <rtl/ref.hxx>
427a32b0c8SAndre Fischer #include <comphelper/namedvaluecollection.hxx>
4337fee4fdSAndre Fischer #include <com/sun/star/ui/XSidebar.hpp>
4402c50d82SAndre Fischer 
457a32b0c8SAndre Fischer #include <boost/bind.hpp>
46b9e67834SAndre Fischer 
47b9e67834SAndre Fischer 
48b9e67834SAndre Fischer using namespace css;
49b9e67834SAndre Fischer using namespace cssu;
50b9e67834SAndre Fischer using ::rtl::OUString;
51b9e67834SAndre Fischer 
52b9e67834SAndre Fischer 
53b9e67834SAndre Fischer namespace svx { namespace sidebar {
54b9e67834SAndre Fischer 
55b9e67834SAndre Fischer #define A2S(s) ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
56b9e67834SAndre Fischer #define IMPLEMENTATION_NAME "org.apache.openoffice.comp.svx.sidebar.PanelFactory"
57b9e67834SAndre Fischer #define SERVICE_NAME "com.sun.star.ui.UIElementFactory"
58b9e67834SAndre Fischer 
59b9e67834SAndre Fischer 
60b9e67834SAndre Fischer ::rtl::OUString SAL_CALL PanelFactory::getImplementationName (void)
61b9e67834SAndre Fischer {
62b9e67834SAndre Fischer     return A2S(IMPLEMENTATION_NAME);
63b9e67834SAndre Fischer }
64b9e67834SAndre Fischer 
65b9e67834SAndre Fischer 
66b9e67834SAndre Fischer 
67b9e67834SAndre Fischer 
68b9e67834SAndre Fischer cssu::Reference<cssu::XInterface> SAL_CALL PanelFactory::createInstance (
69b9e67834SAndre Fischer     const uno::Reference<lang::XMultiServiceFactory>& rxFactory)
70b9e67834SAndre Fischer {
71b9e67834SAndre Fischer     (void)rxFactory;
72b9e67834SAndre Fischer 
73b9e67834SAndre Fischer     ::rtl::Reference<PanelFactory> pPanelFactory (new PanelFactory());
74b9e67834SAndre Fischer     cssu::Reference<cssu::XInterface> xService (static_cast<XWeak*>(pPanelFactory.get()), cssu::UNO_QUERY);
75b9e67834SAndre Fischer     return xService;
76b9e67834SAndre Fischer }
77b9e67834SAndre Fischer 
78b9e67834SAndre Fischer 
79b9e67834SAndre Fischer 
80b9e67834SAndre Fischer 
81b9e67834SAndre Fischer cssu::Sequence<OUString> SAL_CALL PanelFactory::getSupportedServiceNames (void)
82b9e67834SAndre Fischer {
83b9e67834SAndre Fischer     cssu::Sequence<OUString> aServiceNames (1);
84b9e67834SAndre Fischer     aServiceNames[0] = A2S(SERVICE_NAME);
85b9e67834SAndre Fischer     return aServiceNames;
86b9e67834SAndre Fischer 
87b9e67834SAndre Fischer }
88b9e67834SAndre Fischer 
89b9e67834SAndre Fischer 
90b9e67834SAndre Fischer 
91b9e67834SAndre Fischer 
92b9e67834SAndre Fischer PanelFactory::PanelFactory (void)
93b9e67834SAndre Fischer     : PanelFactoryInterfaceBase(m_aMutex)
94b9e67834SAndre Fischer {
95b9e67834SAndre Fischer }
96b9e67834SAndre Fischer 
97b9e67834SAndre Fischer 
98b9e67834SAndre Fischer 
99b9e67834SAndre Fischer 
100b9e67834SAndre Fischer PanelFactory::~PanelFactory (void)
101b9e67834SAndre Fischer {
102b9e67834SAndre Fischer }
103b9e67834SAndre Fischer 
104b9e67834SAndre Fischer 
105b9e67834SAndre Fischer 
106b9e67834SAndre Fischer 
107b9e67834SAndre Fischer Reference<ui::XUIElement> SAL_CALL PanelFactory::createUIElement (
108b9e67834SAndre Fischer     const ::rtl::OUString& rsResourceURL,
109b9e67834SAndre Fischer     const ::cssu::Sequence<css::beans::PropertyValue>& rArguments)
110b9e67834SAndre Fischer     throw(
111b9e67834SAndre Fischer         container::NoSuchElementException,
112b9e67834SAndre Fischer         lang::IllegalArgumentException,
113b9e67834SAndre Fischer         RuntimeException)
114b9e67834SAndre Fischer {
1157a32b0c8SAndre Fischer     const ::comphelper::NamedValueCollection aArguments (rArguments);
1167a32b0c8SAndre Fischer     Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>()));
1177a32b0c8SAndre Fischer     Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>()));
11837fee4fdSAndre Fischer     Reference<ui::XSidebar> xSidebar (aArguments.getOrDefault("Sidebar", Reference<ui::XSidebar>()));
1197a32b0c8SAndre Fischer     const sal_uInt64 nBindingsValue (aArguments.getOrDefault("SfxBindings", sal_uInt64(0)));
1207a32b0c8SAndre Fischer     SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue);
121b9e67834SAndre Fischer 
122b9e67834SAndre Fischer     ::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
123b9e67834SAndre Fischer     if ( ! xParentWindow.is() || pParentWindow==NULL)
124b9e67834SAndre Fischer         throw RuntimeException(
125b9e67834SAndre Fischer             A2S("PanelFactory::createUIElement called without ParentWindow"),
126b9e67834SAndre Fischer             NULL);
127b9e67834SAndre Fischer     if ( ! xFrame.is())
128b9e67834SAndre Fischer         throw RuntimeException(
129b9e67834SAndre Fischer             A2S("PanelFactory::createUIElement called without Frame"),
130b9e67834SAndre Fischer             NULL);
131b9e67834SAndre Fischer     if (pBindings == NULL)
132b9e67834SAndre Fischer         throw RuntimeException(
133b9e67834SAndre Fischer             A2S("PanelFactory::createUIElement called without SfxBindings"),
134b9e67834SAndre Fischer             NULL);
135b9e67834SAndre Fischer 
13637fee4fdSAndre Fischer     Window* pControl = NULL;
13737fee4fdSAndre Fischer     ui::LayoutSize aLayoutSize (-1,-1,-1);
13837fee4fdSAndre Fischer 
13902c50d82SAndre Fischer #define DoesResourceEndWith(s) rsResourceURL.endsWithAsciiL(s,strlen(s))
14002c50d82SAndre Fischer     if (DoesResourceEndWith("/TextPropertyPanel"))
14195a18594SAndre Fischer     {
142f79579d2SAndre Fischer         pControl = TextPropertyPanel::Create(pParentWindow, xFrame, pBindings);
14395a18594SAndre Fischer     }
14437fee4fdSAndre Fischer     else if (DoesResourceEndWith("/ParaPropertyPanel"))
145766ce4d0SZheng Fan     {
14637fee4fdSAndre Fischer         pControl = ParaPropertyPanel::Create(pParentWindow, xFrame, pBindings, xSidebar);
147766ce4d0SZheng Fan     }
14802c50d82SAndre Fischer     else if (DoesResourceEndWith("/AreaPropertyPanel"))
14966c1fc23SArmin Le Grand     {
15037fee4fdSAndre Fischer         pControl = AreaPropertyPanel::Create(pParentWindow, xFrame, pBindings);
15166c1fc23SArmin Le Grand     }
15202c50d82SAndre Fischer     else if (DoesResourceEndWith("/GraphicPropertyPanel"))
1532bdfcea1SArmin Le Grand     {
15437fee4fdSAndre Fischer         pControl = GraphicPropertyPanel::Create(pParentWindow, xFrame, pBindings);
1552bdfcea1SArmin Le Grand     }
15602c50d82SAndre Fischer     else if (DoesResourceEndWith("/LinePropertyPanel"))
15758e893aeSArmin Le Grand     {
15837fee4fdSAndre Fischer         pControl = LinePropertyPanel::Create(pParentWindow, xFrame, pBindings);
15958e893aeSArmin Le Grand     }
160ee093554SAndre Fischer     else if (DoesResourceEndWith("/PosSizePropertyPanel"))
16135fa8f12SArmin Le Grand     {
16237fee4fdSAndre Fischer         pControl = PosSizePropertyPanel::Create(pParentWindow, xFrame, pBindings, xSidebar);
16335fa8f12SArmin Le Grand     }
164*f35c6d02SAndre Fischer     else if (DoesResourceEndWith("/InsertPropertyPanel"))
165*f35c6d02SAndre Fischer     {
166*f35c6d02SAndre Fischer         pControl = new InsertPropertyPanel(pParentWindow, xFrame);
167*f35c6d02SAndre Fischer     }
16802c50d82SAndre Fischer     else if (DoesResourceEndWith("/GalleryPanel"))
16902c50d82SAndre Fischer     {
17037fee4fdSAndre Fischer         pControl = new GalleryControl(pBindings, pParentWindow);
17137fee4fdSAndre Fischer         aLayoutSize = ui::LayoutSize(300,-1,400);
17202c50d82SAndre Fischer     }
173bd7afb38SAndre Fischer     else if (DoesResourceEndWith("/StyleListPanel"))
174bd7afb38SAndre Fischer     {
17537fee4fdSAndre Fischer         pControl = new SfxTemplatePanelControl(pBindings, pParentWindow);
17637fee4fdSAndre Fischer         aLayoutSize = ui::LayoutSize(0,-1,-1);
177bd7afb38SAndre Fischer     }
1782d839242SAndre Fischer     else if (DoesResourceEndWith("/Debug_ColorPanel"))
1792d839242SAndre Fischer     {
18037fee4fdSAndre Fischer         pControl = new ColorPanel(pParentWindow);
18137fee4fdSAndre Fischer         aLayoutSize = ui::LayoutSize(300,-1,400);
1822d839242SAndre Fischer     }
183f120fe41SAndre Fischer     else if (DoesResourceEndWith("/Debug_ContextPanel"))
184f120fe41SAndre Fischer     {
18537fee4fdSAndre Fischer         pControl = new ContextPanel(pParentWindow);
18637fee4fdSAndre Fischer         aLayoutSize = ui::LayoutSize(45,45,45);
187f120fe41SAndre Fischer     }
188f120fe41SAndre Fischer     else if (DoesResourceEndWith("/Debug_NotYetImplementedPanel"))
189f120fe41SAndre Fischer     {
19037fee4fdSAndre Fischer         pControl = new NotYetImplementedPanel(pParentWindow);
19137fee4fdSAndre Fischer         aLayoutSize = ui::LayoutSize(20,25,25);
192f120fe41SAndre Fischer     }
193f120fe41SAndre Fischer     else if (DoesResourceEndWith("/EmptyPanel"))
194f120fe41SAndre Fischer     {
19537fee4fdSAndre Fischer         pControl = new EmptyPanel(pParentWindow);
19637fee4fdSAndre Fischer         aLayoutSize = ui::LayoutSize(20,-1, 50);
197f120fe41SAndre Fischer     }
19802c50d82SAndre Fischer #undef DoesResourceEndWith
19966c1fc23SArmin Le Grand 
20037fee4fdSAndre Fischer     if (pControl != NULL)
20137fee4fdSAndre Fischer     {
20237fee4fdSAndre Fischer         return sfx2::sidebar::SidebarPanelBase::Create(
20337fee4fdSAndre Fischer             rsResourceURL,
20437fee4fdSAndre Fischer             xFrame,
20537fee4fdSAndre Fischer             pControl,
20637fee4fdSAndre Fischer             aLayoutSize);
20737fee4fdSAndre Fischer     }
20837fee4fdSAndre Fischer     else
20937fee4fdSAndre Fischer         return Reference<ui::XUIElement>();
210b9e67834SAndre Fischer }
211b9e67834SAndre Fischer 
212b9e67834SAndre Fischer } } // end of namespace svx::sidebar
21335fa8f12SArmin Le Grand 
21435fa8f12SArmin Le Grand // eof
215