xref: /trunk/main/desktop/test/deployment/boxt/boxt.cxx (revision 2722cedd)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "precompiled_desktop.hxx"
25 #include "sal/config.h"
26 
27 #include "boost/noncopyable.hpp"
28 #include "com/sun/star/beans/PropertyValue.hpp"
29 #include "com/sun/star/frame/DispatchDescriptor.hpp"
30 #include "com/sun/star/frame/XDispatch.hpp"
31 #include "com/sun/star/frame/XDispatchProvider.hpp"
32 #include "com/sun/star/frame/XStatusListener.hpp"
33 #include "com/sun/star/lang/XServiceInfo.hpp"
34 #include "com/sun/star/uno/Exception.hpp"
35 #include "com/sun/star/uno/Reference.hxx"
36 #include "com/sun/star/uno/RuntimeException.hpp"
37 #include "com/sun/star/uno/Sequence.hxx"
38 #include "com/sun/star/uno/XComponentContext.hpp"
39 #include "com/sun/star/uno/XInterface.hpp"
40 #include "com/sun/star/util/URL.hpp"
41 #include "cppuhelper/factory.hxx"
42 #include "cppuhelper/implbase3.hxx"
43 #include "cppuhelper/implementationentry.hxx"
44 #include "cppuhelper/weak.hxx"
45 #include "filter/msfilter/countryid.hxx"
46 #include "osl/diagnose.h"
47 #include "rtl/ustring.h"
48 #include "rtl/ustring.hxx"
49 #include "sal/types.h"
50 #include "uno/lbnames.h"
51 #include "vcl/svapp.hxx"
52 
53 namespace {
54 
55 namespace css = com::sun::star;
56 
57 class Service:
58     public cppu::WeakImplHelper3<
59         css::lang::XServiceInfo, css::frame::XDispatchProvider,
60         css::frame::XDispatch >,
61     private boost::noncopyable
62 {
63 public:
static_create(css::uno::Reference<css::uno::XComponentContext> const &)64     static css::uno::Reference< css::uno::XInterface > SAL_CALL static_create(
65         css::uno::Reference< css::uno::XComponentContext > const &)
66         SAL_THROW((css::uno::Exception))
67     { return static_cast< cppu::OWeakObject * >(new Service); }
68 
69     static rtl::OUString SAL_CALL static_getImplementationName();
70 
71     static css::uno::Sequence< rtl::OUString > SAL_CALL
72     static_getSupportedServiceNames();
73 
74 private:
Service()75     Service() {}
76 
~Service()77     virtual ~Service() {}
78 
getImplementationName()79     virtual rtl::OUString SAL_CALL getImplementationName()
80         throw (css::uno::RuntimeException)
81     { return static_getImplementationName(); }
82 
supportsService(rtl::OUString const & ServiceName)83     virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & ServiceName)
84         throw (css::uno::RuntimeException)
85     { return ServiceName == getSupportedServiceNames()[0]; } //TODO
86 
87     virtual css::uno::Sequence< rtl::OUString > SAL_CALL
getSupportedServiceNames()88     getSupportedServiceNames() throw (css::uno::RuntimeException)
89     { return static_getSupportedServiceNames(); }
90 
queryDispatch(css::util::URL const &,rtl::OUString const &,sal_Int32)91     virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch(
92         css::util::URL const &, rtl::OUString const &, sal_Int32)
93         throw (css::uno::RuntimeException)
94     { return this; }
95 
96     virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > >
97     SAL_CALL queryDispatches(
98         css::uno::Sequence< css::frame::DispatchDescriptor > const & Requests)
99         throw (css::uno::RuntimeException);
100 
101     virtual void SAL_CALL dispatch(
102         css::util::URL const &,
103         css::uno::Sequence< css::beans::PropertyValue > const &)
104         throw (css::uno::RuntimeException);
105 
addStatusListener(css::uno::Reference<css::frame::XStatusListener> const &,css::util::URL const &)106     virtual void SAL_CALL addStatusListener(
107         css::uno::Reference< css::frame::XStatusListener > const &,
108         css::util::URL const &)
109         throw (css::uno::RuntimeException)
110     {}
111 
removeStatusListener(css::uno::Reference<css::frame::XStatusListener> const &,css::util::URL const &)112     virtual void SAL_CALL removeStatusListener(
113         css::uno::Reference< css::frame::XStatusListener > const &,
114         css::util::URL const &)
115         throw (css::uno::RuntimeException)
116     {}
117 };
118 
static_getImplementationName()119 rtl::OUString Service::static_getImplementationName() {
120     return rtl::OUString(
121         RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.test.deployment.boxt"));
122 }
123 
static_getSupportedServiceNames()124 css::uno::Sequence< rtl::OUString > Service::static_getSupportedServiceNames() {
125     rtl::OUString name(
126         RTL_CONSTASCII_USTRINGPARAM("com.sun.star.test.deployment.boxt"));
127     return css::uno::Sequence< rtl::OUString >(&name, 1);
128 }
129 
130 css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > >
queryDispatches(css::uno::Sequence<css::frame::DispatchDescriptor> const & Requests)131 Service::queryDispatches(
132     css::uno::Sequence< css::frame::DispatchDescriptor > const & Requests)
133     throw (css::uno::RuntimeException)
134 {
135     css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > s(
136         Requests.getLength());
137     for (sal_Int32 i = 0; i < s.getLength(); ++i) {
138         s[i] = queryDispatch(
139             Requests[i].FeatureURL, Requests[i].FrameName,
140             Requests[i].SearchFlags);
141     }
142     return s;
143 }
144 
dispatch(css::util::URL const &,css::uno::Sequence<css::beans::PropertyValue> const &)145 void Service::dispatch(
146     css::util::URL const &,
147     css::uno::Sequence< css::beans::PropertyValue > const &)
148     throw (css::uno::RuntimeException)
149 {
150     msfilter::ConvertCountryToLanguage(msfilter::COUNTRY_DONTKNOW);
151         // link against some obscure library that is unlikely already loaded
152     Application::ShowNativeErrorBox(
153         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("boxt")),
154         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("test")));
155 }
156 
157 static cppu::ImplementationEntry const services[] = {
158     { &Service::static_create, &Service::static_getImplementationName,
159       &Service::static_getSupportedServiceNames,
160       &cppu::createSingleComponentFactory, 0, 0 },
161     { 0, 0, 0, 0, 0, 0 }
162 };
163 
164 }
165 
component_getFactory(char const * pImplName,void * pServiceManager,void * pRegistryKey)166 extern "C" void * SAL_CALL component_getFactory(
167     char const * pImplName, void * pServiceManager, void * pRegistryKey)
168 {
169     return cppu::component_getFactoryHelper(
170         pImplName, pServiceManager, pRegistryKey, services);
171 }
172 
component_getImplementationEnvironment(char const ** ppEnvTypeName,uno_Environment **)173 extern "C" void SAL_CALL component_getImplementationEnvironment(
174     char const ** ppEnvTypeName, uno_Environment **)
175 {
176     *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
177 }
178 
component_writeInfo(void * pServiceManager,void * pRegistryKey)179 extern "C" sal_Bool SAL_CALL component_writeInfo(
180     void * pServiceManager, void * pRegistryKey)
181 {
182     return component_writeInfoHelper(pServiceManager, pRegistryKey, services);
183 }
184