1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright IBM Corporation 2010.
6  * Copyright 2000, 2010 Oracle and/or its affiliates.
7  *
8  * OpenOffice.org - a multi-platform office productivity suite
9  *
10  * This file is part of OpenOffice.org.
11  *
12  * OpenOffice.org is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 3
14  * only, as published by the Free Software Foundation.
15  *
16  * OpenOffice.org is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU Lesser General Public License version 3 for more details
20  * (a copy is included in the LICENSE file that accompanied this code).
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * version 3 along with OpenOffice.org.  If not, see
24  * <http://www.openoffice.org/license.html>
25  * for a copy of the LGPLv3 License.
26  *
27  ************************************************************************/
28 
29 #include "AccObjectManagerAgent.hxx"
30 #include "AccObjectWinManager.hxx"
31 
32 #include "UAccCOM2.h"
33 
34 using namespace com::sun::star::uno;
35 using namespace com::sun::star::accessibility;
36 
37 /**
38    * Construction/Destruction.
39    * @param
40    * @return
41    */
42 AccObjectManagerAgent::AccObjectManagerAgent():
43         pWinManager(NULL)
44 {
45     if( pWinManager == NULL )
46     {
47         pWinManager = AccObjectWinManager::CreateAccObjectWinManagerInstance(this);
48     }
49 }
50 
51 AccObjectManagerAgent::~AccObjectManagerAgent()
52 {
53     delete pWinManager;
54     pWinManager = NULL;
55 }
56 
57 /**
58    * Interface of updating MSAA name when UNO name_changed event occurs.
59    * @param pXAcc Uno XAccessible interface of control.
60    * @return
61    */
62 void  AccObjectManagerAgent::UpdateAccName( XAccessible* pXAcc )
63 {
64     if( pWinManager )
65         pWinManager->UpdateAccName( pXAcc );
66 }
67 
68 /**
69    * Interface of updating MSAA name when UNO action changed event occurs.
70    * @param pXAcc Uno XAccessible interface of control.
71    * @return
72    */
73 void  AccObjectManagerAgent::UpdateAction( XAccessible* pXAcc )
74 {
75     if( pWinManager )
76         pWinManager->UpdateAction( pXAcc );
77 }
78 
79 /**
80    * Interface of updating MSAA value when UNO value_changed event occurs.
81    * @param pXAcc Uno XAccessible interface of control.
82    * @param pAny New value.
83    * @return
84    */
85 void  AccObjectManagerAgent::UpdateValue( XAccessible* pXAcc, Any pAny )
86 {
87     if( pWinManager )
88         pWinManager->SetValue( pXAcc, pAny );
89 }
90 
91 /**
92    * Interface of updating MSAA value when UNO value_changed event occurs.If we can not
93    * find new value,we'll get new value from pXAcc to update com value.
94    * @param pXAcc Uno XAccessible interface of control.
95    * @return
96    */
97 void  AccObjectManagerAgent::UpdateValue( XAccessible* pXAcc )
98 {
99     if( pWinManager )
100         pWinManager->UpdateValue( pXAcc );
101 }
102 
103 /**
104    * Interface of updating MSAA name when UNO name_changed event occurs.
105    * @param pXAcc Uno XAccessible interface of control.
106    * @param newName New UNO accessible name.
107    * @return
108    */
109 void  AccObjectManagerAgent::UpdateAccName( XAccessible* pXAcc, Any newName)
110 {
111     if( pWinManager )
112         pWinManager->SetAccName( pXAcc, newName );
113 }
114 
115 
116 /**
117    * Interface of updating MSAA location when UNO location_changed event occurs.
118    * @param pXAcc Uno XAccessible interface of control.
119    * @param pXAcc Uno The top position of new location.
120    * @param pXAcc Uno The left position of new location.
121    * @param pXAcc Uno The width of new location.
122    * @param pXAcc Uno The width of new location.
123    * @return
124    */
125 void  AccObjectManagerAgent::UpdateLocation( XAccessible* /* pXAcc */, long /*top*/, long /*left*/, long /*width*/, long /*height*/ )
126 {
127 #ifdef _IMPL_WIN
128     if( pWinManager )
129         pWinManager->SetLocation( pXAcc, top, left, width, height );
130 #endif
131 }
132 
133 /**
134    * Interface of updating MSAA name when UNO description_changed event occurs.
135    * @param pXAcc Uno XAccessible interface of control.
136    * @param newDesc New UNO accessible description.
137    * @return
138    */
139 void  AccObjectManagerAgent::UpdateDescription( XAccessible* pXAcc, Any newDesc )
140 {
141     if( pWinManager )
142         pWinManager->SetDescription( pXAcc, newDesc );
143 }
144 
145 /**
146    * When a new UNO XAccessible object is found by listener,we'll create a corresponding
147    * com object and insert it to our manager list.
148    * @param pXAcc Uno XAccessible interface of control.
149    * @param pWnd The top window handle containing control.
150    * @return If the method is correctly processed.
151    */
152 unsigned char AccObjectManagerAgent::InsertAccObj( XAccessible* pXAcc,XAccessible* pParentXAcc,long pWnd)
153 {
154     if( pWinManager )
155         return (unsigned char)pWinManager->InsertAccObj( pXAcc, pParentXAcc,HWND((void*)pWnd) );
156 
157     return sal_False;
158 }
159 
160 /**
161    * save the pair <topwindowhandle, XAccessible>
162    * @param hWnd, top window handle
163    * @param pXAcc XAccessible interface for top window
164    * @return void
165    */
166 void AccObjectManagerAgent::SaveTopWindowHandle(long hWnd, com::sun::star::accessibility::XAccessible* pXAcc)
167 {
168     if( pWinManager )
169         pWinManager->SaveTopWindowHandle( HWND((void*)hWnd), pXAcc );
170 }
171 
172 
173 /**
174    * When a UNO XAccessible object's new children are found by listener,we'll create
175    * corresponding com objects and insert them to our manager list.
176    * @param pXAcc Uno XAccessible interface of control.
177    * @param pWnd The top window handle containing control.
178    * @return If the method is correctly processed.
179    */
180 unsigned char AccObjectManagerAgent::InsertChildrenAccObj( XAccessible* pXAcc,
181         long pWnd)
182 {
183     if( pWinManager )
184         return (unsigned char)pWinManager->InsertChildrenAccObj( pXAcc, HWND((void*)pWnd) );
185 
186     return sal_False;
187 }
188 
189 /**
190    * When a new UNO XAccessible object is destroied,we'll delete its corresponding
191    * com object and remove it from our manager list.
192    * @param pXAcc Uno XAccessible interface of control.
193    * @return
194    */
195 void AccObjectManagerAgent::DeleteAccObj( XAccessible* pXAcc )
196 {
197     if( pWinManager )
198         pWinManager->DeleteAccObj( pXAcc );
199 }
200 
201 /**
202    * When new UNO children XAccessible objects are destroyed,we'll delete their
203    * corresponding com objects and remove them from our manager list.
204    * @param pXAcc Uno XAccessible interface of control.
205    * @return
206    */
207 void AccObjectManagerAgent::DeleteChildrenAccObj( XAccessible* pXAcc )
208 {
209     if( pWinManager )
210         pWinManager->DeleteChildrenAccObj( pXAcc );
211 }
212 
213 /**
214    * Interface of decreasing MSAA state when some UNO state is decreased.
215    * @param pXAcc Uno XAccessible interface of control.
216    * @param pState The lost state of control.
217    * @return
218    */
219 void AccObjectManagerAgent::DecreaseState( XAccessible* pXAcc,unsigned short pState )
220 {
221     if(pWinManager)
222     {
223         pWinManager->DecreaseState( pXAcc,  pState );
224     }
225 }
226 
227 /**
228    * Interface of increasing MSAA name when some UNO state is increased.
229    * @param pXAcc Uno XAccessible interface of control.
230    * @param pState The new state of control.
231    * @return
232    */
233 void AccObjectManagerAgent::IncreaseState( XAccessible* pXAcc,unsigned short pState )
234 {
235     if(pWinManager)
236     {
237         pWinManager->IncreaseState( pXAcc,  pState );
238     }
239 }
240 
241 void  AccObjectManagerAgent::UpdateState( com::sun::star::accessibility::XAccessible* pXAcc )
242 {
243     if(pWinManager)
244         pWinManager->UpdateState(pXAcc);
245 }
246 
247 /**
248    * Interface of notify MSAA event when some UNO event occured.
249    * @param pXAcc Uno XAccessible interface of control.
250    * @param pEvent UNO event ID.
251    * @return If the method is correctly processed.
252    */
253 unsigned char AccObjectManagerAgent::NotifyAccEvent( short pEvent,XAccessible* pXAcc )
254 {
255     if(pWinManager)
256         return (unsigned char)pWinManager->NotifyAccEvent(pXAcc,pEvent);
257 
258     return sal_False;
259 }
260 
261 /**
262    * Judge whether a XAccessible object is a container object.
263    * @param pXAcc Uno XAccessible interface of control.
264    * @return If the method is correctly processed.
265    */
266 unsigned short AccObjectManagerAgent::IsContainer( XAccessible* pXAcc )
267 {
268     if(pWinManager)
269         return (unsigned char)pWinManager->IsContainer(pXAcc);
270 
271     return sal_False;
272 }
273 
274 /**
275    * Return com object interface by querying XAccessible interface.
276    * @param pXAcc Uno XAccessible interface of control.
277    * @return Com interface.
278    */
279 IMAccessible* AccObjectManagerAgent::GetIMAccByXAcc(XAccessible* pXAcc)
280 {
281     if(pWinManager)
282         return pWinManager->GetIMAccByXAcc(pXAcc);
283 
284     return NULL;
285 }
286 
287 /**
288    * Notify manger when a XAccessible object is destroying.
289    * @param pXAcc Uno XAccessible interface of control.
290    * @return.
291    */
292 void  AccObjectManagerAgent::NotifyDestroy(XAccessible* pXAcc)
293 {
294     if(pWinManager)
295         pWinManager->NotifyDestroy(pXAcc);
296 }
297 
298 /**
299    * Return com object interface by querying child id.
300    * @param pXAcc Uno XAccessible interface of control.
301    * @return Com interface.
302    */
303 void AccObjectManagerAgent::GetIAccessibleFromResID(long childID,IMAccessible** pIMAcc)
304 {
305     if(pWinManager)
306         *pIMAcc = pWinManager->GetIAccessibleFromResID(childID);
307 }
308 
309 /**
310    * Return object interface by querying interface.
311    * @param pXAcc Uno XAccessible interface of control.
312    * @return Com interface.
313    */
314 unsigned char AccObjectManagerAgent::GetIAccessibleFromXAccessible(XAccessible* pXAcc, IAccessible** ppXI)
315 {
316     if(pWinManager)
317     {
318         *ppXI = (IAccessible*)pWinManager->GetIMAccByXAcc(pXAcc);
319         if(*ppXI)
320             return sal_True;
321     }
322     return sal_False;
323 }
324 
325 XAccessible* AccObjectManagerAgent::GetParentXAccessible( XAccessible* pXAcc )
326 {
327     if(pWinManager)
328         return pWinManager->GetParentXAccessible( pXAcc );
329 
330     return NULL;
331 }
332 
333 short AccObjectManagerAgent::GetParentRole( XAccessible* pXAcc )
334 {
335     if(pWinManager)
336         return pWinManager->GetParentRole( pXAcc );
337 
338     return -1;
339 }
340 
341 void AccObjectManagerAgent::UpdateDescription( XAccessible* pXAcc )
342 {
343     if(pWinManager)
344         pWinManager->UpdateDescription( pXAcc );
345 }
346 
347 void AccObjectManagerAgent::UpdateChildState(com::sun::star::accessibility::XAccessible* pXAcc)
348 {
349     if(pWinManager)
350         pWinManager->UpdateChildState( pXAcc );
351 }
352 
353 
354 bool AccObjectManagerAgent::IsSpecialToolboItem(com::sun::star::accessibility::XAccessible* pXAcc)
355 {
356     if(pWinManager)
357         return pWinManager->IsSpecialToolboItem( pXAcc );
358 
359     return false;
360 }
361 
362 short AccObjectManagerAgent::GetRole(com::sun::star::accessibility::XAccessible* pXAcc)
363 {
364     if(pWinManager)
365         return pWinManager->GetRole( pXAcc );
366 
367     return -1;
368 }
369 
370 XAccessible* AccObjectManagerAgent::GetAccDocByAccTopWin( XAccessible* pXAcc )
371 {
372     if (pWinManager)
373     {
374         return pWinManager->GetAccDocByAccTopWin( pXAcc );
375     }
376     return NULL;
377 }
378 bool AccObjectManagerAgent::IsTopWinAcc( com::sun::star::accessibility::XAccessible* pXAcc )
379 {
380     if (pWinManager)
381     {
382         return pWinManager->IsTopWinAcc( pXAcc );
383     }
384     return NULL;
385 }
386 
387 bool AccObjectManagerAgent::IsStateManageDescendant(com::sun::star::accessibility::XAccessible* pXAcc)
388 {
389     if(pWinManager)
390         return pWinManager->IsStateManageDescendant( pXAcc );
391 
392     return sal_False;
393 }
394