X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fgtksheet%2Fgtksheet.c;h=2e5351191490e54a0d2f36dc14056f9055d06c69;hb=d32776c387defa54d9b853c3925211f17028b99e;hp=57ae79dfe36d3abb03c3164f5d55df41bb012ec8;hpb=543b33d52255b74980108967e55422a77152a48f;p=pspp diff --git a/lib/gtksheet/gtksheet.c b/lib/gtksheet/gtksheet.c index 57ae79dfe3..2e53511914 100644 --- a/lib/gtksheet/gtksheet.c +++ b/lib/gtksheet/gtksheet.c @@ -73,8 +73,7 @@ enum GTK_SHEET_IN_DRAG = 1 << 4, GTK_SHEET_IN_SELECTION = 1 << 5, GTK_SHEET_IN_RESIZE = 1 << 6, - GTK_SHEET_IN_CLIP = 1 << 7, - GTK_SHEET_REDRAW_PENDING = 1 << 8, + GTK_SHEET_REDRAW_PENDING = 1 << 7, }; #define GTK_SHEET_FLAGS(sheet) (GTK_SHEET (sheet)->flags) @@ -90,12 +89,11 @@ 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_IN_CLIP(sheet) (GTK_SHEET_FLAGS (sheet) & GTK_SHEET_IN_CLIP) #define GTK_SHEET_REDRAW_PENDING(sheet) (GTK_SHEET_FLAGS (sheet) & GTK_SHEET_REDRAW_PENDING) #define CELL_SPACING 1 #define DRAG_WIDTH 6 -#define TIMEOUT_FLASH 200 +#define TIMEOUT_HOVER 300 #define TIME_INTERVAL 8 #define COLUMN_MIN_WIDTH 10 #define MINROWS 1 @@ -105,6 +103,9 @@ enum #define DEFAULT_COLUMN_WIDTH 80 +static void gtk_sheet_update_primary_selection (GtkSheet *sheet); + + static void gtk_sheet_column_title_button_draw (GtkSheet *sheet, gint column); static void gtk_sheet_row_title_button_draw (GtkSheet *sheet, gint row); @@ -135,10 +136,13 @@ guint DEFAULT_ROW_HEIGHT (GtkWidget *widget) pango_context_get_metrics (context, widget->style->font_desc, pango_context_get_language (context)); + guint val = pango_font_metrics_get_descent (metrics) + pango_font_metrics_get_ascent (metrics); + pango_font_metrics_unref (metrics); - return PANGO_PIXELS (val)+2 * CELLOFFSET; + + return PANGO_PIXELS (val) + 2 * CELLOFFSET; } } @@ -448,7 +452,7 @@ yyy_set_row_height (GtkSheet *sheet, gint row, gint height) /* returns the total width of the sheet */ static inline gint SHEET_WIDTH (GtkSheet *sheet) { - gint i,cx; + gint i, cx; cx = ( sheet->row_titles_visible ? sheet->row_title_area.width : 0); @@ -459,10 +463,18 @@ static inline gint SHEET_WIDTH (GtkSheet *sheet) return cx; } -#define MIN_VISIBLE_ROW(sheet) sheet->view.row0 -#define MAX_VISIBLE_ROW(sheet) sheet->view.rowi -#define MIN_VISIBLE_COLUMN(sheet) sheet->view.col0 -#define MAX_VISIBLE_COLUMN(sheet) sheet->view.coli +#define MIN_VISIBLE_ROW(sheet) \ + ROW_FROM_YPIXEL (sheet, sheet->column_title_area.height + 1) + +#define MAX_VISIBLE_ROW(sheet) \ + ROW_FROM_YPIXEL (sheet, sheet->sheet_window_height - 1) + +#define MIN_VISIBLE_COLUMN(sheet) \ + COLUMN_FROM_XPIXEL (sheet, sheet->row_title_area.width + 1) + +#define MAX_VISIBLE_COLUMN(sheet) \ + COLUMN_FROM_XPIXEL (sheet, sheet->sheet_window_width) + static inline gboolean @@ -495,7 +507,7 @@ POSSIBLE_YDRAG (const GtkSheet *sheet, gint y, gint *drag_row) row = ROW_FROM_YPIXEL (sheet, y); *drag_row = row; - ydrag = ROW_TOP_YPIXEL (sheet,row)+CELL_SPACING; + ydrag = ROW_TOP_YPIXEL (sheet, row)+CELL_SPACING; if (y <= ydrag + DRAG_WIDTH / 2 && row != 0) { while (!yyy_row_is_visible (sheet, row - 1) && row > 0) row--; @@ -530,7 +542,7 @@ POSSIBLE_DRAG (const GtkSheet *sheet, gint x, gint y, x <= COLUMN_LEFT_XPIXEL (sheet, sheet->range.coli) + xxx_column_width (sheet, sheet->range.coli) + DRAG_WIDTH / 2) { - ydrag = ROW_TOP_YPIXEL (sheet,sheet->range.row0); + ydrag = ROW_TOP_YPIXEL (sheet, sheet->range.row0); if (y >= ydrag - DRAG_WIDTH / 2 && y <= ydrag + DRAG_WIDTH / 2) { *drag_row = sheet->range.row0; @@ -578,20 +590,20 @@ POSSIBLE_RESIZE (const GtkSheet *sheet, gint x, gint y, sheet->range.col0 < 0 || sheet->range.coli < 0 ) return FALSE; - xdrag = COLUMN_LEFT_XPIXEL (sheet,sheet->range.coli)+ + xdrag = COLUMN_LEFT_XPIXEL (sheet, sheet->range.coli)+ xxx_column_width (sheet, sheet->range.coli); - ydrag = ROW_TOP_YPIXEL (sheet,sheet->range.rowi)+ + ydrag = ROW_TOP_YPIXEL (sheet, sheet->range.rowi)+ yyy_row_height (sheet, sheet->range.rowi); if (sheet->state == GTK_SHEET_COLUMN_SELECTED) - ydrag = ROW_TOP_YPIXEL (sheet, sheet->view.row0); + ydrag = ROW_TOP_YPIXEL (sheet, MIN_VISIBLE_ROW (sheet)); if (sheet->state == GTK_SHEET_ROW_SELECTED) - xdrag = COLUMN_LEFT_XPIXEL (sheet, sheet->view.col0); + xdrag = COLUMN_LEFT_XPIXEL (sheet, MIN_VISIBLE_COLUMN (sheet)); - *drag_column = COLUMN_FROM_XPIXEL (sheet,x); - *drag_row = ROW_FROM_YPIXEL (sheet,y); + *drag_column = COLUMN_FROM_XPIXEL (sheet, x); + *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; @@ -637,14 +649,10 @@ static void gtk_sheet_size_allocate (GtkWidget * widget, /* Sheet queries */ -static gint gtk_sheet_range_isvisible (GtkSheet * sheet, - GtkSheetRange range); -static gint gtk_sheet_cell_isvisible (GtkSheet * sheet, - gint row, gint column); -/* Clipped Range */ - -static gint gtk_sheet_flash (gpointer data); - +static gboolean gtk_sheet_range_isvisible (const GtkSheet * sheet, + GtkSheetRange range); +static gboolean gtk_sheet_cell_isvisible (GtkSheet * sheet, + gint row, gint column); /* Drawing Routines */ /* draw cell background and frame */ @@ -705,10 +713,6 @@ static void gtk_sheet_draw_backing_pixmap (GtkSheet *sheet, /* Scrollbars */ static void adjust_scrollbars (GtkSheet * sheet); -static void vadjustment_changed (GtkAdjustment * adjustment, - gpointer data); -static void hadjustment_changed (GtkAdjustment * adjustment, - gpointer data); static void vadjustment_value_changed (GtkAdjustment * adjustment, gpointer data); static void hadjustment_value_changed (GtkAdjustment * adjustment, @@ -719,8 +723,7 @@ static void draw_xor_vline (GtkSheet * sheet); static void draw_xor_hline (GtkSheet * sheet); static void draw_xor_rectangle (GtkSheet *sheet, GtkSheetRange range); -static void gtk_sheet_draw_flashing_range (GtkSheet *sheet, - GtkSheetRange range); + static guint new_column_width (GtkSheet * sheet, gint column, gint * x); @@ -756,12 +759,11 @@ static void init_attributes (const GtkSheet *sheet, gint col, /* Memory allocation routines */ static void gtk_sheet_real_range_clear (GtkSheet *sheet, - const GtkSheetRange *range, - gboolean delete); + const GtkSheetRange *range); + static void gtk_sheet_real_cell_clear (GtkSheet *sheet, gint row, - gint column, - gboolean delete); + gint column); /* Container Functions */ @@ -793,8 +795,9 @@ enum SELECT_COLUMN, DOUBLE_CLICK_ROW, DOUBLE_CLICK_COLUMN, + BUTTON_EVENT_ROW, + BUTTON_EVENT_COLUMN, SELECT_RANGE, - CLIP_RANGE, RESIZE_RANGE, MOVE_RANGE, TRAVERSE, @@ -899,12 +902,16 @@ gtk_sheet_class_init (GtkSheetClass * klass) * A row has been selected. */ sheet_signals[SELECT_ROW] = - gtk_signal_new ("select-row", - GTK_RUN_LAST, - GTK_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (GtkSheetClass, select_row), - gtkextra_VOID__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); + g_signal_new ("select-row", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + offsetof (GtkSheetClass, select_row), + NULL, NULL, + gtkextra_VOID__INT, + G_TYPE_NONE, + 1, + G_TYPE_INT); + /** * GtkSheet::select - column @@ -914,147 +921,216 @@ gtk_sheet_class_init (GtkSheetClass * klass) * A column has been selected. */ sheet_signals[SELECT_COLUMN] = - gtk_signal_new ("select-column", - GTK_RUN_LAST, - GTK_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (GtkSheetClass, select_column), - gtkextra_VOID__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); + g_signal_new ("select-column", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + offsetof (GtkSheetClass, select_column), + NULL, NULL, + gtkextra_VOID__INT, + G_TYPE_NONE, + 1, + G_TYPE_INT); /** - * GtkSheet::double - click - row + * GtkSheet::double-click-row * @sheet: the sheet widget that emitted the signal * @row: the row that was double clicked. * * A row's title button has been double clicked */ sheet_signals[DOUBLE_CLICK_ROW] = - gtk_signal_new ("double-click-row", - GTK_RUN_LAST, - GTK_CLASS_TYPE (object_class), - 0, - gtkextra_VOID__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); + g_signal_new ("double-click-row", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + gtkextra_VOID__INT, + G_TYPE_NONE, + 1, + G_TYPE_INT); /** - * GtkSheet::double - click - column + * GtkSheet::double-click-column * @sheet: the sheet widget that emitted the signal * @column: the column that was double clicked. * * A column's title button has been double clicked */ sheet_signals[DOUBLE_CLICK_COLUMN] = - gtk_signal_new ("double-click-column", - GTK_RUN_LAST, - GTK_CLASS_TYPE (object_class), - 0, - gtkextra_VOID__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); + g_signal_new ("double-click-column", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + gtkextra_VOID__INT, + G_TYPE_NONE, + 1, + G_TYPE_INT); + + + /** + * GtkSheet::button-event-column + * @sheet: the sheet widget that emitted the signal + * @column: the column on which the event occured. + * + * A button event occured on a column title button + */ + sheet_signals[BUTTON_EVENT_COLUMN] = + g_signal_new ("button-event-column", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + gtkextra_VOID__INT_POINTER, + G_TYPE_NONE, + 2, + G_TYPE_INT, + G_TYPE_POINTER + ); + + + /** + * GtkSheet::button-event-row + * @sheet: the sheet widget that emitted the signal + * @column: the column on which the event occured. + * + * A button event occured on a row title button + */ + sheet_signals[BUTTON_EVENT_ROW] = + g_signal_new ("button-event-row", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + gtkextra_VOID__INT_POINTER, + G_TYPE_NONE, + 2, + G_TYPE_INT, + G_TYPE_POINTER + ); + sheet_signals[SELECT_RANGE] = - gtk_signal_new ("select-range", - GTK_RUN_LAST, - GTK_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (GtkSheetClass, select_range), - gtkextra_VOID__BOXED, - GTK_TYPE_NONE, 1, GTK_TYPE_SHEET_RANGE); - - sheet_signals[CLIP_RANGE] = - gtk_signal_new ("clip-range", - GTK_RUN_LAST, - GTK_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (GtkSheetClass, clip_range), - gtkextra_VOID__BOXED, - GTK_TYPE_NONE, 1, GTK_TYPE_SHEET_RANGE); + g_signal_new ("select-range", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + offsetof (GtkSheetClass, select_range), + NULL, NULL, + gtkextra_VOID__BOXED, + G_TYPE_NONE, + 1, + GTK_TYPE_SHEET_RANGE); + sheet_signals[RESIZE_RANGE] = - gtk_signal_new ("resize-range", - GTK_RUN_LAST, - GTK_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (GtkSheetClass, resize_range), - gtkextra_VOID__BOXED_BOXED, - GTK_TYPE_NONE, 2, GTK_TYPE_SHEET_RANGE, GTK_TYPE_SHEET_RANGE); + g_signal_new ("resize-range", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + offsetof (GtkSheetClass, resize_range), + NULL, NULL, + gtkextra_VOID__BOXED_BOXED, + G_TYPE_NONE, + 2, + GTK_TYPE_SHEET_RANGE, GTK_TYPE_SHEET_RANGE + ); + sheet_signals[MOVE_RANGE] = - gtk_signal_new ("move-range", - GTK_RUN_LAST, - GTK_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (GtkSheetClass, move_range), - gtkextra_VOID__BOXED_BOXED, - GTK_TYPE_NONE, 2, GTK_TYPE_SHEET_RANGE, GTK_TYPE_SHEET_RANGE); + g_signal_new ("move-range", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + offsetof (GtkSheetClass, move_range), + NULL, NULL, + gtkextra_VOID__BOXED_BOXED, + G_TYPE_NONE, + 2, + GTK_TYPE_SHEET_RANGE, GTK_TYPE_SHEET_RANGE + ); + sheet_signals[TRAVERSE] = - gtk_signal_new ("traverse", - GTK_RUN_LAST, - GTK_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (GtkSheetClass, traverse), - gtkextra_BOOLEAN__INT_INT_POINTER_POINTER, - GTK_TYPE_BOOL, 4, GTK_TYPE_INT, GTK_TYPE_INT, - GTK_TYPE_POINTER, GTK_TYPE_POINTER); + g_signal_new ("traverse", + G_TYPE_FROM_CLASS (object_class), + 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); + sheet_signals[DEACTIVATE] = - gtk_signal_new ("deactivate", - GTK_RUN_LAST, - GTK_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (GtkSheetClass, deactivate), - gtkextra_BOOLEAN__INT_INT, - GTK_TYPE_BOOL, 2, GTK_TYPE_INT, GTK_TYPE_INT); + g_signal_new ("deactivate", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + offsetof (GtkSheetClass, deactivate), + NULL, NULL, + gtkextra_BOOLEAN__INT_INT, + G_TYPE_BOOLEAN, 2, G_TYPE_INT, G_TYPE_INT); sheet_signals[ACTIVATE] = - gtk_signal_new ("activate", - GTK_RUN_LAST, - GTK_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (GtkSheetClass, activate), - gtkextra_BOOLEAN__INT_INT, - GTK_TYPE_BOOL, 2, GTK_TYPE_INT, GTK_TYPE_INT); + g_signal_new ("activate", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + offsetof (GtkSheetClass, activate), + NULL, NULL, + gtkextra_BOOLEAN__INT_INT, + G_TYPE_BOOLEAN, 2, G_TYPE_INT, G_TYPE_INT); sheet_signals[SET_CELL] = - gtk_signal_new ("set-cell", - GTK_RUN_LAST, - GTK_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (GtkSheetClass, set_cell), - gtkextra_VOID__INT_INT, - GTK_TYPE_NONE, 2, GTK_TYPE_INT, GTK_TYPE_INT); + g_signal_new ("set-cell", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + offsetof (GtkSheetClass, set_cell), + NULL, NULL, + gtkextra_VOID__INT_INT, + G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT); + sheet_signals[CLEAR_CELL] = - gtk_signal_new ("clear-cell", - GTK_RUN_LAST, - GTK_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (GtkSheetClass, clear_cell), - gtkextra_VOID__INT_INT, - GTK_TYPE_NONE, 2, GTK_TYPE_INT, GTK_TYPE_INT); + g_signal_new ("clear-cell", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + offsetof (GtkSheetClass, clear_cell), + NULL, NULL, + gtkextra_VOID__INT_INT, + G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT); sheet_signals[CHANGED] = - gtk_signal_new ("changed", - GTK_RUN_LAST, - GTK_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (GtkSheetClass, changed), - gtkextra_VOID__INT_INT, - GTK_TYPE_NONE, 2, GTK_TYPE_INT, GTK_TYPE_INT); + 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); sheet_signals[NEW_COL_WIDTH] = - gtk_signal_new ("new-column-width", - GTK_RUN_LAST, - GTK_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (GtkSheetClass, changed), - gtkextra_VOID__INT_INT, - GTK_TYPE_NONE, 2, GTK_TYPE_INT, GTK_TYPE_INT); + g_signal_new ("new-column-width", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + offsetof (GtkSheetClass, new_column_width), /*!!!! */ + NULL, NULL, + gtkextra_VOID__INT_INT, + G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT); sheet_signals[NEW_ROW_HEIGHT] = - gtk_signal_new ("new-row-height", - GTK_RUN_LAST, - GTK_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (GtkSheetClass, changed), - gtkextra_VOID__INT_INT, - GTK_TYPE_NONE, 2, GTK_TYPE_INT, GTK_TYPE_INT); + g_signal_new ("new-row-height", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + offsetof (GtkSheetClass, new_row_height), /*!!!! */ + NULL, NULL, + gtkextra_VOID__INT_INT, + G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT); widget_class->set_scroll_adjustments_signal = - gtk_signal_new ("set-scroll-adjustments", - GTK_RUN_LAST, - GTK_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (GtkSheetClass, set_scroll_adjustments), - gtkextra_VOID__OBJECT_OBJECT, - GTK_TYPE_NONE, 2, GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT); + g_signal_new ("set-scroll-adjustments", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + offsetof (GtkSheetClass, set_scroll_adjustments), + NULL, NULL, + gtkextra_VOID__OBJECT_OBJECT, + G_TYPE_NONE, 2, GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT); container_class->add = NULL; @@ -1083,7 +1159,6 @@ gtk_sheet_class_init (GtkSheetClass * klass) klass->select_row = NULL; klass->select_column = NULL; klass->select_range = NULL; - klass->clip_range = NULL; klass->resize_range = NULL; klass->move_range = NULL; klass->traverse = NULL; @@ -1110,11 +1185,6 @@ gtk_sheet_init (GtkSheet *sheet) GTK_WIDGET_UNSET_FLAGS (sheet, GTK_NO_WINDOW); GTK_WIDGET_SET_FLAGS (sheet, GTK_CAN_FOCUS); - sheet->view.row0 = 0; - sheet->view.col0 = 0; - sheet->view.rowi = 0; - sheet->view.coli = 0; - sheet->column_title_window = NULL; sheet->column_title_area.x = 0; sheet->column_title_area.y = 0; @@ -1167,6 +1237,8 @@ gtk_sheet_init (GtkSheet *sheet) gdk_color_parse ("gray", &sheet->grid_color); gdk_color_alloc (gdk_colormap_get_system (), &sheet->grid_color); sheet->show_grid = TRUE; + + sheet->motion_timer = 0; } @@ -1191,15 +1263,6 @@ columns_inserted_deleted_callback (GSheetModel *model, gint first_column, range.coli = xxx_column_count (sheet) - 1; range.rowi = yyy_row_count (sheet) - 1; - sheet->view.col0 = - COLUMN_FROM_XPIXEL (sheet, sheet->row_title_area.width + 1); - - sheet->view.coli = - COLUMN_FROM_XPIXEL (sheet, sheet->sheet_window_width); - - if ( sheet->view.coli > range.coli) - sheet->view.coli = range.coli; - adjust_scrollbars (sheet); if (sheet->active_cell.col >= model_columns) @@ -1232,14 +1295,6 @@ rows_inserted_deleted_callback (GSheetModel *model, gint first_row, range.rowi = yyy_row_count (sheet) - 1; range.coli = xxx_column_count (sheet) - 1; - sheet->view.row0 = - ROW_FROM_YPIXEL (sheet, sheet->column_title_area.height + 1); - sheet->view.rowi = - ROW_FROM_YPIXEL (sheet, sheet->sheet_window_height - 1); - - if ( sheet->view.rowi > range.rowi) - sheet->view.rowi = range.rowi; - adjust_scrollbars (sheet); if (sheet->active_cell.row >= model_rows) @@ -1268,9 +1323,28 @@ 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) + || + MAX_VISIBLE_COLUMN (sheet) > + g_sheet_model_get_column_count (sheet->model)) + { + gtk_sheet_move_query (sheet, 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); + + for (i = MIN_VISIBLE_COLUMN (sheet); + i <= MAX_VISIBLE_COLUMN (sheet); i++) + gtk_sheet_column_title_button_draw (sheet, i); + return; } else if ( row0 < 0 || rowi < 0 ) @@ -1309,9 +1383,7 @@ GtkWidget * gtk_sheet_new (GSheetRow *vgeo, GSheetColumn *hgeo, const gchar *title, GSheetModel *model) { - GtkWidget *widget; - - widget = gtk_type_new (gtk_sheet_get_type ()); + GtkWidget *widget = g_object_new (GTK_TYPE_SHEET, NULL); gtk_sheet_construct (GTK_SHEET (widget), vgeo, hgeo, title); @@ -1380,7 +1452,7 @@ column_titles_changed (GtkWidget *w, gint first, gint n_columns, gpointer data) for ( i = first ; i <= first + n_columns ; ++i ) { gtk_sheet_column_title_button_draw (sheet, i); - gtk_signal_emit (GTK_OBJECT (sheet), sheet_signals[CHANGED], -1, i); + g_signal_emit (G_OBJECT (sheet), sheet_signals[CHANGED], 0, -1, i); } } @@ -1433,9 +1505,7 @@ GtkWidget * gtk_sheet_new_with_custom_entry (GSheetRow *rows, GSheetColumn *columns, const gchar *title, GtkType entry_type) { - GtkWidget *widget; - - widget = gtk_type_new (gtk_sheet_get_type ()); + GtkWidget *widget = g_object_new (GTK_TYPE_SHEET, NULL); gtk_sheet_construct_with_custom_entry (GTK_SHEET (widget), rows, columns, title, entry_type); @@ -1663,23 +1733,6 @@ gtk_sheet_autoscroll (GtkSheet *sheet) return sheet->autoscroll; } -void -gtk_sheet_set_clip_text (GtkSheet *sheet, gboolean clip_text) -{ - g_return_if_fail (sheet != NULL); - g_return_if_fail (GTK_IS_SHEET (sheet)); - - sheet->clip_text = clip_text; -} - -gboolean -gtk_sheet_clip_text (GtkSheet *sheet) -{ - g_return_val_if_fail (sheet != NULL, FALSE); - g_return_val_if_fail (GTK_IS_SHEET (sheet), FALSE); - - return sheet->clip_text; -} void gtk_sheet_set_justify_entry (GtkSheet *sheet, gboolean justify) @@ -1707,13 +1760,13 @@ gtk_sheet_set_locked (GtkSheet *sheet, gboolean locked) if ( locked ) { - GTK_SHEET_SET_FLAGS (sheet,GTK_SHEET_IS_LOCKED); + GTK_SHEET_SET_FLAGS (sheet, GTK_SHEET_IS_LOCKED); gtk_widget_hide (sheet->sheet_entry); gtk_widget_unmap (sheet->sheet_entry); } else { - GTK_SHEET_UNSET_FLAGS (sheet,GTK_SHEET_IS_LOCKED); + GTK_SHEET_UNSET_FLAGS (sheet, GTK_SHEET_IS_LOCKED); if (GTK_WIDGET_MAPPED (GTK_WIDGET (sheet))) { gtk_widget_show (sheet->sheet_entry); @@ -1721,7 +1774,7 @@ gtk_sheet_set_locked (GtkSheet *sheet, gboolean locked) } } - gtk_entry_set_editable (GTK_ENTRY (sheet->sheet_entry), locked); + gtk_editable_set_editable (GTK_EDITABLE (sheet->sheet_entry), locked); } @@ -1787,11 +1840,11 @@ gtk_sheet_thaw (GtkSheet *sheet) sheet->old_hadjustment = -1.; if (sheet->hadjustment) - gtk_signal_emit_by_name (GTK_OBJECT (sheet->hadjustment), - "value_changed"); + g_signal_emit_by_name (G_OBJECT (sheet->hadjustment), + "value_changed"); if (sheet->vadjustment) - gtk_signal_emit_by_name (GTK_OBJECT (sheet->vadjustment), - "value_changed"); + g_signal_emit_by_name (G_OBJECT (sheet->vadjustment), + "value_changed"); if (sheet->state == GTK_STATE_NORMAL) if (sheet->sheet_entry && GTK_WIDGET_MAPPED (sheet->sheet_entry)) @@ -1808,16 +1861,13 @@ gtk_sheet_set_row_titles_width (GtkSheet *sheet, guint width) if (width < COLUMN_MIN_WIDTH) return; sheet->row_title_area.width = width; - sheet->view.col0 = COLUMN_FROM_XPIXEL (sheet, sheet->row_title_area.width + 1); - sheet->view.coli = COLUMN_FROM_XPIXEL (sheet, sheet->sheet_window_width); - adjust_scrollbars (sheet); sheet->old_hadjustment = -1.; if (sheet->hadjustment) - gtk_signal_emit_by_name (GTK_OBJECT (sheet->hadjustment), - "value_changed"); + g_signal_emit_by_name (G_OBJECT (sheet->hadjustment), + "value_changed"); size_allocate_global_button (sheet); } @@ -1827,16 +1877,13 @@ gtk_sheet_set_column_titles_height (GtkSheet *sheet, guint height) if (height < DEFAULT_ROW_HEIGHT (GTK_WIDGET (sheet))) return; sheet->column_title_area.height = height; - sheet->view.row0 = ROW_FROM_YPIXEL (sheet, - sheet->column_title_area.height + 1); - sheet->view.rowi = ROW_FROM_YPIXEL (sheet, sheet->sheet_window_height - 1); adjust_scrollbars (sheet); sheet->old_vadjustment = -1.; if (sheet->vadjustment) - gtk_signal_emit_by_name (GTK_OBJECT (sheet->vadjustment), - "value_changed"); + g_signal_emit_by_name (G_OBJECT (sheet->vadjustment), + "value_changed"); size_allocate_global_button (sheet); } @@ -1874,8 +1921,8 @@ gtk_sheet_show_column_titles (GtkSheet *sheet) sheet->old_vadjustment = -1.; if (sheet->vadjustment) - gtk_signal_emit_by_name (GTK_OBJECT (sheet->vadjustment), - "value_changed"); + g_signal_emit_by_name (G_OBJECT (sheet->vadjustment), + "value_changed"); size_allocate_global_button (sheet); } @@ -1916,8 +1963,8 @@ gtk_sheet_show_row_titles (GtkSheet *sheet) sheet->old_hadjustment = -1.; if (sheet->hadjustment) - gtk_signal_emit_by_name (GTK_OBJECT (sheet->hadjustment), - "value_changed"); + g_signal_emit_by_name (G_OBJECT (sheet->hadjustment), + "value_changed"); size_allocate_global_button (sheet); } @@ -1952,8 +1999,8 @@ gtk_sheet_hide_column_titles (GtkSheet *sheet) sheet->old_vadjustment = -1.; if (sheet->vadjustment) - gtk_signal_emit_by_name (GTK_OBJECT (sheet->vadjustment), - "value_changed"); + g_signal_emit_by_name (G_OBJECT (sheet->vadjustment), + "value_changed"); } void @@ -1987,8 +2034,8 @@ gtk_sheet_hide_row_titles (GtkSheet *sheet) sheet->old_hadjustment = -1.; if (sheet->hadjustment) - gtk_signal_emit_by_name (GTK_OBJECT (sheet->hadjustment), - "value_changed"); + g_signal_emit_by_name (G_OBJECT (sheet->hadjustment), + "value_changed"); } gboolean @@ -2065,8 +2112,8 @@ gtk_sheet_moveto (GtkSheet *sheet, sheet->vadjustment->value = y; sheet->old_vadjustment = -1.; - gtk_signal_emit_by_name (GTK_OBJECT (sheet->vadjustment), - "value_changed"); + g_signal_emit_by_name (G_OBJECT (sheet->vadjustment), + "value_changed"); } @@ -2105,8 +2152,8 @@ gtk_sheet_moveto (GtkSheet *sheet, sheet->hadjustment->value = x; sheet->old_vadjustment = -1.; - gtk_signal_emit_by_name (GTK_OBJECT (sheet->hadjustment), - "value_changed"); + g_signal_emit_by_name (G_OBJECT (sheet->hadjustment), + "value_changed"); } } @@ -2177,7 +2224,7 @@ gtk_sheet_select_row (GtkSheet * sheet, sheet->active_cell.row = row; sheet->active_cell.col = 0; - gtk_signal_emit (GTK_OBJECT (sheet), sheet_signals[SELECT_ROW], row); + g_signal_emit (G_OBJECT (sheet), sheet_signals[SELECT_ROW], 0, row); gtk_sheet_real_select_range (sheet, NULL); } @@ -2208,192 +2255,15 @@ gtk_sheet_select_column (GtkSheet * sheet, gint column) sheet->active_cell.row = 0; sheet->active_cell.col = column; - gtk_signal_emit (GTK_OBJECT (sheet), sheet_signals[SELECT_COLUMN], column); + g_signal_emit (G_OBJECT (sheet), sheet_signals[SELECT_COLUMN], 0, column); gtk_sheet_real_select_range (sheet, NULL); } -void -gtk_sheet_clip_range (GtkSheet *sheet, const GtkSheetRange *range) -{ - - g_return_if_fail (sheet != NULL); - g_return_if_fail (GTK_IS_SHEET (sheet)); - - if (GTK_SHEET_IN_CLIP (sheet)) return; - - GTK_SHEET_SET_FLAGS (sheet, GTK_SHEET_IN_CLIP); - - if (range == NULL) - sheet->clip_range = sheet->range; - else - sheet->clip_range=*range; - - sheet->interval = 0; - sheet->clip_timer = gtk_timeout_add (TIMEOUT_FLASH, gtk_sheet_flash, sheet); - - gtk_signal_emit (GTK_OBJECT (sheet), sheet_signals[CLIP_RANGE], - &sheet->clip_range); - -} - -void -gtk_sheet_unclip_range (GtkSheet *sheet) -{ - - g_return_if_fail (sheet != NULL); - g_return_if_fail (GTK_IS_SHEET (sheet)); - - if (!GTK_SHEET_IN_CLIP (sheet)) return; - - GTK_SHEET_UNSET_FLAGS (sheet, GTK_SHEET_IN_CLIP); - - gtk_timeout_remove (sheet->clip_timer); - gtk_sheet_range_draw (sheet, &sheet->clip_range); - - if (gtk_sheet_range_isvisible (sheet, sheet->range)) - gtk_sheet_range_draw (sheet, &sheet->range); -} - -gboolean -gtk_sheet_in_clip (GtkSheet *sheet) -{ - g_return_val_if_fail (sheet != NULL, FALSE); - g_return_val_if_fail (GTK_IS_SHEET (sheet), FALSE); - return GTK_SHEET_IN_CLIP (sheet); -} -static gint -gtk_sheet_flash (gpointer data) -{ - GtkSheet *sheet; - gint x,y,width,height; - GdkRectangle clip_area; - sheet = GTK_SHEET (data); - - if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) return TRUE; - if (!GTK_WIDGET_DRAWABLE (GTK_WIDGET (sheet))) return TRUE; - if (!gtk_sheet_range_isvisible (sheet, sheet->clip_range)) return TRUE; - if (GTK_SHEET_IN_XDRAG (sheet)) return TRUE; - if (GTK_SHEET_IN_YDRAG (sheet)) return TRUE; - - GDK_THREADS_ENTER (); - - x = COLUMN_LEFT_XPIXEL (sheet,sheet->clip_range.col0)+1; - y = ROW_TOP_YPIXEL (sheet,sheet->clip_range.row0)+1; - width = COLUMN_LEFT_XPIXEL (sheet,sheet->clip_range.coli)- x+ - xxx_column_width (sheet, sheet->clip_range.coli) - 1; - height = ROW_TOP_YPIXEL (sheet,sheet->clip_range.rowi)- y+ - yyy_row_height (sheet, sheet->clip_range.rowi)- 1; - - clip_area.x = COLUMN_LEFT_XPIXEL (sheet, MIN_VISIBLE_COLUMN (sheet)); - clip_area.y = ROW_TOP_YPIXEL (sheet, MIN_VISIBLE_ROW (sheet)); - clip_area.width = sheet->sheet_window_width; - clip_area.height = sheet->sheet_window_height; - - if (x < 0) - { - width += x + 1; - x =- 1; - } - if (width > clip_area.width) width = clip_area.width + 10; - if (y < 0) - { - height += y + 1; - y =- 1; - } - if (height > clip_area.height) height = clip_area.height + 10; - - gdk_draw_pixmap (sheet->sheet_window, - GTK_WIDGET (sheet)->style->fg_gc[GTK_STATE_NORMAL], - sheet->pixmap, - x, y, - x, y, - 1, height); - - gdk_draw_pixmap (sheet->sheet_window, - GTK_WIDGET (sheet)->style->fg_gc[GTK_STATE_NORMAL], - sheet->pixmap, - x, y, - x, y, - width, 1); - - gdk_draw_pixmap (sheet->sheet_window, - GTK_WIDGET (sheet)->style->fg_gc[GTK_STATE_NORMAL], - sheet->pixmap, - x, y + height, - x, y + height, - width, 1); - - gdk_draw_pixmap (sheet->sheet_window, - GTK_WIDGET (sheet)->style->fg_gc[GTK_STATE_NORMAL], - sheet->pixmap, - x + width, y, - x + width, y, - 1, height); - - - sheet->interval = sheet->interval + 1; - if (sheet->interval == TIME_INTERVAL) sheet->interval = 0; - - gdk_gc_set_dashes (sheet->xor_gc, sheet->interval, (gint8*)"\4\4", 2); - gtk_sheet_draw_flashing_range (sheet,sheet->clip_range); - gdk_gc_set_dashes (sheet->xor_gc, 0, (gint8*)"\4\4", 2); - - GDK_THREADS_LEAVE (); - - return TRUE; -} - -static void -gtk_sheet_draw_flashing_range (GtkSheet *sheet, GtkSheetRange range) -{ - GdkRectangle clip_area; - gint x,y,width,height; - - if (!gtk_sheet_range_isvisible (sheet, sheet->clip_range)) return; - - clip_area.x = COLUMN_LEFT_XPIXEL (sheet, MIN_VISIBLE_COLUMN (sheet)); - clip_area.y = ROW_TOP_YPIXEL (sheet, MIN_VISIBLE_ROW (sheet)); - clip_area.width = sheet->sheet_window_width; - clip_area.height = sheet->sheet_window_height; - - gdk_gc_set_clip_rectangle (sheet->xor_gc, &clip_area); - - x = COLUMN_LEFT_XPIXEL (sheet,sheet->clip_range.col0)+1; - y = ROW_TOP_YPIXEL (sheet,sheet->clip_range.row0)+1; - width = COLUMN_LEFT_XPIXEL (sheet,sheet->clip_range.coli)- x+ - xxx_column_width (sheet, sheet->clip_range.coli) - 1; - height = ROW_TOP_YPIXEL (sheet,sheet->clip_range.rowi)- y+ - yyy_row_height (sheet, sheet->clip_range.rowi)- 1; - - if (x < 0) - { - width += x + 1; - x =- 1; - } - if (width > clip_area.width) width = clip_area.width + 10; - if (y < 0) - { - height += y + 1; - y =- 1; - } - if (height > clip_area.height) height = clip_area.height + 10; - - gdk_gc_set_line_attributes (sheet->xor_gc, 1, 1, 0, 0 ); - - gdk_draw_rectangle (sheet->sheet_window, sheet->xor_gc, FALSE, - x, y, - width, height); - - gdk_gc_set_line_attributes (sheet->xor_gc, 1, 0, 0, 0); - - gdk_gc_set_clip_rectangle (sheet->xor_gc, NULL); -} - -static gint -gtk_sheet_range_isvisible (GtkSheet * sheet, +static gboolean +gtk_sheet_range_isvisible (const GtkSheet * sheet, GtkSheetRange range) { g_return_val_if_fail (sheet != NULL, FALSE); @@ -2425,7 +2295,7 @@ gtk_sheet_range_isvisible (GtkSheet * sheet, return TRUE; } -static gint +static gboolean gtk_sheet_cell_isvisible (GtkSheet * sheet, gint row, gint column) { @@ -2488,23 +2358,23 @@ gtk_sheet_set_vadjustment (GtkSheet *sheet, if (sheet->vadjustment) { - gtk_signal_disconnect_by_data (GTK_OBJECT (sheet->vadjustment), sheet); - gtk_object_unref (GTK_OBJECT (sheet->vadjustment)); + g_signal_handlers_disconnect_matched (G_OBJECT (sheet->vadjustment), + G_SIGNAL_MATCH_DATA, + 0, 0, 0, 0, + sheet); + g_object_unref (G_OBJECT (sheet->vadjustment)); } sheet->vadjustment = adjustment; if (sheet->vadjustment) { - gtk_object_ref (GTK_OBJECT (sheet->vadjustment)); - gtk_object_sink (GTK_OBJECT (sheet->vadjustment)); + g_object_ref (G_OBJECT (sheet->vadjustment)); + g_object_ref_sink (G_OBJECT (sheet->vadjustment)); - gtk_signal_connect (GTK_OBJECT (sheet->vadjustment), "changed", - (GtkSignalFunc) vadjustment_changed, - (gpointer) sheet); - gtk_signal_connect (GTK_OBJECT (sheet->vadjustment), "value_changed", - (GtkSignalFunc) vadjustment_value_changed, - (gpointer) sheet); + g_signal_connect (G_OBJECT (sheet->vadjustment), "value_changed", + G_CALLBACK (vadjustment_value_changed), + sheet); } if (!sheet->vadjustment || !old_adjustment) @@ -2534,23 +2404,23 @@ gtk_sheet_set_hadjustment (GtkSheet *sheet, if (sheet->hadjustment) { - gtk_signal_disconnect_by_data (GTK_OBJECT (sheet->hadjustment), sheet); - gtk_object_unref (GTK_OBJECT (sheet->hadjustment)); + g_signal_handlers_disconnect_matched (G_OBJECT (sheet->hadjustment), + G_SIGNAL_MATCH_DATA, + 0, 0, 0, 0, + sheet); + g_object_unref (G_OBJECT (sheet->hadjustment)); } sheet->hadjustment = adjustment; if (sheet->hadjustment) { - gtk_object_ref (GTK_OBJECT (sheet->hadjustment)); - gtk_object_sink (GTK_OBJECT (sheet->hadjustment)); + g_object_ref (G_OBJECT (sheet->hadjustment)); + g_object_ref_sink (G_OBJECT (sheet->hadjustment)); - gtk_signal_connect (GTK_OBJECT (sheet->hadjustment), "changed", - (GtkSignalFunc) hadjustment_changed, - (gpointer) sheet); - gtk_signal_connect (GTK_OBJECT (sheet->hadjustment), "value_changed", - (GtkSignalFunc) hadjustment_value_changed, - (gpointer) sheet); + g_signal_connect (G_OBJECT (sheet->hadjustment), "value_changed", + G_CALLBACK (hadjustment_value_changed), + sheet); } if (!sheet->hadjustment || !old_adjustment) @@ -2584,10 +2454,6 @@ gtk_sheet_finalize (GObject * object) sheet = GTK_SHEET (object); - /* get rid of all the cells */ - gtk_sheet_range_clear (sheet, NULL); - gtk_sheet_range_delete (sheet, NULL); - if (sheet->name) { g_free (sheet->name); @@ -2623,23 +2489,27 @@ gtk_sheet_destroy (GtkObject * object) sheet->button = NULL; } - if (sheet->clip_timer) - { - gtk_timeout_remove (sheet->clip_timer); - sheet->clip_timer = 0; - } - /* unref adjustments */ if (sheet->hadjustment) { - gtk_signal_disconnect_by_data (GTK_OBJECT (sheet->hadjustment), sheet); - gtk_object_unref (GTK_OBJECT (sheet->hadjustment)); + g_signal_handlers_disconnect_matched (G_OBJECT (sheet->hadjustment), + G_SIGNAL_MATCH_DATA, + 0, 0, 0, 0, + sheet); + + g_object_unref (G_OBJECT (sheet->hadjustment)); sheet->hadjustment = NULL; } + if (sheet->vadjustment) { - gtk_signal_disconnect_by_data (GTK_OBJECT (sheet->vadjustment), sheet); - gtk_object_unref (GTK_OBJECT (sheet->vadjustment)); + g_signal_handlers_disconnect_matched (G_OBJECT (sheet->vadjustment), + G_SIGNAL_MATCH_DATA, + 0, 0, 0, 0, + sheet); + + g_object_unref (G_OBJECT (sheet->vadjustment)); + sheet->vadjustment = NULL; } @@ -2837,6 +2707,8 @@ gtk_sheet_realize (GtkWidget * widget) gtk_sheet_realize_child (sheet, child); } + + gtk_sheet_update_primary_selection (sheet); } static void @@ -2844,10 +2716,10 @@ create_global_button (GtkSheet *sheet) { sheet->button = gtk_button_new_with_label (" "); - gtk_signal_connect (GTK_OBJECT (sheet->button), - "pressed", - (GtkSignalFunc) global_button_clicked, - (gpointer) sheet); + g_signal_connect (G_OBJECT (sheet->button), + "pressed", + G_CALLBACK (global_button_clicked), + sheet); } static void @@ -3067,8 +2939,8 @@ gtk_sheet_cell_draw_default (GtkSheet *sheet, gint row, gint col) fg_gc = sheet->fg_gc; bg_gc = sheet->bg_gc; - area.x = COLUMN_LEFT_XPIXEL (sheet,col); - area.y = ROW_TOP_YPIXEL (sheet,row); + area.x = COLUMN_LEFT_XPIXEL (sheet, col); + area.y = ROW_TOP_YPIXEL (sheet, row); area.width= xxx_column_width (sheet, col); area.height = yyy_row_height (sheet, row); @@ -3098,7 +2970,7 @@ static void gtk_sheet_cell_draw_label (GtkSheet *sheet, gint row, gint col) { GtkWidget *widget; - GdkRectangle area, clip_area; + GdkRectangle area; gint i; gint text_width, text_height, y; gint xoffset = 0; @@ -3142,12 +3014,11 @@ gtk_sheet_cell_draw_label (GtkSheet *sheet, gint row, gint col) fg_gc = sheet->fg_gc; bg_gc = sheet->bg_gc; - area.x = COLUMN_LEFT_XPIXEL (sheet,col); - area.y = ROW_TOP_YPIXEL (sheet,row); + area.x = COLUMN_LEFT_XPIXEL (sheet, col); + area.y = ROW_TOP_YPIXEL (sheet, row); area.width = xxx_column_width (sheet, col); area.height = yyy_row_height (sheet, row); - clip_area = area; layout = gtk_widget_create_pango_layout (GTK_WIDGET (sheet), label); dispose_string (sheet, label); @@ -3189,7 +3060,6 @@ gtk_sheet_cell_draw_label (GtkSheet *sheet, gint row, gint col) case GTK_JUSTIFY_RIGHT: size = area.width; area.x +=area.width; - if (!gtk_sheet_clip_text (sheet)) { for (i = col - 1; i >= MIN_VISIBLE_COLUMN (sheet); i--) { @@ -3210,7 +3080,6 @@ gtk_sheet_cell_draw_label (GtkSheet *sheet, gint row, gint col) sizel = area.width / 2; sizer = area.width / 2; area.x += area.width / 2; - if (!gtk_sheet_clip_text (sheet)) { for (i = col + 1; i <= MAX_VISIBLE_COLUMN (sheet); i++) { @@ -3240,7 +3109,6 @@ gtk_sheet_cell_draw_label (GtkSheet *sheet, gint row, gint col) case GTK_JUSTIFY_LEFT: default: size = area.width; - if (!gtk_sheet_clip_text (sheet)) { for (i = col + 1; i <= MAX_VISIBLE_COLUMN (sheet); i++) { @@ -3259,8 +3127,7 @@ gtk_sheet_cell_draw_label (GtkSheet *sheet, gint row, gint col) break; } - if (!gtk_sheet_clip_text (sheet)) clip_area = area; - gdk_gc_set_clip_rectangle (fg_gc, &clip_area); + gdk_gc_set_clip_rectangle (fg_gc, &area); gdk_draw_layout (sheet->pixmap, fg_gc, @@ -3286,7 +3153,7 @@ gtk_sheet_cell_draw_label (GtkSheet *sheet, gint row, gint col) static void gtk_sheet_range_draw (GtkSheet *sheet, const GtkSheetRange *range) { - gint i,j; + gint i, j; GtkSheetRange drawing_range; GdkRectangle area; @@ -3301,14 +3168,15 @@ 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), yyy_row_count (sheet) - 1); + drawing_range.rowi = MIN (MAX_VISIBLE_ROW (sheet), + yyy_row_count (sheet) - 1); drawing_range.coli = MAX_VISIBLE_COLUMN (sheet); gdk_draw_rectangle (sheet->pixmap, GTK_WIDGET (sheet)->style->white_gc, TRUE, - 0,0, + 0, 0, sheet->sheet_window_width, sheet->sheet_window_height); } @@ -3320,7 +3188,6 @@ gtk_sheet_range_draw (GtkSheet *sheet, const GtkSheetRange *range) drawing_range.coli = MIN (range->coli, MAX_VISIBLE_COLUMN (sheet)); } - if (drawing_range.coli == xxx_column_count (sheet) - 1) { area.x = COLUMN_LEFT_XPIXEL (sheet, @@ -3334,7 +3201,7 @@ gtk_sheet_range_draw (GtkSheet *sheet, const GtkSheetRange *range) gdk_draw_rectangle (sheet->pixmap, sheet->fg_gc, TRUE, - area.x,area.y, + area.x, area.y, sheet->sheet_window_width - area.x, sheet->sheet_window_height); @@ -3361,7 +3228,7 @@ gtk_sheet_range_draw (GtkSheet *sheet, const GtkSheetRange *range) gdk_draw_rectangle (sheet->pixmap, sheet->fg_gc, TRUE, - area.x,area.y, + area.x, area.y, sheet->sheet_window_width, sheet->sheet_window_height - area.y); @@ -3401,7 +3268,7 @@ static void gtk_sheet_range_draw_selection (GtkSheet *sheet, GtkSheetRange range) { GdkRectangle area; - gint i,j; + gint i, j; GtkSheetRange aux; if (range.col0 > sheet->range.coli || range.coli < sheet->range.col0 || @@ -3432,8 +3299,8 @@ gtk_sheet_range_draw_selection (GtkSheet *sheet, GtkSheetRange range) xxx_column_is_visible (sheet, j) && yyy_row_is_visible (sheet, i)) { - area.x = COLUMN_LEFT_XPIXEL (sheet,j); - area.y = ROW_TOP_YPIXEL (sheet,i); + area.x = COLUMN_LEFT_XPIXEL (sheet, j); + area.y = ROW_TOP_YPIXEL (sheet, i); area.width= xxx_column_width (sheet, j); area.height = yyy_row_height (sheet, i); @@ -3450,13 +3317,13 @@ gtk_sheet_range_draw_selection (GtkSheet *sheet, GtkSheetRange range) } if (j == sheet->range.coli) area.width = area.width - 3; - if (i!=sheet->active_cell.row || j!=sheet->active_cell.col) + if (i != sheet->active_cell.row || j != sheet->active_cell.col) { gdk_draw_rectangle (sheet->sheet_window, sheet->xor_gc, TRUE, - area.x + 1,area.y + 1, - area.width,area.height); + area.x + 1, area.y + 1, + area.width, area.height); } } @@ -3469,11 +3336,11 @@ gtk_sheet_range_draw_selection (GtkSheet *sheet, GtkSheetRange range) static void gtk_sheet_draw_backing_pixmap (GtkSheet *sheet, GtkSheetRange range) { - gint x,y,width,height; + gint x, y, width, height; if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) return; - x = COLUMN_LEFT_XPIXEL (sheet,range.col0); + x = COLUMN_LEFT_XPIXEL (sheet, range.col0); y = ROW_TOP_YPIXEL (sheet, range.row0); width = COLUMN_LEFT_XPIXEL (sheet, range.coli) - x + xxx_column_width (sheet, range.coli); @@ -3594,8 +3461,8 @@ gtk_sheet_set_cell (GtkSheet *sheet, gint row, gint col, range.row0 = row; range.rowi = row; - range.col0 = sheet->view.col0; - range.coli = sheet->view.coli; + range.col0 = MIN_VISIBLE_COLUMN (sheet); + range.coli = MAX_VISIBLE_COLUMN (sheet); if (gtk_sheet_autoresize (sheet) && text_width > xxx_column_width (sheet, col) - @@ -3611,7 +3478,7 @@ gtk_sheet_set_cell (GtkSheet *sheet, gint row, gint col, } if ( changed ) - gtk_signal_emit (GTK_OBJECT (sheet),sheet_signals[CHANGED], row, col); + g_signal_emit (G_OBJECT (sheet), sheet_signals[CHANGED], 0, row, col); } @@ -3630,33 +3497,10 @@ gtk_sheet_cell_clear (GtkSheet *sheet, gint row, gint column) range.row0 = row; range.rowi = row; - range.col0 = sheet->view.col0; - range.coli = sheet->view.coli; - - gtk_sheet_real_cell_clear (sheet, row, column, FALSE); - - if (!GTK_SHEET_IS_FROZEN (sheet)) - { - gtk_sheet_range_draw (sheet, &range); - } -} - -void -gtk_sheet_cell_delete (GtkSheet *sheet, gint row, gint column) -{ - GtkSheetRange range; - - g_return_if_fail (sheet != NULL); - g_return_if_fail (GTK_IS_SHEET (sheet)); - if (column >= xxx_column_count (sheet) || row >= yyy_row_count (sheet)) return; - if (column < 0 || row < 0) return; - - range.row0 = row; - range.rowi = row; - range.col0 = sheet->view.col0; - range.coli = sheet->view.coli; + range.col0 = MIN_VISIBLE_COLUMN (sheet); + range.coli = MAX_VISIBLE_COLUMN (sheet); - gtk_sheet_real_cell_clear (sheet, row, column, TRUE); + gtk_sheet_real_cell_clear (sheet, row, column); if (!GTK_SHEET_IS_FROZEN (sheet)) { @@ -3665,7 +3509,7 @@ gtk_sheet_cell_delete (GtkSheet *sheet, gint row, gint column) } static void -gtk_sheet_real_cell_clear (GtkSheet *sheet, gint row, gint column, gboolean delete) +gtk_sheet_real_cell_clear (GtkSheet *sheet, gint row, gint column) { GSheetModel *model = gtk_sheet_get_model (sheet); @@ -3676,8 +3520,8 @@ gtk_sheet_real_cell_clear (GtkSheet *sheet, gint row, gint column, gboolean dele g_sheet_model_datum_clear (model, row, column); if (GTK_IS_OBJECT (sheet) && G_OBJECT (sheet)->ref_count > 0) - gtk_signal_emit (GTK_OBJECT (sheet),sheet_signals[CLEAR_CELL], - row, column); + g_signal_emit (G_OBJECT (sheet), sheet_signals[CLEAR_CELL], 0, + row, column); } dispose_string (sheet, old_text); @@ -3689,22 +3533,11 @@ gtk_sheet_range_clear (GtkSheet *sheet, const GtkSheetRange *range) g_return_if_fail (sheet != NULL); g_return_if_fail (GTK_IS_SHEET (sheet)); - gtk_sheet_real_range_clear (sheet, range, FALSE); + gtk_sheet_real_range_clear (sheet, range); } -void -gtk_sheet_range_delete (GtkSheet *sheet, const GtkSheetRange *range) -{ - g_return_if_fail (sheet != NULL); - g_return_if_fail (GTK_IS_SHEET (sheet)); - - gtk_sheet_real_range_clear (sheet, range, TRUE); -} - - static void -gtk_sheet_real_range_clear (GtkSheet *sheet, const GtkSheetRange *range, - gboolean delete) +gtk_sheet_real_range_clear (GtkSheet *sheet, const GtkSheetRange *range) { gint i, j; GtkSheetRange clear; @@ -3727,7 +3560,7 @@ gtk_sheet_real_range_clear (GtkSheet *sheet, const GtkSheetRange *range, for (i = clear.row0; i <= clear.rowi; i++) for (j = clear.col0; j <= clear.coli; j++) { - gtk_sheet_real_cell_clear (sheet, i, j, delete); + gtk_sheet_real_cell_clear (sheet, i, j); } gtk_sheet_range_draw (sheet, NULL); @@ -3803,6 +3636,10 @@ gtk_sheet_cell_get_state (GtkSheet *sheet, gint row, gint col) return GTK_STATE_NORMAL; } +/* Convert X, Y (in pixels) to *ROW, *COLUMN (in cell coords) + -1 indicates the title buttons. + If the function returns FALSE, then the results will be unreliable. +*/ gboolean gtk_sheet_get_pixel_info (GtkSheet *sheet, gint x, @@ -3810,25 +3647,43 @@ gtk_sheet_get_pixel_info (GtkSheet *sheet, gint *row, gint *column) { - gint trow = -1; - gint tcol = -1; + gint trow, tcol; + *row = -G_MAXINT; + *column = -G_MAXINT; g_return_val_if_fail (sheet != NULL, 0); g_return_val_if_fail (GTK_IS_SHEET (sheet), 0); /* bounds checking, return false if the user clicked on a blank area */ - trow = ROW_FROM_YPIXEL (sheet, y); - if (trow >= yyy_row_count (sheet)) + if (y < 0) return FALSE; - *row = trow; - - tcol = COLUMN_FROM_XPIXEL (sheet, x); - if (tcol >= xxx_column_count (sheet)) + if (x < 0) return FALSE; - *column = tcol; + if ( y < sheet->column_title_area.height + sheet->column_title_area.y) + *row = -1; + + else + { + trow = ROW_FROM_YPIXEL (sheet, y); + if (trow > yyy_row_count (sheet)) + return FALSE; + + *row = trow; + } + + if ( x < sheet->row_title_area.width + sheet->row_title_area.x) + *column = -1; + else + { + tcol = COLUMN_FROM_XPIXEL (sheet, x); + if (tcol > xxx_column_count (sheet)) + return FALSE; + + *column = tcol; + } return TRUE; } @@ -3900,15 +3755,15 @@ gtk_sheet_get_active_cell (GtkSheet *sheet, gint *row, gint *column) g_return_if_fail (sheet != NULL); g_return_if_fail (GTK_IS_SHEET (sheet)); - *row = sheet->active_cell.row; - *column = sheet->active_cell.col; + if ( row ) *row = sheet->active_cell.row; + if (column) *column = sheet->active_cell.col; } static void gtk_sheet_entry_changed (GtkWidget *widget, gpointer data) { GtkSheet *sheet; - gint row,col; + gint row, col; const char *text; GtkJustification justification; GtkSheetCellAttr attributes; @@ -3959,7 +3814,7 @@ gtk_sheet_deactivate_cell (GtkSheet *sheet) if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) return FALSE; if (sheet->state != GTK_SHEET_NORMAL) return FALSE; - _gtkextra_signal_emit (GTK_OBJECT (sheet),sheet_signals[DEACTIVATE], + _gtkextra_signal_emit (GTK_OBJECT (sheet), sheet_signals[DEACTIVATE], sheet->active_cell.row, sheet->active_cell.col, &veto); @@ -3968,9 +3823,9 @@ gtk_sheet_deactivate_cell (GtkSheet *sheet) if ( sheet->active_cell.row == -1 || sheet->active_cell.col == -1 ) return TRUE; - gtk_signal_disconnect_by_func (GTK_OBJECT (gtk_sheet_get_entry (sheet)), - (GtkSignalFunc) gtk_sheet_entry_changed, - GTK_OBJECT (GTK_WIDGET (sheet))); + g_signal_handlers_disconnect_by_func (G_OBJECT (gtk_sheet_get_entry (sheet)), + G_CALLBACK (gtk_sheet_entry_changed), + sheet); gtk_sheet_hide_active_cell (sheet); sheet->active_cell.row = -1; @@ -3989,7 +3844,7 @@ static void gtk_sheet_hide_active_cell (GtkSheet *sheet) { const char *text; - gint row,col; + gint row, col; GtkJustification justification; GtkSheetCellAttr attributes; @@ -4011,7 +3866,7 @@ gtk_sheet_hide_active_cell (GtkSheet *sheet) if (text && strlen (text) != 0) { gtk_sheet_set_cell (sheet, row, col, justification, text); - gtk_signal_emit (GTK_OBJECT (sheet),sheet_signals[SET_CELL], row, col); + g_signal_emit (G_OBJECT (sheet), sheet_signals[SET_CELL], 0, row, col); } else { @@ -4028,10 +3883,10 @@ gtk_sheet_hide_active_cell (GtkSheet *sheet) gdk_draw_pixmap (sheet->sheet_window, GTK_WIDGET (sheet)->style->fg_gc[GTK_STATE_NORMAL], sheet->pixmap, - COLUMN_LEFT_XPIXEL (sheet,col)- 1, - ROW_TOP_YPIXEL (sheet,row)- 1, - COLUMN_LEFT_XPIXEL (sheet,col)- 1, - ROW_TOP_YPIXEL (sheet,row)- 1, + COLUMN_LEFT_XPIXEL (sheet, col)- 1, + ROW_TOP_YPIXEL (sheet, row)- 1, + COLUMN_LEFT_XPIXEL (sheet, col)- 1, + ROW_TOP_YPIXEL (sheet, row)- 1, xxx_column_width (sheet, col) + 4, yyy_row_height (sheet, row)+4); @@ -4053,10 +3908,6 @@ gtk_sheet_activate_cell (GtkSheet *sheet, gint row, gint col) if (row >= yyy_row_count (sheet) || col >= xxx_column_count (sheet)) return FALSE; - /* _gtkextra_signal_emit (GTK_OBJECT (sheet),sheet_signals[ACTIVATE], row, col, &veto); - if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) return veto; - */ - if (!veto) return FALSE; if (sheet->state != GTK_SHEET_NORMAL) { @@ -4083,7 +3934,7 @@ gtk_sheet_activate_cell (GtkSheet *sheet, gint row, gint col) G_CALLBACK (gtk_sheet_entry_changed), sheet); - _gtkextra_signal_emit (GTK_OBJECT (sheet),sheet_signals[ACTIVATE], row, col, &veto); + _gtkextra_signal_emit (GTK_OBJECT (sheet), sheet_signals [ACTIVATE], row, col, &veto); return TRUE; } @@ -4130,9 +3981,9 @@ gtk_sheet_show_active_cell (GtkSheet *sheet) gtk_entry_set_visibility (GTK_ENTRY (sheet_entry), attributes.is_visible); if (gtk_sheet_locked (sheet) || !attributes.is_editable) - gtk_entry_set_editable (GTK_ENTRY (sheet_entry), FALSE); + gtk_editable_set_editable (GTK_EDITABLE (sheet_entry), FALSE); else - gtk_entry_set_editable (GTK_ENTRY (sheet_entry), TRUE); + gtk_editable_set_editable (GTK_EDITABLE (sheet_entry), TRUE); /*** Added by John Gotts. Mar 25, 2005 *********/ old_text = gtk_entry_get_text (GTK_ENTRY (sheet_entry)); @@ -4158,6 +4009,7 @@ static void gtk_sheet_draw_active_cell (GtkSheet *sheet) { gint row, col; + GtkSheetRange range; if (!GTK_WIDGET_DRAWABLE (GTK_WIDGET (sheet))) return; if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) return; @@ -4169,7 +4021,10 @@ gtk_sheet_draw_active_cell (GtkSheet *sheet) if (!gtk_sheet_cell_isvisible (sheet, row, col)) return; - gtk_sheet_draw_border (sheet, sheet->range); + range.col0 = range.coli = col; + range.row0 = range.rowi = row; + + gtk_sheet_draw_border (sheet, range); } @@ -4213,9 +4068,9 @@ gtk_sheet_make_backing_pixmap (GtkSheet *sheet, guint width, guint height) static void gtk_sheet_new_selection (GtkSheet *sheet, GtkSheetRange *range) { - gint i,j, mask1, mask2; + gint i, j, mask1, mask2; gint state, selected; - gint x,y,width,height; + gint x, y, width, height; GtkSheetRange new_range, aux_range; g_return_if_fail (sheet != NULL); @@ -4268,7 +4123,7 @@ gtk_sheet_new_selection (GtkSheet *sheet, GtkSheetRange *range) if (mask1 != mask2) { - x = COLUMN_LEFT_XPIXEL (sheet,j); + x = COLUMN_LEFT_XPIXEL (sheet, j); y = ROW_TOP_YPIXEL (sheet, i); width = COLUMN_LEFT_XPIXEL (sheet, j)- x+ xxx_column_width (sheet, j); @@ -4299,7 +4154,7 @@ gtk_sheet_new_selection (GtkSheet *sheet, GtkSheetRange *range) if (i != sheet->active_cell.row || j != sheet->active_cell.col) { - x = COLUMN_LEFT_XPIXEL (sheet,j); + x = COLUMN_LEFT_XPIXEL (sheet, j); y = ROW_TOP_YPIXEL (sheet, i); width = COLUMN_LEFT_XPIXEL (sheet, j)- x+ xxx_column_width (sheet, j); @@ -4322,8 +4177,8 @@ gtk_sheet_new_selection (GtkSheet *sheet, GtkSheetRange *range) gdk_draw_rectangle (sheet->sheet_window, sheet->xor_gc, TRUE, - x + 1,y + 1, - width,height); + x + 1, y + 1, + width, height); } } } @@ -4343,7 +4198,7 @@ gtk_sheet_new_selection (GtkSheet *sheet, GtkSheetRange *range) xxx_column_is_visible (sheet, j) && yyy_row_is_visible (sheet, i)) { - x = COLUMN_LEFT_XPIXEL (sheet,j); + x = COLUMN_LEFT_XPIXEL (sheet, j); y = ROW_TOP_YPIXEL (sheet, i); width = COLUMN_LEFT_XPIXEL (sheet, j)- x+ xxx_column_width (sheet, j); height = ROW_TOP_YPIXEL (sheet, i)- y + yyy_row_height (sheet, i); @@ -4383,12 +4238,12 @@ gtk_sheet_new_selection (GtkSheet *sheet, GtkSheetRange *range) selected= (i <= new_range.rowi && i >= new_range.row0 && j <= new_range.coli && j >= new_range.col0) ? TRUE : FALSE; - if (state!=GTK_STATE_SELECTED && selected && + if (state != GTK_STATE_SELECTED && selected && xxx_column_is_visible (sheet, j) && yyy_row_is_visible (sheet, i) && (i != sheet->active_cell.row || j != sheet->active_cell.col)) { - x = COLUMN_LEFT_XPIXEL (sheet,j); + x = COLUMN_LEFT_XPIXEL (sheet, j); y = ROW_TOP_YPIXEL (sheet, i); width = COLUMN_LEFT_XPIXEL (sheet, j)- x+ xxx_column_width (sheet, j); height = ROW_TOP_YPIXEL (sheet, i)- y + yyy_row_height (sheet, i); @@ -4409,8 +4264,8 @@ gtk_sheet_new_selection (GtkSheet *sheet, GtkSheetRange *range) gdk_draw_rectangle (sheet->sheet_window, sheet->xor_gc, TRUE, - x + 1,y + 1, - width,height); + x + 1, y + 1, + width, height); } @@ -4436,9 +4291,9 @@ gtk_sheet_new_selection (GtkSheet *sheet, GtkSheetRange *range) mask2 = i == new_range.rowi ? mask2 + 2 : mask2; mask2 = j == new_range.col0 ? mask2 + 4 : mask2; mask2 = j == new_range.coli ? mask2 + 8 : mask2; - if (mask2!=mask1 || (mask2 == mask1 && state!=GTK_STATE_SELECTED)) + if (mask2 != mask1 || (mask2 == mask1 && state != GTK_STATE_SELECTED)) { - x = COLUMN_LEFT_XPIXEL (sheet,j); + x = COLUMN_LEFT_XPIXEL (sheet, j); y = ROW_TOP_YPIXEL (sheet, i); width = xxx_column_width (sheet, j); height = yyy_row_height (sheet, i); @@ -4446,31 +4301,31 @@ gtk_sheet_new_selection (GtkSheet *sheet, GtkSheetRange *range) gdk_draw_rectangle (sheet->sheet_window, sheet->xor_gc, TRUE, - x + 1,y - 1, - width,3); + x + 1, y - 1, + width, 3); if (mask2 & 2) gdk_draw_rectangle (sheet->sheet_window, sheet->xor_gc, TRUE, - x + 1,y + height - 1, - width,3); + x + 1, y + height - 1, + width, 3); if (mask2 & 4) gdk_draw_rectangle (sheet->sheet_window, sheet->xor_gc, TRUE, - x - 1,y + 1, - 3,height); + x - 1, y + 1, + 3, height); if (mask2 & 8) gdk_draw_rectangle (sheet->sheet_window, sheet->xor_gc, TRUE, - x + width - 1,y + 1, - 3,height); + x + width - 1, y + 1, + 3, height); @@ -4497,8 +4352,8 @@ gtk_sheet_draw_border (GtkSheet *sheet, GtkSheetRange new_range) widget = GTK_WIDGET (sheet); - x = COLUMN_LEFT_XPIXEL (sheet,new_range.col0); - y = ROW_TOP_YPIXEL (sheet,new_range.row0); + x = COLUMN_LEFT_XPIXEL (sheet, new_range.col0); + y = ROW_TOP_YPIXEL (sheet, new_range.row0); width = COLUMN_LEFT_XPIXEL (sheet, new_range.coli) - x + xxx_column_width (sheet, new_range.coli); @@ -4543,13 +4398,13 @@ gtk_sheet_draw_border (GtkSheet *sheet, GtkSheetRange new_range) static void gtk_sheet_draw_corners (GtkSheet *sheet, GtkSheetRange range) { - gint x,y; + gint x, y; guint width = 1; if (gtk_sheet_cell_isvisible (sheet, range.row0, range.col0)) { - x = COLUMN_LEFT_XPIXEL (sheet,range.col0); - y = ROW_TOP_YPIXEL (sheet,range.row0); + x = COLUMN_LEFT_XPIXEL (sheet, range.col0); + y = ROW_TOP_YPIXEL (sheet, range.row0); gdk_draw_pixmap (sheet->sheet_window, GTK_WIDGET (sheet)->style->fg_gc[GTK_STATE_NORMAL], sheet->pixmap, @@ -4562,20 +4417,20 @@ gtk_sheet_draw_corners (GtkSheet *sheet, GtkSheetRange range) gdk_draw_rectangle (sheet->sheet_window, sheet->xor_gc, TRUE, - x - 1,y - 1, - 3,3); + x - 1, y - 1, + 3, 3); } if (gtk_sheet_cell_isvisible (sheet, range.row0, range.coli) || sheet->state == GTK_SHEET_COLUMN_SELECTED) { - x = COLUMN_LEFT_XPIXEL (sheet,range.coli)+ + x = COLUMN_LEFT_XPIXEL (sheet, range.coli)+ xxx_column_width (sheet, range.coli); - y = ROW_TOP_YPIXEL (sheet,range.row0); + y = ROW_TOP_YPIXEL (sheet, range.row0); width = 1; if (sheet->state == GTK_SHEET_COLUMN_SELECTED) { - y = ROW_TOP_YPIXEL (sheet, sheet->view.row0)+3; + y = ROW_TOP_YPIXEL (sheet, MIN_VISIBLE_ROW (sheet))+3; width = 3; } gdk_draw_pixmap (sheet->sheet_window, @@ -4590,20 +4445,20 @@ gtk_sheet_draw_corners (GtkSheet *sheet, GtkSheetRange range) gdk_draw_rectangle (sheet->sheet_window, sheet->xor_gc, TRUE, - x - width + width / 2,y - width + width / 2, - 2 + width,2 + width); + x - width + width / 2, y - width + width / 2, + 2 + width, 2 + width); } if (gtk_sheet_cell_isvisible (sheet, range.rowi, range.col0) || sheet->state == GTK_SHEET_ROW_SELECTED) { - x = COLUMN_LEFT_XPIXEL (sheet,range.col0); - y = ROW_TOP_YPIXEL (sheet,range.rowi)+ + x = COLUMN_LEFT_XPIXEL (sheet, range.col0); + y = ROW_TOP_YPIXEL (sheet, range.rowi)+ yyy_row_height (sheet, range.rowi); width = 1; if (sheet->state == GTK_SHEET_ROW_SELECTED) { - x = COLUMN_LEFT_XPIXEL (sheet, sheet->view.col0)+3; + x = COLUMN_LEFT_XPIXEL (sheet, MIN_VISIBLE_COLUMN (sheet))+3; width = 3; } gdk_draw_pixmap (sheet->sheet_window, @@ -4618,15 +4473,15 @@ gtk_sheet_draw_corners (GtkSheet *sheet, GtkSheetRange range) gdk_draw_rectangle (sheet->sheet_window, sheet->xor_gc, TRUE, - x - width + width / 2,y - width + width / 2, - 2 + width,2 + width); + x - width + width / 2, y - width + width / 2, + 2 + width, 2 + width); } if (gtk_sheet_cell_isvisible (sheet, range.rowi, range.coli)) { - x = COLUMN_LEFT_XPIXEL (sheet,range.coli)+ + x = COLUMN_LEFT_XPIXEL (sheet, range.coli)+ xxx_column_width (sheet, range.coli); - y = ROW_TOP_YPIXEL (sheet,range.rowi)+ + y = ROW_TOP_YPIXEL (sheet, range.rowi)+ yyy_row_height (sheet, range.rowi); width = 1; if (sheet->state == GTK_SHEET_RANGE_SELECTED) width = 3; @@ -4643,8 +4498,8 @@ gtk_sheet_draw_corners (GtkSheet *sheet, GtkSheetRange range) gdk_draw_rectangle (sheet->sheet_window, sheet->xor_gc, TRUE, - x - width + width / 2,y - width + width / 2, - 2 + width,2 + width); + x - width + width / 2, y - width + width / 2, + 2 + width, 2 + width); } @@ -4679,9 +4534,21 @@ gtk_sheet_real_select_range (GtkSheet * sheet, gtk_sheet_range_draw_selection (sheet, sheet->range); } - gtk_signal_emit (GTK_OBJECT (sheet), sheet_signals[SELECT_RANGE], &sheet->range); + gtk_sheet_update_primary_selection (sheet); + + g_signal_emit (G_OBJECT (sheet), sheet_signals[SELECT_RANGE], 0, &sheet->range); } + +void +gtk_sheet_get_selected_range (GtkSheet *sheet, + GtkSheetRange *range) +{ + g_return_if_fail (sheet != NULL); + *range = sheet->range; +} + + void gtk_sheet_select_range (GtkSheet * sheet, const GtkSheetRange *range) { @@ -4723,6 +4590,7 @@ gtk_sheet_unselect_range (GtkSheet * sheet) { gtk_sheet_real_unselect_range (sheet, NULL); sheet->state = GTK_STATE_NORMAL; + gtk_sheet_activate_cell (sheet, sheet->active_cell.row, sheet->active_cell.col); } @@ -4741,6 +4609,9 @@ gtk_sheet_real_unselect_range (GtkSheet * sheet, if (range->row0 < 0 || range->rowi < 0) return; if (range->col0 < 0 || range->coli < 0) return; + g_signal_emit (G_OBJECT (sheet), sheet_signals[SELECT_COLUMN], 0, -1); + g_signal_emit (G_OBJECT (sheet), sheet_signals[SELECT_ROW], 0, -1); + if (gtk_sheet_range_isvisible (sheet, *range)) gtk_sheet_draw_backing_pixmap (sheet, *range); @@ -4844,21 +4715,37 @@ gtk_sheet_button_press (GtkWidget * widget, sheet = GTK_SHEET (widget); - if ( event->type == GDK_2BUTTON_PRESS) + /* Cancel any pending tooltips */ + if (sheet->motion_timer) { - gtk_widget_get_pointer (widget, &x, &y); - gtk_sheet_get_pixel_info (sheet, x, y, &row, &column); + g_source_remove (sheet->motion_timer); + sheet->motion_timer = 0; + } + + gtk_widget_get_pointer (widget, &x, &y); + gtk_sheet_get_pixel_info (sheet, x, y, &row, &column); + + + if (event->window == sheet->column_title_window) + { + g_signal_emit (G_OBJECT (sheet), + sheet_signals[BUTTON_EVENT_COLUMN], 0, + column, event); + + if ( event->type == GDK_2BUTTON_PRESS && event->button == 1) + g_signal_emit (G_OBJECT (sheet), + sheet_signals[DOUBLE_CLICK_COLUMN], 0, column); - if (event->window == sheet->column_title_window) - { - gtk_signal_emit (GTK_OBJECT (sheet), - sheet_signals[DOUBLE_CLICK_COLUMN], column); - } - else if (event->window == sheet->row_title_window) - { - gtk_signal_emit (GTK_OBJECT (sheet), - sheet_signals[DOUBLE_CLICK_ROW], row); - } + } + else if (event->window == sheet->row_title_window) + { + g_signal_emit (G_OBJECT (sheet), + sheet_signals[BUTTON_EVENT_ROW], 0, + row, event); + + if ( event->type == GDK_2BUTTON_PRESS && event->button == 1) + g_signal_emit (G_OBJECT (sheet), + sheet_signals[DOUBLE_CLICK_ROW], 0, row); } @@ -5034,7 +4921,7 @@ static gint gtk_sheet_scroll (gpointer data) { GtkSheet *sheet; - gint x,y,row,column; + gint x, y, row, column; gint move; sheet = GTK_SHEET (data); @@ -5135,6 +5022,7 @@ gtk_sheet_click_cell (GtkSheet *sheet, gint row, gint column, gboolean *veto) *veto = FALSE; return; } + gtk_sheet_activate_cell (sheet, row, column); } if (gtk_sheet_autoscroll (sheet)) @@ -5163,7 +5051,7 @@ gtk_sheet_button_release (GtkWidget * widget, GdkEventButton * event) { GtkSheet *sheet; - gint x,y; + gint x, y; sheet = GTK_SHEET (widget); @@ -5179,7 +5067,7 @@ gtk_sheet_button_release (GtkWidget * widget, gtk_sheet_set_column_width (sheet, sheet->drag_cell.col, new_column_width (sheet, sheet->drag_cell.col, &x)); sheet->old_hadjustment = -1.; - gtk_signal_emit_by_name (GTK_OBJECT (sheet->hadjustment), "value_changed"); + g_signal_emit_by_name (G_OBJECT (sheet->hadjustment), "value_changed"); return TRUE; } @@ -5193,7 +5081,7 @@ gtk_sheet_button_release (GtkWidget * widget, gtk_sheet_set_row_height (sheet, sheet->drag_cell.row, new_row_height (sheet, sheet->drag_cell.row, &y)); sheet->old_vadjustment = -1.; - gtk_signal_emit_by_name (GTK_OBJECT (sheet->vadjustment), "value_changed"); + g_signal_emit_by_name (G_OBJECT (sheet->vadjustment), "value_changed"); return TRUE; } @@ -5218,8 +5106,8 @@ gtk_sheet_button_release (GtkWidget * widget, old_range = sheet->range; sheet->range = sheet->drag_range; sheet->drag_range = old_range; - gtk_signal_emit (GTK_OBJECT (sheet),sheet_signals[MOVE_RANGE], - &sheet->drag_range, &sheet->range); + g_signal_emit (G_OBJECT (sheet), sheet_signals[MOVE_RANGE], 0, + &sheet->drag_range, &sheet->range); gtk_sheet_select_range (sheet, &sheet->range); } @@ -5249,8 +5137,8 @@ gtk_sheet_button_release (GtkWidget * widget, sheet->drag_range = old_range; if (sheet->state == GTK_STATE_NORMAL) sheet->state = GTK_SHEET_RANGE_SELECTED; - gtk_signal_emit (GTK_OBJECT (sheet),sheet_signals[RESIZE_RANGE], - &sheet->drag_range, &sheet->range); + g_signal_emit (G_OBJECT (sheet), sheet_signals[RESIZE_RANGE], 0, + &sheet->drag_range, &sheet->range); gtk_sheet_select_range (sheet, &sheet->range); } @@ -5271,6 +5159,158 @@ gtk_sheet_button_release (GtkWidget * widget, return TRUE; } +/* Shamelessly lifted from gtktooltips */ +static gboolean +gtk_sheet_subtitle_paint_window (GtkWidget *tip_window) +{ + GtkRequisition req; + + gtk_widget_size_request (tip_window, &req); + gtk_paint_flat_box (tip_window->style, tip_window->window, + GTK_STATE_NORMAL, GTK_SHADOW_OUT, + NULL, GTK_WIDGET(tip_window), "tooltip", + 0, 0, req.width, req.height); + + return FALSE; +} + +static GtkSheetHoverTitle * +create_hover_window (void) +{ + GtkSheetHoverTitle *hw = malloc (sizeof (*hw)); + + hw->window = gtk_window_new (GTK_WINDOW_POPUP); + +#if GTK_CHECK_VERSION (2, 9, 0) + gtk_window_set_type_hint (GTK_WINDOW (hw->window), + GDK_WINDOW_TYPE_HINT_TOOLTIP); +#endif + + gtk_widget_set_app_paintable (hw->window, TRUE); + gtk_window_set_resizable (GTK_WINDOW (hw->window), FALSE); + gtk_widget_set_name (hw->window, "gtk-tooltips"); + gtk_container_set_border_width (GTK_CONTAINER (hw->window), 4); + + g_signal_connect (hw->window, + "expose_event", + G_CALLBACK (gtk_sheet_subtitle_paint_window), + NULL); + + hw->label = gtk_label_new (NULL); + + + gtk_label_set_line_wrap (GTK_LABEL (hw->label), TRUE); + gtk_misc_set_alignment (GTK_MISC (hw->label), 0.5, 0.5); + + gtk_container_add (GTK_CONTAINER (hw->window), hw->label); + + gtk_widget_show (hw->label); + + g_signal_connect (hw->window, + "destroy", + G_CALLBACK (gtk_widget_destroyed), + &hw->window); + + return hw; +} + +#define HOVER_WINDOW_Y_OFFSET 2 + +static void +show_subtitle (GtkSheet *sheet, gint row, gint column, const gchar *subtitle) +{ + gint x, y; + gint px, py; + gint width; + + if ( ! subtitle ) + return; + + if ( ! sheet->hover_window) + { + sheet->hover_window = create_hover_window (); + gtk_widget_add_events (GTK_WIDGET (sheet), GDK_LEAVE_NOTIFY_MASK); + + g_signal_connect_swapped (sheet, "leave-notify-event", + G_CALLBACK (gtk_widget_hide), + sheet->hover_window->window); + } + + gtk_label_set_text (GTK_LABEL (sheet->hover_window->label), + subtitle); + + + sheet->hover_window->row = row; + sheet->hover_window->column = column; + + gdk_window_get_origin (GTK_WIDGET (sheet)->window, &x, &y); + + gtk_widget_get_pointer (GTK_WIDGET (sheet), &px, &py); + + gtk_widget_show (sheet->hover_window->window); + + width = GTK_WIDGET (sheet->hover_window->label)->allocation.width; + + if (row == -1 ) + { + x += px; + x -= width / 2; + y += sheet->column_title_area.y; + y += sheet->column_title_area.height; + y += HOVER_WINDOW_Y_OFFSET; + } + + if ( column == -1 ) + { + y += py; + x += sheet->row_title_area.x; + x += sheet->row_title_area.width * 2 / 3.0; + } + + gtk_window_move (GTK_WINDOW (sheet->hover_window->window), + x, y); +} + +static gboolean +motion_timeout_callback (gpointer data) +{ + GtkSheet *sheet = GTK_SHEET (data); + gint x, y; + gint row, column; + gtk_widget_get_pointer (GTK_WIDGET (sheet), &x, &y); + + if ( gtk_sheet_get_pixel_info (sheet, x, y, &row, &column) ) + { + if ( column == -1 && row == -1 ) + return FALSE; + + if ( column == -1) + { + GSheetRow *row_geo = sheet->row_geometry; + gchar *text; + + text = g_sheet_row_get_subtitle (row_geo, row); + + show_subtitle (sheet, row, column, text); + g_free (text); + } + + if ( row == -1) + { + GSheetColumn *col_geo = sheet->column_geometry; + gchar *text; + + text = g_sheet_column_get_subtitle (col_geo, column); + + show_subtitle (sheet, row, column, text ); + + g_free (text); + } + } + + return FALSE; +} + static gint gtk_sheet_motion (GtkWidget * widget, GdkEventMotion * event) @@ -5291,6 +5331,27 @@ gtk_sheet_motion (GtkWidget * widget, x = event->x; y = event->y; + if (!sheet->hover_window || ! GTK_WIDGET_VISIBLE (sheet->hover_window->window)) + { + if ( sheet->motion_timer > 0 ) + g_source_remove (sheet->motion_timer); + sheet->motion_timer = g_timeout_add (TIMEOUT_HOVER, motion_timeout_callback, sheet); + } + else + { + gint row, column; + gint wx, wy; + gtk_widget_get_pointer (widget, &wx, &wy); + + if ( gtk_sheet_get_pixel_info (sheet, wx, wy, &row, &column) ) + { + if ( row != sheet->hover_window->row || column != sheet->hover_window->column) + { + gtk_widget_hide (sheet->hover_window->window); + } + } + } + if (event->window == sheet->column_title_window && gtk_sheet_columns_resizable (sheet)) { @@ -5325,7 +5386,7 @@ gtk_sheet_motion (GtkWidget * widget, gtk_sheet_rows_resizable (sheet)) { gtk_widget_get_pointer (widget, &x, &y); - if (!GTK_SHEET_IN_SELECTION (sheet) && POSSIBLE_YDRAG (sheet,y, &column)) + if (!GTK_SHEET_IN_SELECTION (sheet) && POSSIBLE_YDRAG (sheet, y, &column)) { new_cursor = GDK_SB_V_DOUBLE_ARROW; if (new_cursor != sheet->cursor_drag->type) @@ -5363,13 +5424,13 @@ gtk_sheet_motion (GtkWidget * widget, new_cursor = GDK_TOP_LEFT_ARROW; if ( event->window == sheet->sheet_window && - ! (POSSIBLE_RESIZE (sheet,x,y,&row,&column) || GTK_SHEET_IN_RESIZE (sheet)) && (POSSIBLE_DRAG (sheet, x,y,&row,&column) || GTK_SHEET_IN_DRAG (sheet)) && + ! (POSSIBLE_RESIZE (sheet, x, y, &row, &column) || GTK_SHEET_IN_RESIZE (sheet)) && (POSSIBLE_DRAG (sheet, x, y, &row, &column) || GTK_SHEET_IN_DRAG (sheet)) && new_cursor != sheet->cursor_drag->type) { gdk_cursor_destroy (sheet->cursor_drag); sheet->cursor_drag = gdk_cursor_new (GDK_TOP_LEFT_ARROW); - gdk_window_set_cursor (sheet->sheet_window,sheet->cursor_drag); + gdk_window_set_cursor (sheet->sheet_window, sheet->cursor_drag); } new_cursor = GDK_SIZING; @@ -5382,7 +5443,7 @@ gtk_sheet_motion (GtkWidget * widget, { gdk_cursor_destroy (sheet->cursor_drag); sheet->cursor_drag = gdk_cursor_new (GDK_SIZING); - gdk_window_set_cursor (sheet->sheet_window,sheet->cursor_drag); + gdk_window_set_cursor (sheet->sheet_window, sheet->cursor_drag); } @@ -5426,8 +5487,8 @@ gtk_sheet_motion (GtkWidget * widget, if (GTK_SHEET_IN_DRAG (sheet)) { GtkSheetRange aux; - column = COLUMN_FROM_XPIXEL (sheet,x)- sheet->drag_cell.col; - row = ROW_FROM_YPIXEL (sheet,y)- sheet->drag_cell.row; + column = COLUMN_FROM_XPIXEL (sheet, x)- sheet->drag_cell.col; + 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; @@ -5457,17 +5518,18 @@ gtk_sheet_motion (GtkWidget * widget, gint v_h, current_col, current_row, col_threshold, row_threshold; v_h = 1; - if (abs (x - COLUMN_LEFT_XPIXEL (sheet,sheet->drag_cell.col)) > - abs (y - ROW_TOP_YPIXEL (sheet,sheet->drag_cell.row))) v_h = 2; + if (abs (x - COLUMN_LEFT_XPIXEL (sheet, sheet->drag_cell.col)) > + abs (y - ROW_TOP_YPIXEL (sheet, sheet->drag_cell.row))) v_h = 2; - current_col = COLUMN_FROM_XPIXEL (sheet,x); - current_row = ROW_FROM_YPIXEL (sheet,y); + current_col = COLUMN_FROM_XPIXEL (sheet, x); + 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 = COLUMN_LEFT_XPIXEL (sheet,current_col)+xxx_column_width (sheet,current_col)/2; + col_threshold = COLUMN_LEFT_XPIXEL (sheet, current_col) + + xxx_column_width (sheet, current_col) / 2; if (column > 0) { if (x < col_threshold) @@ -5478,7 +5540,7 @@ gtk_sheet_motion (GtkWidget * widget, if (x > col_threshold) column +=1; } - row_threshold = ROW_TOP_YPIXEL (sheet,current_row) + + row_threshold = ROW_TOP_YPIXEL (sheet, current_row) + yyy_row_height (sheet, current_row)/2; if (row > 0) { @@ -5505,7 +5567,6 @@ gtk_sheet_motion (GtkWidget * widget, if (aux.row0 + row >= 0 && aux.rowi + row < yyy_row_count (sheet) && aux.col0 + column >= 0 && aux.coli + column < xxx_column_count (sheet)) { - aux = sheet->drag_range; sheet->drag_range = sheet->range; @@ -5526,8 +5587,6 @@ gtk_sheet_motion (GtkWidget * widget, return TRUE; } - - gtk_sheet_get_pixel_info (sheet, x, y, &row, &column); if (sheet->state == GTK_SHEET_NORMAL && row == sheet->active_cell.row && @@ -5556,7 +5615,7 @@ gtk_sheet_move_query (GtkSheet *sheet, gint row, gint column) height = sheet->sheet_window_height; width = sheet->sheet_window_width; - if (row >= MAX_VISIBLE_ROW (sheet) && sheet->state!=GTK_SHEET_COLUMN_SELECTED) + if (row >= MAX_VISIBLE_ROW (sheet) && sheet->state != GTK_SHEET_COLUMN_SELECTED) { row_align = 1.; new_row = MIN (yyy_row_count (sheet), row + 1); @@ -5569,12 +5628,12 @@ gtk_sheet_move_query (GtkSheet *sheet, gint row, gint column) row_align = -1.; } } - if (row < MIN_VISIBLE_ROW (sheet) && sheet->state!=GTK_SHEET_COLUMN_SELECTED) + 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) + if (column >= MAX_VISIBLE_COLUMN (sheet) && sheet->state != GTK_SHEET_ROW_SELECTED) { col_align = 1.; new_col = MIN (xxx_column_count (sheet) - 1, column + 1); @@ -5587,7 +5646,7 @@ gtk_sheet_move_query (GtkSheet *sheet, gint row, gint column) col_align = -1.; } } - if (column < MIN_VISIBLE_COLUMN (sheet) && sheet->state!=GTK_SHEET_ROW_SELECTED) + if (column < MIN_VISIBLE_COLUMN (sheet) && sheet->state != GTK_SHEET_ROW_SELECTED) { col_align = 0.; column_move = TRUE; @@ -5606,7 +5665,7 @@ gtk_sheet_extend_selection (GtkSheet *sheet, gint row, gint column) { GtkSheetRange range; gint state; - gint r,c; + gint r, c; if (row == sheet->selection_cell.row && column == sheet->selection_cell.col) return; @@ -5639,10 +5698,10 @@ gtk_sheet_extend_selection (GtkSheet *sheet, gint row, gint column) gdk_draw_pixmap (sheet->sheet_window, GTK_WIDGET (sheet)->style->fg_gc[GTK_STATE_NORMAL], sheet->pixmap, - COLUMN_LEFT_XPIXEL (sheet,c)- 1, - ROW_TOP_YPIXEL (sheet,r)- 1, - COLUMN_LEFT_XPIXEL (sheet,c)- 1, - ROW_TOP_YPIXEL (sheet,r)- 1, + COLUMN_LEFT_XPIXEL (sheet, c)- 1, + ROW_TOP_YPIXEL (sheet, r)- 1, + COLUMN_LEFT_XPIXEL (sheet, c)- 1, + ROW_TOP_YPIXEL (sheet, r)- 1, xxx_column_width (sheet, c)+4, yyy_row_height (sheet, r)+4); gtk_sheet_range_draw_selection (sheet, sheet->range); @@ -5653,10 +5712,10 @@ gtk_sheet_extend_selection (GtkSheet *sheet, gint row, gint column) sheet->selection_cell.row = row; sheet->selection_cell.col = column; - range.col0 = MIN (column,sheet->active_cell.col); - range.coli = MAX (column,sheet->active_cell.col); - range.row0 = MIN (row,sheet->active_cell.row); - range.rowi = MAX (row,sheet->active_cell.row); + range.col0 = MIN (column, sheet->active_cell.col); + range.coli = MAX (column, sheet->active_cell.col); + range.row0 = MIN (row, sheet->active_cell.row); + range.rowi = MAX (row, sheet->active_cell.row); if (range.row0 != sheet->range.row0 || range.rowi != sheet->range.rowi || range.col0 != sheet->range.col0 || range.coli != sheet->range.coli || @@ -5670,7 +5729,7 @@ gtk_sheet_entry_key_press (GtkWidget *widget, GdkEventKey *key) { gboolean focus; - gtk_signal_emit_by_name (GTK_OBJECT (widget), "key_press_event", key, &focus); + g_signal_emit_by_name (G_OBJECT (widget), "key_press_event", key, &focus); return focus; } @@ -5704,8 +5763,8 @@ gtk_sheet_key_press (GtkWidget *widget, case GDK_Return: case GDK_KP_Enter: if (sheet->state == GTK_SHEET_NORMAL && !GTK_SHEET_IN_SELECTION (sheet)) - gtk_signal_emit_stop_by_name (GTK_OBJECT (gtk_sheet_get_entry (sheet)), - "key_press_event"); + g_signal_stop_emission_by_name (gtk_sheet_get_entry (sheet), + "key-press-event"); row = sheet->active_cell.row; col = sheet->active_cell.col; if (sheet->state == GTK_SHEET_COLUMN_SELECTED) @@ -5783,7 +5842,7 @@ gtk_sheet_key_press (GtkWidget *widget, col = MIN_VISIBLE_COLUMN (sheet); row = row - scroll; while (!yyy_row_is_visible (sheet, row) && row > 0) row--; - row = MAX (0,row); + row = MAX (0, row); gtk_sheet_click_cell (sheet, row, col, &veto); extend_selection = FALSE; break; @@ -5957,17 +6016,6 @@ gtk_sheet_size_request (GtkWidget * widget, if (sheet->row_titles_visible) requisition->width += sheet->row_title_area.width; - sheet->view.row0 = ROW_FROM_YPIXEL (sheet, sheet->column_title_area.height + 1); - sheet->view.rowi = ROW_FROM_YPIXEL (sheet, sheet->sheet_window_height - 1); - sheet->view.col0 = COLUMN_FROM_XPIXEL (sheet, sheet->row_title_area.width + 1); - sheet->view.coli = COLUMN_FROM_XPIXEL (sheet, sheet->sheet_window_width); - - if (!sheet->column_titles_visible) - sheet->view.row0 = ROW_FROM_YPIXEL (sheet, 1); - - if (!sheet->row_titles_visible) - sheet->view.col0 = COLUMN_FROM_XPIXEL (sheet, 1); - children = sheet->children; while (children) { @@ -6063,20 +6111,7 @@ gtk_sheet_size_allocate (GtkWidget * widget, /* row button allocation */ size_allocate_row_title_buttons (sheet); - - sheet->view.row0 = ROW_FROM_YPIXEL (sheet, sheet->column_title_area.height + 1); - sheet->view.rowi = ROW_FROM_YPIXEL (sheet, sheet->sheet_window_height - 1); - sheet->view.col0 = COLUMN_FROM_XPIXEL (sheet, sheet->row_title_area.width + 1); - sheet->view.coli = COLUMN_FROM_XPIXEL (sheet, sheet->sheet_window_width); - - if (!sheet->column_titles_visible) - sheet->view.row0 = ROW_FROM_YPIXEL (sheet, 1); - - if (!sheet->row_titles_visible) - sheet->view.col0 = COLUMN_FROM_XPIXEL (sheet, 1); - size_allocate_column_title_buttons (sheet); - size_allocate_row_title_buttons (sheet); /* re - scale backing pixmap */ gtk_sheet_make_backing_pixmap (sheet, 0, 0); @@ -6090,7 +6125,7 @@ static void size_allocate_column_title_buttons (GtkSheet * sheet) { gint i; - gint x,width; + gint x, width; if (!sheet->column_titles_visible) return; if (!GTK_WIDGET_REALIZED (sheet)) @@ -6119,7 +6154,7 @@ size_allocate_column_title_buttons (GtkSheet * sheet) if (MAX_VISIBLE_COLUMN (sheet) == xxx_column_count (sheet) - 1) gdk_window_clear_area (sheet->column_title_window, - 0,0, + 0, 0, sheet->column_title_area.width, sheet->column_title_area.height); @@ -6160,7 +6195,7 @@ size_allocate_row_title_buttons (GtkSheet * sheet) } if (MAX_VISIBLE_ROW (sheet) == yyy_row_count (sheet)- 1) gdk_window_clear_area (sheet->row_title_window, - 0,0, + 0, 0, sheet->row_title_area.width, sheet->row_title_area.height); @@ -6229,6 +6264,7 @@ gtk_sheet_size_allocate_entry (GtkSheet *sheet) style->fg[GTK_STATE_ACTIVE] = previous_style->fg[GTK_STATE_ACTIVE]; } gtk_widget_set_style (GTK_WIDGET (sheet_entry), style); + g_object_unref (style); } } @@ -6245,13 +6281,13 @@ gtk_sheet_size_allocate_entry (GtkSheet *sheet) column_width = xxx_column_width (sheet, sheet->active_cell.col); size = MIN (text_size, max_size); - size = MAX (size,column_width - 2 * CELLOFFSET); + size = MAX (size, column_width - 2 * CELLOFFSET); row = sheet->active_cell.row; col = sheet->active_cell.col; - shentry_allocation.x = COLUMN_LEFT_XPIXEL (sheet,sheet->active_cell.col); - shentry_allocation.y = ROW_TOP_YPIXEL (sheet,sheet->active_cell.row); + shentry_allocation.x = COLUMN_LEFT_XPIXEL (sheet, sheet->active_cell.col); + shentry_allocation.y = ROW_TOP_YPIXEL (sheet, sheet->active_cell.row); shentry_allocation.width = column_width; shentry_allocation.height = yyy_row_height (sheet, sheet->active_cell.row); @@ -6259,10 +6295,7 @@ gtk_sheet_size_allocate_entry (GtkSheet *sheet) { shentry_allocation.height -= 2 * CELLOFFSET; shentry_allocation.y += CELLOFFSET; - if (gtk_sheet_clip_text (sheet)) - shentry_allocation.width = column_width - 2 * CELLOFFSET; - else - shentry_allocation.width = size; + shentry_allocation.width = size; switch (GTK_ITEM_ENTRY (sheet_entry)->justification) { @@ -6289,7 +6322,7 @@ gtk_sheet_size_allocate_entry (GtkSheet *sheet) gtk_widget_size_allocate (sheet->sheet_entry, &shentry_allocation); - if (previous_style == style) gtk_style_unref (previous_style); + if (previous_style == style) g_object_unref (previous_style); } static void @@ -6298,14 +6331,14 @@ gtk_sheet_entry_set_max_size (GtkSheet *sheet) gint i; gint size = 0; gint sizel = 0, sizer = 0; - gint row,col; + gint row, col; GtkJustification justification; gchar *s = NULL; row = sheet->active_cell.row; col = sheet->active_cell.col; - if ( ! GTK_IS_ITEM_ENTRY (sheet->sheet_entry) || gtk_sheet_clip_text (sheet)) + if ( ! GTK_IS_ITEM_ENTRY (sheet->sheet_entry) ) return; justification = GTK_ITEM_ENTRY (sheet->sheet_entry)->justification; @@ -6359,6 +6392,7 @@ gtk_sheet_entry_set_max_size (GtkSheet *sheet) GTK_ITEM_ENTRY (sheet->sheet_entry)->text_max_size = size; } + static void create_sheet_entry (GtkSheet *sheet) { @@ -6381,7 +6415,7 @@ create_sheet_entry (GtkSheet *sheet) { if (!g_type_is_a (sheet->entry_type, GTK_TYPE_ENTRY)) { - parent = GTK_WIDGET (gtk_type_new (sheet->entry_type)); + parent = g_object_new (sheet->entry_type, NULL); sheet->sheet_entry = parent; @@ -6391,7 +6425,7 @@ create_sheet_entry (GtkSheet *sheet) } else { - parent = GTK_WIDGET (gtk_type_new (sheet->entry_type)); + parent = g_object_new (sheet->entry_type, NULL); entry = parent; found_entry = TRUE; } @@ -6420,9 +6454,9 @@ create_sheet_entry (GtkSheet *sheet) gtk_widget_realize (sheet->sheet_entry); } - gtk_signal_connect_object (GTK_OBJECT (entry),"key_press_event", - (GtkSignalFunc) gtk_sheet_entry_key_press, - GTK_OBJECT (sheet)); + g_signal_connect_swapped (G_OBJECT (entry), "key_press_event", + G_CALLBACK (gtk_sheet_entry_key_press), + sheet); gtk_widget_show (sheet->sheet_entry); } @@ -6671,7 +6705,7 @@ gtk_sheet_column_title_button_draw (GtkSheet *sheet, gint column) { GdkWindow *window = NULL; GdkRectangle allocation; - GtkSheetButton *button = NULL; + gboolean is_sensitive = FALSE; if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) return; @@ -6700,7 +6734,7 @@ gtk_sheet_column_title_button_draw (GtkSheet *sheet, gint column) } else { - button = xxx_column_button (sheet, column); + GtkSheetButton *button = xxx_column_button (sheet, column); allocation.x = COLUMN_LEFT_XPIXEL (sheet, column) + CELL_SPACING; if (sheet->row_titles_visible) allocation.x -= sheet->row_title_area.width; @@ -6710,6 +6744,12 @@ gtk_sheet_column_title_button_draw (GtkSheet *sheet, gint column) is_sensitive = xxx_column_is_sensitive (sheet, column); gtk_sheet_button_draw (sheet, window, button, is_sensitive, allocation); + + /* FIXME: Not freeing this button is correct (sort of), + because in PSPP the model always returns a static copy */ + + /* gtk_sheet_button_free (button); */ + } } @@ -6747,15 +6787,12 @@ gtk_sheet_row_title_button_draw (GtkSheet *sheet, gint row) * * functions: * adjust_scrollbars - * vadjustment_changed - * hadjustment_changed * vadjustment_value_changed * hadjustment_value_changed */ static void adjust_scrollbars (GtkSheet * sheet) { - if (sheet->vadjustment) { sheet->vadjustment->page_size = sheet->sheet_window_height; @@ -6763,7 +6800,7 @@ adjust_scrollbars (GtkSheet * sheet) sheet->vadjustment->step_increment = DEFAULT_ROW_HEIGHT (GTK_WIDGET (sheet)); sheet->vadjustment->lower = 0; sheet->vadjustment->upper = SHEET_HEIGHT (sheet) + 80; - gtk_signal_emit_by_name (GTK_OBJECT (sheet->vadjustment), "changed"); + g_signal_emit_by_name (G_OBJECT (sheet->vadjustment), "changed"); } @@ -6774,38 +6811,11 @@ adjust_scrollbars (GtkSheet * sheet) sheet->hadjustment->step_increment = DEFAULT_COLUMN_WIDTH; sheet->hadjustment->lower = 0; sheet->hadjustment->upper = SHEET_WIDTH (sheet)+ 80; - gtk_signal_emit_by_name (GTK_OBJECT (sheet->hadjustment), "changed"); + g_signal_emit_by_name (G_OBJECT (sheet->hadjustment), "changed"); } } - -static void -vadjustment_changed (GtkAdjustment * adjustment, - gpointer data) -{ - GtkSheet *sheet; - - g_return_if_fail (adjustment != NULL); - g_return_if_fail (data != NULL); - - sheet = GTK_SHEET (data); - -} - -static void -hadjustment_changed (GtkAdjustment * adjustment, - gpointer data) -{ - GtkSheet *sheet; - - g_return_if_fail (adjustment != NULL); - g_return_if_fail (data != NULL); - - sheet = GTK_SHEET (data); -} - - static void vadjustment_value_changed (GtkAdjustment * adjustment, gpointer data) @@ -6823,14 +6833,14 @@ vadjustment_value_changed (GtkAdjustment * adjustment, if (GTK_SHEET_IS_FROZEN (sheet)) return; - row = ROW_FROM_YPIXEL (sheet,sheet->column_title_area.height + CELL_SPACING); + row = ROW_FROM_YPIXEL (sheet, sheet->column_title_area.height + CELL_SPACING); if (!sheet->column_titles_visible) row = ROW_FROM_YPIXEL (sheet, CELL_SPACING); old_value = - sheet->voffset; new_row = g_sheet_row_pixel_to_row (sheet->row_geometry, - adjustment->value,sheet); + adjustment->value, sheet); y = g_sheet_row_start_pixel (sheet->row_geometry, new_row, sheet); @@ -6887,11 +6897,6 @@ vadjustment_value_changed (GtkAdjustment * adjustment, sheet->voffset = - value; - sheet->view.row0 = ROW_FROM_YPIXEL (sheet, sheet->column_title_area.height + 1); - sheet->view.rowi = ROW_FROM_YPIXEL (sheet, sheet->sheet_window_height - 1); - if (!sheet->column_titles_visible) - sheet->view.row0 = ROW_FROM_YPIXEL (sheet, 1); - if (GTK_WIDGET_REALIZED (sheet->sheet_entry) && sheet->state == GTK_SHEET_NORMAL && sheet->active_cell.row >= 0 && sheet->active_cell.col >= 0 && @@ -6933,7 +6938,7 @@ hadjustment_value_changed (GtkAdjustment * adjustment, if (GTK_SHEET_IS_FROZEN (sheet)) return; - column = COLUMN_FROM_XPIXEL (sheet,sheet->row_title_area.width + CELL_SPACING); + column = COLUMN_FROM_XPIXEL (sheet, sheet->row_title_area.width + CELL_SPACING); if (!sheet->row_titles_visible) column = COLUMN_FROM_XPIXEL (sheet, CELL_SPACING); @@ -6998,12 +7003,6 @@ hadjustment_value_changed (GtkAdjustment * adjustment, } sheet->hoffset = - value; - - sheet->view.col0 = COLUMN_FROM_XPIXEL (sheet, sheet->row_title_area.width + 1); - sheet->view.coli = COLUMN_FROM_XPIXEL (sheet, sheet->sheet_window_width); - if (!sheet->row_titles_visible) - sheet->view.col0 = COLUMN_FROM_XPIXEL (sheet, 1); - if (GTK_WIDGET_REALIZED (sheet->sheet_entry) && sheet->state == GTK_SHEET_NORMAL && sheet->active_cell.row >= 0 && sheet->active_cell.col >= 0 && @@ -7151,7 +7150,6 @@ new_column_width (GtkSheet * sheet, width = min_width; xxx_set_column_width (sheet, column, width); - sheet->view.coli = COLUMN_FROM_XPIXEL (sheet, sheet->sheet_window_width); size_allocate_column_title_buttons (sheet); return width; @@ -7185,7 +7183,6 @@ new_row_height (GtkSheet * sheet, height = min_height; yyy_set_row_height (sheet, row, height); - sheet->view.rowi = ROW_FROM_YPIXEL (sheet, sheet->sheet_window_height - 1); size_allocate_row_title_buttons (sheet); return height; @@ -7217,9 +7214,9 @@ gtk_sheet_set_column_width (GtkSheet * sheet, gtk_sheet_range_draw (sheet, NULL); } - gtk_signal_emit (GTK_OBJECT (sheet), sheet_signals[CHANGED], - 1, column); - gtk_signal_emit (GTK_OBJECT (sheet), sheet_signals[NEW_COL_WIDTH], - column, width); + g_signal_emit (G_OBJECT (sheet), sheet_signals[CHANGED], 0, -1, column); + g_signal_emit (G_OBJECT (sheet), sheet_signals[NEW_COL_WIDTH], 0, + column, width); } @@ -7250,8 +7247,9 @@ gtk_sheet_set_row_height (GtkSheet * sheet, gtk_sheet_range_draw (sheet, NULL); } - gtk_signal_emit (GTK_OBJECT (sheet), sheet_signals[CHANGED], row, - 1); - gtk_signal_emit (GTK_OBJECT (sheet), sheet_signals[NEW_ROW_HEIGHT], row, height); + g_signal_emit (G_OBJECT (sheet), sheet_signals[CHANGED], 0, row, - 1); + g_signal_emit (G_OBJECT (sheet), sheet_signals[NEW_ROW_HEIGHT], 0, + row, height); } @@ -7424,7 +7422,8 @@ gtk_sheet_attach_default (GtkSheet *sheet, return; } - gtk_sheet_attach (sheet, widget, row, col, GTK_EXPAND|GTK_FILL, GTK_EXPAND|GTK_FILL, 0, 0); + gtk_sheet_attach (sheet, widget, row, col, + GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); } void @@ -7650,11 +7649,14 @@ gtk_sheet_column_size_request (GtkSheet *sheet, { GtkRequisition button_requisition; GList *children; + GtkSheetButton *button = xxx_column_button (sheet, col); gtk_sheet_button_size_request (sheet, - xxx_column_button (sheet, col), + button, &button_requisition); + gtk_sheet_button_free (button); + *requisition = button_requisition.width; children = sheet->children; @@ -8004,3 +8006,148 @@ gtk_sheet_button_free (GtkSheetButton *button) g_free (button->label); g_free (button); } + + +static GString * +range_to_text (const GtkSheet *sheet) +{ + gchar *celltext = NULL; + gint r, c; + GString *string; + + if ( !gtk_sheet_range_isvisible (sheet, sheet->range)) + return NULL; + + string = g_string_sized_new (80); + + for (r = sheet->range.row0; r <= sheet->range.rowi; ++r) + { + for (c = sheet->range.col0; c < sheet->range.coli; ++c) + { + celltext = gtk_sheet_cell_get_text (sheet, r, c); + g_string_append (string, celltext); + g_string_append (string, "\t"); + g_free (celltext); + } + celltext = gtk_sheet_cell_get_text (sheet, r, c); + g_string_append (string, celltext); + if ( r < sheet->range.rowi) + g_string_append (string, "\n"); + g_free (celltext); + } + + return string; +} + +static GString * +range_to_html (const GtkSheet *sheet) +{ + gchar *celltext = NULL; + gint r, c; + GString *string; + + if ( !gtk_sheet_range_isvisible (sheet, sheet->range)) + return NULL; + + string = g_string_sized_new (480); + + g_string_append (string, "\n"); + g_string_append (string, "
\n"); + g_string_append (string, ""); + celltext = gtk_sheet_cell_get_text (sheet, r, c); + g_string_append (string, celltext); + g_string_append (string, " | \n"); + g_free (celltext); + } + g_string_append (string, "