2 * Copyright (C) 2011 Red Hat Inc.
5 * Matthias Clasen <mclasen@redhat.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
27 " <object class='GtkWindow' id='window1'>"
28 " <property name='visible'>True</property>"
30 " <object class='GtkBox' id='box1'>"
31 " <property name='visible'>True</property>"
33 " <object class='GtkEntry' id='entry1'>"
34 " <property name='visible'>True</property>"
35 " <property name='text'>entry1</property>"
39 " <object class='GtkEntry' id='entry2'>"
40 " <property name='visible'>True</property>"
41 " <property name='text'>entry2</property>"
50 got_active (GObject *win, GParamSpec *pspec, gpointer data)
56 test_focus_change (void)
70 builder = gtk_builder_new ();
72 gtk_builder_add_from_string (builder, data, -1, &error);
73 g_assert_no_error (error);
74 window = (GtkWidget*)gtk_builder_get_object (builder, "window1");
75 entry1 = (GtkWidget*)gtk_builder_get_object (builder, "entry1");
76 entry2 = (GtkWidget*)gtk_builder_get_object (builder, "entry2");
78 wa = gtk_widget_get_accessible (window);
79 ea1 = gtk_widget_get_accessible (entry1);
80 ea2 = gtk_widget_get_accessible (entry2);
83 g_signal_connect (window, "notify::is-active", G_CALLBACK (got_active), NULL);
84 gtk_widget_show (window);
86 g_assert (gtk_window_is_active (GTK_WINDOW (window)));
89 focus = gtk_window_get_focus (GTK_WINDOW (window));
90 g_assert (focus == entry1);
92 set = atk_object_ref_state_set (ea1);
93 ret = atk_state_set_contains_state (set, ATK_STATE_FOCUSED);
96 set = atk_object_ref_state_set (ea2);
97 ret = atk_state_set_contains_state (set, ATK_STATE_FOCUSED);
101 gtk_widget_grab_focus (entry2);
103 focus = gtk_window_get_focus (GTK_WINDOW (window));
104 g_assert (focus == entry2);
106 set = atk_object_ref_state_set (ea1);
107 ret = atk_state_set_contains_state (set, ATK_STATE_FOCUSED);
109 g_object_unref (set);
110 set = atk_object_ref_state_set (ea2);
111 ret = atk_state_set_contains_state (set, ATK_STATE_FOCUSED);
113 g_object_unref (set);
115 g_object_unref (builder);
120 main (int argc, char *argv[])
122 gtk_test_init (&argc, &argv, NULL);
124 g_test_add_func ("/focus/change", test_focus_change);
126 return g_test_run ();