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, see <http://www.gnu.org/licenses/>.
25 " <object class='GtkWindow' id='window1'>"
26 " <property name='visible'>True</property>"
28 " <object class='GtkBox' id='box1'>"
29 " <property name='visible'>True</property>"
31 " <object class='GtkEntry' id='entry1'>"
32 " <property name='visible'>True</property>"
33 " <property name='text'>entry1</property>"
37 " <object class='GtkEntry' id='entry2'>"
38 " <property name='visible'>True</property>"
39 " <property name='text'>entry2</property>"
48 got_active (GObject *win, GParamSpec *pspec, gpointer data)
54 test_focus_change (void)
68 builder = gtk_builder_new ();
70 gtk_builder_add_from_string (builder, data, -1, &error);
71 g_assert_no_error (error);
72 window = (GtkWidget*)gtk_builder_get_object (builder, "window1");
73 entry1 = (GtkWidget*)gtk_builder_get_object (builder, "entry1");
74 entry2 = (GtkWidget*)gtk_builder_get_object (builder, "entry2");
76 wa = gtk_widget_get_accessible (window);
77 ea1 = gtk_widget_get_accessible (entry1);
78 ea2 = gtk_widget_get_accessible (entry2);
81 g_signal_connect (window, "notify::is-active", G_CALLBACK (got_active), NULL);
82 gtk_widget_show (window);
84 g_assert (gtk_window_is_active (GTK_WINDOW (window)));
87 focus = gtk_window_get_focus (GTK_WINDOW (window));
88 g_assert (focus == entry1);
90 set = atk_object_ref_state_set (ea1);
91 ret = atk_state_set_contains_state (set, ATK_STATE_FOCUSED);
94 set = atk_object_ref_state_set (ea2);
95 ret = atk_state_set_contains_state (set, ATK_STATE_FOCUSED);
99 gtk_widget_grab_focus (entry2);
101 focus = gtk_window_get_focus (GTK_WINDOW (window));
102 g_assert (focus == entry2);
104 set = atk_object_ref_state_set (ea1);
105 ret = atk_state_set_contains_state (set, ATK_STATE_FOCUSED);
107 g_object_unref (set);
108 set = atk_object_ref_state_set (ea2);
109 ret = atk_state_set_contains_state (set, ATK_STATE_FOCUSED);
111 g_object_unref (set);
113 g_object_unref (builder);
118 main (int argc, char *argv[])
120 gtk_test_init (&argc, &argv, NULL);
122 g_test_add_func ("/focus/change", test_focus_change);
124 return g_test_run ();