12722ceddSAndrew Rist /**************************************************************
22722ceddSAndrew Rist *
32722ceddSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
42722ceddSAndrew Rist * or more contributor license agreements. See the NOTICE file
52722ceddSAndrew Rist * distributed with this work for additional information
62722ceddSAndrew Rist * regarding copyright ownership. The ASF licenses this file
72722ceddSAndrew Rist * to you under the Apache License, Version 2.0 (the
82722ceddSAndrew Rist * "License"); you may not use this file except in compliance
92722ceddSAndrew Rist * with the License. You may obtain a copy of the License at
102722ceddSAndrew Rist *
112722ceddSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
122722ceddSAndrew Rist *
132722ceddSAndrew Rist * Unless required by applicable law or agreed to in writing,
142722ceddSAndrew Rist * software distributed under the License is distributed on an
152722ceddSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162722ceddSAndrew Rist * KIND, either express or implied. See the License for the
172722ceddSAndrew Rist * specific language governing permissions and limitations
182722ceddSAndrew Rist * under the License.
192722ceddSAndrew Rist *
202722ceddSAndrew Rist *************************************************************/
212722ceddSAndrew Rist
222722ceddSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include "precompiled_desktop.hxx"
25cdf0e10cSrcweir #include "sal/config.h"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "boost/noncopyable.hpp"
28cdf0e10cSrcweir #include "com/sun/star/awt/MessageBoxButtons.hpp"
29cdf0e10cSrcweir #include "com/sun/star/awt/Rectangle.hpp"
30cdf0e10cSrcweir #include "com/sun/star/awt/XMessageBox.hpp"
31cdf0e10cSrcweir #include "com/sun/star/awt/XMessageBoxFactory.hpp"
32cdf0e10cSrcweir #include "com/sun/star/awt/XWindowPeer.hpp"
33cdf0e10cSrcweir #include "com/sun/star/beans/PropertyValue.hpp"
34cdf0e10cSrcweir #include "com/sun/star/frame/DispatchDescriptor.hpp"
35cdf0e10cSrcweir #include "com/sun/star/frame/XDesktop.hpp"
36cdf0e10cSrcweir #include "com/sun/star/frame/XDispatch.hpp"
37cdf0e10cSrcweir #include "com/sun/star/frame/XDispatchProvider.hpp"
38cdf0e10cSrcweir #include "com/sun/star/frame/XFrame.hpp"
39cdf0e10cSrcweir #include "com/sun/star/frame/XStatusListener.hpp"
40cdf0e10cSrcweir #include "com/sun/star/lang/XComponent.hpp"
41cdf0e10cSrcweir #include "com/sun/star/lang/XMultiComponentFactory.hpp"
42cdf0e10cSrcweir #include "com/sun/star/lang/XServiceInfo.hpp"
43cdf0e10cSrcweir #include "com/sun/star/registry/XRegistryKey.hpp"
44cdf0e10cSrcweir #include "com/sun/star/uno/DeploymentException.hpp"
45cdf0e10cSrcweir #include "com/sun/star/uno/Exception.hpp"
46cdf0e10cSrcweir #include "com/sun/star/uno/Reference.hxx"
47cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
48cdf0e10cSrcweir #include "com/sun/star/uno/Sequence.hxx"
49cdf0e10cSrcweir #include "com/sun/star/uno/XComponentContext.hpp"
50cdf0e10cSrcweir #include "com/sun/star/uno/XInterface.hpp"
51cdf0e10cSrcweir #include "com/sun/star/util/URL.hpp"
52cdf0e10cSrcweir #include "cppuhelper/factory.hxx"
53cdf0e10cSrcweir #include "cppuhelper/implbase2.hxx"
54cdf0e10cSrcweir #include "cppuhelper/implementationentry.hxx"
55cdf0e10cSrcweir #include "cppuhelper/weak.hxx"
56cdf0e10cSrcweir #include "osl/diagnose.h"
57cdf0e10cSrcweir #include "rtl/textenc.h"
58cdf0e10cSrcweir #include "rtl/ustring.h"
59cdf0e10cSrcweir #include "rtl/ustring.hxx"
60cdf0e10cSrcweir #include "sal/types.h"
61cdf0e10cSrcweir #include "uno/lbnames.h"
62cdf0e10cSrcweir
63cdf0e10cSrcweir namespace {
64cdf0e10cSrcweir
65cdf0e10cSrcweir namespace css = com::sun::star;
66cdf0e10cSrcweir
67cdf0e10cSrcweir class Provider:
68cdf0e10cSrcweir public cppu::WeakImplHelper2<
69cdf0e10cSrcweir css::lang::XServiceInfo, css::frame::XDispatchProvider >,
70cdf0e10cSrcweir private boost::noncopyable
71cdf0e10cSrcweir {
72cdf0e10cSrcweir public:
static_create(css::uno::Reference<css::uno::XComponentContext> const & xContext)73cdf0e10cSrcweir static css::uno::Reference< css::uno::XInterface > SAL_CALL static_create(
74cdf0e10cSrcweir css::uno::Reference< css::uno::XComponentContext > const & xContext)
75cdf0e10cSrcweir SAL_THROW((css::uno::Exception))
76cdf0e10cSrcweir { return static_cast< cppu::OWeakObject * >(new Provider(xContext)); }
77cdf0e10cSrcweir
78cdf0e10cSrcweir static rtl::OUString SAL_CALL static_getImplementationName();
79cdf0e10cSrcweir
80cdf0e10cSrcweir static css::uno::Sequence< rtl::OUString > SAL_CALL
81cdf0e10cSrcweir static_getSupportedServiceNames();
82cdf0e10cSrcweir
83cdf0e10cSrcweir private:
Provider(css::uno::Reference<css::uno::XComponentContext> const & context)84cdf0e10cSrcweir Provider(
85cdf0e10cSrcweir css::uno::Reference< css::uno::XComponentContext > const & context):
86cdf0e10cSrcweir context_(context) { OSL_ASSERT(context.is()); }
87cdf0e10cSrcweir
~Provider()88cdf0e10cSrcweir virtual ~Provider() {}
89cdf0e10cSrcweir
getImplementationName()90cdf0e10cSrcweir virtual rtl::OUString SAL_CALL getImplementationName()
91cdf0e10cSrcweir throw (css::uno::RuntimeException)
92cdf0e10cSrcweir { return static_getImplementationName(); }
93cdf0e10cSrcweir
supportsService(rtl::OUString const & ServiceName)94cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & ServiceName)
95cdf0e10cSrcweir throw (css::uno::RuntimeException)
96cdf0e10cSrcweir { return ServiceName == getSupportedServiceNames()[0]; } //TODO
97cdf0e10cSrcweir
98cdf0e10cSrcweir virtual css::uno::Sequence< rtl::OUString > SAL_CALL
getSupportedServiceNames()99cdf0e10cSrcweir getSupportedServiceNames() throw (css::uno::RuntimeException)
100cdf0e10cSrcweir { return static_getSupportedServiceNames(); }
101cdf0e10cSrcweir
102cdf0e10cSrcweir virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch(
103cdf0e10cSrcweir css::util::URL const &, rtl::OUString const &, sal_Int32)
104cdf0e10cSrcweir throw (css::uno::RuntimeException);
105cdf0e10cSrcweir
106cdf0e10cSrcweir virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > >
107cdf0e10cSrcweir SAL_CALL queryDispatches(
108cdf0e10cSrcweir css::uno::Sequence< css::frame::DispatchDescriptor > const & Requests)
109cdf0e10cSrcweir throw (css::uno::RuntimeException);
110cdf0e10cSrcweir
111cdf0e10cSrcweir css::uno::Reference< css::uno::XComponentContext > context_;
112cdf0e10cSrcweir };
113cdf0e10cSrcweir
static_getImplementationName()114cdf0e10cSrcweir rtl::OUString Provider::static_getImplementationName() {
115cdf0e10cSrcweir return rtl::OUString(
116cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM(
117cdf0e10cSrcweir "com.sun.star.comp.test.deployment.active_native"));
118cdf0e10cSrcweir }
119cdf0e10cSrcweir
static_getSupportedServiceNames()120cdf0e10cSrcweir css::uno::Sequence< rtl::OUString > Provider::static_getSupportedServiceNames()
121cdf0e10cSrcweir {
122cdf0e10cSrcweir rtl::OUString name(
123cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM(
124cdf0e10cSrcweir "com.sun.star.test.deployment.active_native"));
125cdf0e10cSrcweir return css::uno::Sequence< rtl::OUString >(&name, 1);
126cdf0e10cSrcweir }
127cdf0e10cSrcweir
queryDispatch(css::util::URL const &,rtl::OUString const &,sal_Int32)128cdf0e10cSrcweir css::uno::Reference< css::frame::XDispatch > Provider::queryDispatch(
129cdf0e10cSrcweir css::util::URL const &, rtl::OUString const &, sal_Int32)
130cdf0e10cSrcweir throw (css::uno::RuntimeException)
131cdf0e10cSrcweir {
132cdf0e10cSrcweir css::uno::Reference< css::frame::XDispatch > dispatch;
133cdf0e10cSrcweir if (!(context_->getValueByName(
134cdf0e10cSrcweir rtl::OUString(
135cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM(
136cdf0e10cSrcweir "/singletons/com.sun.star.test.deployment."
137cdf0e10cSrcweir "active_native_singleton"))) >>=
138cdf0e10cSrcweir dispatch) ||
139cdf0e10cSrcweir !dispatch.is())
140cdf0e10cSrcweir {
141cdf0e10cSrcweir throw css::uno::DeploymentException(
142cdf0e10cSrcweir rtl::OUString(
143cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM(
144cdf0e10cSrcweir "component context fails to supply singleton"
145cdf0e10cSrcweir " com.sun.star.test.deployment.active_native_singleton of"
146cdf0e10cSrcweir " type com.sun.star.frame.XDispatch")),
147cdf0e10cSrcweir context_);
148cdf0e10cSrcweir }
149cdf0e10cSrcweir return dispatch;
150cdf0e10cSrcweir }
151cdf0e10cSrcweir
152cdf0e10cSrcweir css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > >
queryDispatches(css::uno::Sequence<css::frame::DispatchDescriptor> const & Requests)153cdf0e10cSrcweir Provider::queryDispatches(
154cdf0e10cSrcweir css::uno::Sequence< css::frame::DispatchDescriptor > const & Requests)
155cdf0e10cSrcweir throw (css::uno::RuntimeException)
156cdf0e10cSrcweir {
157cdf0e10cSrcweir css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > s(
158cdf0e10cSrcweir Requests.getLength());
159cdf0e10cSrcweir for (sal_Int32 i = 0; i < s.getLength(); ++i) {
160cdf0e10cSrcweir s[i] = queryDispatch(
161cdf0e10cSrcweir Requests[i].FeatureURL, Requests[i].FrameName,
162cdf0e10cSrcweir Requests[i].SearchFlags);
163cdf0e10cSrcweir }
164cdf0e10cSrcweir return s;
165cdf0e10cSrcweir }
166cdf0e10cSrcweir
167cdf0e10cSrcweir class Dispatch:
168cdf0e10cSrcweir public cppu::WeakImplHelper2<
169cdf0e10cSrcweir css::lang::XServiceInfo, css::frame::XDispatch >,
170cdf0e10cSrcweir private boost::noncopyable
171cdf0e10cSrcweir {
172cdf0e10cSrcweir public:
static_create(css::uno::Reference<css::uno::XComponentContext> const & xContext)173cdf0e10cSrcweir static css::uno::Reference< css::uno::XInterface > SAL_CALL static_create(
174cdf0e10cSrcweir css::uno::Reference< css::uno::XComponentContext > const & xContext)
175cdf0e10cSrcweir SAL_THROW((css::uno::Exception))
176cdf0e10cSrcweir { return static_cast< cppu::OWeakObject * >(new Dispatch(xContext)); }
177cdf0e10cSrcweir
178cdf0e10cSrcweir static rtl::OUString SAL_CALL static_getImplementationName();
179cdf0e10cSrcweir
180cdf0e10cSrcweir static css::uno::Sequence< rtl::OUString > SAL_CALL
static_getSupportedServiceNames()181cdf0e10cSrcweir static_getSupportedServiceNames()
182cdf0e10cSrcweir { return css::uno::Sequence< rtl::OUString >(); }
183cdf0e10cSrcweir
184cdf0e10cSrcweir private:
Dispatch(css::uno::Reference<css::uno::XComponentContext> const & context)185cdf0e10cSrcweir Dispatch(
186cdf0e10cSrcweir css::uno::Reference< css::uno::XComponentContext > const & context):
187cdf0e10cSrcweir context_(context) { OSL_ASSERT(context.is()); }
188cdf0e10cSrcweir
~Dispatch()189cdf0e10cSrcweir virtual ~Dispatch() {}
190cdf0e10cSrcweir
getImplementationName()191cdf0e10cSrcweir virtual rtl::OUString SAL_CALL getImplementationName()
192cdf0e10cSrcweir throw (css::uno::RuntimeException)
193cdf0e10cSrcweir { return static_getImplementationName(); }
194cdf0e10cSrcweir
supportsService(rtl::OUString const &)195cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService(rtl::OUString const &)
196cdf0e10cSrcweir throw (css::uno::RuntimeException)
197cdf0e10cSrcweir { return false; } //TODO
198cdf0e10cSrcweir
199cdf0e10cSrcweir virtual css::uno::Sequence< rtl::OUString > SAL_CALL
getSupportedServiceNames()200cdf0e10cSrcweir getSupportedServiceNames() throw (css::uno::RuntimeException)
201cdf0e10cSrcweir { return static_getSupportedServiceNames(); }
202cdf0e10cSrcweir
203cdf0e10cSrcweir virtual void SAL_CALL dispatch(
204cdf0e10cSrcweir css::util::URL const &,
205cdf0e10cSrcweir css::uno::Sequence< css::beans::PropertyValue > const &)
206cdf0e10cSrcweir throw (css::uno::RuntimeException);
207cdf0e10cSrcweir
addStatusListener(css::uno::Reference<css::frame::XStatusListener> const &,css::util::URL const &)208cdf0e10cSrcweir virtual void SAL_CALL addStatusListener(
209cdf0e10cSrcweir css::uno::Reference< css::frame::XStatusListener > const &,
210cdf0e10cSrcweir css::util::URL const &)
211cdf0e10cSrcweir throw (css::uno::RuntimeException)
212cdf0e10cSrcweir {}
213cdf0e10cSrcweir
removeStatusListener(css::uno::Reference<css::frame::XStatusListener> const &,css::util::URL const &)214cdf0e10cSrcweir virtual void SAL_CALL removeStatusListener(
215cdf0e10cSrcweir css::uno::Reference< css::frame::XStatusListener > const &,
216cdf0e10cSrcweir css::util::URL const &)
217cdf0e10cSrcweir throw (css::uno::RuntimeException)
218cdf0e10cSrcweir {}
219cdf0e10cSrcweir
220cdf0e10cSrcweir css::uno::Reference< css::uno::XComponentContext > context_;
221cdf0e10cSrcweir };
222cdf0e10cSrcweir
static_getImplementationName()223cdf0e10cSrcweir rtl::OUString Dispatch::static_getImplementationName() {
224cdf0e10cSrcweir return rtl::OUString(
225cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM(
226cdf0e10cSrcweir "com.sun.star.comp.test.deployment.active_native_singleton"));
227cdf0e10cSrcweir }
228cdf0e10cSrcweir
dispatch(css::util::URL const &,css::uno::Sequence<css::beans::PropertyValue> const &)229cdf0e10cSrcweir void Dispatch::dispatch(
230cdf0e10cSrcweir css::util::URL const &,
231cdf0e10cSrcweir css::uno::Sequence< css::beans::PropertyValue > const &)
232cdf0e10cSrcweir throw (css::uno::RuntimeException)
233cdf0e10cSrcweir {
234cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiComponentFactory > smgr(
235cdf0e10cSrcweir context_->getServiceManager(), css::uno::UNO_SET_THROW);
236cdf0e10cSrcweir css::uno::Reference< css::awt::XMessageBox > box(
237cdf0e10cSrcweir css::uno::Reference< css::awt::XMessageBoxFactory >(
238cdf0e10cSrcweir smgr->createInstanceWithContext(
239cdf0e10cSrcweir rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
240cdf0e10cSrcweir "com.sun.star.awt.Toolkit")), context_),
241cdf0e10cSrcweir css::uno::UNO_QUERY_THROW)->createMessageBox(
242cdf0e10cSrcweir css::uno::Reference< css::awt::XWindowPeer >(
243cdf0e10cSrcweir css::uno::Reference< css::frame::XFrame >(
244cdf0e10cSrcweir css::uno::Reference< css::frame::XDesktop >(
245cdf0e10cSrcweir smgr->createInstanceWithContext(
246cdf0e10cSrcweir rtl::OUString(
247cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM(
248cdf0e10cSrcweir "com.sun.star.frame.Desktop")),
249cdf0e10cSrcweir context_),
250cdf0e10cSrcweir css::uno::UNO_QUERY_THROW)->getCurrentFrame(),
251cdf0e10cSrcweir css::uno::UNO_SET_THROW)->getComponentWindow(),
252cdf0e10cSrcweir css::uno::UNO_QUERY_THROW),
253*61161268SAriel Constenla-Haile css::awt::MessageBoxType_INFOBOX,
254cdf0e10cSrcweir css::awt::MessageBoxButtons::BUTTONS_OK,
255cdf0e10cSrcweir rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("active")),
256cdf0e10cSrcweir rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("native"))),
257cdf0e10cSrcweir css::uno::UNO_SET_THROW);
258cdf0e10cSrcweir box->execute();
259cdf0e10cSrcweir css::uno::Reference< css::lang::XComponent >(
260cdf0e10cSrcweir box, css::uno::UNO_QUERY_THROW)->dispose();
261cdf0e10cSrcweir }
262cdf0e10cSrcweir
263cdf0e10cSrcweir static cppu::ImplementationEntry const services[] = {
264cdf0e10cSrcweir { &Provider::static_create, &Provider::static_getImplementationName,
265cdf0e10cSrcweir &Provider::static_getSupportedServiceNames,
266cdf0e10cSrcweir &cppu::createSingleComponentFactory, 0, 0 },
267cdf0e10cSrcweir { &Dispatch::static_create, &Dispatch::static_getImplementationName,
268cdf0e10cSrcweir &Dispatch::static_getSupportedServiceNames,
269cdf0e10cSrcweir &cppu::createSingleComponentFactory, 0, 0 },
270cdf0e10cSrcweir { 0, 0, 0, 0, 0, 0 }
271cdf0e10cSrcweir };
272cdf0e10cSrcweir
273cdf0e10cSrcweir }
274cdf0e10cSrcweir
component_getFactory(char const * pImplName,void * pServiceManager,void * pRegistryKey)275cdf0e10cSrcweir extern "C" void * SAL_CALL component_getFactory(
276cdf0e10cSrcweir char const * pImplName, void * pServiceManager, void * pRegistryKey)
277cdf0e10cSrcweir {
278cdf0e10cSrcweir return cppu::component_getFactoryHelper(
279cdf0e10cSrcweir pImplName, pServiceManager, pRegistryKey, services);
280cdf0e10cSrcweir }
281cdf0e10cSrcweir
component_getImplementationEnvironment(char const ** ppEnvTypeName,uno_Environment **)282cdf0e10cSrcweir extern "C" void SAL_CALL component_getImplementationEnvironment(
283cdf0e10cSrcweir char const ** ppEnvTypeName, uno_Environment **)
284cdf0e10cSrcweir {
285cdf0e10cSrcweir *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
286cdf0e10cSrcweir }
287cdf0e10cSrcweir
component_writeInfo(void * pServiceManager,void * pRegistryKey)288cdf0e10cSrcweir extern "C" sal_Bool SAL_CALL component_writeInfo(
289cdf0e10cSrcweir void * pServiceManager, void * pRegistryKey)
290cdf0e10cSrcweir {
291cdf0e10cSrcweir if (!component_writeInfoHelper(pServiceManager, pRegistryKey, services)) {
292cdf0e10cSrcweir return false;
293cdf0e10cSrcweir }
294cdf0e10cSrcweir try {
295cdf0e10cSrcweir css::uno::Reference< css::registry::XRegistryKey >(
296cdf0e10cSrcweir (css::uno::Reference< css::registry::XRegistryKey >(
297cdf0e10cSrcweir static_cast< css::registry::XRegistryKey * >(pRegistryKey))->
298cdf0e10cSrcweir createKey(
299cdf0e10cSrcweir rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) +
300cdf0e10cSrcweir Dispatch::static_getImplementationName() +
301cdf0e10cSrcweir rtl::OUString(
302cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM(
303cdf0e10cSrcweir "/UNO/SINGLETONS/com.sun.star.test.deployment."
304cdf0e10cSrcweir "active_native_singleton")))),
305cdf0e10cSrcweir css::uno::UNO_SET_THROW)->
306cdf0e10cSrcweir setStringValue(Dispatch::static_getImplementationName());
307cdf0e10cSrcweir } catch (css::uno::Exception & e) {
308cdf0e10cSrcweir (void) e;
309cdf0e10cSrcweir OSL_TRACE(
310cdf0e10cSrcweir "active_native component_writeInfo exception: %s",
311cdf0e10cSrcweir rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).getStr());
312cdf0e10cSrcweir return false;
313cdf0e10cSrcweir }
314cdf0e10cSrcweir return true;
315cdf0e10cSrcweir }
316