1 /* This version of GtkSheet has been heavily modified, for the specific
2 requirements of PSPPIRE. */
5 /* GtkSheet widget for Gtk+.
6 * Copyright (C) 1999-2001 Adrian E. Feiguin <adrian@ifir.ifir.edu.ar>
8 * Based on GtkClist widget by Jay Painter, but major changes.
9 * Memory allocation routines inspired on SC (Spreadsheet Calculator)
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #ifndef __GTK_SHEET_H__
27 #define __GTK_SHEET_H__
31 #include "gtkextra-sheet.h"
32 #include "gsheetmodel.h"
33 #include "gsheet-column-iface.h"
34 #include "gsheet-row-iface.h"
39 #endif /* __cplusplus */
47 GTK_SHEET_JUSTIFICATION,
49 GTK_SHEET_BORDER_COLOR,
50 GTK_SHEET_IS_EDITABLE,
59 GTK_SHEET_ROW_SELECTED,
60 GTK_SHEET_COLUMN_SELECTED,
61 GTK_SHEET_RANGE_SELECTED
65 #define GTK_TYPE_SHEET_RANGE (gtk_sheet_range_get_type ())
66 #define GTK_TYPE_SHEET (gtk_sheet_get_type ())
68 #define GTK_SHEET(obj) GTK_CHECK_CAST (obj, gtk_sheet_get_type (), GtkSheet)
69 #define GTK_SHEET_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gtk_sheet_get_type (), GtkSheetClass)
70 #define GTK_IS_SHEET(obj) GTK_CHECK_TYPE (obj, gtk_sheet_get_type ())
72 /* Public flags, for compatibility */
74 #define GTK_SHEET_ROW_FROZEN(sheet) !gtk_sheet_rows_resizable (sheet)
75 #define GTK_SHEET_COLUMN_FROZEN(sheet) !gtk_sheet_columns_resizable (sheet)
76 #define GTK_SHEET_AUTORESIZE(sheet) gtk_sheet_autoresize (sheet)
77 #define GTK_SHEET_ROW_TITLES_VISIBLE(sheet) gtk_sheet_row_titles_visible (sheet)
78 #define GTK_SHEET_COL_TITLES_VISIBLE(sheet) gtk_sheet_column_titles_visible (sheet)
79 #define GTK_SHEET_AUTO_SCROLL(sheet) gtk_sheet_autoscroll (sheet)
80 #define GTK_SHEET_JUSTIFY_ENTRY(sheet) gtk_sheet_justify_entry (sheet)
83 typedef struct _GtkSheetClass GtkSheetClass;
84 typedef struct _GtkSheetCellAttr GtkSheetCellAttr;
85 typedef struct _GtkSheetCell GtkSheetCell;
86 typedef struct _GtkSheetHoverTitle GtkSheetHoverTitle;
89 struct _GtkSheetCellAttr
91 GtkJustification justification;
92 const PangoFontDescription *font_desc;
95 GtkSheetCellBorder border;
106 struct _GtkSheetHoverTitle
114 GtkContainer container;
116 GSheetColumn *column_geometry;
117 GSheetRow *row_geometry;
123 GtkSelectionMode selection_mode;
126 gboolean justify_entry;
130 /* Background colors */
138 /* allocation rectangle after the container_border_width
139 and the width of the shadow border */
140 GdkRectangle internal_allocation;
144 gint16 column_requisition;
145 gint16 row_requisition;
147 gboolean rows_resizable;
148 gboolean columns_resizable;
151 GtkSheetCell active_cell;
152 GtkWidget *sheet_entry;
156 /* expanding selection */
157 GtkSheetCell selection_cell;
159 /* global selection button */
168 /*the scrolling window and it's height and width to
169 * make things a little speedier */
170 GdkWindow *sheet_window;
171 guint sheet_window_width;
172 guint sheet_window_height;
174 /* sheet backing pixmap */
177 /* offsets for scrolling */
180 gfloat old_hadjustment;
181 gfloat old_vadjustment;
183 /* border shadow style */
184 GtkShadowType shadow_type;
187 GdkRectangle column_title_area;
188 GdkWindow *column_title_window;
189 gboolean column_titles_visible;
192 GdkRectangle row_title_area;
193 GdkWindow *row_title_window;
194 gboolean row_titles_visible;
197 GtkAdjustment *hadjustment;
198 GtkAdjustment *vadjustment;
200 /* xor GC for the verticle drag line */
203 /* gc for drawing unselected cells */
207 /* cursor used to indicate dragging */
208 GdkCursor *cursor_drag;
210 /* the current x-pixel location of the xor-drag vline */
213 /* the current y-pixel location of the xor-drag hline */
216 /* current cell being dragged */
217 GtkSheetCell drag_cell;
218 /* current range being dragged */
219 GtkSheetRange drag_range;
221 /* Used for the subtitle (popups) */
223 GtkSheetHoverTitle *hover_window;
226 struct _GtkSheetClass
228 GtkContainerClass parent_class;
230 void (*set_scroll_adjustments) (GtkSheet *sheet,
231 GtkAdjustment *hadjustment,
232 GtkAdjustment *vadjustment);
234 void (*select_row) (GtkSheet *sheet, gint row);
236 void (*select_column) (GtkSheet *sheet, gint column);
238 void (*select_range) (GtkSheet *sheet, GtkSheetRange *range);
240 void (*resize_range) (GtkSheet *sheet,
241 GtkSheetRange *old_range,
242 GtkSheetRange *new_range);
244 void (*move_range) (GtkSheet *sheet,
245 GtkSheetRange *old_range,
246 GtkSheetRange *new_range);
248 gboolean (*traverse) (GtkSheet *sheet,
249 gint row, gint column,
250 gint *new_row, gint *new_column);
252 gboolean (*deactivate) (GtkSheet *sheet,
253 gint row, gint column);
255 gboolean (*activate) (GtkSheet *sheet,
256 gint row, gint column);
258 void (*set_cell) (GtkSheet *sheet,
259 gint row, gint column);
261 void (*clear_cell) (GtkSheet *sheet,
262 gint row, gint column);
264 void (*changed) (GtkSheet *sheet,
265 gint row, gint column);
267 void (*new_column_width) (GtkSheet *sheet,
271 void (*new_row_height) (GtkSheet *sheet,
277 GType gtk_sheet_get_type (void);
278 GtkType gtk_sheet_range_get_type (void);
281 /* create a new sheet */
282 GtkWidget * gtk_sheet_new (GSheetRow *vgeo, GSheetColumn *hgeo,
289 /* create a new browser sheet. It cells can not be edited */
291 gtk_sheet_new_browser (guint rows, guint columns, const gchar *title);
294 gtk_sheet_construct_browser (GtkSheet *sheet,
295 guint rows, guint columns, const gchar *title);
297 /* create a new sheet with custom entry */
299 gtk_sheet_new_with_custom_entry (GSheetRow *vgeo,
304 gtk_sheet_construct_with_custom_entry (GtkSheet *sheet,
309 /* change scroll adjustments */
311 gtk_sheet_set_hadjustment (GtkSheet *sheet,
312 GtkAdjustment *adjustment);
314 gtk_sheet_set_vadjustment (GtkSheet *sheet,
315 GtkAdjustment *adjustment);
318 gtk_sheet_change_entry (GtkSheet *sheet, GtkType entry_type);
320 /* Returns sheet's entry widget */
322 gtk_sheet_get_entry (GtkSheet *sheet);
324 gtk_sheet_get_entry_widget (GtkSheet *sheet);
326 /* Returns sheet->state
327 * Added by Steven Rostedt <steven.rostedt@lmco.com> */
329 gtk_sheet_get_state (GtkSheet *sheet);
331 /* Returns sheet's ranges
332 * Added by Murray Cumming */
334 gtk_sheet_get_columns_count (GtkSheet *sheet);
337 gtk_sheet_get_rows_count (GtkSheet *sheet);
340 gtk_sheet_get_visible_range (GtkSheet *sheet,
341 GtkSheetRange *range);
344 gtk_sheet_get_selected_range (GtkSheet *sheet,
345 GtkSheetRange *range);
348 gtk_sheet_set_selection_mode (GtkSheet *sheet, gint mode);
351 gtk_sheet_set_autoresize (GtkSheet *sheet, gboolean autoresize);
354 gtk_sheet_autoresize (GtkSheet *sheet);
357 gtk_sheet_set_autoscroll (GtkSheet *sheet, gboolean autoscroll);
360 gtk_sheet_autoscroll (GtkSheet *sheet);
363 gtk_sheet_set_justify_entry (GtkSheet *sheet, gboolean justify);
366 gtk_sheet_justify_entry (GtkSheet *sheet);
369 gtk_sheet_set_locked (GtkSheet *sheet, gboolean lock);
372 gtk_sheet_locked (const GtkSheet *sheet);
374 /* set sheet title */
376 gtk_sheet_set_title (GtkSheet *sheet, const gchar *title);
378 /* freeze all visual updates of the sheet.
379 * Then thaw the sheet after you have made a number of changes.
380 * The updates will occure in a more efficent way than if
381 * you made them on a unfrozen sheet */
383 gtk_sheet_freeze (GtkSheet *sheet);
385 gtk_sheet_thaw (GtkSheet *sheet);
386 /* Background colors */
388 gtk_sheet_set_background (GtkSheet *sheet,
391 gtk_sheet_set_grid (GtkSheet *sheet,
392 GdkColor *grid_color);
394 gtk_sheet_show_grid (GtkSheet *sheet,
397 gtk_sheet_grid_visible (GtkSheet *sheet);
399 /* set/get column title */
401 gtk_sheet_set_column_title (GtkSheet * sheet,
403 const gchar * title);
406 gtk_sheet_get_column_title (GtkSheet * sheet,
409 /* set/get row title */
411 gtk_sheet_set_row_title (GtkSheet * sheet,
413 const gchar * title);
415 gtk_sheet_get_row_title (GtkSheet * sheet,
419 /* set/get button label */
421 gtk_sheet_row_button_add_label (GtkSheet *sheet,
422 gint row, const gchar *label);
424 gtk_sheet_row_button_get_label (GtkSheet *sheet,
427 gtk_sheet_row_button_justify (GtkSheet *sheet,
428 gint row, GtkJustification justification);
432 /* scroll the viewing area of the sheet to the given column
433 * and row; row_align and col_align are between 0-1 representing the
434 * location the row should appear on the screen, 0.0 being top or left,
435 * 1.0 being bottom or right; if row or column is negative then there
438 gtk_sheet_moveto (GtkSheet *sheet,
446 gtk_sheet_show_row_titles (GtkSheet *sheet);
448 gtk_sheet_hide_row_titles (GtkSheet *sheet);
450 gtk_sheet_row_titles_visible (GtkSheet *sheet);
453 /* set row button sensitivity. If sensitivity is TRUE can be toggled,
454 * otherwise it acts as a title */
456 gtk_sheet_row_set_sensitivity (GtkSheet *sheet,
457 gint row, gboolean sensitive);
459 /* set sensitivity for all row buttons */
461 gtk_sheet_rows_set_sensitivity (GtkSheet *sheet, gboolean sensitive);
463 gtk_sheet_rows_set_resizable (GtkSheet *sheet, gboolean resizable);
465 gtk_sheet_rows_resizable (GtkSheet *sheet);
467 /* set row visibility. The default value is TRUE. If FALSE, the
470 gtk_sheet_row_set_visibility (GtkSheet *sheet,
471 gint row, gboolean visible);
473 gtk_sheet_row_label_set_visibility (GtkSheet *sheet,
474 gint row, gboolean visible);
476 gtk_sheet_rows_labels_set_visibility (GtkSheet *sheet, gboolean visible);
479 /* select the row. The range is then highlighted, and the bounds are stored
482 gtk_sheet_select_row (GtkSheet * sheet,
485 /* select the column. The range is then highlighted, and the bounds are stored
488 gtk_sheet_select_column (GtkSheet * sheet,
491 /* get scrollbars adjustment */
493 gtk_sheet_get_vadjustment (GtkSheet * sheet);
495 gtk_sheet_get_hadjustment (GtkSheet * sheet);
497 /* highlight the selected range and store bounds in sheet->range */
498 void gtk_sheet_select_range (GtkSheet *sheet,
499 const GtkSheetRange *range);
502 void gtk_sheet_unselect_range (GtkSheet *sheet);
504 /* set active cell where the entry will be displayed
505 * returns FALSE if current cell can't be deactivated or
506 * requested cell can't be activated */
508 gtk_sheet_set_active_cell (GtkSheet *sheet,
509 gint row, gint column);
511 /* Sets *ROW and *COLUMN to be the coordinates of the active cell.
512 ROW and/or COLUMN may be null if the caller is not interested in their
515 gtk_sheet_get_active_cell (GtkSheet *sheet,
516 gint *row, gint *column);
518 /* set cell contents and allocate memory if needed */
520 gtk_sheet_set_cell (GtkSheet *sheet,
522 GtkJustification justification,
525 gtk_sheet_set_cell_text (GtkSheet *sheet,
528 /* get cell contents */
530 gtk_sheet_cell_get_text (const GtkSheet *sheet, gint row, gint col);
532 /* clear cell contents */
534 gtk_sheet_cell_clear (GtkSheet *sheet, gint row, gint col);
536 /* clear range contents. If range==NULL the whole sheet will be cleared */
538 gtk_sheet_range_clear (GtkSheet *sheet,
539 const GtkSheetRange *range);
541 /* get cell state: GTK_STATE_NORMAL, GTK_STATE_SELECTED */
543 gtk_sheet_cell_get_state (GtkSheet *sheet, gint row, gint col);
545 /* get row and column correspondig to the given position in the screen */
547 gtk_sheet_get_pixel_info (GtkSheet * sheet,
553 /* get area of a given cell */
555 gtk_sheet_get_cell_area (GtkSheet *sheet,
562 gtk_sheet_set_row_height (GtkSheet * sheet,
567 /* delete nrows rows starting in row */
569 gtk_sheet_delete_rows (GtkSheet *sheet, guint row, guint nrows);
571 /* append nrows row to the end of the sheet */
573 gtk_sheet_add_row (GtkSheet *sheet, guint nrows);
575 /* insert nrows rows before the given row and pull right */
577 gtk_sheet_insert_rows (GtkSheet *sheet, guint row, guint nrows);
579 /* set abckground color of the given range */
581 gtk_sheet_range_set_background (GtkSheet *sheet,
582 const GtkSheetRange *range,
583 const GdkColor *color);
585 /* set foreground color (text color) of the given range */
587 gtk_sheet_range_set_foreground (GtkSheet *sheet,
588 const GtkSheetRange *range,
589 const GdkColor *color);
591 /* set text justification (GTK_JUSTIFY_LEFT, RIGHT, CENTER) of the given range.
592 * The default value is GTK_JUSTIFY_LEFT. If autoformat is on, the
593 * default justification for numbers is GTK_JUSTIFY_RIGHT */
595 gtk_sheet_range_set_justification (GtkSheet *sheet,
596 const GtkSheetRange *range,
597 GtkJustification justification);
599 gtk_sheet_column_set_justification (GtkSheet *sheet,
601 GtkJustification justification);
602 /* set if cell contents can be edited or not in the given range:
603 * accepted values are TRUE or FALSE. */
605 gtk_sheet_range_set_editable (GtkSheet *sheet,
606 const GtkSheetRange *range,
609 /* set if cell contents are visible or not in the given range:
610 * accepted values are TRUE or FALSE.*/
612 gtk_sheet_range_set_visible (GtkSheet *sheet,
613 const GtkSheetRange *range,
616 /* set cell border style in the given range.
617 * mask values are CELL_LEFT_BORDER, CELL_RIGHT_BORDER, CELL_TOP_BORDER,
619 * width is the width of the border line in pixels
620 * line_style is the line_style for the border line */
622 gtk_sheet_range_set_border (GtkSheet *sheet,
623 const GtkSheetRange *range,
628 /* set border color for the given range */
630 gtk_sheet_range_set_border_color (GtkSheet *sheet,
631 const GtkSheetRange *range,
632 const GdkColor *color);
634 /* set font for the given range */
636 gtk_sheet_range_set_font (GtkSheet *sheet,
637 const GtkSheetRange *range,
638 PangoFontDescription *font);
640 /* get cell attributes of the given cell */
641 /* TRUE means that the cell is currently allocated */
643 gtk_sheet_get_attributes (const GtkSheet *sheet,
645 GtkSheetCellAttr *attributes);
649 gtk_sheet_put (GtkSheet *sheet,
653 gtk_sheet_attach_floating (GtkSheet *sheet,
657 gtk_sheet_attach_default (GtkSheet *sheet,
661 gtk_sheet_attach (GtkSheet *sheet,
671 gtk_sheet_move_child (GtkSheet *sheet,
676 gtk_sheet_get_child_at (GtkSheet *sheet,
680 gtk_sheet_button_attach (GtkSheet *sheet,
686 void gtk_sheet_set_model (GtkSheet *sheet,
689 GSheetModel * gtk_sheet_get_model (const GtkSheet *sheet);
694 #endif /* __cplusplus */
697 #endif /* __GTK_SHEET_H__ */