1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: atkcomponent.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
34 #include "atkwrapper.hxx"
36 #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
42 using namespace ::com::sun::star
;
44 static accessibility::XAccessibleComponent
*
45 getComponent( AtkComponent
*pComponent
) throw (uno::RuntimeException
)
47 AtkObjectWrapper
*pWrap
= ATK_OBJECT_WRAPPER( pComponent
);
50 if( !pWrap
->mpComponent
&& pWrap
->mpContext
)
52 uno::Any any
= pWrap
->mpContext
->queryInterface( accessibility::XAccessibleComponent::static_type(NULL
) );
53 pWrap
->mpComponent
= reinterpret_cast< accessibility::XAccessibleComponent
* > (any
.pReserved
);
54 pWrap
->mpComponent
->acquire();
57 return pWrap
->mpComponent
;
63 /*****************************************************************************/
66 translatePoint( accessibility::XAccessibleComponent
*pComponent
,
67 gint x
, gint y
, AtkCoordType t
)
69 awt::Point
aOrigin( 0, 0 );
70 if( t
== ATK_XY_SCREEN
)
71 aOrigin
= pComponent
->getLocationOnScreen();
74 fprintf(stderr
, "coordinates ( %u, %u ) translated to: ( %u, %u )\n",
75 x
, y
, x
- aOrigin
.X
, y
- aOrigin
.Y
);
78 return awt::Point( x
- aOrigin
.X
, y
- aOrigin
.Y
);
81 /*****************************************************************************/
86 component_wrapper_grab_focus (AtkComponent
*component
)
90 accessibility::XAccessibleComponent
* pComponent
= getComponent( component
);
93 pComponent
->grabFocus();
97 catch( const uno::Exception
&e
)
99 g_warning( "Exception in grabFocus()" );
105 /*****************************************************************************/
108 component_wrapper_contains (AtkComponent
*component
,
111 AtkCoordType coord_type
)
115 accessibility::XAccessibleComponent
* pComponent
= getComponent( component
);
117 return pComponent
->containsPoint( translatePoint( pComponent
, x
, y
, coord_type
) );
119 catch( const uno::Exception
&e
)
121 g_warning( "Exception in containsPoint()" );
127 /*****************************************************************************/
130 component_wrapper_ref_accessible_at_point (AtkComponent
*component
,
133 AtkCoordType coord_type
)
137 accessibility::XAccessibleComponent
* pComponent
= getComponent( component
);
141 uno::Reference
< accessibility::XAccessible
> xAccessible
;
142 xAccessible
= pComponent
->getAccessibleAtPoint(
143 translatePoint( pComponent
, x
, y
, coord_type
) );
145 #ifdef ENABLE_TRACING
146 fprintf(stderr
, "getAccessibleAtPoint( %u, %u ) returned %p\n",
147 x
, y
, xAccessible
.get());
149 uno::Reference
< accessibility::XAccessibleComponent
> xComponent(
150 xAccessible
->getAccessibleContext(), uno::UNO_QUERY
);
152 if( xComponent
.is() )
154 awt::Rectangle rect
= xComponent
->getBounds();
155 fprintf(stderr
, "%p->getBounds() returned: ( %u, %u, %u, %u )\n",
156 xAccessible
.get(), rect
.X
, rect
.Y
, rect
.Width
, rect
.Height
);
160 return atk_object_wrapper_ref( xAccessible
);
163 catch( const uno::Exception
&e
)
165 g_warning( "Exception in getAccessibleAtPoint()" );
171 /*****************************************************************************/
174 component_wrapper_get_position (AtkComponent
*component
,
177 AtkCoordType coord_type
)
181 accessibility::XAccessibleComponent
* pComponent
= getComponent( component
);
186 if( coord_type
== ATK_XY_SCREEN
)
187 aPos
= pComponent
->getLocationOnScreen();
189 aPos
= pComponent
->getLocation();
194 #ifdef ENABLE_TRACING
195 fprintf(stderr
, "getLocation[OnScreen]() returned: ( %u, %u )\n", *x
, *y
);
199 catch( const uno::Exception
&e
)
201 g_warning( "Exception in getLocation[OnScreen]()" );
205 /*****************************************************************************/
208 component_wrapper_get_size (AtkComponent
*component
,
214 accessibility::XAccessibleComponent
* pComponent
= getComponent( component
);
217 awt::Size aSize
= pComponent
->getSize();
218 *width
= aSize
.Width
;
219 *height
= aSize
.Height
;
221 #ifdef ENABLE_TRACING
222 fprintf(stderr
, "getSize() returned: ( %u, %u )\n", *width
, *height
);
226 catch( const uno::Exception
&e
)
228 g_warning( "Exception in getSize()" );
232 /*****************************************************************************/
235 component_wrapper_get_extents (AtkComponent
*component
,
240 AtkCoordType coord_type
)
242 component_wrapper_get_position( component
, x
, y
, coord_type
);
243 component_wrapper_get_size( component
, width
, height
);
246 /*****************************************************************************/
249 component_wrapper_set_extents (AtkComponent
*, gint
, gint
, gint
, gint
, AtkCoordType
)
251 g_warning( "AtkComponent::set_extents unimplementable" );
255 /*****************************************************************************/
258 component_wrapper_set_position (AtkComponent
*, gint
, gint
, AtkCoordType
)
260 g_warning( "AtkComponent::set_position unimplementable" );
264 /*****************************************************************************/
267 component_wrapper_set_size (AtkComponent
*, gint
, gint
)
269 g_warning( "AtkComponent::set_size unimplementable" );
273 /*****************************************************************************/
276 component_wrapper_get_layer (AtkComponent
*component
)
278 AtkRole role
= atk_object_get_role( ATK_OBJECT( component
) );
279 AtkLayer layer
= ATK_LAYER_WIDGET
;
283 case ATK_ROLE_POPUP_MENU
:
284 case ATK_ROLE_MENU_ITEM
:
285 case ATK_ROLE_CHECK_MENU_ITEM
:
286 case ATK_ROLE_SEPARATOR
:
287 case ATK_ROLE_LIST_ITEM
:
288 layer
= ATK_LAYER_POPUP
;
292 AtkObject
* parent
= atk_object_get_parent( ATK_OBJECT( component
) );
293 if( atk_object_get_role( parent
) != ATK_ROLE_MENU_BAR
)
294 layer
= ATK_LAYER_POPUP
;
300 AtkObject
* parent
= atk_object_get_parent( ATK_OBJECT( component
) );
301 if( atk_object_get_role( parent
) == ATK_ROLE_COMBO_BOX
)
302 layer
= ATK_LAYER_POPUP
;
313 /*****************************************************************************/
316 component_wrapper_get_mdi_zorder (AtkComponent
*)
318 // only needed for ATK_LAYER_MDI (not used) or ATK_LAYER_WINDOW (inherited from GAIL)
322 /*****************************************************************************/
324 // This code is mostly stolen from libgail ..
327 component_wrapper_add_focus_handler (AtkComponent
*component
,
328 AtkFocusHandler handler
)
330 GSignalMatchType match_type
;
334 match_type
= (GSignalMatchType
) (G_SIGNAL_MATCH_ID
| G_SIGNAL_MATCH_FUNC
);
335 signal_id
= g_signal_lookup( "focus-event", ATK_TYPE_OBJECT
);
337 ret
= g_signal_handler_find( component
, match_type
, signal_id
, 0, NULL
,
338 (gpointer
) &handler
, NULL
);
341 return g_signal_connect_closure_by_id (component
,
344 G_CALLBACK (handler
), NULL
,
345 (GClosureNotify
) NULL
),
354 /*****************************************************************************/
357 component_wrapper_remove_focus_handler (AtkComponent
*component
,
360 g_signal_handler_disconnect (component
, handler_id
);
363 /*****************************************************************************/
368 componentIfaceInit (AtkComponentIface
*iface
)
370 g_return_if_fail (iface
!= NULL
);
372 iface
->add_focus_handler
= component_wrapper_add_focus_handler
;
373 iface
->contains
= component_wrapper_contains
;
374 iface
->get_extents
= component_wrapper_get_extents
;
375 iface
->get_layer
= component_wrapper_get_layer
;
376 iface
->get_mdi_zorder
= component_wrapper_get_mdi_zorder
;
377 iface
->get_position
= component_wrapper_get_position
;
378 iface
->get_size
= component_wrapper_get_size
;
379 iface
->grab_focus
= component_wrapper_grab_focus
;
380 iface
->ref_accessible_at_point
= component_wrapper_ref_accessible_at_point
;
381 iface
->remove_focus_handler
= component_wrapper_remove_focus_handler
;
382 iface
->set_extents
= component_wrapper_set_extents
;
383 iface
->set_position
= component_wrapper_set_position
;
384 iface
->set_size
= component_wrapper_set_size
;