xref: /AOO41X/main/vcl/unx/gtk/a11y/atkwrapper.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_vcl.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
32*cdf0e10cSrcweir #include <com/sun/star/uno/Type.hxx>
33*cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
34*cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRole.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRelation.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessible.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessibleText.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessibleTextMarkup.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessibleTextAttributes.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessibleValue.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessibleAction.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessibleContext.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessibleMultiLineText.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessibleStateSet.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessibleRelationSet.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessibleTable.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessibleEditableText.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessibleImage.hpp>
53*cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessibleHyperlink.hpp>
54*cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessibleHypertext.hpp>
55*cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
56*cdf0e10cSrcweir #include <com/sun/star/awt/XExtendedToolkit.hpp>
57*cdf0e10cSrcweir #include <com/sun/star/awt/XTopWindow.hpp>
58*cdf0e10cSrcweir #include <com/sun/star/awt/XTopWindowListener.hpp>
59*cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp>
60*cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
61*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
62*cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
63*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
64*cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp>
65*cdf0e10cSrcweir #include <com/sun/star/beans/Property.hpp>
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir #include <rtl/ref.hxx>
68*cdf0e10cSrcweir #include <cppuhelper/factory.hxx>
69*cdf0e10cSrcweir #include <cppuhelper/queryinterface.hxx>
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir #include "atkwrapper.hxx"
72*cdf0e10cSrcweir #include "atkregistry.hxx"
73*cdf0e10cSrcweir #include "atklistener.hxx"
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir #ifdef ENABLE_TRACING
76*cdf0e10cSrcweir #include <stdio.h>
77*cdf0e10cSrcweir #endif
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir #include <string.h>
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir using namespace ::com::sun::star;
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir static GObjectClass *parent_class = NULL;
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir static AtkRelationType mapRelationType( sal_Int16 nRelation )
86*cdf0e10cSrcweir {
87*cdf0e10cSrcweir     AtkRelationType type = ATK_RELATION_NULL;
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir     switch( nRelation )
90*cdf0e10cSrcweir     {
91*cdf0e10cSrcweir         case accessibility::AccessibleRelationType::CONTENT_FLOWS_FROM:
92*cdf0e10cSrcweir             type = ATK_RELATION_FLOWS_FROM;
93*cdf0e10cSrcweir             break;
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir         case accessibility::AccessibleRelationType::CONTENT_FLOWS_TO:
96*cdf0e10cSrcweir             type = ATK_RELATION_FLOWS_TO;
97*cdf0e10cSrcweir             break;
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir         case accessibility::AccessibleRelationType::CONTROLLED_BY:
100*cdf0e10cSrcweir             type = ATK_RELATION_CONTROLLED_BY;
101*cdf0e10cSrcweir             break;
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir         case accessibility::AccessibleRelationType::CONTROLLER_FOR:
104*cdf0e10cSrcweir             type = ATK_RELATION_CONTROLLER_FOR;
105*cdf0e10cSrcweir             break;
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir         case accessibility::AccessibleRelationType::LABEL_FOR:
108*cdf0e10cSrcweir             type = ATK_RELATION_LABEL_FOR;
109*cdf0e10cSrcweir             break;
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir         case accessibility::AccessibleRelationType::LABELED_BY:
112*cdf0e10cSrcweir             type = ATK_RELATION_LABELLED_BY;
113*cdf0e10cSrcweir             break;
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir         case accessibility::AccessibleRelationType::MEMBER_OF:
116*cdf0e10cSrcweir             type = ATK_RELATION_MEMBER_OF;
117*cdf0e10cSrcweir             break;
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir         case accessibility::AccessibleRelationType::SUB_WINDOW_OF:
120*cdf0e10cSrcweir             type = ATK_RELATION_SUBWINDOW_OF;
121*cdf0e10cSrcweir             break;
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir         case accessibility::AccessibleRelationType::NODE_CHILD_OF:
124*cdf0e10cSrcweir             type = ATK_RELATION_NODE_CHILD_OF;
125*cdf0e10cSrcweir             break;
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir         default:
128*cdf0e10cSrcweir             break;
129*cdf0e10cSrcweir     }
130*cdf0e10cSrcweir #if 0
131*cdf0e10cSrcweir   ATK_RELATION_NODE_CHILD_OF,
132*cdf0e10cSrcweir   ATK_RELATION_EMBEDS,
133*cdf0e10cSrcweir   ATK_RELATION_EMBEDDED_BY,
134*cdf0e10cSrcweir   ATK_RELATION_POPUP_FOR,
135*cdf0e10cSrcweir #endif
136*cdf0e10cSrcweir     return type;
137*cdf0e10cSrcweir }
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir AtkStateType mapAtkState( sal_Int16 nState )
141*cdf0e10cSrcweir {
142*cdf0e10cSrcweir     AtkStateType type = ATK_STATE_INVALID;
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir     // A perfect / complete mapping ...
145*cdf0e10cSrcweir     switch( nState )
146*cdf0e10cSrcweir     {
147*cdf0e10cSrcweir #define MAP_DIRECT( a ) \
148*cdf0e10cSrcweir         case accessibility::AccessibleStateType::a: \
149*cdf0e10cSrcweir             type = ATK_STATE_##a; break
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir         MAP_DIRECT( INVALID );
152*cdf0e10cSrcweir         MAP_DIRECT( ACTIVE );
153*cdf0e10cSrcweir         MAP_DIRECT( ARMED );
154*cdf0e10cSrcweir         MAP_DIRECT( BUSY );
155*cdf0e10cSrcweir         MAP_DIRECT( CHECKED );
156*cdf0e10cSrcweir         MAP_DIRECT( EDITABLE );
157*cdf0e10cSrcweir         MAP_DIRECT( ENABLED );
158*cdf0e10cSrcweir         MAP_DIRECT( EXPANDABLE );
159*cdf0e10cSrcweir         MAP_DIRECT( EXPANDED );
160*cdf0e10cSrcweir         MAP_DIRECT( FOCUSABLE );
161*cdf0e10cSrcweir         MAP_DIRECT( FOCUSED );
162*cdf0e10cSrcweir         MAP_DIRECT( HORIZONTAL );
163*cdf0e10cSrcweir         MAP_DIRECT( ICONIFIED );
164*cdf0e10cSrcweir         MAP_DIRECT( INDETERMINATE );
165*cdf0e10cSrcweir         MAP_DIRECT( MANAGES_DESCENDANTS );
166*cdf0e10cSrcweir         MAP_DIRECT( MODAL );
167*cdf0e10cSrcweir         MAP_DIRECT( MULTI_LINE );
168*cdf0e10cSrcweir         MAP_DIRECT( OPAQUE );
169*cdf0e10cSrcweir         MAP_DIRECT( PRESSED );
170*cdf0e10cSrcweir         MAP_DIRECT( RESIZABLE );
171*cdf0e10cSrcweir         MAP_DIRECT( SELECTABLE );
172*cdf0e10cSrcweir         MAP_DIRECT( SELECTED );
173*cdf0e10cSrcweir         MAP_DIRECT( SENSITIVE );
174*cdf0e10cSrcweir         MAP_DIRECT( SHOWING );
175*cdf0e10cSrcweir         MAP_DIRECT( SINGLE_LINE );
176*cdf0e10cSrcweir         MAP_DIRECT( STALE );
177*cdf0e10cSrcweir         MAP_DIRECT( TRANSIENT );
178*cdf0e10cSrcweir         MAP_DIRECT( VERTICAL );
179*cdf0e10cSrcweir         MAP_DIRECT( VISIBLE );
180*cdf0e10cSrcweir         // a spelling error ...
181*cdf0e10cSrcweir         case accessibility::AccessibleStateType::DEFUNC:
182*cdf0e10cSrcweir             type = ATK_STATE_DEFUNCT; break;
183*cdf0e10cSrcweir         case accessibility::AccessibleStateType::MULTI_SELECTABLE:
184*cdf0e10cSrcweir             type = ATK_STATE_MULTISELECTABLE; break;
185*cdf0e10cSrcweir     default:
186*cdf0e10cSrcweir         break;
187*cdf0e10cSrcweir     }
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir     return type;
190*cdf0e10cSrcweir }
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir static inline AtkRole registerRole( const gchar * name )
193*cdf0e10cSrcweir {
194*cdf0e10cSrcweir     AtkRole ret = atk_role_for_name( name );
195*cdf0e10cSrcweir     if( ATK_ROLE_INVALID == ret )
196*cdf0e10cSrcweir         ret = atk_role_register( name );
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir     return ret;
199*cdf0e10cSrcweir }
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir static AtkRole mapToAtkRole( sal_Int16 nRole )
202*cdf0e10cSrcweir {
203*cdf0e10cSrcweir     AtkRole role = ATK_ROLE_UNKNOWN;
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir     static AtkRole roleMap[] = {
206*cdf0e10cSrcweir         ATK_ROLE_UNKNOWN,
207*cdf0e10cSrcweir         ATK_ROLE_ALERT,
208*cdf0e10cSrcweir         ATK_ROLE_COLUMN_HEADER,
209*cdf0e10cSrcweir         ATK_ROLE_CANVAS,
210*cdf0e10cSrcweir         ATK_ROLE_CHECK_BOX,
211*cdf0e10cSrcweir         ATK_ROLE_CHECK_MENU_ITEM,
212*cdf0e10cSrcweir         ATK_ROLE_COLOR_CHOOSER,
213*cdf0e10cSrcweir         ATK_ROLE_COMBO_BOX,
214*cdf0e10cSrcweir         ATK_ROLE_DATE_EDITOR,
215*cdf0e10cSrcweir         ATK_ROLE_DESKTOP_ICON,
216*cdf0e10cSrcweir         ATK_ROLE_DESKTOP_FRAME,   // ? pane
217*cdf0e10cSrcweir         ATK_ROLE_DIRECTORY_PANE,
218*cdf0e10cSrcweir         ATK_ROLE_DIALOG,
219*cdf0e10cSrcweir         ATK_ROLE_UNKNOWN,         // DOCUMENT - registered below
220*cdf0e10cSrcweir         ATK_ROLE_UNKNOWN,         // EMBEDDED_OBJECT - registered below
221*cdf0e10cSrcweir         ATK_ROLE_UNKNOWN,         // END_NOTE - registered below
222*cdf0e10cSrcweir         ATK_ROLE_FILE_CHOOSER,
223*cdf0e10cSrcweir         ATK_ROLE_FILLER,
224*cdf0e10cSrcweir         ATK_ROLE_FONT_CHOOSER,
225*cdf0e10cSrcweir         ATK_ROLE_FOOTER,
226*cdf0e10cSrcweir         ATK_ROLE_TEXT,            // FOOTNOTE - registered below
227*cdf0e10cSrcweir         ATK_ROLE_FRAME,
228*cdf0e10cSrcweir         ATK_ROLE_GLASS_PANE,
229*cdf0e10cSrcweir         ATK_ROLE_IMAGE,           // GRAPHIC
230*cdf0e10cSrcweir         ATK_ROLE_UNKNOWN,         // GROUP_BOX - registered below
231*cdf0e10cSrcweir         ATK_ROLE_HEADER,
232*cdf0e10cSrcweir         ATK_ROLE_PARAGRAPH,       // HEADING - registered below
233*cdf0e10cSrcweir         ATK_ROLE_TEXT,            // HYPER_LINK - registered below
234*cdf0e10cSrcweir         ATK_ROLE_ICON,
235*cdf0e10cSrcweir         ATK_ROLE_INTERNAL_FRAME,
236*cdf0e10cSrcweir         ATK_ROLE_LABEL,
237*cdf0e10cSrcweir         ATK_ROLE_LAYERED_PANE,
238*cdf0e10cSrcweir         ATK_ROLE_LIST,
239*cdf0e10cSrcweir         ATK_ROLE_LIST_ITEM,
240*cdf0e10cSrcweir         ATK_ROLE_MENU,
241*cdf0e10cSrcweir         ATK_ROLE_MENU_BAR,
242*cdf0e10cSrcweir         ATK_ROLE_MENU_ITEM,
243*cdf0e10cSrcweir         ATK_ROLE_OPTION_PANE,
244*cdf0e10cSrcweir         ATK_ROLE_PAGE_TAB,
245*cdf0e10cSrcweir         ATK_ROLE_PAGE_TAB_LIST,
246*cdf0e10cSrcweir         ATK_ROLE_PANEL,
247*cdf0e10cSrcweir         ATK_ROLE_PARAGRAPH,
248*cdf0e10cSrcweir         ATK_ROLE_PASSWORD_TEXT,
249*cdf0e10cSrcweir         ATK_ROLE_POPUP_MENU,
250*cdf0e10cSrcweir         ATK_ROLE_PUSH_BUTTON,
251*cdf0e10cSrcweir         ATK_ROLE_PROGRESS_BAR,
252*cdf0e10cSrcweir         ATK_ROLE_RADIO_BUTTON,
253*cdf0e10cSrcweir         ATK_ROLE_RADIO_MENU_ITEM,
254*cdf0e10cSrcweir         ATK_ROLE_ROW_HEADER,
255*cdf0e10cSrcweir         ATK_ROLE_ROOT_PANE,
256*cdf0e10cSrcweir         ATK_ROLE_SCROLL_BAR,
257*cdf0e10cSrcweir         ATK_ROLE_SCROLL_PANE,
258*cdf0e10cSrcweir         ATK_ROLE_UNKNOWN,        // SHAPE - registered below
259*cdf0e10cSrcweir         ATK_ROLE_SEPARATOR,
260*cdf0e10cSrcweir         ATK_ROLE_SLIDER,
261*cdf0e10cSrcweir         ATK_ROLE_SPIN_BUTTON,    // SPIN_BOX ?
262*cdf0e10cSrcweir         ATK_ROLE_SPLIT_PANE,
263*cdf0e10cSrcweir         ATK_ROLE_STATUSBAR,
264*cdf0e10cSrcweir         ATK_ROLE_TABLE,
265*cdf0e10cSrcweir         ATK_ROLE_TABLE_CELL,
266*cdf0e10cSrcweir         ATK_ROLE_TEXT,
267*cdf0e10cSrcweir         ATK_ROLE_INTERNAL_FRAME, // TEXT_FRAME - registered below
268*cdf0e10cSrcweir         ATK_ROLE_TOGGLE_BUTTON,
269*cdf0e10cSrcweir         ATK_ROLE_TOOL_BAR,
270*cdf0e10cSrcweir         ATK_ROLE_TOOL_TIP,
271*cdf0e10cSrcweir         ATK_ROLE_TREE,
272*cdf0e10cSrcweir         ATK_ROLE_VIEWPORT,
273*cdf0e10cSrcweir         ATK_ROLE_WINDOW,
274*cdf0e10cSrcweir         ATK_ROLE_PUSH_BUTTON,   // BUTTON_DROPDOWN
275*cdf0e10cSrcweir         ATK_ROLE_PUSH_BUTTON,   // BUTTON_MENU
276*cdf0e10cSrcweir         ATK_ROLE_UNKNOWN,       // CAPTION - registered below
277*cdf0e10cSrcweir         ATK_ROLE_UNKNOWN,       // CHART - registered below
278*cdf0e10cSrcweir         ATK_ROLE_UNKNOWN,       // EDIT_BAR - registered below
279*cdf0e10cSrcweir         ATK_ROLE_UNKNOWN,       // FORM - registered below
280*cdf0e10cSrcweir         ATK_ROLE_UNKNOWN,       // IMAGE_MAP - registered below
281*cdf0e10cSrcweir         ATK_ROLE_UNKNOWN,       // NOTE - registered below
282*cdf0e10cSrcweir         ATK_ROLE_UNKNOWN,       // PAGE - registered below
283*cdf0e10cSrcweir         ATK_ROLE_RULER,
284*cdf0e10cSrcweir         ATK_ROLE_UNKNOWN,       // SECTION - registered below
285*cdf0e10cSrcweir         ATK_ROLE_UNKNOWN,       // TREE_ITEM - registered below
286*cdf0e10cSrcweir         ATK_ROLE_TREE_TABLE,
287*cdf0e10cSrcweir         ATK_ROLE_SCROLL_PANE,   // COMMENT - mapped to atk_role_scroll_pane
288*cdf0e10cSrcweir         ATK_ROLE_UNKNOWN        // COMMENT_END - mapped to atk_role_unknown
289*cdf0e10cSrcweir     };
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir     static bool initialized = false;
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir     if( ! initialized )
294*cdf0e10cSrcweir     {
295*cdf0e10cSrcweir         // re-use strings from ATK library
296*cdf0e10cSrcweir         roleMap[accessibility::AccessibleRole::EDIT_BAR] = registerRole("edit bar");
297*cdf0e10cSrcweir         roleMap[accessibility::AccessibleRole::EMBEDDED_OBJECT] = registerRole("embedded component");
298*cdf0e10cSrcweir         roleMap[accessibility::AccessibleRole::CHART] = registerRole("chart");
299*cdf0e10cSrcweir         roleMap[accessibility::AccessibleRole::CAPTION] = registerRole("caption");
300*cdf0e10cSrcweir         roleMap[accessibility::AccessibleRole::DOCUMENT] = registerRole("document frame");
301*cdf0e10cSrcweir         roleMap[accessibility::AccessibleRole::HEADING] = registerRole("heading");
302*cdf0e10cSrcweir         roleMap[accessibility::AccessibleRole::PAGE] = registerRole("page");
303*cdf0e10cSrcweir         roleMap[accessibility::AccessibleRole::SECTION] = registerRole("section");
304*cdf0e10cSrcweir         roleMap[accessibility::AccessibleRole::FORM] = registerRole("form");
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir         // these don't exist in ATK yet
307*cdf0e10cSrcweir         roleMap[accessibility::AccessibleRole::END_NOTE] = registerRole("end note");
308*cdf0e10cSrcweir         roleMap[accessibility::AccessibleRole::FOOTNOTE] = registerRole("foot note");
309*cdf0e10cSrcweir         roleMap[accessibility::AccessibleRole::GROUP_BOX] = registerRole("group box");
310*cdf0e10cSrcweir         roleMap[accessibility::AccessibleRole::HYPER_LINK] = registerRole("hyper link");
311*cdf0e10cSrcweir         roleMap[accessibility::AccessibleRole::SHAPE] = registerRole("shape");
312*cdf0e10cSrcweir         roleMap[accessibility::AccessibleRole::TEXT_FRAME] = registerRole("text frame");
313*cdf0e10cSrcweir         roleMap[accessibility::AccessibleRole::IMAGE_MAP] = registerRole("image map");
314*cdf0e10cSrcweir         roleMap[accessibility::AccessibleRole::NOTE] = registerRole("note");
315*cdf0e10cSrcweir         roleMap[accessibility::AccessibleRole::TREE_ITEM] = registerRole("tree item");
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir         initialized = true;
318*cdf0e10cSrcweir     }
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir     static const sal_Int32 nMapSize = sizeof(roleMap)/sizeof(sal_Int16);
321*cdf0e10cSrcweir     if( 0 <= nRole &&  nMapSize > nRole )
322*cdf0e10cSrcweir         role = roleMap[nRole];
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir     return role;
325*cdf0e10cSrcweir }
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir /*****************************************************************************/
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir extern "C" {
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir /*****************************************************************************/
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir static G_CONST_RETURN gchar*
335*cdf0e10cSrcweir wrapper_get_name( AtkObject *atk_obj )
336*cdf0e10cSrcweir {
337*cdf0e10cSrcweir     AtkObjectWrapper *obj = ATK_OBJECT_WRAPPER (atk_obj);
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir     if( obj->mpContext )
340*cdf0e10cSrcweir     {
341*cdf0e10cSrcweir         try {
342*cdf0e10cSrcweir             rtl::OString aName =
343*cdf0e10cSrcweir                 rtl::OUStringToOString(
344*cdf0e10cSrcweir                     obj->mpContext->getAccessibleName(),
345*cdf0e10cSrcweir                     RTL_TEXTENCODING_UTF8);
346*cdf0e10cSrcweir 
347*cdf0e10cSrcweir             int nCmp = atk_obj->name ? rtl_str_compare( atk_obj->name, aName.getStr() ) : -1;
348*cdf0e10cSrcweir             if( nCmp != 0 )
349*cdf0e10cSrcweir             {
350*cdf0e10cSrcweir                 if( atk_obj->name )
351*cdf0e10cSrcweir                     g_free(atk_obj->name);
352*cdf0e10cSrcweir                 atk_obj->name = g_strdup(aName.getStr());
353*cdf0e10cSrcweir             }
354*cdf0e10cSrcweir         }
355*cdf0e10cSrcweir         catch(const uno::Exception& e) {
356*cdf0e10cSrcweir             g_warning( "Exception in getAccessibleName()" );
357*cdf0e10cSrcweir         }
358*cdf0e10cSrcweir     }
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir     return ATK_OBJECT_CLASS (parent_class)->get_name(atk_obj);
361*cdf0e10cSrcweir }
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir /*****************************************************************************/
364*cdf0e10cSrcweir 
365*cdf0e10cSrcweir static G_CONST_RETURN gchar*
366*cdf0e10cSrcweir wrapper_get_description( AtkObject *atk_obj )
367*cdf0e10cSrcweir {
368*cdf0e10cSrcweir     AtkObjectWrapper *obj = ATK_OBJECT_WRAPPER (atk_obj);
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir     if( obj->mpContext )
371*cdf0e10cSrcweir     {
372*cdf0e10cSrcweir         try {
373*cdf0e10cSrcweir             rtl::OString aDescription =
374*cdf0e10cSrcweir                 rtl::OUStringToOString(
375*cdf0e10cSrcweir                     obj->mpContext->getAccessibleDescription(),
376*cdf0e10cSrcweir                     RTL_TEXTENCODING_UTF8);
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir             g_free(atk_obj->description);
379*cdf0e10cSrcweir             atk_obj->description = g_strdup(aDescription.getStr());
380*cdf0e10cSrcweir         }
381*cdf0e10cSrcweir         catch(const uno::Exception& e) {
382*cdf0e10cSrcweir             g_warning( "Exception in getAccessibleDescription()" );
383*cdf0e10cSrcweir         }
384*cdf0e10cSrcweir     }
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir     return ATK_OBJECT_CLASS (parent_class)->get_description(atk_obj);
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir }
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir /*****************************************************************************/
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir static gint
393*cdf0e10cSrcweir wrapper_get_n_children( AtkObject *atk_obj )
394*cdf0e10cSrcweir {
395*cdf0e10cSrcweir     AtkObjectWrapper *obj = ATK_OBJECT_WRAPPER (atk_obj);
396*cdf0e10cSrcweir     gint n = 0;
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir     if( obj->mpContext )
399*cdf0e10cSrcweir     {
400*cdf0e10cSrcweir         try {
401*cdf0e10cSrcweir             n = obj->mpContext->getAccessibleChildCount();
402*cdf0e10cSrcweir         }
403*cdf0e10cSrcweir         catch(const uno::Exception& e) {
404*cdf0e10cSrcweir             OSL_ENSURE(0, "Exception in getAccessibleChildCount()" );
405*cdf0e10cSrcweir         }
406*cdf0e10cSrcweir     }
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir     return n;
409*cdf0e10cSrcweir }
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir /*****************************************************************************/
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir static AtkObject *
414*cdf0e10cSrcweir wrapper_ref_child( AtkObject *atk_obj,
415*cdf0e10cSrcweir                    gint       i )
416*cdf0e10cSrcweir {
417*cdf0e10cSrcweir     AtkObjectWrapper *obj = ATK_OBJECT_WRAPPER (atk_obj);
418*cdf0e10cSrcweir     AtkObject* child = NULL;
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir     // see comments above atk_object_wrapper_remove_child
421*cdf0e10cSrcweir     if( -1 < i && obj->index_of_child_about_to_be_removed == i )
422*cdf0e10cSrcweir     {
423*cdf0e10cSrcweir         g_object_ref( obj->child_about_to_be_removed );
424*cdf0e10cSrcweir         return obj->child_about_to_be_removed;
425*cdf0e10cSrcweir     }
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir     if( obj->mpContext )
428*cdf0e10cSrcweir     {
429*cdf0e10cSrcweir         try {
430*cdf0e10cSrcweir             uno::Reference< accessibility::XAccessible > xAccessible =
431*cdf0e10cSrcweir                 obj->mpContext->getAccessibleChild( i );
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir             child = atk_object_wrapper_ref( xAccessible );
434*cdf0e10cSrcweir         }
435*cdf0e10cSrcweir         catch(const uno::Exception& e) {
436*cdf0e10cSrcweir             OSL_ENSURE(0, "Exception in getAccessibleChild");
437*cdf0e10cSrcweir         }
438*cdf0e10cSrcweir     }
439*cdf0e10cSrcweir 
440*cdf0e10cSrcweir     return child;
441*cdf0e10cSrcweir }
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir /*****************************************************************************/
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir static gint
446*cdf0e10cSrcweir wrapper_get_index_in_parent( AtkObject *atk_obj )
447*cdf0e10cSrcweir {
448*cdf0e10cSrcweir     AtkObjectWrapper *obj = ATK_OBJECT_WRAPPER (atk_obj);
449*cdf0e10cSrcweir     gint i = -1;
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir     if( obj->mpContext )
452*cdf0e10cSrcweir     {
453*cdf0e10cSrcweir         try {
454*cdf0e10cSrcweir             i = obj->mpContext->getAccessibleIndexInParent();
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir #ifdef ENABLE_TRACING
457*cdf0e10cSrcweir             fprintf(stderr, "%p->getAccessibleIndexInParent() returned: %u\n",
458*cdf0e10cSrcweir                 obj->mpAccessible, i);
459*cdf0e10cSrcweir #endif
460*cdf0e10cSrcweir         }
461*cdf0e10cSrcweir         catch(const uno::Exception& e) {
462*cdf0e10cSrcweir             g_warning( "Exception in getAccessibleIndexInParent()" );
463*cdf0e10cSrcweir         }
464*cdf0e10cSrcweir     }
465*cdf0e10cSrcweir     return i;
466*cdf0e10cSrcweir }
467*cdf0e10cSrcweir 
468*cdf0e10cSrcweir /*****************************************************************************/
469*cdf0e10cSrcweir 
470*cdf0e10cSrcweir static AtkRelationSet *
471*cdf0e10cSrcweir wrapper_ref_relation_set( AtkObject *atk_obj )
472*cdf0e10cSrcweir {
473*cdf0e10cSrcweir     AtkObjectWrapper *obj = ATK_OBJECT_WRAPPER (atk_obj);
474*cdf0e10cSrcweir     AtkRelationSet *pSet = atk_relation_set_new();
475*cdf0e10cSrcweir 
476*cdf0e10cSrcweir     if( obj->mpContext )
477*cdf0e10cSrcweir     {
478*cdf0e10cSrcweir         try {
479*cdf0e10cSrcweir             uno::Reference< accessibility::XAccessibleRelationSet > xRelationSet(
480*cdf0e10cSrcweir                     obj->mpContext->getAccessibleRelationSet()
481*cdf0e10cSrcweir             );
482*cdf0e10cSrcweir 
483*cdf0e10cSrcweir             sal_Int32 nRelations = xRelationSet.is() ? xRelationSet->getRelationCount() : 0;
484*cdf0e10cSrcweir             for( sal_Int32 n = 0; n < nRelations; n++ )
485*cdf0e10cSrcweir             {
486*cdf0e10cSrcweir                 accessibility::AccessibleRelation aRelation = xRelationSet->getRelation( n );
487*cdf0e10cSrcweir                 sal_uInt32 nTargetCount = aRelation.TargetSet.getLength();
488*cdf0e10cSrcweir                 AtkObject **pTargets = (AtkObject **) alloca( nTargetCount * sizeof(AtkObject *) );
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir                 for( sal_uInt32 i = 0; i < nTargetCount; i++ )
491*cdf0e10cSrcweir                 {
492*cdf0e10cSrcweir                     uno::Reference< accessibility::XAccessible > xAccessible(
493*cdf0e10cSrcweir                             aRelation.TargetSet[i], uno::UNO_QUERY );
494*cdf0e10cSrcweir                     pTargets[i] = atk_object_wrapper_ref( xAccessible );
495*cdf0e10cSrcweir                 }
496*cdf0e10cSrcweir 
497*cdf0e10cSrcweir                 AtkRelation *pRel =
498*cdf0e10cSrcweir                     atk_relation_new(
499*cdf0e10cSrcweir                         pTargets, nTargetCount,
500*cdf0e10cSrcweir                         mapRelationType( aRelation.RelationType )
501*cdf0e10cSrcweir                     );
502*cdf0e10cSrcweir                 atk_relation_set_add( pSet, pRel );
503*cdf0e10cSrcweir                 g_object_unref( G_OBJECT( pRel ) );
504*cdf0e10cSrcweir             }
505*cdf0e10cSrcweir         }
506*cdf0e10cSrcweir         catch(const uno::Exception &e) {
507*cdf0e10cSrcweir             g_object_unref( G_OBJECT( pSet ) );
508*cdf0e10cSrcweir             pSet = NULL;
509*cdf0e10cSrcweir         }
510*cdf0e10cSrcweir     }
511*cdf0e10cSrcweir 
512*cdf0e10cSrcweir     return pSet;
513*cdf0e10cSrcweir }
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir /*****************************************************************************/
516*cdf0e10cSrcweir 
517*cdf0e10cSrcweir #if 0
518*cdf0e10cSrcweir struct {
519*cdf0e10cSrcweir     sal_Int16       value;
520*cdf0e10cSrcweir     const sal_Char* name;
521*cdf0e10cSrcweir } aStateTypeTable[] = {
522*cdf0e10cSrcweir     { accessibility::AccessibleStateType::INVALID, "INVALID" },
523*cdf0e10cSrcweir     { accessibility::AccessibleStateType::ACTIVE, "ACTIVE" },
524*cdf0e10cSrcweir     { accessibility::AccessibleStateType::ARMED, "ARMED" },
525*cdf0e10cSrcweir     { accessibility::AccessibleStateType::BUSY, "BUSY" },
526*cdf0e10cSrcweir     { accessibility::AccessibleStateType::CHECKED, "CHECKED" },
527*cdf0e10cSrcweir     { accessibility::AccessibleStateType::DEFUNC, "DEFUNC" },
528*cdf0e10cSrcweir     { accessibility::AccessibleStateType::EDITABLE, "EDITABLE" },
529*cdf0e10cSrcweir     { accessibility::AccessibleStateType::ENABLED, "ENABLED" },
530*cdf0e10cSrcweir     { accessibility::AccessibleStateType::EXPANDABLE, "EXPANDABLE" },
531*cdf0e10cSrcweir     { accessibility::AccessibleStateType::EXPANDED, "EXPANDED" },
532*cdf0e10cSrcweir     { accessibility::AccessibleStateType::FOCUSABLE, "FOCUSABLE" },
533*cdf0e10cSrcweir     { accessibility::AccessibleStateType::FOCUSED, "FOCUSED" },
534*cdf0e10cSrcweir     { accessibility::AccessibleStateType::HORIZONTAL, "HORIZONTAL" },
535*cdf0e10cSrcweir     { accessibility::AccessibleStateType::ICONIFIED, "ICONIFIED" },
536*cdf0e10cSrcweir     { accessibility::AccessibleStateType::INDETERMINATE, "INDETERMINATE" },
537*cdf0e10cSrcweir     { accessibility::AccessibleStateType::MANAGES_DESCENDANTS, "MANAGES_DESCENDANTS" },
538*cdf0e10cSrcweir     { accessibility::AccessibleStateType::MODAL, "MODAL" },
539*cdf0e10cSrcweir     { accessibility::AccessibleStateType::MULTI_LINE, "MULTI_LINE" },
540*cdf0e10cSrcweir     { accessibility::AccessibleStateType::MULTI_SELECTABLE, "MULTI_SELECTABLE" },
541*cdf0e10cSrcweir     { accessibility::AccessibleStateType::OPAQUE, "OPAQUE" },
542*cdf0e10cSrcweir     { accessibility::AccessibleStateType::PRESSED, "PRESSED" },
543*cdf0e10cSrcweir     { accessibility::AccessibleStateType::RESIZABLE, "RESIZABLE" },
544*cdf0e10cSrcweir     { accessibility::AccessibleStateType::SELECTABLE, "SELECTABLE" },
545*cdf0e10cSrcweir     { accessibility::AccessibleStateType::SELECTED, "SELECTED" },
546*cdf0e10cSrcweir     { accessibility::AccessibleStateType::SENSITIVE, "SENSITIVE" },
547*cdf0e10cSrcweir     { accessibility::AccessibleStateType::SHOWING, "SHOWING" },
548*cdf0e10cSrcweir     { accessibility::AccessibleStateType::SINGLE_LINE, "SINGLE_LINE" },
549*cdf0e10cSrcweir     { accessibility::AccessibleStateType::STALE, "STALE" },
550*cdf0e10cSrcweir     { accessibility::AccessibleStateType::TRANSIENT, "TRANSIENT" },
551*cdf0e10cSrcweir     { accessibility::AccessibleStateType::VERTICAL, "VERTICAL" },
552*cdf0e10cSrcweir     { accessibility::AccessibleStateType::VISIBLE, "VISIBLE" }
553*cdf0e10cSrcweir };
554*cdf0e10cSrcweir 
555*cdf0e10cSrcweir static void printStates(const uno::Sequence<sal_Int16>& rStates)
556*cdf0e10cSrcweir {
557*cdf0e10cSrcweir     sal_Int32 n = rStates.getLength();
558*cdf0e10cSrcweir     size_t nTypes = sizeof(aStateTypeTable)/sizeof(aStateTypeTable[0]);
559*cdf0e10cSrcweir     for (sal_Int32 i = 0; i < n; ++i)
560*cdf0e10cSrcweir     {
561*cdf0e10cSrcweir         for (size_t j = 0; j < nTypes; ++j)
562*cdf0e10cSrcweir         {
563*cdf0e10cSrcweir             if (aStateTypeTable[j].value == rStates[i])
564*cdf0e10cSrcweir                 printf("%s ", aStateTypeTable[j].name);
565*cdf0e10cSrcweir         }
566*cdf0e10cSrcweir     }
567*cdf0e10cSrcweir     printf("\n");
568*cdf0e10cSrcweir }
569*cdf0e10cSrcweir #endif
570*cdf0e10cSrcweir 
571*cdf0e10cSrcweir static AtkStateSet *
572*cdf0e10cSrcweir wrapper_ref_state_set( AtkObject *atk_obj )
573*cdf0e10cSrcweir {
574*cdf0e10cSrcweir     AtkObjectWrapper *obj = ATK_OBJECT_WRAPPER (atk_obj);
575*cdf0e10cSrcweir     AtkStateSet *pSet = atk_state_set_new();
576*cdf0e10cSrcweir 
577*cdf0e10cSrcweir     if( obj->mpContext )
578*cdf0e10cSrcweir     {
579*cdf0e10cSrcweir         try {
580*cdf0e10cSrcweir             uno::Reference< accessibility::XAccessibleStateSet > xStateSet(
581*cdf0e10cSrcweir                 obj->mpContext->getAccessibleStateSet());
582*cdf0e10cSrcweir 
583*cdf0e10cSrcweir             if( xStateSet.is() )
584*cdf0e10cSrcweir             {
585*cdf0e10cSrcweir                 uno::Sequence< sal_Int16 > aStates = xStateSet->getStates();
586*cdf0e10cSrcweir 
587*cdf0e10cSrcweir                 for( sal_Int32 n = 0; n < aStates.getLength(); n++ )
588*cdf0e10cSrcweir                     atk_state_set_add_state( pSet, mapAtkState( aStates[n] ) );
589*cdf0e10cSrcweir 
590*cdf0e10cSrcweir                 // We need to emulate FOCUS state for menus, menu-items etc.
591*cdf0e10cSrcweir                 if( atk_obj == atk_get_focus_object() )
592*cdf0e10cSrcweir                     atk_state_set_add_state( pSet, ATK_STATE_FOCUSED );
593*cdf0e10cSrcweir /* FIXME - should we do this ?
594*cdf0e10cSrcweir                 else
595*cdf0e10cSrcweir                     atk_state_set_remove_state( pSet, ATK_STATE_FOCUSED );
596*cdf0e10cSrcweir */
597*cdf0e10cSrcweir             }
598*cdf0e10cSrcweir         }
599*cdf0e10cSrcweir 
600*cdf0e10cSrcweir         catch(const uno::Exception &e) {
601*cdf0e10cSrcweir             g_warning( "Exception in wrapper_ref_state_set" );
602*cdf0e10cSrcweir             atk_state_set_add_state( pSet, ATK_STATE_DEFUNCT );
603*cdf0e10cSrcweir         }
604*cdf0e10cSrcweir     }
605*cdf0e10cSrcweir     else
606*cdf0e10cSrcweir         atk_state_set_add_state( pSet, ATK_STATE_DEFUNCT );
607*cdf0e10cSrcweir 
608*cdf0e10cSrcweir     return pSet;
609*cdf0e10cSrcweir }
610*cdf0e10cSrcweir 
611*cdf0e10cSrcweir /*****************************************************************************/
612*cdf0e10cSrcweir 
613*cdf0e10cSrcweir 
614*cdf0e10cSrcweir static void
615*cdf0e10cSrcweir atk_object_wrapper_finalize (GObject *obj)
616*cdf0e10cSrcweir {
617*cdf0e10cSrcweir     AtkObjectWrapper *pWrap = ATK_OBJECT_WRAPPER (obj);
618*cdf0e10cSrcweir 
619*cdf0e10cSrcweir     if( pWrap->mpAccessible )
620*cdf0e10cSrcweir     {
621*cdf0e10cSrcweir         ooo_wrapper_registry_remove( pWrap->mpAccessible );
622*cdf0e10cSrcweir         pWrap->mpAccessible->release();
623*cdf0e10cSrcweir         pWrap->mpAccessible = NULL;
624*cdf0e10cSrcweir     }
625*cdf0e10cSrcweir 
626*cdf0e10cSrcweir     atk_object_wrapper_dispose( pWrap );
627*cdf0e10cSrcweir 
628*cdf0e10cSrcweir     parent_class->finalize( obj );
629*cdf0e10cSrcweir }
630*cdf0e10cSrcweir 
631*cdf0e10cSrcweir static void
632*cdf0e10cSrcweir atk_object_wrapper_class_init (AtkObjectWrapperClass *klass)
633*cdf0e10cSrcweir {
634*cdf0e10cSrcweir   GObjectClass *gobject_class = G_OBJECT_CLASS( klass );
635*cdf0e10cSrcweir   AtkObjectClass *atk_class = ATK_OBJECT_CLASS( klass );
636*cdf0e10cSrcweir 
637*cdf0e10cSrcweir   parent_class = (GObjectClass *) g_type_class_peek_parent (klass);
638*cdf0e10cSrcweir 
639*cdf0e10cSrcweir   // GObject methods
640*cdf0e10cSrcweir   gobject_class->finalize = atk_object_wrapper_finalize;
641*cdf0e10cSrcweir 
642*cdf0e10cSrcweir   // AtkObject methods
643*cdf0e10cSrcweir   atk_class->get_name = wrapper_get_name;
644*cdf0e10cSrcweir   atk_class->get_description = wrapper_get_description;
645*cdf0e10cSrcweir   atk_class->get_n_children = wrapper_get_n_children;
646*cdf0e10cSrcweir   atk_class->ref_child = wrapper_ref_child;
647*cdf0e10cSrcweir   atk_class->get_index_in_parent = wrapper_get_index_in_parent;
648*cdf0e10cSrcweir   atk_class->ref_relation_set = wrapper_ref_relation_set;
649*cdf0e10cSrcweir   atk_class->ref_state_set = wrapper_ref_state_set;
650*cdf0e10cSrcweir }
651*cdf0e10cSrcweir 
652*cdf0e10cSrcweir static void
653*cdf0e10cSrcweir atk_object_wrapper_init (AtkObjectWrapper      *wrapper,
654*cdf0e10cSrcweir                          AtkObjectWrapperClass)
655*cdf0e10cSrcweir {
656*cdf0e10cSrcweir    wrapper->mpAction = NULL;
657*cdf0e10cSrcweir    wrapper->mpComponent = NULL;
658*cdf0e10cSrcweir    wrapper->mpEditableText = NULL;
659*cdf0e10cSrcweir    wrapper->mpHypertext = NULL;
660*cdf0e10cSrcweir    wrapper->mpImage = NULL;
661*cdf0e10cSrcweir    wrapper->mpSelection = NULL;
662*cdf0e10cSrcweir    wrapper->mpTable = NULL;
663*cdf0e10cSrcweir    wrapper->mpText = NULL;
664*cdf0e10cSrcweir    wrapper->mpValue = NULL;
665*cdf0e10cSrcweir }
666*cdf0e10cSrcweir 
667*cdf0e10cSrcweir } // extern "C"
668*cdf0e10cSrcweir 
669*cdf0e10cSrcweir GType
670*cdf0e10cSrcweir atk_object_wrapper_get_type (void)
671*cdf0e10cSrcweir {
672*cdf0e10cSrcweir   static GType type = 0;
673*cdf0e10cSrcweir 
674*cdf0e10cSrcweir   if (!type)
675*cdf0e10cSrcweir     {
676*cdf0e10cSrcweir       static const GTypeInfo typeInfo =
677*cdf0e10cSrcweir       {
678*cdf0e10cSrcweir         sizeof (AtkObjectWrapperClass),
679*cdf0e10cSrcweir         (GBaseInitFunc) NULL,
680*cdf0e10cSrcweir         (GBaseFinalizeFunc) NULL,
681*cdf0e10cSrcweir         (GClassInitFunc) atk_object_wrapper_class_init,
682*cdf0e10cSrcweir         (GClassFinalizeFunc) NULL,
683*cdf0e10cSrcweir         NULL,
684*cdf0e10cSrcweir         sizeof (AtkObjectWrapper),
685*cdf0e10cSrcweir         0,
686*cdf0e10cSrcweir         (GInstanceInitFunc) atk_object_wrapper_init,
687*cdf0e10cSrcweir         NULL
688*cdf0e10cSrcweir       } ;
689*cdf0e10cSrcweir       type = g_type_register_static (ATK_TYPE_OBJECT,
690*cdf0e10cSrcweir                                      "OOoAtkObj",
691*cdf0e10cSrcweir                                      &typeInfo, (GTypeFlags)0) ;
692*cdf0e10cSrcweir     }
693*cdf0e10cSrcweir   return type;
694*cdf0e10cSrcweir }
695*cdf0e10cSrcweir 
696*cdf0e10cSrcweir static bool
697*cdf0e10cSrcweir isOfType( uno::XInterface *pInterface, const uno::Type & rType )
698*cdf0e10cSrcweir {
699*cdf0e10cSrcweir     g_return_val_if_fail( pInterface != NULL, false );
700*cdf0e10cSrcweir 
701*cdf0e10cSrcweir     bool bIs = false;
702*cdf0e10cSrcweir     try {
703*cdf0e10cSrcweir         uno::Any aRet = pInterface->queryInterface( rType );
704*cdf0e10cSrcweir 
705*cdf0e10cSrcweir         bIs = ( ( typelib_TypeClass_INTERFACE == aRet.pType->eTypeClass ) &&
706*cdf0e10cSrcweir                 ( aRet.pReserved != NULL ) );
707*cdf0e10cSrcweir     } catch( const uno::Exception &e) { }
708*cdf0e10cSrcweir 
709*cdf0e10cSrcweir     return bIs;
710*cdf0e10cSrcweir }
711*cdf0e10cSrcweir 
712*cdf0e10cSrcweir extern "C" {
713*cdf0e10cSrcweir typedef  GType (* GetGIfaceType ) (void);
714*cdf0e10cSrcweir }
715*cdf0e10cSrcweir const struct {
716*cdf0e10cSrcweir         const char          *name;
717*cdf0e10cSrcweir         GInterfaceInitFunc   aInit;
718*cdf0e10cSrcweir         GetGIfaceType        aGetGIfaceType;
719*cdf0e10cSrcweir         const uno::Type &  (*aGetUnoType) (void *);
720*cdf0e10cSrcweir } aTypeTable[] = {
721*cdf0e10cSrcweir // re-location heaven:
722*cdf0e10cSrcweir     {
723*cdf0e10cSrcweir         "Comp", (GInterfaceInitFunc) componentIfaceInit,
724*cdf0e10cSrcweir         atk_component_get_type,
725*cdf0e10cSrcweir         accessibility::XAccessibleComponent::static_type
726*cdf0e10cSrcweir     },
727*cdf0e10cSrcweir     {
728*cdf0e10cSrcweir         "Act",  (GInterfaceInitFunc) actionIfaceInit,
729*cdf0e10cSrcweir         atk_action_get_type,
730*cdf0e10cSrcweir         accessibility::XAccessibleAction::static_type
731*cdf0e10cSrcweir     },
732*cdf0e10cSrcweir     {
733*cdf0e10cSrcweir         "Txt",  (GInterfaceInitFunc) textIfaceInit,
734*cdf0e10cSrcweir         atk_text_get_type,
735*cdf0e10cSrcweir         accessibility::XAccessibleText::static_type
736*cdf0e10cSrcweir     },
737*cdf0e10cSrcweir     {
738*cdf0e10cSrcweir         "Val",  (GInterfaceInitFunc) valueIfaceInit,
739*cdf0e10cSrcweir         atk_value_get_type,
740*cdf0e10cSrcweir         accessibility::XAccessibleValue::static_type
741*cdf0e10cSrcweir     },
742*cdf0e10cSrcweir     {
743*cdf0e10cSrcweir         "Tab",  (GInterfaceInitFunc) tableIfaceInit,
744*cdf0e10cSrcweir         atk_table_get_type,
745*cdf0e10cSrcweir         accessibility::XAccessibleTable::static_type
746*cdf0e10cSrcweir     },
747*cdf0e10cSrcweir     {
748*cdf0e10cSrcweir         "Edt",  (GInterfaceInitFunc) editableTextIfaceInit,
749*cdf0e10cSrcweir         atk_editable_text_get_type,
750*cdf0e10cSrcweir         accessibility::XAccessibleEditableText::static_type
751*cdf0e10cSrcweir     },
752*cdf0e10cSrcweir     {
753*cdf0e10cSrcweir         "Img",  (GInterfaceInitFunc) imageIfaceInit,
754*cdf0e10cSrcweir         atk_image_get_type,
755*cdf0e10cSrcweir         accessibility::XAccessibleImage::static_type
756*cdf0e10cSrcweir     },
757*cdf0e10cSrcweir     {
758*cdf0e10cSrcweir         "Hyp",  (GInterfaceInitFunc) hypertextIfaceInit,
759*cdf0e10cSrcweir         atk_hypertext_get_type,
760*cdf0e10cSrcweir         accessibility::XAccessibleHypertext::static_type
761*cdf0e10cSrcweir     },
762*cdf0e10cSrcweir     {
763*cdf0e10cSrcweir         "Sel",  (GInterfaceInitFunc) selectionIfaceInit,
764*cdf0e10cSrcweir         atk_selection_get_type,
765*cdf0e10cSrcweir         accessibility::XAccessibleSelection::static_type
766*cdf0e10cSrcweir     }
767*cdf0e10cSrcweir     // AtkDocument is a nastily broken interface (so far)
768*cdf0e10cSrcweir     //  we could impl. get_document_type perhaps though.
769*cdf0e10cSrcweir };
770*cdf0e10cSrcweir 
771*cdf0e10cSrcweir const int aTypeTableSize = G_N_ELEMENTS( aTypeTable );
772*cdf0e10cSrcweir 
773*cdf0e10cSrcweir static GType
774*cdf0e10cSrcweir ensureTypeFor( uno::XInterface *pAccessible )
775*cdf0e10cSrcweir {
776*cdf0e10cSrcweir     int i;
777*cdf0e10cSrcweir     int bTypes[ aTypeTableSize ] = { 0, };
778*cdf0e10cSrcweir     rtl::OString aTypeName( "OOoAtkObj" );
779*cdf0e10cSrcweir 
780*cdf0e10cSrcweir     for( i = 0; i < aTypeTableSize; i++ )
781*cdf0e10cSrcweir     {
782*cdf0e10cSrcweir         if( isOfType( pAccessible, aTypeTable[i].aGetUnoType(0) ) )
783*cdf0e10cSrcweir         {
784*cdf0e10cSrcweir             aTypeName += aTypeTable[i].name;
785*cdf0e10cSrcweir             bTypes[i] = TRUE;
786*cdf0e10cSrcweir         }
787*cdf0e10cSrcweir //      g_message( "Accessible %p has type '%s' (%d)",
788*cdf0e10cSrcweir //                 pAccessible, aTypeTable[i].name, bTypes[i] );
789*cdf0e10cSrcweir     }
790*cdf0e10cSrcweir 
791*cdf0e10cSrcweir     GType nType = g_type_from_name( aTypeName );
792*cdf0e10cSrcweir     if( nType == G_TYPE_INVALID )
793*cdf0e10cSrcweir     {
794*cdf0e10cSrcweir         GTypeInfo aTypeInfo = {
795*cdf0e10cSrcweir             sizeof( AtkObjectWrapperClass ),
796*cdf0e10cSrcweir             NULL, NULL, NULL, NULL, NULL,
797*cdf0e10cSrcweir             sizeof( AtkObjectWrapper ),
798*cdf0e10cSrcweir             0, NULL, NULL
799*cdf0e10cSrcweir         } ;
800*cdf0e10cSrcweir         nType = g_type_register_static( ATK_TYPE_OBJECT_WRAPPER,
801*cdf0e10cSrcweir                                         aTypeName, &aTypeInfo, (GTypeFlags)0 ) ;
802*cdf0e10cSrcweir 
803*cdf0e10cSrcweir         for( int j = 0; j < aTypeTableSize; j++ )
804*cdf0e10cSrcweir             if( bTypes[j] )
805*cdf0e10cSrcweir             {
806*cdf0e10cSrcweir                 GInterfaceInfo aIfaceInfo = { NULL, NULL, NULL };
807*cdf0e10cSrcweir                 aIfaceInfo.interface_init = aTypeTable[j].aInit;
808*cdf0e10cSrcweir                 g_type_add_interface_static (nType, aTypeTable[j].aGetGIfaceType(),
809*cdf0e10cSrcweir                                              &aIfaceInfo);
810*cdf0e10cSrcweir             }
811*cdf0e10cSrcweir     }
812*cdf0e10cSrcweir     return nType;
813*cdf0e10cSrcweir }
814*cdf0e10cSrcweir 
815*cdf0e10cSrcweir AtkObject *
816*cdf0e10cSrcweir atk_object_wrapper_ref( const uno::Reference< accessibility::XAccessible > &rxAccessible, bool create )
817*cdf0e10cSrcweir {
818*cdf0e10cSrcweir     g_return_val_if_fail( rxAccessible.get() != NULL, NULL );
819*cdf0e10cSrcweir 
820*cdf0e10cSrcweir     AtkObject *obj = ooo_wrapper_registry_get(rxAccessible);
821*cdf0e10cSrcweir     if( obj )
822*cdf0e10cSrcweir     {
823*cdf0e10cSrcweir         g_object_ref( obj );
824*cdf0e10cSrcweir         return obj;
825*cdf0e10cSrcweir     }
826*cdf0e10cSrcweir 
827*cdf0e10cSrcweir     if( create )
828*cdf0e10cSrcweir         return atk_object_wrapper_new( rxAccessible );
829*cdf0e10cSrcweir 
830*cdf0e10cSrcweir     return NULL;
831*cdf0e10cSrcweir }
832*cdf0e10cSrcweir 
833*cdf0e10cSrcweir 
834*cdf0e10cSrcweir AtkObject *
835*cdf0e10cSrcweir atk_object_wrapper_new( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& rxAccessible,
836*cdf0e10cSrcweir                         AtkObject* parent )
837*cdf0e10cSrcweir {
838*cdf0e10cSrcweir     g_return_val_if_fail( rxAccessible.get() != NULL, NULL );
839*cdf0e10cSrcweir 
840*cdf0e10cSrcweir     AtkObjectWrapper *pWrap = NULL;
841*cdf0e10cSrcweir 
842*cdf0e10cSrcweir     try {
843*cdf0e10cSrcweir         uno::Reference< accessibility::XAccessibleContext > xContext(rxAccessible->getAccessibleContext());
844*cdf0e10cSrcweir 
845*cdf0e10cSrcweir         g_return_val_if_fail( xContext.get() != NULL, NULL );
846*cdf0e10cSrcweir 
847*cdf0e10cSrcweir         GType nType = ensureTypeFor( xContext.get() );
848*cdf0e10cSrcweir         gpointer obj = g_object_new( nType, NULL);
849*cdf0e10cSrcweir 
850*cdf0e10cSrcweir         pWrap = ATK_OBJECT_WRAPPER( obj );
851*cdf0e10cSrcweir         pWrap->mpAccessible = rxAccessible.get();
852*cdf0e10cSrcweir         rxAccessible->acquire();
853*cdf0e10cSrcweir 
854*cdf0e10cSrcweir         pWrap->index_of_child_about_to_be_removed = -1;
855*cdf0e10cSrcweir         pWrap->child_about_to_be_removed = NULL;
856*cdf0e10cSrcweir 
857*cdf0e10cSrcweir         xContext->acquire();
858*cdf0e10cSrcweir         pWrap->mpContext = xContext.get();
859*cdf0e10cSrcweir 
860*cdf0e10cSrcweir         AtkObject* atk_obj = ATK_OBJECT(pWrap);
861*cdf0e10cSrcweir         atk_obj->role = mapToAtkRole( xContext->getAccessibleRole() );
862*cdf0e10cSrcweir         atk_obj->accessible_parent = parent;
863*cdf0e10cSrcweir 
864*cdf0e10cSrcweir         ooo_wrapper_registry_add( rxAccessible, atk_obj );
865*cdf0e10cSrcweir 
866*cdf0e10cSrcweir         if( parent )
867*cdf0e10cSrcweir             g_object_ref( atk_obj->accessible_parent );
868*cdf0e10cSrcweir         else
869*cdf0e10cSrcweir         {
870*cdf0e10cSrcweir             /* gail_focus_tracker remembers the focused object at the first
871*cdf0e10cSrcweir              * parent in the hierachy that is a Gtk+ widget, but at the time the
872*cdf0e10cSrcweir              * event gets processed (at idle), it may be too late to create the
873*cdf0e10cSrcweir              * hierachy, so doing it now ..
874*cdf0e10cSrcweir              */
875*cdf0e10cSrcweir             uno::Reference< accessibility::XAccessible > xParent( xContext->getAccessibleParent() );
876*cdf0e10cSrcweir 
877*cdf0e10cSrcweir             /* The top-level objects should never be of this class */
878*cdf0e10cSrcweir             OSL_ASSERT( xParent.is() );
879*cdf0e10cSrcweir 
880*cdf0e10cSrcweir             if( xParent.is() )
881*cdf0e10cSrcweir                 atk_obj->accessible_parent = atk_object_wrapper_ref( xParent );
882*cdf0e10cSrcweir         }
883*cdf0e10cSrcweir 
884*cdf0e10cSrcweir         // Attach a listener to the UNO object if it's not TRANSIENT
885*cdf0e10cSrcweir         uno::Reference< accessibility::XAccessibleStateSet > xStateSet( xContext->getAccessibleStateSet() );
886*cdf0e10cSrcweir         if( xStateSet.is() && ! xStateSet->contains( accessibility::AccessibleStateType::TRANSIENT ) )
887*cdf0e10cSrcweir         {
888*cdf0e10cSrcweir             uno::Reference< accessibility::XAccessibleEventBroadcaster > xBroadcaster(xContext, uno::UNO_QUERY);
889*cdf0e10cSrcweir             if( xBroadcaster.is() )
890*cdf0e10cSrcweir                 xBroadcaster->addEventListener( static_cast< accessibility::XAccessibleEventListener * > ( new AtkListener(pWrap) ) );
891*cdf0e10cSrcweir 	    else
892*cdf0e10cSrcweir                 OSL_ASSERT( false );
893*cdf0e10cSrcweir         }
894*cdf0e10cSrcweir 
895*cdf0e10cSrcweir         return ATK_OBJECT( pWrap );
896*cdf0e10cSrcweir     }
897*cdf0e10cSrcweir     catch (const uno::Exception &e)
898*cdf0e10cSrcweir     {
899*cdf0e10cSrcweir         if( pWrap )
900*cdf0e10cSrcweir             g_object_unref( pWrap );
901*cdf0e10cSrcweir 
902*cdf0e10cSrcweir         return NULL;
903*cdf0e10cSrcweir     }
904*cdf0e10cSrcweir }
905*cdf0e10cSrcweir 
906*cdf0e10cSrcweir 
907*cdf0e10cSrcweir /*****************************************************************************/
908*cdf0e10cSrcweir 
909*cdf0e10cSrcweir void atk_object_wrapper_add_child(AtkObjectWrapper* wrapper, AtkObject *child, gint index)
910*cdf0e10cSrcweir {
911*cdf0e10cSrcweir     AtkObject *atk_obj = ATK_OBJECT( wrapper );
912*cdf0e10cSrcweir 
913*cdf0e10cSrcweir     atk_object_set_parent( child, atk_obj );
914*cdf0e10cSrcweir     g_signal_emit_by_name( atk_obj, "children_changed::add", index, child, NULL );
915*cdf0e10cSrcweir }
916*cdf0e10cSrcweir 
917*cdf0e10cSrcweir /*****************************************************************************/
918*cdf0e10cSrcweir 
919*cdf0e10cSrcweir void atk_object_wrapper_remove_child(AtkObjectWrapper* wrapper, AtkObject *child, gint index)
920*cdf0e10cSrcweir {
921*cdf0e10cSrcweir     /*
922*cdf0e10cSrcweir      * the atk-bridge GTK+ module get's back to the event source to ref the child just
923*cdf0e10cSrcweir      * vanishing, so we keep this reference because the semantic on OOo side is different.
924*cdf0e10cSrcweir      */
925*cdf0e10cSrcweir     wrapper->child_about_to_be_removed = child;
926*cdf0e10cSrcweir     wrapper->index_of_child_about_to_be_removed = index;
927*cdf0e10cSrcweir 
928*cdf0e10cSrcweir     g_signal_emit_by_name( ATK_OBJECT( wrapper ), "children_changed::remove", index, child, NULL );
929*cdf0e10cSrcweir 
930*cdf0e10cSrcweir     wrapper->index_of_child_about_to_be_removed = -1;
931*cdf0e10cSrcweir     wrapper->child_about_to_be_removed = NULL;
932*cdf0e10cSrcweir }
933*cdf0e10cSrcweir 
934*cdf0e10cSrcweir /*****************************************************************************/
935*cdf0e10cSrcweir 
936*cdf0e10cSrcweir #define RELEASE(i) if( i ) { i->release(); i = NULL; }
937*cdf0e10cSrcweir 
938*cdf0e10cSrcweir void atk_object_wrapper_dispose(AtkObjectWrapper* wrapper)
939*cdf0e10cSrcweir {
940*cdf0e10cSrcweir     RELEASE( wrapper->mpContext )
941*cdf0e10cSrcweir     RELEASE( wrapper->mpAction )
942*cdf0e10cSrcweir     RELEASE( wrapper->mpComponent )
943*cdf0e10cSrcweir     RELEASE( wrapper->mpEditableText )
944*cdf0e10cSrcweir     RELEASE( wrapper->mpHypertext )
945*cdf0e10cSrcweir     RELEASE( wrapper->mpImage )
946*cdf0e10cSrcweir     RELEASE( wrapper->mpSelection )
947*cdf0e10cSrcweir     RELEASE( wrapper->mpMultiLineText )
948*cdf0e10cSrcweir     RELEASE( wrapper->mpTable )
949*cdf0e10cSrcweir     RELEASE( wrapper->mpText )
950*cdf0e10cSrcweir     RELEASE( wrapper->mpTextMarkup )
951*cdf0e10cSrcweir     RELEASE( wrapper->mpTextAttributes )
952*cdf0e10cSrcweir     RELEASE( wrapper->mpValue )
953*cdf0e10cSrcweir }
954