1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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>
61 public cppu::WeakImplHelper2
<
62 css::lang::XServiceInfo
, css::frame::XDispatchProvider
>
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();
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 return { "com.sun.star.test.deployment.active_native" };
113 css::uno::Reference
< css::frame::XDispatch
> Provider::queryDispatch(
114 css::util::URL
const &, rtl::OUString
const &, sal_Int32
)
116 css::uno::Reference
< css::frame::XDispatch
> dispatch
;
117 if (!(context_
->getValueByName(
118 "/singletons/com.sun.star.test.deployment."
119 "active_native_singleton") >>=
123 throw css::uno::DeploymentException(
124 "component context fails to supply singleton"
125 " com.sun.star.test.deployment.active_native_singleton of type"
126 " com.sun.star.frame.XDispatch",
132 css::uno::Sequence
< css::uno::Reference
< css::frame::XDispatch
> >
133 Provider::queryDispatches(
134 css::uno::Sequence
< css::frame::DispatchDescriptor
> const & Requests
)
136 css::uno::Sequence
< css::uno::Reference
< css::frame::XDispatch
> > s(
137 Requests
.getLength());
138 for (sal_Int32 i
= 0; i
< s
.getLength(); ++i
) {
139 s
[i
] = queryDispatch(
140 Requests
[i
].FeatureURL
, Requests
[i
].FrameName
,
141 Requests
[i
].SearchFlags
);
147 public cppu::WeakImplHelper2
<
148 css::lang::XServiceInfo
, css::frame::XDispatch
>
151 Dispatch(const Dispatch
&) = delete;
152 const Dispatch
& operator=(const Dispatch
&) = delete;
154 static css::uno::Reference
< css::uno::XInterface
> SAL_CALL
static_create(
155 css::uno::Reference
< css::uno::XComponentContext
> const & xContext
)
156 { return static_cast< cppu::OWeakObject
* >(new Dispatch(xContext
)); }
158 static rtl::OUString SAL_CALL
static_getImplementationName();
160 static css::uno::Sequence
< rtl::OUString
> SAL_CALL
161 static_getSupportedServiceNames()
162 { return css::uno::Sequence
< rtl::OUString
>(); }
166 css::uno::Reference
< css::uno::XComponentContext
> const & context
):
167 context_(context
) { assert(context
.is()); }
169 virtual ~Dispatch() {}
171 virtual rtl::OUString SAL_CALL
getImplementationName() override
172 { return static_getImplementationName(); }
174 virtual sal_Bool SAL_CALL
supportsService(rtl::OUString
const & ServiceName
) override
175 { return cppu::supportsService(this, ServiceName
); }
177 virtual css::uno::Sequence
< rtl::OUString
> SAL_CALL
178 getSupportedServiceNames() override
179 { return static_getSupportedServiceNames(); }
181 virtual void SAL_CALL
dispatch(
182 css::util::URL
const &,
183 css::uno::Sequence
< css::beans::PropertyValue
> const &) override
;
185 virtual void SAL_CALL
addStatusListener(
186 css::uno::Reference
< css::frame::XStatusListener
> const &,
187 css::util::URL
const &) override
190 virtual void SAL_CALL
removeStatusListener(
191 css::uno::Reference
< css::frame::XStatusListener
> const &,
192 css::util::URL
const &) override
195 css::uno::Reference
< css::uno::XComponentContext
> context_
;
198 rtl::OUString
Dispatch::static_getImplementationName() {
199 return rtl::OUString(
200 "com.sun.star.comp.test.deployment.active_native_singleton");
203 void Dispatch::dispatch(
204 css::util::URL
const &,
205 css::uno::Sequence
< css::beans::PropertyValue
> const &)
207 css::uno::Reference
< css::frame::XDesktop2
> xDesktop
= css::frame::Desktop::create(context_
);
208 css::uno::Reference
< css::frame::XFrame
> xFrame
= xDesktop
->getCurrentFrame();
209 css::uno::Reference
< css::awt::XWindowPeer
> xWindowPeer( xFrame
->getComponentWindow(), css::uno::UNO_QUERY_THROW
);
210 css::uno::Reference
< css::awt::XToolkit2
> xToolkit
= css::awt::Toolkit::create(context_
);
211 css::uno::Reference
< css::awt::XMessageBox
> box(
212 xToolkit
->createMessageBox(
214 css::awt::MessageBoxType_INFOBOX
,
215 css::awt::MessageBoxButtons::BUTTONS_OK
, "active", "native"),
216 css::uno::UNO_SET_THROW
);
220 css::uno::Reference
< css::lang::XComponent
> xComponent(box
, css::uno::UNO_QUERY_THROW
);
221 xComponent
->dispose();
224 static cppu::ImplementationEntry
const services
[] = {
225 { &Provider::static_create
, &Provider::static_getImplementationName
,
226 &Provider::static_getSupportedServiceNames
,
227 &cppu::createSingleComponentFactory
, nullptr, 0 },
228 { &Dispatch::static_create
, &Dispatch::static_getImplementationName
,
229 &Dispatch::static_getSupportedServiceNames
,
230 &cppu::createSingleComponentFactory
, nullptr, 0 },
231 { nullptr, nullptr, nullptr, nullptr, nullptr, 0 }
236 extern "C" SAL_DLLPUBLIC_EXPORT
void * component_getFactory(
237 char const * pImplName
, void * pServiceManager
, void * pRegistryKey
)
239 return cppu::component_getFactoryHelper(
240 pImplName
, pServiceManager
, pRegistryKey
, services
);
243 extern "C" SAL_DLLPUBLIC_EXPORT
void
244 component_getImplementationEnvironment(
245 char const ** ppEnvTypeName
, uno_Environment
**)
247 *ppEnvTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
;
250 extern "C" SAL_DLLPUBLIC_EXPORT sal_Bool
component_writeInfo(
251 void * pServiceManager
, void * pRegistryKey
)
253 if (!component_writeInfoHelper(pServiceManager
, pRegistryKey
, services
)) {
257 css::uno::Reference
< css::registry::XRegistryKey
>(
258 (css::uno::Reference
< css::registry::XRegistryKey
>(
259 static_cast< css::registry::XRegistryKey
* >(pRegistryKey
))->
261 "/" + Dispatch::static_getImplementationName() +
262 ("/UNO/SINGLETONS/com.sun.star.test.deployment."
263 "active_native_singleton"))),
264 css::uno::UNO_SET_THROW
)->
265 setStringValue(Dispatch::static_getImplementationName());
266 } catch (const css::uno::Exception
& e
) {
269 "active_native component_writeInfo exception: " << e
.Message
);
275 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */