From: John Darrington Date: Sat, 22 Nov 2008 07:07:16 +0000 (+0900) Subject: Change traverse signal to take GtkSheetCell instead of gint,gint X-Git-Tag: v0.7.1~123 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e93857e0338c2a71794db2b57e3659bbe6946240;p=pspp-builds.git Change traverse signal to take GtkSheetCell instead of gint,gint --- diff --git a/lib/gtksheet/gtkextra-sheet.h b/lib/gtksheet/gtkextra-sheet.h index 16d49075..7ea9b171 100644 --- a/lib/gtksheet/gtkextra-sheet.h +++ b/lib/gtksheet/gtkextra-sheet.h @@ -23,8 +23,8 @@ */ -#ifndef __GTK_EXTRA_SHEET_H__ -#define __GTK_EXTRA_SHEET_H__ +#ifndef GTK_EXTRA_SHEET_H__ +#define GTK_EXTRA_SHEET_H__ struct _GtkSheet ; @@ -42,15 +42,20 @@ struct _GtkSheetButton GtkJustification justification; }; -typedef struct _GtkSheetButton GtkSheetButton; - +struct _GtkSheetCell +{ + gint row; + gint col; +}; +typedef struct _GtkSheetButton GtkSheetButton; +typedef struct _GtkSheetCell GtkSheetCell; GtkSheetButton * gtk_sheet_button_new (void); void gtk_sheet_button_free (GtkSheetButton *button); -#endif /* __GTK_EXTRA_SHEET_H__ */ +#endif /* GTK_EXTRA_SHEET_H__ */ diff --git a/lib/gtksheet/gtksheet.c b/lib/gtksheet/gtksheet.c index 9e12bc92..c4556e3e 100644 --- a/lib/gtksheet/gtksheet.c +++ b/lib/gtksheet/gtksheet.c @@ -628,6 +628,8 @@ gtk_sheet_get_type () return sheet_type; } + + static GtkSheetRange* gtk_sheet_range_copy (const GtkSheetRange *range) { @@ -666,6 +668,44 @@ gtk_sheet_range_get_type (void) return sheet_range_type; } +static GtkSheetCell* +gtk_sheet_cell_copy (const GtkSheetCell *cell) +{ + GtkSheetCell *new_cell; + + g_return_val_if_fail (cell != NULL, NULL); + + new_cell = g_new (GtkSheetCell, 1); + + *new_cell = *cell; + + return new_cell; +} + +static void +gtk_sheet_cell_free (GtkSheetCell *cell) +{ + g_return_if_fail (cell != NULL); + + g_free (cell); +} + +GType +gtk_sheet_cell_get_type (void) +{ + static GType sheet_cell_type = 0; + + if (!sheet_cell_type) + { + sheet_cell_type = + g_boxed_type_register_static ("GtkSheetCell", + (GBoxedCopyFunc) gtk_sheet_cell_copy, + (GBoxedFreeFunc) gtk_sheet_cell_free); + } + + return sheet_cell_type; +} + static void column_titles_changed (GtkWidget *w, gint first, gint n_columns, gpointer data); @@ -929,9 +969,10 @@ gtk_sheet_class_init (GtkSheetClass *klass) G_SIGNAL_RUN_LAST, offsetof (GtkSheetClass, traverse), NULL, NULL, - gtkextra_BOOLEAN__INT_INT_POINTER_POINTER, - G_TYPE_BOOLEAN, 4, G_TYPE_INT, G_TYPE_INT, - G_TYPE_POINTER, G_TYPE_POINTER); + gtkextra_BOOLEAN__BOXED_POINTER, + G_TYPE_BOOLEAN, 2, + GTK_TYPE_SHEET_CELL, + G_TYPE_POINTER); sheet_signals[ACTIVATE] = @@ -3513,17 +3554,23 @@ gtk_sheet_button_press (GtkWidget *widget, static gboolean gtk_sheet_click_cell (GtkSheet *sheet, gint row, gint column) { + GtkSheetCell cell; gboolean forbid_move; + cell.row = row; + cell.col = column; + if (row >= g_sheet_row_get_row_count (sheet->row_geometry) || column >= g_sheet_column_get_column_count (sheet->column_geometry)) { return FALSE; } + g_signal_emit (sheet, sheet_signals[TRAVERSE], 0, - sheet->active_cell.row, sheet->active_cell.col, - &row, &column, &forbid_move); + sheet->active_cell, + &cell, + &forbid_move); if (forbid_move) { @@ -4266,23 +4313,25 @@ step_sheet (GtkSheet *sheet, GtkScrollType dir) { gint current_row = sheet->active_cell.row; gint current_col = sheet->active_cell.col; - gint new_row = current_row; - gint new_col = current_col; + GtkSheetCell new_cell ; gboolean forbidden = FALSE; + new_cell.row = current_row; + new_cell.col = current_col; + switch ( dir) { case GTK_SCROLL_STEP_DOWN: - new_row++; + new_cell.row++; break; case GTK_SCROLL_STEP_UP: - new_row--; + new_cell.row--; break; case GTK_SCROLL_STEP_RIGHT: - new_col++; + new_cell.col++; break; case GTK_SCROLL_STEP_LEFT: - new_col--; + new_cell.col--; break; default: g_assert_not_reached (); @@ -4290,60 +4339,61 @@ step_sheet (GtkSheet *sheet, GtkScrollType dir) } - maximize_int (&new_row, 0); - maximize_int (&new_col, 0); + maximize_int (&new_cell.row, 0); + maximize_int (&new_cell.col, 0); - minimize_int (&new_row, + minimize_int (&new_cell.row, g_sheet_row_get_row_count (sheet->row_geometry) - 1); - minimize_int (&new_col, + minimize_int (&new_cell.col, g_sheet_column_get_column_count (sheet->column_geometry) - 1); g_signal_emit (sheet, sheet_signals[TRAVERSE], 0, - current_row, current_col, - &new_row, &new_col, &forbidden); + &sheet->active_cell, + &new_cell, + &forbidden); if (forbidden) return; - change_active_cell (sheet, new_row, new_col); + change_active_cell (sheet, new_cell.row, new_cell.col); - if ( new_col > max_fully_visible_column (sheet)) + if ( new_cell.col > max_fully_visible_column (sheet)) { glong hpos = g_sheet_column_start_pixel (sheet->column_geometry, - new_col + 1); + new_cell.col + 1); hpos -= sheet->hadjustment->page_size; gtk_adjustment_set_value (sheet->hadjustment, hpos); } - else if ( new_col < min_fully_visible_column (sheet)) + else if ( new_cell.col < min_fully_visible_column (sheet)) { glong hpos = g_sheet_column_start_pixel (sheet->column_geometry, - new_col); + new_cell.col); gtk_adjustment_set_value (sheet->hadjustment, hpos); } - if ( new_row > max_fully_visible_row (sheet)) + if ( new_cell.row > max_fully_visible_row (sheet)) { glong vpos = g_sheet_row_start_pixel (sheet->row_geometry, - new_row + 1); + new_cell.row + 1); vpos -= sheet->vadjustment->page_size; gtk_adjustment_set_value (sheet->vadjustment, vpos); } - else if ( new_row < min_fully_visible_row (sheet)) + else if ( new_cell.row < min_fully_visible_row (sheet)) { glong vpos = g_sheet_row_start_pixel (sheet->row_geometry, - new_row); + new_cell.row); gtk_adjustment_set_value (sheet->vadjustment, vpos); diff --git a/lib/gtksheet/gtksheet.h b/lib/gtksheet/gtksheet.h index 8dc21332..fa1ac422 100644 --- a/lib/gtksheet/gtksheet.h +++ b/lib/gtksheet/gtksheet.h @@ -47,6 +47,7 @@ enum #define GTK_TYPE_SHEET_RANGE (gtk_sheet_range_get_type ()) +#define GTK_TYPE_SHEET_CELL (gtk_sheet_cell_get_type ()) #define GTK_TYPE_SHEET (gtk_sheet_get_type ()) #define GTK_SHEET(obj) GTK_CHECK_CAST (obj, gtk_sheet_get_type (), GtkSheet) @@ -56,7 +57,7 @@ enum typedef struct _GtkSheetClass GtkSheetClass; typedef struct _GtkSheetCellAttr GtkSheetCellAttr; -typedef struct _GtkSheetCell GtkSheetCell; + typedef struct _GtkSheetHoverTitle GtkSheetHoverTitle; @@ -71,13 +72,6 @@ struct _GtkSheetCellAttr gboolean is_visible; }; -struct _GtkSheetCell -{ - gint row; - gint col; -}; - - struct _GtkSheetHoverTitle { GtkWidget *window; diff --git a/src/ui/gui/psppire-data-editor.c b/src/ui/gui/psppire-data-editor.c index 784a7319..072e55ba 100644 --- a/src/ui/gui/psppire-data-editor.c +++ b/src/ui/gui/psppire-data-editor.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyrigght (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008 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 @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include "psppire-data-editor.h" #include "psppire-var-sheet.h" @@ -171,14 +171,14 @@ on_var_row_clicked (PsppireDataEditor *de, gint row, gpointer data) 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, + GtkSheetCell *existing_cell, + GtkSheetCell *new_cell, gpointer data) { PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (data); const PsppireDict *dict = de->data_store->dict; - if ( *new_column >= psppire_dict_get_var_cnt (dict)) + if ( new_cell->col >= psppire_dict_get_var_cnt (dict)) return TRUE; return FALSE; @@ -624,7 +624,6 @@ init_sheet (PsppireDataEditor *de, int i, gtk_container_add (GTK_CONTAINER (de->sheet_bin[i]), de->data_sheet[i]); - g_signal_connect (de->data_sheet[i], "traverse", G_CALLBACK (traverse_cell_callback), de); diff --git a/src/ui/gui/psppire-var-sheet.c b/src/ui/gui/psppire-var-sheet.c index 60b968ef..0708bf3e 100644 --- a/src/ui/gui/psppire-var-sheet.c +++ b/src/ui/gui/psppire-var-sheet.c @@ -254,19 +254,18 @@ change_measure (GtkComboBox *cb, 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) + const GtkSheetCell *existing_cell, + GtkSheetCell *new_cell) { PsppireVarSheet *var_sheet = PSPPIRE_VAR_SHEET (sheet); PsppireVarStore *var_store = PSPPIRE_VAR_STORE (gtk_sheet_get_model (sheet)); gint n_vars = psppire_var_store_get_var_cnt (var_store); - if (*new_row >= n_vars && !var_sheet->may_create_vars) + if (new_cell->row >= n_vars && !var_sheet->may_create_vars) return TRUE; - - if ( row == n_vars && *new_row >= n_vars) + if ( existing_cell->row == n_vars && new_cell->row >= n_vars) { GtkEntry *entry = GTK_ENTRY (gtk_sheet_get_entry (sheet)); @@ -275,7 +274,7 @@ traverse_cell_callback (GtkSheet *sheet, if (! psppire_dict_check_name (var_store->dict, name, TRUE)) return TRUE; - psppire_dict_insert_variable (var_store->dict, row, name); + psppire_dict_insert_variable (var_store->dict, existing_cell->row, name); return FALSE; } @@ -284,16 +283,15 @@ traverse_cell_callback (GtkSheet *sheet, /* If the destination cell is outside the current variables, then automatically create variables for the new rows. */ - if ( ((*new_row > n_vars) || - (*new_row == n_vars && *new_column != PSPPIRE_VAR_STORE_COL_NAME)) ) + if ( ((new_cell->row > n_vars) || + (new_cell->row == n_vars && + new_cell->col != PSPPIRE_VAR_STORE_COL_NAME)) ) { gint i; - for ( i = n_vars ; i <= *new_row; ++i ) + for ( i = n_vars ; i <= new_cell->row; ++i ) psppire_dict_insert_variable (var_store->dict, i, NULL); } - - return FALSE; }