merge the formfield patch from ooo-build
[ooovba.git] / vcl / unx / gtk / a11y / atkcomponent.cxx
blob80e076f0fb86543f49a93310d4c4f9a23bad8b0b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: atkcomponent.cxx,v $
10 * $Revision: 1.4 $
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>
38 #ifdef ENABLE_TRACING
39 #include <stdio.h>
40 #endif
42 using namespace ::com::sun::star;
44 static accessibility::XAccessibleComponent*
45 getComponent( AtkComponent *pComponent ) throw (uno::RuntimeException)
47 AtkObjectWrapper *pWrap = ATK_OBJECT_WRAPPER( pComponent );
48 if( pWrap )
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;
60 return NULL;
63 /*****************************************************************************/
65 static awt::Point
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();
73 #ifdef ENABLE_TRACING
74 fprintf(stderr, "coordinates ( %u, %u ) translated to: ( %u, %u )\n",
75 x, y, x - aOrigin.X, y - aOrigin.Y);
76 #endif
78 return awt::Point( x - aOrigin.X, y - aOrigin.Y );
81 /*****************************************************************************/
83 extern "C" {
85 static gboolean
86 component_wrapper_grab_focus (AtkComponent *component)
88 try
90 accessibility::XAccessibleComponent* pComponent = getComponent( component );
91 if( pComponent )
93 pComponent->grabFocus();
94 return TRUE;
97 catch( const uno::Exception &e )
99 g_warning( "Exception in grabFocus()" );
102 return FALSE;
105 /*****************************************************************************/
107 static gboolean
108 component_wrapper_contains (AtkComponent *component,
109 gint x,
110 gint y,
111 AtkCoordType coord_type)
115 accessibility::XAccessibleComponent* pComponent = getComponent( component );
116 if( pComponent )
117 return pComponent->containsPoint( translatePoint( pComponent, x, y, coord_type ) );
119 catch( const uno::Exception &e )
121 g_warning( "Exception in containsPoint()" );
124 return FALSE;
127 /*****************************************************************************/
129 static AtkObject *
130 component_wrapper_ref_accessible_at_point (AtkComponent *component,
131 gint x,
132 gint y,
133 AtkCoordType coord_type)
137 accessibility::XAccessibleComponent* pComponent = getComponent( component );
139 if( pComponent )
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 );
158 #endif
160 return atk_object_wrapper_ref( xAccessible );
163 catch( const uno::Exception &e )
165 g_warning( "Exception in getAccessibleAtPoint()" );
168 return NULL;
171 /*****************************************************************************/
173 static void
174 component_wrapper_get_position (AtkComponent *component,
175 gint *x,
176 gint *y,
177 AtkCoordType coord_type)
181 accessibility::XAccessibleComponent* pComponent = getComponent( component );
182 if( pComponent )
184 awt::Point aPos;
186 if( coord_type == ATK_XY_SCREEN )
187 aPos = pComponent->getLocationOnScreen();
188 else
189 aPos = pComponent->getLocation();
191 *x = aPos.X;
192 *y = aPos.Y;
194 #ifdef ENABLE_TRACING
195 fprintf(stderr, "getLocation[OnScreen]() returned: ( %u, %u )\n", *x, *y );
196 #endif
199 catch( const uno::Exception &e )
201 g_warning( "Exception in getLocation[OnScreen]()" );
205 /*****************************************************************************/
207 static void
208 component_wrapper_get_size (AtkComponent *component,
209 gint *width,
210 gint *height)
214 accessibility::XAccessibleComponent* pComponent = getComponent( component );
215 if( pComponent )
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 );
223 #endif
226 catch( const uno::Exception &e )
228 g_warning( "Exception in getSize()" );
232 /*****************************************************************************/
234 static void
235 component_wrapper_get_extents (AtkComponent *component,
236 gint *x,
237 gint *y,
238 gint *width,
239 gint *height,
240 AtkCoordType coord_type)
242 component_wrapper_get_position( component, x, y, coord_type );
243 component_wrapper_get_size( component, width, height );
246 /*****************************************************************************/
248 static gboolean
249 component_wrapper_set_extents (AtkComponent *, gint, gint, gint, gint, AtkCoordType)
251 g_warning( "AtkComponent::set_extents unimplementable" );
252 return FALSE;
255 /*****************************************************************************/
257 static gboolean
258 component_wrapper_set_position (AtkComponent *, gint, gint, AtkCoordType)
260 g_warning( "AtkComponent::set_position unimplementable" );
261 return FALSE;
264 /*****************************************************************************/
266 static gboolean
267 component_wrapper_set_size (AtkComponent *, gint, gint)
269 g_warning( "AtkComponent::set_size unimplementable" );
270 return FALSE;
273 /*****************************************************************************/
275 static AtkLayer
276 component_wrapper_get_layer (AtkComponent *component)
278 AtkRole role = atk_object_get_role( ATK_OBJECT( component ) );
279 AtkLayer layer = ATK_LAYER_WIDGET;
281 switch (role)
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;
289 break;
290 case ATK_ROLE_MENU:
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;
296 break;
298 case ATK_ROLE_LIST:
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;
304 break;
306 default:
310 return layer;
313 /*****************************************************************************/
315 static gint
316 component_wrapper_get_mdi_zorder (AtkComponent *)
318 // only needed for ATK_LAYER_MDI (not used) or ATK_LAYER_WINDOW (inherited from GAIL)
319 return G_MININT;
322 /*****************************************************************************/
324 // This code is mostly stolen from libgail ..
326 static guint
327 component_wrapper_add_focus_handler (AtkComponent *component,
328 AtkFocusHandler handler)
330 GSignalMatchType match_type;
331 gulong ret;
332 guint signal_id;
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);
339 if (!ret)
341 return g_signal_connect_closure_by_id (component,
342 signal_id, 0,
343 g_cclosure_new (
344 G_CALLBACK (handler), NULL,
345 (GClosureNotify) NULL),
346 FALSE);
348 else
350 return 0;
354 /*****************************************************************************/
356 static void
357 component_wrapper_remove_focus_handler (AtkComponent *component,
358 guint handler_id)
360 g_signal_handler_disconnect (component, handler_id);
363 /*****************************************************************************/
365 } // extern "C"
367 void
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;