X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fgtksheet%2Fgtksheet.c;h=71c656a2b8e589458d52c66305554ba528f9705d;hb=5016e3c7d6888600553543e1a1fd6892f5328519;hp=d1a7c2e2541e46c0937d7636f0289e38ad110c68;hpb=f51fa7c449a0340d3ea94acb7401560eaad069ad;p=pspp-builds.git diff --git a/lib/gtksheet/gtksheet.c b/lib/gtksheet/gtksheet.c index d1a7c2e2..71c656a2 100644 --- a/lib/gtksheet/gtksheet.c +++ b/lib/gtksheet/gtksheet.c @@ -1,6 +1,3 @@ -#define GLIB_DISABLE_DEPRECATED 1 -#define GDK_DISABLE_DEPRECATED 1 -#define GTK_DISABLE_DEPRECATED 1 /* * Copyright (C) 2006, 2008 Free Software Foundation * @@ -56,13 +53,14 @@ #include #include #include "gtksheet.h" -#include "gtkextra-marshal.h" +#include #include "gsheetmodel.h" +#include +#include /* sheet flags */ enum { - GTK_SHEET_REDRAW_PENDING = 1 << 0, GTK_SHEET_IN_XDRAG = 1 << 1, GTK_SHEET_IN_YDRAG = 1 << 2, GTK_SHEET_IN_DRAG = 1 << 3, @@ -79,7 +77,6 @@ enum #define GTK_SHEET_IN_DRAG(sheet) (GTK_SHEET_FLAGS (sheet) & GTK_SHEET_IN_DRAG) #define GTK_SHEET_IN_SELECTION(sheet) (GTK_SHEET_FLAGS (sheet) & GTK_SHEET_IN_SELECTION) #define GTK_SHEET_IN_RESIZE(sheet) (GTK_SHEET_FLAGS (sheet) & GTK_SHEET_IN_RESIZE) -#define GTK_SHEET_REDRAW_PENDING(sheet) (GTK_SHEET_FLAGS (sheet) & GTK_SHEET_REDRAW_PENDING) #define CELL_SPACING 1 @@ -87,11 +84,12 @@ enum #define COLUMN_MIN_WIDTH 10 #define COLUMN_TITLES_HEIGHT 4 #define DEFAULT_COLUMN_WIDTH 80 +#define DEFAULT_ROW_HEIGHT 25 static void gtk_sheet_update_primary_selection (GtkSheet *sheet); -static void gtk_sheet_column_title_button_draw (GtkSheet *sheet, gint column); +static void draw_column_title_buttons_range (GtkSheet *sheet, gint first, gint n); +static void draw_row_title_buttons_range (GtkSheet *sheet, gint first, gint n); -static void gtk_sheet_row_title_button_draw (GtkSheet *sheet, gint row); static void gtk_sheet_set_row_height (GtkSheet *sheet, gint row, @@ -115,107 +113,88 @@ dispose_string (const GtkSheet *sheet, gchar *text) g_free (text); } -static guint -default_row_height (const GtkSheet *sheet) -{ - GtkWidget *widget = GTK_WIDGET (sheet); - if (!widget->style->font_desc) return 25; - else - { - PangoContext *context = gtk_widget_get_pango_context (widget); - PangoFontMetrics *metrics = - pango_context_get_metrics (context, - widget->style->font_desc, - pango_context_get_language (context)); +/* FIXME: Why bother with these two ? */ - guint val = pango_font_metrics_get_descent (metrics) + - pango_font_metrics_get_ascent (metrics); - - pango_font_metrics_unref (metrics); - - return PANGO_PIXELS (val) + 2 * COLUMN_TITLES_HEIGHT; - } -} - -static -guint STRING_WIDTH (GtkWidget *widget, - const PangoFontDescription *font, const gchar *text) +/* returns the column index from a pixel location */ +static inline gint +column_from_xpixel (const GtkSheet *sheet, gint pixel) { - PangoRectangle rect; - PangoLayout *layout; - - layout = gtk_widget_create_pango_layout (widget, text); - pango_layout_set_font_description (layout, font); - - pango_layout_get_extents (layout, NULL, &rect); - - g_object_unref (layout); - return PANGO_PIXELS (rect.width); + return psppire_axis_get_unit_at_pixel (sheet->haxis, pixel); } -/* Return the row containing pixel Y */ -static gint -yyy_row_ypixel_to_row (const GtkSheet *sheet, gint y) +static inline gint +row_from_ypixel (const GtkSheet *sheet, gint pixel) { - GSheetRow *geo = sheet->row_geometry; - - if (y < 0) - { - g_error ("This shouldnt happen"); - return -1; - } - - return g_sheet_row_pixel_to_row (geo, y); + return psppire_axis_get_unit_at_pixel (sheet->vaxis, pixel); } +/* Return the lowest row number which is wholly or partially on + the visible range of the sheet */ static inline glong min_visible_row (const GtkSheet *sheet) { - return yyy_row_ypixel_to_row (sheet, sheet->vadjustment->value); + return row_from_ypixel (sheet, sheet->vadjustment->value); } +static inline glong +min_fully_visible_row (const GtkSheet *sheet) +{ + glong row = min_visible_row (sheet); + + if ( psppire_axis_pixel_start (sheet->vaxis, row) < sheet->vadjustment->value) + row++; + + return row; +} static inline glong max_visible_row (const GtkSheet *sheet) { - return yyy_row_ypixel_to_row (sheet, - sheet->vadjustment->value + - sheet->vadjustment->page_size); + return row_from_ypixel (sheet, + sheet->vadjustment->value + + sheet->vadjustment->page_size); } -/* returns the column index from a x pixel location */ -static inline gint -column_from_xpixel (const GtkSheet *sheet, gint x) +static inline glong +max_fully_visible_row (const GtkSheet *sheet) { - gint i; - gint cx = 0; + glong row = max_visible_row (sheet); - if (x < 0) return -1; - for (i = 0; - i < g_sheet_column_get_column_count (sheet->column_geometry); i++) - { - if (x >= cx && - x <= (cx + g_sheet_column_get_width (sheet->column_geometry, i))) - return i; - - cx += g_sheet_column_get_width (sheet->column_geometry, i); - } + if ( psppire_axis_pixel_start (sheet->vaxis, row) + + + psppire_axis_unit_size (sheet->vaxis, row) + > sheet->vadjustment->value) + row--; - /* no match */ - return g_sheet_column_get_column_count (sheet->column_geometry) - 1; + return row; } +/* Returns the lowest column number which is wholly or partially + on the sheet */ static inline glong min_visible_column (const GtkSheet *sheet) { return column_from_xpixel (sheet, sheet->hadjustment->value); } +static inline glong +min_fully_visible_column (const GtkSheet *sheet) +{ + glong col = min_visible_column (sheet); + + if ( psppire_axis_pixel_start (sheet->haxis, col) < sheet->hadjustment->value) + col++; + + return col; +} + +/* Returns the highest column number which is wholly or partially + on the sheet */ static inline glong max_visible_column (const GtkSheet *sheet) { @@ -224,6 +203,21 @@ max_visible_column (const GtkSheet *sheet) sheet->hadjustment->page_size); } +static inline glong +max_fully_visible_column (const GtkSheet *sheet) +{ + glong col = max_visible_column (sheet); + + if ( psppire_axis_pixel_start (sheet->haxis, col) + + + psppire_axis_unit_size (sheet->haxis, col) + > sheet->hadjustment->value) + col--; + + return col; +} + + /* The size of the region (in pixels) around the row/column boundaries where the height/width may be grabbed to change size */ @@ -253,30 +247,6 @@ on_column_boundary (const GtkSheet *sheet, gint x, gint *column) return FALSE; } -static inline gboolean -POSSIBLE_YDRAG (const GtkSheet *sheet, gint y, gint *drag_row) -{ - gint row, ydrag; - - y += sheet->vadjustment->value; - row = yyy_row_ypixel_to_row (sheet, y); - *drag_row = row; - - ydrag = g_sheet_row_start_pixel (sheet->row_geometry, row) + CELL_SPACING; - if (y <= ydrag + DRAG_WIDTH / 2 && row != 0) - { - *drag_row = row - 1; - return g_sheet_row_get_sensitivity (sheet->row_geometry, row - 1); - } - - ydrag += g_sheet_row_get_height (sheet->row_geometry, row); - - if (y >= ydrag - DRAG_WIDTH / 2 && y <= ydrag + DRAG_WIDTH / 2) - return g_sheet_row_get_sensitivity (sheet->row_geometry, row); - - return FALSE; -} - static inline gboolean POSSIBLE_DRAG (const GtkSheet *sheet, gint x, gint y, gint *drag_row, gint *drag_column) @@ -289,20 +259,20 @@ POSSIBLE_DRAG (const GtkSheet *sheet, gint x, gint y, return FALSE; *drag_column = column_from_xpixel (sheet, x); - *drag_row = yyy_row_ypixel_to_row (sheet, y); + *drag_row = row_from_ypixel (sheet, y); - if (x >= g_sheet_column_start_pixel (sheet->column_geometry, sheet->range.col0) - DRAG_WIDTH / 2 && - x <= g_sheet_column_start_pixel (sheet->column_geometry, sheet->range.coli) + - g_sheet_column_get_width (sheet->column_geometry, sheet->range.coli) + DRAG_WIDTH / 2) + if (x >= psppire_axis_pixel_start (sheet->haxis, sheet->range.col0) - DRAG_WIDTH / 2 && + x <= psppire_axis_pixel_start (sheet->haxis, sheet->range.coli) + + psppire_axis_unit_size (sheet->haxis, sheet->range.coli) + DRAG_WIDTH / 2) { - ydrag = g_sheet_row_start_pixel (sheet->row_geometry, sheet->range.row0); + ydrag = psppire_axis_pixel_start (sheet->vaxis, sheet->range.row0); if (y >= ydrag - DRAG_WIDTH / 2 && y <= ydrag + DRAG_WIDTH / 2) { *drag_row = sheet->range.row0; return TRUE; } - ydrag = g_sheet_row_start_pixel (sheet->row_geometry, sheet->range.rowi) + - g_sheet_row_get_height (sheet->row_geometry, sheet->range.rowi); + ydrag = psppire_axis_pixel_start (sheet->vaxis, sheet->range.rowi) + + psppire_axis_unit_size (sheet->vaxis, sheet->range.rowi); if (y >= ydrag - DRAG_WIDTH / 2 && y <= ydrag + DRAG_WIDTH / 2) { *drag_row = sheet->range.rowi; @@ -310,18 +280,18 @@ POSSIBLE_DRAG (const GtkSheet *sheet, gint x, gint y, } } - if (y >= g_sheet_row_start_pixel (sheet->row_geometry, sheet->range.row0) - DRAG_WIDTH / 2 && - y <= g_sheet_row_start_pixel (sheet->row_geometry, sheet->range.rowi) + - g_sheet_row_get_height (sheet->row_geometry, sheet->range.rowi) + DRAG_WIDTH / 2) + if (y >= psppire_axis_pixel_start (sheet->vaxis, sheet->range.row0) - DRAG_WIDTH / 2 && + y <= psppire_axis_pixel_start (sheet->vaxis, sheet->range.rowi) + + psppire_axis_unit_size (sheet->vaxis, sheet->range.rowi) + DRAG_WIDTH / 2) { - xdrag = g_sheet_column_start_pixel (sheet->column_geometry, sheet->range.col0); + xdrag = psppire_axis_pixel_start (sheet->haxis, sheet->range.col0); if (x >= xdrag - DRAG_WIDTH / 2 && x <= xdrag + DRAG_WIDTH / 2) { *drag_column = sheet->range.col0; return TRUE; } - xdrag = g_sheet_column_start_pixel (sheet->column_geometry, sheet->range.coli) + - g_sheet_column_get_width (sheet->column_geometry, sheet->range.coli); + xdrag = psppire_axis_pixel_start (sheet->haxis, sheet->range.coli) + + psppire_axis_unit_size (sheet->haxis, sheet->range.coli); if (x >= xdrag - DRAG_WIDTH / 2 && x <= xdrag + DRAG_WIDTH / 2) { *drag_column = sheet->range.coli; @@ -343,20 +313,20 @@ POSSIBLE_RESIZE (const GtkSheet *sheet, gint x, gint y, sheet->range.col0 < 0 || sheet->range.coli < 0 ) return FALSE; - xdrag = g_sheet_column_start_pixel (sheet->column_geometry, sheet->range.coli)+ - g_sheet_column_get_width (sheet->column_geometry, sheet->range.coli); + xdrag = psppire_axis_pixel_start (sheet->haxis, sheet->range.coli)+ + psppire_axis_unit_size (sheet->haxis, sheet->range.coli); - ydrag = g_sheet_row_start_pixel (sheet->row_geometry, sheet->range.rowi) + - g_sheet_row_get_height (sheet->row_geometry, sheet->range.rowi); + ydrag = psppire_axis_pixel_start (sheet->vaxis, sheet->range.rowi) + + psppire_axis_unit_size (sheet->vaxis, sheet->range.rowi); if (sheet->state == GTK_SHEET_COLUMN_SELECTED) - ydrag = g_sheet_row_start_pixel (sheet->row_geometry, min_visible_row (sheet)); + ydrag = psppire_axis_pixel_start (sheet->vaxis, min_visible_row (sheet)); if (sheet->state == GTK_SHEET_ROW_SELECTED) - xdrag = g_sheet_column_start_pixel (sheet->column_geometry, min_visible_column (sheet)); + xdrag = psppire_axis_pixel_start (sheet->haxis, min_visible_column (sheet)); *drag_column = column_from_xpixel (sheet, x); - *drag_row = yyy_row_ypixel_to_row (sheet, y); + *drag_row = row_from_ypixel (sheet, y); if (x >= xdrag - DRAG_WIDTH / 2 && x <= xdrag + DRAG_WIDTH / 2 && y >= ydrag - DRAG_WIDTH / 2 && y <= ydrag + DRAG_WIDTH / 2) return TRUE; @@ -371,26 +341,26 @@ rectangle_from_range (GtkSheet *sheet, const GtkSheetRange *range, { g_return_val_if_fail (range, FALSE); - r->x = g_sheet_column_start_pixel (sheet->column_geometry, range->col0); - r->x -= sheet->hadjustment->value; + r->x = psppire_axis_pixel_start (sheet->haxis, range->col0); + r->x -= round (sheet->hadjustment->value); if ( sheet->row_titles_visible) r->x += sheet->row_title_area.width; - r->y = g_sheet_row_start_pixel (sheet->row_geometry, range->row0); - r->y -= sheet->vadjustment->value; + r->y = psppire_axis_pixel_start (sheet->vaxis, range->row0); + r->y -= round (sheet->vadjustment->value); if ( sheet->column_titles_visible) r->y += sheet->column_title_area.height; - r->width = g_sheet_column_start_pixel (sheet->column_geometry, range->coli) - - g_sheet_column_start_pixel (sheet->column_geometry, range->col0) + - g_sheet_column_get_width (sheet->column_geometry, range->coli); + r->width = psppire_axis_pixel_start (sheet->haxis, range->coli) - + psppire_axis_pixel_start (sheet->haxis, range->col0) + + psppire_axis_unit_size (sheet->haxis, range->coli); - r->height = g_sheet_row_start_pixel (sheet->row_geometry, range->rowi) - - g_sheet_row_start_pixel (sheet->row_geometry, range->row0) + - g_sheet_row_get_height (sheet->row_geometry, range->rowi); + r->height = psppire_axis_pixel_start (sheet->vaxis, range->rowi) - + psppire_axis_pixel_start (sheet->vaxis, range->row0) + + psppire_axis_unit_size (sheet->vaxis, range->rowi); return TRUE; } @@ -470,8 +440,6 @@ static void gtk_sheet_range_draw_selection (GtkSheet *sheet, /* Selection */ -static gboolean gtk_sheet_move_query (GtkSheet *sheet, - gint row, gint column); static void gtk_sheet_real_select_range (GtkSheet *sheet, const GtkSheetRange *range); static void gtk_sheet_real_unselect_range (GtkSheet *sheet, @@ -487,12 +455,11 @@ static void gtk_sheet_draw_border (GtkSheet *sheet, static void gtk_sheet_entry_changed (GtkWidget *widget, gpointer data); -static void deactivate_cell (GtkSheet *sheet); -static void gtk_sheet_hide_active_cell (GtkSheet *sheet); -static void activate_cell (GtkSheet *sheet, +static void gtk_sheet_hide_entry_widget (GtkSheet *sheet); +static void change_active_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_show_entry_widget (GtkSheet *sheet); static gboolean gtk_sheet_click_cell (GtkSheet *sheet, gint row, gint column); @@ -565,9 +532,7 @@ enum RESIZE_RANGE, MOVE_RANGE, TRAVERSE, - DEACTIVATE, ACTIVATE, - CHANGED, LAST_SIGNAL }; @@ -603,6 +568,8 @@ gtk_sheet_get_type () return sheet_type; } + + static GtkSheetRange* gtk_sheet_range_copy (const GtkSheetRange *range) { @@ -641,37 +608,76 @@ 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); -static void column_titles_changed (GtkWidget *w, gint first, gint n_columns, - gpointer data); + 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; +} + /* Properties */ enum { PROP_0, - PROP_ROW_GEO, - PROP_COL_GEO, + PROP_VAXIS, + PROP_HAXIS, PROP_MODEL }; static void -gtk_sheet_set_row_geometry (GtkSheet *sheet, GSheetRow *geo) +gtk_sheet_set_horizontal_axis (GtkSheet *sheet, PsppireAxis *a) { - if ( sheet->row_geometry ) g_object_unref (sheet->row_geometry); + if ( sheet->haxis ) + g_object_unref (sheet->haxis); - sheet->row_geometry = geo; + sheet->haxis = a; - if ( sheet->row_geometry ) g_object_ref (sheet->row_geometry); + if ( sheet->haxis ) + g_object_ref (sheet->haxis); } static void -gtk_sheet_set_column_geometry (GtkSheet *sheet, GSheetColumn *geo) +gtk_sheet_set_vertical_axis (GtkSheet *sheet, PsppireAxis *a) { - if ( sheet->column_geometry ) g_object_unref (sheet->column_geometry); + if ( sheet->vaxis ) + g_object_unref (sheet->vaxis); - sheet->column_geometry = geo; + sheet->vaxis = a; - if ( sheet->column_geometry ) g_object_ref (sheet->column_geometry); + if ( sheet->vaxis ) + g_object_ref (sheet->vaxis); } @@ -686,14 +692,11 @@ gtk_sheet_set_property (GObject *object, switch (prop_id) { - case PROP_ROW_GEO: - gtk_sheet_set_row_geometry (sheet, g_value_get_pointer (value)); + case PROP_VAXIS: + gtk_sheet_set_vertical_axis (sheet, g_value_get_pointer (value)); break; - case PROP_COL_GEO: - gtk_sheet_set_column_geometry (sheet, g_value_get_pointer (value)); - if ( sheet->column_geometry) - g_signal_connect (sheet->column_geometry, "columns_changed", - G_CALLBACK (column_titles_changed), sheet); + case PROP_HAXIS: + gtk_sheet_set_horizontal_axis (sheet, g_value_get_pointer (value)); break; case PROP_MODEL: gtk_sheet_set_model (sheet, g_value_get_pointer (value)); @@ -714,11 +717,11 @@ gtk_sheet_get_property (GObject *object, switch (prop_id) { - case PROP_ROW_GEO: - g_value_set_pointer (value, sheet->row_geometry); + case PROP_VAXIS: + g_value_set_pointer (value, sheet->vaxis); break; - case PROP_COL_GEO: - g_value_set_pointer (value, sheet->column_geometry); + case PROP_HAXIS: + g_value_set_pointer (value, sheet->haxis); break; case PROP_MODEL: g_value_set_pointer (value, sheet->model); @@ -735,8 +738,8 @@ gtk_sheet_class_init (GtkSheetClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - GParamSpec *row_geo_spec ; - GParamSpec *col_geo_spec ; + GParamSpec *haxis_spec ; + GParamSpec *vaxis_spec ; GParamSpec *model_spec ; GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); @@ -833,7 +836,7 @@ gtk_sheet_class_init (GtkSheetClass *klass) G_SIGNAL_RUN_LAST, 0, NULL, NULL, - gtkextra_VOID__INT_POINTER, + psppire_marshal_VOID__INT_POINTER, G_TYPE_NONE, 2, G_TYPE_INT, @@ -854,7 +857,7 @@ gtk_sheet_class_init (GtkSheetClass *klass) G_SIGNAL_RUN_LAST, 0, NULL, NULL, - gtkextra_VOID__INT_POINTER, + psppire_marshal_VOID__INT_POINTER, G_TYPE_NONE, 2, G_TYPE_INT, @@ -880,7 +883,7 @@ gtk_sheet_class_init (GtkSheetClass *klass) G_SIGNAL_RUN_LAST, offsetof (GtkSheetClass, resize_range), NULL, NULL, - gtkextra_VOID__BOXED_BOXED, + psppire_marshal_VOID__BOXED_BOXED, G_TYPE_NONE, 2, GTK_TYPE_SHEET_RANGE, GTK_TYPE_SHEET_RANGE @@ -892,7 +895,7 @@ gtk_sheet_class_init (GtkSheetClass *klass) G_SIGNAL_RUN_LAST, offsetof (GtkSheetClass, move_range), NULL, NULL, - gtkextra_VOID__BOXED_BOXED, + psppire_marshal_VOID__BOXED_BOXED, G_TYPE_NONE, 2, GTK_TYPE_SHEET_RANGE, GTK_TYPE_SHEET_RANGE @@ -904,19 +907,11 @@ 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); - + psppire_marshal_BOOLEAN__BOXED_POINTER, + G_TYPE_BOOLEAN, 2, + GTK_TYPE_SHEET_CELL, + G_TYPE_POINTER); - sheet_signals[DEACTIVATE] = - g_signal_new ("deactivate", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - offsetof (GtkSheetClass, deactivate), - NULL, NULL, - gtkextra_VOID__INT_INT, - G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT); sheet_signals[ACTIVATE] = g_signal_new ("activate", @@ -924,17 +919,10 @@ gtk_sheet_class_init (GtkSheetClass *klass) G_SIGNAL_RUN_LAST, offsetof (GtkSheetClass, activate), NULL, NULL, - gtkextra_VOID__INT_INT, - G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT); - - sheet_signals[CHANGED] = - g_signal_new ("changed", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - offsetof (GtkSheetClass, changed), - NULL, NULL, - gtkextra_VOID__INT_INT, - G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT); + psppire_marshal_VOID__INT_INT_INT_INT, + G_TYPE_NONE, 4, + G_TYPE_INT, G_TYPE_INT, + G_TYPE_INT, G_TYPE_INT); widget_class->set_scroll_adjustments_signal = g_signal_new ("set-scroll-adjustments", @@ -942,7 +930,7 @@ gtk_sheet_class_init (GtkSheetClass *klass) G_SIGNAL_RUN_LAST, offsetof (GtkSheetClass, set_scroll_adjustments), NULL, NULL, - gtkextra_VOID__OBJECT_OBJECT, + psppire_marshal_VOID__OBJECT_OBJECT, G_TYPE_NONE, 2, GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT); @@ -954,16 +942,16 @@ gtk_sheet_class_init (GtkSheetClass *klass) object_class->finalize = gtk_sheet_finalize; - row_geo_spec = - g_param_spec_pointer ("row-geometry", - "Row Geometry", - "A pointer to the model of the row geometry", + vaxis_spec = + g_param_spec_pointer ("vertical-axis", + "Vertical Axis", + "A pointer to the PsppireAxis object for the rows", G_PARAM_READABLE | G_PARAM_WRITABLE ); - col_geo_spec = - g_param_spec_pointer ("column-geometry", - "Column Geometry", - "A pointer to the model of the column geometry", + haxis_spec = + g_param_spec_pointer ("horizontal-axis", + "Horizontal Axis", + "A pointer to the PsppireAxis object for the columns", G_PARAM_READABLE | G_PARAM_WRITABLE ); model_spec = @@ -977,12 +965,12 @@ gtk_sheet_class_init (GtkSheetClass *klass) object_class->get_property = gtk_sheet_get_property; g_object_class_install_property (object_class, - PROP_ROW_GEO, - row_geo_spec); + PROP_VAXIS, + vaxis_spec); g_object_class_install_property (object_class, - PROP_COL_GEO, - col_geo_spec); + PROP_HAXIS, + haxis_spec); g_object_class_install_property (object_class, PROP_MODEL, @@ -1013,7 +1001,6 @@ gtk_sheet_class_init (GtkSheetClass *klass) klass->resize_range = NULL; klass->move_range = NULL; klass->traverse = NULL; - klass->deactivate = NULL; klass->activate = NULL; klass->changed = NULL; } @@ -1022,8 +1009,8 @@ static void gtk_sheet_init (GtkSheet *sheet) { sheet->model = NULL; - sheet->column_geometry = NULL; - sheet->row_geometry = NULL; + sheet->haxis = NULL; + sheet->vaxis = NULL; sheet->flags = 0; sheet->selection_mode = GTK_SELECTION_NONE; @@ -1036,7 +1023,7 @@ gtk_sheet_init (GtkSheet *sheet) sheet->column_title_area.x = 0; sheet->column_title_area.y = 0; sheet->column_title_area.width = 0; - sheet->column_title_area.height = default_row_height (sheet); + sheet->column_title_area.height = DEFAULT_ROW_HEIGHT; sheet->row_title_window = NULL; sheet->row_title_area.x = 0; @@ -1059,7 +1046,7 @@ gtk_sheet_init (GtkSheet *sheet) sheet->sheet_window = NULL; sheet->entry_widget = NULL; - sheet->entry_container = NULL; + sheet->entry_handler_id = 0; sheet->button = NULL; sheet->hadjustment = NULL; @@ -1086,7 +1073,7 @@ gtk_sheet_init (GtkSheet *sheet) /* create sheet entry */ - sheet->entry_type = 0; + sheet->entry_type = GTK_TYPE_ENTRY; create_sheet_entry (sheet); /* create global selection button */ @@ -1100,7 +1087,6 @@ columns_inserted_deleted_callback (GSheetModel *model, gint first_column, gint n_columns, gpointer data) { - gint i; GtkSheet *sheet = GTK_SHEET (data); GtkSheetRange range; @@ -1112,16 +1098,16 @@ columns_inserted_deleted_callback (GSheetModel *model, gint first_column, */ range.col0 = first_column; range.row0 = 0; - range.coli = g_sheet_column_get_column_count (sheet->column_geometry) - 1; - range.rowi = g_sheet_row_get_row_count (sheet->row_geometry) - 1; + range.coli = psppire_axis_unit_count (sheet->haxis) - 1; + range.rowi = psppire_axis_unit_count (sheet->vaxis) - 1; adjust_scrollbars (sheet); if (sheet->active_cell.col >= model_columns) - activate_cell (sheet, sheet->active_cell.row, model_columns - 1); + change_active_cell (sheet, sheet->active_cell.row, model_columns - 1); - for (i = first_column; i <= max_visible_column (sheet); i++) - gtk_sheet_column_title_button_draw (sheet, i); + draw_column_title_buttons_range (sheet, + first_column, max_visible_column (sheet)); gtk_sheet_range_draw (sheet, &range); } @@ -1132,7 +1118,6 @@ static void rows_inserted_deleted_callback (GSheetModel *model, gint first_row, gint n_rows, gpointer data) { - gint i; GtkSheet *sheet = GTK_SHEET (data); GtkSheetRange range; @@ -1144,16 +1129,15 @@ rows_inserted_deleted_callback (GSheetModel *model, gint first_row, */ range.row0 = first_row; range.col0 = 0; - range.rowi = g_sheet_row_get_row_count (sheet->row_geometry) - 1; - range.coli = g_sheet_column_get_column_count (sheet->column_geometry) - 1; + range.rowi = psppire_axis_unit_count (sheet->vaxis) - 1; + range.coli = psppire_axis_unit_count (sheet->haxis) - 1; adjust_scrollbars (sheet); if (sheet->active_cell.row >= model_rows) - activate_cell (sheet, model_rows - 1, sheet->active_cell.col); + change_active_cell (sheet, model_rows - 1, sheet->active_cell.col); - for (i = first_row; i <= max_visible_row (sheet); i++) - gtk_sheet_row_title_button_draw (sheet, i); + draw_row_title_buttons_range (sheet, first_row, max_visible_row (sheet)); gtk_sheet_range_draw (sheet, &range); } @@ -1175,27 +1159,26 @@ range_update_callback (GSheetModel *m, gint row0, gint col0, range.rowi = rowi; range.coli = coli; - if ( max_visible_row (sheet) > - g_sheet_model_get_row_count (sheet->model) + if ( !GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) + return; + + if ( max_visible_row (sheet) > g_sheet_model_get_row_count (sheet->model) || - max_visible_column (sheet) > - g_sheet_model_get_column_count (sheet->model)) + max_visible_column (sheet) > g_sheet_model_get_column_count (sheet->model)) { - gtk_sheet_move_query (sheet, 0, 0); + gtk_sheet_moveto (sheet, 0, 0, 0, 0); } if ( ( row0 < 0 && col0 < 0 ) || ( rowi < 0 && coli < 0 ) ) { - gint i; gtk_sheet_range_draw (sheet, NULL); adjust_scrollbars (sheet); - for (i = min_visible_row (sheet); i <= max_visible_row (sheet); i++) - gtk_sheet_row_title_button_draw (sheet, i); + draw_row_title_buttons_range (sheet, min_visible_row (sheet), + max_visible_row (sheet)); - for (i = min_visible_column (sheet); - i <= max_visible_column (sheet); i++) - gtk_sheet_column_title_button_draw (sheet, i); + draw_column_title_buttons_range (sheet, min_visible_column (sheet), + max_visible_column (sheet)); return; } @@ -1226,11 +1209,9 @@ range_update_callback (GSheetModel *m, gint row0, gint col0, * Returns: the new sheet widget */ GtkWidget * -gtk_sheet_new (GSheetRow *vgeo, GSheetColumn *hgeo, GSheetModel *model) +gtk_sheet_new (GSheetModel *model) { GtkWidget *widget = g_object_new (GTK_TYPE_SHEET, - "row-geometry", vgeo, - "column-geometry", hgeo, "model", model, NULL); return widget; @@ -1276,37 +1257,6 @@ gtk_sheet_set_model (GtkSheet *sheet, GSheetModel *model) } -/* Call back for when the column titles have changed. - FIRST is the first column changed. - N_COLUMNS is the number of columns which have changed, or -1, which - indicates that the column has changed to its right-most extremity -*/ -static void -column_titles_changed (GtkWidget *w, gint first, gint n_columns, gpointer data) -{ - GtkSheet *sheet = GTK_SHEET (data); - gboolean extremity = FALSE; - - if ( n_columns == -1 ) - { - extremity = TRUE; - n_columns = g_sheet_column_get_column_count (sheet->column_geometry) - 1 ; - } - - { - gint i; - for ( i = first ; i <= first + n_columns ; ++i ) - { - gtk_sheet_column_title_button_draw (sheet, i); - g_signal_emit (sheet, sheet_signals[CHANGED], 0, -1, i); - } - } - - if ( extremity) - gtk_sheet_column_title_button_draw (sheet, -1); - -} - void gtk_sheet_change_entry (GtkSheet *sheet, GtkType entry_type) { @@ -1318,7 +1268,7 @@ gtk_sheet_change_entry (GtkSheet *sheet, GtkType entry_type) state = sheet->state; if (sheet->state == GTK_SHEET_NORMAL) - gtk_sheet_hide_active_cell (sheet); + gtk_sheet_hide_entry_widget (sheet); sheet->entry_type = entry_type; @@ -1326,12 +1276,9 @@ gtk_sheet_change_entry (GtkSheet *sheet, GtkType entry_type) if (state == GTK_SHEET_NORMAL) { - gtk_sheet_show_active_cell (sheet); - g_signal_connect (gtk_sheet_get_entry (sheet), - "changed", - G_CALLBACK (gtk_sheet_entry_changed), - sheet); + gtk_sheet_show_entry_widget (sheet); } + } void @@ -1362,7 +1309,7 @@ gtk_sheet_get_columns_count (GtkSheet *sheet) g_return_val_if_fail (sheet != NULL, 0); g_return_val_if_fail (GTK_IS_SHEET (sheet), 0); - return g_sheet_column_get_column_count (sheet->column_geometry); + return psppire_axis_unit_count (sheet->haxis); } static void @@ -1371,43 +1318,6 @@ gtk_sheet_set_column_width (GtkSheet *sheet, guint width); -static void -gtk_sheet_autoresize_column (GtkSheet *sheet, gint column) -{ - gint text_width = 0; - gint row; - - g_return_if_fail (sheet != NULL); - g_return_if_fail (GTK_IS_SHEET (sheet)); - if (column >= g_sheet_column_get_column_count (sheet->column_geometry) || column < 0) return; - - for (row = 0; row < g_sheet_row_get_row_count (sheet->row_geometry); row++) - { - gchar *text = gtk_sheet_cell_get_text (sheet, row, column); - if (text && strlen (text) > 0) - { - GtkSheetCellAttr attributes; - - gtk_sheet_get_attributes (sheet, row, column, &attributes); - if (attributes.is_visible) - { - gint width = STRING_WIDTH (GTK_WIDGET (sheet), - attributes.font_desc, - text) - + 2 * COLUMN_TITLES_HEIGHT + attributes.border.width; - text_width = MAX (text_width, width); - } - } - dispose_string (sheet, text); - } - - if (text_width > g_sheet_column_get_width (sheet->column_geometry, column) ) - { - gtk_sheet_set_column_width (sheet, column, text_width); - GTK_SHEET_SET_FLAGS (sheet, GTK_SHEET_REDRAW_PENDING); - } -} - void gtk_sheet_show_column_titles (GtkSheet *sheet) { @@ -1529,16 +1439,16 @@ gtk_sheet_moveto (GtkSheet *sheet, g_return_if_fail (col_align <= 1); g_return_if_fail (col < - g_sheet_column_get_column_count (sheet->column_geometry)); + psppire_axis_unit_count (sheet->haxis)); g_return_if_fail (row < - g_sheet_row_get_row_count (sheet->row_geometry)); + psppire_axis_unit_count (sheet->vaxis)); gdk_drawable_get_size (sheet->sheet_window, &width, &height); if (row >= 0) { - gint y = g_sheet_row_start_pixel (sheet->row_geometry, row); + gint y = psppire_axis_pixel_start (sheet->vaxis, row); gtk_adjustment_set_value (sheet->vadjustment, y - height * row_align); } @@ -1546,7 +1456,7 @@ gtk_sheet_moveto (GtkSheet *sheet, if (col >= 0) { - gint x = g_sheet_column_start_pixel (sheet->column_geometry, col); + gint x = psppire_axis_pixel_start (sheet->haxis, col); gtk_adjustment_set_value (sheet->hadjustment, x - width * col_align); } @@ -1579,19 +1489,17 @@ gtk_sheet_select_row (GtkSheet *sheet, gint row) g_return_if_fail (sheet != NULL); g_return_if_fail (GTK_IS_SHEET (sheet)); - if (row < 0 || row >= g_sheet_row_get_row_count (sheet->row_geometry)) + if (row < 0 || row >= psppire_axis_unit_count (sheet->vaxis)) return; if (sheet->state != GTK_SHEET_NORMAL) gtk_sheet_real_unselect_range (sheet, NULL); - else - deactivate_cell (sheet); sheet->state = GTK_SHEET_ROW_SELECTED; sheet->range.row0 = row; sheet->range.col0 = 0; sheet->range.rowi = row; - sheet->range.coli = g_sheet_column_get_column_count (sheet->column_geometry) - 1; + sheet->range.coli = psppire_axis_unit_count (sheet->haxis) - 1; sheet->active_cell.row = row; sheet->active_cell.col = 0; @@ -1606,19 +1514,16 @@ gtk_sheet_select_column (GtkSheet *sheet, gint column) g_return_if_fail (sheet != NULL); g_return_if_fail (GTK_IS_SHEET (sheet)); - if (column < 0 || column >= g_sheet_column_get_column_count (sheet->column_geometry)) + if (column < 0 || column >= psppire_axis_unit_count (sheet->haxis)) return; if (sheet->state != GTK_SHEET_NORMAL) gtk_sheet_real_unselect_range (sheet, NULL); - else - deactivate_cell (sheet); - sheet->state = GTK_SHEET_COLUMN_SELECTED; sheet->range.row0 = 0; sheet->range.col0 = column; - sheet->range.rowi = g_sheet_row_get_row_count (sheet->row_geometry) - 1; + sheet->range.rowi = psppire_axis_unit_count (sheet->vaxis) - 1; sheet->range.coli = column; sheet->active_cell.row = 0; sheet->active_cell.col = column; @@ -1636,16 +1541,16 @@ gtk_sheet_range_isvisible (const GtkSheet *sheet, { g_return_val_if_fail (sheet != NULL, FALSE); - if (range.row0 < 0 || range.row0 >= g_sheet_row_get_row_count (sheet->row_geometry)) + if (range.row0 < 0 || range.row0 >= psppire_axis_unit_count (sheet->vaxis)) return FALSE; - if (range.rowi < 0 || range.rowi >= g_sheet_row_get_row_count (sheet->row_geometry)) + if (range.rowi < 0 || range.rowi >= psppire_axis_unit_count (sheet->vaxis)) return FALSE; - if (range.col0 < 0 || range.col0 >= g_sheet_column_get_column_count (sheet->column_geometry)) + if (range.col0 < 0 || range.col0 >= psppire_axis_unit_count (sheet->haxis)) return FALSE; - if (range.coli < 0 || range.coli >= g_sheet_column_get_column_count (sheet->column_geometry)) + if (range.coli < 0 || range.coli >= psppire_axis_unit_count (sheet->haxis)) return FALSE; if (range.rowi < min_visible_row (sheet)) @@ -1749,11 +1654,8 @@ gtk_sheet_dispose (GObject *object) sheet->dispose_has_run = TRUE; if (sheet->model) g_object_unref (sheet->model); - if (sheet->row_geometry) g_object_unref (sheet->row_geometry); - if (sheet->column_geometry) g_object_unref (sheet->column_geometry); - - g_object_unref (sheet->entry_container); - sheet->entry_container = NULL; + if (sheet->vaxis) g_object_unref (sheet->vaxis); + if (sheet->haxis) g_object_unref (sheet->haxis); g_object_unref (sheet->button); sheet->button = NULL; @@ -1807,6 +1709,8 @@ gtk_sheet_style_set (GtkWidget *widget, } +#define BORDER_WIDTH 4 + static void gtk_sheet_realize (GtkWidget *widget) { @@ -1815,7 +1719,7 @@ gtk_sheet_realize (GtkWidget *widget) const gint attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP | GDK_WA_CURSOR; - GdkGCValues values, auxvalues; + GdkGCValues values; GdkColormap *colormap; GdkDisplay *display; @@ -1912,12 +1816,10 @@ gtk_sheet_realize (GtkWidget *widget) sheet->fg_gc = gdk_gc_new (widget->window); sheet->bg_gc = gdk_gc_new (widget->window); - gdk_gc_get_values (sheet->fg_gc, &auxvalues); - values.foreground = widget->style->white; values.function = GDK_INVERT; values.subwindow_mode = GDK_INCLUDE_INFERIORS; - values.line_width = 3; + values.line_width = BORDER_WIDTH; sheet->xor_gc = gdk_gc_new_with_values (widget->window, &values, @@ -2071,7 +1973,7 @@ gtk_sheet_map (GtkWidget *widget) gtk_widget_map (GTK_BIN (sheet->button)->child); gtk_sheet_range_draw (sheet, NULL); - activate_cell (sheet, + change_active_cell (sheet, sheet->active_cell.row, sheet->active_cell.col); } @@ -2120,11 +2022,11 @@ gtk_sheet_cell_draw (GtkSheet *sheet, gint row, gint col) if (!GTK_WIDGET_DRAWABLE (sheet)) return; if (row < 0 || - row >= g_sheet_row_get_row_count (sheet->row_geometry)) + row >= psppire_axis_unit_count (sheet->vaxis)) return; if (col < 0 || - col >= g_sheet_column_get_column_count (sheet->column_geometry)) + col >= psppire_axis_unit_count (sheet->haxis)) return; gtk_sheet_get_attributes (sheet, row, col, &attributes); @@ -2148,8 +2050,6 @@ gtk_sheet_cell_draw (GtkSheet *sheet, gint row, gint col) area.width, area.height); } - // gtk_sheet_cell_draw_label (sheet, row, col); - label = gtk_sheet_cell_get_text (sheet, row, col); if (NULL == label) @@ -2220,7 +2120,7 @@ gtk_sheet_range_draw (GtkSheet *sheet, const GtkSheetRange *range) drawing_range.row0 = min_visible_row (sheet); drawing_range.col0 = min_visible_column (sheet); drawing_range.rowi = MIN (max_visible_row (sheet), - g_sheet_row_get_row_count (sheet->row_geometry) - 1); + psppire_axis_unit_count (sheet->vaxis) - 1); drawing_range.coli = max_visible_column (sheet); gdk_drawable_get_size (sheet->sheet_window, &area.width, &area.height); area.x = area.y = 0; @@ -2258,7 +2158,7 @@ gtk_sheet_range_draw (GtkSheet *sheet, const GtkSheetRange *range) sheet->active_cell.row <= drawing_range.rowi && sheet->active_cell.col >= drawing_range.col0 && sheet->active_cell.col <= drawing_range.coli) - gtk_sheet_show_active_cell (sheet); + gtk_sheet_show_entry_widget (sheet); } static void @@ -2324,16 +2224,11 @@ gtk_sheet_range_draw_selection (GtkSheet *sheet, GtkSheetRange range) gtk_sheet_draw_border (sheet, sheet->range); } -static void gtk_sheet_set_cell (GtkSheet *sheet, gint row, gint col, - GtkJustification justification, - const gchar *text); - - static inline gint safe_strcmp (const gchar *s1, const gchar *s2) { if ( !s1 && !s2) return 0; - if ( !s1) return - 1; + if ( !s1) return -1; if ( !s2) return +1; return strcmp (s1, s2); } @@ -2344,14 +2239,13 @@ gtk_sheet_set_cell (GtkSheet *sheet, gint row, gint col, const gchar *text) { GSheetModel *model ; - gboolean changed = FALSE; gchar *old_text ; g_return_if_fail (sheet != NULL); g_return_if_fail (GTK_IS_SHEET (sheet)); - if (col >= g_sheet_column_get_column_count (sheet->column_geometry) - || row >= g_sheet_row_get_row_count (sheet->row_geometry)) + if (col >= psppire_axis_unit_count (sheet->haxis) + || row >= psppire_axis_unit_count (sheet->vaxis)) return; if (col < 0 || row < 0) return; @@ -2361,13 +2255,10 @@ gtk_sheet_set_cell (GtkSheet *sheet, gint row, gint col, old_text = g_sheet_model_get_string (model, row, col); if (0 != safe_strcmp (old_text, text)) - changed = g_sheet_model_set_string (model, text, row, col); + g_sheet_model_set_string (model, text, row, col); if ( g_sheet_model_free_strings (model)) g_free (old_text); - - if ( changed ) - g_signal_emit (sheet, sheet_signals[CHANGED], 0, row, col); } @@ -2378,8 +2269,8 @@ gtk_sheet_cell_clear (GtkSheet *sheet, gint row, gint column) g_return_if_fail (sheet != NULL); g_return_if_fail (GTK_IS_SHEET (sheet)); - if (column >= g_sheet_column_get_column_count (sheet->column_geometry) || - row >= g_sheet_row_get_row_count (sheet->row_geometry)) return; + if (column >= psppire_axis_unit_count (sheet->haxis) || + row >= psppire_axis_unit_count (sheet->vaxis)) return; if (column < 0 || row < 0) return; @@ -2415,7 +2306,7 @@ gtk_sheet_cell_get_text (const GtkSheet *sheet, gint row, gint col) g_return_val_if_fail (sheet != NULL, NULL); g_return_val_if_fail (GTK_IS_SHEET (sheet), NULL); - if (col >= g_sheet_column_get_column_count (sheet->column_geometry) || row >= g_sheet_row_get_row_count (sheet->row_geometry)) + if (col >= psppire_axis_unit_count (sheet->haxis) || row >= psppire_axis_unit_count (sheet->vaxis)) return NULL; if (col < 0 || row < 0) return NULL; @@ -2436,7 +2327,7 @@ gtk_sheet_cell_get_state (GtkSheet *sheet, gint row, gint col) g_return_val_if_fail (sheet != NULL, 0); g_return_val_if_fail (GTK_IS_SHEET (sheet), 0); - if (col >= g_sheet_column_get_column_count (sheet->column_geometry) || row >= g_sheet_row_get_row_count (sheet->row_geometry)) return 0; + if (col >= psppire_axis_unit_count (sheet->haxis) || row >= psppire_axis_unit_count (sheet->vaxis)) return 0; if (col < 0 || row < 0) return 0; state = sheet->state; @@ -2500,8 +2391,8 @@ gtk_sheet_get_pixel_info (GtkSheet *sheet, } else { - trow = yyy_row_ypixel_to_row (sheet, y); - if (trow > g_sheet_row_get_row_count (sheet->row_geometry)) + trow = row_from_ypixel (sheet, y); + if (trow > psppire_axis_unit_count (sheet->vaxis)) return FALSE; } @@ -2519,7 +2410,7 @@ gtk_sheet_get_pixel_info (GtkSheet *sheet, else { tcol = column_from_xpixel (sheet, x); - if (tcol > g_sheet_column_get_column_count (sheet->column_geometry)) + if (tcol > psppire_axis_unit_count (sheet->haxis)) return FALSE; } @@ -2537,17 +2428,17 @@ gtk_sheet_get_cell_area (GtkSheet *sheet, g_return_val_if_fail (sheet != NULL, 0); g_return_val_if_fail (GTK_IS_SHEET (sheet), 0); - if (row >= g_sheet_row_get_row_count (sheet->row_geometry) || column >= g_sheet_column_get_column_count (sheet->column_geometry)) + if (row >= psppire_axis_unit_count (sheet->vaxis) || column >= psppire_axis_unit_count (sheet->haxis)) return FALSE; - area->x = (column == -1) ? 0 : g_sheet_column_start_pixel (sheet->column_geometry, column); - area->y = (row == -1) ? 0 : g_sheet_row_start_pixel (sheet->row_geometry, row); + area->x = (column == -1) ? 0 : psppire_axis_pixel_start (sheet->haxis, column); + area->y = (row == -1) ? 0 : psppire_axis_pixel_start (sheet->vaxis, row); area->width= (column == -1) ? sheet->row_title_area.width - : g_sheet_column_get_width (sheet->column_geometry, column); + : psppire_axis_unit_size (sheet->haxis, column); area->height= (row == -1) ? sheet->column_title_area.height - : g_sheet_row_get_height (sheet->row_geometry, row); + : psppire_axis_unit_size (sheet->vaxis, row); return TRUE; } @@ -2561,9 +2452,9 @@ gtk_sheet_set_active_cell (GtkSheet *sheet, gint row, gint col) if (row < -1 || col < -1) return; - if (row >= g_sheet_row_get_row_count (sheet->row_geometry) + if (row >= psppire_axis_unit_count (sheet->vaxis) || - col >= g_sheet_column_get_column_count (sheet->column_geometry)) + col >= psppire_axis_unit_count (sheet->haxis)) return; sheet->active_cell.row = row; @@ -2572,15 +2463,13 @@ gtk_sheet_set_active_cell (GtkSheet *sheet, gint row, gint col) if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) return; - deactivate_cell (sheet); - if ( row == -1 || col == -1) { - gtk_sheet_hide_active_cell (sheet); + gtk_sheet_hide_entry_widget (sheet); return; } - activate_cell (sheet, row, col); + change_active_cell (sheet, row, col); } void @@ -2618,7 +2507,7 @@ gtk_sheet_entry_changed (GtkWidget *widget, gpointer data) sheet->active_cell.row = -1; sheet->active_cell.col = -1; - text = gtk_entry_get_text (GTK_ENTRY (gtk_sheet_get_entry (sheet))); + text = gtk_entry_get_text (gtk_sheet_get_entry (sheet)); if (text && strlen (text) > 0) { @@ -2633,55 +2522,7 @@ gtk_sheet_entry_changed (GtkWidget *widget, gpointer data) static void -deactivate_cell (GtkSheet *sheet) -{ - g_return_if_fail (sheet != NULL); - g_return_if_fail (GTK_IS_SHEET (sheet)); - - if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) return ; - if (sheet->state != GTK_SHEET_NORMAL) return ; - - - if ( sheet->active_cell.row == -1 || sheet->active_cell.col == -1 ) - return ; - - /* - g_print ("%s\n", __FUNCTION__); - - - GtkSheetRange r; - r.col0 = r.coli = sheet->active_cell.col; - r.row0 = r.rowi = sheet->active_cell.row; - gtk_sheet_range_draw (sheet, &r); - */ - - - g_signal_emit (sheet, sheet_signals[DEACTIVATE], 0, - sheet->active_cell.row, - sheet->active_cell.col); - - - g_signal_handlers_disconnect_by_func (gtk_sheet_get_entry (sheet), - G_CALLBACK (gtk_sheet_entry_changed), - sheet); - - gtk_sheet_hide_active_cell (sheet); - sheet->active_cell.row = -1; - sheet->active_cell.col = -1; - -#if 0 - if (GTK_SHEET_REDRAW_PENDING (sheet)) - { - GTK_SHEET_UNSET_FLAGS (sheet, GTK_SHEET_REDRAW_PENDING); - gtk_sheet_range_draw (sheet, NULL); - } -#endif -} - - - -static void -gtk_sheet_hide_active_cell (GtkSheet *sheet) +gtk_sheet_hide_entry_widget (GtkSheet *sheet) { GdkRectangle area; @@ -2694,33 +2535,22 @@ gtk_sheet_hide_active_cell (GtkSheet *sheet) gtk_widget_hide (sheet->entry_widget); gtk_widget_unmap (sheet->entry_widget); - rectangle_from_cell (sheet, - sheet->active_cell.row, sheet->active_cell.col, - &area); - - gdk_draw_rectangle (sheet->sheet_window, - GTK_WIDGET (sheet)->style->white_gc, - TRUE, - area.x, area.y, - area.width, area.height); - - gtk_sheet_cell_draw (sheet, sheet->active_cell.row, - sheet->active_cell.col); - GTK_WIDGET_UNSET_FLAGS (GTK_WIDGET (sheet->entry_widget), GTK_VISIBLE); } static void -activate_cell (GtkSheet *sheet, gint row, gint col) +change_active_cell (GtkSheet *sheet, gint row, gint col) { - g_return_if_fail (sheet != NULL); + gint old_row, old_col; + glong old_handler_id = sheet->entry_handler_id; + g_return_if_fail (GTK_IS_SHEET (sheet)); if (row < 0 || col < 0) return; - if ( row > g_sheet_row_get_row_count (sheet->row_geometry) - || col > g_sheet_column_get_column_count (sheet->column_geometry)) + if ( row > psppire_axis_unit_count (sheet->vaxis) + || col > psppire_axis_unit_count (sheet->haxis)) return; if (sheet->state != GTK_SHEET_NORMAL) @@ -2729,6 +2559,23 @@ activate_cell (GtkSheet *sheet, gint row, gint col) gtk_sheet_real_unselect_range (sheet, NULL); } + + g_signal_handler_block (sheet->entry_widget, sheet->entry_handler_id); + + old_row = sheet->active_cell.row; + old_col = sheet->active_cell.col; + + { + /* Redraw the neighbourhood of the old active cell */ + GtkSheetRange r; + r.col0 = old_col - 1; + r.coli = old_col + 1; + r.row0 = old_row - 1; + r.rowi = old_row + 1; + gtk_sheet_range_draw (sheet, &r); + } + + sheet->range.row0 = row; sheet->range.col0 = col; sheet->range.rowi = row; @@ -2740,18 +2587,19 @@ activate_cell (GtkSheet *sheet, gint row, gint col) GTK_SHEET_UNSET_FLAGS (sheet, GTK_SHEET_IN_SELECTION); - gtk_sheet_show_active_cell (sheet); + gtk_sheet_draw_active_cell (sheet); + gtk_sheet_show_entry_widget (sheet); + - g_signal_connect (gtk_sheet_get_entry (sheet), - "changed", - G_CALLBACK (gtk_sheet_entry_changed), - sheet); + g_signal_emit (sheet, sheet_signals [ACTIVATE], 0, + row, col, old_row, old_col); - g_signal_emit (sheet, sheet_signals [ACTIVATE], 0, row, col); + if ( old_handler_id == sheet->entry_handler_id) + g_signal_handler_unblock (sheet->entry_widget, sheet->entry_handler_id); } static void -gtk_sheet_show_active_cell (GtkSheet *sheet) +gtk_sheet_show_entry_widget (GtkSheet *sheet) { GtkEntry *sheet_entry; GtkSheetCellAttr attributes; @@ -2774,7 +2622,7 @@ gtk_sheet_show_active_cell (GtkSheet *sheet) GTK_WIDGET_SET_FLAGS (GTK_WIDGET (sheet->entry_widget), GTK_VISIBLE); - sheet_entry = GTK_ENTRY (gtk_sheet_get_entry (sheet)); + sheet_entry = gtk_sheet_get_entry (sheet); gtk_sheet_get_attributes (sheet, row, col, &attributes); @@ -2783,14 +2631,11 @@ gtk_sheet_show_active_cell (GtkSheet *sheet) if ( ! text ) text = g_strdup (""); - gtk_entry_set_visibility (GTK_ENTRY (sheet_entry), attributes.is_visible); - - if ( GTK_IS_ENTRY (sheet_entry)) { const gchar *old_text = gtk_entry_get_text (GTK_ENTRY (sheet_entry)); if (strcmp (old_text, text) != 0) - gtk_entry_set_text (GTK_ENTRY (sheet_entry), text); + gtk_entry_set_text (sheet_entry, text); switch (attributes.justification) { @@ -2809,6 +2654,9 @@ gtk_sheet_show_active_cell (GtkSheet *sheet) gtk_sheet_size_allocate_entry (sheet); + gtk_widget_set_sensitive (GTK_WIDGET (sheet_entry), + g_sheet_model_is_editable (sheet->model, + row, col)); gtk_widget_map (sheet->entry_widget); gtk_widget_grab_focus (GTK_WIDGET (sheet_entry)); @@ -2898,11 +2746,11 @@ gtk_sheet_new_selection (GtkSheet *sheet, GtkSheetRange *range) if (mask1 != mask2) { - x = g_sheet_column_start_pixel (sheet->column_geometry, j); - y = g_sheet_row_start_pixel (sheet->row_geometry, i); - width = g_sheet_column_start_pixel (sheet->column_geometry, j)- x+ - g_sheet_column_get_width (sheet->column_geometry, j); - height = g_sheet_row_start_pixel (sheet->row_geometry, i) - y + g_sheet_row_get_height (sheet->row_geometry, i); + x = psppire_axis_pixel_start (sheet->haxis, j); + y = psppire_axis_pixel_start (sheet->vaxis, i); + width = psppire_axis_pixel_start (sheet->haxis, j)- x+ + psppire_axis_unit_size (sheet->haxis, j); + height = psppire_axis_pixel_start (sheet->vaxis, i) - y + psppire_axis_unit_size (sheet->vaxis, i); if (i == sheet->range.row0) { @@ -2919,12 +2767,12 @@ gtk_sheet_new_selection (GtkSheet *sheet, GtkSheetRange *range) if (i != sheet->active_cell.row || j != sheet->active_cell.col) { - x = g_sheet_column_start_pixel (sheet->column_geometry, j); - y = g_sheet_row_start_pixel (sheet->row_geometry, i); - width = g_sheet_column_start_pixel (sheet->column_geometry, j)- x+ - g_sheet_column_get_width (sheet->column_geometry, j); + x = psppire_axis_pixel_start (sheet->haxis, j); + y = psppire_axis_pixel_start (sheet->vaxis, i); + width = psppire_axis_pixel_start (sheet->haxis, j)- x+ + psppire_axis_unit_size (sheet->haxis, j); - height = g_sheet_row_start_pixel (sheet->row_geometry, i) - y + g_sheet_row_get_height (sheet->row_geometry, i); + height = psppire_axis_pixel_start (sheet->vaxis, i) - y + psppire_axis_unit_size (sheet->vaxis, i); if (i == new_range.row0) { @@ -2962,10 +2810,10 @@ gtk_sheet_new_selection (GtkSheet *sheet, GtkSheetRange *range) if (state == GTK_STATE_SELECTED && !selected) { - x = g_sheet_column_start_pixel (sheet->column_geometry, j); - y = g_sheet_row_start_pixel (sheet->row_geometry, i); - width = g_sheet_column_start_pixel (sheet->column_geometry, j) - x + g_sheet_column_get_width (sheet->column_geometry, j); - height = g_sheet_row_start_pixel (sheet->row_geometry, i) - y + g_sheet_row_get_height (sheet->row_geometry, i); + x = psppire_axis_pixel_start (sheet->haxis, j); + y = psppire_axis_pixel_start (sheet->vaxis, i); + width = psppire_axis_pixel_start (sheet->haxis, j) - x + psppire_axis_unit_size (sheet->haxis, j); + height = psppire_axis_pixel_start (sheet->vaxis, i) - y + psppire_axis_unit_size (sheet->vaxis, i); if (i == sheet->range.row0) { @@ -2997,10 +2845,10 @@ gtk_sheet_new_selection (GtkSheet *sheet, GtkSheetRange *range) (i != sheet->active_cell.row || j != sheet->active_cell.col)) { - x = g_sheet_column_start_pixel (sheet->column_geometry, j); - y = g_sheet_row_start_pixel (sheet->row_geometry, i); - width = g_sheet_column_start_pixel (sheet->column_geometry, j) - x + g_sheet_column_get_width (sheet->column_geometry, j); - height = g_sheet_row_start_pixel (sheet->row_geometry, i) - y + g_sheet_row_get_height (sheet->row_geometry, i); + x = psppire_axis_pixel_start (sheet->haxis, j); + y = psppire_axis_pixel_start (sheet->vaxis, i); + width = psppire_axis_pixel_start (sheet->haxis, j) - x + psppire_axis_unit_size (sheet->haxis, j); + height = psppire_axis_pixel_start (sheet->vaxis, i) - y + psppire_axis_unit_size (sheet->vaxis, i); if (i == new_range.row0) { @@ -3043,10 +2891,10 @@ gtk_sheet_new_selection (GtkSheet *sheet, GtkSheetRange *range) mask2 = j == new_range.coli ? mask2 + 8 : mask2; if (mask2 != mask1 || (mask2 == mask1 && state != GTK_STATE_SELECTED)) { - x = g_sheet_column_start_pixel (sheet->column_geometry, j); - y = g_sheet_row_start_pixel (sheet->row_geometry, i); - width = g_sheet_column_get_width (sheet->column_geometry, j); - height = g_sheet_row_get_height (sheet->row_geometry, i); + x = psppire_axis_pixel_start (sheet->haxis, j); + y = psppire_axis_pixel_start (sheet->vaxis, i); + width = psppire_axis_unit_size (sheet->haxis, j); + height = psppire_axis_unit_size (sheet->vaxis, i); if (mask2 & 1) gdk_draw_rectangle (sheet->sheet_window, sheet->xor_gc, @@ -3083,6 +2931,8 @@ gtk_sheet_new_selection (GtkSheet *sheet, GtkSheetRange *range) *range = new_range; } + + static void gtk_sheet_draw_border (GtkSheet *sheet, GtkSheetRange new_range) { @@ -3093,10 +2943,10 @@ gtk_sheet_draw_border (GtkSheet *sheet, GtkSheetRange new_range) gdk_draw_rectangle (sheet->sheet_window, sheet->xor_gc, FALSE, - area.x + 1, - area.y + 1, - area.width - 2, - area.height - 2); + area.x - BORDER_WIDTH / 2, + area.y - BORDER_WIDTH / 2, + area.width + BORDER_WIDTH, + area.height + BORDER_WIDTH); } @@ -3156,8 +3006,6 @@ gtk_sheet_select_range (GtkSheet *sheet, const GtkSheetRange *range) if (sheet->state != GTK_SHEET_NORMAL) gtk_sheet_real_unselect_range (sheet, NULL); - else - deactivate_cell (sheet); sheet->range.row0 = range->row0; sheet->range.rowi = range->rowi; @@ -3181,7 +3029,7 @@ gtk_sheet_unselect_range (GtkSheet *sheet) gtk_sheet_real_unselect_range (sheet, NULL); sheet->state = GTK_STATE_NORMAL; - activate_cell (sheet, + change_active_cell (sheet, sheet->active_cell.row, sheet->active_cell.col); } @@ -3234,29 +3082,27 @@ gtk_sheet_expose (GtkWidget *widget, if (event->window == sheet->row_title_window && sheet->row_titles_visible) { - gint i; - for (i = min_visible_row (sheet); i <= max_visible_row (sheet); i++) - gtk_sheet_row_title_button_draw (sheet, i); + draw_row_title_buttons_range (sheet, + min_visible_row (sheet), + max_visible_row (sheet)); } if (event->window == sheet->column_title_window && sheet->column_titles_visible) { - gint i; - for (i = min_visible_column (sheet); - i <= max_visible_column (sheet); - ++i) - gtk_sheet_column_title_button_draw (sheet, i); + draw_column_title_buttons_range (sheet, + min_visible_column (sheet), + max_visible_column (sheet)); } range.row0 = - yyy_row_ypixel_to_row (sheet, + row_from_ypixel (sheet, event->area.y + sheet->vadjustment->value); range.row0--; range.rowi = - yyy_row_ypixel_to_row (sheet, + row_from_ypixel (sheet, event->area.y + event->area.height + sheet->vadjustment->value); range.rowi++; @@ -3272,6 +3118,7 @@ gtk_sheet_expose (GtkWidget *widget, sheet->hadjustment->value); range.coli++; + if (event->window == sheet->sheet_window) { gtk_sheet_range_draw (sheet, &range); @@ -3297,9 +3144,6 @@ gtk_sheet_expose (GtkWidget *widget, } } - if (sheet->state != GTK_SHEET_NORMAL && GTK_SHEET_IN_SELECTION (sheet)) - gtk_widget_grab_focus (GTK_WIDGET (sheet)); - (* GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event); return FALSE; @@ -3339,10 +3183,12 @@ gtk_sheet_button_press (GtkWidget *widget, sheet_signals[BUTTON_EVENT_COLUMN], 0, column, event); - if ( event->type == GDK_2BUTTON_PRESS && event->button == 1) - g_signal_emit (sheet, - sheet_signals[DOUBLE_CLICK_COLUMN], 0, column); - + if (g_sheet_model_get_column_sensitivity (sheet->model, column)) + { + if ( event->type == GDK_2BUTTON_PRESS && event->button == 1) + g_signal_emit (sheet, + sheet_signals[DOUBLE_CLICK_COLUMN], 0, column); + } } else if (event->window == sheet->row_title_window) { @@ -3350,12 +3196,14 @@ gtk_sheet_button_press (GtkWidget *widget, sheet_signals[BUTTON_EVENT_ROW], 0, row, event); - if ( event->type == GDK_2BUTTON_PRESS && event->button == 1) - g_signal_emit (sheet, - sheet_signals[DOUBLE_CLICK_ROW], 0, row); + if (g_sheet_model_get_row_sensitivity (sheet->model, row)) + { + if ( event->type == GDK_2BUTTON_PRESS && event->button == 1) + g_signal_emit (sheet, + sheet_signals[DOUBLE_CLICK_ROW], 0, row); + } } - gdk_window_get_pointer (widget->window, NULL, NULL, &mods); if (! (mods & GDK_BUTTON1_MASK)) return TRUE; @@ -3376,12 +3224,6 @@ gtk_sheet_button_press (GtkWidget *widget, if (on_column_boundary (sheet, sheet->x_drag, &sheet->drag_cell.col)) { guint req; - if (event->type == GDK_2BUTTON_PRESS) - { - gtk_sheet_autoresize_column (sheet, sheet->drag_cell.col); - GTK_SHEET_UNSET_FLAGS (sheet, GTK_SHEET_IN_XDRAG); - return TRUE; - } gtk_sheet_column_size_request (sheet, sheet->drag_cell.col, &req); GTK_SHEET_SET_FLAGS (sheet, GTK_SHEET_IN_XDRAG); gdk_pointer_grab (sheet->column_title_window, FALSE, @@ -3399,6 +3241,7 @@ gtk_sheet_button_press (GtkWidget *widget, { gtk_widget_get_pointer (widget, NULL, &sheet->y_drag); +#if AXIS_TRANSITION if (POSSIBLE_YDRAG (sheet, sheet->y_drag, &sheet->drag_cell.row)) { guint req; @@ -3413,6 +3256,7 @@ gtk_sheet_button_press (GtkWidget *widget, draw_xor_hline (sheet); return TRUE; } +#endif } /* the sheet itself does not handle other than single click events */ @@ -3445,7 +3289,6 @@ gtk_sheet_button_press (GtkWidget *widget, { row = sheet->active_cell.row; column = sheet->active_cell.col; - deactivate_cell (sheet); sheet->active_cell.row = row; sheet->active_cell.col = column; sheet->drag_range = sheet->range; @@ -3473,7 +3316,6 @@ gtk_sheet_button_press (GtkWidget *widget, { row = sheet->active_cell.row; column = sheet->active_cell.col; - deactivate_cell (sheet); sheet->active_cell.row = row; sheet->active_cell.col = column; sheet->drag_range = sheet->range; @@ -3509,7 +3351,7 @@ gtk_sheet_button_press (GtkWidget *widget, column = column_from_xpixel (sheet, x); - if (g_sheet_column_get_sensitivity (sheet->column_geometry, column)) + if (g_sheet_model_get_column_sensitivity (sheet->model, column)) { veto = gtk_sheet_click_cell (sheet, -1, column); gtk_grab_add (GTK_WIDGET (sheet)); @@ -3526,8 +3368,8 @@ gtk_sheet_button_press (GtkWidget *widget, y += sheet->vadjustment->value; - row = yyy_row_ypixel_to_row (sheet, y); - if (g_sheet_row_get_sensitivity (sheet->row_geometry, row)) + row = row_from_ypixel (sheet, y); + if (g_sheet_model_get_row_sensitivity (sheet->model, row)) { veto = gtk_sheet_click_cell (sheet, row, -1); gtk_grab_add (GTK_WIDGET (sheet)); @@ -3542,17 +3384,22 @@ gtk_sheet_button_press (GtkWidget *widget, static gboolean gtk_sheet_click_cell (GtkSheet *sheet, gint row, gint column) { + GtkSheetCell cell; gboolean forbid_move; - if (row >= g_sheet_row_get_row_count (sheet->row_geometry) - || column >= g_sheet_column_get_column_count (sheet->column_geometry)) + cell.row = row; + cell.col = column; + + if (row >= psppire_axis_unit_count (sheet->vaxis) + || column >= psppire_axis_unit_count (sheet->haxis)) { 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) { @@ -3562,7 +3409,7 @@ gtk_sheet_click_cell (GtkSheet *sheet, gint row, gint column) row = sheet->active_cell.row; column = sheet->active_cell.col; - activate_cell (sheet, row, column); + change_active_cell (sheet, row, column); return FALSE; } @@ -3582,9 +3429,9 @@ gtk_sheet_click_cell (GtkSheet *sheet, gint row, gint column) { sheet->range.row0 = 0; sheet->range.col0 = 0; - sheet->range.rowi = g_sheet_row_get_row_count (sheet->row_geometry) - 1; + sheet->range.rowi = psppire_axis_unit_count (sheet->vaxis) - 1; sheet->range.coli = - g_sheet_column_get_column_count (sheet->column_geometry) - 1; + psppire_axis_unit_count (sheet->haxis) - 1; sheet->active_cell.row = 0; sheet->active_cell.col = 0; gtk_sheet_select_range (sheet, NULL); @@ -3598,8 +3445,7 @@ gtk_sheet_click_cell (GtkSheet *sheet, gint row, gint column) } else { - deactivate_cell (sheet); - activate_cell (sheet, row, column); + change_active_cell (sheet, row, column); } sheet->active_cell.row = row; @@ -3717,7 +3563,7 @@ gtk_sheet_button_release (GtkWidget *widget, { GTK_SHEET_UNSET_FLAGS (sheet, GTK_SHEET_IN_SELECTION); gdk_display_pointer_ungrab (display, event->time); - activate_cell (sheet, sheet->active_cell.row, + change_active_cell (sheet, sheet->active_cell.row, sheet->active_cell.col); } @@ -3855,10 +3701,7 @@ motion_timeout_callback (gpointer data) { if (sheet->row_title_under) { - GSheetRow *row_geo = sheet->row_geometry; - gchar *text; - - text = g_sheet_row_get_subtitle (row_geo, row); + gchar *text = g_sheet_model_get_row_subtitle (sheet->model, row); show_subtitle (sheet, row, -1, text); g_free (text); @@ -3866,10 +3709,8 @@ motion_timeout_callback (gpointer data) if (sheet->column_title_under) { - GSheetColumn *col_geo = sheet->column_geometry; - gchar *text; - - text = g_sheet_column_get_subtitle (col_geo, column); + gchar *text = g_sheet_model_get_column_subtitle (sheet->model, + column); show_subtitle (sheet, -1, column, text); @@ -3957,6 +3798,7 @@ gtk_sheet_motion (GtkWidget *widget, GdkEventMotion *event) if (event->window == sheet->row_title_window && gtk_sheet_rows_resizable (sheet)) { +#if AXIS_TRANSITION if (!GTK_SHEET_IN_SELECTION (sheet) && POSSIBLE_YDRAG (sheet, y, &column)) { new_cursor = GDK_SB_V_DOUBLE_ARROW; @@ -3968,6 +3810,7 @@ gtk_sheet_motion (GtkWidget *widget, GdkEventMotion *event) } } else +#endif { new_cursor = GDK_TOP_LEFT_ARROW; if (!GTK_SHEET_IN_YDRAG (sheet) && @@ -4060,14 +3903,14 @@ gtk_sheet_motion (GtkWidget *widget, GdkEventMotion *event) { GtkSheetRange aux; column = column_from_xpixel (sheet, x)- sheet->drag_cell.col; - row = yyy_row_ypixel_to_row (sheet, y) - sheet->drag_cell.row; + row = row_from_ypixel (sheet, y) - sheet->drag_cell.row; if (sheet->state == GTK_SHEET_COLUMN_SELECTED) row = 0; if (sheet->state == GTK_SHEET_ROW_SELECTED) column = 0; sheet->x_drag = x; sheet->y_drag = y; aux = sheet->range; - if (aux.row0 + row >= 0 && aux.rowi + row < g_sheet_row_get_row_count (sheet->row_geometry) && - aux.col0 + column >= 0 && aux.coli + column < g_sheet_column_get_column_count (sheet->column_geometry)) + if (aux.row0 + row >= 0 && aux.rowi + row < psppire_axis_unit_count (sheet->vaxis) && + aux.col0 + column >= 0 && aux.coli + column < psppire_axis_unit_count (sheet->haxis)) { aux = sheet->drag_range; sheet->drag_range.row0 = sheet->range.row0 + row; @@ -4089,18 +3932,18 @@ gtk_sheet_motion (GtkWidget *widget, GdkEventMotion *event) GtkSheetRange aux; gint v_h, current_col, current_row, col_threshold, row_threshold; v_h = 1; - if (abs (x - g_sheet_column_start_pixel (sheet->column_geometry, sheet->drag_cell.col)) > - abs (y - g_sheet_row_start_pixel (sheet->row_geometry, sheet->drag_cell.row))) v_h = 2; + if (abs (x - psppire_axis_pixel_start (sheet->haxis, sheet->drag_cell.col)) > + abs (y - psppire_axis_pixel_start (sheet->vaxis, sheet->drag_cell.row))) v_h = 2; current_col = column_from_xpixel (sheet, x); - current_row = yyy_row_ypixel_to_row (sheet, y); + current_row = row_from_ypixel (sheet, y); column = current_col - sheet->drag_cell.col; row = current_row - sheet->drag_cell.row; /*use half of column width resp. row height as threshold to expand selection*/ - col_threshold = g_sheet_column_start_pixel (sheet->column_geometry, current_col) + - g_sheet_column_get_width (sheet->column_geometry, current_col) / 2; + col_threshold = psppire_axis_pixel_start (sheet->haxis, current_col) + + psppire_axis_unit_size (sheet->haxis, current_col) / 2; if (column > 0) { if (x < col_threshold) @@ -4111,8 +3954,8 @@ gtk_sheet_motion (GtkWidget *widget, GdkEventMotion *event) if (x > col_threshold) column +=1; } - row_threshold = g_sheet_row_start_pixel (sheet->row_geometry, current_row) + - g_sheet_row_get_height (sheet->row_geometry, current_row)/2; + row_threshold = psppire_axis_pixel_start (sheet->vaxis, current_row) + + psppire_axis_unit_size (sheet->vaxis, current_row)/2; if (row > 0) { if (y < row_threshold) @@ -4135,8 +3978,8 @@ gtk_sheet_motion (GtkWidget *widget, GdkEventMotion *event) else row = 0; - if (aux.row0 + row >= 0 && aux.rowi + row < g_sheet_row_get_row_count (sheet->row_geometry) && - aux.col0 + column >= 0 && aux.coli + column < g_sheet_column_get_column_count (sheet->column_geometry)) + if (aux.row0 + row >= 0 && aux.rowi + row < psppire_axis_unit_count (sheet->vaxis) && + aux.col0 + column >= 0 && aux.coli + column < psppire_axis_unit_count (sheet->haxis)) { aux = sheet->drag_range; sheet->drag_range = sheet->range; @@ -4183,71 +4026,6 @@ gtk_sheet_crossing_notify (GtkWidget *widget, return TRUE; } - -static gboolean -gtk_sheet_move_query (GtkSheet *sheet, gint row, gint column) -{ - gint height, width; - gint new_row = row; - gint new_col = column; - - gint row_move = FALSE; - gint column_move = FALSE; - gfloat row_align = -1.0; - gfloat col_align = -1.0; - - if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) - return FALSE; - - gdk_drawable_get_size (sheet->sheet_window, &width, &height); - - if (row >= max_visible_row (sheet) && - sheet->state != GTK_SHEET_COLUMN_SELECTED) - { - row_align = 1.; - new_row = MIN (g_sheet_row_get_row_count (sheet->row_geometry) - 1, row + 1); - row_move = TRUE; - if (max_visible_row (sheet) == g_sheet_row_get_row_count (sheet->row_geometry) - 1 && - g_sheet_row_start_pixel (sheet->row_geometry, g_sheet_row_get_row_count (sheet->row_geometry) - 1) + - g_sheet_row_get_height (sheet->row_geometry, g_sheet_row_get_row_count (sheet->row_geometry) - 1) < height) - { - row_move = FALSE; - row_align = -1.; - } - } - - if (row < min_visible_row (sheet) && sheet->state != GTK_SHEET_COLUMN_SELECTED) - { - row_align= 0.; - row_move = TRUE; - } - if (column >= max_visible_column (sheet) && sheet->state != GTK_SHEET_ROW_SELECTED) - { - col_align = 1.; - new_col = MIN (g_sheet_column_get_column_count (sheet->column_geometry) - 1, column + 1); - column_move = TRUE; - if (max_visible_column (sheet) == (g_sheet_column_get_column_count (sheet->column_geometry) - 1) && - g_sheet_column_start_pixel (sheet->column_geometry, g_sheet_column_get_column_count (sheet->column_geometry) - 1) + - g_sheet_column_get_width (sheet->column_geometry, g_sheet_column_get_column_count (sheet->column_geometry) - 1) < width) - { - column_move = FALSE; - col_align = -1.; - } - } - if (column < min_visible_column (sheet) && sheet->state != GTK_SHEET_ROW_SELECTED) - { - col_align = 0.0; - column_move = TRUE; - } - - if (row_move || column_move) - { - gtk_sheet_moveto (sheet, new_row, new_col, row_align, col_align); - } - - return (row_move || column_move); -} - static void gtk_sheet_extend_selection (GtkSheet *sheet, gint row, gint column) { @@ -4260,7 +4038,6 @@ gtk_sheet_extend_selection (GtkSheet *sheet, gint row, gint column) if (sheet->selection_mode == GTK_SELECTION_SINGLE) return; - gtk_sheet_move_query (sheet, row, column); gtk_widget_grab_focus (GTK_WIDGET (sheet)); if (GTK_SHEET_IN_DRAG (sheet)) return; @@ -4270,10 +4047,10 @@ gtk_sheet_extend_selection (GtkSheet *sheet, gint row, gint column) switch (sheet->state) { case GTK_SHEET_ROW_SELECTED: - column = g_sheet_column_get_column_count (sheet->column_geometry) - 1; + column = psppire_axis_unit_count (sheet->haxis) - 1; break; case GTK_SHEET_COLUMN_SELECTED: - row = g_sheet_row_get_row_count (sheet->row_geometry) - 1; + row = psppire_axis_unit_count (sheet->vaxis) - 1; break; case GTK_SHEET_NORMAL: sheet->state = GTK_SHEET_RANGE_SELECTED; @@ -4321,11 +4098,11 @@ static void page_vertical (GtkSheet *sheet, GtkScrollType dir) { gint old_row = sheet->active_cell.row ; - glong vpixel = g_sheet_row_start_pixel (sheet->row_geometry, old_row); + glong vpixel = psppire_axis_pixel_start (sheet->vaxis, old_row); gint new_row; - vpixel -= g_sheet_row_start_pixel (sheet->row_geometry, + vpixel -= psppire_axis_pixel_start (sheet->vaxis, min_visible_row (sheet)); switch ( dir) @@ -4347,60 +4124,109 @@ page_vertical (GtkSheet *sheet, GtkScrollType dir) } - vpixel += g_sheet_row_start_pixel (sheet->row_geometry, + vpixel += psppire_axis_pixel_start (sheet->vaxis, min_visible_row (sheet)); - new_row = yyy_row_ypixel_to_row (sheet, vpixel); + new_row = row_from_ypixel (sheet, vpixel); - activate_cell (sheet, new_row, + change_active_cell (sheet, new_row, sheet->active_cell.col); } static void -step_horizontal (GtkSheet *sheet, GtkScrollType dir) +step_sheet (GtkSheet *sheet, GtkScrollType dir) { + gint current_row = sheet->active_cell.row; + gint current_col = sheet->active_cell.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_cell.row++; + break; + case GTK_SCROLL_STEP_UP: + new_cell.row--; + break; case GTK_SCROLL_STEP_RIGHT: - - activate_cell (sheet, - sheet->active_cell.row, - sheet->active_cell.col + 1); + new_cell.col++; break; case GTK_SCROLL_STEP_LEFT: - - activate_cell (sheet, - sheet->active_cell.row, - sheet->active_cell.col - 1); + new_cell.col--; break; - default: g_assert_not_reached (); break; } - if ( sheet->active_cell.col >= max_visible_column (sheet)) + + maximize_int (&new_cell.row, 0); + maximize_int (&new_cell.col, 0); + + minimize_int (&new_cell.row, + psppire_axis_unit_count (sheet->vaxis) - 1); + + minimize_int (&new_cell.col, + psppire_axis_unit_count (sheet->haxis) - 1); + + g_signal_emit (sheet, sheet_signals[TRAVERSE], 0, + &sheet->active_cell, + &new_cell, + &forbidden); + + if (forbidden) + return; + + change_active_cell (sheet, new_cell.row, new_cell.col); + + if ( new_cell.col > max_fully_visible_column (sheet)) { glong hpos = - g_sheet_column_start_pixel (sheet->column_geometry, - sheet->active_cell.col + 1); + psppire_axis_pixel_start (sheet->haxis, + new_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)) + else if ( new_cell.col < min_fully_visible_column (sheet)) { glong hpos = - g_sheet_column_start_pixel (sheet->column_geometry, - sheet->active_cell.col); + psppire_axis_pixel_start (sheet->haxis, + new_cell.col); gtk_adjustment_set_value (sheet->hadjustment, hpos); } + + + if ( new_cell.row > max_fully_visible_row (sheet)) + { + glong vpos = + psppire_axis_pixel_start (sheet->vaxis, + new_cell.row + 1); + vpos -= sheet->vadjustment->page_size; + + gtk_adjustment_set_value (sheet->vadjustment, + vpos); + } + else if ( new_cell.row < min_fully_visible_row (sheet)) + { + glong vpos = + psppire_axis_pixel_start (sheet->vaxis, + new_cell.row); + + gtk_adjustment_set_value (sheet->vadjustment, + vpos); + } } + static gboolean gtk_sheet_key_press (GtkWidget *widget, GdkEventKey *key) @@ -4413,33 +4239,18 @@ gtk_sheet_key_press (GtkWidget *widget, { case GDK_Tab: case GDK_Right: - step_horizontal (sheet, GTK_SCROLL_STEP_RIGHT); + step_sheet (sheet, GTK_SCROLL_STEP_RIGHT); break; case GDK_ISO_Left_Tab: case GDK_Left: - step_horizontal (sheet, GTK_SCROLL_STEP_LEFT); + step_sheet (sheet, GTK_SCROLL_STEP_LEFT); break; - case GDK_Return: case GDK_Down: - activate_cell (sheet, - sheet->active_cell.row + ROWS_PER_STEP, - sheet->active_cell.col); - - if ( sheet->active_cell.row >= max_visible_row (sheet)) - gtk_adjustment_set_value (sheet->vadjustment, - sheet->vadjustment->value + - sheet->vadjustment->step_increment); + step_sheet (sheet, GTK_SCROLL_STEP_DOWN); break; case GDK_Up: - activate_cell (sheet, - sheet->active_cell.row - ROWS_PER_STEP, - sheet->active_cell.col); - - if ( sheet->active_cell.row < min_visible_row (sheet)) - gtk_adjustment_set_value (sheet->vadjustment, - sheet->vadjustment->value - - sheet->vadjustment->step_increment); + step_sheet (sheet, GTK_SCROLL_STEP_UP); break; case GDK_Page_Down: @@ -4453,7 +4264,7 @@ gtk_sheet_key_press (GtkWidget *widget, gtk_adjustment_set_value (sheet->vadjustment, sheet->vadjustment->lower); - activate_cell (sheet, 0, + change_active_cell (sheet, 0, sheet->active_cell.col); break; @@ -4465,8 +4276,8 @@ gtk_sheet_key_press (GtkWidget *widget, sheet->vadjustment->page_increment); /* - activate_cell (sheet, - g_sheet_row_get_row_count (sheet->row_geometry) - 1, + change_active_cellx (sheet, + psppire_axis_unit_count (sheet->vaxis) - 1, sheet->active_cell.col); */ break; @@ -4494,7 +4305,7 @@ gtk_sheet_size_request (GtkWidget *widget, sheet = GTK_SHEET (widget); requisition->width = 3 * DEFAULT_COLUMN_WIDTH; - requisition->height = 3 * default_row_height (sheet); + requisition->height = 3 * DEFAULT_ROW_HEIGHT; /* compute the size of the column title area */ if (sheet->column_titles_visible) @@ -4529,14 +4340,6 @@ gtk_sheet_size_allocate (GtkWidget *widget, allocation->width - 2 * border_width, allocation->height - 2 * border_width); - /* use internal allocation structure for all the math - * because it's easier than always subtracting the container - * border width */ - sheet->internal_allocation.x = 0; - sheet->internal_allocation.y = 0; - sheet->internal_allocation.width = allocation->width - 2 * border_width; - sheet->internal_allocation.height = allocation->height - 2 * border_width; - sheet_allocation.x = 0; sheet_allocation.y = 0; sheet_allocation.width = allocation->width - 2 * border_width; @@ -4552,13 +4355,19 @@ gtk_sheet_size_allocate (GtkWidget *widget, /* position the window which holds the column title buttons */ sheet->column_title_area.x = 0; sheet->column_title_area.y = 0; + sheet->column_title_area.width = sheet_allocation.width ; + + + /* position the window which holds the row title buttons */ + sheet->row_title_area.x = 0; + sheet->row_title_area.y = 0; + sheet->row_title_area.height = sheet_allocation.height; if (sheet->row_titles_visible) - { - sheet->column_title_area.x = sheet->row_title_area.width; - } + sheet->column_title_area.x += sheet->row_title_area.width; - sheet->column_title_area.width = sheet_allocation.width ; + if (sheet->column_titles_visible) + sheet->row_title_area.y += sheet->column_title_area.height; if (GTK_WIDGET_REALIZED (widget) && sheet->column_titles_visible) @@ -4569,20 +4378,6 @@ gtk_sheet_size_allocate (GtkWidget *widget, sheet->column_title_area.height); - /* column button allocation */ - draw_column_title_buttons (sheet); - - /* position the window which holds the row title buttons */ - sheet->row_title_area.x = 0; - sheet->row_title_area.y = 0; - if (sheet->column_titles_visible) - { - sheet->row_title_area.y = sheet->column_title_area.height; - } - - sheet->row_title_area.height = sheet_allocation.height - - sheet->row_title_area.y; - if (GTK_WIDGET_REALIZED (widget) && sheet->row_titles_visible) gdk_window_move_resize (sheet->row_title_window, sheet->row_title_area.x, @@ -4590,10 +4385,31 @@ gtk_sheet_size_allocate (GtkWidget *widget, sheet->row_title_area.width, sheet->row_title_area.height); + if (sheet->haxis) + { + gint width = sheet->column_title_area.width; + + if ( sheet->row_titles_visible) + width -= sheet->row_title_area.width; + + g_object_set (sheet->haxis, + "minimum-extent", width, + NULL); + } + + + if (sheet->vaxis) + { + gint height = sheet->row_title_area.height; + + if ( sheet->column_titles_visible) + height -= sheet->column_title_area.height; + + g_object_set (sheet->vaxis, + "minimum-extent", height, + NULL); + } - /* row button allocation */ - draw_row_title_buttons (sheet); - draw_column_title_buttons (sheet); /* set the scrollbars adjustments */ adjust_scrollbars (sheet); @@ -4602,7 +4418,6 @@ gtk_sheet_size_allocate (GtkWidget *widget, static void draw_column_title_buttons (GtkSheet *sheet) { - gint i; gint x, width; if (!sheet->column_titles_visible) return; @@ -4629,7 +4444,7 @@ draw_column_title_buttons (GtkSheet *sheet) } if (max_visible_column (sheet) == - g_sheet_column_get_column_count (sheet->column_geometry) - 1) + psppire_axis_unit_count (sheet->haxis) - 1) gdk_window_clear_area (sheet->column_title_window, 0, 0, sheet->column_title_area.width, @@ -4639,14 +4454,13 @@ draw_column_title_buttons (GtkSheet *sheet) size_allocate_global_button (sheet); - for (i = min_visible_column (sheet); i <= max_visible_column (sheet); i++) - gtk_sheet_column_title_button_draw (sheet, i); + draw_column_title_buttons_range (sheet, min_visible_column (sheet), + max_visible_column (sheet)); } static void draw_row_title_buttons (GtkSheet *sheet) { - gint i; gint y = 0; gint height; @@ -4672,7 +4486,7 @@ draw_row_title_buttons (GtkSheet *sheet) sheet->row_title_area.height); } - if (max_visible_row (sheet) == g_sheet_row_get_row_count (sheet->row_geometry) - 1) + if (max_visible_row (sheet) == psppire_axis_unit_count (sheet->vaxis) - 1) gdk_window_clear_area (sheet->row_title_window, 0, 0, sheet->row_title_area.width, @@ -4682,12 +4496,9 @@ draw_row_title_buttons (GtkSheet *sheet) size_allocate_global_button (sheet); - for (i = min_visible_row (sheet); i <= max_visible_row (sheet); i++) - { - if ( i >= g_sheet_row_get_row_count (sheet->row_geometry)) - break; - gtk_sheet_row_title_button_draw (sheet, i); - } + + draw_row_title_buttons_range (sheet, min_visible_row (sheet), + max_visible_row (sheet)); } @@ -4698,19 +4509,16 @@ gtk_sheet_size_allocate_entry (GtkSheet *sheet) GtkSheetCellAttr attributes = { 0 }; GtkEntry *sheet_entry; - if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) return; if (!GTK_WIDGET_MAPPED (GTK_WIDGET (sheet))) return; - sheet_entry = GTK_ENTRY (gtk_sheet_get_entry (sheet)); + sheet_entry = gtk_sheet_get_entry (sheet); if ( ! gtk_sheet_get_attributes (sheet, sheet->active_cell.row, sheet->active_cell.col, &attributes) ) return ; - gtk_widget_ensure_style (GTK_WIDGET (sheet_entry)); - if ( GTK_WIDGET_REALIZED (sheet->entry_widget) ) { GtkStyle *style = GTK_WIDGET (sheet_entry)->style; @@ -4721,10 +4529,6 @@ gtk_sheet_size_allocate_entry (GtkSheet *sheet) 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); } rectangle_from_cell (sheet, sheet->active_cell.row, @@ -4744,29 +4548,8 @@ create_sheet_entry (GtkSheet *sheet) gtk_widget_unparent (sheet->entry_widget); } - if (sheet->entry_type) - { - sheet->entry_container = g_object_new (sheet->entry_type, NULL); - g_object_ref_sink (sheet->entry_container); - sheet->entry_widget = gtk_sheet_get_entry (sheet); - - if ( NULL == sheet->entry_widget) - { - g_warning ("Entry type is %s. It must be GtkEntry subclass, or a widget containing one. " - "Using default", g_type_name (sheet->entry_type)); - g_object_unref (sheet->entry_container); - sheet->entry_widget = sheet->entry_container = gtk_entry_new (); - } - else - { - sheet->entry_widget = sheet->entry_container ; - } - } - else - { - sheet->entry_widget = sheet->entry_container = gtk_entry_new (); - g_object_ref_sink (sheet->entry_container); - } + sheet->entry_widget = g_object_new (sheet->entry_type, NULL); + g_object_ref_sink (sheet->entry_widget); gtk_widget_size_request (sheet->entry_widget, NULL); @@ -4781,6 +4564,12 @@ create_sheet_entry (GtkSheet *sheet) G_CALLBACK (gtk_sheet_entry_key_press), sheet); + sheet->entry_handler_id = + g_signal_connect (sheet->entry_widget, + "changed", + G_CALLBACK (gtk_sheet_entry_changed), + sheet); + gtk_widget_show (sheet->entry_widget); } @@ -4796,48 +4585,37 @@ find_entry (GtkWidget *w, gpointer user_data) } } -GtkWidget * + +GtkEntry * gtk_sheet_get_entry (GtkSheet *sheet) { - GtkWidget *parent; - GtkWidget *entry = NULL; + GtkWidget *w = sheet->entry_widget; g_return_val_if_fail (sheet != NULL, NULL); g_return_val_if_fail (GTK_IS_SHEET (sheet), NULL); g_return_val_if_fail (sheet->entry_widget != NULL, NULL); - if (GTK_IS_ENTRY (sheet->entry_container)) - return (sheet->entry_container); - - parent = sheet->entry_container; - - if (GTK_IS_CONTAINER (parent)) + while (! GTK_IS_ENTRY (w)) { - gtk_container_forall (GTK_CONTAINER (parent), find_entry, &entry); + GtkWidget *entry = NULL; - if (GTK_IS_ENTRY (entry)) - return entry; - } - - if (!GTK_IS_ENTRY (entry)) return NULL; - - return (entry); + if (GTK_IS_CONTAINER (w)) + { + gtk_container_forall (GTK_CONTAINER (w), find_entry, &entry); -} + if (NULL == entry) + break; -GtkWidget * -gtk_sheet_get_entry_widget (GtkSheet *sheet) -{ - g_return_val_if_fail (sheet != NULL, NULL); - g_return_val_if_fail (GTK_IS_SHEET (sheet), NULL); - g_return_val_if_fail (sheet->entry_widget != NULL, NULL); + w = entry; + } + } - return (sheet->entry_widget); + return GTK_ENTRY (w); } static void -gtk_sheet_button_draw (GtkSheet *sheet, GdkWindow *window, +draw_button (GtkSheet *sheet, GdkWindow *window, GtkSheetButton *button, gboolean is_sensitive, GdkRectangle allocation) { @@ -4848,8 +4626,6 @@ gtk_sheet_button_draw (GtkSheet *sheet, GdkWindow *window, gboolean rtl ; gint state = 0; - gint len = 0; - gchar *line = 0; g_return_if_fail (sheet != NULL); g_return_if_fail (button != NULL); @@ -4886,8 +4662,7 @@ gtk_sheet_button_draw (GtkSheet *sheet, GdkWindow *window, if (button->label_visible) { - - text_height = default_row_height (sheet) - + text_height = DEFAULT_ROW_HEIGHT - 2 * COLUMN_TITLES_HEIGHT; gdk_gc_set_clip_rectangle (GTK_WIDGET (sheet)->style->fg_gc[button->state], @@ -4897,68 +4672,46 @@ gtk_sheet_button_draw (GtkSheet *sheet, GdkWindow *window, allocation.y += 2 * sheet->button->style->ythickness; - if (button->label && strlen (button->label)>0) { - gchar *words = 0; + PangoRectangle rect; + gchar *line = button->label; + PangoLayout *layout = NULL; - gint real_x = allocation.x, real_y = allocation.y; + gint real_x = allocation.x; + gint real_y = allocation.y; - words = button->label; - line = g_new (gchar, 1); - line[0]='\0'; + layout = gtk_widget_create_pango_layout (GTK_WIDGET (sheet), line); + pango_layout_get_extents (layout, NULL, &rect); - while (words && *words != '\0') + text_width = PANGO_PIXELS (rect.width); + switch (button->justification) { - if (*words != '\n') - { - len = strlen (line); - line = g_realloc (line, len + 2); - line[len]=*words; - line[len + 1]='\0'; - } - if (*words == '\n' || * (words + 1) == '\0') - { - text_width = STRING_WIDTH (GTK_WIDGET (sheet), GTK_WIDGET (sheet)->style->font_desc, line); - - layout = gtk_widget_create_pango_layout (GTK_WIDGET (sheet), line); - switch (button->justification) - { - case GTK_JUSTIFY_LEFT: - real_x = allocation.x + COLUMN_TITLES_HEIGHT; - align = rtl ? PANGO_ALIGN_RIGHT : PANGO_ALIGN_LEFT; - break; - case GTK_JUSTIFY_RIGHT: - real_x = allocation.x + allocation.width - text_width - COLUMN_TITLES_HEIGHT; - align = rtl ? PANGO_ALIGN_LEFT : PANGO_ALIGN_RIGHT; - break; - case GTK_JUSTIFY_CENTER: - default: - real_x = allocation.x + (allocation.width - text_width)/2; - align = rtl ? PANGO_ALIGN_RIGHT : PANGO_ALIGN_LEFT; - pango_layout_set_justify (layout, TRUE); - } - pango_layout_set_alignment (layout, align); - gtk_paint_layout (GTK_WIDGET (sheet)->style, - window, - state, - FALSE, - &allocation, - GTK_WIDGET (sheet), - "label", - real_x, real_y, - layout); - g_object_unref (layout); - - real_y += text_height + 2; - - g_free (line); - line = g_new (gchar, 1); - line[0]='\0'; - } - words++; + case GTK_JUSTIFY_LEFT: + real_x = allocation.x + COLUMN_TITLES_HEIGHT; + align = rtl ? PANGO_ALIGN_RIGHT : PANGO_ALIGN_LEFT; + break; + case GTK_JUSTIFY_RIGHT: + real_x = allocation.x + allocation.width - text_width - COLUMN_TITLES_HEIGHT; + align = rtl ? PANGO_ALIGN_LEFT : PANGO_ALIGN_RIGHT; + break; + case GTK_JUSTIFY_CENTER: + default: + real_x = allocation.x + (allocation.width - text_width)/2; + align = rtl ? PANGO_ALIGN_RIGHT : PANGO_ALIGN_LEFT; + pango_layout_set_justify (layout, TRUE); } - g_free (line); + pango_layout_set_alignment (layout, align); + gtk_paint_layout (GTK_WIDGET (sheet)->style, + window, + state, + FALSE, + &allocation, + GTK_WIDGET (sheet), + "label", + real_x, real_y, + layout); + g_object_unref (layout); } gdk_gc_set_clip_rectangle (GTK_WIDGET (sheet)->style->fg_gc[button->state], @@ -4970,60 +4723,90 @@ gtk_sheet_button_draw (GtkSheet *sheet, GdkWindow *window, gtk_sheet_button_free (button); } + +/* Draw the column title buttons FIRST through to LAST */ static void -gtk_sheet_column_title_button_draw (GtkSheet *sheet, gint column) +draw_column_title_buttons_range (GtkSheet *sheet, gint first, gint last) { - GdkRectangle allocation; - GtkSheetButton *button = NULL; - gboolean is_sensitive = FALSE; - + GdkRegion *region; + gint col; if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) return; if (!sheet->column_titles_visible) return; - if (column < min_visible_column (sheet)) return; - if (column > max_visible_column (sheet)) return; + g_return_if_fail (first >= min_visible_column (sheet)); + g_return_if_fail (last <= max_visible_column (sheet)); - button = g_sheet_column_get_button (sheet->column_geometry, column); - allocation.y = 0; - allocation.x = g_sheet_column_start_pixel (sheet->column_geometry, column) + CELL_SPACING; - allocation.x -= sheet->hadjustment->value; + region = + gdk_drawable_get_visible_region (GDK_DRAWABLE (sheet->column_title_window)); - allocation.height = sheet->column_title_area.height; - allocation.width = g_sheet_column_get_width (sheet->column_geometry, column); - is_sensitive = g_sheet_column_get_sensitivity (sheet->column_geometry, column); + gdk_window_begin_paint_region (sheet->column_title_window, region); + + for (col = first ; col <= last ; ++col) + { + GdkRectangle allocation; + gboolean is_sensitive = FALSE; + + GtkSheetButton * + button = g_sheet_model_get_column_button (sheet->model, col); + allocation.y = 0; + allocation.x = psppire_axis_pixel_start (sheet->haxis, col) + + CELL_SPACING; + allocation.x -= sheet->hadjustment->value; - gtk_sheet_button_draw (sheet, sheet->column_title_window, - button, is_sensitive, allocation); + allocation.height = sheet->column_title_area.height; + allocation.width = psppire_axis_unit_size (sheet->haxis, col); + is_sensitive = g_sheet_model_get_column_sensitivity (sheet->model, col); + + draw_button (sheet, sheet->column_title_window, + button, is_sensitive, allocation); + } + + gdk_window_end_paint (sheet->column_title_window); } static void -gtk_sheet_row_title_button_draw (GtkSheet *sheet, gint row) +draw_row_title_buttons_range (GtkSheet *sheet, gint first, gint last) { - GdkRectangle allocation; - GtkSheetButton *button = NULL; - gboolean is_sensitive = FALSE; - - + GdkRegion *region; + gint row; if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) return; if (!sheet->row_titles_visible) return; - if (row < min_visible_row (sheet)) return; - if (row > max_visible_row (sheet)) return; + g_return_if_fail (first >= min_visible_row (sheet)); + g_return_if_fail (last <= max_visible_row (sheet)); - button = g_sheet_row_get_button (sheet->row_geometry, row); - allocation.x = 0; - allocation.y = g_sheet_row_start_pixel (sheet->row_geometry, row) + CELL_SPACING; - allocation.y -= sheet->vadjustment->value; - allocation.width = sheet->row_title_area.width; - allocation.height = g_sheet_row_get_height (sheet->row_geometry, row); - is_sensitive = g_sheet_row_get_sensitivity (sheet->row_geometry, row); + region = + gdk_drawable_get_visible_region (GDK_DRAWABLE (sheet->row_title_window)); + + gdk_window_begin_paint_region (sheet->row_title_window, region); + - gtk_sheet_button_draw (sheet, sheet->row_title_window, - button, is_sensitive, allocation); + for (row = first; row <= last; ++row) + { + GdkRectangle allocation; + + gboolean is_sensitive = FALSE; + + GtkSheetButton *button = + g_sheet_model_get_row_button (sheet->model, row); + allocation.x = 0; + allocation.y = psppire_axis_pixel_start (sheet->vaxis, row) + + CELL_SPACING; + allocation.y -= sheet->vadjustment->value; + + allocation.width = sheet->row_title_area.width; + allocation.height = psppire_axis_unit_size (sheet->vaxis, row); + is_sensitive = g_sheet_model_get_row_sensitivity (sheet->model, row); + + draw_button (sheet, sheet->row_title_window, + button, is_sensitive, allocation); + } + + gdk_window_end_paint (sheet->row_title_window); } /* SCROLLBARS @@ -5043,30 +4826,33 @@ adjust_scrollbars (GtkSheet *sheet) gdk_drawable_get_size (sheet->sheet_window, &width, &height); + if ( sheet->row_titles_visible) + width -= sheet->row_title_area.width; + + if (sheet->column_titles_visible) + height -= sheet->column_title_area.height; + if (sheet->vadjustment) { - glong last_row = g_sheet_row_get_row_count (sheet->row_geometry) - 1; + glong last_row = psppire_axis_unit_count (sheet->vaxis) - 1; sheet->vadjustment->step_increment = ROWS_PER_STEP * - g_sheet_row_get_height (sheet->row_geometry, last_row); + psppire_axis_unit_size (sheet->vaxis, last_row); sheet->vadjustment->page_increment = height - sheet->column_title_area.height - - g_sheet_row_get_height (sheet->row_geometry, last_row); + psppire_axis_unit_size (sheet->vaxis, last_row); sheet->vadjustment->upper = - g_sheet_row_start_pixel (sheet->row_geometry, last_row) + psppire_axis_pixel_start (sheet->vaxis, last_row) + - g_sheet_row_get_height (sheet->row_geometry, last_row) + psppire_axis_unit_size (sheet->vaxis, last_row) ; - if (sheet->column_titles_visible) - sheet->vadjustment->upper += sheet->column_title_area.height; - sheet->vadjustment->lower = 0; sheet->vadjustment->page_size = height; @@ -5080,17 +4866,14 @@ adjust_scrollbars (GtkSheet *sheet) sheet->hadjustment->page_increment = width; - last_col = g_sheet_column_get_column_count (sheet->column_geometry) - 1; + last_col = psppire_axis_unit_count (sheet->haxis) - 1; sheet->hadjustment->upper = - g_sheet_column_start_pixel (sheet->column_geometry, last_col) + psppire_axis_pixel_start (sheet->haxis, last_col) + - g_sheet_column_get_width (sheet->column_geometry, last_col) + psppire_axis_unit_size (sheet->haxis, last_col) ; - if (sheet->row_titles_visible) - sheet->hadjustment->upper += sheet->row_title_area.width; - sheet->hadjustment->lower = 0; sheet->hadjustment->page_size = width; @@ -5203,12 +4986,12 @@ draw_xor_rectangle (GtkSheet *sheet, GtkSheetRange range) GdkRectangle clip_area, area; GdkGCValues values; - area.x = g_sheet_column_start_pixel (sheet->column_geometry, range.col0); - area.y = g_sheet_row_start_pixel (sheet->row_geometry, range.row0); - area.width = g_sheet_column_start_pixel (sheet->column_geometry, range.coli)- area.x+ - g_sheet_column_get_width (sheet->column_geometry, range.coli); - area.height = g_sheet_row_start_pixel (sheet->row_geometry, range.rowi)- area.y + - g_sheet_row_get_height (sheet->row_geometry, range.rowi); + area.x = psppire_axis_pixel_start (sheet->haxis, range.col0); + area.y = psppire_axis_pixel_start (sheet->vaxis, range.row0); + area.width = psppire_axis_pixel_start (sheet->haxis, range.coli)- area.x+ + psppire_axis_unit_size (sheet->haxis, range.coli); + area.height = psppire_axis_pixel_start (sheet->vaxis, range.rowi)- area.y + + psppire_axis_unit_size (sheet->vaxis, range.rowi); clip_area.x = sheet->row_title_area.width; clip_area.y = sheet->column_title_area.height; @@ -5261,7 +5044,7 @@ draw_xor_rectangle (GtkSheet *sheet, GtkSheetRange range) static guint new_column_width (GtkSheet *sheet, gint column, gint *x) { - gint left_pos = g_sheet_column_start_pixel (sheet->column_geometry, column) + gint left_pos = psppire_axis_pixel_start (sheet->haxis, column) - sheet->hadjustment->value; gint width = *x - left_pos; @@ -5272,7 +5055,9 @@ new_column_width (GtkSheet *sheet, gint column, gint *x) *x = left_pos + width; } +#if AXIS_TRANSITION g_sheet_column_set_width (sheet->column_geometry, column, width); +#endif draw_column_title_buttons (sheet); @@ -5292,19 +5077,21 @@ new_row_height (GtkSheet *sheet, gint row, gint *y) min_height = sheet->row_requisition; /* you can't shrink a row to less than its minimum height */ - if (cy < g_sheet_row_start_pixel (sheet->row_geometry, row) + min_height) + if (cy < psppire_axis_pixel_start (sheet->vaxis, row) + min_height) { - *y = cy = g_sheet_row_start_pixel (sheet->row_geometry, row) + min_height; + *y = cy = psppire_axis_pixel_start (sheet->vaxis, row) + min_height; } /* calculate new row height making sure it doesn't end up * less than the minimum height */ - height = (cy - g_sheet_row_start_pixel (sheet->row_geometry, row)); + height = (cy - psppire_axis_pixel_start (sheet->vaxis, row)); if (height < min_height) height = min_height; +#if AXIS_TRANSITION g_sheet_row_set_height (sheet->row_geometry, row, height); +#endif draw_row_title_buttons (sheet); return height; @@ -5320,13 +5107,15 @@ gtk_sheet_set_column_width (GtkSheet *sheet, g_return_if_fail (sheet != NULL); g_return_if_fail (GTK_IS_SHEET (sheet)); - if (column < 0 || column >= g_sheet_column_get_column_count (sheet->column_geometry)) + if (column < 0 || column >= psppire_axis_unit_count (sheet->haxis)) return; gtk_sheet_column_size_request (sheet, column, &min_width); if (width < min_width) return; +#if AXIS_TRANSITION g_sheet_column_set_width (sheet->column_geometry, column, width); +#endif if (GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) { @@ -5335,8 +5124,6 @@ gtk_sheet_set_column_width (GtkSheet *sheet, gtk_sheet_size_allocate_entry (sheet); gtk_sheet_range_draw (sheet, NULL); } - - g_signal_emit (sheet, sheet_signals[CHANGED], 0, -1, column); } @@ -5351,13 +5138,15 @@ gtk_sheet_set_row_height (GtkSheet *sheet, g_return_if_fail (sheet != NULL); g_return_if_fail (GTK_IS_SHEET (sheet)); - if (row < 0 || row >= g_sheet_row_get_row_count (sheet->row_geometry)) + if (row < 0 || row >= psppire_axis_unit_count (sheet->vaxis)) return; gtk_sheet_row_size_request (sheet, row, &min_height); if (height < min_height) return; +#if AXIS_TRANSITION g_sheet_row_set_height (sheet->row_geometry, row, height); +#endif if (GTK_WIDGET_REALIZED (GTK_WIDGET (sheet)) ) { @@ -5366,8 +5155,6 @@ gtk_sheet_set_row_height (GtkSheet *sheet, gtk_sheet_size_allocate_entry (sheet); gtk_sheet_range_draw (sheet, NULL); } - - g_signal_emit (sheet, sheet_signals[CHANGED], 0, row, - 1); } gboolean @@ -5385,7 +5172,6 @@ gtk_sheet_get_attributes (const GtkSheet *sheet, gint row, gint col, if (row < 0 || col < 0) return FALSE; - attr->foreground = GTK_WIDGET (sheet)->style->black; attr->background = sheet->color[BG_COLOR]; @@ -5398,8 +5184,6 @@ gtk_sheet_get_attributes (const GtkSheet *sheet, gint row, gint col, attr->font_desc = GTK_WIDGET (sheet)->style->font_desc; attr->is_editable = g_sheet_model_is_editable (sheet->model, row, col); - attr->is_visible = g_sheet_model_is_visible (sheet->model, row, col); - colormap = gtk_widget_get_colormap (GTK_WIDGET (sheet)); fg = g_sheet_model_get_foreground (sheet->model, row, col); @@ -5417,7 +5201,7 @@ gtk_sheet_get_attributes (const GtkSheet *sheet, gint row, gint col, } attr->justification = - g_sheet_column_get_justification (sheet->column_geometry, col); + g_sheet_model_get_column_justification (sheet->model, col); j = g_sheet_model_get_justification (sheet->model, row, col); if (j) @@ -5441,10 +5225,10 @@ gtk_sheet_button_size_request (GtkSheet *sheet, GtkRequisition requisition; GtkRequisition label_requisition; - label_requisition.height = default_row_height (sheet); + label_requisition.height = DEFAULT_ROW_HEIGHT; label_requisition.width = COLUMN_MIN_WIDTH; - requisition.height = default_row_height (sheet); + requisition.height = DEFAULT_ROW_HEIGHT; requisition.width = COLUMN_MIN_WIDTH; @@ -5462,7 +5246,7 @@ gtk_sheet_row_size_request (GtkSheet *sheet, GtkRequisition button_requisition; gtk_sheet_button_size_request (sheet, - g_sheet_row_get_button (sheet->row_geometry, row), + g_sheet_model_get_row_button (sheet->model, row), &button_requisition); *requisition = button_requisition.height; @@ -5477,7 +5261,7 @@ gtk_sheet_column_size_request (GtkSheet *sheet, { GtkRequisition button_requisition; - GtkSheetButton *button = g_sheet_column_get_button (sheet->column_geometry, col); + GtkSheetButton *button = g_sheet_model_get_column_button (sheet->model, col); gtk_sheet_button_size_request (sheet, button, @@ -5504,8 +5288,8 @@ gtk_sheet_forall (GtkContainer *container, if (sheet->button && sheet->button->parent) (* callback) (sheet->button, callback_data); - if (sheet->entry_container && GTK_IS_CONTAINER (sheet->entry_container)) - (* callback) (sheet->entry_container, callback_data); + if (sheet->entry_widget && GTK_IS_CONTAINER (sheet->entry_widget)) + (* callback) (sheet->entry_widget, callback_data); } @@ -5541,7 +5325,6 @@ gtk_sheet_button_free (GtkSheetButton *button) g_free (button); } - static void append_cell_text (GString *string, const GtkSheet *sheet, gint r, gint c) {