2 Copyright (C) 2006, 2008 Free Software Foundation
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 This file is derived from the gtksheet.c and extensively modified for the
19 requirements of PSPPIRE. The changes are copyright by the
20 Free Software Foundation. The copyright notice for the original work is
24 GtkSheet widget for Gtk+.
25 * Copyright (C) 1999-2001 Adrian E. Feiguin <adrian@ifir.ifir.edu.ar>
27 * Based on GtkClist widget by Jay Painter, but major changes.
28 * Memory allocation routines inspired on SC (Spreadsheet Calculator)
30 * This library is free software; you can redistribute it and/or
31 * modify it under the terms of the GNU Lesser General Public
32 * License as published by the Free Software Foundation; either
33 * version 2.1 of the License, or (at your option) any later version.
35 * This library is distributed in the hope that it will be useful,
36 * but WITHOUT ANY WARRANTY; without even the implied warranty of
37 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
38 * Lesser General Public License for more details.
40 * You should have received a copy of the GNU Lesser General Public
41 * License along with this library; if not, write to the Free Software
42 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
45 #ifndef __PSPPIRE_SHEET_H__
46 #define __PSPPIRE_SHEET_H__
50 #include "gtkextra-sheet.h"
51 #include <ui/gui/sheet/psppire-sheetmodel.h>
52 #include <ui/gui/sheet/psppire-axis.h>
56 /* sheet->select_status */
60 PSPPIRE_SHEET_ROW_SELECTED,
61 PSPPIRE_SHEET_COLUMN_SELECTED,
62 PSPPIRE_SHEET_RANGE_SELECTED
66 #define PSPPIRE_TYPE_SHEET_RANGE (psppire_sheet_range_get_type ())
67 #define PSPPIRE_TYPE_SHEET_CELL (psppire_sheet_cell_get_type ())
70 #define PSPPIRE_TYPE_SHEET (psppire_sheet_get_type ())
71 #define PSPPIRE_SHEET(obj) G_TYPE_CHECK_INSTANCE_CAST ((obj), PSPPIRE_TYPE_SHEET, PsppireSheet)
72 #define PSPPIRE_SHEET_CLASS(klass) G_TYPE_CHECK_CLASS_CAST ((klass), PSPPIRE_TYPE_SHEET, PsppireSheetClass)
73 #define PSPPIRE_IS_SHEET(obj) G_TYPE_CHECK_INSTANCE_TYPE ((obj), PSPPIRE_TYPE_SHEET)
76 typedef struct _PsppireSheetClass PsppireSheetClass;
77 typedef struct _PsppireSheetCellAttr PsppireSheetCellAttr;
79 typedef struct _PsppireSheetHoverTitle PsppireSheetHoverTitle;
82 struct _PsppireSheetCellAttr
84 GtkJustification justification;
87 PsppireSheetCellBorder border;
90 struct _PsppireSheetHoverTitle
108 gboolean dispose_has_run;
114 PsppireSheetModel *model;
116 /* Component colors */
117 GdkColor color[n_COLORS];
121 PsppireSheetCell active_cell;
123 /* The GtkEntry used for editing the cells */
124 GtkWidget *entry_widget;
126 /* The type of entry_widget */
129 /* global selection button */
136 PsppireSheetRange range;
138 /* The space between a cell's contents and its border */
139 GtkBorder *cell_padding;
141 /* the scrolling window and its height and width to
142 * make things a little speedier */
143 GdkWindow *sheet_window;
145 /* border shadow style */
146 GtkShadowType shadow_type;
149 GdkRectangle column_title_area;
150 GdkWindow *column_title_window;
151 gboolean column_titles_visible;
152 /* TRUE if the cursor is over the column title window */
153 gboolean column_title_under;
156 GdkRectangle row_title_area;
157 GdkWindow *row_title_window;
158 gboolean row_titles_visible;
159 /* TRUE if the cursor is over the row title window */
160 gboolean row_title_under;
163 GtkAdjustment *hadjustment;
164 GtkAdjustment *vadjustment;
166 /* xor GC for the verticle drag line */
169 /* gc for drawing unselected cells */
173 /* cursor used to indicate dragging */
174 GdkCursor *cursor_drag;
176 /* the current x-pixel location of the xor-drag vline */
179 /* the current y-pixel location of the xor-drag hline */
182 /* current cell being dragged */
183 PsppireSheetCell drag_cell;
184 /* current range being dragged */
185 PsppireSheetRange drag_range;
187 /* Used for the subtitle (popups) */
189 PsppireSheetHoverTitle *hover_window;
191 gulong update_handler_id;
194 struct _PsppireSheetClass
196 GtkBinClass parent_class;
198 gboolean (*set_scroll_adjustments) (PsppireSheet *sheet,
199 GtkAdjustment *hadjustment,
200 GtkAdjustment *vadjustment);
202 void (*select_row) (PsppireSheet *sheet, gint row);
204 void (*select_column) (PsppireSheet *sheet, gint column);
206 void (*select_range) (PsppireSheet *sheet, PsppireSheetRange *range);
208 void (*resize_range) (PsppireSheet *sheet,
209 PsppireSheetRange *old_range,
210 PsppireSheetRange *new_range);
212 void (*move_range) (PsppireSheet *sheet,
213 PsppireSheetRange *old_range,
214 PsppireSheetRange *new_range);
216 gboolean (*traverse) (PsppireSheet *sheet,
217 gint row, gint column,
218 gint *new_row, gint *new_column);
220 gboolean (*activate) (PsppireSheet *sheet,
221 gint row, gint column);
223 void (*changed) (PsppireSheet *sheet,
224 gint row, gint column);
227 GType psppire_sheet_get_type (void);
228 GType psppire_sheet_range_get_type (void);
231 /* create a new sheet */
232 GtkWidget * psppire_sheet_new (PsppireSheetModel *model);
234 /* create a new sheet with custom entry */
236 psppire_sheet_new_with_custom_entry (GType entry_type);
239 void psppire_sheet_change_entry (PsppireSheet *sheet, GType entry_type);
241 GtkEntry *psppire_sheet_get_entry (PsppireSheet *sheet);
244 void psppire_sheet_get_selected_range (PsppireSheet *sheet,
245 PsppireSheetRange *range);
247 void psppire_sheet_show_grid (PsppireSheet *sheet,
250 gboolean psppire_sheet_grid_visible (PsppireSheet *sheet);
253 /* scroll the viewing area of the sheet to the given column
254 * and row; row_align and col_align are between 0-1 representing the
255 * location the row should appear on the screen, 0.0 being top or left,
256 * 1.0 being bottom or right; if row or column is negative then there
258 void psppire_sheet_moveto (PsppireSheet *sheet,
265 void psppire_sheet_show_row_titles (PsppireSheet *sheet);
266 void psppire_sheet_hide_row_titles (PsppireSheet *sheet);
267 void psppire_sheet_show_column_titles (PsppireSheet *sheet);
268 void psppire_sheet_hide_column_titles (PsppireSheet *sheet);
270 /* select the row. The range is then highlighted, and the bounds are stored
272 void psppire_sheet_select_row (PsppireSheet * sheet, gint row);
274 /* select the column. The range is then highlighted, and the bounds are stored
276 void psppire_sheet_select_column (PsppireSheet * sheet, gint column);
278 /* highlight the selected range and store bounds in sheet->range */
279 void psppire_sheet_select_range (PsppireSheet *sheet, const PsppireSheetRange *range);
281 void psppire_sheet_get_visible_range (PsppireSheet *sheet, PsppireSheetRange *range);
285 void psppire_sheet_unselect_range (PsppireSheet *sheet);
287 /* set active cell where the entry will be displayed */
288 void psppire_sheet_set_active_cell (PsppireSheet *sheet,
289 gint row, gint column);
291 /* Sets *ROW and *COLUMN to be the coordinates of the active cell.
292 ROW and/or COLUMN may be null if the caller is not interested in their
294 void psppire_sheet_get_active_cell (PsppireSheet *sheet,
295 gint *row, gint *column);
297 /* get cell contents */
298 gchar *psppire_sheet_cell_get_text (const PsppireSheet *sheet, gint row, gint col);
301 void psppire_sheet_set_model (PsppireSheet *sheet,
302 PsppireSheetModel *model);
304 PsppireSheetModel * psppire_sheet_get_model (const PsppireSheet *sheet);
310 #endif /* __PSPPIRE_SHEET_H__ */