From 2dd0df69f627a06ffb887128d22e3d686d1cd207 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Sun, 23 Jul 2006 10:32:50 +0000 Subject: [PATCH] Fixed bug where gui would crash when columns were resized. --- lib/gtksheet/gsheet-column-iface.c | 53 ++++--- lib/gtksheet/gsheet-column-iface.h | 56 +++---- lib/gtksheet/gsheet-hetero-column.c | 20 ++- lib/gtksheet/gsheet-uniform-column.c | 12 +- lib/gtksheet/gtksheet.c | 219 ++++++++++++--------------- src/ui/gui/TODO | 4 - src/ui/gui/data-sheet.c | 53 ++++++- src/ui/gui/psppire-data-store.c | 97 +++++------- src/ui/gui/psppire-data-store.h | 18 ++- 9 files changed, 262 insertions(+), 270 deletions(-) diff --git a/lib/gtksheet/gsheet-column-iface.c b/lib/gtksheet/gsheet-column-iface.c index df3c9065..50960036 100644 --- a/lib/gtksheet/gsheet-column-iface.c +++ b/lib/gtksheet/gsheet-column-iface.c @@ -99,58 +99,57 @@ g_sheet_column_base_init (gpointer g_class) inline void -g_sheet_column_set_width (GSheetColumn *column, gint col, gint size, - gpointer data) +g_sheet_column_set_width (GSheetColumn *column, gint col, gint size) { g_return_if_fail (G_IS_SHEET_COLUMN (column)); if ((G_SHEET_COLUMN_GET_IFACE (column)->set_width) ) - (G_SHEET_COLUMN_GET_IFACE (column)->set_width) (column, col, size, data); + (G_SHEET_COLUMN_GET_IFACE (column)->set_width) (column, col, size); } inline gint -g_sheet_column_get_width (const GSheetColumn *column, gint col, gpointer data) +g_sheet_column_get_width (const GSheetColumn *column, gint col) { g_return_val_if_fail (G_IS_SHEET_COLUMN (column), -1); g_assert (G_SHEET_COLUMN_GET_IFACE (column)->get_width); - return (G_SHEET_COLUMN_GET_IFACE (column)->get_width) (column, col, data); + return (G_SHEET_COLUMN_GET_IFACE (column)->get_width) (column, col); } inline gboolean g_sheet_column_get_visibility(const GSheetColumn *column, - gint col, gpointer data) + gint col) { g_return_val_if_fail (G_IS_SHEET_COLUMN (column), FALSE); g_assert (G_SHEET_COLUMN_GET_IFACE (column)->get_visibility); return (G_SHEET_COLUMN_GET_IFACE (column)->get_visibility) (column, - col, data); + col); } inline gboolean g_sheet_column_get_sensitivity(const GSheetColumn *column, - gint col, gpointer data) + gint col) { g_return_val_if_fail (G_IS_SHEET_COLUMN (column), FALSE); g_assert (G_SHEET_COLUMN_GET_IFACE (column)->get_sensitivity); return (G_SHEET_COLUMN_GET_IFACE (column)->get_sensitivity) (column, - col, data); + col); } inline GtkSheetButton * g_sheet_column_get_button(const GSheetColumn *column, - gint col, gpointer data) + gint col) { GtkSheetButton *button = gtk_sheet_button_new(); @@ -159,20 +158,20 @@ g_sheet_column_get_button(const GSheetColumn *column, g_return_val_if_fail (G_IS_SHEET_COLUMN (column), FALSE); if ( iface->get_button_label) - button->label = iface->get_button_label(column, col, data); + button->label = iface->get_button_label(column, col); return button; } inline GtkJustification g_sheet_column_get_justification(const GSheetColumn *column, - gint col, gpointer data) + gint col) { g_return_val_if_fail (G_IS_SHEET_COLUMN (column), FALSE); g_assert (G_SHEET_COLUMN_GET_IFACE (column)->get_justification); - return (G_SHEET_COLUMN_GET_IFACE (column)->get_justification) (column, col, data); + return (G_SHEET_COLUMN_GET_IFACE (column)->get_justification) (column, col); } @@ -180,76 +179,76 @@ g_sheet_column_get_justification(const GSheetColumn *column, inline gint g_sheet_column_get_left_text_column (const GSheetColumn *column, - gint col, gpointer data) + gint col) { g_return_val_if_fail (G_IS_SHEET_COLUMN (column), -1); if ( ! G_SHEET_COLUMN_GET_IFACE (column)->get_left_text_column) return col; - return (G_SHEET_COLUMN_GET_IFACE (column)->get_left_text_column) (column, col, data); + return (G_SHEET_COLUMN_GET_IFACE (column)->get_left_text_column) (column, col); } inline gint g_sheet_column_get_right_text_column (const GSheetColumn *column, - gint col, gpointer data) + gint col) { g_return_val_if_fail (G_IS_SHEET_COLUMN (column), -1); if ( ! G_SHEET_COLUMN_GET_IFACE (column)->get_right_text_column) return col; - return (G_SHEET_COLUMN_GET_IFACE (column)->get_right_text_column) (column, col, data); + return (G_SHEET_COLUMN_GET_IFACE (column)->get_right_text_column) (column, col); } inline void g_sheet_column_set_left_text_column (const GSheetColumn *column, - gint col, gint i, gpointer data) + gint col, gint i) { g_return_if_fail (G_IS_SHEET_COLUMN (column)); if ( G_SHEET_COLUMN_GET_IFACE (column)->set_left_text_column) - (G_SHEET_COLUMN_GET_IFACE (column)->set_left_text_column) (column, col, i, data); + (G_SHEET_COLUMN_GET_IFACE (column)->set_left_text_column) (column, col, i); } inline void g_sheet_column_set_right_text_column (const GSheetColumn *column, - gint col, gint i, gpointer data) + gint col, gint i) { g_return_if_fail (G_IS_SHEET_COLUMN (column)); if ( G_SHEET_COLUMN_GET_IFACE (column)->set_right_text_column) - (G_SHEET_COLUMN_GET_IFACE (column)->set_right_text_column) (column, col, i, data); + (G_SHEET_COLUMN_GET_IFACE (column)->set_right_text_column) (column, col, i); } inline gint -g_sheet_column_get_column_count(const GSheetColumn *geo, gpointer data) +g_sheet_column_get_column_count(const GSheetColumn *geo) { g_return_val_if_fail (G_IS_SHEET_COLUMN (geo), -1); g_assert ( G_SHEET_COLUMN_GET_IFACE (geo)->get_column_count); - return (G_SHEET_COLUMN_GET_IFACE (geo)->get_column_count) (geo, data); + return (G_SHEET_COLUMN_GET_IFACE (geo)->get_column_count) (geo); } inline gint -g_sheet_column_start_pixel(const GSheetColumn *geo, gint col, gpointer data) +g_sheet_column_start_pixel(const GSheetColumn *geo, gint col) { gint i; gint start_pixel = 0; g_return_val_if_fail (G_IS_SHEET_COLUMN (geo), -1); g_return_val_if_fail (col < - g_sheet_column_get_column_count(geo, data),-1); + g_sheet_column_get_column_count(geo),-1); for ( i = 0 ; i < col ; ++i ) { - if ( g_sheet_column_get_visibility(geo, i, data)) - start_pixel += g_sheet_column_get_width(geo, i, data); + if ( g_sheet_column_get_visibility(geo, i)) + start_pixel += g_sheet_column_get_width(geo, i); } return start_pixel; diff --git a/lib/gtksheet/gsheet-column-iface.h b/lib/gtksheet/gsheet-column-iface.h index 430814ab..3bcab803 100644 --- a/lib/gtksheet/gsheet-column-iface.h +++ b/lib/gtksheet/gsheet-column-iface.h @@ -47,37 +47,37 @@ struct _GSheetColumnIface gint col, gint n_columns); /* Virtual Table */ - gint (* get_width) (const GSheetColumn *gcolumn, gint col, gpointer data); - void (* set_width) (GSheetColumn *gcolumn, gint col, gint width, gpointer data); + gint (* get_width) (const GSheetColumn *gcolumn, gint col); + void (* set_width) (GSheetColumn *gcolumn, gint col, gint width); - gboolean (* get_visibility) (const GSheetColumn *gcolumn, gint col, gpointer data); - gboolean (* get_sensitivity) (const GSheetColumn *gcolumn, gint col, gpointer data); - const GtkSheetButton * (* get_button) (const GSheetColumn *gcolumn, gint col, gpointer data); - GtkJustification (* get_justification) (const GSheetColumn *gcolumn, gint col, gpointer data); + gboolean (* get_visibility) (const GSheetColumn *gcolumn, gint col); + gboolean (* get_sensitivity) (const GSheetColumn *gcolumn, gint col); + const GtkSheetButton * (* get_button) (const GSheetColumn *gcolumn, gint col); + GtkJustification (* get_justification) (const GSheetColumn *gcolumn, gint col); gint (*get_left_text_column) (const GSheetColumn *gcolumn, - gint col, gpointer data); + gint col); gint (*get_right_text_column) (const GSheetColumn *gcolumn, - gint col, gpointer data); + gint col); void (* set_left_text_column) (const GSheetColumn *gcolumn, - gint col, gint i, gpointer data); + gint col, gint i); void (* set_right_text_column) (const GSheetColumn *gcolumn, - gint col, gint i, gpointer data); + gint col, gint i); - gint (* get_column_count) (const GSheetColumn *geo, gpointer data); + gint (* get_column_count) (const GSheetColumn *geo); - GtkStateType (*get_button_state)(const GSheetColumn *geo, gint col, gpointer data); - gchar * (*get_button_label)(const GSheetColumn *geo, gint col, gpointer data); + GtkStateType (*get_button_state)(const GSheetColumn *geo, gint col); + gchar * (*get_button_label)(const GSheetColumn *geo, gint col); gboolean (*get_button_visibility)(const GSheetColumn *geo, - gint col, gpointer data); + gint col); const GtkSheetChild * (*get_button_child)(const GSheetColumn *geo, - gint col, gpointer data); + gint col); GtkJustification * (*get_button_justification)(const GSheetColumn *geo, - gint col, gpointer data); + gint col); }; @@ -85,43 +85,43 @@ inline GType g_sheet_column_get_type (void) G_GNUC_CONST; inline gint g_sheet_column_get_width (const GSheetColumn *gcolumn, - gint col, gpointer data); + gint col); inline void g_sheet_column_set_width (GSheetColumn *gcolumn, - gint col, gint size, gpointer data); + gint col, gint size); inline gboolean g_sheet_column_get_visibility(const GSheetColumn *gcolumn, - gint col, gpointer data); + gint col); inline gboolean g_sheet_column_get_sensitivity(const GSheetColumn *gcolumn, - gint col, gpointer data); + gint col); inline GtkSheetButton *g_sheet_column_get_button(const GSheetColumn *gcolumn, - gint col, gpointer data); + gint col); -inline GtkJustification g_sheet_column_get_justification(const GSheetColumn *gcolumn, gint col, gpointer data); +inline GtkJustification g_sheet_column_get_justification(const GSheetColumn *gcolumn, gint col); inline gint g_sheet_column_get_left_text_column (const GSheetColumn *gcolumn, - gint col, gpointer data); + gint col); inline gint g_sheet_column_get_right_text_column (const GSheetColumn *gcolumn, - gint col, gpointer data); + gint col); inline void g_sheet_column_set_left_text_column (const GSheetColumn *gcolumn, - gint col, gint i, gpointer data); + gint col, gint i); inline void g_sheet_column_set_right_text_column (const GSheetColumn *gcolumn, - gint col, gint i, gpointer data); + gint col, gint i); -inline gint g_sheet_column_get_column_count(const GSheetColumn *geo, gpointer data); +inline gint g_sheet_column_get_column_count(const GSheetColumn *geo); -inline gint g_sheet_column_start_pixel(const GSheetColumn *geo, gint col, gpointer data); +inline gint g_sheet_column_start_pixel(const GSheetColumn *geo, gint col); inline void g_sheet_column_columns_changed(GSheetColumn *geo, gint first, gint n_columns); diff --git a/lib/gtksheet/gsheet-hetero-column.c b/lib/gtksheet/gsheet-hetero-column.c index ebd67903..e32f4f4a 100644 --- a/lib/gtksheet/gsheet-hetero-column.c +++ b/lib/gtksheet/gsheet-hetero-column.c @@ -104,7 +104,7 @@ g_sheet_hetero_column_new (gint default_width, gint n_columns) } static gint -g_sheet_hetero_column_get_width(const GSheetColumn *geom, gint i, gpointer data) +g_sheet_hetero_column_get_width(const GSheetColumn *geom, gint i) { GSheetHeteroColumn *hg = G_SHEET_HETERO_COLUMN(geom); @@ -114,14 +114,14 @@ g_sheet_hetero_column_get_width(const GSheetColumn *geom, gint i, gpointer data) } static gint -g_sheet_hetero_column_get_sensitivity(const GSheetColumn *geom, gint u, gpointer data) +g_sheet_hetero_column_get_sensitivity(const GSheetColumn *geom, gint u) { return TRUE; } static gint -g_sheet_hetero_column_get_visibility(const GSheetColumn *geom, gint u, gpointer data) +g_sheet_hetero_column_get_visibility(const GSheetColumn *geom, gint u) { return TRUE; } @@ -129,7 +129,7 @@ g_sheet_hetero_column_get_visibility(const GSheetColumn *geom, gint u, gpointer static gchar * -g_sheet_hetero_column_get_button_label(const GSheetColumn *geom, gint u, gpointer data) +g_sheet_hetero_column_get_button_label(const GSheetColumn *geom, gint u) { GSheetHeteroColumn *hg = G_SHEET_HETERO_COLUMN(geom); @@ -138,7 +138,7 @@ g_sheet_hetero_column_get_button_label(const GSheetColumn *geom, gint u, gpointe static GtkJustification -g_sheet_hetero_column_get_justification(const GSheetColumn *geom, gint u, gpointer data) +g_sheet_hetero_column_get_justification(const GSheetColumn *geom, gint u) { return GTK_JUSTIFY_FILL; } @@ -146,7 +146,7 @@ g_sheet_hetero_column_get_justification(const GSheetColumn *geom, gint u, gpoint static gint -g_sheet_hetero_column_get_column_count(const GSheetColumn *geom, gpointer data) +g_sheet_hetero_column_get_column_count(const GSheetColumn *geom) { GSheetHeteroColumn *hg = G_SHEET_HETERO_COLUMN(geom); @@ -185,8 +185,7 @@ g_sheet_hetero_column_finalize (GObject *object) } static void -hetero_column_set_width(GSheetColumn *geo, - gint i, gint size, gpointer data) +hetero_column_set_width(GSheetColumn *geo, gint i, gint size) { GSheetHeteroColumn *hg = G_SHEET_HETERO_COLUMN(geo); @@ -227,12 +226,11 @@ g_sheet_hetero_column_set_button_label(GSheetHeteroColumn *geo, inline void -g_sheet_hetero_column_set_width(GSheetHeteroColumn *geo, - gint i, gint size) +g_sheet_hetero_column_set_width(GSheetHeteroColumn *geo, gint i, gint size) { GSheetColumn *iface = G_SHEET_COLUMN(geo); - hetero_column_set_width(iface, i, size, 0); + hetero_column_set_width(iface, i, size); } diff --git a/lib/gtksheet/gsheet-uniform-column.c b/lib/gtksheet/gsheet-uniform-column.c index 6822fa36..e7e6f4ed 100644 --- a/lib/gtksheet/gsheet-uniform-column.c +++ b/lib/gtksheet/gsheet-uniform-column.c @@ -96,7 +96,7 @@ g_sheet_uniform_column_new (gint width, gint n_columns) } static gint -g_sheet_uniform_column_get_width(const GSheetColumn *geom, gint u, gpointer data) +g_sheet_uniform_column_get_width(const GSheetColumn *geom, gint u) { GSheetUniformColumn *ug = G_SHEET_UNIFORM_COLUMN(geom); @@ -104,7 +104,7 @@ g_sheet_uniform_column_get_width(const GSheetColumn *geom, gint u, gpointer data } static gint -g_sheet_uniform_column_get_sensitivity(const GSheetColumn *geom, gint u, gpointer data) +g_sheet_uniform_column_get_sensitivity(const GSheetColumn *geom, gint u) { GSheetUniformColumn *ug = G_SHEET_UNIFORM_COLUMN(geom); @@ -113,7 +113,7 @@ g_sheet_uniform_column_get_sensitivity(const GSheetColumn *geom, gint u, gpointe static gint -g_sheet_uniform_column_get_visibility(const GSheetColumn *geom, gint u, gpointer data) +g_sheet_uniform_column_get_visibility(const GSheetColumn *geom, gint u) { GSheetUniformColumn *ug = G_SHEET_UNIFORM_COLUMN(geom); @@ -122,7 +122,7 @@ g_sheet_uniform_column_get_visibility(const GSheetColumn *geom, gint u, gpointer static gchar * -g_sheet_uniform_column_get_button_label(const GSheetColumn *geom, gint u, gpointer data) +g_sheet_uniform_column_get_button_label(const GSheetColumn *geom, gint u) { gchar *label = g_strdup_printf("%d", u); @@ -131,7 +131,7 @@ g_sheet_uniform_column_get_button_label(const GSheetColumn *geom, gint u, gpoint static GtkJustification -g_sheet_uniform_column_get_justification(const GSheetColumn *geom, gint u, gpointer data) +g_sheet_uniform_column_get_justification(const GSheetColumn *geom, gint u) { return GTK_JUSTIFY_FILL; } @@ -139,7 +139,7 @@ g_sheet_uniform_column_get_justification(const GSheetColumn *geom, gint u, gpoin static gint -g_sheet_uniform_column_get_column_count(const GSheetColumn *geom, gpointer data) +g_sheet_uniform_column_get_column_count(const GSheetColumn *geom) { GSheetUniformColumn *ug = G_SHEET_UNIFORM_COLUMN(geom); diff --git a/lib/gtksheet/gtksheet.c b/lib/gtksheet/gtksheet.c index 7435b8e2..7b5774ce 100644 --- a/lib/gtksheet/gtksheet.c +++ b/lib/gtksheet/gtksheet.c @@ -269,7 +269,7 @@ xxx_column_button(const GtkSheet *sheet, gint col) GSheetColumn *col_geo = sheet->column_geometry; if ( col < 0 ) return NULL ; - return g_sheet_column_get_button(col_geo, col, 0); + return g_sheet_column_get_button(col_geo, col); } @@ -278,9 +278,7 @@ xxx_column_left_xpixel(const GtkSheet *sheet, gint col) { GSheetColumn *geo = sheet->column_geometry; - /* FIXME: Get rid of this nasty cast. - In fact, get rid of this entire variable */ - gint x = g_sheet_column_start_pixel(geo, col, (GtkSheet *) sheet); + gint x = g_sheet_column_start_pixel(geo, col); if ( sheet->row_titles_visible ) x += sheet->row_title_area.width; @@ -293,9 +291,7 @@ xxx_column_width(const GtkSheet *sheet, gint col) { GSheetColumn *col_geo = sheet->column_geometry; - /* FIXME: Get rid of this nasty cast. - In fact, get rid of this entire variable */ - return g_sheet_column_get_width(col_geo, col, (GtkSheet *)sheet); + return g_sheet_column_get_width(col_geo, col); } @@ -303,7 +299,7 @@ static inline void xxx_set_column_width(GtkSheet *sheet, gint col, gint width) { if ( sheet->column_geometry ) - g_sheet_column_set_width(sheet->column_geometry, col, width, sheet); + g_sheet_column_set_width(sheet->column_geometry, col, width); } static inline void @@ -311,7 +307,7 @@ xxx_column_set_left_column(GtkSheet *sheet, gint col, gint i) { GSheetColumn *col_geo = sheet->column_geometry; - g_sheet_column_set_left_text_column(col_geo, col, i, sheet); + g_sheet_column_set_left_text_column(col_geo, col, i); } static inline gint @@ -319,7 +315,7 @@ xxx_column_left_column(const GtkSheet *sheet, gint col) { GSheetColumn *col_geo = sheet->column_geometry; - return g_sheet_column_get_left_text_column(col_geo, col, 0); + return g_sheet_column_get_left_text_column(col_geo, col); } static inline void @@ -327,7 +323,7 @@ xxx_column_set_right_column(GtkSheet *sheet, gint col, gint i) { GSheetColumn *col_geo = sheet->column_geometry; - g_sheet_column_set_right_text_column(col_geo, col, i, 0); + g_sheet_column_set_right_text_column(col_geo, col, i); } static inline gint @@ -335,7 +331,7 @@ xxx_column_right_column(const GtkSheet *sheet, gint col) { GSheetColumn *col_geo = sheet->column_geometry; - return g_sheet_column_get_right_text_column(col_geo, col, 0); + return g_sheet_column_get_right_text_column(col_geo, col); } static inline GtkJustification @@ -343,7 +339,7 @@ xxx_column_justification(const GtkSheet *sheet, gint col) { GSheetColumn *col_geo = sheet->column_geometry; - return g_sheet_column_get_justification(col_geo, col, 0); + return g_sheet_column_get_justification(col_geo, col); } static inline gint @@ -351,7 +347,7 @@ xxx_column_is_visible(const GtkSheet *sheet, gint col) { GSheetColumn *col_geo = sheet->column_geometry; - return g_sheet_column_get_visibility(col_geo, col, 0); + return g_sheet_column_get_visibility(col_geo, col); } @@ -360,7 +356,7 @@ xxx_column_is_sensitive(const GtkSheet *sheet, gint col) { GSheetColumn *col_geo = sheet->column_geometry; - return g_sheet_column_get_sensitivity(col_geo, col, 0); + return g_sheet_column_get_sensitivity(col_geo, col); } @@ -377,7 +373,7 @@ xxx_column_count(const GtkSheet *sheet) { GSheetColumn *col_geo = sheet->column_geometry; - return g_sheet_column_get_column_count(col_geo, 0); + return g_sheet_column_get_column_count(col_geo); } /* returns the column index from a x pixel location in the @@ -481,7 +477,6 @@ static inline gboolean POSSIBLE_YDRAG(const GtkSheet *sheet, gint y, gint *drag_row) { gint row, ydrag; - row=ROW_FROM_YPIXEL(sheet, y); *drag_row=row; @@ -560,7 +555,7 @@ POSSIBLE_RESIZE(const GtkSheet *sheet, gint x, gint y, gint *drag_row, gint *drag_column) { gint xdrag, ydrag; - + /* Can't drag if nothing is selected */ if ( sheet->range.row0 < 0 || sheet->range.rowi < 0 || sheet->range.col0 < 0 || sheet->range.coli < 0 ) @@ -4733,7 +4728,7 @@ gtk_sheet_real_select_range (GtkSheet * sheet, g_return_if_fail (sheet != NULL); - if(range==NULL) range=&sheet->range; + if(range == NULL) range = &sheet->range; memcpy(&sheet->range, range, sizeof(*range)); @@ -4742,39 +4737,10 @@ gtk_sheet_real_select_range (GtkSheet * sheet, state = sheet->state; -#if 0 - if(state==GTK_SHEET_COLUMN_SELECTED || state==GTK_SHEET_RANGE_SELECTED){ - for(i=sheet->range.col0; i< range->col0; i++) - column_button_release(sheet, i); - for(i=range->coli+1; i<= sheet->range.coli; i++) - column_button_release(sheet, i); - for(i=range->col0; i<=range->coli; i++){ - column_button_set(sheet, i); - } - } - - if(state==GTK_SHEET_ROW_SELECTED || state==GTK_SHEET_RANGE_SELECTED){ - for(i=sheet->range.row0; i< range->row0; i++) - row_button_release(sheet, i); - for(i=range->rowi+1; i<= sheet->range.rowi; i++) - row_button_release(sheet, i); - for(i=range->row0; i<=range->rowi; i++){ - row_button_set(sheet, i); - } - } -#endif - if(range->coli != sheet->range.coli || range->col0 != sheet->range.col0 || range->rowi != sheet->range.rowi || range->row0 != sheet->range.row0) { - - gtk_sheet_new_selection(sheet, range); - - sheet->range.col0=range->col0; - sheet->range.coli=range->coli; - sheet->range.row0=range->row0; - sheet->range.rowi=range->rowi; - + gtk_sheet_new_selection(sheet, &sheet->range); } else { @@ -4782,7 +4748,7 @@ gtk_sheet_real_select_range (GtkSheet * sheet, gtk_sheet_range_draw_selection(sheet, sheet->range); } - gtk_signal_emit(GTK_OBJECT(sheet), sheet_signals[SELECT_RANGE], range); + gtk_signal_emit(GTK_OBJECT(sheet), sheet_signals[SELECT_RANGE], &sheet->range); } void @@ -5257,18 +5223,20 @@ gtk_sheet_button_release (GtkWidget * widget, sheet=GTK_SHEET(widget); /* release on resize windows */ - if (GTK_SHEET_IN_XDRAG (sheet)){ - GTK_SHEET_UNSET_FLAGS (sheet, GTK_SHEET_IN_XDRAG); - GTK_SHEET_UNSET_FLAGS (sheet, GTK_SHEET_IN_SELECTION); - gtk_widget_get_pointer (widget, &x, NULL); - gdk_pointer_ungrab (event->time); - draw_xor_vline (sheet); + if (GTK_SHEET_IN_XDRAG (sheet)) + { + GTK_SHEET_UNSET_FLAGS (sheet, GTK_SHEET_IN_XDRAG); + GTK_SHEET_UNSET_FLAGS (sheet, GTK_SHEET_IN_SELECTION); + gtk_widget_get_pointer (widget, &x, NULL); + gdk_pointer_ungrab (event->time); + draw_xor_vline (sheet); - gtk_sheet_set_column_width (sheet, sheet->drag_cell.col, new_column_width (sheet, sheet->drag_cell.col, &x)); - sheet->old_hadjustment = -1.; - gtk_signal_emit_by_name (GTK_OBJECT (sheet->hadjustment), "value_changed"); - return TRUE; - } + gtk_sheet_set_column_width (sheet, sheet->drag_cell.col, + new_column_width (sheet, sheet->drag_cell.col, &x)); + sheet->old_hadjustment = -1.; + gtk_signal_emit_by_name (GTK_OBJECT (sheet->hadjustment), "value_changed"); + return TRUE; + } if (GTK_SHEET_IN_YDRAG (sheet)){ GTK_SHEET_UNSET_FLAGS (sheet, GTK_SHEET_IN_YDRAG); @@ -6266,52 +6234,54 @@ gtk_sheet_size_allocate_entry(GtkSheet *sheet) sheet_entry = GTK_ENTRY(gtk_sheet_get_entry(sheet)); - gtk_sheet_get_attributes(sheet, sheet->active_cell.row, sheet->active_cell.col, &attributes); - - if(GTK_WIDGET_REALIZED(sheet->sheet_entry)) - { - - if(!GTK_WIDGET(sheet_entry)->style) - gtk_widget_ensure_style(GTK_WIDGET(sheet_entry)); - - previous_style = GTK_WIDGET(sheet_entry)->style; - - style = gtk_style_copy(previous_style); - style->bg[GTK_STATE_NORMAL] = attributes.background; - style->fg[GTK_STATE_NORMAL] = attributes.foreground; - style->text[GTK_STATE_NORMAL] = attributes.foreground; - style->bg[GTK_STATE_ACTIVE] = attributes.background; - style->fg[GTK_STATE_ACTIVE] = attributes.foreground; - style->text[GTK_STATE_ACTIVE] = attributes.foreground; - - pango_font_description_free(style->font_desc); - style->font_desc = pango_font_description_copy(attributes.font_desc); - - GTK_WIDGET(sheet_entry)->style = style; - gtk_widget_size_request(sheet->sheet_entry, NULL); - GTK_WIDGET(sheet_entry)->style = previous_style; + if ( ! gtk_sheet_get_attributes(sheet, sheet->active_cell.row, + sheet->active_cell.col, + &attributes) ) + return ; - if(style != previous_style){ - if(!GTK_IS_ITEM_ENTRY(sheet->sheet_entry)){ - style->bg[GTK_STATE_NORMAL] = previous_style->bg[GTK_STATE_NORMAL]; - style->fg[GTK_STATE_NORMAL] = previous_style->fg[GTK_STATE_NORMAL]; - style->bg[GTK_STATE_ACTIVE] = previous_style->bg[GTK_STATE_ACTIVE]; - style->fg[GTK_STATE_ACTIVE] = previous_style->fg[GTK_STATE_ACTIVE]; - } - gtk_widget_set_style(GTK_WIDGET(sheet_entry), style); - } - } + if ( GTK_WIDGET_REALIZED(sheet->sheet_entry) ) + { + if(!GTK_WIDGET(sheet_entry)->style) + gtk_widget_ensure_style(GTK_WIDGET(sheet_entry)); + + previous_style = GTK_WIDGET(sheet_entry)->style; + + style = gtk_style_copy(previous_style); + style->bg[GTK_STATE_NORMAL] = attributes.background; + style->fg[GTK_STATE_NORMAL] = attributes.foreground; + style->text[GTK_STATE_NORMAL] = attributes.foreground; + style->bg[GTK_STATE_ACTIVE] = attributes.background; + style->fg[GTK_STATE_ACTIVE] = attributes.foreground; + style->text[GTK_STATE_ACTIVE] = attributes.foreground; + + pango_font_description_free(style->font_desc); + g_assert(attributes.font_desc); + style->font_desc = pango_font_description_copy(attributes.font_desc); + + GTK_WIDGET(sheet_entry)->style = style; + gtk_widget_size_request(sheet->sheet_entry, NULL); + GTK_WIDGET(sheet_entry)->style = previous_style; + + if(style != previous_style){ + if(!GTK_IS_ITEM_ENTRY(sheet->sheet_entry)){ + style->bg[GTK_STATE_NORMAL] = previous_style->bg[GTK_STATE_NORMAL]; + style->fg[GTK_STATE_NORMAL] = previous_style->fg[GTK_STATE_NORMAL]; + style->bg[GTK_STATE_ACTIVE] = previous_style->bg[GTK_STATE_ACTIVE]; + style->fg[GTK_STATE_ACTIVE] = previous_style->fg[GTK_STATE_ACTIVE]; + } + gtk_widget_set_style(GTK_WIDGET(sheet_entry), style); + } + } if(GTK_IS_ITEM_ENTRY(sheet_entry)) - max_size = GTK_ITEM_ENTRY(sheet_entry)->text_max_size; + max_size = GTK_ITEM_ENTRY(sheet_entry)->text_max_size; else - max_size = 0; + max_size = 0; text_size = 0; text = gtk_entry_get_text(GTK_ENTRY(sheet_entry)); - if(text && strlen(text) > 0){ - text_size = STRING_WIDTH(GTK_WIDGET(sheet), attributes.font_desc, text); - } + if(text && strlen(text) > 0) + text_size = STRING_WIDTH(GTK_WIDGET(sheet), attributes.font_desc, text); column_width=xxx_column_width(sheet, sheet->active_cell.col); @@ -6326,16 +6296,16 @@ gtk_sheet_size_allocate_entry(GtkSheet *sheet) shentry_allocation.width = column_width; shentry_allocation.height = yyy_row_height(sheet, sheet->active_cell.row); - if(GTK_IS_ITEM_ENTRY(sheet->sheet_entry)){ - - shentry_allocation.height -= 2*CELLOFFSET; - shentry_allocation.y += CELLOFFSET; - if(gtk_sheet_clip_text(sheet)) - shentry_allocation.width = column_width - 2*CELLOFFSET; - else - shentry_allocation.width = size; - - switch(GTK_ITEM_ENTRY(sheet_entry)->justification){ + if(GTK_IS_ITEM_ENTRY(sheet->sheet_entry)) + { + shentry_allocation.height -= 2*CELLOFFSET; + shentry_allocation.y += CELLOFFSET; + if(gtk_sheet_clip_text(sheet)) + shentry_allocation.width = column_width - 2*CELLOFFSET; + else + shentry_allocation.width = size; + + switch(GTK_ITEM_ENTRY(sheet_entry)->justification){ case GTK_JUSTIFY_CENTER: shentry_allocation.x += (column_width)/2 - size/2; break; @@ -6346,9 +6316,8 @@ gtk_sheet_size_allocate_entry(GtkSheet *sheet) case GTK_JUSTIFY_FILL: shentry_allocation.x += CELLOFFSET; break; - } - - } + } + } if(!GTK_IS_ITEM_ENTRY(sheet->sheet_entry)) { @@ -6376,7 +6345,8 @@ gtk_sheet_entry_set_max_size(GtkSheet *sheet) row=sheet->active_cell.row; col=sheet->active_cell.col; - if(!GTK_IS_ITEM_ENTRY(sheet->sheet_entry) || gtk_sheet_clip_text(sheet)) return; + if( ! GTK_IS_ITEM_ENTRY(sheet->sheet_entry) || gtk_sheet_clip_text(sheet)) + return; justification = GTK_ITEM_ENTRY(sheet->sheet_entry)->justification; @@ -7249,7 +7219,7 @@ new_column_width (GtkSheet * sheet, xxx_set_column_width(sheet, column, width); sheet->view.coli = COLUMN_FROM_XPIXEL(sheet, sheet->sheet_window_width); size_allocate_column_title_buttons (sheet); - + return width; } @@ -7312,16 +7282,17 @@ gtk_sheet_set_column_width (GtkSheet * sheet, xxx_set_column_width(sheet, column, width); - if(GTK_WIDGET_REALIZED(GTK_WIDGET(sheet)) && !GTK_SHEET_IS_FROZEN(sheet)){ - size_allocate_column_title_buttons (sheet); - adjust_scrollbars (sheet); - gtk_sheet_size_allocate_entry(sheet); - gtk_sheet_range_draw (sheet, NULL); - } else - + if(GTK_WIDGET_REALIZED(GTK_WIDGET(sheet)) && !GTK_SHEET_IS_FROZEN(sheet)) + { + size_allocate_column_title_buttons (sheet); + adjust_scrollbars (sheet); + gtk_sheet_size_allocate_entry(sheet); + gtk_sheet_range_draw (sheet, NULL); + } + gtk_signal_emit(GTK_OBJECT(sheet), sheet_signals[CHANGED], -1, column); - gtk_signal_emit(GTK_OBJECT(sheet), sheet_signals[NEW_COL_WIDTH], column, width); - + gtk_signal_emit(GTK_OBJECT(sheet), sheet_signals[NEW_COL_WIDTH], + column, width); } diff --git a/src/ui/gui/TODO b/src/ui/gui/TODO index fa7eb0aa..6256855b 100644 --- a/src/ui/gui/TODO +++ b/src/ui/gui/TODO @@ -1,5 +1,3 @@ -* Crashes when resizing rows/columns when no cell is selected. - * Blank cell reference when deselecting cells. (Eg New command). * Strip leading/trailing whitespace on data in cells. @@ -8,8 +6,6 @@ * Case weights. -* Resizing of string variables. - * Goto Variable. * Widen columns in var sheet as necessary to accomodate non-english translations. diff --git a/src/ui/gui/data-sheet.c b/src/ui/gui/data-sheet.c index 87dcc500..29e0309c 100644 --- a/src/ui/gui/data-sheet.c +++ b/src/ui/gui/data-sheet.c @@ -118,10 +118,45 @@ update_data_ref_entry(const GtkSheet *sheet, gint row, gint col) return FALSE; } - extern PsppireDataStore *data_store ; +/* Return the width that an 'M' character would occupy when typeset in WIDGET */ +static guint +calc_m_width(GtkWidget *widget, const PangoFontDescription *font_desc) +{ + PangoRectangle rect; + PangoLayout *layout ; + PangoContext * context; + + context = gtk_widget_create_pango_context (widget); + g_assert (context); + layout = pango_layout_new (context); + g_assert (layout); + + pango_layout_set_text (layout, "M", 1); + + pango_layout_set_font_description (layout, font_desc); + + pango_layout_get_extents (layout, NULL, &rect); + + g_object_unref(G_OBJECT(layout)); + g_object_unref(G_OBJECT(context)); + + return PANGO_PIXELS(rect.width); +} + + + +void +font_change_callback(GObject *obj, gpointer data) +{ + GtkWidget *sheet = data; + PsppireDataStore *ds = PSPPIRE_DATA_STORE(obj); + + ds->width_of_m = calc_m_width(sheet, ds->font_desc); +} + GtkWidget* psppire_data_sheet_create (gchar *widget_name, gchar *string1, gchar *string2, gint int1, gint int2) @@ -131,19 +166,23 @@ psppire_data_sheet_create (gchar *widget_name, gchar *string1, gchar *string2, sheet = gtk_sheet_new(G_SHEET_ROW(data_store), G_SHEET_COLUMN(data_store), "data sheet", 0); + data_store->width_of_m = calc_m_width(sheet, data_store->font_desc); - g_signal_connect (GTK_OBJECT (sheet), "activate", - GTK_SIGNAL_FUNC (update_data_ref_entry), + g_signal_connect (G_OBJECT (sheet), "activate", + G_CALLBACK (update_data_ref_entry), 0); - g_signal_connect (GTK_OBJECT (sheet), "traverse", - GTK_SIGNAL_FUNC (traverse_callback), 0); + g_signal_connect (G_OBJECT (sheet), "traverse", + G_CALLBACK (traverse_callback), 0); - g_signal_connect (GTK_OBJECT (sheet), "double-click-column", - GTK_SIGNAL_FUNC (click2column), + g_signal_connect (G_OBJECT (sheet), "double-click-column", + G_CALLBACK (click2column), 0); + g_signal_connect (G_OBJECT (data_store), "font-changed", + G_CALLBACK (font_change_callback), sheet); + gtk_sheet_set_active_cell(GTK_SHEET(sheet), -1, -1); gtk_widget_show(sheet); diff --git a/src/ui/gui/psppire-data-store.c b/src/ui/gui/psppire-data-store.c index 6c82a30b..16f709ff 100644 --- a/src/ui/gui/psppire-data-store.c +++ b/src/ui/gui/psppire-data-store.c @@ -33,6 +33,8 @@ #include #include +#include + #include "psppire-variable.h" #include "psppire-data-store.h" #include "helper.h" @@ -70,6 +72,13 @@ static gboolean psppire_data_store_clear_datum(GSheetModel *model, static GObjectClass *parent_class = NULL; + +enum {FONT_CHANGED, + n_SIGNALS}; + +static guint signal[n_SIGNALS]; + + inline GType psppire_data_store_get_type (void) { @@ -131,6 +140,7 @@ psppire_data_store_get_type (void) return data_store_type; } + static void psppire_data_store_class_init (PsppireDataStoreClass *class) { @@ -140,6 +150,16 @@ psppire_data_store_class_init (PsppireDataStoreClass *class) object_class = (GObjectClass*) class; object_class->finalize = psppire_data_store_finalize; + + signal[FONT_CHANGED] = + g_signal_new ("font_changed", + G_TYPE_FROM_CLASS(class), + G_SIGNAL_RUN_FIRST, + 0, + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); } @@ -166,6 +186,7 @@ psppire_data_store_init (PsppireDataStore *data_store) { data_store->dict = 0; data_store->case_file = 0; + data_store->width_of_m = 10; } const PangoFontDescription * @@ -531,12 +552,19 @@ psppire_data_store_set_string(GSheetModel *model, void -psppire_data_store_set_font(PsppireDataStore *store, PangoFontDescription *fd) +psppire_data_store_set_font(PsppireDataStore *store, + const PangoFontDescription *fd) { g_return_if_fail (store); g_return_if_fail (PSPPIRE_IS_DATA_STORE (store)); store->font_desc = fd; +#if 0 + store->width_of_m = calc_m_width(fd); +#endif + g_signal_emit(store, signal[FONT_CHANGED], 0); + + g_sheet_model_range_changed (G_SHEET_MODEL(store), -1, -1, -1, -1); } @@ -598,84 +626,46 @@ psppire_data_store_clear(PsppireDataStore *data_store) /* Column related funcs */ static gint -geometry_get_column_count(const GSheetColumn *geom, gpointer data) +geometry_get_column_count(const GSheetColumn *geom) { PsppireDataStore *ds = PSPPIRE_DATA_STORE(geom); return MAX(MIN_COLUMNS, psppire_dict_get_var_cnt(ds->dict)); } -/* Return the width that an 'M' character would occupy when typeset at - row, col */ -static guint -M_width(const GtkSheet *sheet, gint row, gint col) -{ - GtkSheetCellAttr attributes; - PangoRectangle rect; - /* FIXME: make this a member of the data store */ - static PangoLayout *layout = 0; - - gtk_sheet_get_attributes(sheet, row, col, &attributes); - - if (! layout ) - layout = gtk_widget_create_pango_layout (GTK_WIDGET(sheet), "M"); - - g_assert(layout); - - pango_layout_set_font_description (layout, - attributes.font_desc); - - pango_layout_get_extents (layout, NULL, &rect); - -#if 0 - g_object_unref(G_OBJECT(layout)); -#endif - - return PANGO_PIXELS(rect.width); -} - - -/* Return the number of pixels corresponding to a column of - WIDTH characters */ -static inline guint -columnWidthToPixels(GtkSheet *sheet, gint column, guint width) -{ - return (M_width(sheet, 0, column) * width); -} static gint -geometry_get_width(const GSheetColumn *geom, gint unit, GtkSheet *sheet) +geometry_get_width(const GSheetColumn *geom, gint unit) { const struct PsppireVariable *pv ; PsppireDataStore *ds = PSPPIRE_DATA_STORE(geom); if ( unit >= psppire_dict_get_var_cnt(ds->dict) ) - return 75; + return ds->width_of_m * 8 ; - /* FIXME: We can optimise this by caching the widths until they're resized */ pv = psppire_dict_get_variable(ds->dict, unit); - return columnWidthToPixels(sheet, unit, psppire_variable_get_columns(pv)); -} - - + if ( pv == NULL ) + return ds->width_of_m * 8 ; + return ds->width_of_m * psppire_variable_get_columns(pv); +} static void -geometry_set_width(GSheetColumn *geom, gint unit, gint width, GtkSheet *sheet) +geometry_set_width(GSheetColumn *geom, gint unit, gint width) { PsppireDataStore *ds = PSPPIRE_DATA_STORE(geom); struct PsppireVariable *pv = psppire_dict_get_variable(ds->dict, unit); - psppire_variable_set_columns(pv, width / M_width(sheet, 1, unit)); + psppire_variable_set_columns(pv, width / ds->width_of_m ); } static GtkJustification -geometry_get_justification(const GSheetColumn *geom, gint unit, gpointer data) +geometry_get_justification(const GSheetColumn *geom, gint unit) { PsppireDataStore *ds = PSPPIRE_DATA_STORE(geom); const struct PsppireVariable *pv ; @@ -695,8 +685,7 @@ geometry_get_justification(const GSheetColumn *geom, gint unit, gpointer data) static const gchar null_var_name[]=N_("var"); static gchar * -geometry_get_column_button_label(const GSheetColumn *geom, gint unit, - gpointer data) +geometry_get_column_button_label(const GSheetColumn *geom, gint unit) { gchar *text; struct PsppireVariable *pv ; @@ -714,7 +703,7 @@ geometry_get_column_button_label(const GSheetColumn *geom, gint unit, static gboolean -geometry_get_sensitivity(const GSheetColumn *geom, gint unit, gpointer data) +geometry_get_sensitivity(const GSheetColumn *geom, gint unit) { PsppireDataStore *ds = PSPPIRE_DATA_STORE(geom); @@ -798,7 +787,3 @@ psppire_data_store_sheet_row_init (GSheetRowIface *iface) iface->get_button_label = geometry_get_row_button_label; } - - - - diff --git a/src/ui/gui/psppire-data-store.h b/src/ui/gui/psppire-data-store.h index d9b05843..c16d158e 100644 --- a/src/ui/gui/psppire-data-store.h +++ b/src/ui/gui/psppire-data-store.h @@ -59,7 +59,11 @@ struct _PsppireDataStore /*< private >*/ PsppireDict *dict; PsppireCaseFile *case_file; - PangoFontDescription *font_desc; + const PangoFontDescription *font_desc; + + /* The width of an upper case 'M' rendered in the current font */ + gint width_of_m ; + gboolean show_labels; /* Geometry */ @@ -81,17 +85,17 @@ struct _PsppireDataStoreClass inline GType psppire_data_store_get_type (void) G_GNUC_CONST; PsppireDataStore *psppire_data_store_new (PsppireDict *dict); -void psppire_data_store_set_dictionary(PsppireDataStore *data_store, PsppireDict *dict); -void psppire_data_store_set_font(PsppireDataStore *store, PangoFontDescription *fd); +void psppire_data_store_set_dictionary(PsppireDataStore *data_store, + PsppireDict *dict); -void psppire_data_store_show_labels(PsppireDataStore *store, gboolean show_labels); +void psppire_data_store_set_font(PsppireDataStore *store, + const PangoFontDescription *fd); +void psppire_data_store_show_labels(PsppireDataStore *store, + gboolean show_labels); void psppire_data_store_clear(PsppireDataStore *data_store); - - - struct file_handle; void psppire_data_store_create_system_file(PsppireDataStore *store, -- 2.30.2