From 2fbfb300e1200847986e5c669aa8322fe96683e7 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Fri, 14 Nov 2008 14:41:17 +0900 Subject: [PATCH] Delete gtkextra.c Use the standard g_signal_emit instead of the one from gtkextra. Sort out confusion over the "veto" variable. --- lib/gtksheet/automake.mk | 1 - lib/gtksheet/gtkextra.c | 137 ----------------------- lib/gtksheet/gtksheet.c | 196 +++++++++++++-------------------- lib/gtksheet/gtksheet.h | 17 --- src/ui/gui/psppire-var-sheet.c | 15 ++- 5 files changed, 84 insertions(+), 282 deletions(-) delete mode 100644 lib/gtksheet/gtkextra.c diff --git a/lib/gtksheet/automake.mk b/lib/gtksheet/automake.mk index c5a32962..d6bb3cdc 100644 --- a/lib/gtksheet/automake.mk +++ b/lib/gtksheet/automake.mk @@ -18,7 +18,6 @@ lib_gtksheet_libgtksheet_a_SOURCES = \ lib/gtksheet/gsheet-uniform-column.h \ lib/gtksheet/gsheet-uniform-row.c \ lib/gtksheet/gsheet-uniform-row.h \ - lib/gtksheet/gtkextra.c \ lib/gtksheet/gtkextrafeatures.h \ lib/gtksheet/gtkextra-marshal.c \ lib/gtksheet/gtkextra-marshal.h \ diff --git a/lib/gtksheet/gtkextra.c b/lib/gtksheet/gtkextra.c deleted file mode 100644 index 4d792685..00000000 --- a/lib/gtksheet/gtkextra.c +++ /dev/null @@ -1,137 +0,0 @@ -/* gtkextra - * Copyright 1999-2001 Adrian E. Feiguin - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include - -#include -#include -#include "gtkextrafeatures.h" -#include - -const guint gtkextra_major_version = GTKEXTRA_MAJOR_VERSION; -const guint gtkextra_minor_version = GTKEXTRA_MINOR_VERSION; -const guint gtkextra_micro_version = GTKEXTRA_MICRO_VERSION; -const guint gtkextra_binary_age = GTKEXTRA_BINARY_AGE; -const guint gtkextra_interface_age = GTKEXTRA_INTERFACE_AGE; - -gchar * -gtkextra_check_version (guint required_major, - guint required_minor, - guint required_micro) -{ - if (required_major > GTKEXTRA_MAJOR_VERSION) - return "GtkExtra version too old (major mismatch)"; - if (required_major < GTKEXTRA_MAJOR_VERSION) - return "GtkExtra version too new (major mismatch)"; - if (required_minor > GTKEXTRA_MINOR_VERSION) - return "GtkExtra version too old (minor mismatch)"; - if (required_minor < GTKEXTRA_MINOR_VERSION) - return "GtkExtra version too new (minor mismatch)"; - if (required_micro < GTKEXTRA_MICRO_VERSION - GTKEXTRA_BINARY_AGE) - return "GtkExtra version too new (micro mismatch)"; - if (required_micro > GTKEXTRA_MICRO_VERSION) - return "GtkExtra version too old (micro mismatch)"; - return NULL; -} - -/* -void -_gtkextra_signal_test(GtkObject *object, guint signal_id, gint arg1, gint arg2, gboolean *default_ret) -{ - gboolean result; - GValue ret = { 0, }; - GValue instance_and_param[3] = { { 0, }, {0, }, {0, } }; - - g_value_init(instance_and_param + 0, GTK_OBJECT_TYPE(object)); - g_value_set_instance(instance_and_param + 0, G_OBJECT(object)); - - g_value_init(instance_and_param + 1, G_TYPE_INT); - g_value_set_int(instance_and_param + 1, arg1); - - g_value_init(instance_and_param + 2, G_TYPE_INT); - g_value_set_int(instance_and_param + 2, arg2); - - g_value_init(&ret, G_TYPE_BOOLEAN); - g_value_set_boolean(&ret, *default_ret); - - g_signal_emitv(instance_and_param, signal_id, 0, &ret); - *default_ret = g_value_get_boolean(&ret); - - g_value_unset(instance_and_param + 0); - g_value_unset(instance_and_param + 1); - g_value_unset(instance_and_param + 2); -} -*/ - -void -_gtkextra_signal_emit(GtkObject *object, guint signal_id, ...) -{ - gboolean *result; - GValue ret = { 0, }; - GValue instance_and_params [10] = { {0, }, }; - va_list var_args; - GSignalQuery query; - gchar *error; - int i; - - va_start (var_args, signal_id); - - g_value_init(instance_and_params + 0, GTK_OBJECT_TYPE(object)); - g_value_set_instance (instance_and_params + 0, G_OBJECT(object)); - - g_signal_query(signal_id, &query); - - for (i = 0; i < query.n_params; i++) - { - gboolean static_scope = query.param_types[i]&~G_SIGNAL_TYPE_STATIC_SCOPE; - g_value_init(instance_and_params + i + 1, query.param_types[i]); - - - G_VALUE_COLLECT (instance_and_params + i + 1, - var_args, - static_scope ? G_VALUE_NOCOPY_CONTENTS : 0, - &error); - - if (error) - { - g_warning ("%s: %s", G_STRLOC, error); - g_free (error); - while (i-- > 0) - g_value_unset (instance_and_params + i); - - va_end (var_args); - return; - } - - - } - - g_value_init(&ret, query.return_type); - result = va_arg(var_args,gboolean *); - g_value_set_boolean(&ret, *result); - g_signal_emitv(instance_and_params, signal_id, 0, &ret); - *result = g_value_get_boolean(&ret); - g_value_unset (&ret); - - for (i = 0; i < query.n_params; i++) - g_value_unset (instance_and_params + 1 + i); - g_value_unset (instance_and_params + 0); - - va_end (var_args); -} diff --git a/lib/gtksheet/gtksheet.c b/lib/gtksheet/gtksheet.c index c3d1807c..f7cf7822 100644 --- a/lib/gtksheet/gtksheet.c +++ b/lib/gtksheet/gtksheet.c @@ -499,13 +499,11 @@ static gboolean gtk_sheet_activate_cell (GtkSheet *sheet, gint row, gint col); static void gtk_sheet_draw_active_cell (GtkSheet *sheet); static void gtk_sheet_show_active_cell (GtkSheet *sheet); -static void gtk_sheet_click_cell (GtkSheet *sheet, +static gboolean gtk_sheet_click_cell (GtkSheet *sheet, gint row, - gint column, - gboolean *veto); + gint column); /* Backing Pixmap */ - static void gtk_sheet_make_backing_pixmap (GtkSheet *sheet); static void gtk_sheet_draw_backing_pixmap (GtkSheet *sheet, @@ -576,10 +574,6 @@ static void gtk_sheet_row_size_request (GtkSheet *sheet, /* Signals */ - -extern void -_gtkextra_signal_emit (GtkObject *object, guint signal_id, ...); - enum { SELECT_ROW, @@ -1114,8 +1108,6 @@ gtk_sheet_init (GtkSheet *sheet) sheet->row_title_area.width = DEFAULT_COLUMN_WIDTH; sheet->column_titles_visible = TRUE; - sheet->autoscroll = TRUE; - sheet->justify_entry = TRUE; /* create sheet entry */ @@ -1481,43 +1473,6 @@ gtk_sheet_autoresize_column (GtkSheet *sheet, gint column) } -void -gtk_sheet_set_autoscroll (GtkSheet *sheet, gboolean autoscroll) -{ - g_return_if_fail (sheet != NULL); - g_return_if_fail (GTK_IS_SHEET (sheet)); - - sheet->autoscroll = autoscroll; -} - -gboolean -gtk_sheet_autoscroll (GtkSheet *sheet) -{ - g_return_val_if_fail (sheet != NULL, FALSE); - g_return_val_if_fail (GTK_IS_SHEET (sheet), FALSE); - - return sheet->autoscroll; -} - - -void -gtk_sheet_set_justify_entry (GtkSheet *sheet, gboolean justify) -{ - g_return_if_fail (sheet != NULL); - g_return_if_fail (GTK_IS_SHEET (sheet)); - - sheet->justify_entry = justify; -} - -gboolean -gtk_sheet_justify_entry (GtkSheet *sheet) -{ - g_return_val_if_fail (sheet != NULL, FALSE); - g_return_val_if_fail (GTK_IS_SHEET (sheet), FALSE); - - return sheet->justify_entry; -} - void gtk_sheet_set_row_titles_width (GtkSheet *sheet, guint width) @@ -2210,9 +2165,7 @@ size_allocate_global_button (GtkSheet *sheet) static void global_button_clicked (GtkWidget *widget, gpointer data) { - gboolean veto; - - gtk_sheet_click_cell (GTK_SHEET (data), - 1, - 1, &veto); + gtk_sheet_click_cell (GTK_SHEET (data), -1, -1); gtk_widget_grab_focus (GTK_WIDGET (data)); } @@ -3050,8 +3003,6 @@ gtk_sheet_set_active_cell (GtkSheet *sheet, gint row, gint column) if (!gtk_sheet_activate_cell (sheet, row, column)) return FALSE; - if (gtk_sheet_autoscroll (sheet)) - gtk_sheet_move_query (sheet, row, column); return TRUE; } @@ -3208,7 +3159,7 @@ gtk_sheet_activate_cell (GtkSheet *sheet, gint row, gint col) G_CALLBACK (gtk_sheet_entry_changed), sheet); - _gtkextra_signal_emit (GTK_OBJECT (sheet), sheet_signals [ACTIVATE], row, col, &veto); + g_signal_emit (sheet, sheet_signals [ACTIVATE], 0, row, col, &veto); return TRUE; } @@ -3245,8 +3196,6 @@ gtk_sheet_show_active_cell (GtkSheet *sheet) justification = GTK_JUSTIFY_LEFT; - if (gtk_sheet_justify_entry (sheet)) - justification = attributes.justification; text = gtk_sheet_cell_get_text (sheet, row, col); if ( ! text ) @@ -4027,7 +3976,7 @@ gtk_sheet_button_press (GtkWidget * widget, } else { - gtk_sheet_click_cell (sheet, row, column, &veto); + veto = gtk_sheet_click_cell (sheet, row, column); if (veto) GTK_SHEET_SET_FLAGS (sheet, GTK_SHEET_IN_SELECTION); } } @@ -4044,7 +3993,7 @@ gtk_sheet_button_press (GtkWidget * widget, if (g_sheet_column_get_sensitivity (sheet->column_geometry, column)) { - gtk_sheet_click_cell (sheet, - 1, column, &veto); + veto = gtk_sheet_click_cell (sheet, -1, column); gtk_grab_add (GTK_WIDGET (sheet)); gtk_widget_grab_focus (GTK_WIDGET (sheet)); GTK_SHEET_SET_FLAGS (sheet, GTK_SHEET_IN_SELECTION); @@ -4062,7 +4011,7 @@ gtk_sheet_button_press (GtkWidget * widget, row = yyy_row_ypixel_to_row (sheet, y); if (g_sheet_row_get_sensitivity (sheet->row_geometry, row)) { - gtk_sheet_click_cell (sheet, row, - 1, &veto); + veto = gtk_sheet_click_cell (sheet, row, -1); gtk_grab_add (GTK_WIDGET (sheet)); gtk_widget_grab_focus (GTK_WIDGET (sheet)); GTK_SHEET_SET_FLAGS (sheet, GTK_SHEET_IN_SELECTION); @@ -4072,15 +4021,15 @@ gtk_sheet_button_press (GtkWidget * widget, return TRUE; } -static void -gtk_sheet_click_cell (GtkSheet *sheet, gint row, gint column, gboolean *veto) +static gboolean +gtk_sheet_click_cell (GtkSheet *sheet, gint row, gint column) { - *veto = TRUE; + gboolean forbid_move; - if (row >= g_sheet_row_get_row_count (sheet->row_geometry) || column >= g_sheet_column_get_column_count (sheet->column_geometry)) + if (row >= g_sheet_row_get_row_count (sheet->row_geometry) + || column >= g_sheet_column_get_column_count (sheet->column_geometry)) { - *veto = FALSE; - return; + return FALSE; } if (column >= 0 && row >= 0) @@ -4088,39 +4037,36 @@ gtk_sheet_click_cell (GtkSheet *sheet, gint row, gint column, gboolean *veto) if (! g_sheet_column_get_visibility (sheet->column_geometry, column) || !g_sheet_row_get_visibility (sheet->row_geometry, row)) { - *veto = FALSE; - return; + return FALSE; } } - _gtkextra_signal_emit (GTK_OBJECT (sheet), sheet_signals[TRAVERSE], - sheet->active_cell.row, sheet->active_cell.col, - &row, &column, veto); + g_signal_emit (sheet, sheet_signals[TRAVERSE], 0, + sheet->active_cell.row, sheet->active_cell.col, + &row, &column, &forbid_move); - if (!*veto) + if (forbid_move) { - if (sheet->state == GTK_STATE_NORMAL) return; + if (sheet->state == GTK_STATE_NORMAL) + return FALSE; row = sheet->active_cell.row; column = sheet->active_cell.col; gtk_sheet_activate_cell (sheet, row, column); - return; + return FALSE; } if (row == -1 && column >= 0) { - if (gtk_sheet_autoscroll (sheet)) - gtk_sheet_move_query (sheet, row, column); gtk_sheet_select_column (sheet, column); - return; + return TRUE; } + if (column == -1 && row >= 0) { - if (gtk_sheet_autoscroll (sheet)) - gtk_sheet_move_query (sheet, row, column); gtk_sheet_select_row (sheet, row); - return; + return TRUE; } if (row == - 1 && column == - 1) @@ -4128,11 +4074,12 @@ gtk_sheet_click_cell (GtkSheet *sheet, gint row, gint column, gboolean *veto) sheet->range.row0 = 0; sheet->range.col0 = 0; sheet->range.rowi = g_sheet_row_get_row_count (sheet->row_geometry) - 1; - sheet->range.coli = g_sheet_column_get_column_count (sheet->column_geometry) - 1; + sheet->range.coli = + g_sheet_column_get_column_count (sheet->column_geometry) - 1; sheet->active_cell.row = 0; sheet->active_cell.col = 0; gtk_sheet_select_range (sheet, NULL); - return; + return TRUE; } if (row != -1 && column != -1) @@ -4148,8 +4095,6 @@ gtk_sheet_click_cell (GtkSheet *sheet, gint row, gint column, gboolean *veto) gtk_sheet_activate_cell (sheet, row, column); } - if (gtk_sheet_autoscroll (sheet)) - gtk_sheet_move_query (sheet, row, column); sheet->active_cell.row = row; sheet->active_cell.col = column; sheet->selection_cell.row = row; @@ -4161,12 +4106,10 @@ gtk_sheet_click_cell (GtkSheet *sheet, gint row, gint column, gboolean *veto) sheet->state = GTK_SHEET_NORMAL; GTK_SHEET_SET_FLAGS (sheet, GTK_SHEET_IN_SELECTION); gtk_sheet_draw_active_cell (sheet); - return; + return TRUE; } g_assert_not_reached (); - gtk_sheet_activate_cell (sheet, sheet->active_cell.row, - sheet->active_cell.col); } static gint @@ -4904,6 +4847,50 @@ page_vertical (GtkSheet *sheet, GtkScrollType dir) } +static void +step_horizontal (GtkSheet *sheet, GtkScrollType dir) +{ + switch ( dir) + { + case GTK_SCROLL_STEP_RIGHT: + + gtk_sheet_activate_cell (sheet, + sheet->active_cell.row, + sheet->active_cell.col + 1); + break; + case GTK_SCROLL_STEP_LEFT: + + gtk_sheet_activate_cell (sheet, + sheet->active_cell.row, + sheet->active_cell.col - 1); + break; + + default: + g_assert_not_reached (); + break; + } + + if ( sheet->active_cell.col >= max_visible_column (sheet)) + { + glong hpos = + g_sheet_column_start_pixel (sheet->column_geometry, + sheet->active_cell.col + 1); + hpos -= sheet->hadjustment->page_size; + + gtk_adjustment_set_value (sheet->hadjustment, + hpos); + } + else if ( sheet->active_cell.col <= min_visible_column (sheet)) + { + glong hpos = + g_sheet_column_start_pixel (sheet->column_geometry, + sheet->active_cell.col); + + gtk_adjustment_set_value (sheet->hadjustment, + hpos); + } +} + static gboolean gtk_sheet_key_press (GtkWidget *widget, GdkEventKey *key) @@ -4914,39 +4901,16 @@ gtk_sheet_key_press (GtkWidget *widget, switch (key->keyval) { + case GDK_Tab: case GDK_Right: - gtk_sheet_activate_cell (sheet, - sheet->active_cell.row, - sheet->active_cell.col + 1); - - if ( sheet->active_cell.col >= max_visible_column (sheet)) - { - glong hpos = - g_sheet_column_start_pixel (sheet->column_geometry, - sheet->active_cell.col + 1); - hpos -= sheet->hadjustment->page_size; - - gtk_adjustment_set_value (sheet->hadjustment, - hpos); - } + step_horizontal (sheet, GTK_SCROLL_STEP_RIGHT); break; + case GDK_ISO_Left_Tab: case GDK_Left: - gtk_sheet_activate_cell (sheet, - sheet->active_cell.row, - sheet->active_cell.col - 1); - - if ( sheet->active_cell.col <= min_visible_column (sheet)) - { - glong hpos = - g_sheet_column_start_pixel (sheet->column_geometry, - sheet->active_cell.col); - - gtk_adjustment_set_value (sheet->hadjustment, - hpos); - } - + step_horizontal (sheet, GTK_SCROLL_STEP_LEFT); break; + case GDK_Return: case GDK_Down: gtk_sheet_activate_cell (sheet, sheet->active_cell.row + ROWS_PER_STEP, @@ -4997,12 +4961,6 @@ gtk_sheet_key_press (GtkWidget *widget, */ break; - case GDK_Tab: - break; - case GDK_Return: - g_print ("Enter\n"); - break; - default: return FALSE; break; diff --git a/lib/gtksheet/gtksheet.h b/lib/gtksheet/gtksheet.h index b6188368..97f893a0 100644 --- a/lib/gtksheet/gtksheet.h +++ b/lib/gtksheet/gtksheet.h @@ -69,10 +69,6 @@ enum -#define GTK_SHEET_AUTORESIZE(sheet) gtk_sheet_autoresize (sheet) -#define GTK_SHEET_AUTO_SCROLL(sheet) gtk_sheet_autoscroll (sheet) -#define GTK_SHEET_JUSTIFY_ENTRY(sheet) gtk_sheet_justify_entry (sheet) - typedef struct _GtkSheetClass GtkSheetClass; typedef struct _GtkSheetCellAttr GtkSheetCellAttr; @@ -126,8 +122,6 @@ struct _GtkSheet GtkSelectionMode selection_mode; gboolean autoresize; - gboolean autoscroll; - gboolean justify_entry; /* Component colors */ GdkColor color[n_COLORS]; @@ -293,17 +287,6 @@ void gtk_sheet_get_selected_range (GtkSheet *sheet, void gtk_sheet_set_selection_mode (GtkSheet *sheet, gint mode); -void gtk_sheet_set_autoresize (GtkSheet *sheet, gboolean autoresize); - -gboolean gtk_sheet_autoresize (GtkSheet *sheet); - -void gtk_sheet_set_autoscroll (GtkSheet *sheet, gboolean autoscroll); - -gboolean gtk_sheet_autoscroll (GtkSheet *sheet); - -void gtk_sheet_set_justify_entry (GtkSheet *sheet, gboolean justify); - -gboolean gtk_sheet_justify_entry (GtkSheet *sheet); void gtk_sheet_show_grid (GtkSheet *sheet, gboolean show); diff --git a/src/ui/gui/psppire-var-sheet.c b/src/ui/gui/psppire-var-sheet.c index 256f3c93..9ad91515 100644 --- a/src/ui/gui/psppire-var-sheet.c +++ b/src/ui/gui/psppire-var-sheet.c @@ -251,12 +251,12 @@ change_measure (GtkComboBox *cb, } - +/* Moves the focus to a new cell. + Returns TRUE iff the move should be disallowed */ static gboolean traverse_cell_callback (GtkSheet *sheet, gint row, gint column, - gint *new_row, gint *new_column - ) + gint *new_row, gint *new_column) { PsppireVarSheet *var_sheet = PSPPIRE_VAR_SHEET (sheet); PsppireVarStore *var_store = PSPPIRE_VAR_STORE (gtk_sheet_get_model (sheet)); @@ -264,7 +264,7 @@ traverse_cell_callback (GtkSheet *sheet, gint n_vars = psppire_var_store_get_var_cnt (var_store); if (*new_row >= n_vars && !var_sheet->may_create_vars) - return FALSE; + return TRUE; if ( row == n_vars && *new_row >= n_vars) { @@ -273,11 +273,11 @@ traverse_cell_callback (GtkSheet *sheet, const gchar *name = gtk_entry_get_text (entry); if (! psppire_dict_check_name (var_store->dict, name, TRUE)) - return FALSE; + return TRUE; psppire_dict_insert_variable (var_store->dict, row, name); - return TRUE; + return FALSE; } /* If the destination cell is outside the current variables, then @@ -291,12 +291,11 @@ traverse_cell_callback (GtkSheet *sheet, psppire_dict_insert_variable (var_store->dict, i, NULL); } - return TRUE; + return FALSE; } - /* Callback whenever the pointer leaves a cell on the var sheet. */ -- 2.30.2