X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-keypad.c;h=edf46ac1edc9f60e843c60946cf5cbc98061429a;hb=4cee6fc1f72440698ca8f3f89a71d29e7ee46a0d;hp=84107c743ab89302d6972a12b6a96c2bf87fa014;hpb=2b998cd1a6d72214726d05cc050b816d131399e6;p=pspp diff --git a/src/ui/gui/psppire-keypad.c b/src/ui/gui/psppire-keypad.c index 84107c743a..edf46ac1ed 100644 --- a/src/ui/gui/psppire-keypad.c +++ b/src/ui/gui/psppire-keypad.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2007, 2010 Free Software Foundation, Inc. + Copyright (C) 2007, 2010, 2011, 2015 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -25,37 +25,9 @@ enum { n_SIGNALS }; -static void psppire_keypad_class_init (PsppireKeypadClass *klass); -static void psppire_keypad_init (PsppireKeypad *kp); - static guint keypad_signals [n_SIGNALS] = { 0 }; -GType -psppire_keypad_get_type (void) -{ - static GType kp_type = 0; - - if (!kp_type) - { - static const GTypeInfo kp_info = - { - sizeof (PsppireKeypadClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) psppire_keypad_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (PsppireKeypad), - 0, - (GInstanceInitFunc) psppire_keypad_init, - }; - - kp_type = g_type_register_static (GTK_TYPE_EVENT_BOX, "PsppireKeypad", - &kp_info, 0); - } - - return kp_type; -} +G_DEFINE_TYPE (PsppireKeypad, psppire_keypad, GTK_TYPE_EVENT_BOX) static GObjectClass * parent_class = NULL; @@ -139,7 +111,7 @@ button_click (GtkButton *b, PsppireKeypad *kp) const gchar *s = g_hash_table_lookup (kp->frag_table, b); - if ( s ) + if (s) g_signal_emit (kp, keypad_signals [INSERT_SYNTAX], 0, s); else g_signal_emit (kp, keypad_signals [ERASE], 0); @@ -159,17 +131,14 @@ add_button (PsppireKeypad *kp, GtkWidget **button, { g_object_set (G_OBJECT (*button), "focus-on-click", FALSE, NULL); - gtk_table_attach_defaults (GTK_TABLE (kp->table), - *button, - x1, x2, - y1, y2); + gtk_grid_attach (GTK_GRID(kp->table), *button, x1, y1, x2 - x1, y2 - y1); gtk_widget_set_size_request (*button, 30 * rows / (float) cols, 30 * cols / (float) rows); g_hash_table_insert (kp->frag_table, *button, - (void *) keypad_insert_text[(button - &kp->digit[0])] ); + (void *) keypad_insert_text[(button - &kp->digit[0])]); g_signal_connect (*button, "clicked", G_CALLBACK (button_click), kp); @@ -206,9 +175,6 @@ enter_leave_notify (GtkWidget *widget, if (event->type == GDK_ENTER_NOTIFY) gtk_widget_grab_focus (widget); - if (event->type == GDK_LEAVE_NOTIFY) - GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS); - return FALSE; } @@ -217,7 +183,7 @@ key_release_callback (GtkWidget *widget, GdkEventKey *event, gpointer user_data) { - if ( ! (GTK_WIDGET_FLAGS (widget) & GTK_HAS_FOCUS) ) + if (! gtk_widget_has_focus (widget)) return FALSE; switch (event->keyval) @@ -234,67 +200,67 @@ key_release_callback (GtkWidget *widget, case '<': g_signal_emit (widget, keypad_signals [INSERT_SYNTAX], 0, "<"); break; - case GDK_KP_Equal : + case GDK_KEY_KP_Equal : case '=': g_signal_emit (widget, keypad_signals [INSERT_SYNTAX], 0, "="); break; - case GDK_KP_Multiply : + case GDK_KEY_KP_Multiply : case '*': g_signal_emit (widget, keypad_signals [INSERT_SYNTAX], 0, "*"); break; - case GDK_KP_Add : + case GDK_KEY_KP_Add : case '+': g_signal_emit (widget, keypad_signals [INSERT_SYNTAX], 0, "+"); break; - case GDK_KP_Subtract : + case GDK_KEY_KP_Subtract : case '-': g_signal_emit (widget, keypad_signals [INSERT_SYNTAX], 0, "-"); break; - case GDK_KP_Decimal : + case GDK_KEY_KP_Decimal : case '.': g_signal_emit (widget, keypad_signals [INSERT_SYNTAX], 0, "."); break; - case GDK_KP_Divide : + case GDK_KEY_KP_Divide : case '/': g_signal_emit (widget, keypad_signals [INSERT_SYNTAX], 0, "/"); break; - case GDK_KP_0 : + case GDK_KEY_KP_0 : case '0': g_signal_emit (widget, keypad_signals [INSERT_SYNTAX], 0, "0"); break; - case GDK_KP_1 : + case GDK_KEY_KP_1 : case '1': g_signal_emit (widget, keypad_signals [INSERT_SYNTAX], 0, "1"); break; - case GDK_KP_2 : + case GDK_KEY_KP_2 : case '2': g_signal_emit (widget, keypad_signals [INSERT_SYNTAX], 0, "2"); break; - case GDK_KP_3 : + case GDK_KEY_KP_3 : case '3': g_signal_emit (widget, keypad_signals [INSERT_SYNTAX], 0, "3"); break; - case GDK_KP_4 : + case GDK_KEY_KP_4 : case '4': g_signal_emit (widget, keypad_signals [INSERT_SYNTAX], 0, "4"); break; - case GDK_KP_5 : + case GDK_KEY_KP_5 : case '5': g_signal_emit (widget, keypad_signals [INSERT_SYNTAX], 0, "5"); break; - case GDK_KP_6 : + case GDK_KEY_KP_6 : case '6': g_signal_emit (widget, keypad_signals [INSERT_SYNTAX], 0, "6"); break; - case GDK_KP_7 : + case GDK_KEY_KP_7 : case '7': g_signal_emit (widget, keypad_signals [INSERT_SYNTAX], 0, "7"); break; - case GDK_KP_8 : + case GDK_KEY_KP_8 : case '8': g_signal_emit (widget, keypad_signals [INSERT_SYNTAX], 0, "8"); break; - case GDK_KP_9 : + case GDK_KEY_KP_9 : case '9': g_signal_emit (widget, keypad_signals [INSERT_SYNTAX], 0, "9"); break; @@ -313,8 +279,7 @@ psppire_keypad_init (PsppireKeypad *kp) const int digit_voffset = 0; const int digit_hoffset = 3; - GTK_WIDGET_SET_FLAGS (kp, GTK_CAN_FOCUS); - GTK_WIDGET_UNSET_FLAGS (kp, GTK_HAS_FOCUS); + gtk_widget_set_can_focus (GTK_WIDGET (kp), TRUE); kp->dispose_has_run = FALSE; @@ -329,7 +294,7 @@ psppire_keypad_init (PsppireKeypad *kp) kp->frag_table = g_hash_table_new (g_direct_hash, g_direct_equal); - kp->table = gtk_table_new (rows, cols, TRUE); + kp->table = gtk_grid_new (); /* Buttons for the digits */ for (i = 0; i < 10; i++) @@ -339,7 +304,7 @@ psppire_keypad_init (PsppireKeypad *kp) g_snprintf (buf, 5, "%d", i); kp->digit[i] = gtk_button_new_with_label (buf); - if ( i == 0 ) + if (i == 0) add_button (kp, &kp->digit[i], digit_hoffset + 0, digit_hoffset + 2, digit_voffset + 3, digit_voffset + 4);