1
/* This file is part of Maliit framework
3
* Copyright (C) 2012 One Laptop per Child Association
5
* Contact: maliit-discuss@lists.maliit.org
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public
9
* License as published by the Free Software Foundation; either
10
* version 2.1 of the licence, 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
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser 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.
24
#include <maliit-glib/maliitattributeextension.h>
26
#include "actionkeyfilter.h"
29
put_widgets_into_container (GtkContainer* window, ...) G_GNUC_NULL_TERMINATED;
32
put_widgets_into_container (GtkContainer* window, ...)
36
va_start (var_args, window);
38
#if GTK_MAJOR_VERSION >= 3
39
GtkGrid *grid = GTK_GRID (gtk_grid_new ());
40
GtkWidget *previous_widget = NULL;
43
GtkWidget *widget = va_arg (var_args, GtkWidget *);
45
if (widget && GTK_IS_WIDGET (widget)) {
46
gtk_grid_attach_next_to (grid, widget, previous_widget, GTK_POS_BOTTOM, 1, 1);
47
previous_widget = widget;
53
gtk_container_add (window, GTK_WIDGET (grid));
55
GtkBox *box = GTK_BOX (gtk_vbox_new (FALSE, 10));
58
GtkWidget *widget = va_arg (var_args, GtkWidget *);
60
if (widget && GTK_IS_WIDGET (widget)) {
61
gtk_box_pack_start (box, widget, FALSE, FALSE, 0);
67
gtk_container_add (window, GTK_WIDGET (box));
74
label_override (GtkToggleButton *button,
78
MaliitAttributeExtension *extension = MALIIT_ATTRIBUTE_EXTENSION (user_data);
79
const gchar* new_label;
82
if (gtk_toggle_button_get_active (button)) {
88
value = g_variant_new_string (new_label);
89
if (g_variant_is_floating (value)) {
90
g_variant_ref_sink (value);
92
maliit_attribute_extension_set_attribute (extension, "/keys/actionKey/label", value);
93
g_variant_unref (value);
97
login_override (GtkToggleButton* button,
100
label_override (button, user_data, "Next");
104
login_change_enter_accepts (GtkToggleButton* button,
107
ActionKeyFilter *filter = (ActionKeyFilter*)user_data;
109
action_key_filter_set_enter_login_accepts (filter,
110
gtk_toggle_button_get_active (button));
114
password_override (GtkToggleButton* button,
117
label_override (button, user_data, "Login");
121
password_change_enter_accepts (GtkToggleButton* button,
124
ActionKeyFilter *filter = (ActionKeyFilter*)user_data;
126
action_key_filter_set_enter_login_accepts (filter,
127
gtk_toggle_button_get_active (button));
131
grab_focus (GtkWidget *widget G_GNUC_UNUSED,
132
GdkEvent *event G_GNUC_UNUSED,
135
GtkWidget *target_widget = GTK_WIDGET (user_data);
137
gtk_widget_grab_focus (target_widget);
142
check_button_realized (GtkWidget *widget,
145
GdkWindow *window = gtk_widget_get_window (widget);
148
GdkEventMask mask = gdk_window_get_events (window);
150
mask |= GDK_FOCUS_CHANGE_MASK;
151
gdk_window_set_events (window, mask);
153
g_signal_connect (widget, "focus-in-event",
154
G_CALLBACK (grab_focus), user_data);
162
MaliitAttributeExtension *login_extension;
163
MaliitAttributeExtension *password_extension;
165
GtkWidget *hide_keyboard_button;
166
GtkWidget *login_label;
168
GtkEntry *login_entry;
169
GtkWidget *login_check_button;
170
GtkWidget *password_label;
172
GtkEntry *password_entry;
173
GtkWidget *password_check_button;
174
GtkWidget *comment_label;
177
ActionKeyFilter *filter;
179
gtk_init (&argc, &argv);
181
login_extension = maliit_attribute_extension_new ();
182
password_extension = maliit_attribute_extension_new ();
184
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
185
gtk_window_set_title (GTK_WINDOW (window), "Maliit GTK+ key override test application");
187
/* Clicking the button will steal focus from the text entry, thus
188
* hiding the virtual keyboard. */
189
hide_keyboard_button = gtk_button_new_with_label("Hide keyboard");
190
login_label = gtk_label_new ("Login:");
191
login = gtk_entry_new();
192
login_entry = GTK_ENTRY (login);
193
login_check_button = gtk_check_button_new_with_label ("Enter accepts login");
194
password_label = gtk_label_new ("Password:");
195
password = gtk_entry_new();
196
password_entry = GTK_ENTRY (password);
197
password_check_button = gtk_check_button_new_with_label ("Enter accepts password");
198
comment_label = gtk_label_new ("Comment (not required):");
199
comment = gtk_entry_new();
200
close = gtk_button_new_with_label ("Close application");
201
filter = action_key_filter_new (login_entry, password_entry);
203
maliit_attribute_extension_attach_to_object (login_extension, G_OBJECT (login));
204
g_signal_connect (login_check_button, "realize",
205
G_CALLBACK (check_button_realized), login);
206
g_signal_connect (login_check_button, "toggled",
207
G_CALLBACK (login_override), login_extension);
208
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (login_check_button),
209
action_key_filter_get_enter_login_accepts (filter));
210
g_signal_connect (login_check_button, "toggled",
211
G_CALLBACK (login_change_enter_accepts), filter);
213
gtk_entry_set_visibility (GTK_ENTRY (password), FALSE);
214
maliit_attribute_extension_attach_to_object (password_extension, G_OBJECT (password));
215
g_signal_connect (password_check_button, "realize",
216
G_CALLBACK (check_button_realized), password);
217
g_signal_connect (password_check_button, "toggled",
218
G_CALLBACK (password_override), password_extension);
219
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (password_check_button),
220
action_key_filter_get_enter_password_accepts (filter));
221
g_signal_connect (password_check_button, "toggled",
222
G_CALLBACK (password_change_enter_accepts), filter);
224
put_widgets_into_container (GTK_CONTAINER (window),
225
hide_keyboard_button,
231
password_check_button,
237
g_signal_connect(window, "delete-event",
238
G_CALLBACK(gtk_main_quit), NULL);
239
g_signal_connect (close, "clicked",
240
G_CALLBACK (gtk_main_quit), NULL);
241
gtk_widget_show_all(window);
245
action_key_filter_free (filter);