bump product version to 7.6.3.2-android
[LibreOffice.git] / desktop / test / deployment / passive / passive_native.cxx
blob9bfbcb7b160fe212ce311cdbdbca49692050871d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include <cassert>
24 #include <com/sun/star/awt/MessageBoxButtons.hpp>
25 #include <com/sun/star/awt/Rectangle.hpp>
26 #include <com/sun/star/awt/Toolkit.hpp>
27 #include <com/sun/star/awt/XMessageBox.hpp>
28 #include <com/sun/star/awt/XWindowPeer.hpp>
29 #include <com/sun/star/beans/PropertyValue.hpp>
30 #include <com/sun/star/frame/DispatchDescriptor.hpp>
31 #include <com/sun/star/frame/Desktop.hpp>
32 #include <com/sun/star/frame/XDispatch.hpp>
33 #include <com/sun/star/frame/XDispatchProvider.hpp>
34 #include <com/sun/star/frame/XFrame.hpp>
35 #include <com/sun/star/frame/XStatusListener.hpp>
36 #include <com/sun/star/lang/XComponent.hpp>
37 #include <com/sun/star/lang/XServiceInfo.hpp>
38 #include <com/sun/star/uno/DeploymentException.hpp>
39 #include <com/sun/star/uno/Exception.hpp>
40 #include <com/sun/star/uno/Reference.hxx>
41 #include <com/sun/star/uno/RuntimeException.hpp>
42 #include <com/sun/star/uno/Sequence.hxx>
43 #include <com/sun/star/uno/XComponentContext.hpp>
44 #include <com/sun/star/uno/XInterface.hpp>
45 #include <com/sun/star/util/URL.hpp>
46 #include <cppuhelper/factory.hxx>
47 #include <cppuhelper/implbase2.hxx>
48 #include <cppuhelper/implementationentry.hxx>
49 #include <cppuhelper/supportsservice.hxx>
50 #include <cppuhelper/weak.hxx>
51 #include <rtl/ustring.hxx>
52 #include <sal/types.h>
53 #include <uno/lbnames.h>
55 namespace {
57 class Provider:
58 public cppu::WeakImplHelper2<
59 css::lang::XServiceInfo, css::frame::XDispatchProvider >
61 public:
62 Provider(const Provider&) = delete;
63 const Provider& operator=(const Provider&) = delete;
65 static css::uno::Reference< css::uno::XInterface > SAL_CALL static_create(
66 css::uno::Reference< css::uno::XComponentContext > const & xContext)
67 { return static_cast< cppu::OWeakObject * >(new Provider(xContext)); }
69 static rtl::OUString SAL_CALL static_getImplementationName();
71 static css::uno::Sequence< rtl::OUString > SAL_CALL
72 static_getSupportedServiceNames();
74 private:
75 explicit Provider(
76 css::uno::Reference< css::uno::XComponentContext > const & context):
77 context_(context) { assert(context.is()); }
79 virtual ~Provider() {}
81 virtual rtl::OUString SAL_CALL getImplementationName() override
82 { return static_getImplementationName(); }
84 virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & ServiceName) override
85 { return cppu::supportsService(this, ServiceName); }
87 virtual css::uno::Sequence< rtl::OUString > SAL_CALL
88 getSupportedServiceNames() override
89 { return static_getSupportedServiceNames(); }
91 virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch(
92 css::util::URL const &, rtl::OUString const &, sal_Int32) override;
94 virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > >
95 SAL_CALL queryDispatches(
96 css::uno::Sequence< css::frame::DispatchDescriptor > const & Requests) override;
98 css::uno::Reference< css::uno::XComponentContext > context_;
101 rtl::OUString Provider::static_getImplementationName() {
102 return rtl::OUString("com.sun.star.comp.test.deployment.passive_native");
105 css::uno::Sequence< rtl::OUString > Provider::static_getSupportedServiceNames()
107 rtl::OUString name("com.sun.star.test.deployment.passive_native");
108 return css::uno::Sequence< rtl::OUString >(&name, 1);
111 css::uno::Reference< css::frame::XDispatch > Provider::queryDispatch(
112 css::util::URL const &, rtl::OUString const &, sal_Int32)
114 css::uno::Reference< css::frame::XDispatch > dispatch;
115 if (!(context_->getValueByName(
116 "/singletons/com.sun.star.test.deployment."
117 "passive_native_singleton") >>=
118 dispatch) ||
119 !dispatch.is())
121 throw css::uno::DeploymentException(
122 "component context fails to supply singleton"
123 " com.sun.star.test.deployment.passive_native_singleton of type"
124 " com.sun.star.frame.XDispatch",
125 context_);
127 return dispatch;
130 css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > >
131 Provider::queryDispatches(
132 css::uno::Sequence< css::frame::DispatchDescriptor > const & Requests)
134 css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > s(
135 Requests.getLength());
136 for (sal_Int32 i = 0; i < s.getLength(); ++i) {
137 s[i] = queryDispatch(
138 Requests[i].FeatureURL, Requests[i].FrameName,
139 Requests[i].SearchFlags);
141 return s;
144 class Dispatch:
145 public cppu::WeakImplHelper2<
146 css::lang::XServiceInfo, css::frame::XDispatch >
148 public:
149 Dispatch(const Dispatch&) = delete;
150 const Dispatch& operator=(const Dispatch&) = delete;
152 static css::uno::Reference< css::uno::XInterface > SAL_CALL static_create(
153 css::uno::Reference< css::uno::XComponentContext > const & xContext)
154 { return static_cast< cppu::OWeakObject * >(new Dispatch(xContext)); }
156 static rtl::OUString SAL_CALL static_getImplementationName();
158 static css::uno::Sequence< rtl::OUString > SAL_CALL
159 static_getSupportedServiceNames()
160 { return css::uno::Sequence< rtl::OUString >(); }
162 private:
163 explicit Dispatch(
164 css::uno::Reference< css::uno::XComponentContext > const & context):
165 context_(context) { assert(context.is()); }
167 virtual ~Dispatch() {}
169 virtual rtl::OUString SAL_CALL getImplementationName() override
170 { return static_getImplementationName(); }
172 virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & ServiceName) override
173 { return cppu::supportsService(this, ServiceName); }
175 virtual css::uno::Sequence< rtl::OUString > SAL_CALL
176 getSupportedServiceNames() override
177 { return static_getSupportedServiceNames(); }
179 virtual void SAL_CALL dispatch(
180 css::util::URL const &,
181 css::uno::Sequence< css::beans::PropertyValue > const &) override;
183 virtual void SAL_CALL addStatusListener(
184 css::uno::Reference< css::frame::XStatusListener > const &,
185 css::util::URL const &) override
188 virtual void SAL_CALL removeStatusListener(
189 css::uno::Reference< css::frame::XStatusListener > const &,
190 css::util::URL const &) override
193 css::uno::Reference< css::uno::XComponentContext > context_;
196 rtl::OUString Dispatch::static_getImplementationName() {
197 return rtl::OUString(
198 "com.sun.star.comp.test.deployment.passive_native_singleton");
201 void Dispatch::dispatch(
202 css::util::URL const &,
203 css::uno::Sequence< css::beans::PropertyValue > const &)
205 css::uno::Reference< css::frame::XDesktop2 > xDesktop = css::frame::Desktop::create(context_);
206 css::uno::Reference< css::frame::XFrame > xFrame = xDesktop->getCurrentFrame();
207 css::uno::Reference< css::awt::XWindowPeer > xWindowPeer( xFrame->getComponentWindow(), css::uno::UNO_QUERY_THROW );
208 css::uno::Reference< css::awt::XToolkit2 > xToolkit = css::awt::Toolkit::create(context_);
209 css::uno::Reference< css::awt::XMessageBox > box(
210 xToolkit->createMessageBox(
211 xWindowPeer,
212 css::awt::MessageBoxType_INFOBOX,
213 css::awt::MessageBoxButtons::BUTTONS_OK, "passive", "native"),
214 css::uno::UNO_SET_THROW);
216 box->execute();
218 css::uno::Reference< css::lang::XComponent > xComponent(box, css::uno::UNO_QUERY_THROW);
219 xComponent->dispose();
222 cppu::ImplementationEntry const services[] = {
223 { &Provider::static_create, &Provider::static_getImplementationName,
224 &Provider::static_getSupportedServiceNames,
225 &cppu::createSingleComponentFactory, nullptr, 0 },
226 { &Dispatch::static_create, &Dispatch::static_getImplementationName,
227 &Dispatch::static_getSupportedServiceNames,
228 &cppu::createSingleComponentFactory, nullptr, 0 },
229 { nullptr, nullptr, nullptr, nullptr, nullptr, 0 }
234 extern "C" SAL_DLLPUBLIC_EXPORT void * component_getFactory(
235 char const * pImplName, void * pServiceManager, void * pRegistryKey)
237 return cppu::component_getFactoryHelper(
238 pImplName, pServiceManager, pRegistryKey, services);
241 extern "C" SAL_DLLPUBLIC_EXPORT void
242 component_getImplementationEnvironment(
243 char const ** ppEnvTypeName, uno_Environment **)
245 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
248 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */