2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 #include "sidebar/PanelFactory.hxx"
20 #include "text/TextPropertyPanel.hxx"
21 #include "paragraph/ParaPropertyPanel.hxx"
22 #include "area/AreaPropertyPanel.hxx"
23 #include "graphic/GraphicPropertyPanel.hxx"
24 #include "line/LinePropertyPanel.hxx"
25 #include "possize/PosSizePropertyPanel.hxx"
26 #include "insert/InsertPropertyPanel.hxx"
27 #include "GalleryControl.hxx"
28 #include "debug/ColorPanel.hxx"
29 #include "debug/ContextPanel.hxx"
30 #include "debug/NotYetImplementedPanel.hxx"
31 #include "EmptyPanel.hxx"
32 #include <sfx2/sidebar/SidebarPanelBase.hxx>
33 #include <sfx2/sfxbasecontroller.hxx>
34 #include <sfx2/templdlg.hxx>
35 #include <toolkit/helper/vclunohelper.hxx>
36 #include <vcl/window.hxx>
37 #include <rtl/ref.hxx>
38 #include <comphelper/namedvaluecollection.hxx>
39 #include <com/sun/star/ui/XSidebar.hpp>
41 #include <boost/bind.hpp>
46 using ::rtl::OUString
;
49 namespace svx
{ namespace sidebar
{
51 #define A2S(s) ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
52 #define IMPLEMENTATION_NAME "org.apache.openoffice.comp.svx.sidebar.PanelFactory"
53 #define SERVICE_NAME "com.sun.star.ui.UIElementFactory"
56 ::rtl::OUString SAL_CALL
PanelFactory::getImplementationName (void)
58 return A2S(IMPLEMENTATION_NAME
);
64 cssu::Reference
<cssu::XInterface
> SAL_CALL
PanelFactory::createInstance (
65 const uno::Reference
<lang::XMultiServiceFactory
>& rxFactory
)
69 ::rtl::Reference
<PanelFactory
> pPanelFactory (new PanelFactory());
70 cssu::Reference
<cssu::XInterface
> xService (static_cast<XWeak
*>(pPanelFactory
.get()), cssu::UNO_QUERY
);
77 cssu::Sequence
<OUString
> SAL_CALL
PanelFactory::getSupportedServiceNames (void)
79 cssu::Sequence
<OUString
> aServiceNames (1);
80 aServiceNames
[0] = A2S(SERVICE_NAME
);
88 PanelFactory::PanelFactory (void)
89 : PanelFactoryInterfaceBase(m_aMutex
)
96 PanelFactory::~PanelFactory (void)
103 Reference
<ui::XUIElement
> SAL_CALL
PanelFactory::createUIElement (
104 const ::rtl::OUString
& rsResourceURL
,
105 const ::cssu::Sequence
<css::beans::PropertyValue
>& rArguments
)
107 container::NoSuchElementException
,
108 lang::IllegalArgumentException
,
111 const ::comphelper::NamedValueCollection
aArguments (rArguments
);
112 Reference
<frame::XFrame
> xFrame (aArguments
.getOrDefault("Frame", Reference
<frame::XFrame
>()));
113 Reference
<awt::XWindow
> xParentWindow (aArguments
.getOrDefault("ParentWindow", Reference
<awt::XWindow
>()));
114 Reference
<ui::XSidebar
> xSidebar (aArguments
.getOrDefault("Sidebar", Reference
<ui::XSidebar
>()));
115 const sal_uInt64
nBindingsValue (aArguments
.getOrDefault("SfxBindings", sal_uInt64(0)));
116 SfxBindings
* pBindings
= reinterpret_cast<SfxBindings
*>(nBindingsValue
);
117 ::sfx2::sidebar::EnumContext
aContext (
118 aArguments
.getOrDefault("ApplicationName", OUString()),
119 aArguments
.getOrDefault("ContextName", OUString()));
121 ::Window
* pParentWindow
= VCLUnoHelper::GetWindow(xParentWindow
);
122 if ( ! xParentWindow
.is() || pParentWindow
==NULL
)
123 throw RuntimeException(
124 A2S("PanelFactory::createUIElement called without ParentWindow"),
127 throw RuntimeException(
128 A2S("PanelFactory::createUIElement called without Frame"),
130 if (pBindings
== NULL
)
131 throw RuntimeException(
132 A2S("PanelFactory::createUIElement called without SfxBindings"),
135 Window
* pControl
= NULL
;
136 ui::LayoutSize
aLayoutSize (-1,-1,-1);
138 #define DoesResourceEndWith(s) rsResourceURL.endsWithAsciiL(s,strlen(s))
139 if (DoesResourceEndWith("/TextPropertyPanel"))
141 pControl
= TextPropertyPanel::Create(pParentWindow
, xFrame
, pBindings
, aContext
);
143 else if (DoesResourceEndWith("/ParaPropertyPanel"))
145 pControl
= ParaPropertyPanel::Create(pParentWindow
, xFrame
, pBindings
, xSidebar
);
147 else if (DoesResourceEndWith("/AreaPropertyPanel"))
149 pControl
= AreaPropertyPanel::Create(pParentWindow
, xFrame
, pBindings
);
151 else if (DoesResourceEndWith("/GraphicPropertyPanel"))
153 pControl
= GraphicPropertyPanel::Create(pParentWindow
, xFrame
, pBindings
);
155 else if (DoesResourceEndWith("/LinePropertyPanel"))
157 pControl
= LinePropertyPanel::Create(pParentWindow
, xFrame
, pBindings
);
159 else if (DoesResourceEndWith("/PosSizePropertyPanel"))
161 pControl
= PosSizePropertyPanel::Create(pParentWindow
, xFrame
, pBindings
, xSidebar
);
163 else if (DoesResourceEndWith("/InsertPropertyPanel"))
165 pControl
= new InsertPropertyPanel(pParentWindow
, xFrame
);
167 else if (DoesResourceEndWith("/GalleryPanel"))
169 pControl
= new GalleryControl(pBindings
, pParentWindow
);
170 aLayoutSize
= ui::LayoutSize(300,-1,400);
172 else if (DoesResourceEndWith("/StyleListPanel"))
174 pControl
= new SfxTemplatePanelControl(pBindings
, pParentWindow
);
175 aLayoutSize
= ui::LayoutSize(0,-1,-1);
177 else if (DoesResourceEndWith("/Debug_ColorPanel"))
179 pControl
= new ColorPanel(pParentWindow
);
180 aLayoutSize
= ui::LayoutSize(300,-1,400);
182 else if (DoesResourceEndWith("/Debug_ContextPanel"))
184 pControl
= new ContextPanel(pParentWindow
);
185 aLayoutSize
= ui::LayoutSize(45,45,45);
187 else if (DoesResourceEndWith("/Debug_NotYetImplementedPanel"))
189 pControl
= new NotYetImplementedPanel(pParentWindow
);
190 aLayoutSize
= ui::LayoutSize(20,25,25);
192 else if (DoesResourceEndWith("/EmptyPanel"))
194 pControl
= new EmptyPanel(pParentWindow
);
195 aLayoutSize
= ui::LayoutSize(20,-1, 50);
197 #undef DoesResourceEndWith
199 if (pControl
!= NULL
)
201 return sfx2::sidebar::SidebarPanelBase::Create(
208 return Reference
<ui::XUIElement
>();
211 } } // end of namespace svx::sidebar