tdf#164393 Change themes UI as per UX feedback
[LibreOffice.git] / desktop / test / deployment / active / active_native.cxx
blob753f0da77312f9c35e6ffd2d18a770b9fa66a28e
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/registry/XRegistryKey.hpp>
39 #include <com/sun/star/uno/DeploymentException.hpp>
40 #include <com/sun/star/uno/Exception.hpp>
41 #include <com/sun/star/uno/Reference.hxx>
42 #include <com/sun/star/uno/RuntimeException.hpp>
43 #include <com/sun/star/uno/Sequence.hxx>
44 #include <com/sun/star/uno/XComponentContext.hpp>
45 #include <com/sun/star/uno/XInterface.hpp>
46 #include <com/sun/star/util/URL.hpp>
47 #include <cppuhelper/factory.hxx>
48 #include <cppuhelper/implbase2.hxx>
49 #include <cppuhelper/implementationentry.hxx>
50 #include <cppuhelper/supportsservice.hxx>
51 #include <cppuhelper/weak.hxx>
52 #include <rtl/textenc.h>
53 #include <rtl/ustring.hxx>
54 #include <sal/log.hxx>
55 #include <sal/types.h>
56 #include <uno/lbnames.h>
58 namespace {
60 class Provider:
61 public cppu::WeakImplHelper2<
62 css::lang::XServiceInfo, css::frame::XDispatchProvider >
64 public:
65 Provider(const Provider&) = delete;
66 const Provider& operator=(const Provider&) = delete;
68 static css::uno::Reference< css::uno::XInterface > SAL_CALL static_create(
69 css::uno::Reference< css::uno::XComponentContext > const & xContext)
70 { return static_cast< cppu::OWeakObject * >(new Provider(xContext)); }
72 static rtl::OUString SAL_CALL static_getImplementationName();
74 static css::uno::Sequence< rtl::OUString > SAL_CALL
75 static_getSupportedServiceNames();
77 private:
78 explicit Provider(
79 css::uno::Reference< css::uno::XComponentContext > const & context):
80 context_(context) { assert(context.is()); }
82 virtual ~Provider() {}
84 virtual rtl::OUString SAL_CALL getImplementationName() override
85 { return static_getImplementationName(); }
87 virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & ServiceName) override
88 { return cppu::supportsService(this, ServiceName); }
90 virtual css::uno::Sequence< rtl::OUString > SAL_CALL
91 getSupportedServiceNames() override
92 { return static_getSupportedServiceNames(); }
94 virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch(
95 css::util::URL const &, rtl::OUString const &, sal_Int32) override;
97 virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > >
98 SAL_CALL queryDispatches(
99 css::uno::Sequence< css::frame::DispatchDescriptor > const & Requests) override;
101 css::uno::Reference< css::uno::XComponentContext > context_;
104 rtl::OUString Provider::static_getImplementationName() {
105 return rtl::OUString("com.sun.star.comp.test.deployment.active_native");
108 css::uno::Sequence< rtl::OUString > Provider::static_getSupportedServiceNames()
110 rtl::OUString name("com.sun.star.test.deployment.active_native");
111 return css::uno::Sequence< rtl::OUString >(&name, 1);
114 css::uno::Reference< css::frame::XDispatch > Provider::queryDispatch(
115 css::util::URL const &, rtl::OUString const &, sal_Int32)
117 css::uno::Reference< css::frame::XDispatch > dispatch;
118 if (!(context_->getValueByName(
119 "/singletons/com.sun.star.test.deployment."
120 "active_native_singleton") >>=
121 dispatch) ||
122 !dispatch.is())
124 throw css::uno::DeploymentException(
125 "component context fails to supply singleton"
126 " com.sun.star.test.deployment.active_native_singleton of type"
127 " com.sun.star.frame.XDispatch",
128 context_);
130 return dispatch;
133 css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > >
134 Provider::queryDispatches(
135 css::uno::Sequence< css::frame::DispatchDescriptor > const & Requests)
137 css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > s(
138 Requests.getLength());
139 for (sal_Int32 i = 0; i < s.getLength(); ++i) {
140 s[i] = queryDispatch(
141 Requests[i].FeatureURL, Requests[i].FrameName,
142 Requests[i].SearchFlags);
144 return s;
147 class Dispatch:
148 public cppu::WeakImplHelper2<
149 css::lang::XServiceInfo, css::frame::XDispatch >
151 public:
152 Dispatch(const Dispatch&) = delete;
153 const Dispatch& operator=(const Dispatch&) = delete;
155 static css::uno::Reference< css::uno::XInterface > SAL_CALL static_create(
156 css::uno::Reference< css::uno::XComponentContext > const & xContext)
157 { return static_cast< cppu::OWeakObject * >(new Dispatch(xContext)); }
159 static rtl::OUString SAL_CALL static_getImplementationName();
161 static css::uno::Sequence< rtl::OUString > SAL_CALL
162 static_getSupportedServiceNames()
163 { return css::uno::Sequence< rtl::OUString >(); }
165 private:
166 explicit Dispatch(
167 css::uno::Reference< css::uno::XComponentContext > const & context):
168 context_(context) { assert(context.is()); }
170 virtual ~Dispatch() {}
172 virtual rtl::OUString SAL_CALL getImplementationName() override
173 { return static_getImplementationName(); }
175 virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & ServiceName) override
176 { return cppu::supportsService(this, ServiceName); }
178 virtual css::uno::Sequence< rtl::OUString > SAL_CALL
179 getSupportedServiceNames() override
180 { return static_getSupportedServiceNames(); }
182 virtual void SAL_CALL dispatch(
183 css::util::URL const &,
184 css::uno::Sequence< css::beans::PropertyValue > const &) override;
186 virtual void SAL_CALL addStatusListener(
187 css::uno::Reference< css::frame::XStatusListener > const &,
188 css::util::URL const &) override
191 virtual void SAL_CALL removeStatusListener(
192 css::uno::Reference< css::frame::XStatusListener > const &,
193 css::util::URL const &) override
196 css::uno::Reference< css::uno::XComponentContext > context_;
199 rtl::OUString Dispatch::static_getImplementationName() {
200 return rtl::OUString(
201 "com.sun.star.comp.test.deployment.active_native_singleton");
204 void Dispatch::dispatch(
205 css::util::URL const &,
206 css::uno::Sequence< css::beans::PropertyValue > const &)
208 css::uno::Reference< css::frame::XDesktop2 > xDesktop = css::frame::Desktop::create(context_);
209 css::uno::Reference< css::frame::XFrame > xFrame = xDesktop->getCurrentFrame();
210 css::uno::Reference< css::awt::XWindowPeer > xWindowPeer( xFrame->getComponentWindow(), css::uno::UNO_QUERY_THROW );
211 css::uno::Reference< css::awt::XToolkit2 > xToolkit = css::awt::Toolkit::create(context_);
212 css::uno::Reference< css::awt::XMessageBox > box(
213 xToolkit->createMessageBox(
214 xWindowPeer,
215 css::awt::MessageBoxType_INFOBOX,
216 css::awt::MessageBoxButtons::BUTTONS_OK, "active", "native"),
217 css::uno::UNO_SET_THROW);
219 box->execute();
221 css::uno::Reference< css::lang::XComponent > xComponent(box, css::uno::UNO_QUERY_THROW);
222 xComponent->dispose();
225 cppu::ImplementationEntry const services[] = {
226 { &Provider::static_create, &Provider::static_getImplementationName,
227 &Provider::static_getSupportedServiceNames,
228 &cppu::createSingleComponentFactory, nullptr, 0 },
229 { &Dispatch::static_create, &Dispatch::static_getImplementationName,
230 &Dispatch::static_getSupportedServiceNames,
231 &cppu::createSingleComponentFactory, nullptr, 0 },
232 { nullptr, nullptr, nullptr, nullptr, nullptr, 0 }
237 extern "C" SAL_DLLPUBLIC_EXPORT void * component_getFactory(
238 char const * pImplName, void * pServiceManager, void * pRegistryKey)
240 return cppu::component_getFactoryHelper(
241 pImplName, pServiceManager, pRegistryKey, services);
244 extern "C" SAL_DLLPUBLIC_EXPORT void
245 component_getImplementationEnvironment(
246 char const ** ppEnvTypeName, uno_Environment **)
248 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
251 extern "C" SAL_DLLPUBLIC_EXPORT sal_Bool component_writeInfo(
252 void * pServiceManager, void * pRegistryKey)
254 if (!component_writeInfoHelper(pServiceManager, pRegistryKey, services)) {
255 return false;
257 try {
258 css::uno::Reference< css::registry::XRegistryKey >(
259 (css::uno::Reference< css::registry::XRegistryKey >(
260 static_cast< css::registry::XRegistryKey * >(pRegistryKey))->
261 createKey(
262 "/" + Dispatch::static_getImplementationName() +
263 ("/UNO/SINGLETONS/com.sun.star.test.deployment."
264 "active_native_singleton"))),
265 css::uno::UNO_SET_THROW)->
266 setStringValue(Dispatch::static_getImplementationName());
267 } catch (const css::uno::Exception & e) {
268 SAL_INFO(
269 "desktop.test",
270 "active_native component_writeInfo exception: " << e.Message);
271 return false;
273 return true;
276 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */