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 <com/sun/star/ui/XUIElementFactory.hpp>
21 :
22 : #include <PagePropertyPanel.hxx>
23 : #include <WrapPropertyPanel.hxx>
24 : #include <navipi.hxx>
25 :
26 : #include <sfx2/sidebar/SidebarPanelBase.hxx>
27 : #include <sfx2/sfxbasecontroller.hxx>
28 : #include <toolkit/helper/vclunohelper.hxx>
29 : #include <vcl/window.hxx>
30 : #include <rtl/ref.hxx>
31 : #include <comphelper/namedvaluecollection.hxx>
32 : #include <cppuhelper/compbase1.hxx>
33 : #include <cppuhelper/basemutex.hxx>
34 :
35 : #include <boost/bind.hpp>
36 : #include <boost/noncopyable.hpp>
37 :
38 : using namespace css;
39 : using namespace css::uno;
40 :
41 : namespace {
42 :
43 : typedef ::cppu::WeakComponentImplHelper1 <
44 : css::ui::XUIElementFactory
45 : > PanelFactoryInterfaceBase;
46 :
47 : class SwPanelFactory
48 : : private ::boost::noncopyable,
49 : private ::cppu::BaseMutex,
50 : public PanelFactoryInterfaceBase
51 : {
52 : public:
53 : SwPanelFactory(void);
54 : virtual ~SwPanelFactory(void);
55 :
56 : // XUIElementFactory
57 : css::uno::Reference<css::ui::XUIElement> SAL_CALL createUIElement(
58 : const ::rtl::OUString& rsResourceURL,
59 : const css::uno::Sequence<css::beans::PropertyValue>& rArguments)
60 : throw(
61 : css::container::NoSuchElementException,
62 : css::lang::IllegalArgumentException,
63 : css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
64 : };
65 :
66 744 : SwPanelFactory::SwPanelFactory (void)
67 744 : : PanelFactoryInterfaceBase(m_aMutex)
68 : {
69 744 : }
70 :
71 1488 : SwPanelFactory::~SwPanelFactory (void)
72 : {
73 1488 : }
74 :
75 744 : Reference<ui::XUIElement> SAL_CALL SwPanelFactory::createUIElement (
76 : const ::rtl::OUString& rsResourceURL,
77 : const css::uno::Sequence<css::beans::PropertyValue>& rArguments)
78 : throw(
79 : container::NoSuchElementException,
80 : lang::IllegalArgumentException,
81 : RuntimeException, std::exception)
82 : {
83 744 : Reference<ui::XUIElement> xElement;
84 :
85 1488 : const ::comphelper::NamedValueCollection aArguments (rArguments);
86 1488 : Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>()));
87 1488 : Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>()));
88 744 : const sal_uInt64 nBindingsValue (aArguments.getOrDefault("SfxBindings", sal_uInt64(0)));
89 744 : SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue);
90 :
91 744 : vcl::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
92 744 : if ( ! xParentWindow.is() || pParentWindow==NULL)
93 : throw RuntimeException(
94 : "PanelFactory::createUIElement called without ParentWindow",
95 0 : NULL);
96 744 : if ( ! xFrame.is())
97 : throw RuntimeException(
98 : "PanelFactory::createUIElement called without Frame",
99 0 : NULL);
100 744 : if (pBindings == NULL)
101 : throw RuntimeException(
102 : "PanelFactory::createUIElement called without SfxBindings",
103 0 : NULL);
104 :
105 : #define DoesResourceEndWith(s) rsResourceURL.endsWithAsciiL(s,strlen(s))
106 744 : if (DoesResourceEndWith("/PagePropertyPanel"))
107 : {
108 742 : sw::sidebar::PagePropertyPanel* pPanel = sw::sidebar::PagePropertyPanel::Create( pParentWindow, xFrame, pBindings );
109 1484 : xElement = sfx2::sidebar::SidebarPanelBase::Create(
110 : rsResourceURL,
111 : xFrame,
112 : pPanel,
113 742 : ui::LayoutSize(-1,-1,-1));
114 : }
115 2 : else if (DoesResourceEndWith("/WrapPropertyPanel"))
116 : {
117 0 : sw::sidebar::WrapPropertyPanel* pPanel = sw::sidebar::WrapPropertyPanel::Create( pParentWindow, xFrame, pBindings );
118 0 : xElement = sfx2::sidebar::SidebarPanelBase::Create(
119 : rsResourceURL,
120 : xFrame,
121 : pPanel,
122 0 : ui::LayoutSize(-1,-1,-1));
123 : }
124 2 : else if (DoesResourceEndWith("/NavigatorPanel"))
125 : {
126 2 : vcl::Window* pPanel = new SwNavigationPI(pBindings, NULL, pParentWindow);
127 4 : xElement = sfx2::sidebar::SidebarPanelBase::Create(
128 : rsResourceURL,
129 : xFrame,
130 : pPanel,
131 2 : ui::LayoutSize(0,-1,-1));
132 : }
133 : #undef DoesResourceEndWith
134 :
135 1488 : return xElement;
136 : }
137 :
138 : }
139 :
140 : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
141 744 : org_apache_openoffice_comp_sw_sidebar_SwPanelFactory_get_implementation(
142 : css::uno::XComponentContext *,
143 : css::uno::Sequence<css::uno::Any> const &)
144 : {
145 744 : return cppu::acquire(new SwPanelFactory());
146 270 : }
147 :
148 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|