Line data Source code
1 : /*
2 : * This file is part of the LibreOffice project.
3 : *
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/.
7 : *
8 : * This file incorporates work covered by the following license notice:
9 : *
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 .
17 : */
18 :
19 : #include "SwPanelFactory.hxx"
20 :
21 : #include <PagePropertyPanel.hxx>
22 : #include <WrapPropertyPanel.hxx>
23 : #include <navipi.hxx>
24 :
25 : #include <sfx2/sidebar/SidebarPanelBase.hxx>
26 : #include <sfx2/sfxbasecontroller.hxx>
27 : #include <toolkit/helper/vclunohelper.hxx>
28 : #include <vcl/window.hxx>
29 : #include <rtl/ref.hxx>
30 : #include <comphelper/namedvaluecollection.hxx>
31 :
32 : #include <boost/bind.hpp>
33 :
34 :
35 : using namespace css;
36 : using namespace cssu;
37 : using ::rtl::OUString;
38 :
39 :
40 : namespace sw { namespace sidebar {
41 :
42 : #define A2S(s) ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
43 : #define IMPLEMENTATION_NAME "org.apache.openoffice.comp.sw.sidebar.SwPanelFactory"
44 : #define SERVICE_NAME "com.sun.star.ui.UIElementFactory"
45 :
46 :
47 1 : ::rtl::OUString SAL_CALL SwPanelFactory::getImplementationName (void)
48 : {
49 1 : return A2S(IMPLEMENTATION_NAME);
50 : }
51 :
52 :
53 0 : cssu::Reference<cssu::XInterface> SAL_CALL SwPanelFactory::createInstance(
54 : const uno::Reference<lang::XMultiServiceFactory>& )
55 : {
56 0 : ::rtl::Reference<SwPanelFactory> pPanelFactory (new SwPanelFactory());
57 0 : cssu::Reference<cssu::XInterface> xService (static_cast<XWeak*>(pPanelFactory.get()), cssu::UNO_QUERY);
58 0 : return xService;
59 : }
60 :
61 :
62 0 : cssu::Sequence<OUString> SAL_CALL SwPanelFactory::getSupportedServiceNames (void)
63 : {
64 0 : cssu::Sequence<OUString> aServiceNames (1);
65 0 : aServiceNames[0] = A2S(SERVICE_NAME);
66 0 : return aServiceNames;
67 :
68 : }
69 :
70 :
71 0 : SwPanelFactory::SwPanelFactory (void)
72 0 : : PanelFactoryInterfaceBase(m_aMutex)
73 : {
74 0 : }
75 :
76 :
77 0 : SwPanelFactory::~SwPanelFactory (void)
78 : {
79 0 : }
80 :
81 :
82 0 : Reference<ui::XUIElement> SAL_CALL SwPanelFactory::createUIElement (
83 : const ::rtl::OUString& rsResourceURL,
84 : const ::cssu::Sequence<css::beans::PropertyValue>& rArguments)
85 : throw(
86 : container::NoSuchElementException,
87 : lang::IllegalArgumentException,
88 : RuntimeException)
89 : {
90 0 : Reference<ui::XUIElement> xElement;
91 :
92 0 : const ::comphelper::NamedValueCollection aArguments (rArguments);
93 0 : Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>()));
94 0 : Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>()));
95 0 : const sal_uInt64 nBindingsValue (aArguments.getOrDefault("SfxBindings", sal_uInt64(0)));
96 0 : SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue);
97 :
98 0 : ::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
99 0 : if ( ! xParentWindow.is() || pParentWindow==NULL)
100 : throw RuntimeException(
101 0 : A2S("PanelFactory::createUIElement called without ParentWindow"),
102 0 : NULL);
103 0 : if ( ! xFrame.is())
104 : throw RuntimeException(
105 0 : A2S("PanelFactory::createUIElement called without Frame"),
106 0 : NULL);
107 0 : if (pBindings == NULL)
108 : throw RuntimeException(
109 0 : A2S("PanelFactory::createUIElement called without SfxBindings"),
110 0 : NULL);
111 :
112 : #define DoesResourceEndWith(s) rsResourceURL.endsWithAsciiL(s,strlen(s))
113 0 : if (DoesResourceEndWith("/PagePropertyPanel"))
114 : {
115 0 : PagePropertyPanel* pPanel = PagePropertyPanel::Create( pParentWindow, xFrame, pBindings );
116 0 : xElement = sfx2::sidebar::SidebarPanelBase::Create(
117 : rsResourceURL,
118 : xFrame,
119 : pPanel,
120 0 : ui::LayoutSize(-1,-1,-1));
121 : }
122 0 : else if (DoesResourceEndWith("/WrapPropertyPanel"))
123 : {
124 0 : WrapPropertyPanel* pPanel = WrapPropertyPanel::Create( pParentWindow, xFrame, pBindings );
125 0 : xElement = sfx2::sidebar::SidebarPanelBase::Create(
126 : rsResourceURL,
127 : xFrame,
128 : pPanel,
129 0 : ui::LayoutSize(-1,-1,-1));
130 : }
131 0 : else if (DoesResourceEndWith("/NavigatorPanel"))
132 : {
133 0 : Window* pPanel = new SwNavigationPI(pBindings, NULL, pParentWindow);
134 0 : xElement = sfx2::sidebar::SidebarPanelBase::Create(
135 : rsResourceURL,
136 : xFrame,
137 : pPanel,
138 0 : ui::LayoutSize(0,-1,-1));
139 : }
140 : #undef DoesResourceEndWith
141 :
142 0 : return xElement;
143 : }
144 :
145 99 : } } // end of namespace sw::sidebar
146 :
147 : // eof
|