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/uno/DeploymentException.hpp"
44cdf0e10cSrcweir #include "com/sun/star/uno/Exception.hpp"
45cdf0e10cSrcweir #include "com/sun/star/uno/Reference.hxx"
46cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
47cdf0e10cSrcweir #include "com/sun/star/uno/Sequence.hxx"
48cdf0e10cSrcweir #include "com/sun/star/uno/XComponentContext.hpp"
49cdf0e10cSrcweir #include "com/sun/star/uno/XInterface.hpp"
50cdf0e10cSrcweir #include "com/sun/star/util/URL.hpp"
51cdf0e10cSrcweir #include "cppuhelper/factory.hxx"
52cdf0e10cSrcweir #include "cppuhelper/implbase2.hxx"
53cdf0e10cSrcweir #include "cppuhelper/implementationentry.hxx"
54cdf0e10cSrcweir #include "cppuhelper/weak.hxx"
55cdf0e10cSrcweir #include "osl/diagnose.h"
56cdf0e10cSrcweir #include "rtl/ustring.h"
57cdf0e10cSrcweir #include "rtl/ustring.hxx"
58cdf0e10cSrcweir #include "sal/types.h"
59cdf0e10cSrcweir #include "uno/lbnames.h"
60cdf0e10cSrcweir 
61cdf0e10cSrcweir namespace {
62cdf0e10cSrcweir 
63cdf0e10cSrcweir namespace css = com::sun::star;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir class Provider:
66cdf0e10cSrcweir     public cppu::WeakImplHelper2<
67cdf0e10cSrcweir         css::lang::XServiceInfo, css::frame::XDispatchProvider >,
68cdf0e10cSrcweir     private boost::noncopyable
69cdf0e10cSrcweir {
70cdf0e10cSrcweir public:
static_create(css::uno::Reference<css::uno::XComponentContext> const & xContext)71cdf0e10cSrcweir     static css::uno::Reference< css::uno::XInterface > SAL_CALL static_create(
72cdf0e10cSrcweir         css::uno::Reference< css::uno::XComponentContext > const & xContext)
73cdf0e10cSrcweir         SAL_THROW((css::uno::Exception))
74cdf0e10cSrcweir     { return static_cast< cppu::OWeakObject * >(new Provider(xContext)); }
75cdf0e10cSrcweir 
76cdf0e10cSrcweir     static rtl::OUString SAL_CALL static_getImplementationName();
77cdf0e10cSrcweir 
78cdf0e10cSrcweir     static css::uno::Sequence< rtl::OUString > SAL_CALL
79cdf0e10cSrcweir     static_getSupportedServiceNames();
80cdf0e10cSrcweir 
81cdf0e10cSrcweir private:
Provider(css::uno::Reference<css::uno::XComponentContext> const & context)82cdf0e10cSrcweir     Provider(
83cdf0e10cSrcweir         css::uno::Reference< css::uno::XComponentContext > const & context):
84cdf0e10cSrcweir         context_(context) { OSL_ASSERT(context.is()); }
85cdf0e10cSrcweir 
~Provider()86cdf0e10cSrcweir     virtual ~Provider() {}
87cdf0e10cSrcweir 
getImplementationName()88cdf0e10cSrcweir     virtual rtl::OUString SAL_CALL getImplementationName()
89cdf0e10cSrcweir         throw (css::uno::RuntimeException)
90cdf0e10cSrcweir     { return static_getImplementationName(); }
91cdf0e10cSrcweir 
supportsService(rtl::OUString const & ServiceName)92cdf0e10cSrcweir     virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & ServiceName)
93cdf0e10cSrcweir         throw (css::uno::RuntimeException)
94cdf0e10cSrcweir     { return ServiceName == getSupportedServiceNames()[0]; } //TODO
95cdf0e10cSrcweir 
96cdf0e10cSrcweir     virtual css::uno::Sequence< rtl::OUString > SAL_CALL
getSupportedServiceNames()97cdf0e10cSrcweir     getSupportedServiceNames() throw (css::uno::RuntimeException)
98cdf0e10cSrcweir     { return static_getSupportedServiceNames(); }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir     virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch(
101cdf0e10cSrcweir         css::util::URL const &, rtl::OUString const &, sal_Int32)
102cdf0e10cSrcweir         throw (css::uno::RuntimeException);
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > >
105cdf0e10cSrcweir     SAL_CALL queryDispatches(
106cdf0e10cSrcweir         css::uno::Sequence< css::frame::DispatchDescriptor > const & Requests)
107cdf0e10cSrcweir         throw (css::uno::RuntimeException);
108cdf0e10cSrcweir 
109cdf0e10cSrcweir     css::uno::Reference< css::uno::XComponentContext > context_;
110cdf0e10cSrcweir };
111cdf0e10cSrcweir 
static_getImplementationName()112cdf0e10cSrcweir rtl::OUString Provider::static_getImplementationName() {
113cdf0e10cSrcweir     return rtl::OUString(
114cdf0e10cSrcweir         RTL_CONSTASCII_USTRINGPARAM(
115cdf0e10cSrcweir             "com.sun.star.comp.test.deployment.passive_native"));
116cdf0e10cSrcweir }
117cdf0e10cSrcweir 
static_getSupportedServiceNames()118cdf0e10cSrcweir css::uno::Sequence< rtl::OUString > Provider::static_getSupportedServiceNames()
119cdf0e10cSrcweir {
120cdf0e10cSrcweir     rtl::OUString name(
121cdf0e10cSrcweir         RTL_CONSTASCII_USTRINGPARAM(
122cdf0e10cSrcweir             "com.sun.star.test.deployment.passive_native"));
123cdf0e10cSrcweir     return css::uno::Sequence< rtl::OUString >(&name, 1);
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
queryDispatch(css::util::URL const &,rtl::OUString const &,sal_Int32)126cdf0e10cSrcweir css::uno::Reference< css::frame::XDispatch > Provider::queryDispatch(
127cdf0e10cSrcweir     css::util::URL const &, rtl::OUString const &, sal_Int32)
128cdf0e10cSrcweir     throw (css::uno::RuntimeException)
129cdf0e10cSrcweir {
130cdf0e10cSrcweir     css::uno::Reference< css::frame::XDispatch > dispatch;
131cdf0e10cSrcweir     if (!(context_->getValueByName(
132cdf0e10cSrcweir               rtl::OUString(
133cdf0e10cSrcweir                   RTL_CONSTASCII_USTRINGPARAM(
134cdf0e10cSrcweir                       "/singletons/com.sun.star.test.deployment."
135cdf0e10cSrcweir                       "passive_native_singleton"))) >>=
136cdf0e10cSrcweir           dispatch) ||
137cdf0e10cSrcweir         !dispatch.is())
138cdf0e10cSrcweir     {
139cdf0e10cSrcweir         throw css::uno::DeploymentException(
140cdf0e10cSrcweir             rtl::OUString(
141cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
142cdf0e10cSrcweir                     "component context fails to supply singleton"
143cdf0e10cSrcweir                     " com.sun.star.test.deployment.passive_native_singleton of"
144cdf0e10cSrcweir                     " type com.sun.star.frame.XDispatch")),
145cdf0e10cSrcweir             context_);
146cdf0e10cSrcweir     }
147cdf0e10cSrcweir     return dispatch;
148cdf0e10cSrcweir }
149cdf0e10cSrcweir 
150cdf0e10cSrcweir css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > >
queryDispatches(css::uno::Sequence<css::frame::DispatchDescriptor> const & Requests)151cdf0e10cSrcweir Provider::queryDispatches(
152cdf0e10cSrcweir     css::uno::Sequence< css::frame::DispatchDescriptor > const & Requests)
153cdf0e10cSrcweir     throw (css::uno::RuntimeException)
154cdf0e10cSrcweir {
155cdf0e10cSrcweir     css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > s(
156cdf0e10cSrcweir         Requests.getLength());
157cdf0e10cSrcweir     for (sal_Int32 i = 0; i < s.getLength(); ++i) {
158cdf0e10cSrcweir         s[i] = queryDispatch(
159cdf0e10cSrcweir             Requests[i].FeatureURL, Requests[i].FrameName,
160cdf0e10cSrcweir             Requests[i].SearchFlags);
161cdf0e10cSrcweir     }
162cdf0e10cSrcweir     return s;
163cdf0e10cSrcweir }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir class Dispatch:
166cdf0e10cSrcweir     public cppu::WeakImplHelper2<
167cdf0e10cSrcweir         css::lang::XServiceInfo, css::frame::XDispatch >,
168cdf0e10cSrcweir     private boost::noncopyable
169cdf0e10cSrcweir {
170cdf0e10cSrcweir public:
static_create(css::uno::Reference<css::uno::XComponentContext> const & xContext)171cdf0e10cSrcweir     static css::uno::Reference< css::uno::XInterface > SAL_CALL static_create(
172cdf0e10cSrcweir         css::uno::Reference< css::uno::XComponentContext > const & xContext)
173cdf0e10cSrcweir         SAL_THROW((css::uno::Exception))
174cdf0e10cSrcweir     { return static_cast< cppu::OWeakObject * >(new Dispatch(xContext)); }
175cdf0e10cSrcweir 
176cdf0e10cSrcweir     static rtl::OUString SAL_CALL static_getImplementationName();
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     static css::uno::Sequence< rtl::OUString > SAL_CALL
static_getSupportedServiceNames()179cdf0e10cSrcweir     static_getSupportedServiceNames()
180cdf0e10cSrcweir     { return css::uno::Sequence< rtl::OUString >(); }
181cdf0e10cSrcweir 
182cdf0e10cSrcweir private:
Dispatch(css::uno::Reference<css::uno::XComponentContext> const & context)183cdf0e10cSrcweir     Dispatch(
184cdf0e10cSrcweir         css::uno::Reference< css::uno::XComponentContext > const & context):
185cdf0e10cSrcweir         context_(context) { OSL_ASSERT(context.is()); }
186cdf0e10cSrcweir 
~Dispatch()187cdf0e10cSrcweir     virtual ~Dispatch() {}
188cdf0e10cSrcweir 
getImplementationName()189cdf0e10cSrcweir     virtual rtl::OUString SAL_CALL getImplementationName()
190cdf0e10cSrcweir         throw (css::uno::RuntimeException)
191cdf0e10cSrcweir     { return static_getImplementationName(); }
192cdf0e10cSrcweir 
supportsService(rtl::OUString const &)193cdf0e10cSrcweir     virtual sal_Bool SAL_CALL supportsService(rtl::OUString const &)
194cdf0e10cSrcweir         throw (css::uno::RuntimeException)
195cdf0e10cSrcweir     { return false; } //TODO
196cdf0e10cSrcweir 
197cdf0e10cSrcweir     virtual css::uno::Sequence< rtl::OUString > SAL_CALL
getSupportedServiceNames()198cdf0e10cSrcweir     getSupportedServiceNames() throw (css::uno::RuntimeException)
199cdf0e10cSrcweir     { return static_getSupportedServiceNames(); }
200cdf0e10cSrcweir 
201cdf0e10cSrcweir     virtual void SAL_CALL dispatch(
202cdf0e10cSrcweir         css::util::URL const &,
203cdf0e10cSrcweir         css::uno::Sequence< css::beans::PropertyValue > const &)
204cdf0e10cSrcweir         throw (css::uno::RuntimeException);
205cdf0e10cSrcweir 
addStatusListener(css::uno::Reference<css::frame::XStatusListener> const &,css::util::URL const &)206cdf0e10cSrcweir     virtual void SAL_CALL addStatusListener(
207cdf0e10cSrcweir         css::uno::Reference< css::frame::XStatusListener > const &,
208cdf0e10cSrcweir         css::util::URL const &)
209cdf0e10cSrcweir         throw (css::uno::RuntimeException)
210cdf0e10cSrcweir     {}
211cdf0e10cSrcweir 
removeStatusListener(css::uno::Reference<css::frame::XStatusListener> const &,css::util::URL const &)212cdf0e10cSrcweir     virtual void SAL_CALL removeStatusListener(
213cdf0e10cSrcweir         css::uno::Reference< css::frame::XStatusListener > const &,
214cdf0e10cSrcweir         css::util::URL const &)
215cdf0e10cSrcweir         throw (css::uno::RuntimeException)
216cdf0e10cSrcweir     {}
217cdf0e10cSrcweir 
218cdf0e10cSrcweir     css::uno::Reference< css::uno::XComponentContext > context_;
219cdf0e10cSrcweir };
220cdf0e10cSrcweir 
static_getImplementationName()221cdf0e10cSrcweir rtl::OUString Dispatch::static_getImplementationName() {
222cdf0e10cSrcweir     return rtl::OUString(
223cdf0e10cSrcweir         RTL_CONSTASCII_USTRINGPARAM(
224cdf0e10cSrcweir             "com.sun.star.comp.test.deployment.passive_native_singleton"));
225cdf0e10cSrcweir }
226cdf0e10cSrcweir 
dispatch(css::util::URL const &,css::uno::Sequence<css::beans::PropertyValue> const &)227cdf0e10cSrcweir void Dispatch::dispatch(
228cdf0e10cSrcweir     css::util::URL const &,
229cdf0e10cSrcweir     css::uno::Sequence< css::beans::PropertyValue > const &)
230cdf0e10cSrcweir     throw (css::uno::RuntimeException)
231cdf0e10cSrcweir {
232cdf0e10cSrcweir     css::uno::Reference< css::lang::XMultiComponentFactory > smgr(
233cdf0e10cSrcweir         context_->getServiceManager(), css::uno::UNO_SET_THROW);
234cdf0e10cSrcweir     css::uno::Reference< css::awt::XMessageBox > box(
235cdf0e10cSrcweir         css::uno::Reference< css::awt::XMessageBoxFactory >(
236cdf0e10cSrcweir             smgr->createInstanceWithContext(
237cdf0e10cSrcweir                 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
238cdf0e10cSrcweir                                   "com.sun.star.awt.Toolkit")), context_),
239cdf0e10cSrcweir             css::uno::UNO_QUERY_THROW)->createMessageBox(
240cdf0e10cSrcweir                 css::uno::Reference< css::awt::XWindowPeer >(
241cdf0e10cSrcweir                     css::uno::Reference< css::frame::XFrame >(
242cdf0e10cSrcweir                         css::uno::Reference< css::frame::XDesktop >(
243cdf0e10cSrcweir                             smgr->createInstanceWithContext(
244cdf0e10cSrcweir                                 rtl::OUString(
245cdf0e10cSrcweir                                     RTL_CONSTASCII_USTRINGPARAM(
246cdf0e10cSrcweir                                         "com.sun.star.frame.Desktop")),
247cdf0e10cSrcweir                                 context_),
248cdf0e10cSrcweir                             css::uno::UNO_QUERY_THROW)->getCurrentFrame(),
249cdf0e10cSrcweir                         css::uno::UNO_SET_THROW)->getComponentWindow(),
250cdf0e10cSrcweir                     css::uno::UNO_QUERY_THROW),
251*61161268SAriel Constenla-Haile                 css::awt::MessageBoxType_INFOBOX,
252cdf0e10cSrcweir                 css::awt::MessageBoxButtons::BUTTONS_OK,
253cdf0e10cSrcweir                 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("passive")),
254cdf0e10cSrcweir                 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("native"))),
255cdf0e10cSrcweir         css::uno::UNO_SET_THROW);
256cdf0e10cSrcweir     box->execute();
257cdf0e10cSrcweir     css::uno::Reference< css::lang::XComponent >(
258cdf0e10cSrcweir         box, css::uno::UNO_QUERY_THROW)->dispose();
259cdf0e10cSrcweir }
260cdf0e10cSrcweir 
261cdf0e10cSrcweir static cppu::ImplementationEntry const services[] = {
262cdf0e10cSrcweir     { &Provider::static_create, &Provider::static_getImplementationName,
263cdf0e10cSrcweir       &Provider::static_getSupportedServiceNames,
264cdf0e10cSrcweir       &cppu::createSingleComponentFactory, 0, 0 },
265cdf0e10cSrcweir     { &Dispatch::static_create, &Dispatch::static_getImplementationName,
266cdf0e10cSrcweir       &Dispatch::static_getSupportedServiceNames,
267cdf0e10cSrcweir       &cppu::createSingleComponentFactory, 0, 0 },
268cdf0e10cSrcweir     { 0, 0, 0, 0, 0, 0 }
269cdf0e10cSrcweir };
270cdf0e10cSrcweir 
271cdf0e10cSrcweir }
272cdf0e10cSrcweir 
component_getFactory(char const * pImplName,void * pServiceManager,void * pRegistryKey)273cdf0e10cSrcweir extern "C" void * SAL_CALL component_getFactory(
274cdf0e10cSrcweir     char const * pImplName, void * pServiceManager, void * pRegistryKey)
275cdf0e10cSrcweir {
276cdf0e10cSrcweir     return cppu::component_getFactoryHelper(
277cdf0e10cSrcweir         pImplName, pServiceManager, pRegistryKey, services);
278cdf0e10cSrcweir }
279cdf0e10cSrcweir 
component_getImplementationEnvironment(char const ** ppEnvTypeName,uno_Environment **)280cdf0e10cSrcweir extern "C" void SAL_CALL component_getImplementationEnvironment(
281cdf0e10cSrcweir     char const ** ppEnvTypeName, uno_Environment **)
282cdf0e10cSrcweir {
283cdf0e10cSrcweir     *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
284cdf0e10cSrcweir }
285