Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
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 "EmptyPanel.hxx"
29 : #include <sfx2/sidebar/SidebarPanelBase.hxx>
30 : #include <sfx2/sidebar/Tools.hxx>
31 : #include <sfx2/sfxbasecontroller.hxx>
32 : #include <sfx2/templdlg.hxx>
33 : #include <toolkit/helper/vclunohelper.hxx>
34 : #include <vcl/window.hxx>
35 : #include <rtl/ref.hxx>
36 : #include <comphelper/namedvaluecollection.hxx>
37 : #include <cppuhelper/basemutex.hxx>
38 : #include <cppuhelper/compbase.hxx>
39 : #include <cppuhelper/supportsservice.hxx>
40 : #include <com/sun/star/lang/XServiceInfo.hpp>
41 : #include <com/sun/star/ui/XSidebar.hpp>
42 : #include <com/sun/star/ui/XUIElementFactory.hpp>
43 :
44 : #include <boost/bind.hpp>
45 : #include <boost/noncopyable.hpp>
46 :
47 : using namespace css;
48 : using namespace css::uno;
49 : using namespace svx::sidebar;
50 :
51 :
52 : namespace {
53 :
54 : /* Why this is not used ? Doesn't it need to inherit from XServiceInfo ?
55 : #define IMPLEMENTATION_NAME "org.apache.openoffice.comp.svx.sidebar.PanelFactory"
56 : #define SERVICE_NAME "com.sun.star.ui.UIElementFactory"
57 : */
58 :
59 : typedef ::cppu::WeakComponentImplHelper< css::ui::XUIElementFactory, css::lang::XServiceInfo >
60 : PanelFactoryInterfaceBase;
61 :
62 : class PanelFactory
63 : : private ::boost::noncopyable,
64 : private ::cppu::BaseMutex,
65 : public PanelFactoryInterfaceBase
66 : {
67 : public:
68 : PanelFactory();
69 : virtual ~PanelFactory();
70 :
71 : // XUIElementFactory
72 : css::uno::Reference<css::ui::XUIElement> SAL_CALL createUIElement (
73 : const ::rtl::OUString& rsResourceURL,
74 : const ::css::uno::Sequence<css::beans::PropertyValue>& rArguments)
75 : throw(
76 : css::container::NoSuchElementException,
77 : css::lang::IllegalArgumentException,
78 : css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
79 :
80 1 : OUString SAL_CALL getImplementationName()
81 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
82 1 : { return OUString("org.apache.openoffice.comp.svx.sidebar.PanelFactory"); }
83 :
84 0 : sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
85 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
86 0 : { return cppu::supportsService(this, ServiceName); }
87 :
88 1 : css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames()
89 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
90 1 : { return css::uno::Sequence<OUString>{"com.sun.star.ui.UIElementFactory"}; }
91 : };
92 :
93 3480 : PanelFactory::PanelFactory()
94 3480 : : PanelFactoryInterfaceBase(m_aMutex)
95 : {
96 3480 : }
97 :
98 :
99 :
100 :
101 6960 : PanelFactory::~PanelFactory()
102 : {
103 6960 : }
104 :
105 :
106 :
107 :
108 3479 : Reference<ui::XUIElement> SAL_CALL PanelFactory::createUIElement (
109 : const ::rtl::OUString& rsResourceURL,
110 : const ::css::uno::Sequence<css::beans::PropertyValue>& rArguments)
111 : throw(
112 : container::NoSuchElementException,
113 : lang::IllegalArgumentException,
114 : RuntimeException, std::exception)
115 : {
116 3479 : const ::comphelper::NamedValueCollection aArguments (rArguments);
117 6958 : Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>()));
118 6958 : Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>()));
119 6958 : Reference<ui::XSidebar> xSidebar (aArguments.getOrDefault("Sidebar", Reference<ui::XSidebar>()));
120 3479 : const sal_uInt64 nBindingsValue (aArguments.getOrDefault("SfxBindings", sal_uInt64(0)));
121 3479 : SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue);
122 : ::sfx2::sidebar::EnumContext aContext (
123 : aArguments.getOrDefault("ApplicationName", OUString()),
124 3479 : aArguments.getOrDefault("ContextName", OUString()));
125 :
126 3479 : vcl::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
127 3479 : if ( ! xParentWindow.is() || pParentWindow==NULL)
128 : throw RuntimeException(
129 : "PanelFactory::createUIElement called without ParentWindow",
130 0 : NULL);
131 3479 : if ( ! xFrame.is())
132 : throw RuntimeException(
133 : "PanelFactory::createUIElement called without Frame",
134 0 : NULL);
135 3479 : if (pBindings == NULL)
136 : throw RuntimeException(
137 : "PanelFactory::createUIElement called without SfxBindings",
138 0 : NULL);
139 :
140 6958 : VclPtr<vcl::Window> pControl;
141 3479 : ui::LayoutSize aLayoutSize (-1,-1,-1);
142 :
143 3479 : if (rsResourceURL.endsWith("/TextPropertyPanel"))
144 : {
145 515 : pControl = TextPropertyPanel::Create(pParentWindow, xFrame, pBindings, aContext);
146 : }
147 2964 : else if (rsResourceURL.endsWith("/ParaPropertyPanel"))
148 : {
149 341 : pControl = ParaPropertyPanel::Create(pParentWindow, xFrame, pBindings, xSidebar);
150 : }
151 2623 : else if (rsResourceURL.endsWith("/AreaPropertyPanel"))
152 : {
153 2 : pControl = AreaPropertyPanel::Create(pParentWindow, xFrame, pBindings);
154 : }
155 2621 : else if (rsResourceURL.endsWith("/GraphicPropertyPanel"))
156 : {
157 0 : pControl = GraphicPropertyPanel::Create(pParentWindow, xFrame, pBindings);
158 : }
159 2621 : else if (rsResourceURL.endsWith("/LinePropertyPanel"))
160 : {
161 2 : pControl = LinePropertyPanel::Create(pParentWindow, xFrame, pBindings);
162 : }
163 2619 : else if (rsResourceURL.endsWith("/PosSizePropertyPanel"))
164 : {
165 2 : pControl = PosSizePropertyPanel::Create(pParentWindow, xFrame, pBindings, xSidebar);
166 : }
167 2617 : else if (rsResourceURL.endsWith("/InsertPropertyPanel"))
168 : {
169 0 : pControl.reset(VclPtr<InsertPropertyPanel>::Create(pParentWindow, xFrame));
170 : }
171 2617 : else if (rsResourceURL.endsWith("/GalleryPanel"))
172 : {
173 0 : pControl.reset(VclPtr<GalleryControl>::Create(pBindings, pParentWindow));
174 0 : aLayoutSize = ui::LayoutSize(300,-1,400);
175 : }
176 2617 : else if (rsResourceURL.endsWith("/StyleListPanel"))
177 : {
178 0 : pControl.reset(VclPtr<SfxTemplatePanelControl>::Create(pBindings, pParentWindow));
179 0 : aLayoutSize = ui::LayoutSize(0,-1,-1);
180 : }
181 2617 : else if (rsResourceURL.endsWith("/EmptyPanel"))
182 : {
183 2617 : pControl.reset(VclPtr<EmptyPanel>::Create(pParentWindow));
184 2617 : aLayoutSize = ui::LayoutSize(20,-1, 50);
185 : }
186 :
187 3447 : if (pControl)
188 : {
189 : return sfx2::sidebar::SidebarPanelBase::Create(
190 : rsResourceURL,
191 : xFrame,
192 : pControl,
193 3447 : aLayoutSize);
194 : }
195 : else
196 3479 : return Reference<ui::XUIElement>();
197 : }
198 :
199 : }
200 :
201 : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
202 3480 : org_apache_openoffice_comp_svx_sidebar_PanelFactory_get_implementation(
203 : css::uno::XComponentContext *,
204 : css::uno::Sequence<css::uno::Any> const &)
205 : {
206 3480 : return cppu::acquire(new PanelFactory);
207 390 : }
208 :
209 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|