1*9f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*9f62ea84SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*9f62ea84SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*9f62ea84SAndrew Rist * distributed with this work for additional information
6*9f62ea84SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*9f62ea84SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*9f62ea84SAndrew Rist * "License"); you may not use this file except in compliance
9*9f62ea84SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*9f62ea84SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*9f62ea84SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*9f62ea84SAndrew Rist * software distributed under the License is distributed on an
15*9f62ea84SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9f62ea84SAndrew Rist * KIND, either express or implied. See the License for the
17*9f62ea84SAndrew Rist * specific language governing permissions and limitations
18*9f62ea84SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*9f62ea84SAndrew Rist *************************************************************/
21*9f62ea84SAndrew Rist
22*9f62ea84SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_vcl.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <unx/gtk/gtkframe.hxx>
28cdf0e10cSrcweir #include <vcl/window.hxx>
29cdf0e10cSrcweir #include "vcl/popupmenuwindow.hxx"
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include "atkwindow.hxx"
32cdf0e10cSrcweir #include "atkwrapper.hxx"
33cdf0e10cSrcweir #include "atkregistry.hxx"
34cdf0e10cSrcweir
35cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRole.hpp>
36cdf0e10cSrcweir
37cdf0e10cSrcweir using namespace ::com::sun::star::accessibility;
38cdf0e10cSrcweir using namespace ::com::sun::star::uno;
39cdf0e10cSrcweir
40cdf0e10cSrcweir extern "C" {
41cdf0e10cSrcweir
42cdf0e10cSrcweir static void (* window_real_initialize) (AtkObject *obj, gpointer data) = NULL;
43cdf0e10cSrcweir static void (* window_real_finalize) (GObject *obj) = NULL;
44cdf0e10cSrcweir
45cdf0e10cSrcweir static void
init_from_window(AtkObject * accessible,Window * pWindow)46cdf0e10cSrcweir init_from_window( AtkObject *accessible, Window *pWindow )
47cdf0e10cSrcweir {
48cdf0e10cSrcweir static AtkRole aDefaultRole = ATK_ROLE_INVALID;
49cdf0e10cSrcweir
50cdf0e10cSrcweir // Special role for sub-menu and combo-box popups that are exposed directly
51cdf0e10cSrcweir // by their parents already.
52cdf0e10cSrcweir if( aDefaultRole == ATK_ROLE_INVALID )
53cdf0e10cSrcweir aDefaultRole = atk_role_register( "redundant object" );
54cdf0e10cSrcweir
55cdf0e10cSrcweir AtkRole role = aDefaultRole;
56cdf0e10cSrcweir
57cdf0e10cSrcweir // Determine the appropriate role for the GtkWindow
58cdf0e10cSrcweir switch( pWindow->GetAccessibleRole() )
59cdf0e10cSrcweir {
60cdf0e10cSrcweir case AccessibleRole::ALERT:
61cdf0e10cSrcweir role = ATK_ROLE_ALERT;
62cdf0e10cSrcweir break;
63cdf0e10cSrcweir
64cdf0e10cSrcweir case AccessibleRole::DIALOG:
65cdf0e10cSrcweir role = ATK_ROLE_DIALOG;
66cdf0e10cSrcweir break;
67cdf0e10cSrcweir
68cdf0e10cSrcweir case AccessibleRole::FRAME:
69cdf0e10cSrcweir role = ATK_ROLE_FRAME;
70cdf0e10cSrcweir break;
71cdf0e10cSrcweir
72cdf0e10cSrcweir /* Ignore window objects for sub-menus, combo- and list boxes,
73cdf0e10cSrcweir * which are exposed as children of their parents.
74cdf0e10cSrcweir */
75cdf0e10cSrcweir case AccessibleRole::WINDOW:
76cdf0e10cSrcweir {
77cdf0e10cSrcweir sal_uInt16 type = WINDOW_WINDOW;
78cdf0e10cSrcweir bool parentIsMenuFloatingWindow = false;
79cdf0e10cSrcweir
80cdf0e10cSrcweir Window *pParent = pWindow->GetParent();
81cdf0e10cSrcweir if( pParent ) {
82cdf0e10cSrcweir type = pParent->GetType();
83cdf0e10cSrcweir parentIsMenuFloatingWindow = ( TRUE == pParent->IsMenuFloatingWindow() );
84cdf0e10cSrcweir }
85cdf0e10cSrcweir
86cdf0e10cSrcweir if( (WINDOW_LISTBOX != type) && (WINDOW_COMBOBOX != type) &&
87cdf0e10cSrcweir (WINDOW_MENUBARWINDOW != type) && ! parentIsMenuFloatingWindow )
88cdf0e10cSrcweir {
89cdf0e10cSrcweir role = ATK_ROLE_WINDOW;
90cdf0e10cSrcweir }
91cdf0e10cSrcweir }
92cdf0e10cSrcweir break;
93cdf0e10cSrcweir
94cdf0e10cSrcweir default:
95cdf0e10cSrcweir {
96cdf0e10cSrcweir Window *pChild = pWindow->GetChild( 0 );
97cdf0e10cSrcweir if( pChild )
98cdf0e10cSrcweir {
99cdf0e10cSrcweir if( WINDOW_HELPTEXTWINDOW == pChild->GetType() )
100cdf0e10cSrcweir {
101cdf0e10cSrcweir role = ATK_ROLE_TOOL_TIP;
102cdf0e10cSrcweir pChild->SetAccessibleRole( AccessibleRole::LABEL );
103cdf0e10cSrcweir accessible->name = g_strdup( rtl::OUStringToOString( pChild->GetText(), RTL_TEXTENCODING_UTF8 ).getStr() );
104cdf0e10cSrcweir }
105cdf0e10cSrcweir else if ( pWindow->GetType() == WINDOW_BORDERWINDOW && pChild->GetType() == WINDOW_FLOATINGWINDOW )
106cdf0e10cSrcweir {
107cdf0e10cSrcweir PopupMenuFloatingWindow* p = dynamic_cast<PopupMenuFloatingWindow*>(pChild);
108cdf0e10cSrcweir if (p && p->IsPopupMenu() && p->GetMenuStackLevel() == 0)
109cdf0e10cSrcweir {
110cdf0e10cSrcweir // This is a top-level menu popup. Register it.
111cdf0e10cSrcweir role = ATK_ROLE_POPUP_MENU;
112cdf0e10cSrcweir pChild->SetAccessibleRole( AccessibleRole::POPUP_MENU );
113cdf0e10cSrcweir accessible->name = g_strdup( rtl::OUStringToOString( pChild->GetText(), RTL_TEXTENCODING_UTF8 ).getStr() );
114cdf0e10cSrcweir }
115cdf0e10cSrcweir }
116cdf0e10cSrcweir }
117cdf0e10cSrcweir break;
118cdf0e10cSrcweir }
119cdf0e10cSrcweir }
120cdf0e10cSrcweir
121cdf0e10cSrcweir accessible->role = role;
122cdf0e10cSrcweir }
123cdf0e10cSrcweir
124cdf0e10cSrcweir /*****************************************************************************/
125cdf0e10cSrcweir
126cdf0e10cSrcweir static gint
ooo_window_wrapper_clear_focus(gpointer)127cdf0e10cSrcweir ooo_window_wrapper_clear_focus(gpointer)
128cdf0e10cSrcweir {
129cdf0e10cSrcweir atk_focus_tracker_notify( NULL );
130cdf0e10cSrcweir return FALSE;
131cdf0e10cSrcweir }
132cdf0e10cSrcweir
133cdf0e10cSrcweir /*****************************************************************************/
134cdf0e10cSrcweir
135cdf0e10cSrcweir static gboolean
ooo_window_wrapper_real_focus_gtk(GtkWidget *,GdkEventFocus *)136cdf0e10cSrcweir ooo_window_wrapper_real_focus_gtk (GtkWidget *, GdkEventFocus *)
137cdf0e10cSrcweir {
138cdf0e10cSrcweir g_idle_add( ooo_window_wrapper_clear_focus, NULL );
139cdf0e10cSrcweir return FALSE;
140cdf0e10cSrcweir }
141cdf0e10cSrcweir
ooo_tooltip_map(GtkWidget * pToolTip,gpointer)142cdf0e10cSrcweir static gboolean ooo_tooltip_map( GtkWidget* pToolTip, gpointer )
143cdf0e10cSrcweir {
144cdf0e10cSrcweir AtkObject* pAccessible = gtk_widget_get_accessible( pToolTip );
145cdf0e10cSrcweir if( pAccessible )
146cdf0e10cSrcweir atk_object_notify_state_change( pAccessible, ATK_STATE_SHOWING, TRUE );
147cdf0e10cSrcweir return FALSE;
148cdf0e10cSrcweir }
149cdf0e10cSrcweir
ooo_tooltip_unmap(GtkWidget * pToolTip,gpointer)150cdf0e10cSrcweir static gboolean ooo_tooltip_unmap( GtkWidget* pToolTip, gpointer )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir AtkObject* pAccessible = gtk_widget_get_accessible( pToolTip );
153cdf0e10cSrcweir if( pAccessible )
154cdf0e10cSrcweir atk_object_notify_state_change( pAccessible, ATK_STATE_SHOWING, FALSE );
155cdf0e10cSrcweir return FALSE;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir
158cdf0e10cSrcweir /*****************************************************************************/
159cdf0e10cSrcweir
160cdf0e10cSrcweir static bool
isChildPopupMenu(Window * pWindow)161cdf0e10cSrcweir isChildPopupMenu(Window* pWindow)
162cdf0e10cSrcweir {
163cdf0e10cSrcweir Window* pChild = pWindow->GetAccessibleChildWindow(0);
164cdf0e10cSrcweir if (!pChild)
165cdf0e10cSrcweir return false;
166cdf0e10cSrcweir
167cdf0e10cSrcweir if (WINDOW_FLOATINGWINDOW != pChild->GetType())
168cdf0e10cSrcweir return false;
169cdf0e10cSrcweir
170cdf0e10cSrcweir PopupMenuFloatingWindow* p = dynamic_cast<PopupMenuFloatingWindow*>(pChild);
171cdf0e10cSrcweir if (!p)
172cdf0e10cSrcweir return false;
173cdf0e10cSrcweir
174cdf0e10cSrcweir return p->IsPopupMenu();
175cdf0e10cSrcweir }
176cdf0e10cSrcweir
177cdf0e10cSrcweir static void
ooo_window_wrapper_real_initialize(AtkObject * obj,gpointer data)178cdf0e10cSrcweir ooo_window_wrapper_real_initialize(AtkObject *obj, gpointer data)
179cdf0e10cSrcweir {
180cdf0e10cSrcweir window_real_initialize(obj, data);
181cdf0e10cSrcweir
182cdf0e10cSrcweir GtkSalFrame *pFrame = GtkSalFrame::getFromWindow( GTK_WINDOW( data ) );
183cdf0e10cSrcweir if( pFrame )
184cdf0e10cSrcweir {
185cdf0e10cSrcweir Window *pWindow = pFrame->GetWindow();
186cdf0e10cSrcweir if( pWindow )
187cdf0e10cSrcweir {
188cdf0e10cSrcweir init_from_window( obj, pWindow );
189cdf0e10cSrcweir
190cdf0e10cSrcweir Reference< XAccessible > xAccessible( pWindow->GetAccessible(true) );
191cdf0e10cSrcweir
192cdf0e10cSrcweir /* We need the wrapper object for the top-level XAccessible to be
193cdf0e10cSrcweir * in the wrapper registry when atk traverses the hierachy up on
194cdf0e10cSrcweir * focus events
195cdf0e10cSrcweir */
196cdf0e10cSrcweir if( WINDOW_BORDERWINDOW == pWindow->GetType() )
197cdf0e10cSrcweir {
198cdf0e10cSrcweir if ( isChildPopupMenu(pWindow) )
199cdf0e10cSrcweir {
200cdf0e10cSrcweir AtkObject *child = atk_object_wrapper_new( xAccessible, obj );
201cdf0e10cSrcweir ooo_wrapper_registry_add( xAccessible, child );
202cdf0e10cSrcweir }
203cdf0e10cSrcweir else
204cdf0e10cSrcweir {
205cdf0e10cSrcweir ooo_wrapper_registry_add( xAccessible, obj );
206cdf0e10cSrcweir g_object_set_data( G_OBJECT(obj), "ooo:atk-wrapper-key", xAccessible.get() );
207cdf0e10cSrcweir }
208cdf0e10cSrcweir }
209cdf0e10cSrcweir else
210cdf0e10cSrcweir {
211cdf0e10cSrcweir AtkObject *child = atk_object_wrapper_new( xAccessible, obj );
212cdf0e10cSrcweir child->role = ATK_ROLE_FILLER;
213cdf0e10cSrcweir if( (ATK_ROLE_DIALOG == obj->role) || (ATK_ROLE_ALERT == obj->role) )
214cdf0e10cSrcweir child->role = ATK_ROLE_OPTION_PANE;
215cdf0e10cSrcweir ooo_wrapper_registry_add( xAccessible, child );
216cdf0e10cSrcweir }
217cdf0e10cSrcweir }
218cdf0e10cSrcweir }
219cdf0e10cSrcweir
220cdf0e10cSrcweir g_signal_connect_after( GTK_WIDGET( data ), "focus-out-event",
221cdf0e10cSrcweir G_CALLBACK (ooo_window_wrapper_real_focus_gtk),
222cdf0e10cSrcweir NULL);
223cdf0e10cSrcweir
224cdf0e10cSrcweir if( obj->role == ATK_ROLE_TOOL_TIP )
225cdf0e10cSrcweir {
226cdf0e10cSrcweir g_signal_connect_after( GTK_WIDGET( data ), "map-event",
227cdf0e10cSrcweir G_CALLBACK (ooo_tooltip_map),
228cdf0e10cSrcweir NULL);
229cdf0e10cSrcweir g_signal_connect_after( GTK_WIDGET( data ), "unmap-event",
230cdf0e10cSrcweir G_CALLBACK (ooo_tooltip_unmap),
231cdf0e10cSrcweir NULL);
232cdf0e10cSrcweir }
233cdf0e10cSrcweir }
234cdf0e10cSrcweir
235cdf0e10cSrcweir /*****************************************************************************/
236cdf0e10cSrcweir
237cdf0e10cSrcweir static void
ooo_window_wrapper_real_finalize(GObject * obj)238cdf0e10cSrcweir ooo_window_wrapper_real_finalize (GObject *obj)
239cdf0e10cSrcweir {
240cdf0e10cSrcweir ooo_wrapper_registry_remove( (XAccessible *) g_object_get_data( obj, "ooo:atk-wrapper-key" ));
241cdf0e10cSrcweir window_real_finalize( obj );
242cdf0e10cSrcweir }
243cdf0e10cSrcweir
244cdf0e10cSrcweir /*****************************************************************************/
245cdf0e10cSrcweir
246cdf0e10cSrcweir static void
ooo_window_wrapper_class_init(AtkObjectClass * klass,gpointer)247cdf0e10cSrcweir ooo_window_wrapper_class_init (AtkObjectClass *klass, gpointer)
248cdf0e10cSrcweir {
249cdf0e10cSrcweir AtkObjectClass *atk_class;
250cdf0e10cSrcweir GObjectClass *gobject_class;
251cdf0e10cSrcweir gpointer data;
252cdf0e10cSrcweir
253cdf0e10cSrcweir /*
254cdf0e10cSrcweir * Patch the gobject vtable of GailWindow to refer to our instance of
255cdf0e10cSrcweir * "initialize".
256cdf0e10cSrcweir */
257cdf0e10cSrcweir
258cdf0e10cSrcweir data = g_type_class_peek_parent( klass );
259cdf0e10cSrcweir atk_class = ATK_OBJECT_CLASS (data);
260cdf0e10cSrcweir
261cdf0e10cSrcweir window_real_initialize = atk_class->initialize;
262cdf0e10cSrcweir atk_class->initialize = ooo_window_wrapper_real_initialize;
263cdf0e10cSrcweir
264cdf0e10cSrcweir gobject_class = G_OBJECT_CLASS (data);
265cdf0e10cSrcweir
266cdf0e10cSrcweir window_real_finalize = gobject_class->finalize;
267cdf0e10cSrcweir gobject_class->finalize = ooo_window_wrapper_real_finalize;
268cdf0e10cSrcweir }
269cdf0e10cSrcweir
270cdf0e10cSrcweir } // extern "C"
271cdf0e10cSrcweir
272cdf0e10cSrcweir /*****************************************************************************/
273cdf0e10cSrcweir
274cdf0e10cSrcweir GType
ooo_window_wrapper_get_type(void)275cdf0e10cSrcweir ooo_window_wrapper_get_type (void)
276cdf0e10cSrcweir {
277cdf0e10cSrcweir static GType type = 0;
278cdf0e10cSrcweir
279cdf0e10cSrcweir if (!type)
280cdf0e10cSrcweir {
281cdf0e10cSrcweir GType parent_type = g_type_from_name( "GailWindow" );
282cdf0e10cSrcweir
283cdf0e10cSrcweir if( ! parent_type )
284cdf0e10cSrcweir {
285cdf0e10cSrcweir g_warning( "Unknown type: GailWindow" );
286cdf0e10cSrcweir parent_type = ATK_TYPE_OBJECT;
287cdf0e10cSrcweir }
288cdf0e10cSrcweir
289cdf0e10cSrcweir GTypeQuery type_query;
290cdf0e10cSrcweir g_type_query( parent_type, &type_query );
291cdf0e10cSrcweir
292cdf0e10cSrcweir static const GTypeInfo typeInfo =
293cdf0e10cSrcweir {
294cdf0e10cSrcweir type_query.class_size,
295cdf0e10cSrcweir (GBaseInitFunc) NULL,
296cdf0e10cSrcweir (GBaseFinalizeFunc) NULL,
297cdf0e10cSrcweir (GClassInitFunc) ooo_window_wrapper_class_init,
298cdf0e10cSrcweir (GClassFinalizeFunc) NULL,
299cdf0e10cSrcweir NULL,
300cdf0e10cSrcweir type_query.instance_size,
301cdf0e10cSrcweir 0,
302cdf0e10cSrcweir (GInstanceInitFunc) NULL,
303cdf0e10cSrcweir NULL
304cdf0e10cSrcweir } ;
305cdf0e10cSrcweir
306cdf0e10cSrcweir type = g_type_register_static (parent_type, "OOoWindowAtkObject", &typeInfo, (GTypeFlags)0) ;
307cdf0e10cSrcweir }
308cdf0e10cSrcweir
309cdf0e10cSrcweir return type;
310cdf0e10cSrcweir }
311cdf0e10cSrcweir
restore_gail_window_vtable(void)312cdf0e10cSrcweir void restore_gail_window_vtable (void)
313cdf0e10cSrcweir {
314cdf0e10cSrcweir AtkObjectClass *atk_class;
315cdf0e10cSrcweir gpointer data;
316cdf0e10cSrcweir
317cdf0e10cSrcweir GType type = g_type_from_name( "GailWindow" );
318cdf0e10cSrcweir
319cdf0e10cSrcweir if( type == G_TYPE_INVALID )
320cdf0e10cSrcweir return;
321cdf0e10cSrcweir
322cdf0e10cSrcweir data = g_type_class_peek( type );
323cdf0e10cSrcweir atk_class = ATK_OBJECT_CLASS (data);
324cdf0e10cSrcweir
325cdf0e10cSrcweir atk_class->initialize = window_real_initialize;
326cdf0e10cSrcweir }
327cdf0e10cSrcweir
328