1 /* GtkSheet widget for Gtk+.
2 * Copyright (C) 1999-2001 Adrian E. Feiguin <adrian@ifir.ifir.edu.ar>
4 * Based on GtkClist widget by Jay Painter, but major changes.
5 * Memory allocation routines inspired on SC (Spreadsheet Calculator)
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301 USA
23 #ifndef __GTK_SHEET_H__
24 #define __GTK_SHEET_H__
29 #endif /* __cplusplus */
37 GTK_SHEET_JUSTIFICATION
,
39 GTK_SHEET_BORDER_COLOR
,
40 GTK_SHEET_IS_EDITABLE
,
49 GTK_SHEET_ROW_SELECTED
,
50 GTK_SHEET_COLUMN_SELECTED
,
51 GTK_SHEET_RANGE_SELECTED
56 GTK_SHEET_LEFT_BORDER
= 1 << 0,
57 GTK_SHEET_RIGHT_BORDER
= 1 << 1,
58 GTK_SHEET_TOP_BORDER
= 1 << 2,
59 GTK_SHEET_BOTTOM_BORDER
= 1 << 3
62 #define GTK_TYPE_SHEET_RANGE (gtk_sheet_range_get_type ())
63 #define GTK_TYPE_SHEET (gtk_sheet_get_type ())
65 #define GTK_SHEET(obj) GTK_CHECK_CAST (obj, gtk_sheet_get_type (), GtkSheet)
66 #define GTK_SHEET_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gtk_sheet_get_type (), GtkSheetClass)
67 #define GTK_IS_SHEET(obj) GTK_CHECK_TYPE (obj, gtk_sheet_get_type ())
69 /* Public flags, for compatibility */
71 #define GTK_SHEET_IS_LOCKED(sheet) gtk_sheet_locked(sheet)
72 #define GTK_SHEET_ROW_FROZEN(sheet) !gtk_sheet_rows_resizable(sheet)
73 #define GTK_SHEET_COLUMN_FROZEN(sheet) !gtk_sheet_columns_resizable(sheet)
74 #define GTK_SHEET_AUTORESIZE(sheet) gtk_sheet_autoresize(sheet)
75 #define GTK_SHEET_CLIP_TEXT(sheet) gtk_sheet_clip_text(sheet)
76 #define GTK_SHEET_ROW_TITLES_VISIBLE(sheet) gtk_sheet_row_titles_visible(sheet)
77 #define GTK_SHEET_COL_TITLES_VISIBLE(sheet) gtk_sheet_column_titles_visible(sheet)
78 #define GTK_SHEET_AUTO_SCROLL(sheet) gtk_sheet_autoscroll(sheet)
79 #define GTK_SHEET_JUSTIFY_ENTRY(sheet) gtk_sheet_justify_entry(sheet)
81 typedef struct _GtkSheet GtkSheet
;
82 typedef struct _GtkSheetClass GtkSheetClass
;
83 typedef struct _GtkSheetChild GtkSheetChild
;
84 typedef struct _GtkSheetRow GtkSheetRow
;
85 typedef struct _GtkSheetColumn GtkSheetColumn
;
86 typedef struct _GtkSheetCell GtkSheetCell
;
87 typedef struct _GtkSheetRange GtkSheetRange
;
88 typedef struct _GtkSheetButton GtkSheetButton
;
89 typedef struct _GtkSheetCellAttr GtkSheetCellAttr
;
90 typedef struct _GtkSheetCellBorder GtkSheetCellBorder
;
96 gboolean attached_to_cell
;
109 struct _GtkSheetButton
114 gboolean label_visible
;
115 GtkSheetChild
*child
;
117 GtkJustification justification
;
120 struct _GtkSheetCellBorder
124 GdkLineStyle line_style
;
125 GdkCapStyle cap_style
;
126 GdkJoinStyle join_style
;
130 struct _GtkSheetCellAttr
132 GtkJustification justification
;
134 PangoFontDescription
*font_desc
;
137 GtkSheetCellBorder border
;
138 gboolean is_editable
;
148 GtkSheetCellAttr
*attributes
;
154 struct _GtkSheetRange
156 gint row0
,col0
; /* upper-left cell */
157 gint rowi
,coli
; /* lower-right cell */
168 GtkSheetButton button
;
169 gboolean is_sensitive
;
173 struct _GtkSheetColumn
180 GtkSheetButton button
;
182 gint left_text_column
; /* min left column displaying text on this column */
183 gint right_text_column
; /* max right column displaying text on this column */
185 GtkJustification justification
;
186 gboolean is_sensitive
;
192 GtkContainer container
;
196 GtkSelectionMode selection_mode
;
200 gboolean justify_entry
;
205 /* Background colors */
213 /* allocation rectangle after the container_border_width
214 and the width of the shadow border */
215 GdkRectangle internal_allocation
;
220 GtkSheetColumn
*column
;
222 gboolean rows_resizable
;
223 gboolean columns_resizable
;
225 /* max number of diplayed cells */
229 /* Displayed range */
233 /* sheet data: dynamically allocated array of cell pointers */
234 GtkSheetCell
***data
;
236 /* max number of allocated cells */
241 GtkSheetCell active_cell
;
242 GtkWidget
*sheet_entry
;
246 /* expanding selection */
247 GtkSheetCell selection_cell
;
249 /* timer for automatic scroll during selection */
251 /* timer for flashing clipped range */
255 /* global selection button */
264 /*the scrolling window and it's height and width to
265 * make things a little speedier */
266 GdkWindow
*sheet_window
;
267 guint sheet_window_width
;
268 guint sheet_window_height
;
270 /* sheet backing pixmap */
273 /* offsets for scrolling */
276 gfloat old_hadjustment
;
277 gfloat old_vadjustment
;
279 /* border shadow style */
280 GtkShadowType shadow_type
;
283 GdkRectangle column_title_area
;
284 GdkWindow
*column_title_window
;
285 gboolean column_titles_visible
;
288 GdkRectangle row_title_area
;
289 GdkWindow
*row_title_window
;
290 gboolean row_titles_visible
;
293 GtkAdjustment
*hadjustment
;
294 GtkAdjustment
*vadjustment
;
296 /* xor GC for the verticle drag line */
299 /* gc for drawing unselected cells */
303 /* cursor used to indicate dragging */
304 GdkCursor
*cursor_drag
;
306 /* the current x-pixel location of the xor-drag vline */
309 /* the current y-pixel location of the xor-drag hline */
312 /* current cell being dragged */
313 GtkSheetCell drag_cell
;
314 /* current range being dragged */
315 GtkSheetRange drag_range
;
318 GtkSheetRange clip_range
;
321 struct _GtkSheetClass
323 GtkContainerClass parent_class
;
325 void (*set_scroll_adjustments
) (GtkSheet
*sheet
,
326 GtkAdjustment
*hadjustment
,
327 GtkAdjustment
*vadjustment
);
329 void (*select_row
) (GtkSheet
*sheet
, gint row
);
331 void (*select_column
) (GtkSheet
*sheet
, gint column
);
333 void (*select_range
) (GtkSheet
*sheet
, GtkSheetRange
*range
);
335 void (*clip_range
) (GtkSheet
*sheet
, GtkSheetRange
*clip_range
);
337 void (*resize_range
) (GtkSheet
*sheet
,
338 GtkSheetRange
*old_range
,
339 GtkSheetRange
*new_range
);
341 void (*move_range
) (GtkSheet
*sheet
,
342 GtkSheetRange
*old_range
,
343 GtkSheetRange
*new_range
);
345 gboolean (*traverse
) (GtkSheet
*sheet
,
346 gint row
, gint column
,
347 gint
*new_row
, gint
*new_column
);
349 gboolean (*deactivate
) (GtkSheet
*sheet
,
350 gint row
, gint column
);
352 gboolean (*activate
) (GtkSheet
*sheet
,
353 gint row
, gint column
);
355 void (*set_cell
) (GtkSheet
*sheet
,
356 gint row
, gint column
);
358 void (*clear_cell
) (GtkSheet
*sheet
,
359 gint row
, gint column
);
361 void (*changed
) (GtkSheet
*sheet
,
362 gint row
, gint column
);
364 void (*new_column_width
) (GtkSheet
*sheet
,
368 void (*new_row_height
) (GtkSheet
*sheet
,
374 GType
gtk_sheet_get_type (void);
375 GtkType
gtk_sheet_range_get_type (void);
377 /* create a new sheet */
379 gtk_sheet_new (guint rows
, guint columns
, const gchar
*title
);
382 gtk_sheet_construct (GtkSheet
*sheet
,
383 guint rows
, guint columns
, const gchar
*title
);
385 /* create a new browser sheet. It cells can not be edited */
387 gtk_sheet_new_browser (guint rows
, guint columns
, const gchar
*title
);
390 gtk_sheet_construct_browser (GtkSheet
*sheet
,
391 guint rows
, guint columns
, const gchar
*title
);
393 /* create a new sheet with custom entry */
395 gtk_sheet_new_with_custom_entry (guint rows
, guint columns
,
399 gtk_sheet_construct_with_custom_entry (GtkSheet
*sheet
,
400 guint rows
, guint columns
,
403 /* change scroll adjustments */
405 gtk_sheet_set_hadjustment (GtkSheet
*sheet
,
406 GtkAdjustment
*adjustment
);
408 gtk_sheet_set_vadjustment (GtkSheet
*sheet
,
409 GtkAdjustment
*adjustment
);
412 gtk_sheet_change_entry (GtkSheet
*sheet
, GtkType entry_type
);
414 /* Returns sheet's entry widget */
416 gtk_sheet_get_entry (GtkSheet
*sheet
);
418 gtk_sheet_get_entry_widget (GtkSheet
*sheet
);
420 /* Returns sheet->state
421 * Added by Steven Rostedt <steven.rostedt@lmco.com> */
423 gtk_sheet_get_state (GtkSheet
*sheet
);
425 /* Returns sheet's ranges
426 * Added by Murray Cumming */
428 gtk_sheet_get_columns_count (GtkSheet
*sheet
);
431 gtk_sheet_get_rows_count (GtkSheet
*sheet
);
434 gtk_sheet_get_visible_range (GtkSheet
*sheet
,
435 GtkSheetRange
*range
);
437 gtk_sheet_set_selection_mode (GtkSheet
*sheet
, gint mode
);
440 gtk_sheet_set_autoresize (GtkSheet
*sheet
, gboolean autoresize
);
443 gtk_sheet_autoresize (GtkSheet
*sheet
);
446 gtk_sheet_set_autoscroll (GtkSheet
*sheet
, gboolean autoscroll
);
449 gtk_sheet_autoscroll (GtkSheet
*sheet
);
452 gtk_sheet_set_clip_text (GtkSheet
*sheet
, gboolean clip_text
);
455 gtk_sheet_clip_text (GtkSheet
*sheet
);
458 gtk_sheet_set_justify_entry (GtkSheet
*sheet
, gboolean justify
);
461 gtk_sheet_justify_entry (GtkSheet
*sheet
);
464 gtk_sheet_set_locked (GtkSheet
*sheet
, gboolean lock
);
467 gtk_sheet_locked (GtkSheet
*sheet
);
469 /* set sheet title */
471 gtk_sheet_set_title (GtkSheet
*sheet
, const gchar
*title
);
473 /* freeze all visual updates of the sheet.
474 * Then thaw the sheet after you have made a number of changes.
475 * The updates will occure in a more efficent way than if
476 * you made them on a unfrozen sheet */
478 gtk_sheet_freeze (GtkSheet
*sheet
);
480 gtk_sheet_thaw (GtkSheet
*sheet
);
481 /* Background colors */
483 gtk_sheet_set_background (GtkSheet
*sheet
,
486 gtk_sheet_set_grid (GtkSheet
*sheet
,
487 GdkColor
*grid_color
);
489 gtk_sheet_show_grid (GtkSheet
*sheet
,
492 gtk_sheet_grid_visible (GtkSheet
*sheet
);
494 /* set/get column title */
496 gtk_sheet_set_column_title (GtkSheet
* sheet
,
498 const gchar
* title
);
501 gtk_sheet_get_column_title (GtkSheet
* sheet
,
504 /* set/get row title */
506 gtk_sheet_set_row_title (GtkSheet
* sheet
,
508 const gchar
* title
);
510 gtk_sheet_get_row_title (GtkSheet
* sheet
,
513 /* set/get button label */
515 gtk_sheet_row_button_add_label (GtkSheet
*sheet
,
516 gint row
, const gchar
*label
);
518 gtk_sheet_column_button_add_label (GtkSheet
*sheet
,
519 gint column
, const gchar
*label
);
521 gtk_sheet_row_button_get_label (GtkSheet
*sheet
,
524 gtk_sheet_column_button_get_label (GtkSheet
*sheet
,
527 gtk_sheet_row_button_justify (GtkSheet
*sheet
,
528 gint row
, GtkJustification justification
);
530 gtk_sheet_column_button_justify (GtkSheet
*sheet
,
531 gint column
, GtkJustification justification
);
533 /* scroll the viewing area of the sheet to the given column
534 * and row; row_align and col_align are between 0-1 representing the
535 * location the row should appear on the screnn, 0.0 being top or left,
536 * 1.0 being bottom or right; if row or column is negative then there
539 gtk_sheet_moveto (GtkSheet
* sheet
,
545 /* resize column/row titles window */
547 gtk_sheet_set_row_titles_width(GtkSheet
*sheet
, guint width
);
549 gtk_sheet_set_column_titles_height(GtkSheet
*sheet
, guint height
);
551 /* show/hide column/row titles window */
553 gtk_sheet_show_column_titles (GtkSheet
*sheet
);
555 gtk_sheet_show_row_titles (GtkSheet
*sheet
);
557 gtk_sheet_hide_column_titles (GtkSheet
*sheet
);
559 gtk_sheet_hide_row_titles (GtkSheet
*sheet
);
561 gtk_sheet_column_titles_visible (GtkSheet
*sheet
);
563 gtk_sheet_row_titles_visible (GtkSheet
*sheet
);
565 /* set column button sensitivity. If sensitivity is TRUE it can be toggled,
566 * otherwise it acts as a title */
568 gtk_sheet_column_set_sensitivity (GtkSheet
*sheet
,
569 gint column
, gboolean sensitive
);
571 /* set sensitivity for all column buttons */
573 gtk_sheet_columns_set_sensitivity (GtkSheet
*sheet
, gboolean sensitive
);
575 gtk_sheet_columns_set_resizable (GtkSheet
*sheet
, gboolean resizable
);
577 gtk_sheet_columns_resizable (GtkSheet
*sheet
);
579 /* set row button sensitivity. If sensitivity is TRUE can be toggled,
580 * otherwise it acts as a title */
582 gtk_sheet_row_set_sensitivity (GtkSheet
*sheet
,
583 gint row
, gboolean sensitive
);
585 /* set sensitivity for all row buttons */
587 gtk_sheet_rows_set_sensitivity (GtkSheet
*sheet
, gboolean sensitive
);
589 gtk_sheet_rows_set_resizable (GtkSheet
*sheet
, gboolean resizable
);
591 gtk_sheet_rows_resizable (GtkSheet
*sheet
);
593 /* set column visibility. The default value is TRUE. If FALSE, the
594 * column is hidden */
596 gtk_sheet_column_set_visibility (GtkSheet
*sheet
,
597 gint column
, gboolean visible
);
599 gtk_sheet_column_label_set_visibility (GtkSheet
*sheet
,
600 gint column
, gboolean visible
);
602 gtk_sheet_columns_labels_set_visibility (GtkSheet
*sheet
, gboolean visible
);
604 /* set row visibility. The default value is TRUE. If FALSE, the
607 gtk_sheet_row_set_visibility (GtkSheet
*sheet
,
608 gint row
, gboolean visible
);
610 gtk_sheet_row_label_set_visibility (GtkSheet
*sheet
,
611 gint row
, gboolean visible
);
613 gtk_sheet_rows_labels_set_visibility (GtkSheet
*sheet
, gboolean visible
);
616 /* select the row. The range is then highlighted, and the bounds are stored
619 gtk_sheet_select_row (GtkSheet
* sheet
,
622 /* select the column. The range is then highlighted, and the bounds are stored
625 gtk_sheet_select_column (GtkSheet
* sheet
,
628 /* save selected range to "clipboard" */
630 gtk_sheet_clip_range (GtkSheet
*sheet
, const GtkSheetRange
*range
);
633 gtk_sheet_unclip_range (GtkSheet
*sheet
);
636 gtk_sheet_in_clip (GtkSheet
*sheet
);
638 /* get scrollbars adjustment */
640 gtk_sheet_get_vadjustment (GtkSheet
* sheet
);
642 gtk_sheet_get_hadjustment (GtkSheet
* sheet
);
644 /* highlight the selected range and store bounds in sheet->range */
645 void gtk_sheet_select_range (GtkSheet
*sheet
,
646 const GtkSheetRange
*range
);
649 void gtk_sheet_unselect_range (GtkSheet
*sheet
);
651 /* set active cell where the entry will be displayed
652 * returns FALSE if current cell can't be deactivated or
653 * requested cell can't be activated */
655 gtk_sheet_set_active_cell (GtkSheet
*sheet
,
656 gint row
, gint column
);
658 gtk_sheet_get_active_cell (GtkSheet
*sheet
,
659 gint
*row
, gint
*column
);
661 /* set cell contents and allocate memory if needed */
663 gtk_sheet_set_cell (GtkSheet
*sheet
,
665 GtkJustification justification
,
668 gtk_sheet_set_cell_text (GtkSheet
*sheet
,
672 /* get cell contents */
674 gtk_sheet_cell_get_text (GtkSheet
*sheet
, gint row
, gint col
);
677 /* clear cell contents */
679 gtk_sheet_cell_clear (GtkSheet
*sheet
, gint row
, gint col
);
680 /* clear cell contents and remove links */
682 gtk_sheet_cell_delete (GtkSheet
*sheet
, gint row
, gint col
);
684 /* clear range contents. If range==NULL the whole sheet will be cleared */
686 gtk_sheet_range_clear (GtkSheet
*sheet
,
687 const GtkSheetRange
*range
);
688 /* clear range contents and remove links */
690 gtk_sheet_range_delete (GtkSheet
*sheet
,
691 const GtkSheetRange
*range
);
693 /* get cell state: GTK_STATE_NORMAL, GTK_STATE_SELECTED */
695 gtk_sheet_cell_get_state (GtkSheet
*sheet
, gint row
, gint col
);
697 /* Handles cell links */
699 gtk_sheet_link_cell (GtkSheet
*sheet
, gint row
, gint col
,
703 gtk_sheet_get_link (GtkSheet
*sheet
, gint row
, gint col
);
705 gtk_sheet_remove_link (GtkSheet
*sheet
, gint row
, gint col
);
707 /* get row and column correspondig to the given position in the screen */
709 gtk_sheet_get_pixel_info (GtkSheet
* sheet
,
715 /* get area of a given cell */
717 gtk_sheet_get_cell_area (GtkSheet
*sheet
,
722 /* set column width */
724 gtk_sheet_set_column_width (GtkSheet
* sheet
,
730 gtk_sheet_set_row_height (GtkSheet
* sheet
,
734 /* append ncols columns to the end of the sheet */
736 gtk_sheet_add_column (GtkSheet
*sheet
, guint ncols
);
738 /* append nrows row to the end of the sheet */
740 gtk_sheet_add_row (GtkSheet
*sheet
, guint nrows
);
742 /* insert nrows rows before the given row and pull right */
744 gtk_sheet_insert_rows (GtkSheet
*sheet
, guint row
, guint nrows
);
746 /* insert ncols columns before the given col and pull down */
748 gtk_sheet_insert_columns (GtkSheet
*sheet
, guint col
, guint ncols
);
750 /* delete nrows rows starting in row */
752 gtk_sheet_delete_rows (GtkSheet
*sheet
, guint row
, guint nrows
);
754 /* delete ncols columns starting in col */
756 gtk_sheet_delete_columns (GtkSheet
*sheet
, guint col
, guint ncols
);
758 /* set abckground color of the given range */
760 gtk_sheet_range_set_background (GtkSheet
*sheet
,
761 const GtkSheetRange
*range
,
762 const GdkColor
*color
);
764 /* set foreground color (text color) of the given range */
766 gtk_sheet_range_set_foreground (GtkSheet
*sheet
,
767 const GtkSheetRange
*range
,
768 const GdkColor
*color
);
770 /* set text justification (GTK_JUSTIFY_LEFT, RIGHT, CENTER) of the given range.
771 * The default value is GTK_JUSTIFY_LEFT. If autoformat is on, the
772 * default justification for numbers is GTK_JUSTIFY_RIGHT */
774 gtk_sheet_range_set_justification (GtkSheet
*sheet
,
775 const GtkSheetRange
*range
,
776 GtkJustification justification
);
778 gtk_sheet_column_set_justification (GtkSheet
*sheet
,
780 GtkJustification justification
);
781 /* set if cell contents can be edited or not in the given range:
782 * accepted values are TRUE or FALSE. */
784 gtk_sheet_range_set_editable (GtkSheet
*sheet
,
785 const GtkSheetRange
*range
,
788 /* set if cell contents are visible or not in the given range:
789 * accepted values are TRUE or FALSE.*/
791 gtk_sheet_range_set_visible (GtkSheet
*sheet
,
792 const GtkSheetRange
*range
,
795 /* set cell border style in the given range.
796 * mask values are CELL_LEFT_BORDER, CELL_RIGHT_BORDER, CELL_TOP_BORDER,
798 * width is the width of the border line in pixels
799 * line_style is the line_style for the border line */
801 gtk_sheet_range_set_border (GtkSheet
*sheet
,
802 const GtkSheetRange
*range
,
807 /* set border color for the given range */
809 gtk_sheet_range_set_border_color (GtkSheet
*sheet
,
810 const GtkSheetRange
*range
,
811 const GdkColor
*color
);
813 /* set font for the given range */
815 gtk_sheet_range_set_font (GtkSheet
*sheet
,
816 const GtkSheetRange
*range
,
817 PangoFontDescription
*font
);
819 /* get cell attributes of the given cell */
820 /* TRUE means that the cell is currently allocated */
822 gtk_sheet_get_attributes (GtkSheet
*sheet
,
824 GtkSheetCellAttr
*attributes
);
828 gtk_sheet_put (GtkSheet
*sheet
,
832 gtk_sheet_attach_floating (GtkSheet
*sheet
,
836 gtk_sheet_attach_default (GtkSheet
*sheet
,
840 gtk_sheet_attach (GtkSheet
*sheet
,
850 gtk_sheet_move_child (GtkSheet
*sheet
,
855 gtk_sheet_get_child_at (GtkSheet
*sheet
,
859 gtk_sheet_button_attach (GtkSheet
*sheet
,
866 #endif /* __cplusplus */
869 #endif /* __GTK_SHEET_H__ */