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 #include <cppuhelper/implbase3.hxx>
23 #include <cppuhelper/factory.hxx>
24 #include <cppuhelper/implementationentry.hxx>
25
26 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <com/sun/star/lang/XInitialization.hpp>
28 #include <com/sun/star/lang/IllegalArgumentException.hpp>
29 #include <com/sun/star/accessibility/XMSAAService.hpp>
30
31 #include <com/sun/star/awt/XExtendedToolkit.hpp>
32 #include <vcl/svapp.hxx>
33
34 using namespace ::rtl; // for OUString
35 using namespace ::com::sun::star; // for odk interfaces
36 using namespace ::com::sun::star::uno; // for basic types
37 using namespace ::com::sun::star::accessibility;
38
39 using namespace ::com::sun::star::awt;
40
41 typedef void* HWND;
42
43 #include "AccTopWindowListener.hxx"
44 #include "g_msacc.hxx"
45
46 extern void FreeTopWindowListener();
47 extern sal_IntPtr GetMSComPtr( sal_IntPtr hWnd, sal_IntPtr lParam, sal_IntPtr wParam);
48 extern void handleWindowOpened_impl( sal_Int64 pAcc);
49
50
51 namespace my_sc_impl
52 {
53
54 extern Sequence< OUString > SAL_CALL getSupportedServiceNames_MSAAServiceImpl();
55 extern OUString SAL_CALL getImplementationName_MSAAServiceImpl();
56 extern Reference< XInterface > SAL_CALL create_MSAAServiceImpl(
57 Reference< XComponentContext > const & xContext )
58 SAL_THROW( () );
59 /**
60 * Method that returns the service name.
61 * @param
62 * @return Name sequence.
63 */
getSupportedServiceNames_MSAAServiceImpl()64 static Sequence< OUString > getSupportedServiceNames_MSAAServiceImpl()
65 {
66 static Sequence < OUString > *pNames = 0;
67 if( ! pNames )
68 {
69 // MutexGuard guard( Mutex::getGlobalMutex() );
70 if( !pNames )
71 {
72 static Sequence< OUString > seqNames(1);
73 seqNames.getArray()[0] = OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.accessibility.MSAAService"));
74 pNames = &seqNames;
75 }
76 }
77 return *pNames;
78 }
79
80 /**
81 * Method that returns the service name.
82 * @param
83 * @return Name sequence.
84 */
getImplementationName_MSAAServiceImpl()85 static OUString getImplementationName_MSAAServiceImpl()
86 {
87 static OUString *pImplName = 0;
88 if( ! pImplName )
89 {
90 // MutexGuard guard( Mutex::getGlobalMutex() );
91 if( ! pImplName )
92 {
93 static OUString implName( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.accessibility.my_sc_implementation.MSAAService") );
94 pImplName = &implName;
95 }
96 }
97 return *pImplName;
98 }
99
100 class MSAAServiceImpl : public ::cppu::WeakImplHelper3<
101 XMSAAService, lang::XServiceInfo, lang::XInitialization >
102 {
103 OUString m_arg;
104 public:
105 // focus on three given interfaces,
106 // no need to implement XInterface, XTypeProvider, XWeak
107 MSAAServiceImpl ();
108 virtual ~MSAAServiceImpl( void );
109 // XInitialization will be called upon createInstanceWithArguments[AndContext]()
110 virtual void SAL_CALL initialize( Sequence< Any > const & args );
111 // XMSAAService
112 virtual sal_Int64 SAL_CALL getAccObjectPtr (sal_Int64 hWnd, sal_Int64 lParam, sal_Int64 wParam);
113 virtual void SAL_CALL handleWindowOpened(sal_Int64);
114 // XServiceInfo
115 virtual OUString SAL_CALL getImplementationName();
116 virtual sal_Bool SAL_CALL supportsService( OUString const & serviceName );
117 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames();
118 };
119
120 /**
121 * Implementation of XInitialization.
122 * @param
123 * @return.
124 */
initialize(Sequence<Any> const & args)125 void MSAAServiceImpl::initialize( Sequence< Any > const & args )
126 {
127 if (1 != args.getLength())
128 {
129 throw lang::IllegalArgumentException(
130 OUString( RTL_CONSTASCII_USTRINGPARAM("give a string instantiating this component!") ),
131 (::cppu::OWeakObject *)this, // resolve to XInterface reference
132 0 ); // argument pos
133 }
134 if (! (args[ 0 ] >>= m_arg))
135 {
136 throw lang::IllegalArgumentException(
137 OUString( RTL_CONSTASCII_USTRINGPARAM("no string given as argument!") ),
138 (::cppu::OWeakObject *)this, // resolve to XInterface reference
139 0 ); // argument pos
140 }
141 }
142
143 /**
144 * Implementation of getAccObjectPtr.
145 * @param
146 * @return Com interface.
147 */
getAccObjectPtr(sal_Int64 hWnd,sal_Int64 lParam,sal_Int64 wParam)148 sal_Int64 MSAAServiceImpl::getAccObjectPtr ( sal_Int64 hWnd, sal_Int64 lParam, sal_Int64 wParam)
149 {
150 return (sal_Int64)GetMSComPtr((sal_IntPtr)hWnd, (sal_IntPtr)lParam, (sal_IntPtr)wParam);
151 }
152
153 /**
154 * Implementation of handleWindowOpened,the method will be invoked when a top window
155 * opened and AT starts up.
156 * @param
157 * @return
158 */
handleWindowOpened(sal_Int64 pAcc)159 void MSAAServiceImpl::handleWindowOpened( sal_Int64 pAcc)
160 {
161 handleWindowOpened_impl(pAcc);
162 }
163
164 /**
165 * Implementation of XServiceInfo.
166 * @param
167 * @return Implementation name.
168 */
getImplementationName()169 OUString MSAAServiceImpl::getImplementationName()
170 {
171 // unique implementation name
172 return OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.accessibility.my_sc_impl.MSAAService") );
173 }
174
175 /**
176 * Implementation of XServiceInfo,return support service name.
177 * @param Service name.
178 * @return If the service name is supported.
179 */
supportsService(OUString const & serviceName)180 sal_Bool MSAAServiceImpl::supportsService( OUString const & serviceName )
181 {
182 // this object only supports one service, so the test is simple
183 return serviceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.accessibility.MSAAService") );
184 }
185
186 /**
187 * Implementation of XServiceInfo,return all service names.
188 * @param.
189 * @return service name sequence.
190 */
getSupportedServiceNames()191 Sequence< OUString > MSAAServiceImpl::getSupportedServiceNames()
192 {
193 return getSupportedServiceNames_MSAAServiceImpl();
194 }
195
196 /**
197 * Static method that can create an entity of our MSAA Service
198 * @param xContext No use here.
199 * @return The object interface.
200 */
create_MSAAServiceImpl(Reference<XComponentContext> const &)201 Reference< XInterface > SAL_CALL create_MSAAServiceImpl( Reference< XComponentContext > const & /*xContext*/ ) SAL_THROW( () )
202 {
203 MSAAServiceImpl* xxx = new MSAAServiceImpl();
204 //return static_cast< lang::XTypeProvider * >( xxx );
205 Reference< XMSAAService > p( xxx );
206 return p;
207 }
208
209 /**
210 * Constructor.
211 * @param
212 * @return
213 */
MSAAServiceImpl()214 MSAAServiceImpl::MSAAServiceImpl()
215 {
216 Reference< XExtendedToolkit > xToolkit =
217 Reference< XExtendedToolkit >(Application::GetVCLToolkit(), UNO_QUERY);
218
219 if(xToolkit.is())
220 {
221 AccTopWindowListener *accListener;
222 accListener = new AccTopWindowListener();
223 g_pTop = accListener;
224 Reference< XTopWindowListener> x(accListener);
225 xToolkit->addTopWindowListener(x);
226 }
227 }
228
229 /**
230 * Static method that can create an entity of our MSAA Service
231 * @param Destructor
232 * @return
233 */
~MSAAServiceImpl()234 MSAAServiceImpl::~MSAAServiceImpl()
235 {
236
237 // As all folders and streams contain references to their parents,
238 // we must remove these references so that they will be deleted when
239 // the hash_map of the root folder is cleared, releasing all subfolders
240 // and substreams which in turn release theirs, etc. When xRootFolder is
241 // released when this destructor completes, the folder tree should be
242 // deleted fully (and automagically).
243 FreeTopWindowListener();
244
245
246 }
247
248 }
249
250 /* shared lib exports implemented without helpers in service_impl1.cxx */
251 namespace my_sc_impl
252 {
253 static struct ::cppu::ImplementationEntry s_component_entries [] =
254 {
255 {
256 create_MSAAServiceImpl, getImplementationName_MSAAServiceImpl,
257 getSupportedServiceNames_MSAAServiceImpl, ::cppu::createSingleComponentFactory,
258 0, 0
259 },
260 {
261 create_MSAAServiceImpl, getImplementationName_MSAAServiceImpl,
262 getSupportedServiceNames_MSAAServiceImpl, ::cppu::createSingleComponentFactory,
263 0, 0
264 },
265 { 0, 0, 0, 0, 0, 0 }
266 };
267 }
268
269 extern "C"
270 {
component_getImplementationEnvironment(sal_Char const ** ppEnvTypeName,uno_Environment **)271 void SAL_CALL component_getImplementationEnvironment(
272 sal_Char const ** ppEnvTypeName, uno_Environment ** /*ppEnv*/ )
273 {
274 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
275 }
component_getFactory(sal_Char const * implName,lang::XMultiServiceFactory * xMgr,registry::XRegistryKey * xRegistry)276 void * SAL_CALL component_getFactory(
277 sal_Char const * implName, lang::XMultiServiceFactory * xMgr,
278 registry::XRegistryKey * xRegistry )
279 {
280 return ::cppu::component_getFactoryHelper(
281 implName, xMgr, xRegistry, ::my_sc_impl::s_component_entries );
282 }
283 }
284