1 /* This version of GtkSheet has been *heavily* modified, for the specific
2 requirements of PSPPIRE. */
4 /* GtkSheet widget for Gtk+.
5 * Copyright (C) 1999-2001 Adrian E. Feiguin <adrian@ifir.ifir.edu.ar>
7 * Based on GtkClist widget by Jay Painter, but major changes.
8 * Memory allocation routines inspired on SC (Spreadsheet Calculator)
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 * @short_description: spreadsheet widget for gtk2
29 * GtkSheet is a matrix widget for GTK+. It consists of an scrollable grid of
30 * cells where you can allocate text. Cell contents can be edited interactively
31 * through a specially designed entry, GtkItemEntry. It is also a container
32 * subclass, allowing you to display buttons, curves, pixmaps and any other
35 * You can also set many attributes as: border, foreground and background color,
36 * text justification, and more.
38 * The testgtksheet program shows how easy is to create a spreadsheet-like GUI
48 #include <gdk/gdkkeysyms.h>
49 #include <gtk/gtksignal.h>
50 #include <gtk/gtklabel.h>
51 #include <gtk/gtkbutton.h>
52 #include <gtk/gtkadjustment.h>
53 #include <gtk/gtktable.h>
54 #include <gtk/gtkbox.h>
55 #include <gtk/gtkmain.h>
56 #include <gtk/gtktypeutils.h>
57 #include <gtk/gtkentry.h>
58 #include <gtk/gtkcontainer.h>
59 #include <gtk/gtkpixmap.h>
60 #include <pango/pango.h>
61 #include "gtkitementry.h"
63 #include "gtkextra-marshal.h"
64 #include "gsheetmodel.h"
69 GTK_SHEET_IS_LOCKED = 1 << 0,
70 GTK_SHEET_IS_FROZEN = 1 << 1,
71 GTK_SHEET_IN_XDRAG = 1 << 2,
72 GTK_SHEET_IN_YDRAG = 1 << 3,
73 GTK_SHEET_IN_DRAG = 1 << 4,
74 GTK_SHEET_IN_SELECTION = 1 << 5,
75 GTK_SHEET_IN_RESIZE = 1 << 6,
76 GTK_SHEET_IN_CLIP = 1 << 7,
77 GTK_SHEET_REDRAW_PENDING = 1 << 8,
80 #define GTK_SHEET_FLAGS(sheet) (GTK_SHEET (sheet)->flags)
81 #define GTK_SHEET_SET_FLAGS(sheet,flag) (GTK_SHEET_FLAGS (sheet) |= (flag))
82 #define GTK_SHEET_UNSET_FLAGS(sheet,flag) (GTK_SHEET_FLAGS (sheet) &= ~ (flag))
84 #define GTK_SHEET_IS_LOCKED(sheet) (GTK_SHEET_FLAGS (sheet) & GTK_SHEET_IS_LOCKED)
87 #define GTK_SHEET_IS_FROZEN(sheet) (GTK_SHEET_FLAGS (sheet) & GTK_SHEET_IS_FROZEN)
88 #define GTK_SHEET_IN_XDRAG(sheet) (GTK_SHEET_FLAGS (sheet) & GTK_SHEET_IN_XDRAG)
89 #define GTK_SHEET_IN_YDRAG(sheet) (GTK_SHEET_FLAGS (sheet) & GTK_SHEET_IN_YDRAG)
90 #define GTK_SHEET_IN_DRAG(sheet) (GTK_SHEET_FLAGS (sheet) & GTK_SHEET_IN_DRAG)
91 #define GTK_SHEET_IN_SELECTION(sheet) (GTK_SHEET_FLAGS (sheet) & GTK_SHEET_IN_SELECTION)
92 #define GTK_SHEET_IN_RESIZE(sheet) (GTK_SHEET_FLAGS (sheet) & GTK_SHEET_IN_RESIZE)
93 #define GTK_SHEET_IN_CLIP(sheet) (GTK_SHEET_FLAGS (sheet) & GTK_SHEET_IN_CLIP)
94 #define GTK_SHEET_REDRAW_PENDING(sheet) (GTK_SHEET_FLAGS (sheet) & GTK_SHEET_REDRAW_PENDING)
96 #define CELL_SPACING 1
98 #define TIMEOUT_FLASH 200
99 #define TIMEOUT_HOVER 300
100 #define TIME_INTERVAL 8
101 #define COLUMN_MIN_WIDTH 10
106 #define DEFAULT_COLUMN_WIDTH 80
109 static void gtk_sheet_column_title_button_draw (GtkSheet *sheet, gint column);
111 static void gtk_sheet_row_title_button_draw (GtkSheet *sheet, gint row);
114 static gboolean gtk_sheet_cell_empty (const GtkSheet *sheet, gint row, gint col);
117 void dispose_string (const GtkSheet *sheet, gchar *text)
119 GSheetModel *model = gtk_sheet_get_model (sheet);
124 if (g_sheet_model_free_strings (model))
129 guint DEFAULT_ROW_HEIGHT (GtkWidget *widget)
131 if (!widget->style->font_desc) return 24;
134 PangoContext *context = gtk_widget_get_pango_context (widget);
135 PangoFontMetrics *metrics =
136 pango_context_get_metrics (context,
137 widget->style->font_desc,
138 pango_context_get_language (context));
139 guint val = pango_font_metrics_get_descent (metrics) +
140 pango_font_metrics_get_ascent (metrics);
141 pango_font_metrics_unref (metrics);
142 return PANGO_PIXELS (val)+2 * CELLOFFSET;
147 guint DEFAULT_FONT_ASCENT (GtkWidget *widget)
149 if (!widget->style->font_desc) return 12;
152 PangoContext *context = gtk_widget_get_pango_context (widget);
153 PangoFontMetrics *metrics =
154 pango_context_get_metrics (context,
155 widget->style->font_desc,
156 pango_context_get_language (context));
157 guint val = pango_font_metrics_get_ascent (metrics);
158 pango_font_metrics_unref (metrics);
159 return PANGO_PIXELS (val);
164 guint STRING_WIDTH (GtkWidget *widget,
165 const PangoFontDescription *font, const gchar *text)
170 layout = gtk_widget_create_pango_layout (widget, text);
171 pango_layout_set_font_description (layout, font);
173 pango_layout_get_extents (layout, NULL, &rect);
175 g_object_unref (G_OBJECT (layout));
176 return PANGO_PIXELS (rect.width);
180 guint DEFAULT_FONT_DESCENT (GtkWidget *widget)
182 if (!widget->style->font_desc) return 12;
185 PangoContext *context = gtk_widget_get_pango_context (widget);
186 PangoFontMetrics *metrics =
187 pango_context_get_metrics (context,
188 widget->style->font_desc,
189 pango_context_get_language (context));
190 guint val = pango_font_metrics_get_descent (metrics);
191 pango_font_metrics_unref (metrics);
192 return PANGO_PIXELS (val);
198 yyy_row_is_visible (const GtkSheet *sheet, gint row)
200 GSheetRow *row_geo = sheet->row_geometry;
202 return g_sheet_row_get_visibility (row_geo, row, 0);
207 yyy_row_is_sensitive (const GtkSheet *sheet, gint row)
209 GSheetRow *row_geo = sheet->row_geometry;
211 return g_sheet_row_get_sensitivity (row_geo, row, 0);
217 yyy_row_count (const GtkSheet *sheet)
219 GSheetRow *row_geo = sheet->row_geometry;
221 return g_sheet_row_get_row_count (row_geo, 0);
225 yyy_row_height (const GtkSheet *sheet, gint row)
227 GSheetRow *row_geo = sheet->row_geometry;
229 return g_sheet_row_get_height (row_geo, row, 0);
233 yyy_row_top_ypixel (const GtkSheet *sheet, gint row)
235 GSheetRow *geo = sheet->row_geometry;
237 gint y = g_sheet_row_start_pixel (geo, row, 0);
239 if ( sheet->column_titles_visible )
240 y += sheet->column_title_area.height;
246 /* Return the row containing pixel Y */
248 yyy_row_ypixel_to_row (const GtkSheet *sheet, gint y)
250 GSheetRow *geo = sheet->row_geometry;
252 gint cy = sheet->voffset;
254 if (sheet->column_titles_visible)
255 cy += sheet->column_title_area.height;
257 if (y < cy) return 0;
259 return g_sheet_row_pixel_to_row (geo, y - cy, 0);
263 /* gives the top pixel of the given row in context of
264 * the sheet's voffset */
266 ROW_TOP_YPIXEL (const GtkSheet *sheet, gint row)
268 return (sheet->voffset + yyy_row_top_ypixel (sheet, row));
272 /* returns the row index from a y pixel location in the
273 * context of the sheet's voffset */
275 ROW_FROM_YPIXEL (const GtkSheet *sheet, gint y)
277 return (yyy_row_ypixel_to_row (sheet, y));
280 static inline GtkSheetButton *
281 xxx_column_button (const GtkSheet *sheet, gint col)
283 GSheetColumn *col_geo = sheet->column_geometry;
284 if ( col < 0 ) return NULL ;
286 return g_sheet_column_get_button (col_geo, col);
291 xxx_column_left_xpixel (const GtkSheet *sheet, gint col)
293 GSheetColumn *geo = sheet->column_geometry;
295 gint x = g_sheet_column_start_pixel (geo, col);
297 if ( sheet->row_titles_visible )
298 x += sheet->row_title_area.width;
304 xxx_column_width (const GtkSheet *sheet, gint col)
306 GSheetColumn *col_geo = sheet->column_geometry;
308 return g_sheet_column_get_width (col_geo, col);
313 xxx_set_column_width (GtkSheet *sheet, gint col, gint width)
315 if ( sheet->column_geometry )
316 g_sheet_column_set_width (sheet->column_geometry, col, width);
320 xxx_column_set_left_column (GtkSheet *sheet, gint col, gint i)
322 GSheetColumn *col_geo = sheet->column_geometry;
324 g_sheet_column_set_left_text_column (col_geo, col, i);
328 xxx_column_left_column (const GtkSheet *sheet, gint col)
330 GSheetColumn *col_geo = sheet->column_geometry;
332 return g_sheet_column_get_left_text_column (col_geo, col);
336 xxx_column_set_right_column (GtkSheet *sheet, gint col, gint i)
338 GSheetColumn *col_geo = sheet->column_geometry;
340 g_sheet_column_set_right_text_column (col_geo, col, i);
344 xxx_column_right_column (const GtkSheet *sheet, gint col)
346 GSheetColumn *col_geo = sheet->column_geometry;
348 return g_sheet_column_get_right_text_column (col_geo, col);
351 static inline GtkJustification
352 xxx_column_justification (const GtkSheet *sheet, gint col)
354 GSheetColumn *col_geo = sheet->column_geometry;
356 return g_sheet_column_get_justification (col_geo, col);
360 xxx_column_is_visible (const GtkSheet *sheet, gint col)
362 GSheetColumn *col_geo = sheet->column_geometry;
364 return g_sheet_column_get_visibility (col_geo, col);
369 xxx_column_is_sensitive (const GtkSheet *sheet, gint col)
371 GSheetColumn *col_geo = sheet->column_geometry;
373 return g_sheet_column_get_sensitivity (col_geo, col);
377 /* gives the left pixel of the given column in context of
378 * the sheet's hoffset */
380 COLUMN_LEFT_XPIXEL (const GtkSheet *sheet, gint ncol)
382 return (sheet->hoffset + xxx_column_left_xpixel (sheet, ncol));
386 xxx_column_count (const GtkSheet *sheet)
388 GSheetColumn *col_geo = sheet->column_geometry;
390 return g_sheet_column_get_column_count (col_geo);
393 /* returns the column index from a x pixel location in the
394 * context of the sheet's hoffset */
396 COLUMN_FROM_XPIXEL (const GtkSheet * sheet,
402 if ( sheet->row_titles_visible )
403 cx += sheet->row_title_area.width;
405 if (x < cx) return 0;
406 for (i = 0; i < xxx_column_count (sheet); i++)
408 if (x >= cx && x <= (cx + xxx_column_width (sheet, i)) &&
409 xxx_column_is_visible (sheet, i))
411 if ( xxx_column_is_visible (sheet, i))
412 cx += xxx_column_width (sheet, i);
416 return xxx_column_count (sheet) - 1;
419 /* returns the total height of the sheet */
420 static inline gint SHEET_HEIGHT (GtkSheet *sheet)
422 const gint n_rows = yyy_row_count (sheet);
424 return yyy_row_top_ypixel (sheet, n_rows - 1) +
425 yyy_row_height (sheet, n_rows - 1);
429 static inline GtkSheetButton *
430 yyy_row_button (GtkSheet *sheet, gint row)
432 GSheetRow *row_geo = sheet->row_geometry;
434 return g_sheet_row_get_button (row_geo, row, sheet);
441 yyy_set_row_height (GtkSheet *sheet, gint row, gint height)
443 if ( sheet->row_geometry )
444 g_sheet_row_set_height (sheet->row_geometry, row, height, sheet);
449 /* returns the total width of the sheet */
450 static inline gint SHEET_WIDTH (GtkSheet *sheet)
454 cx = ( sheet->row_titles_visible ? sheet->row_title_area.width : 0);
456 for (i = 0; i < xxx_column_count (sheet); i++)
457 if (xxx_column_is_visible (sheet, i))
458 cx += xxx_column_width (sheet, i);
463 #define MIN_VISIBLE_ROW(sheet) \
464 ROW_FROM_YPIXEL (sheet, sheet->column_title_area.height + 1)
466 #define MAX_VISIBLE_ROW(sheet) \
467 ROW_FROM_YPIXEL (sheet, sheet->sheet_window_height - 1)
469 #define MIN_VISIBLE_COLUMN(sheet) \
470 COLUMN_FROM_XPIXEL (sheet, sheet->row_title_area.width + 1)
472 #define MAX_VISIBLE_COLUMN(sheet) \
473 COLUMN_FROM_XPIXEL (sheet, sheet->sheet_window_width)
477 static inline gboolean
478 POSSIBLE_XDRAG (const GtkSheet *sheet, gint x, gint *drag_column)
482 column = COLUMN_FROM_XPIXEL (sheet, x);
483 *drag_column = column;
485 xdrag = COLUMN_LEFT_XPIXEL (sheet, column) + CELL_SPACING;
486 if (x <= xdrag + DRAG_WIDTH / 2 && column != 0)
488 while (! xxx_column_is_visible (sheet, column - 1) && column > 0) column--;
489 *drag_column = column - 1;
490 return xxx_column_is_sensitive (sheet, column - 1);
493 xdrag += xxx_column_width (sheet, column);
494 if (x >= xdrag - DRAG_WIDTH / 2 && x <= xdrag + DRAG_WIDTH / 2)
495 return xxx_column_is_sensitive (sheet, column);
500 static inline gboolean
501 POSSIBLE_YDRAG (const GtkSheet *sheet, gint y, gint *drag_row)
504 row = ROW_FROM_YPIXEL (sheet, y);
507 ydrag = ROW_TOP_YPIXEL (sheet,row)+CELL_SPACING;
508 if (y <= ydrag + DRAG_WIDTH / 2 && row != 0)
510 while (!yyy_row_is_visible (sheet, row - 1) && row > 0) row--;
512 return yyy_row_is_sensitive (sheet, row - 1);
515 ydrag +=yyy_row_height (sheet, row);
517 if (y >= ydrag - DRAG_WIDTH / 2 && y <= ydrag + DRAG_WIDTH / 2)
518 return yyy_row_is_sensitive (sheet, row);
524 static inline gboolean
525 POSSIBLE_DRAG (const GtkSheet *sheet, gint x, gint y,
526 gint *drag_row, gint *drag_column)
530 /* Can't drag if nothing is selected */
531 if ( sheet->range.row0 < 0 || sheet->range.rowi < 0 ||
532 sheet->range.col0 < 0 || sheet->range.coli < 0 )
535 *drag_column = COLUMN_FROM_XPIXEL (sheet, x);
536 *drag_row = ROW_FROM_YPIXEL (sheet, y);
538 if (x >= COLUMN_LEFT_XPIXEL (sheet, sheet->range.col0) - DRAG_WIDTH / 2 &&
539 x <= COLUMN_LEFT_XPIXEL (sheet, sheet->range.coli) +
540 xxx_column_width (sheet, sheet->range.coli) + DRAG_WIDTH / 2)
542 ydrag = ROW_TOP_YPIXEL (sheet,sheet->range.row0);
543 if (y >= ydrag - DRAG_WIDTH / 2 && y <= ydrag + DRAG_WIDTH / 2)
545 *drag_row = sheet->range.row0;
548 ydrag = ROW_TOP_YPIXEL (sheet, sheet->range.rowi) +
549 yyy_row_height (sheet, sheet->range.rowi);
550 if (y >= ydrag - DRAG_WIDTH / 2 && y <= ydrag + DRAG_WIDTH / 2)
552 *drag_row = sheet->range.rowi;
557 if (y >= ROW_TOP_YPIXEL (sheet, sheet->range.row0) - DRAG_WIDTH / 2 &&
558 y <= ROW_TOP_YPIXEL (sheet, sheet->range.rowi) +
559 yyy_row_height (sheet, sheet->range.rowi) + DRAG_WIDTH / 2)
561 xdrag = COLUMN_LEFT_XPIXEL (sheet, sheet->range.col0);
562 if (x >= xdrag - DRAG_WIDTH / 2 && x <= xdrag + DRAG_WIDTH / 2)
564 *drag_column = sheet->range.col0;
567 xdrag = COLUMN_LEFT_XPIXEL (sheet, sheet->range.coli) +
568 xxx_column_width (sheet, sheet->range.coli);
569 if (x >= xdrag - DRAG_WIDTH / 2 && x <= xdrag + DRAG_WIDTH / 2)
571 *drag_column = sheet->range.coli;
579 static inline gboolean
580 POSSIBLE_RESIZE (const GtkSheet *sheet, gint x, gint y,
581 gint *drag_row, gint *drag_column)
585 /* Can't drag if nothing is selected */
586 if ( sheet->range.row0 < 0 || sheet->range.rowi < 0 ||
587 sheet->range.col0 < 0 || sheet->range.coli < 0 )
590 xdrag = COLUMN_LEFT_XPIXEL (sheet,sheet->range.coli)+
591 xxx_column_width (sheet, sheet->range.coli);
593 ydrag = ROW_TOP_YPIXEL (sheet,sheet->range.rowi)+
594 yyy_row_height (sheet, sheet->range.rowi);
596 if (sheet->state == GTK_SHEET_COLUMN_SELECTED)
597 ydrag = ROW_TOP_YPIXEL (sheet, MIN_VISIBLE_ROW (sheet));
599 if (sheet->state == GTK_SHEET_ROW_SELECTED)
600 xdrag = COLUMN_LEFT_XPIXEL (sheet, MIN_VISIBLE_COLUMN (sheet));
602 *drag_column = COLUMN_FROM_XPIXEL (sheet,x);
603 *drag_row = ROW_FROM_YPIXEL (sheet,y);
605 if (x >= xdrag - DRAG_WIDTH / 2 && x <= xdrag + DRAG_WIDTH / 2 &&
606 y >= ydrag - DRAG_WIDTH / 2 && y <= ydrag + DRAG_WIDTH / 2) return TRUE;
611 static void gtk_sheet_class_init (GtkSheetClass * klass);
612 static void gtk_sheet_init (GtkSheet * sheet);
613 static void gtk_sheet_destroy (GtkObject * object);
614 static void gtk_sheet_finalize (GObject * object);
615 static void gtk_sheet_style_set (GtkWidget *widget,
616 GtkStyle *previous_style);
617 static void gtk_sheet_realize (GtkWidget * widget);
618 static void gtk_sheet_unrealize (GtkWidget * widget);
619 static void gtk_sheet_map (GtkWidget * widget);
620 static void gtk_sheet_unmap (GtkWidget * widget);
621 static gint gtk_sheet_expose (GtkWidget * widget,
622 GdkEventExpose * event);
623 static void gtk_sheet_forall (GtkContainer *container,
624 gboolean include_internals,
625 GtkCallback callback,
626 gpointer callback_data);
628 static void gtk_sheet_set_scroll_adjustments (GtkSheet *sheet,
629 GtkAdjustment *hadjustment,
630 GtkAdjustment *vadjustment);
632 static gint gtk_sheet_button_press (GtkWidget * widget,
633 GdkEventButton * event);
634 static gint gtk_sheet_button_release (GtkWidget * widget,
635 GdkEventButton * event);
636 static gint gtk_sheet_motion (GtkWidget * widget,
637 GdkEventMotion * event);
638 static gint gtk_sheet_entry_key_press (GtkWidget *widget,
640 static gint gtk_sheet_key_press (GtkWidget *widget,
642 static void gtk_sheet_size_request (GtkWidget * widget,
643 GtkRequisition * requisition);
644 static void gtk_sheet_size_allocate (GtkWidget * widget,
645 GtkAllocation * allocation);
649 static gint gtk_sheet_range_isvisible (GtkSheet * sheet,
650 GtkSheetRange range);
651 static gint gtk_sheet_cell_isvisible (GtkSheet * sheet,
652 gint row, gint column);
655 static gint gtk_sheet_flash (gpointer data);
657 /* Drawing Routines */
659 /* draw cell background and frame */
660 static void gtk_sheet_cell_draw_default (GtkSheet *sheet,
661 gint row, gint column);
663 /* draw cell contents */
664 static void gtk_sheet_cell_draw_label (GtkSheet *sheet,
665 gint row, gint column);
667 /* draw visible part of range. If range == NULL then draw the whole screen */
668 static void gtk_sheet_range_draw (GtkSheet *sheet,
669 const GtkSheetRange *range);
671 /* highlight the visible part of the selected range */
672 static void gtk_sheet_range_draw_selection (GtkSheet *sheet,
673 GtkSheetRange range);
677 static gboolean gtk_sheet_move_query (GtkSheet *sheet,
678 gint row, gint column);
679 static void gtk_sheet_real_select_range (GtkSheet * sheet,
680 const GtkSheetRange * range);
681 static void gtk_sheet_real_unselect_range (GtkSheet * sheet,
682 const GtkSheetRange * range);
683 static void gtk_sheet_extend_selection (GtkSheet *sheet,
684 gint row, gint column);
685 static void gtk_sheet_new_selection (GtkSheet *sheet,
686 GtkSheetRange *range);
687 static void gtk_sheet_draw_border (GtkSheet *sheet,
688 GtkSheetRange range);
689 static void gtk_sheet_draw_corners (GtkSheet *sheet,
690 GtkSheetRange range);
693 /* Active Cell handling */
695 static void gtk_sheet_entry_changed (GtkWidget *widget,
697 static gboolean gtk_sheet_deactivate_cell (GtkSheet *sheet);
698 static void gtk_sheet_hide_active_cell (GtkSheet *sheet);
699 static gboolean gtk_sheet_activate_cell (GtkSheet *sheet,
701 static void gtk_sheet_draw_active_cell (GtkSheet *sheet);
702 static void gtk_sheet_show_active_cell (GtkSheet *sheet);
703 static void gtk_sheet_click_cell (GtkSheet *sheet,
710 static void gtk_sheet_make_backing_pixmap (GtkSheet *sheet,
711 guint width, guint height);
712 static void gtk_sheet_draw_backing_pixmap (GtkSheet *sheet,
713 GtkSheetRange range);
716 static void adjust_scrollbars (GtkSheet * sheet);
717 static void vadjustment_value_changed (GtkAdjustment * adjustment,
719 static void hadjustment_value_changed (GtkAdjustment * adjustment,
723 static void draw_xor_vline (GtkSheet * sheet);
724 static void draw_xor_hline (GtkSheet * sheet);
725 static void draw_xor_rectangle (GtkSheet *sheet,
726 GtkSheetRange range);
727 static void gtk_sheet_draw_flashing_range (GtkSheet *sheet,
728 GtkSheetRange range);
729 static guint new_column_width (GtkSheet * sheet,
732 static guint new_row_height (GtkSheet * sheet,
737 static void create_global_button (GtkSheet *sheet);
738 static void global_button_clicked (GtkWidget *widget,
742 static void create_sheet_entry (GtkSheet *sheet);
743 static void gtk_sheet_size_allocate_entry (GtkSheet *sheet);
744 static void gtk_sheet_entry_set_max_size (GtkSheet *sheet);
746 /* Sheet button gadgets */
748 static void size_allocate_column_title_buttons (GtkSheet * sheet);
749 static void size_allocate_row_title_buttons (GtkSheet * sheet);
752 static void size_allocate_global_button (GtkSheet *sheet);
753 static void gtk_sheet_button_size_request (GtkSheet *sheet,
754 const GtkSheetButton *button,
755 GtkRequisition *requisition);
757 /* Attributes routines */
758 static void init_attributes (const GtkSheet *sheet, gint col,
759 GtkSheetCellAttr *attributes);
762 /* Memory allocation routines */
763 static void gtk_sheet_real_range_clear (GtkSheet *sheet,
764 const GtkSheetRange *range,
766 static void gtk_sheet_real_cell_clear (GtkSheet *sheet,
772 /* Container Functions */
773 static void gtk_sheet_remove (GtkContainer *container,
775 static void gtk_sheet_realize_child (GtkSheet *sheet,
776 GtkSheetChild *child);
777 static void gtk_sheet_position_child (GtkSheet *sheet,
778 GtkSheetChild *child);
779 static void gtk_sheet_position_children (GtkSheet *sheet);
780 static void gtk_sheet_child_show (GtkSheetChild *child);
781 static void gtk_sheet_child_hide (GtkSheetChild *child);
782 static void gtk_sheet_column_size_request (GtkSheet *sheet,
785 static void gtk_sheet_row_size_request (GtkSheet *sheet,
793 _gtkextra_signal_emit (GtkObject *object, guint signal_id, ...);
816 static GtkContainerClass *parent_class = NULL;
817 static guint sheet_signals[LAST_SIGNAL] = { 0 };
821 gtk_sheet_get_type ()
823 static GType sheet_type = 0;
827 static const GTypeInfo sheet_info =
829 sizeof (GtkSheetClass),
832 (GClassInitFunc) gtk_sheet_class_init,
837 (GInstanceInitFunc) gtk_sheet_init,
841 g_type_register_static (GTK_TYPE_CONTAINER, "GtkSheet",
847 static GtkSheetRange*
848 gtk_sheet_range_copy (const GtkSheetRange *range)
850 GtkSheetRange *new_range;
852 g_return_val_if_fail (range != NULL, NULL);
854 new_range = g_new (GtkSheetRange, 1);
862 gtk_sheet_range_free (GtkSheetRange *range)
864 g_return_if_fail (range != NULL);
870 gtk_sheet_range_get_type (void)
872 static GType sheet_range_type = 0;
874 if (!sheet_range_type)
877 g_boxed_type_register_static ("GtkSheetRange",
878 (GBoxedCopyFunc) gtk_sheet_range_copy,
879 (GBoxedFreeFunc) gtk_sheet_range_free);
882 return sheet_range_type;
886 gtk_sheet_class_init (GtkSheetClass * klass)
888 GtkObjectClass *object_class;
889 GtkWidgetClass *widget_class;
890 GtkContainerClass *container_class;
891 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
893 object_class = (GtkObjectClass *) klass;
894 widget_class = (GtkWidgetClass *) klass;
895 container_class = (GtkContainerClass *) klass;
897 parent_class = g_type_class_peek_parent (klass);
900 * GtkSheet::select-row
901 * @sheet: the sheet widget that emitted the signal
902 * @row: the newly selected row index
904 * A row has been selected.
906 sheet_signals[SELECT_ROW] =
907 g_signal_new ("select-row",
908 G_TYPE_FROM_CLASS (object_class),
910 offsetof (GtkSheetClass, select_row),
919 * GtkSheet::select - column
920 * @sheet: the sheet widget that emitted the signal
921 * @column: the newly selected column index
923 * A column has been selected.
925 sheet_signals[SELECT_COLUMN] =
926 g_signal_new ("select-column",
927 G_TYPE_FROM_CLASS (object_class),
929 offsetof (GtkSheetClass, select_column),
938 * GtkSheet::double - click - row
939 * @sheet: the sheet widget that emitted the signal
940 * @row: the row that was double clicked.
942 * A row's title button has been double clicked
944 sheet_signals[DOUBLE_CLICK_ROW] =
945 g_signal_new ("double-click-row",
946 G_TYPE_FROM_CLASS (object_class),
957 * GtkSheet::double - click - column
958 * @sheet: the sheet widget that emitted the signal
959 * @column: the column that was double clicked.
961 * A column's title button has been double clicked
963 sheet_signals[DOUBLE_CLICK_COLUMN] =
964 g_signal_new ("double-click-column",
965 G_TYPE_FROM_CLASS (object_class),
975 sheet_signals[SELECT_RANGE] =
976 g_signal_new ("select-range",
977 G_TYPE_FROM_CLASS (object_class),
979 offsetof (GtkSheetClass, select_range),
981 gtkextra_VOID__BOXED,
984 GTK_TYPE_SHEET_RANGE);
987 sheet_signals[CLIP_RANGE] =
988 g_signal_new ("clip-range",
989 G_TYPE_FROM_CLASS (object_class),
991 offsetof (GtkSheetClass, clip_range),
993 gtkextra_VOID__BOXED,
996 GTK_TYPE_SHEET_RANGE);
998 sheet_signals[RESIZE_RANGE] =
999 g_signal_new ("resize-range",
1000 G_TYPE_FROM_CLASS (object_class),
1002 offsetof (GtkSheetClass, resize_range),
1004 gtkextra_VOID__BOXED_BOXED,
1007 GTK_TYPE_SHEET_RANGE, GTK_TYPE_SHEET_RANGE
1010 sheet_signals[MOVE_RANGE] =
1011 g_signal_new ("move-range",
1012 G_TYPE_FROM_CLASS (object_class),
1014 offsetof (GtkSheetClass, move_range),
1016 gtkextra_VOID__BOXED_BOXED,
1019 GTK_TYPE_SHEET_RANGE, GTK_TYPE_SHEET_RANGE
1022 sheet_signals[TRAVERSE] =
1023 g_signal_new ("traverse",
1024 G_TYPE_FROM_CLASS (object_class),
1026 offsetof (GtkSheetClass, traverse),
1028 gtkextra_BOOLEAN__INT_INT_POINTER_POINTER,
1029 G_TYPE_BOOLEAN, 4, G_TYPE_INT, G_TYPE_INT,
1030 G_TYPE_POINTER, G_TYPE_POINTER);
1033 sheet_signals[DEACTIVATE] =
1034 g_signal_new ("deactivate",
1035 G_TYPE_FROM_CLASS (object_class),
1037 offsetof (GtkSheetClass, deactivate),
1039 gtkextra_BOOLEAN__INT_INT,
1040 G_TYPE_BOOLEAN, 2, G_TYPE_INT, G_TYPE_INT);
1042 sheet_signals[ACTIVATE] =
1043 g_signal_new ("activate",
1044 G_TYPE_FROM_CLASS (object_class),
1046 offsetof (GtkSheetClass, activate),
1048 gtkextra_BOOLEAN__INT_INT,
1049 G_TYPE_BOOLEAN, 2, G_TYPE_INT, G_TYPE_INT);
1051 sheet_signals[SET_CELL] =
1052 g_signal_new ("set-cell",
1053 G_TYPE_FROM_CLASS (object_class),
1055 offsetof (GtkSheetClass, set_cell),
1057 gtkextra_VOID__INT_INT,
1058 G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT);
1061 sheet_signals[CLEAR_CELL] =
1062 g_signal_new ("clear-cell",
1063 G_TYPE_FROM_CLASS (object_class),
1065 offsetof (GtkSheetClass, clear_cell),
1067 gtkextra_VOID__INT_INT,
1068 G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT);
1070 sheet_signals[CHANGED] =
1071 g_signal_new ("changed",
1072 G_TYPE_FROM_CLASS (object_class),
1074 offsetof (GtkSheetClass, changed),
1076 gtkextra_VOID__INT_INT,
1077 G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT);
1079 sheet_signals[NEW_COL_WIDTH] =
1080 g_signal_new ("new-column-width",
1081 G_TYPE_FROM_CLASS (object_class),
1083 offsetof (GtkSheetClass, new_column_width), /*!!!! */
1085 gtkextra_VOID__INT_INT,
1086 G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT);
1088 sheet_signals[NEW_ROW_HEIGHT] =
1089 g_signal_new ("new-row-height",
1090 G_TYPE_FROM_CLASS (object_class),
1092 offsetof (GtkSheetClass, new_row_height), /*!!!! */
1094 gtkextra_VOID__INT_INT,
1095 G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT);
1097 widget_class->set_scroll_adjustments_signal =
1098 g_signal_new ("set-scroll-adjustments",
1099 G_TYPE_FROM_CLASS (object_class),
1101 offsetof (GtkSheetClass, set_scroll_adjustments),
1103 gtkextra_VOID__OBJECT_OBJECT,
1104 G_TYPE_NONE, 2, GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
1107 container_class->add = NULL;
1108 container_class->remove = gtk_sheet_remove;
1109 container_class->forall = gtk_sheet_forall;
1111 object_class->destroy = gtk_sheet_destroy;
1112 gobject_class->finalize = gtk_sheet_finalize;
1114 widget_class->realize = gtk_sheet_realize;
1115 widget_class->unrealize = gtk_sheet_unrealize;
1116 widget_class->map = gtk_sheet_map;
1117 widget_class->unmap = gtk_sheet_unmap;
1118 widget_class->style_set = gtk_sheet_style_set;
1119 widget_class->button_press_event = gtk_sheet_button_press;
1120 widget_class->button_release_event = gtk_sheet_button_release;
1121 widget_class->motion_notify_event = gtk_sheet_motion;
1122 widget_class->key_press_event = gtk_sheet_key_press;
1123 widget_class->expose_event = gtk_sheet_expose;
1124 widget_class->size_request = gtk_sheet_size_request;
1125 widget_class->size_allocate = gtk_sheet_size_allocate;
1126 widget_class->focus_in_event = NULL;
1127 widget_class->focus_out_event = NULL;
1129 klass->set_scroll_adjustments = gtk_sheet_set_scroll_adjustments;
1130 klass->select_row = NULL;
1131 klass->select_column = NULL;
1132 klass->select_range = NULL;
1133 klass->clip_range = NULL;
1134 klass->resize_range = NULL;
1135 klass->move_range = NULL;
1136 klass->traverse = NULL;
1137 klass->deactivate = NULL;
1138 klass->activate = NULL;
1139 klass->set_cell = NULL;
1140 klass->clear_cell = NULL;
1141 klass->changed = NULL;
1145 gtk_sheet_init (GtkSheet *sheet)
1147 sheet->column_geometry = NULL;
1148 sheet->row_geometry = NULL;
1150 sheet->children = NULL;
1153 sheet->selection_mode = GTK_SELECTION_NONE;
1154 sheet->freeze_count = 0;
1155 sheet->state = GTK_SHEET_NORMAL;
1157 GTK_WIDGET_UNSET_FLAGS (sheet, GTK_NO_WINDOW);
1158 GTK_WIDGET_SET_FLAGS (sheet, GTK_CAN_FOCUS);
1160 sheet->column_title_window = NULL;
1161 sheet->column_title_area.x = 0;
1162 sheet->column_title_area.y = 0;
1163 sheet->column_title_area.width = 0;
1164 sheet->column_title_area.height = DEFAULT_ROW_HEIGHT (GTK_WIDGET (sheet));
1166 sheet->row_title_window = NULL;
1167 sheet->row_title_area.x = 0;
1168 sheet->row_title_area.y = 0;
1169 sheet->row_title_area.width = DEFAULT_COLUMN_WIDTH;
1170 sheet->row_title_area.height = 0;
1173 sheet->active_cell.row = 0;
1174 sheet->active_cell.col = 0;
1175 sheet->selection_cell.row = 0;
1176 sheet->selection_cell.col = 0;
1178 sheet->sheet_entry = NULL;
1179 sheet->pixmap = NULL;
1181 sheet->range.row0 = 0;
1182 sheet->range.rowi = 0;
1183 sheet->range.col0 = 0;
1184 sheet->range.coli = 0;
1186 sheet->state = GTK_SHEET_NORMAL;
1188 sheet->sheet_window = NULL;
1189 sheet->sheet_window_width = 0;
1190 sheet->sheet_window_height = 0;
1191 sheet->sheet_entry = NULL;
1192 sheet->button = NULL;
1197 sheet->hadjustment = NULL;
1198 sheet->vadjustment = NULL;
1200 sheet->cursor_drag = gdk_cursor_new (GDK_PLUS);
1201 sheet->xor_gc = NULL;
1202 sheet->fg_gc = NULL;
1203 sheet->bg_gc = NULL;
1207 gdk_color_parse ("white", &sheet->bg_color);
1208 gdk_color_alloc (gdk_colormap_get_system (), &sheet->bg_color);
1209 gdk_color_parse ("gray", &sheet->grid_color);
1210 gdk_color_alloc (gdk_colormap_get_system (), &sheet->grid_color);
1211 sheet->show_grid = TRUE;
1213 sheet->motion_events = 0;
1217 /* Callback which occurs whenever columns are inserted / deleted in the model */
1219 columns_inserted_deleted_callback (GSheetModel *model, gint first_column,
1224 GtkSheet *sheet = GTK_SHEET (data);
1226 GtkSheetRange range;
1227 gint model_columns = g_sheet_model_get_column_count (model);
1230 /* Need to update all the columns starting from the first column and onwards.
1231 * Previous column are unchanged, so don't need to be updated.
1233 range.col0 = first_column;
1235 range.coli = xxx_column_count (sheet) - 1;
1236 range.rowi = yyy_row_count (sheet) - 1;
1238 adjust_scrollbars (sheet);
1240 if (sheet->active_cell.col >= model_columns)
1241 gtk_sheet_activate_cell (sheet, sheet->active_cell.row, model_columns - 1);
1243 for (i = first_column; i <= MAX_VISIBLE_COLUMN (sheet); i++)
1244 gtk_sheet_column_title_button_draw (sheet, i);
1246 gtk_sheet_range_draw (sheet, &range);
1250 /* Callback which occurs whenever rows are inserted / deleted in the model */
1252 rows_inserted_deleted_callback (GSheetModel *model, gint first_row,
1253 gint n_rows, gpointer data)
1256 GtkSheet *sheet = GTK_SHEET (data);
1258 GtkSheetRange range;
1260 gint model_rows = g_sheet_model_get_row_count (model);
1262 /* Need to update all the rows starting from the first row and onwards.
1263 * Previous rows are unchanged, so don't need to be updated.
1265 range.row0 = first_row;
1267 range.rowi = yyy_row_count (sheet) - 1;
1268 range.coli = xxx_column_count (sheet) - 1;
1270 adjust_scrollbars (sheet);
1272 if (sheet->active_cell.row >= model_rows)
1273 gtk_sheet_activate_cell (sheet, model_rows - 1, sheet->active_cell.col);
1275 for (i = first_row; i <= MAX_VISIBLE_ROW (sheet); i++)
1276 gtk_sheet_row_title_button_draw (sheet, i);
1278 gtk_sheet_range_draw (sheet, &range);
1282 If row0 or rowi are negative, then all rows will be updated.
1283 If col0 or coli are negative, then all columns will be updated.
1286 range_update_callback (GSheetModel *m, gint row0, gint col0,
1287 gint rowi, gint coli, gpointer data)
1289 GtkSheet *sheet = GTK_SHEET (data);
1291 GtkSheetRange range;
1298 if ( ( row0 < 0 && col0 < 0 ) || ( rowi < 0 && coli < 0 ) )
1301 gtk_sheet_range_draw (sheet, NULL);
1302 adjust_scrollbars (sheet);
1304 for (i = MIN_VISIBLE_ROW (sheet); i <= MAX_VISIBLE_ROW (sheet); i++)
1305 gtk_sheet_row_title_button_draw (sheet, i);
1307 for (i = MIN_VISIBLE_COLUMN (sheet);
1308 i <= MAX_VISIBLE_COLUMN (sheet); i++)
1309 gtk_sheet_column_title_button_draw (sheet, i);
1313 else if ( row0 < 0 || rowi < 0 )
1315 range.row0 = MIN_VISIBLE_ROW (sheet);
1316 range.rowi = MAX_VISIBLE_ROW (sheet);
1318 else if ( col0 < 0 || coli < 0 )
1320 range.col0 = MIN_VISIBLE_COLUMN (sheet);
1321 range.coli = MAX_VISIBLE_COLUMN (sheet);
1324 gtk_sheet_range_draw (sheet, &range);
1328 static void gtk_sheet_construct (GtkSheet *sheet,
1331 const gchar *title);
1336 * @rows: initial number of rows
1337 * @columns: initial number of columns
1338 * @title: sheet title
1339 * @model: the model to use for the sheet data
1341 * Creates a new sheet widget with the given number of rows and columns.
1343 * Returns: the new sheet widget
1346 gtk_sheet_new (GSheetRow *vgeo, GSheetColumn *hgeo, const gchar *title,
1349 GtkWidget *widget = g_object_new (GTK_TYPE_SHEET, NULL);
1351 gtk_sheet_construct (GTK_SHEET (widget), vgeo, hgeo, title);
1354 gtk_sheet_set_model (GTK_SHEET (widget), model);
1362 * gtk_sheet_set_model
1363 * @sheet: the sheet to set the model for
1364 * @model: the model to use for the sheet data
1366 * Sets the model for a GtkSheet
1370 gtk_sheet_set_model (GtkSheet *sheet, GSheetModel *model)
1372 g_return_if_fail (GTK_IS_SHEET (sheet));
1373 g_return_if_fail (G_IS_SHEET_MODEL (model));
1375 sheet->model = model;
1377 g_signal_connect (model, "range_changed",
1378 G_CALLBACK (range_update_callback), sheet);
1380 g_signal_connect (model, "rows_inserted",
1381 G_CALLBACK (rows_inserted_deleted_callback), sheet);
1383 g_signal_connect (model, "rows_deleted",
1384 G_CALLBACK (rows_inserted_deleted_callback), sheet);
1386 g_signal_connect (model, "columns_inserted",
1387 G_CALLBACK (columns_inserted_deleted_callback), sheet);
1389 g_signal_connect (model, "columns_deleted",
1390 G_CALLBACK (columns_inserted_deleted_callback), sheet);
1395 /* Call back for when the column titles have changed.
1396 FIRST is the first column changed.
1397 N_COLUMNS is the number of columns which have changed, or - 1, which
1398 indicates that the column has changed to its right - most extremity
1401 column_titles_changed (GtkWidget *w, gint first, gint n_columns, gpointer data)
1403 GtkSheet *sheet = GTK_SHEET (data);
1404 gboolean extremity = FALSE;
1406 if ( n_columns == -1 )
1409 n_columns = xxx_column_count (sheet) - 1 ;
1412 if (!GTK_SHEET_IS_FROZEN (sheet))
1415 for ( i = first ; i <= first + n_columns ; ++i )
1417 gtk_sheet_column_title_button_draw (sheet, i);
1418 g_signal_emit (G_OBJECT (sheet), sheet_signals[CHANGED], 0, -1, i);
1423 gtk_sheet_column_title_button_draw (sheet, -1);
1428 gtk_sheet_construct (GtkSheet *sheet,
1433 g_return_if_fail (G_IS_SHEET_COLUMN (hgeo));
1434 g_return_if_fail (G_IS_SHEET_ROW (vgeo));
1436 sheet->column_geometry = hgeo;
1437 sheet->row_geometry = vgeo;
1440 sheet->columns_resizable = TRUE;
1441 sheet->rows_resizable = TRUE;
1443 sheet->row_titles_visible = TRUE;
1444 sheet->row_title_area.width = DEFAULT_COLUMN_WIDTH;
1446 sheet->column_titles_visible = TRUE;
1447 sheet->autoscroll = TRUE;
1448 sheet->justify_entry = TRUE;
1451 /* create sheet entry */
1452 sheet->entry_type = 0;
1453 create_sheet_entry (sheet);
1455 /* create global selection button */
1456 create_global_button (sheet);
1459 sheet->name = g_strdup (title);
1461 g_signal_connect (sheet->column_geometry, "columns_changed",
1462 G_CALLBACK (column_titles_changed), sheet);
1468 gtk_sheet_new_with_custom_entry (GSheetRow *rows, GSheetColumn *columns,
1469 const gchar *title, GtkType entry_type)
1471 GtkWidget *widget = g_object_new (GTK_TYPE_SHEET, NULL);
1473 gtk_sheet_construct_with_custom_entry (GTK_SHEET (widget),
1474 rows, columns, title, entry_type);
1480 gtk_sheet_construct_with_custom_entry (GtkSheet *sheet,
1486 gtk_sheet_construct (sheet, vgeo, hgeo, title);
1488 sheet->entry_type = entry_type;
1489 create_sheet_entry (sheet);
1495 gtk_sheet_change_entry (GtkSheet *sheet, GtkType entry_type)
1499 g_return_if_fail (sheet != NULL);
1500 g_return_if_fail (GTK_IS_SHEET (sheet));
1502 state = sheet->state;
1504 if (sheet->state == GTK_SHEET_NORMAL)
1505 gtk_sheet_hide_active_cell (sheet);
1507 sheet->entry_type = entry_type;
1509 create_sheet_entry (sheet);
1511 if (state == GTK_SHEET_NORMAL)
1513 gtk_sheet_show_active_cell (sheet);
1514 g_signal_connect (G_OBJECT (gtk_sheet_get_entry (sheet)),
1516 G_CALLBACK (gtk_sheet_entry_changed),
1522 gtk_sheet_show_grid (GtkSheet *sheet, gboolean show)
1524 g_return_if_fail (sheet != NULL);
1525 g_return_if_fail (GTK_IS_SHEET (sheet));
1527 if (show == sheet->show_grid) return;
1529 sheet->show_grid = show;
1531 if (!GTK_SHEET_IS_FROZEN (sheet))
1532 gtk_sheet_range_draw (sheet, NULL);
1536 gtk_sheet_grid_visible (GtkSheet *sheet)
1538 g_return_val_if_fail (sheet != NULL, 0);
1539 g_return_val_if_fail (GTK_IS_SHEET (sheet), 0);
1541 return sheet->show_grid;
1545 gtk_sheet_set_background (GtkSheet *sheet, GdkColor *color)
1547 g_return_if_fail (sheet != NULL);
1548 g_return_if_fail (GTK_IS_SHEET (sheet));
1552 gdk_color_parse ("white", &sheet->bg_color);
1553 gdk_color_alloc (gdk_colormap_get_system (), &sheet->bg_color);
1556 sheet->bg_color = *color;
1558 if (!GTK_SHEET_IS_FROZEN (sheet))
1559 gtk_sheet_range_draw (sheet, NULL);
1563 gtk_sheet_set_grid (GtkSheet *sheet, GdkColor *color)
1565 g_return_if_fail (sheet != NULL);
1566 g_return_if_fail (GTK_IS_SHEET (sheet));
1570 gdk_color_parse ("black", &sheet->grid_color);
1571 gdk_color_alloc (gdk_colormap_get_system (), &sheet->grid_color);
1574 sheet->grid_color = *color;
1576 if (!GTK_SHEET_IS_FROZEN (sheet))
1577 gtk_sheet_range_draw (sheet, NULL);
1581 gtk_sheet_get_columns_count (GtkSheet *sheet)
1583 g_return_val_if_fail (sheet != NULL, 0);
1584 g_return_val_if_fail (GTK_IS_SHEET (sheet), 0);
1586 return xxx_column_count (sheet);
1590 gtk_sheet_get_rows_count (GtkSheet *sheet)
1592 g_return_val_if_fail (sheet != NULL, 0);
1593 g_return_val_if_fail (GTK_IS_SHEET (sheet), 0);
1595 return yyy_row_count (sheet);
1599 gtk_sheet_get_state (GtkSheet *sheet)
1601 g_return_val_if_fail (sheet != NULL, 0);
1602 g_return_val_if_fail (GTK_IS_SHEET (sheet), 0);
1604 return (sheet->state);
1608 gtk_sheet_set_selection_mode (GtkSheet *sheet, gint mode)
1610 g_return_if_fail (sheet != NULL);
1611 g_return_if_fail (GTK_IS_SHEET (sheet));
1613 if (GTK_WIDGET_REALIZED (sheet))
1614 gtk_sheet_real_unselect_range (sheet, NULL);
1616 sheet->selection_mode = mode;
1620 gtk_sheet_set_autoresize (GtkSheet *sheet, gboolean autoresize)
1622 g_return_if_fail (sheet != NULL);
1623 g_return_if_fail (GTK_IS_SHEET (sheet));
1625 sheet->autoresize = autoresize;
1629 gtk_sheet_autoresize (GtkSheet *sheet)
1631 g_return_val_if_fail (sheet != NULL, FALSE);
1632 g_return_val_if_fail (GTK_IS_SHEET (sheet), FALSE);
1634 return sheet->autoresize;
1638 gtk_sheet_set_column_width (GtkSheet * sheet,
1644 gtk_sheet_autoresize_column (GtkSheet *sheet, gint column)
1646 gint text_width = 0;
1649 g_return_if_fail (sheet != NULL);
1650 g_return_if_fail (GTK_IS_SHEET (sheet));
1651 if (column >= xxx_column_count (sheet) || column < 0) return;
1653 for (row = 0; row < yyy_row_count (sheet); row++)
1655 gchar *text = gtk_sheet_cell_get_text (sheet, row, column);
1656 if (text && strlen (text) > 0)
1658 GtkSheetCellAttr attributes;
1660 gtk_sheet_get_attributes (sheet, row, column, &attributes);
1661 if (attributes.is_visible)
1663 gint width = STRING_WIDTH (GTK_WIDGET (sheet),
1664 attributes.font_desc,
1666 + 2 * CELLOFFSET + attributes.border.width;
1667 text_width = MAX (text_width, width);
1670 dispose_string (sheet, text);
1673 if (text_width > xxx_column_width (sheet, column) )
1675 gtk_sheet_set_column_width (sheet, column, text_width);
1676 GTK_SHEET_SET_FLAGS (sheet, GTK_SHEET_REDRAW_PENDING);
1682 gtk_sheet_set_autoscroll (GtkSheet *sheet, gboolean autoscroll)
1684 g_return_if_fail (sheet != NULL);
1685 g_return_if_fail (GTK_IS_SHEET (sheet));
1687 sheet->autoscroll = autoscroll;
1691 gtk_sheet_autoscroll (GtkSheet *sheet)
1693 g_return_val_if_fail (sheet != NULL, FALSE);
1694 g_return_val_if_fail (GTK_IS_SHEET (sheet), FALSE);
1696 return sheet->autoscroll;
1700 gtk_sheet_set_clip_text (GtkSheet *sheet, gboolean clip_text)
1702 g_return_if_fail (sheet != NULL);
1703 g_return_if_fail (GTK_IS_SHEET (sheet));
1705 sheet->clip_text = clip_text;
1709 gtk_sheet_clip_text (GtkSheet *sheet)
1711 g_return_val_if_fail (sheet != NULL, FALSE);
1712 g_return_val_if_fail (GTK_IS_SHEET (sheet), FALSE);
1714 return sheet->clip_text;
1718 gtk_sheet_set_justify_entry (GtkSheet *sheet, gboolean justify)
1720 g_return_if_fail (sheet != NULL);
1721 g_return_if_fail (GTK_IS_SHEET (sheet));
1723 sheet->justify_entry = justify;
1727 gtk_sheet_justify_entry (GtkSheet *sheet)
1729 g_return_val_if_fail (sheet != NULL, FALSE);
1730 g_return_val_if_fail (GTK_IS_SHEET (sheet), FALSE);
1732 return sheet->justify_entry;
1736 gtk_sheet_set_locked (GtkSheet *sheet, gboolean locked)
1738 g_return_if_fail (sheet != NULL);
1739 g_return_if_fail (GTK_IS_SHEET (sheet));
1743 GTK_SHEET_SET_FLAGS (sheet,GTK_SHEET_IS_LOCKED);
1744 gtk_widget_hide (sheet->sheet_entry);
1745 gtk_widget_unmap (sheet->sheet_entry);
1749 GTK_SHEET_UNSET_FLAGS (sheet,GTK_SHEET_IS_LOCKED);
1750 if (GTK_WIDGET_MAPPED (GTK_WIDGET (sheet)))
1752 gtk_widget_show (sheet->sheet_entry);
1753 gtk_widget_map (sheet->sheet_entry);
1757 gtk_editable_set_editable (GTK_EDITABLE (sheet->sheet_entry), locked);
1762 gtk_sheet_locked (const GtkSheet *sheet)
1764 g_return_val_if_fail (sheet != NULL, FALSE);
1765 g_return_val_if_fail (GTK_IS_SHEET (sheet), FALSE);
1767 return GTK_SHEET_IS_LOCKED (sheet);
1770 /* This routine has problems with gtk+- 1.2 related with the
1771 label / button drawing - I think it's a bug in gtk+- 1.2 */
1773 gtk_sheet_set_title (GtkSheet *sheet, const gchar *title)
1777 g_return_if_fail (sheet != NULL);
1778 g_return_if_fail (title != NULL);
1779 g_return_if_fail (GTK_IS_SHEET (sheet));
1782 g_free (sheet->name);
1784 sheet->name = g_strdup (title);
1786 if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet)) || !title) return;
1788 if (GTK_BIN (sheet->button)->child)
1789 label = GTK_BIN (sheet->button)->child;
1791 size_allocate_global_button (sheet);
1795 gtk_sheet_freeze (GtkSheet *sheet)
1797 g_return_if_fail (sheet != NULL);
1798 g_return_if_fail (GTK_IS_SHEET (sheet));
1800 sheet->freeze_count++;
1801 GTK_SHEET_SET_FLAGS (sheet, GTK_SHEET_IS_FROZEN);
1805 gtk_sheet_thaw (GtkSheet *sheet)
1807 g_return_if_fail (sheet != NULL);
1808 g_return_if_fail (GTK_IS_SHEET (sheet));
1810 if (sheet->freeze_count == 0) return;
1812 sheet->freeze_count--;
1813 if (sheet->freeze_count > 0) return;
1815 adjust_scrollbars (sheet);
1817 GTK_SHEET_UNSET_FLAGS (sheet, GTK_SHEET_IS_FROZEN);
1819 sheet->old_vadjustment = -1.;
1820 sheet->old_hadjustment = -1.;
1822 if (sheet->hadjustment)
1823 g_signal_emit_by_name (G_OBJECT (sheet->hadjustment),
1825 if (sheet->vadjustment)
1826 g_signal_emit_by_name (G_OBJECT (sheet->vadjustment),
1829 if (sheet->state == GTK_STATE_NORMAL)
1830 if (sheet->sheet_entry && GTK_WIDGET_MAPPED (sheet->sheet_entry))
1832 gtk_sheet_activate_cell (sheet, sheet->active_cell.row,
1833 sheet->active_cell.col);
1839 gtk_sheet_set_row_titles_width (GtkSheet *sheet, guint width)
1841 if (width < COLUMN_MIN_WIDTH) return;
1843 sheet->row_title_area.width = width;
1845 adjust_scrollbars (sheet);
1847 sheet->old_hadjustment = -1.;
1848 if (sheet->hadjustment)
1849 g_signal_emit_by_name (G_OBJECT (sheet->hadjustment),
1851 size_allocate_global_button (sheet);
1855 gtk_sheet_set_column_titles_height (GtkSheet *sheet, guint height)
1857 if (height < DEFAULT_ROW_HEIGHT (GTK_WIDGET (sheet))) return;
1859 sheet->column_title_area.height = height;
1861 adjust_scrollbars (sheet);
1863 sheet->old_vadjustment = -1.;
1864 if (sheet->vadjustment)
1865 g_signal_emit_by_name (G_OBJECT (sheet->vadjustment),
1867 size_allocate_global_button (sheet);
1871 gtk_sheet_show_column_titles (GtkSheet *sheet)
1875 if (sheet->column_titles_visible) return;
1877 sheet->column_titles_visible = TRUE;
1880 if (GTK_WIDGET_REALIZED (GTK_WIDGET (sheet)))
1882 gdk_window_show (sheet->column_title_window);
1883 gdk_window_move_resize (sheet->column_title_window,
1884 sheet->column_title_area.x,
1885 sheet->column_title_area.y,
1886 sheet->column_title_area.width,
1887 sheet->column_title_area.height);
1889 for (col = MIN_VISIBLE_COLUMN (sheet);
1890 col <= MAX_VISIBLE_COLUMN (sheet);
1893 GtkSheetButton *button = xxx_column_button (sheet, col);
1894 GtkSheetChild *child = button->child;
1896 gtk_sheet_child_show (child);
1897 gtk_sheet_button_free (button);
1899 adjust_scrollbars (sheet);
1902 sheet->old_vadjustment = -1.;
1903 if (sheet->vadjustment)
1904 g_signal_emit_by_name (G_OBJECT (sheet->vadjustment),
1906 size_allocate_global_button (sheet);
1911 gtk_sheet_show_row_titles (GtkSheet *sheet)
1915 if (sheet->row_titles_visible) return;
1917 sheet->row_titles_visible = TRUE;
1920 if (GTK_WIDGET_REALIZED (GTK_WIDGET (sheet)))
1922 gdk_window_show (sheet->row_title_window);
1923 gdk_window_move_resize (sheet->row_title_window,
1924 sheet->row_title_area.x,
1925 sheet->row_title_area.y,
1926 sheet->row_title_area.width,
1927 sheet->row_title_area.height);
1929 for (row = MIN_VISIBLE_ROW (sheet);
1930 row <= MAX_VISIBLE_ROW (sheet);
1933 const GtkSheetButton *button = yyy_row_button (sheet, row);
1934 GtkSheetChild *child = button->child;
1938 gtk_sheet_child_show (child);
1941 adjust_scrollbars (sheet);
1944 sheet->old_hadjustment = -1.;
1945 if (sheet->hadjustment)
1946 g_signal_emit_by_name (G_OBJECT (sheet->hadjustment),
1948 size_allocate_global_button (sheet);
1952 gtk_sheet_hide_column_titles (GtkSheet *sheet)
1956 if (!sheet->column_titles_visible) return;
1958 sheet->column_titles_visible = FALSE;
1960 if (GTK_WIDGET_REALIZED (GTK_WIDGET (sheet)))
1962 if (sheet->column_title_window)
1963 gdk_window_hide (sheet->column_title_window);
1964 if (GTK_WIDGET_VISIBLE (sheet->button))
1965 gtk_widget_hide (sheet->button);
1967 for (col = MIN_VISIBLE_COLUMN (sheet);
1968 col <= MAX_VISIBLE_COLUMN (sheet);
1971 GtkSheetButton *button = xxx_column_button (sheet, col);
1972 GtkSheetChild *child = button->child;
1974 gtk_sheet_child_hide (child);
1975 gtk_sheet_button_free (button);
1977 adjust_scrollbars (sheet);
1980 sheet->old_vadjustment = -1.;
1981 if (sheet->vadjustment)
1982 g_signal_emit_by_name (G_OBJECT (sheet->vadjustment),
1987 gtk_sheet_hide_row_titles (GtkSheet *sheet)
1991 if (!sheet->row_titles_visible) return;
1993 sheet->row_titles_visible = FALSE;
1996 if (GTK_WIDGET_REALIZED (GTK_WIDGET (sheet)))
1998 if (sheet->row_title_window)
1999 gdk_window_hide (sheet->row_title_window);
2000 if (GTK_WIDGET_VISIBLE (sheet->button))
2001 gtk_widget_hide (sheet->button);
2002 for (row = MIN_VISIBLE_ROW (sheet);
2003 row <= MAX_VISIBLE_ROW (sheet);
2006 const GtkSheetButton *button = yyy_row_button (sheet, row);
2007 GtkSheetChild *child = button->child;
2010 gtk_sheet_child_hide (child);
2012 adjust_scrollbars (sheet);
2015 sheet->old_hadjustment = -1.;
2016 if (sheet->hadjustment)
2017 g_signal_emit_by_name (G_OBJECT (sheet->hadjustment),
2022 gtk_sheet_column_titles_visible (GtkSheet *sheet)
2024 g_return_val_if_fail (sheet != NULL, FALSE);
2025 g_return_val_if_fail (GTK_IS_SHEET (sheet), FALSE);
2026 return sheet->column_titles_visible;
2030 gtk_sheet_row_titles_visible (GtkSheet *sheet)
2032 g_return_val_if_fail (sheet != NULL, FALSE);
2033 g_return_val_if_fail (GTK_IS_SHEET (sheet), FALSE);
2034 return sheet->row_titles_visible;
2038 gtk_sheet_moveto (GtkSheet *sheet,
2045 guint width, height;
2047 gint min_row, min_col;
2049 g_return_if_fail (sheet != NULL);
2050 g_return_if_fail (GTK_IS_SHEET (sheet));
2051 g_return_if_fail (sheet->hadjustment != NULL);
2052 g_return_if_fail (sheet->vadjustment != NULL);
2054 if (row < 0 || row >= yyy_row_count (sheet))
2056 if (column < 0 || column >= xxx_column_count (sheet))
2059 height = sheet->sheet_window_height;
2060 width = sheet->sheet_window_width;
2062 /* adjust vertical scrollbar */
2063 if (row >= 0 && row_align >= 0.)
2065 y = ROW_TOP_YPIXEL (sheet, row) - sheet->voffset
2066 - (gint) ( row_align*height + (1. - row_align)
2067 * yyy_row_height (sheet, row));
2069 /* This forces the sheet to scroll when you don't see the entire cell */
2072 if (row_align == 1.)
2074 while (min_row >= 0 && min_row > MIN_VISIBLE_ROW (sheet))
2076 if (yyy_row_is_visible (sheet, min_row))
2077 adjust += yyy_row_height (sheet, min_row);
2078 if (adjust >= height)
2084 min_row = MAX (min_row, 0);
2085 y = ROW_TOP_YPIXEL (sheet, min_row) - sheet->voffset +
2086 yyy_row_height (sheet, min_row) - 1;
2090 sheet->vadjustment->value = 0.0;
2092 sheet->vadjustment->value = y;
2094 sheet->old_vadjustment = -1.;
2095 g_signal_emit_by_name (G_OBJECT (sheet->vadjustment),
2100 /* adjust horizontal scrollbar */
2101 if (column >= 0 && col_align >= 0.)
2103 x = COLUMN_LEFT_XPIXEL (sheet, column) - sheet->hoffset
2104 - (gint) ( col_align*width + (1.- col_align)*
2105 xxx_column_width (sheet, column));
2108 /* This forces the sheet to scroll when you don't see the entire cell */
2111 if (col_align == 1.)
2113 while (min_col >= 0 && min_col > MIN_VISIBLE_COLUMN (sheet))
2115 if (xxx_column_is_visible (sheet, min_col))
2116 adjust += xxx_column_width (sheet, min_col);
2118 if (adjust >= width)
2124 min_col = MAX (min_col, 0);
2125 x = COLUMN_LEFT_XPIXEL (sheet, min_col) - sheet->hoffset +
2126 xxx_column_width (sheet, min_col) - 1;
2130 sheet->hadjustment->value = 0.0;
2132 sheet->hadjustment->value = x;
2134 sheet->old_vadjustment = -1.;
2135 g_signal_emit_by_name (G_OBJECT (sheet->hadjustment),
2143 gtk_sheet_columns_set_resizable (GtkSheet *sheet, gboolean resizable)
2145 g_return_if_fail (sheet != NULL);
2146 g_return_if_fail (GTK_IS_SHEET (sheet));
2148 sheet->columns_resizable = resizable;
2152 gtk_sheet_columns_resizable (GtkSheet *sheet)
2154 g_return_val_if_fail (sheet != NULL, FALSE);
2155 g_return_val_if_fail (GTK_IS_SHEET (sheet), FALSE);
2157 return sheet->columns_resizable;
2162 gtk_sheet_rows_set_resizable (GtkSheet *sheet, gboolean resizable)
2164 g_return_if_fail (sheet != NULL);
2165 g_return_if_fail (GTK_IS_SHEET (sheet));
2167 sheet->rows_resizable = resizable;
2171 gtk_sheet_rows_resizable (GtkSheet *sheet)
2173 g_return_val_if_fail (sheet != NULL, FALSE);
2174 g_return_val_if_fail (GTK_IS_SHEET (sheet), FALSE);
2176 return sheet->rows_resizable;
2181 gtk_sheet_select_row (GtkSheet * sheet,
2184 g_return_if_fail (sheet != NULL);
2185 g_return_if_fail (GTK_IS_SHEET (sheet));
2187 if (row < 0 || row >= yyy_row_count (sheet))
2190 if (sheet->state != GTK_SHEET_NORMAL)
2191 gtk_sheet_real_unselect_range (sheet, NULL);
2194 gboolean veto = TRUE;
2195 veto = gtk_sheet_deactivate_cell (sheet);
2199 sheet->state = GTK_SHEET_ROW_SELECTED;
2200 sheet->range.row0 = row;
2201 sheet->range.col0 = 0;
2202 sheet->range.rowi = row;
2203 sheet->range.coli = xxx_column_count (sheet) - 1;
2204 sheet->active_cell.row = row;
2205 sheet->active_cell.col = 0;
2207 g_signal_emit (G_OBJECT (sheet), sheet_signals[SELECT_ROW], 0, row);
2208 gtk_sheet_real_select_range (sheet, NULL);
2213 gtk_sheet_select_column (GtkSheet * sheet, gint column)
2215 g_return_if_fail (sheet != NULL);
2216 g_return_if_fail (GTK_IS_SHEET (sheet));
2218 if (column < 0 || column >= xxx_column_count (sheet))
2221 if (sheet->state != GTK_SHEET_NORMAL)
2222 gtk_sheet_real_unselect_range (sheet, NULL);
2225 gboolean veto = TRUE;
2226 veto = gtk_sheet_deactivate_cell (sheet);
2230 sheet->state = GTK_SHEET_COLUMN_SELECTED;
2231 sheet->range.row0 = 0;
2232 sheet->range.col0 = column;
2233 sheet->range.rowi = yyy_row_count (sheet) - 1;
2234 sheet->range.coli = column;
2235 sheet->active_cell.row = 0;
2236 sheet->active_cell.col = column;
2238 g_signal_emit (G_OBJECT (sheet), sheet_signals[SELECT_COLUMN], 0, column);
2239 gtk_sheet_real_select_range (sheet, NULL);
2245 gtk_sheet_clip_range (GtkSheet *sheet, const GtkSheetRange *range)
2248 g_return_if_fail (sheet != NULL);
2249 g_return_if_fail (GTK_IS_SHEET (sheet));
2251 if (GTK_SHEET_IN_CLIP (sheet)) return;
2253 GTK_SHEET_SET_FLAGS (sheet, GTK_SHEET_IN_CLIP);
2256 sheet->clip_range = sheet->range;
2258 sheet->clip_range=*range;
2260 sheet->interval = 0;
2261 sheet->clip_timer = g_timeout_add (TIMEOUT_FLASH, gtk_sheet_flash, sheet);
2263 g_signal_emit (G_OBJECT (sheet), sheet_signals[CLIP_RANGE], 0,
2264 &sheet->clip_range);
2268 gtk_sheet_unclip_range (GtkSheet *sheet)
2271 g_return_if_fail (sheet != NULL);
2272 g_return_if_fail (GTK_IS_SHEET (sheet));
2274 if (!GTK_SHEET_IN_CLIP (sheet)) return;
2276 GTK_SHEET_UNSET_FLAGS (sheet, GTK_SHEET_IN_CLIP);
2278 g_source_remove (sheet->clip_timer);
2279 gtk_sheet_range_draw (sheet, &sheet->clip_range);
2281 if (gtk_sheet_range_isvisible (sheet, sheet->range))
2282 gtk_sheet_range_draw (sheet, &sheet->range);
2286 gtk_sheet_in_clip (GtkSheet *sheet)
2288 g_return_val_if_fail (sheet != NULL, FALSE);
2289 g_return_val_if_fail (GTK_IS_SHEET (sheet), FALSE);
2291 return GTK_SHEET_IN_CLIP (sheet);
2295 gtk_sheet_flash (gpointer data)
2298 gint x,y,width,height;
2299 GdkRectangle clip_area;
2301 sheet = GTK_SHEET (data);
2303 if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) return TRUE;
2304 if (!GTK_WIDGET_DRAWABLE (GTK_WIDGET (sheet))) return TRUE;
2305 if (!gtk_sheet_range_isvisible (sheet, sheet->clip_range)) return TRUE;
2306 if (GTK_SHEET_IN_XDRAG (sheet)) return TRUE;
2307 if (GTK_SHEET_IN_YDRAG (sheet)) return TRUE;
2309 GDK_THREADS_ENTER ();
2311 x = COLUMN_LEFT_XPIXEL (sheet,sheet->clip_range.col0)+1;
2312 y = ROW_TOP_YPIXEL (sheet,sheet->clip_range.row0)+1;
2313 width = COLUMN_LEFT_XPIXEL (sheet,sheet->clip_range.coli)- x+
2314 xxx_column_width (sheet, sheet->clip_range.coli) - 1;
2315 height = ROW_TOP_YPIXEL (sheet,sheet->clip_range.rowi)- y+
2316 yyy_row_height (sheet, sheet->clip_range.rowi)- 1;
2318 clip_area.x = COLUMN_LEFT_XPIXEL (sheet, MIN_VISIBLE_COLUMN (sheet));
2319 clip_area.y = ROW_TOP_YPIXEL (sheet, MIN_VISIBLE_ROW (sheet));
2320 clip_area.width = sheet->sheet_window_width;
2321 clip_area.height = sheet->sheet_window_height;
2328 if (width > clip_area.width) width = clip_area.width + 10;
2334 if (height > clip_area.height) height = clip_area.height + 10;
2336 gdk_draw_pixmap (sheet->sheet_window,
2337 GTK_WIDGET (sheet)->style->fg_gc[GTK_STATE_NORMAL],
2343 gdk_draw_pixmap (sheet->sheet_window,
2344 GTK_WIDGET (sheet)->style->fg_gc[GTK_STATE_NORMAL],
2350 gdk_draw_pixmap (sheet->sheet_window,
2351 GTK_WIDGET (sheet)->style->fg_gc[GTK_STATE_NORMAL],
2357 gdk_draw_pixmap (sheet->sheet_window,
2358 GTK_WIDGET (sheet)->style->fg_gc[GTK_STATE_NORMAL],
2365 sheet->interval = sheet->interval + 1;
2366 if (sheet->interval == TIME_INTERVAL) sheet->interval = 0;
2368 gdk_gc_set_dashes (sheet->xor_gc, sheet->interval, (gint8*)"\4\4", 2);
2369 gtk_sheet_draw_flashing_range (sheet,sheet->clip_range);
2370 gdk_gc_set_dashes (sheet->xor_gc, 0, (gint8*)"\4\4", 2);
2372 GDK_THREADS_LEAVE ();
2378 gtk_sheet_draw_flashing_range (GtkSheet *sheet, GtkSheetRange range)
2380 GdkRectangle clip_area;
2381 gint x,y,width,height;
2383 if (!gtk_sheet_range_isvisible (sheet, sheet->clip_range)) return;
2385 clip_area.x = COLUMN_LEFT_XPIXEL (sheet, MIN_VISIBLE_COLUMN (sheet));
2386 clip_area.y = ROW_TOP_YPIXEL (sheet, MIN_VISIBLE_ROW (sheet));
2387 clip_area.width = sheet->sheet_window_width;
2388 clip_area.height = sheet->sheet_window_height;
2390 gdk_gc_set_clip_rectangle (sheet->xor_gc, &clip_area);
2392 x = COLUMN_LEFT_XPIXEL (sheet,sheet->clip_range.col0)+1;
2393 y = ROW_TOP_YPIXEL (sheet,sheet->clip_range.row0)+1;
2394 width = COLUMN_LEFT_XPIXEL (sheet,sheet->clip_range.coli)- x+
2395 xxx_column_width (sheet, sheet->clip_range.coli) - 1;
2396 height = ROW_TOP_YPIXEL (sheet,sheet->clip_range.rowi)- y+
2397 yyy_row_height (sheet, sheet->clip_range.rowi)- 1;
2404 if (width > clip_area.width) width = clip_area.width + 10;
2410 if (height > clip_area.height) height = clip_area.height + 10;
2412 gdk_gc_set_line_attributes (sheet->xor_gc, 1, 1, 0, 0 );
2414 gdk_draw_rectangle (sheet->sheet_window, sheet->xor_gc, FALSE,
2418 gdk_gc_set_line_attributes (sheet->xor_gc, 1, 0, 0, 0);
2420 gdk_gc_set_clip_rectangle (sheet->xor_gc, NULL);
2424 gtk_sheet_range_isvisible (GtkSheet * sheet,
2425 GtkSheetRange range)
2427 g_return_val_if_fail (sheet != NULL, FALSE);
2429 if (range.row0 < 0 || range.row0 >= yyy_row_count (sheet))
2432 if (range.rowi < 0 || range.rowi >= yyy_row_count (sheet))
2435 if (range.col0 < 0 || range.col0 >= xxx_column_count (sheet))
2438 if (range.coli < 0 || range.coli >= xxx_column_count (sheet))
2441 if (range.rowi < MIN_VISIBLE_ROW (sheet))
2444 if (range.row0 > MAX_VISIBLE_ROW (sheet))
2447 if (range.coli < MIN_VISIBLE_COLUMN (sheet))
2450 if (range.col0 > MAX_VISIBLE_COLUMN (sheet))
2457 gtk_sheet_cell_isvisible (GtkSheet * sheet,
2458 gint row, gint column)
2460 GtkSheetRange range;
2463 range.col0 = column;
2465 range.coli = column;
2467 return gtk_sheet_range_isvisible (sheet, range);
2471 gtk_sheet_get_visible_range (GtkSheet *sheet, GtkSheetRange *range)
2473 g_return_if_fail (sheet != NULL);
2474 g_return_if_fail (GTK_IS_SHEET (sheet)) ;
2475 g_return_if_fail (range != NULL);
2477 range->row0 = MIN_VISIBLE_ROW (sheet);
2478 range->col0 = MIN_VISIBLE_COLUMN (sheet);
2479 range->rowi = MAX_VISIBLE_ROW (sheet);
2480 range->coli = MAX_VISIBLE_COLUMN (sheet);
2484 gtk_sheet_get_vadjustment (GtkSheet * sheet)
2486 g_return_val_if_fail (sheet != NULL, NULL);
2487 g_return_val_if_fail (GTK_IS_SHEET (sheet), NULL);
2489 return sheet->vadjustment;
2493 gtk_sheet_get_hadjustment (GtkSheet * sheet)
2495 g_return_val_if_fail (sheet != NULL, NULL);
2496 g_return_val_if_fail (GTK_IS_SHEET (sheet), NULL);
2498 return sheet->hadjustment;
2502 gtk_sheet_set_vadjustment (GtkSheet *sheet,
2503 GtkAdjustment *adjustment)
2505 GtkAdjustment *old_adjustment;
2507 g_return_if_fail (sheet != NULL);
2508 g_return_if_fail (GTK_IS_SHEET (sheet));
2510 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
2512 if (sheet->vadjustment == adjustment)
2515 old_adjustment = sheet->vadjustment;
2517 if (sheet->vadjustment)
2519 g_signal_handlers_disconnect_matched (G_OBJECT (sheet->vadjustment),
2520 G_SIGNAL_MATCH_DATA,
2523 g_object_unref (G_OBJECT (sheet->vadjustment));
2526 sheet->vadjustment = adjustment;
2528 if (sheet->vadjustment)
2530 g_object_ref (G_OBJECT (sheet->vadjustment));
2531 g_object_ref_sink (G_OBJECT (sheet->vadjustment));
2533 g_signal_connect (G_OBJECT (sheet->vadjustment), "value_changed",
2534 G_CALLBACK (vadjustment_value_changed),
2538 if (!sheet->vadjustment || !old_adjustment)
2540 gtk_widget_queue_resize (GTK_WIDGET (sheet));
2544 sheet->old_vadjustment = sheet->vadjustment->value;
2548 gtk_sheet_set_hadjustment (GtkSheet *sheet,
2549 GtkAdjustment *adjustment)
2551 GtkAdjustment *old_adjustment;
2553 g_return_if_fail (sheet != NULL);
2554 g_return_if_fail (GTK_IS_SHEET (sheet));
2556 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
2558 if (sheet->hadjustment == adjustment)
2561 old_adjustment = sheet->hadjustment;
2563 if (sheet->hadjustment)
2565 g_signal_handlers_disconnect_matched (G_OBJECT (sheet->hadjustment),
2566 G_SIGNAL_MATCH_DATA,
2569 g_object_unref (G_OBJECT (sheet->hadjustment));
2572 sheet->hadjustment = adjustment;
2574 if (sheet->hadjustment)
2576 g_object_ref (G_OBJECT (sheet->hadjustment));
2577 g_object_ref_sink (G_OBJECT (sheet->hadjustment));
2579 g_signal_connect (G_OBJECT (sheet->hadjustment), "value_changed",
2580 G_CALLBACK (hadjustment_value_changed),
2584 if (!sheet->hadjustment || !old_adjustment)
2586 gtk_widget_queue_resize (GTK_WIDGET (sheet));
2590 sheet->old_hadjustment = sheet->hadjustment->value;
2594 gtk_sheet_set_scroll_adjustments (GtkSheet *sheet,
2595 GtkAdjustment *hadjustment,
2596 GtkAdjustment *vadjustment)
2598 if (sheet->hadjustment != hadjustment)
2599 gtk_sheet_set_hadjustment (sheet, hadjustment);
2601 if (sheet->vadjustment != vadjustment)
2602 gtk_sheet_set_vadjustment (sheet, vadjustment);
2606 gtk_sheet_finalize (GObject * object)
2610 g_return_if_fail (object != NULL);
2611 g_return_if_fail (GTK_IS_SHEET (object));
2613 sheet = GTK_SHEET (object);
2615 /* get rid of all the cells */
2616 gtk_sheet_range_clear (sheet, NULL);
2617 gtk_sheet_range_delete (sheet, NULL);
2621 g_free (sheet->name);
2625 if (G_OBJECT_CLASS (parent_class)->finalize)
2626 (*G_OBJECT_CLASS (parent_class)->finalize) (object);
2630 gtk_sheet_destroy (GtkObject * object)
2635 g_return_if_fail (object != NULL);
2636 g_return_if_fail (GTK_IS_SHEET (object));
2638 sheet = GTK_SHEET (object);
2640 /* destroy the entry */
2641 if (sheet->sheet_entry && GTK_IS_WIDGET (sheet->sheet_entry))
2643 gtk_widget_destroy (sheet->sheet_entry);
2644 sheet->sheet_entry = NULL;
2647 /* destroy the global selection button */
2648 if (sheet->button && GTK_IS_WIDGET (sheet->button))
2650 gtk_widget_destroy (sheet->button);
2651 sheet->button = NULL;
2654 if (sheet->clip_timer)
2656 g_source_remove (sheet->clip_timer);
2657 sheet->clip_timer = 0;
2660 /* unref adjustments */
2661 if (sheet->hadjustment)
2663 g_signal_handlers_disconnect_matched (G_OBJECT (sheet->hadjustment),
2664 G_SIGNAL_MATCH_DATA,
2668 g_object_unref (G_OBJECT (sheet->hadjustment));
2669 sheet->hadjustment = NULL;
2672 if (sheet->vadjustment)
2674 g_signal_handlers_disconnect_matched (G_OBJECT (sheet->vadjustment),
2675 G_SIGNAL_MATCH_DATA,
2679 g_object_unref (G_OBJECT (sheet->vadjustment));
2681 sheet->vadjustment = NULL;
2684 children = sheet->children;
2687 GtkSheetChild *child = (GtkSheetChild *)children->data;
2688 if (child && child->widget)
2689 gtk_sheet_remove (GTK_CONTAINER (sheet), child->widget);
2690 children = sheet->children;
2692 sheet->children = NULL;
2694 if (GTK_OBJECT_CLASS (parent_class)->destroy)
2695 (*GTK_OBJECT_CLASS (parent_class)->destroy) (object);
2699 gtk_sheet_style_set (GtkWidget *widget,
2700 GtkStyle *previous_style)
2704 g_return_if_fail (widget != NULL);
2705 g_return_if_fail (GTK_IS_SHEET (widget));
2707 if (GTK_WIDGET_CLASS (parent_class)->style_set)
2708 (*GTK_WIDGET_CLASS (parent_class)->style_set) (widget, previous_style);
2710 sheet = GTK_SHEET (widget);
2712 if (GTK_WIDGET_REALIZED (widget))
2714 gtk_style_set_background (widget->style, widget->window, widget->state);
2720 gtk_sheet_realize (GtkWidget * widget)
2723 GdkWindowAttr attributes;
2724 gint attributes_mask;
2725 GdkGCValues values, auxvalues;
2726 GdkColormap *colormap;
2728 GtkSheetChild *child;
2731 g_return_if_fail (widget != NULL);
2732 g_return_if_fail (GTK_IS_SHEET (widget));
2734 sheet = GTK_SHEET (widget);
2736 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
2738 attributes.window_type = GDK_WINDOW_CHILD;
2739 attributes.x = widget->allocation.x;
2740 attributes.y = widget->allocation.y;
2741 attributes.width = widget->allocation.width;
2742 attributes.height = widget->allocation.height;
2743 attributes.wclass = GDK_INPUT_OUTPUT;
2745 attributes.visual = gtk_widget_get_visual (widget);
2746 attributes.colormap = gtk_widget_get_colormap (widget);
2748 attributes.event_mask = gtk_widget_get_events (widget);
2749 attributes.event_mask |= (GDK_EXPOSURE_MASK |
2750 GDK_BUTTON_PRESS_MASK |
2751 GDK_BUTTON_RELEASE_MASK |
2752 GDK_KEY_PRESS_MASK |
2753 GDK_POINTER_MOTION_MASK |
2754 GDK_POINTER_MOTION_HINT_MASK);
2755 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP |
2758 attributes.cursor = gdk_cursor_new (GDK_TOP_LEFT_ARROW);
2761 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
2763 gdk_window_set_user_data (widget->window, sheet);
2765 widget->style = gtk_style_attach (widget->style, widget->window);
2767 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
2770 if (sheet->row_titles_visible)
2771 attributes.x = sheet->row_title_area.width;
2773 attributes.width = sheet->column_title_area.width;
2774 attributes.height = sheet->column_title_area.height;
2776 /* column - title window */
2777 sheet->column_title_window = gdk_window_new (widget->window, &attributes, attributes_mask);
2778 gdk_window_set_user_data (sheet->column_title_window, sheet);
2779 gtk_style_set_background (widget->style, sheet->column_title_window, GTK_STATE_NORMAL);
2783 if (sheet->column_titles_visible)
2784 attributes.y = sheet->column_title_area.height;
2785 attributes.width = sheet->row_title_area.width;
2786 attributes.height = sheet->row_title_area.height;
2788 /* row - title window */
2789 sheet->row_title_window = gdk_window_new (widget->window, &attributes, attributes_mask);
2790 gdk_window_set_user_data (sheet->row_title_window, sheet);
2791 gtk_style_set_background (widget->style, sheet->row_title_window, GTK_STATE_NORMAL);
2793 /* sheet - window */
2794 attributes.cursor = gdk_cursor_new (GDK_PLUS);
2798 attributes.width = sheet->sheet_window_width,
2799 attributes.height = sheet->sheet_window_height;
2801 sheet->sheet_window = gdk_window_new (widget->window, &attributes, attributes_mask);
2802 gdk_window_set_user_data (sheet->sheet_window, sheet);
2804 gdk_cursor_unref (attributes.cursor);
2806 gdk_window_set_background (sheet->sheet_window, &widget->style->white);
2807 gdk_window_show (sheet->sheet_window);
2809 /* backing_pixmap */
2810 gtk_sheet_make_backing_pixmap (sheet, 0, 0);
2814 gdk_gc_unref (sheet->fg_gc);
2816 gdk_gc_unref (sheet->bg_gc);
2817 sheet->fg_gc = gdk_gc_new (widget->window);
2818 sheet->bg_gc = gdk_gc_new (widget->window);
2820 colormap = gtk_widget_get_colormap (widget);
2822 gdk_color_white (colormap, &widget->style->white);
2823 gdk_color_black (colormap, &widget->style->black);
2825 gdk_gc_get_values (sheet->fg_gc, &auxvalues);
2827 values.foreground = widget->style->white;
2828 values.function = GDK_INVERT;
2829 values.subwindow_mode = GDK_INCLUDE_INFERIORS;
2831 gdk_gc_unref (sheet->xor_gc);
2832 sheet->xor_gc = gdk_gc_new_with_values (widget->window,
2838 if (sheet->sheet_entry->parent)
2840 gtk_widget_ref (sheet->sheet_entry);
2841 gtk_widget_unparent (sheet->sheet_entry);
2843 gtk_widget_set_parent_window (sheet->sheet_entry, sheet->sheet_window);
2844 gtk_widget_set_parent (sheet->sheet_entry, GTK_WIDGET (sheet));
2846 if (sheet->button && sheet->button->parent)
2848 gtk_widget_ref (sheet->button);
2849 gtk_widget_unparent (sheet->button);
2851 gtk_widget_set_parent_window (sheet->button, sheet->sheet_window);
2852 gtk_widget_set_parent (sheet->button, GTK_WIDGET (sheet));
2854 if (!sheet->cursor_drag)
2855 sheet->cursor_drag = gdk_cursor_new (GDK_PLUS);
2857 if (sheet->column_titles_visible)
2858 gdk_window_show (sheet->column_title_window);
2859 if (sheet->row_titles_visible)
2860 gdk_window_show (sheet->row_title_window);
2862 size_allocate_row_title_buttons (sheet);
2863 size_allocate_column_title_buttons (sheet);
2865 name = g_strdup (sheet->name);
2866 gtk_sheet_set_title (sheet, name);
2870 children = sheet->children;
2873 child = children->data;
2874 children = children->next;
2876 gtk_sheet_realize_child (sheet, child);
2881 create_global_button (GtkSheet *sheet)
2883 sheet->button = gtk_button_new_with_label (" ");
2885 g_signal_connect (G_OBJECT (sheet->button),
2887 G_CALLBACK (global_button_clicked),
2892 size_allocate_global_button (GtkSheet *sheet)
2894 GtkAllocation allocation;
2896 if (!sheet->column_titles_visible) return;
2897 if (!sheet->row_titles_visible) return;
2899 gtk_widget_size_request (sheet->button, NULL);
2903 allocation.width = sheet->row_title_area.width;
2904 allocation.height = sheet->column_title_area.height;
2906 gtk_widget_size_allocate (sheet->button, &allocation);
2907 gtk_widget_show (sheet->button);
2911 global_button_clicked (GtkWidget *widget, gpointer data)
2915 gtk_sheet_click_cell (GTK_SHEET (data), - 1, - 1, &veto);
2916 gtk_widget_grab_focus (GTK_WIDGET (data));
2921 gtk_sheet_unrealize (GtkWidget * widget)
2925 g_return_if_fail (widget != NULL);
2926 g_return_if_fail (GTK_IS_SHEET (widget));
2928 sheet = GTK_SHEET (widget);
2930 gdk_cursor_destroy (sheet->cursor_drag);
2932 gdk_gc_destroy (sheet->xor_gc);
2933 gdk_gc_destroy (sheet->fg_gc);
2934 gdk_gc_destroy (sheet->bg_gc);
2936 gdk_window_destroy (sheet->sheet_window);
2937 gdk_window_destroy (sheet->column_title_window);
2938 gdk_window_destroy (sheet->row_title_window);
2942 g_object_unref (sheet->pixmap);
2943 sheet->pixmap = NULL;
2946 sheet->column_title_window = NULL;
2947 sheet->sheet_window = NULL;
2948 sheet->cursor_drag = NULL;
2949 sheet->xor_gc = NULL;
2950 sheet->fg_gc = NULL;
2951 sheet->bg_gc = NULL;
2953 if (GTK_WIDGET_CLASS (parent_class)->unrealize)
2954 (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
2958 gtk_sheet_map (GtkWidget * widget)
2961 GtkSheetChild *child;
2964 g_return_if_fail (widget != NULL);
2965 g_return_if_fail (GTK_IS_SHEET (widget));
2967 sheet = GTK_SHEET (widget);
2969 if (!GTK_WIDGET_MAPPED (widget))
2971 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
2973 if (!sheet->cursor_drag) sheet->cursor_drag = gdk_cursor_new (GDK_PLUS);
2975 gdk_window_show (widget->window);
2977 gdk_window_show (sheet->sheet_window);
2979 if (sheet->column_titles_visible)
2981 size_allocate_column_title_buttons (sheet);
2982 gdk_window_show (sheet->column_title_window);
2984 if (sheet->row_titles_visible)
2986 size_allocate_row_title_buttons (sheet);
2987 gdk_window_show (sheet->row_title_window);
2990 if (!GTK_WIDGET_MAPPED (sheet->sheet_entry)
2991 && ! gtk_sheet_locked (sheet)
2992 && sheet->active_cell.row >= 0
2993 && sheet->active_cell.col >= 0 )
2995 gtk_widget_show (sheet->sheet_entry);
2996 gtk_widget_map (sheet->sheet_entry);
2999 if (GTK_WIDGET_VISIBLE (sheet->button) &&
3000 !GTK_WIDGET_MAPPED (sheet->button))
3002 gtk_widget_show (sheet->button);
3003 gtk_widget_map (sheet->button);
3006 if (GTK_BIN (sheet->button)->child)
3007 if (GTK_WIDGET_VISIBLE (GTK_BIN (sheet->button)->child) &&
3008 !GTK_WIDGET_MAPPED (GTK_BIN (sheet->button)->child))
3009 gtk_widget_map (GTK_BIN (sheet->button)->child);
3011 gtk_sheet_range_draw (sheet, NULL);
3012 gtk_sheet_activate_cell (sheet,
3013 sheet->active_cell.row,
3014 sheet->active_cell.col);
3016 children = sheet->children;
3019 child = children->data;
3020 children = children->next;
3022 if (GTK_WIDGET_VISIBLE (child->widget) &&
3023 !GTK_WIDGET_MAPPED (child->widget))
3025 gtk_widget_map (child->widget);
3026 gtk_sheet_position_child (sheet, child);
3034 gtk_sheet_unmap (GtkWidget * widget)
3037 GtkSheetChild *child;
3040 g_return_if_fail (widget != NULL);
3041 g_return_if_fail (GTK_IS_SHEET (widget));
3043 sheet = GTK_SHEET (widget);
3045 if (GTK_WIDGET_MAPPED (widget))
3047 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
3049 gdk_window_hide (sheet->sheet_window);
3050 if (sheet->column_titles_visible)
3051 gdk_window_hide (sheet->column_title_window);
3052 if (sheet->row_titles_visible)
3053 gdk_window_hide (sheet->row_title_window);
3054 gdk_window_hide (widget->window);
3056 if (GTK_WIDGET_MAPPED (sheet->sheet_entry))
3057 gtk_widget_unmap (sheet->sheet_entry);
3059 if (GTK_WIDGET_MAPPED (sheet->button))
3060 gtk_widget_unmap (sheet->button);
3062 children = sheet->children;
3065 child = children->data;
3066 children = children->next;
3068 if (GTK_WIDGET_VISIBLE (child->widget) &&
3069 GTK_WIDGET_MAPPED (child->widget))
3071 gtk_widget_unmap (child->widget);
3080 gtk_sheet_cell_draw_default (GtkSheet *sheet, gint row, gint col)
3083 GdkGC *fg_gc, *bg_gc;
3084 GtkSheetCellAttr attributes;
3087 g_return_if_fail (sheet != NULL);
3089 /* bail now if we arn't drawable yet */
3090 if (!GTK_WIDGET_DRAWABLE (sheet)) return;
3092 if (row < 0 || row >= yyy_row_count (sheet)) return;
3093 if (col < 0 || col >= xxx_column_count (sheet)) return;
3094 if (! xxx_column_is_visible (sheet, col)) return;
3095 if (! yyy_row_is_visible (sheet, row)) return;
3097 widget = GTK_WIDGET (sheet);
3099 gtk_sheet_get_attributes (sheet, row, col, &attributes);
3101 /* select GC for background rectangle */
3102 gdk_gc_set_foreground (sheet->fg_gc, &attributes.foreground);
3103 gdk_gc_set_foreground (sheet->bg_gc, &attributes.background);
3105 fg_gc = sheet->fg_gc;
3106 bg_gc = sheet->bg_gc;
3108 area.x = COLUMN_LEFT_XPIXEL (sheet,col);
3109 area.y = ROW_TOP_YPIXEL (sheet,row);
3110 area.width= xxx_column_width (sheet, col);
3111 area.height = yyy_row_height (sheet, row);
3113 gdk_draw_rectangle (sheet->pixmap,
3121 gdk_gc_set_line_attributes (sheet->fg_gc, 1, 0, 0, 0);
3123 if (sheet->show_grid)
3125 gdk_gc_set_foreground (sheet->bg_gc, &sheet->grid_color);
3127 gdk_draw_rectangle (sheet->pixmap,
3131 area.width, area.height);
3136 gtk_sheet_cell_draw_label (GtkSheet *sheet, gint row, gint col)
3139 GdkRectangle area, clip_area;
3141 gint text_width, text_height, y;
3143 gint size, sizel, sizer;
3144 GdkGC *fg_gc, *bg_gc;
3145 GtkSheetCellAttr attributes;
3146 PangoLayout *layout;
3147 PangoRectangle rect;
3148 PangoRectangle logical_rect;
3149 PangoLayoutLine *line;
3150 PangoFontMetrics *metrics;
3151 PangoContext *context = gtk_widget_get_pango_context (GTK_WIDGET (sheet));
3152 gint ascent, descent, y_pos;
3156 g_return_if_fail (sheet != NULL);
3158 /* bail now if we aren't drawable yet */
3159 if (!GTK_WIDGET_DRAWABLE (sheet))
3162 label = gtk_sheet_cell_get_text (sheet, row, col);
3166 if (row < 0 || row >= yyy_row_count (sheet)) return;
3167 if (col < 0 || col >= xxx_column_count (sheet)) return;
3168 if (! xxx_column_is_visible (sheet, col)) return;
3169 if (!yyy_row_is_visible (sheet, row)) return;
3172 widget = GTK_WIDGET (sheet);
3174 gtk_sheet_get_attributes (sheet, row, col, &attributes);
3176 /* select GC for background rectangle */
3177 gdk_gc_set_foreground (sheet->fg_gc, &attributes.foreground);
3178 gdk_gc_set_foreground (sheet->bg_gc, &attributes.background);
3180 fg_gc = sheet->fg_gc;
3181 bg_gc = sheet->bg_gc;
3183 area.x = COLUMN_LEFT_XPIXEL (sheet,col);
3184 area.y = ROW_TOP_YPIXEL (sheet,row);
3185 area.width = xxx_column_width (sheet, col);
3186 area.height = yyy_row_height (sheet, row);
3190 layout = gtk_widget_create_pango_layout (GTK_WIDGET (sheet), label);
3191 dispose_string (sheet, label);
3192 pango_layout_set_font_description (layout, attributes.font_desc);
3194 pango_layout_get_pixel_extents (layout, NULL, &rect);
3196 line = pango_layout_get_lines (layout)->data;
3197 pango_layout_line_get_extents (line, NULL, &logical_rect);
3199 metrics = pango_context_get_metrics (context,
3200 attributes.font_desc,
3201 pango_context_get_language (context));
3203 ascent = pango_font_metrics_get_ascent (metrics) / PANGO_SCALE;
3204 descent = pango_font_metrics_get_descent (metrics) / PANGO_SCALE;
3206 pango_font_metrics_unref (metrics);
3208 /* Align primarily for locale's ascent / descent */
3210 logical_rect.height /= PANGO_SCALE;
3211 logical_rect.y /= PANGO_SCALE;
3212 y_pos = area.height - logical_rect.height;
3214 if (logical_rect.height > area.height)
3215 y_pos = (logical_rect.height - area.height - 2 * CELLOFFSET) / 2;
3218 else if (y_pos + logical_rect.height > area.height)
3219 y_pos = area.height - logical_rect.height;
3221 text_width = rect.width;
3222 text_height = rect.height;
3223 y = area.y + y_pos - CELLOFFSET;
3225 switch (attributes.justification)
3227 case GTK_JUSTIFY_RIGHT:
3229 area.x +=area.width;
3230 if (!gtk_sheet_clip_text (sheet))
3232 for (i = col - 1; i >= MIN_VISIBLE_COLUMN (sheet); i--)
3234 if ( !gtk_sheet_cell_empty (sheet, row, i)) break;
3235 if (size >= text_width + CELLOFFSET) break;
3236 size +=xxx_column_width (sheet, i);
3237 xxx_column_set_right_column (sheet, i,
3239 xxx_column_right_column (sheet, i)));
3244 xoffset += area.width - text_width - 2 * CELLOFFSET -
3245 attributes.border.width / 2;
3247 case GTK_JUSTIFY_CENTER:
3248 sizel = area.width / 2;
3249 sizer = area.width / 2;
3250 area.x += area.width / 2;
3251 if (!gtk_sheet_clip_text (sheet))
3253 for (i = col + 1; i <= MAX_VISIBLE_COLUMN (sheet); i++)
3255 if ( ! gtk_sheet_cell_empty (sheet, row, i)) break;
3256 if (sizer >= text_width / 2) break;
3257 sizer += xxx_column_width (sheet, i);
3258 xxx_column_set_left_column (sheet, i,
3261 xxx_column_left_column (sheet, i)));
3263 for (i = col - 1; i >= MIN_VISIBLE_COLUMN (sheet); i--)
3265 if ( ! gtk_sheet_cell_empty (sheet, row, i)) break;
3266 if (sizel >= text_width / 2) break;
3267 sizel +=xxx_column_width (sheet, i);
3268 xxx_column_set_right_column (sheet, i,
3270 xxx_column_right_column (sheet, i)));
3272 size = MIN (sizel, sizer);
3275 xoffset += sizel - text_width / 2 - CELLOFFSET;
3276 area.width = sizel + sizer;
3278 case GTK_JUSTIFY_LEFT:
3281 if (!gtk_sheet_clip_text (sheet))
3283 for (i = col + 1; i <= MAX_VISIBLE_COLUMN (sheet); i++)
3285 if (! gtk_sheet_cell_empty (sheet, row, i)) break;
3286 if (size >= text_width + CELLOFFSET) break;
3287 size +=xxx_column_width (sheet, i);
3288 xxx_column_set_left_column (sheet, i,
3291 xxx_column_left_column (sheet, i)));
3296 xoffset += attributes.border.width / 2;
3300 if (!gtk_sheet_clip_text (sheet)) clip_area = area;
3301 gdk_gc_set_clip_rectangle (fg_gc, &clip_area);
3304 gdk_draw_layout (sheet->pixmap, fg_gc,
3305 area.x + xoffset + CELLOFFSET,
3309 gdk_gc_set_clip_rectangle (fg_gc, NULL);
3310 g_object_unref (G_OBJECT (layout));
3312 gdk_draw_pixmap (sheet->sheet_window,
3313 GTK_WIDGET (sheet)->style->fg_gc[GTK_STATE_NORMAL],
3325 gtk_sheet_range_draw (GtkSheet *sheet, const GtkSheetRange *range)
3328 GtkSheetRange drawing_range;
3331 g_return_if_fail (sheet != NULL);
3332 g_return_if_fail (GTK_SHEET (sheet));
3334 if (!GTK_WIDGET_DRAWABLE (GTK_WIDGET (sheet))) return;
3335 if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) return;
3336 if (!GTK_WIDGET_MAPPED (GTK_WIDGET (sheet))) return;
3340 drawing_range.row0 = MIN_VISIBLE_ROW (sheet);
3341 drawing_range.col0 = MIN_VISIBLE_COLUMN (sheet);
3342 drawing_range.rowi = MIN (MAX_VISIBLE_ROW (sheet),
3343 yyy_row_count (sheet) - 1);
3344 drawing_range.coli = MAX_VISIBLE_COLUMN (sheet);
3347 gdk_draw_rectangle (sheet->pixmap,
3348 GTK_WIDGET (sheet)->style->white_gc,
3351 sheet->sheet_window_width,
3352 sheet->sheet_window_height);
3356 drawing_range.row0 = MAX (range->row0, MIN_VISIBLE_ROW (sheet));
3357 drawing_range.col0 = MAX (range->col0, MIN_VISIBLE_COLUMN (sheet));
3358 drawing_range.rowi = MIN (range->rowi, MAX_VISIBLE_ROW (sheet));
3359 drawing_range.coli = MIN (range->coli, MAX_VISIBLE_COLUMN (sheet));
3362 if (drawing_range.coli == xxx_column_count (sheet) - 1)
3364 area.x = COLUMN_LEFT_XPIXEL (sheet,
3365 xxx_column_count (sheet) - 1) +
3366 xxx_column_width (sheet, xxx_column_count (sheet) - 1) + 1;
3370 gdk_gc_set_foreground (sheet->fg_gc, &sheet->bg_color);
3372 gdk_draw_rectangle (sheet->pixmap,
3376 sheet->sheet_window_width - area.x,
3377 sheet->sheet_window_height);
3379 gdk_draw_pixmap (sheet->sheet_window,
3380 GTK_WIDGET (sheet)->style->fg_gc[GTK_STATE_NORMAL],
3386 sheet->sheet_window_width - area.x,
3387 sheet->sheet_window_height);
3390 if (drawing_range.rowi == yyy_row_count (sheet) - 1)
3393 area.y = ROW_TOP_YPIXEL (sheet,
3394 yyy_row_count (sheet) - 1) +
3395 yyy_row_height (sheet, yyy_row_count (sheet) - 1) + 1;
3397 gdk_gc_set_foreground (sheet->fg_gc, &sheet->bg_color);
3399 gdk_draw_rectangle (sheet->pixmap,
3403 sheet->sheet_window_width,
3404 sheet->sheet_window_height - area.y);
3406 gdk_draw_pixmap (sheet->sheet_window,
3407 GTK_WIDGET (sheet)->style->fg_gc[GTK_STATE_NORMAL],
3413 sheet->sheet_window_width,
3414 sheet->sheet_window_height - area.y);
3417 for (i = drawing_range.row0; i <= drawing_range.rowi; i++)
3418 for (j = drawing_range.col0; j <= drawing_range.coli; j++)
3420 gtk_sheet_cell_draw_default (sheet, i, j);
3421 gtk_sheet_cell_draw_label (sheet, i, j);
3424 gtk_sheet_draw_backing_pixmap (sheet, drawing_range);
3426 if (sheet->state != GTK_SHEET_NORMAL &&
3427 gtk_sheet_range_isvisible (sheet, sheet->range))
3428 gtk_sheet_range_draw_selection (sheet, drawing_range);
3430 if (sheet->state == GTK_STATE_NORMAL &&
3431 sheet->active_cell.row >= drawing_range.row0 &&
3432 sheet->active_cell.row <= drawing_range.rowi &&
3433 sheet->active_cell.col >= drawing_range.col0 &&
3434 sheet->active_cell.col <= drawing_range.coli)
3435 gtk_sheet_show_active_cell (sheet);
3439 gtk_sheet_range_draw_selection (GtkSheet *sheet, GtkSheetRange range)
3445 if (range.col0 > sheet->range.coli || range.coli < sheet->range.col0 ||
3446 range.row0 > sheet->range.rowi || range.rowi < sheet->range.row0)
3449 if (!gtk_sheet_range_isvisible (sheet, range)) return;
3450 if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) return;
3454 range.col0 = MAX (sheet->range.col0, range.col0);
3455 range.coli = MIN (sheet->range.coli, range.coli);
3456 range.row0 = MAX (sheet->range.row0, range.row0);
3457 range.rowi = MIN (sheet->range.rowi, range.rowi);
3459 range.col0 = MAX (range.col0, MIN_VISIBLE_COLUMN (sheet));
3460 range.coli = MIN (range.coli, MAX_VISIBLE_COLUMN (sheet));
3461 range.row0 = MAX (range.row0, MIN_VISIBLE_ROW (sheet));
3462 range.rowi = MIN (range.rowi, MAX_VISIBLE_ROW (sheet));
3464 for (i = range.row0; i <= range.rowi; i++)
3466 for (j = range.col0; j <= range.coli; j++)
3469 if (gtk_sheet_cell_get_state (sheet, i, j) == GTK_STATE_SELECTED &&
3470 xxx_column_is_visible (sheet, j) && yyy_row_is_visible (sheet, i))
3473 area.x = COLUMN_LEFT_XPIXEL (sheet,j);
3474 area.y = ROW_TOP_YPIXEL (sheet,i);
3475 area.width= xxx_column_width (sheet, j);
3476 area.height = yyy_row_height (sheet, i);
3478 if (i == sheet->range.row0)
3480 area.y = area.y + 2;
3481 area.height = area.height - 2;
3483 if (i == sheet->range.rowi) area.height = area.height - 3;
3484 if (j == sheet->range.col0)
3486 area.x = area.x + 2;
3487 area.width = area.width - 2;
3489 if (j == sheet->range.coli) area.width = area.width - 3;
3491 if (i != sheet->active_cell.row || j != sheet->active_cell.col)
3493 gdk_draw_rectangle (sheet->sheet_window,
3496 area.x + 1,area.y + 1,
3497 area.width,area.height);
3504 gtk_sheet_draw_border (sheet, sheet->range);
3508 gtk_sheet_draw_backing_pixmap (GtkSheet *sheet, GtkSheetRange range)
3510 gint x,y,width,height;
3512 if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) return;
3514 x = COLUMN_LEFT_XPIXEL (sheet,range.col0);
3515 y = ROW_TOP_YPIXEL (sheet, range.row0);
3516 width = COLUMN_LEFT_XPIXEL (sheet, range.coli) - x +
3517 xxx_column_width (sheet, range.coli);
3519 height = ROW_TOP_YPIXEL (sheet, range.rowi)- y + yyy_row_height (sheet, range.rowi);
3521 if (range.row0 == sheet->range.row0)
3524 height = height + 5;
3526 if (range.rowi == sheet->range.rowi) height = height + 5;
3527 if (range.col0 == sheet->range.col0)
3532 if (range.coli == sheet->range.coli) width = width + 5;
3534 width = MIN (width, sheet->sheet_window_width - x);
3535 height = MIN (height, sheet->sheet_window_height - y);
3542 x = (sheet->row_titles_visible)
3543 ? MAX (x, sheet->row_title_area.width) : MAX (x, 0);
3544 y = (sheet->column_titles_visible)
3545 ? MAX (y, sheet->column_title_area.height) : MAX (y, 0);
3547 if (range.coli == xxx_column_count (sheet) - 1)
3548 width = sheet->sheet_window_width - x;
3549 if (range.rowi == yyy_row_count (sheet) - 1)
3550 height = sheet->sheet_window_height - y;
3552 gdk_draw_pixmap (sheet->sheet_window,
3553 GTK_WIDGET (sheet)->style->fg_gc[GTK_STATE_NORMAL],
3565 gtk_sheet_set_cell_text (GtkSheet *sheet, gint row, gint col, const gchar *text)
3567 GtkSheetCellAttr attributes;
3569 g_return_if_fail (sheet != NULL);
3570 g_return_if_fail (GTK_IS_SHEET (sheet));
3571 if (col >= xxx_column_count (sheet) || row >= yyy_row_count (sheet)) return;
3572 if (col < 0 || row < 0) return;
3574 gtk_sheet_get_attributes (sheet, row, col, &attributes);
3575 gtk_sheet_set_cell (sheet, row, col, attributes.justification, text);
3579 safe_strcmp (const gchar *s1, const gchar *s2)
3581 if ( !s1 && !s2) return 0;
3582 if ( !s1) return - 1;
3583 if ( !s2) return +1;
3584 return strcmp (s1, s2);
3588 gtk_sheet_set_cell (GtkSheet *sheet, gint row, gint col,
3589 GtkJustification justification,
3592 GSheetModel *model ;
3596 GtkSheetRange range;
3598 GtkSheetCellAttr attributes;
3600 g_return_if_fail (sheet != NULL);
3601 g_return_if_fail (GTK_IS_SHEET (sheet));
3602 if (col >= xxx_column_count (sheet) || row >= yyy_row_count (sheet)) return;
3603 if (col < 0 || row < 0) return;
3605 gtk_sheet_get_attributes (sheet, row, col, &attributes);
3607 attributes.justification = justification;
3609 model = gtk_sheet_get_model (sheet);
3611 old_text = g_sheet_model_get_string (model, row, col);
3615 if (0 != safe_strcmp (old_text, text))
3616 changed = g_sheet_model_set_string (model, text, row, col);
3618 if ( g_sheet_model_free_strings (model))
3622 if (changed && attributes.is_visible)
3624 gchar *s = gtk_sheet_cell_get_text (sheet, row, col);
3626 if (s && strlen (s) > 0)
3628 text_width = STRING_WIDTH (GTK_WIDGET (sheet),
3629 attributes.font_desc, text);
3631 dispose_string (sheet, s);
3635 range.col0 = MIN_VISIBLE_COLUMN (sheet);
3636 range.coli = MAX_VISIBLE_COLUMN (sheet);
3638 if (gtk_sheet_autoresize (sheet) &&
3639 text_width > xxx_column_width (sheet, col) -
3640 2 * CELLOFFSET- attributes.border.width)
3642 gtk_sheet_set_column_width (sheet, col, text_width + 2 * CELLOFFSET
3643 + attributes.border.width);
3644 GTK_SHEET_SET_FLAGS (sheet, GTK_SHEET_REDRAW_PENDING);
3647 if (!GTK_SHEET_IS_FROZEN (sheet))
3648 gtk_sheet_range_draw (sheet, &range);
3652 g_signal_emit (G_OBJECT (sheet), sheet_signals[CHANGED], 0, row, col);
3658 gtk_sheet_cell_clear (GtkSheet *sheet, gint row, gint column)
3660 GtkSheetRange range;
3662 g_return_if_fail (sheet != NULL);
3663 g_return_if_fail (GTK_IS_SHEET (sheet));
3664 if (column >= xxx_column_count (sheet) ||
3665 row >= yyy_row_count (sheet)) return;
3667 if (column < 0 || row < 0) return;
3671 range.col0 = MIN_VISIBLE_COLUMN (sheet);
3672 range.coli = MAX_VISIBLE_COLUMN (sheet);
3674 gtk_sheet_real_cell_clear (sheet, row, column, FALSE);
3676 if (!GTK_SHEET_IS_FROZEN (sheet))
3678 gtk_sheet_range_draw (sheet, &range);
3683 gtk_sheet_cell_delete (GtkSheet *sheet, gint row, gint column)
3685 GtkSheetRange range;
3687 g_return_if_fail (sheet != NULL);
3688 g_return_if_fail (GTK_IS_SHEET (sheet));
3689 if (column >= xxx_column_count (sheet) || row >= yyy_row_count (sheet)) return;
3690 if (column < 0 || row < 0) return;
3694 range.col0 = MIN_VISIBLE_COLUMN (sheet);
3695 range.coli = MAX_VISIBLE_COLUMN (sheet);
3697 gtk_sheet_real_cell_clear (sheet, row, column, TRUE);
3699 if (!GTK_SHEET_IS_FROZEN (sheet))
3701 gtk_sheet_range_draw (sheet, &range);
3706 gtk_sheet_real_cell_clear (GtkSheet *sheet, gint row, gint column, gboolean delete)
3708 GSheetModel *model = gtk_sheet_get_model (sheet);
3710 gchar *old_text = gtk_sheet_cell_get_text (sheet, row, column);
3712 if (old_text && strlen (old_text) > 0 )
3714 g_sheet_model_datum_clear (model, row, column);
3716 if (GTK_IS_OBJECT (sheet) && G_OBJECT (sheet)->ref_count > 0)
3717 g_signal_emit (G_OBJECT (sheet), sheet_signals[CLEAR_CELL], 0,
3721 dispose_string (sheet, old_text);
3725 gtk_sheet_range_clear (GtkSheet *sheet, const GtkSheetRange *range)
3727 g_return_if_fail (sheet != NULL);
3728 g_return_if_fail (GTK_IS_SHEET (sheet));
3730 gtk_sheet_real_range_clear (sheet, range, FALSE);
3734 gtk_sheet_range_delete (GtkSheet *sheet, const GtkSheetRange *range)
3736 g_return_if_fail (sheet != NULL);
3737 g_return_if_fail (GTK_IS_SHEET (sheet));
3739 gtk_sheet_real_range_clear (sheet, range, TRUE);
3744 gtk_sheet_real_range_clear (GtkSheet *sheet, const GtkSheetRange *range,
3748 GtkSheetRange clear;
3753 clear.rowi = yyy_row_count (sheet) - 1;
3755 clear.coli = xxx_column_count (sheet) - 1;
3760 clear.row0 = MAX (clear.row0, 0);
3761 clear.col0 = MAX (clear.col0, 0);
3762 clear.rowi = MIN (clear.rowi, yyy_row_count (sheet) - 1 );
3763 clear.coli = MIN (clear.coli, xxx_column_count (sheet) - 1 );
3765 for (i = clear.row0; i <= clear.rowi; i++)
3766 for (j = clear.col0; j <= clear.coli; j++)
3768 gtk_sheet_real_cell_clear (sheet, i, j, delete);
3771 gtk_sheet_range_draw (sheet, NULL);
3776 gtk_sheet_cell_empty (const GtkSheet *sheet, gint row, gint col)
3779 char *text = gtk_sheet_cell_get_text (sheet, row, col);
3780 empty = (text == NULL );
3782 dispose_string (sheet, text);
3789 gtk_sheet_cell_get_text (const GtkSheet *sheet, gint row, gint col)
3792 g_return_val_if_fail (sheet != NULL, NULL);
3793 g_return_val_if_fail (GTK_IS_SHEET (sheet), NULL);
3795 if (col >= xxx_column_count (sheet) || row >= yyy_row_count (sheet))
3797 if (col < 0 || row < 0) return NULL;
3799 model = gtk_sheet_get_model (sheet);
3804 return g_sheet_model_get_string (model, row, col);
3809 gtk_sheet_cell_get_state (GtkSheet *sheet, gint row, gint col)
3812 GtkSheetRange *range;
3814 g_return_val_if_fail (sheet != NULL, 0);
3815 g_return_val_if_fail (GTK_IS_SHEET (sheet), 0);
3816 if (col >= xxx_column_count (sheet) || row >= yyy_row_count (sheet)) return 0;
3817 if (col < 0 || row < 0) return 0;
3819 state = sheet->state;
3820 range = &sheet->range;
3824 case GTK_SHEET_NORMAL:
3825 return GTK_STATE_NORMAL;
3827 case GTK_SHEET_ROW_SELECTED:
3828 if (row >= range->row0 && row <= range->rowi)
3829 return GTK_STATE_SELECTED;
3831 case GTK_SHEET_COLUMN_SELECTED:
3832 if (col >= range->col0 && col <= range->coli)
3833 return GTK_STATE_SELECTED;
3835 case GTK_SHEET_RANGE_SELECTED:
3836 if (row >= range->row0 && row <= range->rowi && \
3837 col >= range->col0 && col <= range->coli)
3838 return GTK_STATE_SELECTED;
3841 return GTK_STATE_NORMAL;
3844 /* Convert X, Y (in pixels) to *ROW, *COLUMN (in cell coords)
3845 -1 indicates the title buttons.
3846 If the function returns FALSE, then the results will be unreliable.
3849 gtk_sheet_get_pixel_info (GtkSheet *sheet,
3857 *column = -G_MAXINT;
3859 g_return_val_if_fail (sheet != NULL, 0);
3860 g_return_val_if_fail (GTK_IS_SHEET (sheet), 0);
3862 /* bounds checking, return false if the user clicked
3870 if ( y < sheet->column_title_area.height + sheet->column_title_area.y)
3875 trow = ROW_FROM_YPIXEL (sheet, y);
3876 if (trow > yyy_row_count (sheet))
3882 if ( x < sheet->row_title_area.width + sheet->row_title_area.x)
3886 tcol = COLUMN_FROM_XPIXEL (sheet, x);
3887 if (tcol > xxx_column_count (sheet))
3897 gtk_sheet_get_cell_area (GtkSheet * sheet,
3902 g_return_val_if_fail (sheet != NULL, 0);
3903 g_return_val_if_fail (GTK_IS_SHEET (sheet), 0);
3905 if (row >= yyy_row_count (sheet) || column >= xxx_column_count (sheet))
3908 area->x = (column == -1) ? 0 : (COLUMN_LEFT_XPIXEL (sheet, column) -
3909 (sheet->row_titles_visible
3910 ? sheet->row_title_area.width
3912 area->y = (row == -1) ? 0 : (ROW_TOP_YPIXEL (sheet, row) -
3913 (sheet->column_titles_visible
3914 ? sheet->column_title_area.height
3916 area->width= (column == -1) ? sheet->row_title_area.width
3917 : xxx_column_width (sheet, column);
3919 area->height= (row == -1) ? sheet->column_title_area.height
3920 : yyy_row_height (sheet, row);
3926 gtk_sheet_set_active_cell (GtkSheet *sheet, gint row, gint column)
3928 g_return_val_if_fail (sheet != NULL, 0);
3929 g_return_val_if_fail (GTK_IS_SHEET (sheet), 0);
3931 if (row < - 1 || column < - 1) return FALSE;
3932 if (row >= yyy_row_count (sheet) || column >= xxx_column_count (sheet))
3935 if (GTK_WIDGET_REALIZED (GTK_WIDGET (sheet)))
3937 if (!gtk_sheet_deactivate_cell (sheet)) return FALSE;
3940 sheet->active_cell.row = row;
3941 sheet->active_cell.col = column;
3943 if ( row == -1 || column == -1)
3945 gtk_sheet_hide_active_cell (sheet);
3949 if (!gtk_sheet_activate_cell (sheet, row, column)) return FALSE;
3951 if (gtk_sheet_autoscroll (sheet))
3952 gtk_sheet_move_query (sheet, row, column);
3958 gtk_sheet_get_active_cell (GtkSheet *sheet, gint *row, gint *column)
3960 g_return_if_fail (sheet != NULL);
3961 g_return_if_fail (GTK_IS_SHEET (sheet));
3963 if ( row ) *row = sheet->active_cell.row;
3964 if (column) *column = sheet->active_cell.col;
3968 gtk_sheet_entry_changed (GtkWidget *widget, gpointer data)
3973 GtkJustification justification;
3974 GtkSheetCellAttr attributes;
3976 g_return_if_fail (data != NULL);
3977 g_return_if_fail (GTK_IS_SHEET (data));
3979 sheet = GTK_SHEET (data);
3981 if (!GTK_WIDGET_VISIBLE (widget)) return;
3982 if (sheet->state != GTK_STATE_NORMAL) return;
3984 row = sheet->active_cell.row;
3985 col = sheet->active_cell.col;
3987 if (row < 0 || col < 0) return;
3989 sheet->active_cell.row =- 1;
3990 sheet->active_cell.col =- 1;
3992 text = gtk_entry_get_text (GTK_ENTRY (gtk_sheet_get_entry (sheet)));
3994 GTK_SHEET_SET_FLAGS (sheet, GTK_SHEET_IS_FROZEN);
3996 if (text && strlen (text) > 0)
3998 gtk_sheet_get_attributes (sheet, row, col, &attributes);
3999 justification = attributes.justification;
4000 gtk_sheet_set_cell (sheet, row, col, justification, text);
4003 if (sheet->freeze_count == 0)
4004 GTK_SHEET_UNSET_FLAGS (sheet, GTK_SHEET_IS_FROZEN);
4006 sheet->active_cell.row = row;;
4007 sheet->active_cell.col = col;
4012 gtk_sheet_deactivate_cell (GtkSheet *sheet)
4014 gboolean veto = TRUE;
4016 g_return_val_if_fail (sheet != NULL, FALSE);
4017 g_return_val_if_fail (GTK_IS_SHEET (sheet), FALSE);
4019 if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) return FALSE;
4020 if (sheet->state != GTK_SHEET_NORMAL) return FALSE;
4022 _gtkextra_signal_emit (GTK_OBJECT (sheet),sheet_signals[DEACTIVATE],
4023 sheet->active_cell.row,
4024 sheet->active_cell.col, &veto);
4026 if (!veto) return FALSE;
4028 if ( sheet->active_cell.row == -1 || sheet->active_cell.col == -1 )
4031 g_signal_handlers_disconnect_by_func (G_OBJECT (gtk_sheet_get_entry (sheet)),
4032 G_CALLBACK (gtk_sheet_entry_changed),
4035 gtk_sheet_hide_active_cell (sheet);
4036 sheet->active_cell.row = -1;
4037 sheet->active_cell.col = -1;
4039 if (GTK_SHEET_REDRAW_PENDING (sheet))
4041 GTK_SHEET_UNSET_FLAGS (sheet, GTK_SHEET_REDRAW_PENDING);
4042 gtk_sheet_range_draw (sheet, NULL);
4049 gtk_sheet_hide_active_cell (GtkSheet *sheet)
4053 GtkJustification justification;
4054 GtkSheetCellAttr attributes;
4056 if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) return;
4058 row = sheet->active_cell.row;
4059 col = sheet->active_cell.col;
4061 if (row < 0 || col < 0) return;
4063 if (sheet->freeze_count == 0)
4064 GTK_SHEET_UNSET_FLAGS (sheet, GTK_SHEET_IS_FROZEN);
4066 text = gtk_entry_get_text (GTK_ENTRY (gtk_sheet_get_entry (sheet)));
4068 gtk_sheet_get_attributes (sheet, row, col, &attributes);
4069 justification = attributes.justification;
4071 if (text && strlen (text) != 0)
4073 gtk_sheet_set_cell (sheet, row, col, justification, text);
4074 g_signal_emit (G_OBJECT (sheet),sheet_signals[SET_CELL], 0, row, col);
4078 gtk_sheet_cell_clear (sheet, row, col);
4081 row = sheet->active_cell.row;
4082 col = sheet->active_cell.col;
4084 gtk_widget_hide (sheet->sheet_entry);
4085 gtk_widget_unmap (sheet->sheet_entry);
4087 if (row != -1 && col != -1)
4088 gdk_draw_pixmap (sheet->sheet_window,
4089 GTK_WIDGET (sheet)->style->fg_gc[GTK_STATE_NORMAL],
4091 COLUMN_LEFT_XPIXEL (sheet,col)- 1,
4092 ROW_TOP_YPIXEL (sheet,row)- 1,
4093 COLUMN_LEFT_XPIXEL (sheet,col)- 1,
4094 ROW_TOP_YPIXEL (sheet,row)- 1,
4095 xxx_column_width (sheet, col) + 4,
4096 yyy_row_height (sheet, row)+4);
4098 gtk_widget_grab_focus (GTK_WIDGET (sheet));
4100 GTK_WIDGET_UNSET_FLAGS (GTK_WIDGET (sheet->sheet_entry), GTK_VISIBLE);
4105 gtk_sheet_activate_cell (GtkSheet *sheet, gint row, gint col)
4107 gboolean veto = TRUE;
4109 g_return_val_if_fail (sheet != NULL, FALSE);
4110 g_return_val_if_fail (GTK_IS_SHEET (sheet), FALSE);
4112 if (row < 0 || col < 0) return FALSE;
4113 if (row >= yyy_row_count (sheet) || col >= xxx_column_count (sheet))
4116 /* _gtkextra_signal_emit (GTK_OBJECT (sheet),sheet_signals[ACTIVATE], row, col, &veto);
4117 if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) return veto;
4120 if (!veto) return FALSE;
4121 if (sheet->state != GTK_SHEET_NORMAL)
4123 sheet->state = GTK_SHEET_NORMAL;
4124 gtk_sheet_real_unselect_range (sheet, NULL);
4127 sheet->range.row0 = row;
4128 sheet->range.col0 = col;
4129 sheet->range.rowi = row;
4130 sheet->range.coli = col;
4131 sheet->active_cell.row = row;
4132 sheet->active_cell.col = col;
4133 sheet->selection_cell.row = row;
4134 sheet->selection_cell.col = col;
4136 GTK_SHEET_UNSET_FLAGS (sheet, GTK_SHEET_IN_SELECTION);
4138 gtk_sheet_show_active_cell (sheet);
4141 g_signal_connect (G_OBJECT (gtk_sheet_get_entry (sheet)),
4143 G_CALLBACK (gtk_sheet_entry_changed),
4146 _gtkextra_signal_emit (GTK_OBJECT (sheet),sheet_signals[ACTIVATE], row, col, &veto);
4152 gtk_sheet_show_active_cell (GtkSheet *sheet)
4154 GtkEntry *sheet_entry;
4155 GtkSheetCellAttr attributes;
4157 const gchar *old_text;
4158 GtkJustification justification;
4161 g_return_if_fail (sheet != NULL);
4162 g_return_if_fail (GTK_IS_SHEET (sheet));
4164 row = sheet->active_cell.row;
4165 col = sheet->active_cell.col;
4167 /* Don't show the active cell, if there is no active cell: */
4168 if (! (row >= 0 && col >= 0)) /* e.g row or coll == -1. */
4171 if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) return;
4172 if (sheet->state != GTK_SHEET_NORMAL) return;
4173 if (GTK_SHEET_IN_SELECTION (sheet)) return;
4175 GTK_WIDGET_SET_FLAGS (GTK_WIDGET (sheet->sheet_entry), GTK_VISIBLE);
4177 sheet_entry = GTK_ENTRY (gtk_sheet_get_entry (sheet));
4179 gtk_sheet_get_attributes (sheet, row, col, &attributes);
4181 justification = GTK_JUSTIFY_LEFT;
4183 if (gtk_sheet_justify_entry (sheet))
4184 justification = attributes.justification;
4186 text = gtk_sheet_cell_get_text (sheet, row, col);
4188 text = g_strdup ("");
4190 gtk_entry_set_visibility (GTK_ENTRY (sheet_entry), attributes.is_visible);
4192 if (gtk_sheet_locked (sheet) || !attributes.is_editable)
4193 gtk_editable_set_editable (GTK_EDITABLE (sheet_entry), FALSE);
4195 gtk_editable_set_editable (GTK_EDITABLE (sheet_entry), TRUE);
4197 /*** Added by John Gotts. Mar 25, 2005 *********/
4198 old_text = gtk_entry_get_text (GTK_ENTRY (sheet_entry));
4199 if (strcmp (old_text, text) != 0)
4201 if (!GTK_IS_ITEM_ENTRY (sheet_entry))
4202 gtk_entry_set_text (GTK_ENTRY (sheet_entry), text);
4204 gtk_item_entry_set_text (GTK_ITEM_ENTRY (sheet_entry), text, justification);
4207 gtk_sheet_entry_set_max_size (sheet);
4208 gtk_sheet_size_allocate_entry (sheet);
4210 gtk_widget_map (sheet->sheet_entry);
4212 gtk_widget_grab_focus (GTK_WIDGET (sheet_entry));
4214 dispose_string (sheet, text);
4218 gtk_sheet_draw_active_cell (GtkSheet *sheet)
4222 if (!GTK_WIDGET_DRAWABLE (GTK_WIDGET (sheet))) return;
4223 if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) return;
4225 row = sheet->active_cell.row;
4226 col = sheet->active_cell.col;
4228 if (row < 0 || col < 0) return;
4230 if (!gtk_sheet_cell_isvisible (sheet, row, col)) return;
4232 gtk_sheet_draw_border (sheet, sheet->range);
4237 gtk_sheet_make_backing_pixmap (GtkSheet *sheet, guint width, guint height)
4239 gint pixmap_width, pixmap_height;
4241 if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) return;
4243 if (width == 0 && height == 0)
4245 width = sheet->sheet_window_width + 80;
4246 height = sheet->sheet_window_height + 80;
4252 sheet->pixmap = gdk_pixmap_new (sheet->sheet_window,
4255 if (!GTK_SHEET_IS_FROZEN (sheet)) gtk_sheet_range_draw (sheet, NULL);
4259 /* reallocate if sizes don't match */
4260 gdk_window_get_size (sheet->pixmap,
4261 &pixmap_width, &pixmap_height);
4262 if ( (pixmap_width != width) || (pixmap_height != height))
4264 g_object_unref (sheet->pixmap);
4265 sheet->pixmap = gdk_pixmap_new (sheet->sheet_window,
4268 if (!GTK_SHEET_IS_FROZEN (sheet)) gtk_sheet_range_draw (sheet, NULL);
4274 gtk_sheet_new_selection (GtkSheet *sheet, GtkSheetRange *range)
4276 gint i,j, mask1, mask2;
4277 gint state, selected;
4278 gint x,y,width,height;
4279 GtkSheetRange new_range, aux_range;
4281 g_return_if_fail (sheet != NULL);
4283 if (range == NULL) range=&sheet->range;
4287 range->row0 = MIN (range->row0, sheet->range.row0);
4288 range->rowi = MAX (range->rowi, sheet->range.rowi);
4289 range->col0 = MIN (range->col0, sheet->range.col0);
4290 range->coli = MAX (range->coli, sheet->range.coli);
4292 range->row0 = MAX (range->row0, MIN_VISIBLE_ROW (sheet));
4293 range->rowi = MIN (range->rowi, MAX_VISIBLE_ROW (sheet));
4294 range->col0 = MAX (range->col0, MIN_VISIBLE_COLUMN (sheet));
4295 range->coli = MIN (range->coli, MAX_VISIBLE_COLUMN (sheet));
4297 aux_range.row0 = MAX (new_range.row0, MIN_VISIBLE_ROW (sheet));
4298 aux_range.rowi = MIN (new_range.rowi, MAX_VISIBLE_ROW (sheet));
4299 aux_range.col0 = MAX (new_range.col0, MIN_VISIBLE_COLUMN (sheet));
4300 aux_range.coli = MIN (new_range.coli, MAX_VISIBLE_COLUMN (sheet));
4302 for (i = range->row0; i <= range->rowi; i++)
4304 for (j = range->col0; j <= range->coli; j++)
4307 state = gtk_sheet_cell_get_state (sheet, i, j);
4308 selected= (i <= new_range.rowi && i >= new_range.row0 &&
4309 j <= new_range.coli && j >= new_range.col0) ? TRUE : FALSE;
4311 if (state == GTK_STATE_SELECTED && selected &&
4312 xxx_column_is_visible (sheet, j) && yyy_row_is_visible (sheet, i) &&
4313 (i == sheet->range.row0 || i == sheet->range.rowi ||
4314 j == sheet->range.col0 || j == sheet->range.coli ||
4315 i == new_range.row0 || i == new_range.rowi ||
4316 j == new_range.col0 || j == new_range.coli))
4319 mask1 = i == sheet->range.row0 ? 1 : 0;
4320 mask1 = i == sheet->range.rowi ? mask1 + 2 : mask1;
4321 mask1 = j == sheet->range.col0 ? mask1 + 4 : mask1;
4322 mask1 = j == sheet->range.coli ? mask1 + 8 : mask1;
4324 mask2 = i == new_range.row0 ? 1 : 0;
4325 mask2 = i == new_range.rowi ? mask2 + 2 : mask2;
4326 mask2 = j == new_range.col0 ? mask2 + 4 : mask2;
4327 mask2 = j == new_range.coli ? mask2 + 8 : mask2;
4331 x = COLUMN_LEFT_XPIXEL (sheet,j);
4332 y = ROW_TOP_YPIXEL (sheet, i);
4333 width = COLUMN_LEFT_XPIXEL (sheet, j)- x+
4334 xxx_column_width (sheet, j);
4335 height = ROW_TOP_YPIXEL (sheet, i)- y + yyy_row_height (sheet, i);
4337 if (i == sheet->range.row0)
4340 height = height + 3;
4342 if (i == sheet->range.rowi) height = height + 3;
4343 if (j == sheet->range.col0)
4348 if (j == sheet->range.coli) width = width + 3;
4350 gdk_draw_pixmap (sheet->sheet_window,
4351 GTK_WIDGET (sheet)->style->fg_gc[GTK_STATE_NORMAL],
4360 if (i != sheet->active_cell.row || j != sheet->active_cell.col)
4362 x = COLUMN_LEFT_XPIXEL (sheet,j);
4363 y = ROW_TOP_YPIXEL (sheet, i);
4364 width = COLUMN_LEFT_XPIXEL (sheet, j)- x+
4365 xxx_column_width (sheet, j);
4367 height = ROW_TOP_YPIXEL (sheet, i)- y + yyy_row_height (sheet, i);
4369 if (i == new_range.row0)
4372 height = height - 2;
4374 if (i == new_range.rowi) height = height - 3;
4375 if (j == new_range.col0)
4380 if (j == new_range.coli) width = width - 3;
4382 gdk_draw_rectangle (sheet->sheet_window,
4393 for (i = range->row0; i <= range->rowi; i++)
4395 for (j = range->col0; j <= range->coli; j++)
4398 state = gtk_sheet_cell_get_state (sheet, i, j);
4399 selected= (i <= new_range.rowi && i >= new_range.row0 &&
4400 j <= new_range.coli && j >= new_range.col0) ? TRUE : FALSE;
4402 if (state == GTK_STATE_SELECTED && !selected &&
4403 xxx_column_is_visible (sheet, j) && yyy_row_is_visible (sheet, i))
4406 x = COLUMN_LEFT_XPIXEL (sheet,j);
4407 y = ROW_TOP_YPIXEL (sheet, i);
4408 width = COLUMN_LEFT_XPIXEL (sheet, j)- x+ xxx_column_width (sheet, j);
4409 height = ROW_TOP_YPIXEL (sheet, i)- y + yyy_row_height (sheet, i);
4411 if (i == sheet->range.row0)
4414 height = height + 3;
4416 if (i == sheet->range.rowi) height = height + 3;
4417 if (j == sheet->range.col0)
4422 if (j == sheet->range.coli) width = width + 3;
4424 gdk_draw_pixmap (sheet->sheet_window,
4425 GTK_WIDGET (sheet)->style->fg_gc[GTK_STATE_NORMAL],
4437 for (i = range->row0; i <= range->rowi; i++)
4439 for (j = range->col0; j <= range->coli; j++)
4442 state = gtk_sheet_cell_get_state (sheet, i, j);
4443 selected= (i <= new_range.rowi && i >= new_range.row0 &&
4444 j <= new_range.coli && j >= new_range.col0) ? TRUE : FALSE;
4446 if (state != GTK_STATE_SELECTED && selected &&
4447 xxx_column_is_visible (sheet, j) && yyy_row_is_visible (sheet, i) &&
4448 (i != sheet->active_cell.row || j != sheet->active_cell.col))
4451 x = COLUMN_LEFT_XPIXEL (sheet,j);
4452 y = ROW_TOP_YPIXEL (sheet, i);
4453 width = COLUMN_LEFT_XPIXEL (sheet, j)- x+ xxx_column_width (sheet, j);
4454 height = ROW_TOP_YPIXEL (sheet, i)- y + yyy_row_height (sheet, i);
4456 if (i == new_range.row0)
4459 height = height - 2;
4461 if (i == new_range.rowi) height = height - 3;
4462 if (j == new_range.col0)
4467 if (j == new_range.coli) width = width - 3;
4469 gdk_draw_rectangle (sheet->sheet_window,
4480 for (i = aux_range.row0; i <= aux_range.rowi; i++)
4482 for (j = aux_range.col0; j <= aux_range.coli; j++)
4485 if (xxx_column_is_visible (sheet, j) && yyy_row_is_visible (sheet, i))
4488 state = gtk_sheet_cell_get_state (sheet, i, j);
4490 mask1 = i == sheet->range.row0 ? 1 : 0;
4491 mask1 = i == sheet->range.rowi ? mask1 + 2 : mask1;
4492 mask1 = j == sheet->range.col0 ? mask1 + 4 : mask1;
4493 mask1 = j == sheet->range.coli ? mask1 + 8 : mask1;
4495 mask2 = i == new_range.row0 ? 1 : 0;
4496 mask2 = i == new_range.rowi ? mask2 + 2 : mask2;
4497 mask2 = j == new_range.col0 ? mask2 + 4 : mask2;
4498 mask2 = j == new_range.coli ? mask2 + 8 : mask2;
4499 if (mask2 != mask1 || (mask2 == mask1 && state != GTK_STATE_SELECTED))
4501 x = COLUMN_LEFT_XPIXEL (sheet,j);
4502 y = ROW_TOP_YPIXEL (sheet, i);
4503 width = xxx_column_width (sheet, j);
4504 height = yyy_row_height (sheet, i);
4506 gdk_draw_rectangle (sheet->sheet_window,
4514 gdk_draw_rectangle (sheet->sheet_window,
4517 x + 1,y + height - 1,
4521 gdk_draw_rectangle (sheet->sheet_window,
4529 gdk_draw_rectangle (sheet->sheet_window,
4532 x + width - 1,y + 1,
4546 gtk_sheet_draw_corners (sheet, new_range);
4551 gtk_sheet_draw_border (GtkSheet *sheet, GtkSheetRange new_range)
4556 gint x, y, width, height;
4558 widget = GTK_WIDGET (sheet);
4560 x = COLUMN_LEFT_XPIXEL (sheet,new_range.col0);
4561 y = ROW_TOP_YPIXEL (sheet,new_range.row0);
4562 width = COLUMN_LEFT_XPIXEL (sheet, new_range.coli) - x +
4563 xxx_column_width (sheet, new_range.coli);
4565 height = ROW_TOP_YPIXEL (sheet, new_range.rowi) - y +
4566 yyy_row_height (sheet, new_range.rowi);
4568 area.x = COLUMN_LEFT_XPIXEL (sheet, MIN_VISIBLE_COLUMN (sheet));
4569 area.y = ROW_TOP_YPIXEL (sheet, MIN_VISIBLE_ROW (sheet));
4570 area.width = sheet->sheet_window_width;
4571 area.height = sheet->sheet_window_height;
4578 if (width > area.width) width = area.width + 10;
4581 height = height + y;
4584 if (height > area.height) height = area.height + 10;
4586 gdk_gc_set_clip_rectangle (sheet->xor_gc, &area);
4588 for (i =- 1; i <= 1; ++i)
4589 gdk_draw_rectangle (sheet->sheet_window,
4597 gdk_gc_set_clip_rectangle (sheet->xor_gc, NULL);
4600 gtk_sheet_draw_corners (sheet, new_range);
4604 gtk_sheet_draw_corners (GtkSheet *sheet, GtkSheetRange range)
4609 if (gtk_sheet_cell_isvisible (sheet, range.row0, range.col0))
4611 x = COLUMN_LEFT_XPIXEL (sheet,range.col0);
4612 y = ROW_TOP_YPIXEL (sheet,range.row0);
4613 gdk_draw_pixmap (sheet->sheet_window,
4614 GTK_WIDGET (sheet)->style->fg_gc[GTK_STATE_NORMAL],
4622 gdk_draw_rectangle (sheet->sheet_window,
4629 if (gtk_sheet_cell_isvisible (sheet, range.row0, range.coli) ||
4630 sheet->state == GTK_SHEET_COLUMN_SELECTED)
4632 x = COLUMN_LEFT_XPIXEL (sheet,range.coli)+
4633 xxx_column_width (sheet, range.coli);
4634 y = ROW_TOP_YPIXEL (sheet,range.row0);
4636 if (sheet->state == GTK_SHEET_COLUMN_SELECTED)
4638 y = ROW_TOP_YPIXEL (sheet, MIN_VISIBLE_ROW (sheet))+3;
4641 gdk_draw_pixmap (sheet->sheet_window,
4642 GTK_WIDGET (sheet)->style->fg_gc[GTK_STATE_NORMAL],
4650 gdk_draw_rectangle (sheet->sheet_window,
4653 x - width + width / 2,y - width + width / 2,
4654 2 + width,2 + width);
4657 if (gtk_sheet_cell_isvisible (sheet, range.rowi, range.col0) ||
4658 sheet->state == GTK_SHEET_ROW_SELECTED)
4660 x = COLUMN_LEFT_XPIXEL (sheet,range.col0);
4661 y = ROW_TOP_YPIXEL (sheet,range.rowi)+
4662 yyy_row_height (sheet, range.rowi);
4664 if (sheet->state == GTK_SHEET_ROW_SELECTED)
4666 x = COLUMN_LEFT_XPIXEL (sheet, MIN_VISIBLE_COLUMN (sheet))+3;
4669 gdk_draw_pixmap (sheet->sheet_window,
4670 GTK_WIDGET (sheet)->style->fg_gc[GTK_STATE_NORMAL],
4678 gdk_draw_rectangle (sheet->sheet_window,
4681 x - width + width / 2,y - width + width / 2,
4682 2 + width,2 + width);
4685 if (gtk_sheet_cell_isvisible (sheet, range.rowi, range.coli))
4687 x = COLUMN_LEFT_XPIXEL (sheet,range.coli)+
4688 xxx_column_width (sheet, range.coli);
4689 y = ROW_TOP_YPIXEL (sheet,range.rowi)+
4690 yyy_row_height (sheet, range.rowi);
4692 if (sheet->state == GTK_SHEET_RANGE_SELECTED) width = 3;
4693 if (sheet->state == GTK_SHEET_NORMAL) width = 3;
4694 gdk_draw_pixmap (sheet->sheet_window,
4695 GTK_WIDGET (sheet)->style->fg_gc[GTK_STATE_NORMAL],
4703 gdk_draw_rectangle (sheet->sheet_window,
4706 x - width + width / 2,y - width + width / 2,
4707 2 + width,2 + width);
4715 gtk_sheet_real_select_range (GtkSheet * sheet,
4716 const GtkSheetRange * range)
4720 g_return_if_fail (sheet != NULL);
4722 if (range == NULL) range = &sheet->range;
4724 memcpy (&sheet->range, range, sizeof (*range));
4726 if (range->row0 < 0 || range->rowi < 0) return;
4727 if (range->col0 < 0 || range->coli < 0) return;
4729 state = sheet->state;
4731 if (range->coli != sheet->range.coli || range->col0 != sheet->range.col0 ||
4732 range->rowi != sheet->range.rowi || range->row0 != sheet->range.row0)
4734 gtk_sheet_new_selection (sheet, &sheet->range);
4738 gtk_sheet_draw_backing_pixmap (sheet, sheet->range);
4739 gtk_sheet_range_draw_selection (sheet, sheet->range);
4742 g_signal_emit (G_OBJECT (sheet), sheet_signals[SELECT_RANGE], 0, &sheet->range);
4747 gtk_sheet_get_selected_range (GtkSheet *sheet,
4748 GtkSheetRange *range)
4750 g_return_if_fail (sheet != NULL);
4751 *range = sheet->range;
4756 gtk_sheet_select_range (GtkSheet * sheet, const GtkSheetRange *range)
4758 g_return_if_fail (sheet != NULL);
4760 if (range == NULL) range=&sheet->range;
4762 if (range->row0 < 0 || range->rowi < 0) return;
4763 if (range->col0 < 0 || range->coli < 0) return;
4766 if ( gtk_sheet_locked (sheet)) return ;
4768 if (sheet->state != GTK_SHEET_NORMAL)
4769 gtk_sheet_real_unselect_range (sheet, NULL);
4772 gboolean veto = TRUE;
4773 veto = gtk_sheet_deactivate_cell (sheet);
4777 sheet->range.row0 = range->row0;
4778 sheet->range.rowi = range->rowi;
4779 sheet->range.col0 = range->col0;
4780 sheet->range.coli = range->coli;
4781 sheet->active_cell.row = range->row0;
4782 sheet->active_cell.col = range->col0;
4783 sheet->selection_cell.row = range->rowi;
4784 sheet->selection_cell.col = range->coli;
4786 sheet->state = GTK_SHEET_RANGE_SELECTED;
4787 gtk_sheet_real_select_range (sheet, NULL);
4792 gtk_sheet_unselect_range (GtkSheet * sheet)
4794 gtk_sheet_real_unselect_range (sheet, NULL);
4795 sheet->state = GTK_STATE_NORMAL;
4796 gtk_sheet_activate_cell (sheet,
4797 sheet->active_cell.row, sheet->active_cell.col);
4802 gtk_sheet_real_unselect_range (GtkSheet * sheet,
4803 const GtkSheetRange *range)
4805 g_return_if_fail (sheet != NULL);
4806 g_return_if_fail (GTK_WIDGET_REALIZED (GTK_WIDGET (sheet)));
4809 range = &sheet->range;
4811 if (range->row0 < 0 || range->rowi < 0) return;
4812 if (range->col0 < 0 || range->coli < 0) return;
4814 if (gtk_sheet_range_isvisible (sheet, *range))
4815 gtk_sheet_draw_backing_pixmap (sheet, *range);
4817 sheet->range.row0 = -1;
4818 sheet->range.rowi = -1;
4819 sheet->range.col0 = -1;
4820 sheet->range.coli = -1;
4822 gtk_sheet_position_children (sheet);
4827 gtk_sheet_expose (GtkWidget * widget,
4828 GdkEventExpose * event)
4831 GtkSheetRange range;
4833 g_return_val_if_fail (widget != NULL, FALSE);
4834 g_return_val_if_fail (GTK_IS_SHEET (widget), FALSE);
4835 g_return_val_if_fail (event != NULL, FALSE);
4838 sheet = GTK_SHEET (widget);
4840 if (GTK_WIDGET_DRAWABLE (widget))
4842 range.row0 = ROW_FROM_YPIXEL (sheet, event->area.y);
4843 range.col0 = COLUMN_FROM_XPIXEL (sheet, event->area.x);
4844 range.rowi = ROW_FROM_YPIXEL (sheet, event->area.y + event->area.height);
4845 range.coli = COLUMN_FROM_XPIXEL (sheet, event->area.x + event->area.width);
4847 /* exposure events on the sheet */
4848 if (event->window == sheet->row_title_window &&
4849 sheet->row_titles_visible)
4852 for (i = MIN_VISIBLE_ROW (sheet); i <= MAX_VISIBLE_ROW (sheet); i++)
4853 gtk_sheet_row_title_button_draw (sheet, i);
4856 if (event->window == sheet->column_title_window &&
4857 sheet->column_titles_visible)
4860 for (i = MIN_VISIBLE_COLUMN (sheet); i <= MAX_VISIBLE_COLUMN (sheet); i++)
4861 gtk_sheet_column_title_button_draw (sheet, i);
4864 if (event->window == sheet->sheet_window)
4866 gtk_sheet_draw_backing_pixmap (sheet, range);
4868 if (sheet->state != GTK_SHEET_NORMAL)
4870 if (gtk_sheet_range_isvisible (sheet, sheet->range))
4871 gtk_sheet_draw_backing_pixmap (sheet, sheet->range);
4872 if (GTK_SHEET_IN_RESIZE (sheet) || GTK_SHEET_IN_DRAG (sheet))
4873 gtk_sheet_draw_backing_pixmap (sheet, sheet->drag_range);
4875 if (gtk_sheet_range_isvisible (sheet, sheet->range))
4876 gtk_sheet_range_draw_selection (sheet, sheet->range);
4877 if (GTK_SHEET_IN_RESIZE (sheet) || GTK_SHEET_IN_DRAG (sheet))
4878 draw_xor_rectangle (sheet, sheet->drag_range);
4881 if ((!GTK_SHEET_IN_XDRAG (sheet)) && (!GTK_SHEET_IN_YDRAG (sheet)))
4883 if (sheet->state == GTK_SHEET_NORMAL)
4885 gtk_sheet_draw_active_cell (sheet);
4886 if (!GTK_SHEET_IN_SELECTION (sheet))
4887 gtk_widget_queue_draw (sheet->sheet_entry);
4893 if (sheet->state != GTK_SHEET_NORMAL && GTK_SHEET_IN_SELECTION (sheet))
4894 gtk_widget_grab_focus (GTK_WIDGET (sheet));
4896 (* GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event);
4903 gtk_sheet_button_press (GtkWidget * widget,
4904 GdkEventButton * event)
4907 GdkModifierType mods;
4908 gint x, y, row, column;
4911 g_return_val_if_fail (widget != NULL, FALSE);
4912 g_return_val_if_fail (GTK_IS_SHEET (widget), FALSE);
4913 g_return_val_if_fail (event != NULL, FALSE);
4915 sheet = GTK_SHEET (widget);
4917 if ( event->type == GDK_2BUTTON_PRESS)
4919 gtk_widget_get_pointer (widget, &x, &y);
4920 gtk_sheet_get_pixel_info (sheet, x, y, &row, &column);
4922 if (event->window == sheet->column_title_window)
4924 g_signal_emit (G_OBJECT (sheet),
4925 sheet_signals[DOUBLE_CLICK_COLUMN], 0, column);
4927 else if (event->window == sheet->row_title_window)
4929 g_signal_emit (G_OBJECT (sheet),
4930 sheet_signals[DOUBLE_CLICK_ROW], 0, row);
4935 gdk_window_get_pointer (widget->window, NULL, NULL, &mods);
4937 if (! (mods & GDK_BUTTON1_MASK)) return TRUE;
4940 /* press on resize windows */
4941 if (event->window == sheet->column_title_window &&
4942 gtk_sheet_columns_resizable (sheet))
4944 gtk_widget_get_pointer (widget, &sheet->x_drag, NULL);
4945 if (POSSIBLE_XDRAG (sheet, sheet->x_drag, &sheet->drag_cell.col))
4948 if (event->type == GDK_2BUTTON_PRESS)
4950 gtk_sheet_autoresize_column (sheet, sheet->drag_cell.col);
4951 GTK_SHEET_UNSET_FLAGS (sheet, GTK_SHEET_IN_XDRAG);
4954 gtk_sheet_column_size_request (sheet, sheet->drag_cell.col, &req);
4955 GTK_SHEET_SET_FLAGS (sheet, GTK_SHEET_IN_XDRAG);
4956 gdk_pointer_grab (sheet->column_title_window, FALSE,
4957 GDK_POINTER_MOTION_HINT_MASK |
4958 GDK_BUTTON1_MOTION_MASK |
4959 GDK_BUTTON_RELEASE_MASK,
4960 NULL, NULL, event->time);
4962 draw_xor_vline (sheet);
4967 if (event->window == sheet->row_title_window && gtk_sheet_rows_resizable (sheet))
4969 gtk_widget_get_pointer (widget, NULL, &sheet->y_drag);
4971 if (POSSIBLE_YDRAG (sheet, sheet->y_drag, &sheet->drag_cell.row))
4974 gtk_sheet_row_size_request (sheet, sheet->drag_cell.row, &req);
4975 GTK_SHEET_SET_FLAGS (sheet, GTK_SHEET_IN_YDRAG);
4976 gdk_pointer_grab (sheet->row_title_window, FALSE,
4977 GDK_POINTER_MOTION_HINT_MASK |
4978 GDK_BUTTON1_MOTION_MASK |
4979 GDK_BUTTON_RELEASE_MASK,
4980 NULL, NULL, event->time);
4982 draw_xor_hline (sheet);
4987 /* the sheet itself does not handle other than single click events */
4988 if (event->type != GDK_BUTTON_PRESS) return FALSE;
4990 /* selections on the sheet */
4991 if (event->window == sheet->sheet_window)
4993 gtk_widget_get_pointer (widget, &x, &y);
4994 gtk_sheet_get_pixel_info (sheet, x, y, &row, &column);
4995 gdk_pointer_grab (sheet->sheet_window, FALSE,
4996 GDK_POINTER_MOTION_HINT_MASK |
4997 GDK_BUTTON1_MOTION_MASK |
4998 GDK_BUTTON_RELEASE_MASK,
4999 NULL, NULL, event->time);
5000 gtk_grab_add (GTK_WIDGET (sheet));
5002 /* This seems to be a kludge to work around a problem where the sheet
5003 scrolls to another position. The timeout scrolls it back to its
5004 original posn. JMD 3 July 2007
5006 gtk_widget_grab_focus (GTK_WIDGET (sheet));
5008 if (sheet->selection_mode != GTK_SELECTION_SINGLE &&
5009 sheet->selection_mode != GTK_SELECTION_NONE &&
5010 sheet->cursor_drag->type == GDK_SIZING &&
5011 !GTK_SHEET_IN_SELECTION (sheet) && !GTK_SHEET_IN_RESIZE (sheet))
5013 if (sheet->state == GTK_STATE_NORMAL)
5015 row = sheet->active_cell.row;
5016 column = sheet->active_cell.col;
5017 if (!gtk_sheet_deactivate_cell (sheet)) return FALSE;
5018 sheet->active_cell.row = row;
5019 sheet->active_cell.col = column;
5020 sheet->drag_range = sheet->range;
5021 sheet->state = GTK_SHEET_RANGE_SELECTED;
5022 gtk_sheet_select_range (sheet, &sheet->drag_range);
5026 if (row > sheet->range.rowi) row--;
5027 if (column > sheet->range.coli) column--;
5028 sheet->drag_cell.row = row;
5029 sheet->drag_cell.col = column;
5030 sheet->drag_range = sheet->range;
5031 draw_xor_rectangle (sheet, sheet->drag_range);
5032 GTK_SHEET_SET_FLAGS (sheet, GTK_SHEET_IN_RESIZE);
5034 else if (sheet->cursor_drag->type == GDK_TOP_LEFT_ARROW &&
5035 !GTK_SHEET_IN_SELECTION (sheet)
5036 && ! GTK_SHEET_IN_DRAG (sheet)
5037 && ! gtk_sheet_locked (sheet)
5038 && sheet->active_cell.row >= 0
5039 && sheet->active_cell.col >= 0
5042 if (sheet->state == GTK_STATE_NORMAL)
5044 row = sheet->active_cell.row;
5045 column = sheet->active_cell.col;
5046 if (!gtk_sheet_deactivate_cell (sheet)) return FALSE;
5047 sheet->active_cell.row = row;
5048 sheet->active_cell.col = column;
5049 sheet->drag_range = sheet->range;
5050 sheet->state = GTK_SHEET_RANGE_SELECTED;
5051 gtk_sheet_select_range (sheet, &sheet->drag_range);
5055 if (row < sheet->range.row0) row++;
5056 if (row > sheet->range.rowi) row--;
5057 if (column < sheet->range.col0) column++;
5058 if (column > sheet->range.coli) column--;
5059 sheet->drag_cell.row = row;
5060 sheet->drag_cell.col = column;
5061 sheet->drag_range = sheet->range;
5062 draw_xor_rectangle (sheet, sheet->drag_range);
5063 GTK_SHEET_SET_FLAGS (sheet, GTK_SHEET_IN_DRAG);
5067 gtk_sheet_click_cell (sheet, row, column, &veto);
5068 if (veto) GTK_SHEET_SET_FLAGS (sheet, GTK_SHEET_IN_SELECTION);
5072 if (event->window == sheet->column_title_window)
5074 gtk_widget_get_pointer (widget, &x, &y);
5075 column = COLUMN_FROM_XPIXEL (sheet, x);
5077 if (xxx_column_is_sensitive (sheet, column))
5079 gtk_sheet_click_cell (sheet, - 1, column, &veto);
5080 gtk_grab_add (GTK_WIDGET (sheet));
5081 gtk_widget_grab_focus (GTK_WIDGET (sheet));
5082 GTK_SHEET_SET_FLAGS (sheet, GTK_SHEET_IN_SELECTION);
5086 if (event->window == sheet->row_title_window)
5088 gtk_widget_get_pointer (widget, &x, &y);
5089 row = ROW_FROM_YPIXEL (sheet, y);
5090 if (yyy_row_is_sensitive (sheet, row))
5092 gtk_sheet_click_cell (sheet, row, - 1, &veto);
5093 gtk_grab_add (GTK_WIDGET (sheet));
5094 gtk_widget_grab_focus (GTK_WIDGET (sheet));
5095 GTK_SHEET_SET_FLAGS (sheet, GTK_SHEET_IN_SELECTION);
5104 gtk_sheet_scroll (gpointer data)
5107 gint x,y,row,column;
5110 sheet = GTK_SHEET (data);
5112 GDK_THREADS_ENTER ();
5114 gtk_widget_get_pointer (GTK_WIDGET (sheet), &x, &y);
5115 gtk_sheet_get_pixel_info (sheet, x, y, &row, &column);
5119 if (GTK_SHEET_IN_SELECTION (sheet))
5120 gtk_sheet_extend_selection (sheet, row, column);
5122 if (GTK_SHEET_IN_DRAG (sheet) || GTK_SHEET_IN_RESIZE (sheet))
5124 move = gtk_sheet_move_query (sheet, row, column);
5125 if (move) draw_xor_rectangle (sheet, sheet->drag_range);
5128 GDK_THREADS_LEAVE ();
5135 gtk_sheet_click_cell (GtkSheet *sheet, gint row, gint column, gboolean *veto)
5139 if (row >= yyy_row_count (sheet) || column >= xxx_column_count (sheet))
5145 if (column >= 0 && row >= 0)
5146 if (! xxx_column_is_visible (sheet, column) || !yyy_row_is_visible (sheet, row))
5152 _gtkextra_signal_emit (GTK_OBJECT (sheet), sheet_signals[TRAVERSE],
5153 sheet->active_cell.row, sheet->active_cell.col,
5154 &row, &column, veto);
5158 if (sheet->state == GTK_STATE_NORMAL) return;
5160 row = sheet->active_cell.row;
5161 column = sheet->active_cell.col;
5163 gtk_sheet_activate_cell (sheet, row, column);
5167 if (row == -1 && column >= 0)
5169 if (gtk_sheet_autoscroll (sheet))
5170 gtk_sheet_move_query (sheet, row, column);
5171 gtk_sheet_select_column (sheet, column);
5174 if (column == -1 && row >= 0)
5176 if (gtk_sheet_autoscroll (sheet))
5177 gtk_sheet_move_query (sheet, row, column);
5178 gtk_sheet_select_row (sheet, row);
5182 if (row == - 1 && column == - 1)
5184 sheet->range.row0 = 0;
5185 sheet->range.col0 = 0;
5186 sheet->range.rowi = yyy_row_count (sheet) - 1;
5187 sheet->range.coli = xxx_column_count (sheet) - 1;
5188 sheet->active_cell.row = 0;
5189 sheet->active_cell.col = 0;
5190 gtk_sheet_select_range (sheet, NULL);
5194 if (row != -1 && column != -1)
5196 if (sheet->state != GTK_SHEET_NORMAL)
5198 sheet->state = GTK_SHEET_NORMAL;
5199 gtk_sheet_real_unselect_range (sheet, NULL);
5203 if (!gtk_sheet_deactivate_cell (sheet))
5210 if (gtk_sheet_autoscroll (sheet))
5211 gtk_sheet_move_query (sheet, row, column);
5212 sheet->active_cell.row = row;
5213 sheet->active_cell.col = column;
5214 sheet->selection_cell.row = row;
5215 sheet->selection_cell.col = column;
5216 sheet->range.row0 = row;
5217 sheet->range.col0 = column;
5218 sheet->range.rowi = row;
5219 sheet->range.coli = column;
5220 sheet->state = GTK_SHEET_NORMAL;
5221 GTK_SHEET_SET_FLAGS (sheet, GTK_SHEET_IN_SELECTION);
5222 gtk_sheet_draw_active_cell (sheet);
5226 g_assert_not_reached ();
5227 gtk_sheet_activate_cell (sheet, sheet->active_cell.row,
5228 sheet->active_cell.col);
5232 gtk_sheet_button_release (GtkWidget * widget,
5233 GdkEventButton * event)
5238 sheet = GTK_SHEET (widget);
5240 /* release on resize windows */
5241 if (GTK_SHEET_IN_XDRAG (sheet))
5243 GTK_SHEET_UNSET_FLAGS (sheet, GTK_SHEET_IN_XDRAG);
5244 GTK_SHEET_UNSET_FLAGS (sheet, GTK_SHEET_IN_SELECTION);
5245 gtk_widget_get_pointer (widget, &x, NULL);
5246 gdk_pointer_ungrab (event->time);
5247 draw_xor_vline (sheet);
5249 gtk_sheet_set_column_width (sheet, sheet->drag_cell.col,
5250 new_column_width (sheet, sheet->drag_cell.col, &x));
5251 sheet->old_hadjustment = -1.;
5252 g_signal_emit_by_name (G_OBJECT (sheet->hadjustment), "value_changed");
5256 if (GTK_SHEET_IN_YDRAG (sheet))
5258 GTK_SHEET_UNSET_FLAGS (sheet, GTK_SHEET_IN_YDRAG);
5259 GTK_SHEET_UNSET_FLAGS (sheet, GTK_SHEET_IN_SELECTION);
5260 gtk_widget_get_pointer (widget, NULL, &y);
5261 gdk_pointer_ungrab (event->time);
5262 draw_xor_hline (sheet);
5264 gtk_sheet_set_row_height (sheet, sheet->drag_cell.row, new_row_height (sheet, sheet->drag_cell.row, &y));
5265 sheet->old_vadjustment = -1.;
5266 g_signal_emit_by_name (G_OBJECT (sheet->vadjustment), "value_changed");
5271 if (GTK_SHEET_IN_DRAG (sheet))
5273 GtkSheetRange old_range;
5274 draw_xor_rectangle (sheet, sheet->drag_range);
5275 GTK_SHEET_UNSET_FLAGS (sheet, GTK_SHEET_IN_DRAG);
5276 gdk_pointer_ungrab (event->time);
5278 gtk_sheet_real_unselect_range (sheet, NULL);
5280 sheet->active_cell.row = sheet->active_cell.row +
5281 (sheet->drag_range.row0 - sheet->range.row0);
5282 sheet->active_cell.col = sheet->active_cell.col +
5283 (sheet->drag_range.col0 - sheet->range.col0);
5284 sheet->selection_cell.row = sheet->selection_cell.row +
5285 (sheet->drag_range.row0 - sheet->range.row0);
5286 sheet->selection_cell.col = sheet->selection_cell.col +
5287 (sheet->drag_range.col0 - sheet->range.col0);
5288 old_range = sheet->range;
5289 sheet->range = sheet->drag_range;
5290 sheet->drag_range = old_range;
5291 g_signal_emit (G_OBJECT (sheet), sheet_signals[MOVE_RANGE], 0,
5292 &sheet->drag_range, &sheet->range);
5293 gtk_sheet_select_range (sheet, &sheet->range);
5296 if (GTK_SHEET_IN_RESIZE (sheet))
5298 GtkSheetRange old_range;
5299 draw_xor_rectangle (sheet, sheet->drag_range);
5300 GTK_SHEET_UNSET_FLAGS (sheet, GTK_SHEET_IN_RESIZE);
5301 gdk_pointer_ungrab (event->time);
5303 gtk_sheet_real_unselect_range (sheet, NULL);
5305 sheet->active_cell.row = sheet->active_cell.row +
5306 (sheet->drag_range.row0 - sheet->range.row0);
5307 sheet->active_cell.col = sheet->active_cell.col +
5308 (sheet->drag_range.col0 - sheet->range.col0);
5309 if (sheet->drag_range.row0 < sheet->range.row0)
5310 sheet->selection_cell.row = sheet->drag_range.row0;
5311 if (sheet->drag_range.rowi >= sheet->range.rowi)
5312 sheet->selection_cell.row = sheet->drag_range.rowi;
5313 if (sheet->drag_range.col0 < sheet->range.col0)
5314 sheet->selection_cell.col = sheet->drag_range.col0;
5315 if (sheet->drag_range.coli >= sheet->range.coli)
5316 sheet->selection_cell.col = sheet->drag_range.coli;
5317 old_range = sheet->range;
5318 sheet->range = sheet->drag_range;
5319 sheet->drag_range = old_range;
5321 if (sheet->state == GTK_STATE_NORMAL) sheet->state = GTK_SHEET_RANGE_SELECTED;
5322 g_signal_emit (G_OBJECT (sheet), sheet_signals[RESIZE_RANGE], 0,
5323 &sheet->drag_range, &sheet->range);
5324 gtk_sheet_select_range (sheet, &sheet->range);
5327 if (sheet->state == GTK_SHEET_NORMAL && GTK_SHEET_IN_SELECTION (sheet))
5329 GTK_SHEET_UNSET_FLAGS (sheet, GTK_SHEET_IN_SELECTION);
5330 gdk_pointer_ungrab (event->time);
5331 gtk_sheet_activate_cell (sheet, sheet->active_cell.row,
5332 sheet->active_cell.col);
5335 if (GTK_SHEET_IN_SELECTION)
5336 gdk_pointer_ungrab (event->time);
5337 gtk_grab_remove (GTK_WIDGET (sheet));
5339 GTK_SHEET_UNSET_FLAGS (sheet, GTK_SHEET_IN_SELECTION);
5344 /* Shamelessly lifted from gtktooltips */
5346 gtk_sheet_subtitle_paint_window (GtkWidget *tip_window)
5350 gtk_widget_size_request (tip_window, &req);
5351 gtk_paint_flat_box (tip_window->style, tip_window->window,
5352 GTK_STATE_NORMAL, GTK_SHADOW_OUT,
5353 NULL, GTK_WIDGET(tip_window), "tooltip",
5354 0, 0, req.width, req.height);
5359 static GtkSheetHoverTitle *
5360 create_hover_window (void)
5362 GtkSheetHoverTitle *hw = malloc (sizeof (*hw));
5364 hw->window = gtk_window_new (GTK_WINDOW_POPUP);
5366 #if GTK_CHECK_VERSION (2, 9, 0)
5367 gtk_window_set_type_hint (GTK_WINDOW (hw->window),
5368 GDK_WINDOW_TYPE_HINT_TOOLTIP);
5371 gtk_widget_set_app_paintable (hw->window, TRUE);
5372 gtk_window_set_resizable (GTK_WINDOW (hw->window), FALSE);
5373 gtk_widget_set_name (hw->window, "gtk-tooltips");
5374 gtk_container_set_border_width (GTK_CONTAINER (hw->window), 4);
5376 g_signal_connect (hw->window,
5378 G_CALLBACK (gtk_sheet_subtitle_paint_window),
5381 hw->label = gtk_label_new (NULL);
5384 gtk_label_set_line_wrap (GTK_LABEL (hw->label), TRUE);
5385 gtk_misc_set_alignment (GTK_MISC (hw->label), 0.5, 0.5);
5387 gtk_container_add (GTK_CONTAINER (hw->window), hw->label);
5389 gtk_widget_show (hw->label);
5391 g_signal_connect (hw->window,
5393 G_CALLBACK (gtk_widget_destroyed),
5399 #define HOVER_WINDOW_Y_OFFSET 2
5402 show_subtitle (GtkSheet *sheet, gint row, gint column, const gchar *subtitle)
5411 if ( ! sheet->hover_window)
5413 sheet->hover_window = create_hover_window ();
5414 gtk_widget_add_events (GTK_WIDGET (sheet), GDK_LEAVE_NOTIFY_MASK);
5416 g_signal_connect_swapped (sheet, "leave-notify-event",
5417 G_CALLBACK (gtk_widget_hide),
5418 sheet->hover_window->window);
5421 gtk_label_set_text (GTK_LABEL (sheet->hover_window->label),
5425 sheet->hover_window->row = row;
5426 sheet->hover_window->column = column;
5428 gdk_window_get_origin (GTK_WIDGET (sheet)->window, &x, &y);
5430 gtk_widget_get_pointer (GTK_WIDGET (sheet), &px, &py);
5432 gtk_widget_show (sheet->hover_window->window);
5434 width = GTK_WIDGET (sheet->hover_window->label)->allocation.width;
5440 y += sheet->column_title_area.y;
5441 y += sheet->column_title_area.height;
5442 y += HOVER_WINDOW_Y_OFFSET;
5448 x += sheet->row_title_area.x;
5449 x += sheet->row_title_area.width * 2 / 3.0;
5452 gtk_window_move (GTK_WINDOW (sheet->hover_window->window),
5457 motion_timeout_callback (gpointer data)
5459 GtkSheet *sheet = GTK_SHEET (data);
5460 if ( --sheet->motion_events == 0 )
5464 gtk_widget_get_pointer (GTK_WIDGET (sheet), &x, &y);
5466 if ( gtk_sheet_get_pixel_info (sheet, x, y, &row, &column) )
5468 if ( column == -1 && row == -1 )
5473 GSheetRow *row_geo = sheet->row_geometry;
5476 text = g_sheet_row_get_subtitle (row_geo, row);
5478 show_subtitle (sheet, row, column, text);
5484 GSheetColumn *col_geo = sheet->column_geometry;
5487 text = g_sheet_column_get_subtitle (col_geo, column);
5489 show_subtitle (sheet, row, column, text );
5500 gtk_sheet_motion (GtkWidget * widget,
5501 GdkEventMotion * event)
5504 GdkModifierType mods;
5505 GdkCursorType new_cursor;
5509 g_return_val_if_fail (widget != NULL, FALSE);
5510 g_return_val_if_fail (GTK_IS_SHEET (widget), FALSE);
5511 g_return_val_if_fail (event != NULL, FALSE);
5513 sheet = GTK_SHEET (widget);
5515 /* selections on the sheet */
5519 if (!sheet->hover_window || ! GTK_WIDGET_VISIBLE (sheet->hover_window->window))
5521 sheet->motion_events++;
5522 g_timeout_add (TIMEOUT_HOVER, motion_timeout_callback, sheet);
5528 gtk_widget_get_pointer (widget, &wx, &wy);
5530 if ( gtk_sheet_get_pixel_info (sheet, wx, wy, &row, &column) )
5532 if ( row != sheet->hover_window->row || column != sheet->hover_window->column)
5534 gtk_widget_hide (sheet->hover_window->window);
5539 if (event->window == sheet->column_title_window &&
5540 gtk_sheet_columns_resizable (sheet))
5542 gtk_widget_get_pointer (widget, &x, &y);
5543 if (!GTK_SHEET_IN_SELECTION (sheet) &&
5544 POSSIBLE_XDRAG (sheet, x, &column))
5546 new_cursor = GDK_SB_H_DOUBLE_ARROW;
5547 if (new_cursor != sheet->cursor_drag->type)
5549 gdk_cursor_destroy (sheet->cursor_drag);
5550 sheet->cursor_drag = gdk_cursor_new (GDK_SB_H_DOUBLE_ARROW);
5551 gdk_window_set_cursor (sheet->column_title_window,
5552 sheet->cursor_drag);
5557 new_cursor = GDK_TOP_LEFT_ARROW;
5558 if (!GTK_SHEET_IN_XDRAG (sheet) &&
5559 new_cursor != sheet->cursor_drag->type)
5561 gdk_cursor_destroy (sheet->cursor_drag);
5562 sheet->cursor_drag = gdk_cursor_new (GDK_TOP_LEFT_ARROW);
5563 gdk_window_set_cursor (sheet->column_title_window,
5564 sheet->cursor_drag);
5569 if (event->window == sheet->row_title_window &&
5570 gtk_sheet_rows_resizable (sheet))
5572 gtk_widget_get_pointer (widget, &x, &y);
5573 if (!GTK_SHEET_IN_SELECTION (sheet) && POSSIBLE_YDRAG (sheet,y, &column))
5575 new_cursor = GDK_SB_V_DOUBLE_ARROW;
5576 if (new_cursor != sheet->cursor_drag->type)
5578 gdk_cursor_destroy (sheet->cursor_drag);
5579 sheet->cursor_drag = gdk_cursor_new (GDK_SB_V_DOUBLE_ARROW);
5580 gdk_window_set_cursor (sheet->row_title_window, sheet->cursor_drag);
5585 new_cursor = GDK_TOP_LEFT_ARROW;
5586 if (!GTK_SHEET_IN_YDRAG (sheet) &&
5587 new_cursor != sheet->cursor_drag->type)
5589 gdk_cursor_destroy (sheet->cursor_drag);
5590 sheet->cursor_drag = gdk_cursor_new (GDK_TOP_LEFT_ARROW);
5591 gdk_window_set_cursor (sheet->row_title_window, sheet->cursor_drag);
5596 new_cursor = GDK_PLUS;
5597 if ( event->window == sheet->sheet_window &&
5598 !POSSIBLE_DRAG (sheet, x, y, &row, &column) &&
5599 !GTK_SHEET_IN_DRAG (sheet) &&
5600 !POSSIBLE_RESIZE (sheet, x, y, &row, &column) &&
5601 !GTK_SHEET_IN_RESIZE (sheet) &&
5602 new_cursor != sheet->cursor_drag->type)
5604 gdk_cursor_destroy (sheet->cursor_drag);
5605 sheet->cursor_drag = gdk_cursor_new (GDK_PLUS);
5606 gdk_window_set_cursor (sheet->sheet_window, sheet->cursor_drag);
5609 new_cursor = GDK_TOP_LEFT_ARROW;
5610 if ( event->window == sheet->sheet_window &&
5611 ! (POSSIBLE_RESIZE (sheet,x,y,&row,&column) || GTK_SHEET_IN_RESIZE (sheet)) && (POSSIBLE_DRAG (sheet, x,y,&row,&column) || GTK_SHEET_IN_DRAG (sheet)) &&
5613 new_cursor != sheet->cursor_drag->type)
5615 gdk_cursor_destroy (sheet->cursor_drag);
5616 sheet->cursor_drag = gdk_cursor_new (GDK_TOP_LEFT_ARROW);
5617 gdk_window_set_cursor (sheet->sheet_window,sheet->cursor_drag);
5620 new_cursor = GDK_SIZING;
5621 if ( event->window == sheet->sheet_window &&
5622 sheet->selection_mode != GTK_SELECTION_NONE &&
5623 !GTK_SHEET_IN_DRAG (sheet) &&
5624 (POSSIBLE_RESIZE (sheet, x, y, &row, &column) ||
5625 GTK_SHEET_IN_RESIZE (sheet)) &&
5626 new_cursor != sheet->cursor_drag->type)
5628 gdk_cursor_destroy (sheet->cursor_drag);
5629 sheet->cursor_drag = gdk_cursor_new (GDK_SIZING);
5630 gdk_window_set_cursor (sheet->sheet_window,sheet->cursor_drag);
5634 gdk_window_get_pointer (widget->window, &x, &y, &mods);
5635 if (! (mods & GDK_BUTTON1_MASK)) return FALSE;
5637 if (GTK_SHEET_IN_XDRAG (sheet))
5639 if (event->is_hint || event->window != widget->window)
5640 gtk_widget_get_pointer (widget, &x, NULL);
5644 new_column_width (sheet, sheet->drag_cell.col, &x);
5645 if (x != sheet->x_drag)
5647 draw_xor_vline (sheet);
5649 draw_xor_vline (sheet);
5654 if (GTK_SHEET_IN_YDRAG (sheet))
5656 if (event->is_hint || event->window != widget->window)
5657 gtk_widget_get_pointer (widget, NULL, &y);
5661 new_row_height (sheet, sheet->drag_cell.row, &y);
5662 if (y != sheet->y_drag)
5664 draw_xor_hline (sheet);
5666 draw_xor_hline (sheet);
5671 if (GTK_SHEET_IN_DRAG (sheet))
5674 column = COLUMN_FROM_XPIXEL (sheet,x)- sheet->drag_cell.col;
5675 row = ROW_FROM_YPIXEL (sheet,y)- sheet->drag_cell.row;
5676 if (sheet->state == GTK_SHEET_COLUMN_SELECTED) row = 0;
5677 if (sheet->state == GTK_SHEET_ROW_SELECTED) column = 0;
5681 if (aux.row0 + row >= 0 && aux.rowi + row < yyy_row_count (sheet) &&
5682 aux.col0 + column >= 0 && aux.coli + column < xxx_column_count (sheet))
5684 aux = sheet->drag_range;
5685 sheet->drag_range.row0 = sheet->range.row0 + row;
5686 sheet->drag_range.col0 = sheet->range.col0 + column;
5687 sheet->drag_range.rowi = sheet->range.rowi + row;
5688 sheet->drag_range.coli = sheet->range.coli + column;
5689 if (aux.row0 != sheet->drag_range.row0 ||
5690 aux.col0 != sheet->drag_range.col0)
5692 draw_xor_rectangle (sheet, aux);
5693 draw_xor_rectangle (sheet, sheet->drag_range);
5699 if (GTK_SHEET_IN_RESIZE (sheet))
5702 gint v_h, current_col, current_row, col_threshold, row_threshold;
5705 if (abs (x - COLUMN_LEFT_XPIXEL (sheet,sheet->drag_cell.col)) >
5706 abs (y - ROW_TOP_YPIXEL (sheet,sheet->drag_cell.row))) v_h = 2;
5708 current_col = COLUMN_FROM_XPIXEL (sheet,x);
5709 current_row = ROW_FROM_YPIXEL (sheet,y);
5710 column = current_col - sheet->drag_cell.col;
5711 row = current_row - sheet->drag_cell.row;
5713 /*use half of column width resp. row height as threshold to
5715 col_threshold = COLUMN_LEFT_XPIXEL (sheet,current_col) +
5716 xxx_column_width (sheet,current_col) / 2;
5719 if (x < col_threshold)
5722 else if (column < 0)
5724 if (x > col_threshold)
5727 row_threshold = ROW_TOP_YPIXEL (sheet,current_row) +
5728 yyy_row_height (sheet, current_row)/2;
5731 if (y < row_threshold)
5736 if (y > row_threshold)
5740 if (sheet->state == GTK_SHEET_COLUMN_SELECTED) row = 0;
5741 if (sheet->state == GTK_SHEET_ROW_SELECTED) column = 0;
5751 if (aux.row0 + row >= 0 && aux.rowi + row < yyy_row_count (sheet) &&
5752 aux.col0 + column >= 0 && aux.coli + column < xxx_column_count (sheet))
5754 aux = sheet->drag_range;
5755 sheet->drag_range = sheet->range;
5757 if (row < 0) sheet->drag_range.row0 = sheet->range.row0 + row;
5758 if (row > 0) sheet->drag_range.rowi = sheet->range.rowi + row;
5759 if (column < 0) sheet->drag_range.col0 = sheet->range.col0 + column;
5760 if (column > 0) sheet->drag_range.coli = sheet->range.coli + column;
5762 if (aux.row0 != sheet->drag_range.row0 ||
5763 aux.rowi != sheet->drag_range.rowi ||
5764 aux.col0 != sheet->drag_range.col0 ||
5765 aux.coli != sheet->drag_range.coli)
5767 draw_xor_rectangle (sheet, aux);
5768 draw_xor_rectangle (sheet, sheet->drag_range);
5774 gtk_sheet_get_pixel_info (sheet, x, y, &row, &column);
5776 if (sheet->state == GTK_SHEET_NORMAL && row == sheet->active_cell.row &&
5777 column == sheet->active_cell.col) return TRUE;
5779 if (GTK_SHEET_IN_SELECTION (sheet) && mods&GDK_BUTTON1_MASK)
5780 gtk_sheet_extend_selection (sheet, row, column);
5786 gtk_sheet_move_query (GtkSheet *sheet, gint row, gint column)
5788 gint row_move, column_move;
5789 gfloat row_align, col_align;
5790 guint height, width;
5792 gint new_col = column;
5795 column_move = FALSE;
5799 height = sheet->sheet_window_height;
5800 width = sheet->sheet_window_width;
5802 if (row >= MAX_VISIBLE_ROW (sheet) && sheet->state != GTK_SHEET_COLUMN_SELECTED)
5805 new_row = MIN (yyy_row_count (sheet), row + 1);
5807 if (MAX_VISIBLE_ROW (sheet) == yyy_row_count (sheet) - 1 &&
5808 ROW_TOP_YPIXEL (sheet, yyy_row_count (sheet)- 1) +
5809 yyy_row_height (sheet, yyy_row_count (sheet)- 1) < height)
5815 if (row < MIN_VISIBLE_ROW (sheet) && sheet->state != GTK_SHEET_COLUMN_SELECTED)
5820 if (column >= MAX_VISIBLE_COLUMN (sheet) && sheet->state != GTK_SHEET_ROW_SELECTED)
5823 new_col = MIN (xxx_column_count (sheet) - 1, column + 1);
5825 if (MAX_VISIBLE_COLUMN (sheet) == (xxx_column_count (sheet) - 1) &&
5826 COLUMN_LEFT_XPIXEL (sheet, xxx_column_count (sheet) - 1) +
5827 xxx_column_width (sheet, xxx_column_count (sheet) - 1) < width)
5829 column_move = FALSE;
5833 if (column < MIN_VISIBLE_COLUMN (sheet) && sheet->state != GTK_SHEET_ROW_SELECTED)
5839 if (row_move || column_move)
5841 gtk_sheet_moveto (sheet, new_row, new_col, row_align, col_align);
5844 return (row_move || column_move);
5848 gtk_sheet_extend_selection (GtkSheet *sheet, gint row, gint column)
5850 GtkSheetRange range;
5854 if (row == sheet->selection_cell.row && column == sheet->selection_cell.col)
5857 if (sheet->selection_mode == GTK_SELECTION_SINGLE) return;
5859 gtk_sheet_move_query (sheet, row, column);
5860 gtk_widget_grab_focus (GTK_WIDGET (sheet));
5862 if (GTK_SHEET_IN_DRAG (sheet)) return;
5864 state = sheet->state;
5866 switch (sheet->state)
5868 case GTK_SHEET_ROW_SELECTED:
5869 column = xxx_column_count (sheet) - 1;
5871 case GTK_SHEET_COLUMN_SELECTED:
5872 row = yyy_row_count (sheet) - 1;
5874 case GTK_SHEET_NORMAL:
5875 sheet->state = GTK_SHEET_RANGE_SELECTED;
5876 r = sheet->active_cell.row;
5877 c = sheet->active_cell.col;
5878 sheet->range.col0 = c;
5879 sheet->range.row0 = r;
5880 sheet->range.coli = c;
5881 sheet->range.rowi = r;
5882 gdk_draw_pixmap (sheet->sheet_window,
5883 GTK_WIDGET (sheet)->style->fg_gc[GTK_STATE_NORMAL],
5885 COLUMN_LEFT_XPIXEL (sheet,c)- 1,
5886 ROW_TOP_YPIXEL (sheet,r)- 1,
5887 COLUMN_LEFT_XPIXEL (sheet,c)- 1,
5888 ROW_TOP_YPIXEL (sheet,r)- 1,
5889 xxx_column_width (sheet, c)+4,
5890 yyy_row_height (sheet, r)+4);
5891 gtk_sheet_range_draw_selection (sheet, sheet->range);
5892 case GTK_SHEET_RANGE_SELECTED:
5893 sheet->state = GTK_SHEET_RANGE_SELECTED;
5896 sheet->selection_cell.row = row;
5897 sheet->selection_cell.col = column;
5899 range.col0 = MIN (column,sheet->active_cell.col);
5900 range.coli = MAX (column,sheet->active_cell.col);
5901 range.row0 = MIN (row,sheet->active_cell.row);
5902 range.rowi = MAX (row,sheet->active_cell.row);
5904 if (range.row0 != sheet->range.row0 || range.rowi != sheet->range.rowi ||
5905 range.col0 != sheet->range.col0 || range.coli != sheet->range.coli ||
5906 state == GTK_SHEET_NORMAL)
5907 gtk_sheet_real_select_range (sheet, &range);
5912 gtk_sheet_entry_key_press (GtkWidget *widget,
5916 g_signal_emit_by_name (G_OBJECT (widget), "key_press_event", key, &focus);
5921 gtk_sheet_key_press (GtkWidget *widget,
5927 gboolean extend_selection = FALSE;
5928 gboolean force_move = FALSE;
5929 gboolean in_selection = FALSE;
5930 gboolean veto = TRUE;
5933 sheet = GTK_SHEET (widget);
5935 if (key->state & GDK_CONTROL_MASK || key->keyval == GDK_Control_L ||
5936 key->keyval == GDK_Control_R) return FALSE;
5938 extend_selection = (key->state & GDK_SHIFT_MASK) || key->keyval == GDK_Shift_L
5939 || key->keyval == GDK_Shift_R;
5941 state = sheet->state;
5942 in_selection = GTK_SHEET_IN_SELECTION (sheet);
5943 GTK_SHEET_UNSET_FLAGS (sheet, GTK_SHEET_IN_SELECTION);
5945 switch (key->keyval)
5947 case GDK_Return: case GDK_KP_Enter:
5948 if (sheet->state == GTK_SHEET_NORMAL &&
5949 !GTK_SHEET_IN_SELECTION (sheet))
5950 g_signal_stop_emission_by_name (gtk_sheet_get_entry (sheet),
5952 row = sheet->active_cell.row;
5953 col = sheet->active_cell.col;
5954 if (sheet->state == GTK_SHEET_COLUMN_SELECTED)
5955 row = MIN_VISIBLE_ROW (sheet)- 1;
5956 if (sheet->state == GTK_SHEET_ROW_SELECTED)
5957 col = MIN_VISIBLE_COLUMN (sheet);
5958 if (row < yyy_row_count (sheet) - 1)
5961 while (!yyy_row_is_visible (sheet, row) && row < yyy_row_count (sheet)- 1)
5964 gtk_sheet_click_cell (sheet, row, col, &veto);
5965 extend_selection = FALSE;
5967 case GDK_ISO_Left_Tab:
5968 row = sheet->active_cell.row;
5969 col = sheet->active_cell.col;
5970 if (sheet->state == GTK_SHEET_ROW_SELECTED)
5971 col = MIN_VISIBLE_COLUMN (sheet)- 1;
5972 if (sheet->state == GTK_SHEET_COLUMN_SELECTED)
5973 row = MIN_VISIBLE_ROW (sheet);
5977 while (! xxx_column_is_visible (sheet, col) && col > 0) col--;
5980 gtk_sheet_click_cell (sheet, row, col, &veto);
5981 extend_selection = FALSE;
5984 row = sheet->active_cell.row;
5985 col = sheet->active_cell.col;
5986 if (sheet->state == GTK_SHEET_ROW_SELECTED)
5987 col = MIN_VISIBLE_COLUMN (sheet)- 1;
5988 if (sheet->state == GTK_SHEET_COLUMN_SELECTED)
5989 row = MIN_VISIBLE_ROW (sheet);
5990 if (col < xxx_column_count (sheet) - 1)
5993 while (! xxx_column_is_visible (sheet, col) &&
5994 col < xxx_column_count (sheet) - 1)
5997 gtk_sheet_click_cell (sheet, row, col, &veto);
5998 extend_selection = FALSE;
6001 scroll = MAX_VISIBLE_ROW (sheet)- MIN_VISIBLE_ROW (sheet)+1;
6003 if (extend_selection)
6005 if (state == GTK_STATE_NORMAL)
6007 row = sheet->active_cell.row;
6008 col = sheet->active_cell.col;
6009 gtk_sheet_click_cell (sheet, row, col, &veto);
6012 if (sheet->selection_cell.row > 0)
6014 row = sheet->selection_cell.row - scroll;
6015 while (!yyy_row_is_visible (sheet, row) && row > 0) row--;
6017 gtk_sheet_extend_selection (sheet, row, sheet->selection_cell.col);
6021 col = sheet->active_cell.col;
6022 row = sheet->active_cell.row;
6023 if (state == GTK_SHEET_COLUMN_SELECTED)
6024 row = MIN_VISIBLE_ROW (sheet);
6025 if (state == GTK_SHEET_ROW_SELECTED)
6026 col = MIN_VISIBLE_COLUMN (sheet);
6028 while (!yyy_row_is_visible (sheet, row) && row > 0) row--;
6030 gtk_sheet_click_cell (sheet, row, col, &veto);
6031 extend_selection = FALSE;
6034 scroll = MAX_VISIBLE_ROW (sheet)- MIN_VISIBLE_ROW (sheet)+1;
6036 if (extend_selection)
6038 if (state == GTK_STATE_NORMAL)
6040 row = sheet->active_cell.row;
6041 col = sheet->active_cell.col;
6042 gtk_sheet_click_cell (sheet, row, col, &veto);
6045 if (sheet->selection_cell.row < yyy_row_count (sheet)- 1)
6047 row = sheet->selection_cell.row + scroll;
6048 while (!yyy_row_is_visible (sheet, row) && row < yyy_row_count (sheet)- 1) row++;
6049 row = MIN (yyy_row_count (sheet)- 1, row);
6050 gtk_sheet_extend_selection (sheet, row, sheet->selection_cell.col);
6054 col = sheet->active_cell.col;
6055 row = sheet->active_cell.row;
6056 if (sheet->active_cell.row < yyy_row_count (sheet)- 1)
6058 if (state == GTK_SHEET_COLUMN_SELECTED)
6059 row = MIN_VISIBLE_ROW (sheet)- 1;
6060 if (state == GTK_SHEET_ROW_SELECTED)
6061 col = MIN_VISIBLE_COLUMN (sheet);
6063 while (!yyy_row_is_visible (sheet, row) && row < yyy_row_count (sheet)- 1) row++;
6064 row = MIN (yyy_row_count (sheet)- 1, row);
6066 gtk_sheet_click_cell (sheet, row, col, &veto);
6067 extend_selection = FALSE;
6070 if (extend_selection)
6072 if (state == GTK_STATE_NORMAL)
6074 row = sheet->active_cell.row;
6075 col = sheet->active_cell.col;
6076 gtk_sheet_click_cell (sheet, row, col, &veto);
6079 if (sheet->selection_cell.col < xxx_column_count (sheet) - 1)
6081 col = sheet->selection_cell.col + 1;
6082 while (! xxx_column_is_visible (sheet, col) && col < xxx_column_count (sheet) - 1)
6084 gtk_sheet_extend_selection (sheet, sheet->selection_cell.row, col);
6088 col = sheet->active_cell.col;
6089 row = sheet->active_cell.row;
6090 if (sheet->active_cell.col < xxx_column_count (sheet) - 1)
6093 if (state == GTK_SHEET_ROW_SELECTED)
6094 col = MIN_VISIBLE_COLUMN (sheet)- 1;
6095 if (state == GTK_SHEET_COLUMN_SELECTED)
6096 row = MIN_VISIBLE_ROW (sheet);
6097 while (! xxx_column_is_visible (sheet, col) && col < xxx_column_count (sheet) - 1) col++;
6098 if (strlen (gtk_entry_get_text (GTK_ENTRY (gtk_sheet_get_entry (sheet)))) == 0
6101 gtk_sheet_click_cell (sheet, row, col, &veto);
6106 extend_selection = FALSE;
6109 if (extend_selection)
6111 if (state == GTK_STATE_NORMAL)
6113 row = sheet->active_cell.row;
6114 col = sheet->active_cell.col;
6115 gtk_sheet_click_cell (sheet, row, col, &veto);
6118 if (sheet->selection_cell.col > 0)
6120 col = sheet->selection_cell.col - 1;
6121 while (! xxx_column_is_visible (sheet, col) && col > 0) col--;
6122 gtk_sheet_extend_selection (sheet, sheet->selection_cell.row, col);
6126 col = sheet->active_cell.col - 1;
6127 row = sheet->active_cell.row;
6128 if (state == GTK_SHEET_ROW_SELECTED)
6129 col = MIN_VISIBLE_COLUMN (sheet)- 1;
6130 if (state == GTK_SHEET_COLUMN_SELECTED)
6131 row = MIN_VISIBLE_ROW (sheet);
6132 while (! xxx_column_is_visible (sheet, col) && col > 0) col--;
6135 if (strlen (gtk_entry_get_text (GTK_ENTRY (gtk_sheet_get_entry (sheet)))) == 0
6138 gtk_sheet_click_cell (sheet, row, col, &veto);
6142 extend_selection = FALSE;
6146 while (!yyy_row_is_visible (sheet, row) && row < yyy_row_count (sheet)- 1) row++;
6147 gtk_sheet_click_cell (sheet, row, sheet->active_cell.col, &veto);
6148 extend_selection = FALSE;
6151 row = yyy_row_count (sheet)- 1;
6152 while (!yyy_row_is_visible (sheet, row) && row > 0) row--;
6153 gtk_sheet_click_cell (sheet, row, sheet->active_cell.col, &veto);
6154 extend_selection = FALSE;
6159 GTK_SHEET_SET_FLAGS (sheet, GTK_SHEET_IN_SELECTION);
6160 if (extend_selection) return TRUE;
6162 if (state == GTK_SHEET_ROW_SELECTED)
6163 sheet->active_cell.col = MIN_VISIBLE_COLUMN (sheet);
6164 if (state == GTK_SHEET_COLUMN_SELECTED)
6165 sheet->active_cell.row = MIN_VISIBLE_ROW (sheet);
6169 if (extend_selection) return TRUE;
6171 gtk_sheet_activate_cell (sheet, sheet->active_cell.row,
6172 sheet->active_cell.col);
6178 gtk_sheet_size_request (GtkWidget * widget,
6179 GtkRequisition * requisition)
6183 GtkSheetChild *child;
6184 GtkRequisition child_requisition;
6186 g_return_if_fail (widget != NULL);
6187 g_return_if_fail (GTK_IS_SHEET (widget));
6188 g_return_if_fail (requisition != NULL);
6190 sheet = GTK_SHEET (widget);
6192 requisition->width = 3*DEFAULT_COLUMN_WIDTH;
6193 requisition->height = 3*DEFAULT_ROW_HEIGHT (widget);
6195 /* compute the size of the column title area */
6196 if (sheet->column_titles_visible)
6197 requisition->height += sheet->column_title_area.height;
6199 /* compute the size of the row title area */
6200 if (sheet->row_titles_visible)
6201 requisition->width += sheet->row_title_area.width;
6203 children = sheet->children;
6206 child = children->data;
6207 children = children->next;
6209 gtk_widget_size_request (child->widget, &child_requisition);
6215 gtk_sheet_size_allocate (GtkWidget * widget,
6216 GtkAllocation * allocation)
6219 GtkAllocation sheet_allocation;
6222 g_return_if_fail (widget != NULL);
6223 g_return_if_fail (GTK_IS_SHEET (widget));
6224 g_return_if_fail (allocation != NULL);
6226 sheet = GTK_SHEET (widget);
6227 widget->allocation = *allocation;
6228 border_width = GTK_CONTAINER (widget)->border_width;
6230 if (GTK_WIDGET_REALIZED (widget))
6231 gdk_window_move_resize (widget->window,
6232 allocation->x + border_width,
6233 allocation->y + border_width,
6234 allocation->width - 2 * border_width,
6235 allocation->height - 2 * border_width);
6237 /* use internal allocation structure for all the math
6238 * because it's easier than always subtracting the container
6240 sheet->internal_allocation.x = 0;
6241 sheet->internal_allocation.y = 0;
6242 sheet->internal_allocation.width = allocation->width - 2 * border_width;
6243 sheet->internal_allocation.height = allocation->height - 2 * border_width;
6245 sheet_allocation.x = 0;
6246 sheet_allocation.y = 0;
6247 sheet_allocation.width = allocation->width - 2 * border_width;
6248 sheet_allocation.height = allocation->height - 2 * border_width;
6250 sheet->sheet_window_width = sheet_allocation.width;
6251 sheet->sheet_window_height = sheet_allocation.height;
6253 if (GTK_WIDGET_REALIZED (widget))
6254 gdk_window_move_resize (sheet->sheet_window,
6257 sheet_allocation.width,
6258 sheet_allocation.height);
6260 /* position the window which holds the column title buttons */
6261 sheet->column_title_area.x = 0;
6262 sheet->column_title_area.y = 0;
6263 if (sheet->row_titles_visible)
6264 sheet->column_title_area.x = sheet->row_title_area.width;
6265 sheet->column_title_area.width = sheet_allocation.width -
6266 sheet->column_title_area.x;
6267 if (GTK_WIDGET_REALIZED (widget) && sheet->column_titles_visible)
6268 gdk_window_move_resize (sheet->column_title_window,
6269 sheet->column_title_area.x,
6270 sheet->column_title_area.y,
6271 sheet->column_title_area.width,
6272 sheet->column_title_area.height);
6274 sheet->sheet_window_width = sheet_allocation.width;
6275 sheet->sheet_window_height = sheet_allocation.height;
6277 /* column button allocation */
6278 size_allocate_column_title_buttons (sheet);
6280 /* position the window which holds the row title buttons */
6281 sheet->row_title_area.x = 0;
6282 sheet->row_title_area.y = 0;
6283 if (sheet->column_titles_visible)
6284 sheet->row_title_area.y = sheet->column_title_area.height;
6285 sheet->row_title_area.height = sheet_allocation.height -
6286 sheet->row_title_area.y;
6288 if (GTK_WIDGET_REALIZED (widget) && sheet->row_titles_visible)
6289 gdk_window_move_resize (sheet->row_title_window,
6290 sheet->row_title_area.x,
6291 sheet->row_title_area.y,
6292 sheet->row_title_area.width,
6293 sheet->row_title_area.height);
6296 /* row button allocation */
6297 size_allocate_row_title_buttons (sheet);
6298 size_allocate_column_title_buttons (sheet);
6300 /* re - scale backing pixmap */
6301 gtk_sheet_make_backing_pixmap (sheet, 0, 0);
6302 gtk_sheet_position_children (sheet);
6304 /* set the scrollbars adjustments */
6305 adjust_scrollbars (sheet);
6309 size_allocate_column_title_buttons (GtkSheet * sheet)
6314 if (!sheet->column_titles_visible) return;
6315 if (!GTK_WIDGET_REALIZED (sheet))
6318 width = sheet->sheet_window_width;
6321 if (sheet->row_titles_visible)
6323 width -= sheet->row_title_area.width;
6324 x = sheet->row_title_area.width;
6327 if (sheet->column_title_area.width != width || sheet->column_title_area.x != x)
6329 sheet->column_title_area.width = width;
6330 sheet->column_title_area.x = x;
6331 gdk_window_move_resize (sheet->column_title_window,
6332 sheet->column_title_area.x,
6333 sheet->column_title_area.y,
6334 sheet->column_title_area.width,
6335 sheet->column_title_area.height);
6339 if (MAX_VISIBLE_COLUMN (sheet) == xxx_column_count (sheet) - 1)
6340 gdk_window_clear_area (sheet->column_title_window,
6342 sheet->column_title_area.width,
6343 sheet->column_title_area.height);
6345 if (!GTK_WIDGET_DRAWABLE (sheet)) return;
6347 for (i = MIN_VISIBLE_COLUMN (sheet); i <= MAX_VISIBLE_COLUMN (sheet); i++)
6348 gtk_sheet_column_title_button_draw (sheet, i);
6352 size_allocate_row_title_buttons (GtkSheet * sheet)
6357 if (!sheet->row_titles_visible) return;
6358 if (!GTK_WIDGET_REALIZED (sheet))
6361 height = sheet->sheet_window_height;
6364 if (sheet->column_titles_visible)
6366 height -= sheet->column_title_area.height;
6367 y = sheet->column_title_area.height;
6370 if (sheet->row_title_area.height != height || sheet->row_title_area.y != y)
6372 sheet->row_title_area.y = y;
6373 sheet->row_title_area.height = height;
6374 gdk_window_move_resize (sheet->row_title_window,
6375 sheet->row_title_area.x,
6376 sheet->row_title_area.y,
6377 sheet->row_title_area.width,
6378 sheet->row_title_area.height);
6380 if (MAX_VISIBLE_ROW (sheet) == yyy_row_count (sheet)- 1)
6381 gdk_window_clear_area (sheet->row_title_window,
6383 sheet->row_title_area.width,
6384 sheet->row_title_area.height);
6386 if (!GTK_WIDGET_DRAWABLE (sheet)) return;
6388 for (i = MIN_VISIBLE_ROW (sheet); i <= MAX_VISIBLE_ROW (sheet); i++)
6390 if ( i >= yyy_row_count (sheet))
6392 gtk_sheet_row_title_button_draw (sheet, i);
6398 gtk_sheet_size_allocate_entry (GtkSheet *sheet)
6400 GtkAllocation shentry_allocation;
6401 GtkSheetCellAttr attributes = { 0 };
6402 GtkEntry *sheet_entry;
6403 GtkStyle *style = NULL, *previous_style = NULL;
6405 gint size, max_size, text_size, column_width;
6408 if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) return;
6409 if (!GTK_WIDGET_MAPPED (GTK_WIDGET (sheet))) return;
6411 sheet_entry = GTK_ENTRY (gtk_sheet_get_entry (sheet));
6413 if ( ! gtk_sheet_get_attributes (sheet, sheet->active_cell.row,
6414 sheet->active_cell.col,
6418 if ( GTK_WIDGET_REALIZED (sheet->sheet_entry) )
6420 if (!GTK_WIDGET (sheet_entry)->style)
6421 gtk_widget_ensure_style (GTK_WIDGET (sheet_entry));
6423 previous_style = GTK_WIDGET (sheet_entry)->style;
6425 style = gtk_style_copy (previous_style);
6426 style->bg[GTK_STATE_NORMAL] = attributes.background;
6427 style->fg[GTK_STATE_NORMAL] = attributes.foreground;
6428 style->text[GTK_STATE_NORMAL] = attributes.foreground;
6429 style->bg[GTK_STATE_ACTIVE] = attributes.background;
6430 style->fg[GTK_STATE_ACTIVE] = attributes.foreground;
6431 style->text[GTK_STATE_ACTIVE] = attributes.foreground;
6433 pango_font_description_free (style->font_desc);
6434 g_assert (attributes.font_desc);
6435 style->font_desc = pango_font_description_copy (attributes.font_desc);
6437 GTK_WIDGET (sheet_entry)->style = style;
6438 gtk_widget_size_request (sheet->sheet_entry, NULL);
6439 GTK_WIDGET (sheet_entry)->style = previous_style;
6441 if (style != previous_style)
6443 if (!GTK_IS_ITEM_ENTRY (sheet->sheet_entry))
6445 style->bg[GTK_STATE_NORMAL] = previous_style->bg[GTK_STATE_NORMAL];
6446 style->fg[GTK_STATE_NORMAL] = previous_style->fg[GTK_STATE_NORMAL];
6447 style->bg[GTK_STATE_ACTIVE] = previous_style->bg[GTK_STATE_ACTIVE];
6448 style->fg[GTK_STATE_ACTIVE] = previous_style->fg[GTK_STATE_ACTIVE];
6450 gtk_widget_set_style (GTK_WIDGET (sheet_entry), style);
6454 if (GTK_IS_ITEM_ENTRY (sheet_entry))
6455 max_size = GTK_ITEM_ENTRY (sheet_entry)->text_max_size;
6460 text = gtk_entry_get_text (GTK_ENTRY (sheet_entry));
6461 if (text && strlen (text) > 0)
6462 text_size = STRING_WIDTH (GTK_WIDGET (sheet), attributes.font_desc, text);
6464 column_width = xxx_column_width (sheet, sheet->active_cell.col);
6466 size = MIN (text_size, max_size);
6467 size = MAX (size,column_width - 2 * CELLOFFSET);
6469 row = sheet->active_cell.row;
6470 col = sheet->active_cell.col;
6472 shentry_allocation.x = COLUMN_LEFT_XPIXEL (sheet,sheet->active_cell.col);
6473 shentry_allocation.y = ROW_TOP_YPIXEL (sheet,sheet->active_cell.row);
6474 shentry_allocation.width = column_width;
6475 shentry_allocation.height = yyy_row_height (sheet, sheet->active_cell.row);
6477 if (GTK_IS_ITEM_ENTRY (sheet->sheet_entry))
6479 shentry_allocation.height -= 2 * CELLOFFSET;
6480 shentry_allocation.y += CELLOFFSET;
6481 if (gtk_sheet_clip_text (sheet))
6482 shentry_allocation.width = column_width - 2 * CELLOFFSET;
6484 shentry_allocation.width = size;
6486 switch (GTK_ITEM_ENTRY (sheet_entry)->justification)
6488 case GTK_JUSTIFY_CENTER:
6489 shentry_allocation.x += column_width / 2 - size / 2;
6491 case GTK_JUSTIFY_RIGHT:
6492 shentry_allocation.x += column_width - size - CELLOFFSET;
6494 case GTK_JUSTIFY_LEFT:
6495 case GTK_JUSTIFY_FILL:
6496 shentry_allocation.x += CELLOFFSET;
6501 if (!GTK_IS_ITEM_ENTRY (sheet->sheet_entry))
6503 shentry_allocation.x += 2;
6504 shentry_allocation.y += 2;
6505 shentry_allocation.width -= MIN (shentry_allocation.width, 3);
6506 shentry_allocation.height -= MIN (shentry_allocation.height, 3);
6509 gtk_widget_size_allocate (sheet->sheet_entry, &shentry_allocation);
6511 if (previous_style == style) g_object_unref (previous_style);
6515 gtk_sheet_entry_set_max_size (GtkSheet *sheet)
6519 gint sizel = 0, sizer = 0;
6521 GtkJustification justification;
6524 row = sheet->active_cell.row;
6525 col = sheet->active_cell.col;
6527 if ( ! GTK_IS_ITEM_ENTRY (sheet->sheet_entry) || gtk_sheet_clip_text (sheet))
6530 justification = GTK_ITEM_ENTRY (sheet->sheet_entry)->justification;
6532 switch (justification)
6534 case GTK_JUSTIFY_FILL:
6535 case GTK_JUSTIFY_LEFT:
6536 for (i = col + 1; i <= MAX_VISIBLE_COLUMN (sheet); i++)
6538 if ((s = gtk_sheet_cell_get_text (sheet, row, i)))
6543 size +=xxx_column_width (sheet, i);
6545 size = MIN (size, sheet->sheet_window_width - COLUMN_LEFT_XPIXEL (sheet, col));
6547 case GTK_JUSTIFY_RIGHT:
6548 for (i = col - 1; i >= MIN_VISIBLE_COLUMN (sheet); i--)
6550 if ((s = gtk_sheet_cell_get_text (sheet, row, i)))
6555 size +=xxx_column_width (sheet, i);
6558 case GTK_JUSTIFY_CENTER:
6559 for (i = col + 1; i <= MAX_VISIBLE_COLUMN (sheet); i++)
6561 sizer += xxx_column_width (sheet, i);
6563 for (i = col - 1; i >= MIN_VISIBLE_COLUMN (sheet); i--)
6565 if ((s = gtk_sheet_cell_get_text (sheet, row, i)))
6570 sizel +=xxx_column_width (sheet, i);
6572 size = 2 * MIN (sizel, sizer);
6577 size += xxx_column_width (sheet, col);
6578 GTK_ITEM_ENTRY (sheet->sheet_entry)->text_max_size = size;
6583 create_sheet_entry (GtkSheet *sheet)
6588 gint found_entry = FALSE;
6590 widget = GTK_WIDGET (sheet);
6592 if (sheet->sheet_entry)
6594 /* avoids warnings */
6595 gtk_widget_ref (sheet->sheet_entry);
6596 gtk_widget_unparent (sheet->sheet_entry);
6597 gtk_widget_destroy (sheet->sheet_entry);
6600 if (sheet->entry_type)
6602 if (!g_type_is_a (sheet->entry_type, GTK_TYPE_ENTRY))
6604 parent = g_object_new (sheet->entry_type, NULL);
6606 sheet->sheet_entry = parent;
6608 entry = gtk_sheet_get_entry (sheet);
6609 if (GTK_IS_ENTRY (entry))
6614 parent = g_object_new (sheet->entry_type, NULL);
6621 g_warning ("Entry type must be GtkEntry subclass, using default");
6622 entry = gtk_item_entry_new ();
6623 sheet->sheet_entry = entry;
6626 sheet->sheet_entry = parent;
6630 entry = gtk_item_entry_new ();
6631 sheet->sheet_entry = entry;
6634 gtk_widget_size_request (sheet->sheet_entry, NULL);
6636 if (GTK_WIDGET_REALIZED (sheet))
6638 gtk_widget_set_parent_window (sheet->sheet_entry, sheet->sheet_window);
6639 gtk_widget_set_parent (sheet->sheet_entry, GTK_WIDGET (sheet));
6640 gtk_widget_realize (sheet->sheet_entry);
6643 g_signal_connect_swapped (G_OBJECT (entry), "key_press_event",
6644 G_CALLBACK (gtk_sheet_entry_key_press),
6647 gtk_widget_show (sheet->sheet_entry);
6651 /* Finds the last child widget that happens to be of type GtkEntry */
6653 find_entry (GtkWidget *w, gpointer user_data)
6655 GtkWidget **entry = user_data;
6656 if ( GTK_IS_ENTRY (w))
6663 gtk_sheet_get_entry (GtkSheet *sheet)
6666 GtkWidget *entry = NULL;
6667 GtkTableChild *table_child;
6668 GtkBoxChild *box_child;
6669 GList *children = NULL;
6671 g_return_val_if_fail (sheet != NULL, NULL);
6672 g_return_val_if_fail (GTK_IS_SHEET (sheet), NULL);
6673 g_return_val_if_fail (sheet->sheet_entry != NULL, NULL);
6675 if (GTK_IS_ENTRY (sheet->sheet_entry)) return (sheet->sheet_entry);
6677 parent = GTK_WIDGET (sheet->sheet_entry);
6679 if (GTK_IS_TABLE (parent)) children = GTK_TABLE (parent)->children;
6680 if (GTK_IS_BOX (parent)) children = GTK_BOX (parent)->children;
6682 if (GTK_IS_CONTAINER (parent))
6684 gtk_container_forall (GTK_CONTAINER (parent), find_entry, &entry);
6686 if (GTK_IS_ENTRY (entry))
6690 if (!children) return NULL;
6694 if (GTK_IS_TABLE (parent))
6696 table_child = children->data;
6697 entry = table_child->widget;
6699 if (GTK_IS_BOX (parent))
6701 box_child = children->data;
6702 entry = box_child->widget;
6705 if (GTK_IS_ENTRY (entry))
6707 children = children->next;
6711 if (!GTK_IS_ENTRY (entry)) return NULL;
6718 gtk_sheet_get_entry_widget (GtkSheet *sheet)
6720 g_return_val_if_fail (sheet != NULL, NULL);
6721 g_return_val_if_fail (GTK_IS_SHEET (sheet), NULL);
6722 g_return_val_if_fail (sheet->sheet_entry != NULL, NULL);
6724 return (sheet->sheet_entry);
6729 gtk_sheet_button_draw (GtkSheet *sheet, GdkWindow *window,
6730 GtkSheetButton *button, gboolean is_sensitive,
6731 GdkRectangle allocation)
6733 GtkShadowType shadow_type;
6734 gint text_width = 0, text_height = 0;
6735 GtkSheetChild *child = NULL;
6736 PangoAlignment align = PANGO_ALIGN_LEFT;
6744 g_return_if_fail (sheet != NULL);
6745 g_return_if_fail (button != NULL);
6747 rtl = gtk_widget_get_direction (GTK_WIDGET (sheet)) == GTK_TEXT_DIR_RTL;
6749 gdk_window_clear_area (window,
6750 allocation.x, allocation.y,
6751 allocation.width, allocation.height);
6753 gtk_paint_box (sheet->button->style, window,
6754 GTK_STATE_NORMAL, GTK_SHADOW_OUT,
6755 &allocation, GTK_WIDGET (sheet->button),
6757 allocation.x, allocation.y,
6758 allocation.width, allocation.height);
6760 state = button->state;
6761 if (!is_sensitive) state = GTK_STATE_INSENSITIVE;
6763 if (state == GTK_STATE_ACTIVE)
6764 shadow_type = GTK_SHADOW_IN;
6766 shadow_type = GTK_SHADOW_OUT;
6768 if (state != GTK_STATE_NORMAL && state != GTK_STATE_INSENSITIVE)
6769 gtk_paint_box (sheet->button->style, window,
6770 button->state, shadow_type,
6771 &allocation, GTK_WIDGET (sheet->button),
6773 allocation.x, allocation.y,
6774 allocation.width, allocation.height);
6776 if (button->label_visible)
6779 text_height = DEFAULT_ROW_HEIGHT (GTK_WIDGET (sheet))- 2 * CELLOFFSET;
6781 gdk_gc_set_clip_rectangle (GTK_WIDGET (sheet)->style->fg_gc[button->state],
6783 gdk_gc_set_clip_rectangle (GTK_WIDGET (sheet)->style->white_gc, &allocation);
6785 allocation.y += 2 * sheet->button->style->ythickness;
6788 if (button->label && strlen (button->label)>0)
6791 PangoLayout *layout = NULL;
6792 gint real_x = allocation.x, real_y = allocation.y;
6794 words = button->label;
6795 line = g_new (gchar, 1);
6798 while (words && *words != '\0')
6802 len = strlen (line);
6803 line = g_realloc (line, len + 2);
6807 if (*words == '\n' || * (words + 1) == '\0')
6809 text_width = STRING_WIDTH (GTK_WIDGET (sheet), GTK_WIDGET (sheet)->style->font_desc, line);
6811 layout = gtk_widget_create_pango_layout (GTK_WIDGET (sheet), line);
6812 switch (button->justification)
6814 case GTK_JUSTIFY_LEFT:
6815 real_x = allocation.x + CELLOFFSET;
6816 align = rtl ? PANGO_ALIGN_RIGHT : PANGO_ALIGN_LEFT;
6818 case GTK_JUSTIFY_RIGHT:
6819 real_x = allocation.x + allocation.width - text_width - CELLOFFSET;
6820 align = rtl ? PANGO_ALIGN_LEFT : PANGO_ALIGN_RIGHT;
6822 case GTK_JUSTIFY_CENTER:
6824 real_x = allocation.x + (allocation.width - text_width)/2;
6825 align = rtl ? PANGO_ALIGN_RIGHT : PANGO_ALIGN_LEFT;
6826 pango_layout_set_justify (layout, TRUE);
6828 pango_layout_set_alignment (layout, align);
6829 gtk_paint_layout (GTK_WIDGET (sheet)->style,
6838 g_object_unref (G_OBJECT (layout));
6840 real_y += text_height + 2;
6843 line = g_new (gchar, 1);
6851 gdk_gc_set_clip_rectangle (GTK_WIDGET (sheet)->style->fg_gc[button->state],
6853 gdk_gc_set_clip_rectangle (GTK_WIDGET (sheet)->style->white_gc, NULL);
6857 if ((child = button->child) && (child->widget))
6859 child->x = allocation.x;
6860 child->y = allocation.y;
6862 child->x += (allocation.width - child->widget->requisition.width) / 2;
6863 child->y += (allocation.height - child->widget->requisition.height) / 2;
6864 allocation.x = child->x;
6865 allocation.y = child->y;
6866 allocation.width = child->widget->requisition.width;
6867 allocation.height = child->widget->requisition.height;
6869 allocation.x = child->x;
6870 allocation.y = child->y;
6872 gtk_widget_set_state (child->widget, button->state);
6874 if (GTK_WIDGET_REALIZED (GTK_WIDGET (sheet)) &&
6875 GTK_WIDGET_MAPPED (child->widget))
6877 gtk_widget_size_allocate (child->widget,
6879 gtk_widget_queue_draw (child->widget);
6883 gtk_sheet_button_free (button);
6887 /* COLUMN value of - 1 indicates that the area to the right of the rightmost
6888 button should be redrawn */
6890 gtk_sheet_column_title_button_draw (GtkSheet *sheet, gint column)
6892 GdkWindow *window = NULL;
6893 GdkRectangle allocation;
6894 GtkSheetButton *button = NULL;
6895 gboolean is_sensitive = FALSE;
6897 if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) return;
6899 if (column >= 0 && ! xxx_column_is_visible (sheet, column)) return;
6900 if (column >= 0 && !sheet->column_titles_visible) return;
6901 if (column >= 0 && column < MIN_VISIBLE_COLUMN (sheet)) return;
6902 if (column >= 0 && column > MAX_VISIBLE_COLUMN (sheet)) return;
6904 window = sheet->column_title_window;
6906 allocation.height = sheet->column_title_area.height;
6910 const gint cols = xxx_column_count (sheet) ;
6911 allocation.x = COLUMN_LEFT_XPIXEL (sheet, cols - 1)
6913 allocation.width = sheet->column_title_area.width
6914 + sheet->column_title_area.x
6917 gdk_window_clear_area (window,
6918 allocation.x, allocation.y,
6919 allocation.width, allocation.height);
6923 button = xxx_column_button (sheet, column);
6924 allocation.x = COLUMN_LEFT_XPIXEL (sheet, column) + CELL_SPACING;
6925 if (sheet->row_titles_visible)
6926 allocation.x -= sheet->row_title_area.width;
6928 allocation.width = xxx_column_width (sheet, column);
6930 is_sensitive = xxx_column_is_sensitive (sheet, column);
6931 gtk_sheet_button_draw (sheet, window, button,
6932 is_sensitive, allocation);
6937 gtk_sheet_row_title_button_draw (GtkSheet *sheet, gint row)
6939 GdkWindow *window = NULL;
6940 GdkRectangle allocation;
6941 GtkSheetButton *button = NULL;
6942 gboolean is_sensitive = FALSE;
6945 if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) return;
6947 if (row >= 0 && !yyy_row_is_visible (sheet, row)) return;
6948 if (row >= 0 && !sheet->row_titles_visible) return;
6949 if (row >= 0 && row < MIN_VISIBLE_ROW (sheet)) return;
6950 if (row >= 0 && row > MAX_VISIBLE_ROW (sheet)) return;
6953 window = sheet->row_title_window;
6954 button = yyy_row_button (sheet, row);
6956 allocation.y = ROW_TOP_YPIXEL (sheet, row) + CELL_SPACING;
6957 if (sheet->column_titles_visible)
6958 allocation.y -= sheet->column_title_area.height;
6959 allocation.width = sheet->row_title_area.width;
6960 allocation.height = yyy_row_height (sheet, row);
6961 is_sensitive = yyy_row_is_sensitive (sheet, row);
6963 gtk_sheet_button_draw (sheet, window, button, is_sensitive, allocation);
6970 * vadjustment_value_changed
6971 * hadjustment_value_changed */
6974 adjust_scrollbars (GtkSheet * sheet)
6976 if (sheet->vadjustment)
6978 sheet->vadjustment->page_size = sheet->sheet_window_height;
6979 sheet->vadjustment->page_increment = sheet->sheet_window_height / 2;
6980 sheet->vadjustment->step_increment = DEFAULT_ROW_HEIGHT (GTK_WIDGET (sheet));
6981 sheet->vadjustment->lower = 0;
6982 sheet->vadjustment->upper = SHEET_HEIGHT (sheet) + 80;
6983 g_signal_emit_by_name (G_OBJECT (sheet->vadjustment), "changed");
6987 if (sheet->hadjustment)
6989 sheet->hadjustment->page_size = sheet->sheet_window_width;
6990 sheet->hadjustment->page_increment = sheet->sheet_window_width / 2;
6991 sheet->hadjustment->step_increment = DEFAULT_COLUMN_WIDTH;
6992 sheet->hadjustment->lower = 0;
6993 sheet->hadjustment->upper = SHEET_WIDTH (sheet)+ 80;
6994 g_signal_emit_by_name (G_OBJECT (sheet->hadjustment), "changed");
7000 vadjustment_value_changed (GtkAdjustment * adjustment,
7004 gint diff, value, old_value;
7008 g_return_if_fail (adjustment != NULL);
7009 g_return_if_fail (data != NULL);
7010 g_return_if_fail (GTK_IS_SHEET (data));
7012 sheet = GTK_SHEET (data);
7014 if (GTK_SHEET_IS_FROZEN (sheet)) return;
7016 row = ROW_FROM_YPIXEL (sheet,sheet->column_title_area.height + CELL_SPACING);
7017 if (!sheet->column_titles_visible)
7018 row = ROW_FROM_YPIXEL (sheet, CELL_SPACING);
7020 old_value = - sheet->voffset;
7022 new_row = g_sheet_row_pixel_to_row (sheet->row_geometry,
7023 adjustment->value,sheet);
7025 y = g_sheet_row_start_pixel (sheet->row_geometry, new_row, sheet);
7027 if (adjustment->value > sheet->old_vadjustment && sheet->old_vadjustment > 0. &&
7028 yyy_row_height (sheet, row) > sheet->vadjustment->step_increment)
7030 /* This avoids embarrassing twitching */
7031 if (row == new_row && row != yyy_row_count (sheet) - 1 &&
7032 adjustment->value - sheet->old_vadjustment >=
7033 sheet->vadjustment->step_increment &&
7034 new_row + 1 != MIN_VISIBLE_ROW (sheet))
7037 y = y+yyy_row_height (sheet, row);
7041 /* Negative old_adjustment enforces the redraw, otherwise avoid
7043 if (sheet->old_vadjustment >= 0. && row == new_row)
7045 sheet->old_vadjustment = sheet->vadjustment->value;
7049 sheet->old_vadjustment = sheet->vadjustment->value;
7050 adjustment->value = y;
7055 sheet->vadjustment->step_increment = yyy_row_height (sheet, 0);
7059 sheet->vadjustment->step_increment =
7060 MIN (yyy_row_height (sheet, new_row), yyy_row_height (sheet, new_row - 1));
7063 sheet->vadjustment->value = adjustment->value;
7065 value = adjustment->value;
7067 if (value >= - sheet->voffset)
7070 diff = value + sheet->voffset;
7075 diff = - sheet->voffset - value;
7078 sheet->voffset = - value;
7080 if (GTK_WIDGET_REALIZED (sheet->sheet_entry) &&
7081 sheet->state == GTK_SHEET_NORMAL &&
7082 sheet->active_cell.row >= 0 && sheet->active_cell.col >= 0 &&
7083 !gtk_sheet_cell_isvisible (sheet, sheet->active_cell.row,
7084 sheet->active_cell.col))
7088 text = gtk_entry_get_text (GTK_ENTRY (gtk_sheet_get_entry (sheet)));
7090 if (!text || strlen (text) == 0)
7091 gtk_sheet_cell_clear (sheet,
7092 sheet->active_cell.row,
7093 sheet->active_cell.col);
7094 gtk_widget_unmap (sheet->sheet_entry);
7097 gtk_sheet_position_children (sheet);
7099 gtk_sheet_range_draw (sheet, NULL);
7100 size_allocate_row_title_buttons (sheet);
7101 size_allocate_global_button (sheet);
7105 hadjustment_value_changed (GtkAdjustment * adjustment,
7109 gint i, diff, value, old_value;
7110 gint column, new_column;
7113 g_return_if_fail (adjustment != NULL);
7114 g_return_if_fail (data != NULL);
7115 g_return_if_fail (GTK_IS_SHEET (data));
7117 sheet = GTK_SHEET (data);
7119 if (GTK_SHEET_IS_FROZEN (sheet)) return;
7121 column = COLUMN_FROM_XPIXEL (sheet,sheet->row_title_area.width + CELL_SPACING);
7122 if (!sheet->row_titles_visible)
7123 column = COLUMN_FROM_XPIXEL (sheet, CELL_SPACING);
7125 old_value = - sheet->hoffset;
7127 for (i = 0; i < xxx_column_count (sheet); i++)
7129 if (xxx_column_is_visible (sheet, i)) x += xxx_column_width (sheet, i);
7130 if (x > adjustment->value) break;
7132 x -= xxx_column_width (sheet, i);
7135 if (adjustment->value > sheet->old_hadjustment && sheet->old_hadjustment > 0 &&
7136 xxx_column_width (sheet, i) > sheet->hadjustment->step_increment)
7138 /* This avoids embarrassing twitching */
7139 if (column == new_column && column != xxx_column_count (sheet) - 1 &&
7140 adjustment->value - sheet->old_hadjustment >=
7141 sheet->hadjustment->step_increment &&
7142 new_column + 1 != MIN_VISIBLE_COLUMN (sheet))
7145 x += xxx_column_width (sheet, column);
7149 /* Negative old_adjustment enforces the redraw, otherwise avoid spureous redraw */
7150 if (sheet->old_hadjustment >= 0. && new_column == column)
7152 sheet->old_hadjustment = sheet->hadjustment->value;
7156 sheet->old_hadjustment = sheet->hadjustment->value;
7157 adjustment->value = x;
7159 if (new_column == 0)
7161 sheet->hadjustment->step_increment = xxx_column_width (sheet, 0);
7165 sheet->hadjustment->step_increment =
7166 MIN (xxx_column_width (sheet, new_column), xxx_column_width (sheet, new_column - 1));
7170 sheet->hadjustment->value = adjustment->value;
7172 value = adjustment->value;
7174 if (value >= - sheet->hoffset)
7177 diff = value + sheet->hoffset;
7182 diff = - sheet->hoffset - value;
7185 sheet->hoffset = - value;
7186 if (GTK_WIDGET_REALIZED (sheet->sheet_entry) &&
7187 sheet->state == GTK_SHEET_NORMAL &&
7188 sheet->active_cell.row >= 0 && sheet->active_cell.col >= 0 &&
7189 !gtk_sheet_cell_isvisible (sheet, sheet->active_cell.row,
7190 sheet->active_cell.col))
7194 text = gtk_entry_get_text (GTK_ENTRY (gtk_sheet_get_entry (sheet)));
7195 if (!text || strlen (text) == 0)
7196 gtk_sheet_cell_clear (sheet,
7197 sheet->active_cell.row,
7198 sheet->active_cell.col);
7200 gtk_widget_unmap (sheet->sheet_entry);
7203 gtk_sheet_position_children (sheet);
7205 gtk_sheet_range_draw (sheet, NULL);
7206 size_allocate_column_title_buttons (sheet);
7210 /* COLUMN RESIZING */
7212 draw_xor_vline (GtkSheet * sheet)
7216 g_return_if_fail (sheet != NULL);
7218 widget = GTK_WIDGET (sheet);
7220 gdk_draw_line (widget->window, sheet->xor_gc,
7222 sheet->column_title_area.height,
7224 sheet->sheet_window_height + 1);
7229 draw_xor_hline (GtkSheet * sheet)
7233 g_return_if_fail (sheet != NULL);
7235 widget = GTK_WIDGET (sheet);
7237 gdk_draw_line (widget->window, sheet->xor_gc,
7238 sheet->row_title_area.width,
7241 sheet->sheet_window_width + 1,
7245 /* SELECTED RANGE */
7247 draw_xor_rectangle (GtkSheet *sheet, GtkSheetRange range)
7250 GdkRectangle clip_area, area;
7253 area.x = COLUMN_LEFT_XPIXEL (sheet, range.col0);
7254 area.y = ROW_TOP_YPIXEL (sheet, range.row0);
7255 area.width = COLUMN_LEFT_XPIXEL (sheet, range.coli)- area.x+
7256 xxx_column_width (sheet, range.coli);
7257 area.height = ROW_TOP_YPIXEL (sheet, range.rowi)- area.y+
7258 yyy_row_height (sheet, range.rowi);
7260 clip_area.x = sheet->row_title_area.width;
7261 clip_area.y = sheet->column_title_area.height;
7262 clip_area.width = sheet->sheet_window_width;
7263 clip_area.height = sheet->sheet_window_height;
7265 if (!sheet->row_titles_visible) clip_area.x = 0;
7266 if (!sheet->column_titles_visible) clip_area.y = 0;
7270 area.width = area.width + area.x;
7273 if (area.width > clip_area.width) area.width = clip_area.width + 10;
7276 area.height = area.height + area.y;
7279 if (area.height > clip_area.height) area.height = clip_area.height + 10;
7283 clip_area.width += 3;
7284 clip_area.height += 3;
7286 gdk_gc_get_values (sheet->xor_gc, &values);
7288 gdk_gc_set_clip_rectangle (sheet->xor_gc, &clip_area);
7290 for (i =- 1; i <= 1; ++i)
7291 gdk_draw_rectangle (sheet->sheet_window,
7294 area.x + i, area.y + i,
7295 area.width - 2 * i, area.height - 2 * i);
7298 gdk_gc_set_clip_rectangle (sheet->xor_gc, NULL);
7300 gdk_gc_set_foreground (sheet->xor_gc, &values.foreground);
7305 /* this function returns the new width of the column being resized given
7306 * the column and x position of the cursor; the x cursor position is passed
7307 * in as a pointer and automaticaly corrected if it's beyond min / max limits */
7309 new_column_width (GtkSheet * sheet,
7318 min_width = sheet->column_requisition;
7320 /* you can't shrink a column to less than its minimum width */
7321 if (cx < COLUMN_LEFT_XPIXEL (sheet, column) + min_width)
7323 *x = cx = COLUMN_LEFT_XPIXEL (sheet, column) + min_width;
7326 /* calculate new column width making sure it doesn't end up
7327 * less than the minimum width */
7328 width = cx - COLUMN_LEFT_XPIXEL (sheet, column);
7329 if (width < min_width)
7332 xxx_set_column_width (sheet, column, width);
7333 size_allocate_column_title_buttons (sheet);
7338 /* this function returns the new height of the row being resized given
7339 * the row and y position of the cursor; the y cursor position is passed
7340 * in as a pointer and automaticaly corrected if it's beyond min / max limits */
7342 new_row_height (GtkSheet * sheet,
7350 min_height = sheet->row_requisition;
7352 /* you can't shrink a row to less than its minimum height */
7353 if (cy < ROW_TOP_YPIXEL (sheet, row) + min_height)
7356 *y = cy = ROW_TOP_YPIXEL (sheet, row) + min_height;
7359 /* calculate new row height making sure it doesn't end up
7360 * less than the minimum height */
7361 height = (cy - ROW_TOP_YPIXEL (sheet, row));
7362 if (height < min_height)
7363 height = min_height;
7365 yyy_set_row_height (sheet, row, height);
7366 size_allocate_row_title_buttons (sheet);
7372 gtk_sheet_set_column_width (GtkSheet * sheet,
7378 g_return_if_fail (sheet != NULL);
7379 g_return_if_fail (GTK_IS_SHEET (sheet));
7381 if (column < 0 || column >= xxx_column_count (sheet))
7384 gtk_sheet_column_size_request (sheet, column, &min_width);
7385 if (width < min_width) return;
7387 xxx_set_column_width (sheet, column, width);
7389 if (GTK_WIDGET_REALIZED (GTK_WIDGET (sheet)) && !GTK_SHEET_IS_FROZEN (sheet))
7391 size_allocate_column_title_buttons (sheet);
7392 adjust_scrollbars (sheet);
7393 gtk_sheet_size_allocate_entry (sheet);
7394 gtk_sheet_range_draw (sheet, NULL);
7397 g_signal_emit (G_OBJECT (sheet), sheet_signals[CHANGED], 0, -1, column);
7398 g_signal_emit (G_OBJECT (sheet), sheet_signals[NEW_COL_WIDTH], 0,
7405 gtk_sheet_set_row_height (GtkSheet * sheet,
7411 g_return_if_fail (sheet != NULL);
7412 g_return_if_fail (GTK_IS_SHEET (sheet));
7414 if (row < 0 || row >= yyy_row_count (sheet))
7417 gtk_sheet_row_size_request (sheet, row, &min_height);
7418 if (height < min_height) return;
7420 yyy_set_row_height (sheet, row, height);
7422 if (GTK_WIDGET_REALIZED (GTK_WIDGET (sheet)) && !GTK_SHEET_IS_FROZEN (sheet))
7424 size_allocate_row_title_buttons (sheet);
7425 adjust_scrollbars (sheet);
7426 gtk_sheet_size_allocate_entry (sheet);
7427 gtk_sheet_range_draw (sheet, NULL);
7430 g_signal_emit (G_OBJECT (sheet), sheet_signals[CHANGED], 0, row, - 1);
7431 g_signal_emit (G_OBJECT (sheet), sheet_signals[NEW_ROW_HEIGHT], 0,
7438 gtk_sheet_get_attributes (const GtkSheet *sheet, gint row, gint col,
7439 GtkSheetCellAttr *attributes)
7441 const GdkColor *fg, *bg;
7442 const GtkJustification *j ;
7443 const PangoFontDescription *font_desc ;
7444 const GtkSheetCellBorder *border ;
7446 g_return_val_if_fail (sheet != NULL, FALSE);
7447 g_return_val_if_fail (GTK_IS_SHEET (sheet), FALSE);
7449 if (row < 0 || col < 0) return FALSE;
7451 init_attributes (sheet, col, attributes);
7456 attributes->is_editable = g_sheet_model_is_editable (sheet->model, row, col);
7457 attributes->is_visible = g_sheet_model_is_visible (sheet->model, row, col);
7459 fg = g_sheet_model_get_foreground (sheet->model, row, col);
7461 attributes->foreground = *fg;
7463 bg = g_sheet_model_get_background (sheet->model, row, col);
7465 attributes->background = *bg;
7467 j = g_sheet_model_get_justification (sheet->model, row, col);
7468 if (j) attributes->justification = *j;
7470 font_desc = g_sheet_model_get_font_desc (sheet->model, row, col);
7471 if ( font_desc ) attributes->font_desc = font_desc;
7473 border = g_sheet_model_get_cell_border (sheet->model, row, col);
7475 if ( border ) attributes->border = *border;
7481 init_attributes (const GtkSheet *sheet, gint col, GtkSheetCellAttr *attributes)
7483 /* DEFAULT VALUES */
7484 attributes->foreground = GTK_WIDGET (sheet)->style->black;
7485 attributes->background = sheet->bg_color;
7486 if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet)))
7488 GdkColormap *colormap;
7489 colormap = gdk_colormap_get_system ();
7490 gdk_color_black (colormap, &attributes->foreground);
7491 attributes->background = sheet->bg_color;
7493 attributes->justification = xxx_column_justification (sheet, col);
7494 attributes->border.width = 0;
7495 attributes->border.line_style = GDK_LINE_SOLID;
7496 attributes->border.cap_style = GDK_CAP_NOT_LAST;
7497 attributes->border.join_style = GDK_JOIN_MITER;
7498 attributes->border.mask = 0;
7499 attributes->border.color = GTK_WIDGET (sheet)->style->black;
7500 attributes->is_editable = TRUE;
7501 attributes->is_visible = TRUE;
7502 attributes->font_desc = GTK_WIDGET (sheet)->style->font_desc;
7506 /********************************************************************
7507 * Container Functions:
7512 * gtk_sheet_move_child
7513 * gtk_sheet_position_child
7514 * gtk_sheet_position_children
7515 * gtk_sheet_realize_child
7516 * gtk_sheet_get_child_at
7517 ********************************************************************/
7520 gtk_sheet_put (GtkSheet *sheet, GtkWidget *child, gint x, gint y)
7522 GtkRequisition child_requisition;
7523 GtkSheetChild *child_info;
7525 g_return_val_if_fail (sheet != NULL, NULL);
7526 g_return_val_if_fail (GTK_IS_SHEET (sheet), NULL);
7527 g_return_val_if_fail (child != NULL, NULL);
7528 g_return_val_if_fail (child->parent == NULL, NULL);
7530 child_info = g_new (GtkSheetChild, 1);
7531 child_info->widget = child;
7534 child_info->attached_to_cell = FALSE;
7535 child_info->floating = TRUE;
7536 child_info->xpadding = child_info->ypadding = 0;
7537 child_info->xexpand = child_info->yexpand = FALSE;
7538 child_info->xshrink = child_info->yshrink = FALSE;
7539 child_info->xfill = child_info->yfill = FALSE;
7541 sheet->children = g_list_append (sheet->children, child_info);
7543 gtk_widget_set_parent (child, GTK_WIDGET (sheet));
7545 gtk_widget_size_request (child, &child_requisition);
7547 if (GTK_WIDGET_VISIBLE (GTK_WIDGET (sheet)))
7549 if (GTK_WIDGET_REALIZED (GTK_WIDGET (sheet)) &&
7550 (!GTK_WIDGET_REALIZED (child) || GTK_WIDGET_NO_WINDOW (child)))
7551 gtk_sheet_realize_child (sheet, child_info);
7553 if (GTK_WIDGET_MAPPED (GTK_WIDGET (sheet)) &&
7554 !GTK_WIDGET_MAPPED (child))
7555 gtk_widget_map (child);
7558 gtk_sheet_position_child (sheet, child_info);
7560 /* This will avoid drawing on the titles */
7562 if (GTK_WIDGET_REALIZED (GTK_WIDGET (sheet)))
7564 if (sheet->row_titles_visible)
7565 gdk_window_show (sheet->row_title_window);
7566 if (sheet->column_titles_visible)
7567 gdk_window_show (sheet->column_title_window);
7570 return (child_info);
7574 gtk_sheet_attach_floating (GtkSheet *sheet,
7579 GtkSheetChild *child;
7581 if (row < 0 || col < 0)
7583 gtk_sheet_button_attach (sheet, widget, row, col);
7587 gtk_sheet_get_cell_area (sheet, row, col, &area);
7588 child = gtk_sheet_put (sheet, widget, area.x, area.y);
7589 child->attached_to_cell = TRUE;
7595 gtk_sheet_attach_default (GtkSheet *sheet,
7599 if (row < 0 || col < 0)
7601 gtk_sheet_button_attach (sheet, widget, row, col);
7605 gtk_sheet_attach (sheet, widget, row, col,
7606 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
7610 gtk_sheet_attach (GtkSheet *sheet,
7619 GtkSheetChild *child = NULL;
7621 if (row < 0 || col < 0)
7623 gtk_sheet_button_attach (sheet, widget, row, col);
7627 child = g_new0 (GtkSheetChild, 1);
7628 child->attached_to_cell = TRUE;
7629 child->floating = FALSE;
7630 child->widget = widget;
7633 child->xpadding = xpadding;
7634 child->ypadding = ypadding;
7635 child->xexpand = (xoptions & GTK_EXPAND) != 0;
7636 child->yexpand = (yoptions & GTK_EXPAND) != 0;
7637 child->xshrink = (xoptions & GTK_SHRINK) != 0;
7638 child->yshrink = (yoptions & GTK_SHRINK) != 0;
7639 child->xfill = (xoptions & GTK_FILL) != 0;
7640 child->yfill = (yoptions & GTK_FILL) != 0;
7642 sheet->children = g_list_append (sheet->children, child);
7644 gtk_sheet_get_cell_area (sheet, row, col, &area);
7646 child->x = area.x + child->xpadding;
7647 child->y = area.y + child->ypadding;
7649 if (GTK_WIDGET_VISIBLE (GTK_WIDGET (sheet)))
7651 if (GTK_WIDGET_REALIZED (GTK_WIDGET (sheet)) &&
7652 (!GTK_WIDGET_REALIZED (widget) || GTK_WIDGET_NO_WINDOW (widget)))
7653 gtk_sheet_realize_child (sheet, child);
7655 if (GTK_WIDGET_MAPPED (GTK_WIDGET (sheet)) &&
7656 !GTK_WIDGET_MAPPED (widget))
7657 gtk_widget_map (widget);
7660 gtk_sheet_position_child (sheet, child);
7662 /* This will avoid drawing on the titles */
7664 if (GTK_WIDGET_REALIZED (GTK_WIDGET (sheet)))
7666 if (GTK_SHEET_ROW_TITLES_VISIBLE (sheet))
7667 gdk_window_show (sheet->row_title_window);
7668 if (GTK_SHEET_COL_TITLES_VISIBLE (sheet))
7669 gdk_window_show (sheet->column_title_window);
7675 gtk_sheet_button_attach (GtkSheet *sheet,
7679 GtkSheetButton *button = 0;
7680 GtkSheetChild *child;
7681 GtkRequisition button_requisition;
7683 if (row >= 0 && col >= 0) return;
7684 if (row < 0 && col < 0) return;
7686 child = g_new (GtkSheetChild, 1);
7687 child->widget = widget;
7690 child->attached_to_cell = TRUE;
7691 child->floating = FALSE;
7694 child->xpadding = child->ypadding = 0;
7695 child->xshrink = child->yshrink = FALSE;
7696 child->xfill = child->yfill = FALSE;
7699 sheet->children = g_list_append (sheet->children, child);
7701 gtk_sheet_button_size_request (sheet, button, &button_requisition);
7704 if (GTK_WIDGET_VISIBLE (GTK_WIDGET (sheet)))
7706 if (GTK_WIDGET_REALIZED (GTK_WIDGET (sheet)) &&
7707 (!GTK_WIDGET_REALIZED (widget) || GTK_WIDGET_NO_WINDOW (widget)))
7708 gtk_sheet_realize_child (sheet, child);
7710 if (GTK_WIDGET_MAPPED (GTK_WIDGET (sheet)) &&
7711 !GTK_WIDGET_MAPPED (widget))
7712 gtk_widget_map (widget);
7715 if (row == -1) size_allocate_column_title_buttons (sheet);
7716 if (col == -1) size_allocate_row_title_buttons (sheet);
7721 label_size_request (GtkSheet *sheet, gchar *label, GtkRequisition *req)
7726 gint row_height = DEFAULT_ROW_HEIGHT (GTK_WIDGET (sheet)) - 2 * CELLOFFSET + 2;
7732 while (words && *words != '\0')
7734 if (*words == '\n' || * (words + 1) == '\0')
7736 req->height += row_height;
7739 req->width = MAX (req->width, STRING_WIDTH (GTK_WIDGET (sheet), GTK_WIDGET (sheet)->style->font_desc, word));
7749 if (n > 0) req->height -= 2;
7753 gtk_sheet_button_size_request (GtkSheet *sheet,
7754 const GtkSheetButton *button,
7755 GtkRequisition *button_requisition)
7757 GtkRequisition requisition;
7758 GtkRequisition label_requisition;
7760 if (gtk_sheet_autoresize (sheet) && button->label && strlen (button->label) > 0)
7762 label_size_request (sheet, button->label, &label_requisition);
7763 label_requisition.width += 2 * CELLOFFSET;
7764 label_requisition.height += 2 * CELLOFFSET;
7768 label_requisition.height = DEFAULT_ROW_HEIGHT (GTK_WIDGET (sheet));
7769 label_requisition.width = COLUMN_MIN_WIDTH;
7774 gtk_widget_size_request (button->child->widget, &requisition);
7775 requisition.width += 2 * button->child->xpadding;
7776 requisition.height += 2 * button->child->ypadding;
7777 requisition.width += 2 * sheet->button->style->xthickness;
7778 requisition.height += 2 * sheet->button->style->ythickness;
7782 requisition.height = DEFAULT_ROW_HEIGHT (GTK_WIDGET (sheet));
7783 requisition.width = COLUMN_MIN_WIDTH;
7786 *button_requisition = requisition;
7787 button_requisition->width = MAX (requisition.width, label_requisition.width);
7788 button_requisition->height = MAX (requisition.height, label_requisition.height);
7793 gtk_sheet_row_size_request (GtkSheet *sheet,
7797 GtkRequisition button_requisition;
7800 gtk_sheet_button_size_request (sheet,
7801 yyy_row_button (sheet, row),
7802 &button_requisition);
7804 *requisition = button_requisition.height;
7806 children = sheet->children;
7809 GtkSheetChild *child = (GtkSheetChild *)children->data;
7810 GtkRequisition child_requisition;
7812 if (child->attached_to_cell && child->row == row && child->col != -1 && !child->floating && !child->yshrink)
7814 gtk_widget_get_child_requisition (child->widget, &child_requisition);
7816 if (child_requisition.height + 2 * child->ypadding > *requisition)
7817 *requisition = child_requisition.height + 2 * child->ypadding;
7819 children = children->next;
7822 sheet->row_requisition = * requisition;
7826 gtk_sheet_column_size_request (GtkSheet *sheet,
7830 GtkRequisition button_requisition;
7833 gtk_sheet_button_size_request (sheet,
7834 xxx_column_button (sheet, col),
7835 &button_requisition);
7837 *requisition = button_requisition.width;
7839 children = sheet->children;
7842 GtkSheetChild *child = (GtkSheetChild *)children->data;
7843 GtkRequisition child_requisition;
7845 if (child->attached_to_cell && child->col == col && child->row != -1 && !child->floating && !child->xshrink)
7847 gtk_widget_get_child_requisition (child->widget, &child_requisition);
7849 if (child_requisition.width + 2 * child->xpadding > *requisition)
7850 *requisition = child_requisition.width + 2 * child->xpadding;
7852 children = children->next;
7855 sheet->column_requisition = *requisition;
7859 gtk_sheet_move_child (GtkSheet *sheet, GtkWidget *widget, gint x, gint y)
7861 GtkSheetChild *child;
7864 g_return_if_fail (sheet != NULL);
7865 g_return_if_fail (GTK_IS_SHEET (sheet));
7867 children = sheet->children;
7870 child = children->data;
7872 if (child->widget == widget)
7876 child->row = ROW_FROM_YPIXEL (sheet, y);
7877 child->col = COLUMN_FROM_XPIXEL (sheet, x);
7878 gtk_sheet_position_child (sheet, child);
7882 children = children->next;
7885 g_warning ("Widget must be a GtkSheet child");
7890 gtk_sheet_position_child (GtkSheet *sheet, GtkSheetChild *child)
7892 GtkRequisition child_requisition;
7893 GtkAllocation child_allocation;
7899 gtk_widget_get_child_requisition (child->widget, &child_requisition);
7901 if (sheet->column_titles_visible)
7902 yoffset = sheet->column_title_area.height;
7904 if (sheet->row_titles_visible)
7905 xoffset = sheet->row_title_area.width;
7907 if (child->attached_to_cell)
7909 gtk_sheet_get_cell_area (sheet, child->row, child->col, &area);
7910 child->x = area.x + child->xpadding;
7911 child->y = area.y + child->ypadding;
7913 if (!child->floating)
7915 if (child_requisition.width + 2 * child->xpadding <= xxx_column_width (sheet, child->col))
7919 child_requisition.width = child_allocation.width = xxx_column_width (sheet, child->col) - 2 * child->xpadding;
7925 child->x = area.x + xxx_column_width (sheet, child->col) / 2 -
7926 child_requisition.width / 2;
7928 child_allocation.width = child_requisition.width;
7933 if (!child->xshrink)
7935 gtk_sheet_set_column_width (sheet, child->col, child_requisition.width + 2 * child->xpadding);
7937 child_allocation.width = xxx_column_width (sheet, child->col) - 2 * child->xpadding;
7940 if (child_requisition.height +
7941 2 * child->ypadding <= yyy_row_height (sheet, child->row))
7945 child_requisition.height = child_allocation.height =
7946 yyy_row_height (sheet, child->row) - 2 * child->ypadding;
7952 child->y = area.y + yyy_row_height (sheet, child->row) / 2
7953 - child_requisition.height / 2;
7955 child_allocation.height = child_requisition.height;
7960 if (!child->yshrink)
7962 gtk_sheet_set_row_height (sheet, child->row, child_requisition.height + 2 * child->ypadding);
7964 child_allocation.height = yyy_row_height (sheet, child->row) -
7965 2 * child->ypadding;
7970 child_allocation.width = child_requisition.width;
7971 child_allocation.height = child_requisition.height;
7974 x = child_allocation.x = child->x + xoffset;
7975 y = child_allocation.y = child->y + yoffset;
7979 x = child_allocation.x = child->x + sheet->hoffset + xoffset;
7980 x = child_allocation.x = child->x + xoffset;
7981 y = child_allocation.y = child->y + sheet->voffset + yoffset;
7982 y = child_allocation.y = child->y + yoffset;
7983 child_allocation.width = child_requisition.width;
7984 child_allocation.height = child_requisition.height;
7987 gtk_widget_size_allocate (child->widget, &child_allocation);
7988 gtk_widget_queue_draw (child->widget);
7992 gtk_sheet_forall (GtkContainer *container,
7993 gboolean include_internals,
7994 GtkCallback callback,
7995 gpointer callback_data)
7998 GtkSheetChild *child;
8001 g_return_if_fail (GTK_IS_SHEET (container));
8002 g_return_if_fail (callback != NULL);
8004 sheet = GTK_SHEET (container);
8005 children = sheet->children;
8008 child = children->data;
8009 children = children->next;
8011 (* callback) (child->widget, callback_data);
8014 (* callback) (sheet->button, callback_data);
8015 if (sheet->sheet_entry)
8016 (* callback) (sheet->sheet_entry, callback_data);
8021 gtk_sheet_position_children (GtkSheet *sheet)
8024 GtkSheetChild *child;
8026 children = sheet->children;
8030 child = (GtkSheetChild *)children->data;
8032 if (child->col != -1 && child->row != -1)
8033 gtk_sheet_position_child (sheet, child);
8035 if (child->row == -1)
8037 if (child->col < MIN_VISIBLE_COLUMN (sheet) ||
8038 child->col > MAX_VISIBLE_COLUMN (sheet))
8039 gtk_sheet_child_hide (child);
8041 gtk_sheet_child_show (child);
8043 if (child->col == -1)
8045 if (child->row < MIN_VISIBLE_ROW (sheet) ||
8046 child->row > MAX_VISIBLE_ROW (sheet))
8047 gtk_sheet_child_hide (child);
8049 gtk_sheet_child_show (child);
8052 children = children->next;
8057 gtk_sheet_remove (GtkContainer *container, GtkWidget *widget)
8061 GtkSheetChild *child = 0;
8063 g_return_if_fail (container != NULL);
8064 g_return_if_fail (GTK_IS_SHEET (container));
8066 sheet = GTK_SHEET (container);
8068 children = sheet->children;
8072 child = (GtkSheetChild *)children->data;
8074 if (child->widget == widget) break;
8076 children = children->next;
8081 gtk_widget_unparent (widget);
8082 child->widget = NULL;
8084 sheet->children = g_list_remove_link (sheet->children, children);
8085 g_list_free_1 (children);
8092 gtk_sheet_realize_child (GtkSheet *sheet, GtkSheetChild *child)
8096 widget = GTK_WIDGET (sheet);
8098 if (GTK_WIDGET_REALIZED (widget))
8100 if (child->row == -1)
8101 gtk_widget_set_parent_window (child->widget, sheet->column_title_window);
8102 else if (child->col == -1)
8103 gtk_widget_set_parent_window (child->widget, sheet->row_title_window);
8105 gtk_widget_set_parent_window (child->widget, sheet->sheet_window);
8108 gtk_widget_set_parent (child->widget, widget);
8114 gtk_sheet_get_child_at (GtkSheet *sheet, gint row, gint col)
8117 GtkSheetChild *child = 0;
8119 g_return_val_if_fail (sheet != NULL, NULL);
8120 g_return_val_if_fail (GTK_IS_SHEET (sheet), NULL);
8122 children = sheet->children;
8126 child = (GtkSheetChild *)children->data;
8128 if (child->attached_to_cell)
8129 if (child->row == row && child->col == col) break;
8131 children = children->next;
8134 if (children) return child;
8140 gtk_sheet_child_hide (GtkSheetChild *child)
8142 g_return_if_fail (child != NULL);
8143 gtk_widget_hide (child->widget);
8147 gtk_sheet_child_show (GtkSheetChild *child)
8149 g_return_if_fail (child != NULL);
8151 gtk_widget_show (child->widget);
8155 gtk_sheet_get_model (const GtkSheet *sheet)
8157 g_return_val_if_fail (GTK_IS_SHEET (sheet), NULL);
8159 return sheet->model;
8164 gtk_sheet_button_new (void)
8166 GtkSheetButton *button = g_malloc (sizeof (GtkSheetButton));
8168 button->state = GTK_STATE_NORMAL;
8169 button->label = NULL;
8170 button->label_visible = TRUE;
8171 button->child = NULL;
8172 button->justification = GTK_JUSTIFY_FILL;
8179 gtk_sheet_button_free (GtkSheetButton *button)
8181 if (!button) return ;
8183 g_free (button->label);