fa1ac422bee3df8b1724bd95db693717063726a0
[pspp-builds.git] / lib / gtksheet / gtksheet.h
1 /* This version of GtkSheet has been heavily modified, for the specific
2    requirements of PSPPIRE. */
3
4
5 /* GtkSheet widget for Gtk+.
6  * Copyright (C) 1999-2001 Adrian E. Feiguin <adrian@ifir.ifir.edu.ar>
7  *
8  * Based on GtkClist widget by Jay Painter, but major changes.
9  * Memory allocation routines inspired on SC (Spreadsheet Calculator)
10  *
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.
15  *
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.
20  *
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
24  */
25
26 #ifndef __GTK_SHEET_H__
27 #define __GTK_SHEET_H__
28
29 #include <gtk/gtk.h>
30
31 #include "gtkextra-sheet.h"
32 #include "gsheetmodel.h"
33 #include "gsheet-column-iface.h"
34 #include "gsheet-row-iface.h"
35
36
37 G_BEGIN_DECLS
38
39 /* sheet->state */
40 enum
41 {
42   GTK_SHEET_NORMAL,
43   GTK_SHEET_ROW_SELECTED,
44   GTK_SHEET_COLUMN_SELECTED,
45   GTK_SHEET_RANGE_SELECTED
46 };
47
48
49 #define GTK_TYPE_SHEET_RANGE (gtk_sheet_range_get_type ())
50 #define GTK_TYPE_SHEET_CELL (gtk_sheet_cell_get_type ())
51 #define GTK_TYPE_SHEET (gtk_sheet_get_type ())
52
53 #define GTK_SHEET(obj)          GTK_CHECK_CAST (obj, gtk_sheet_get_type (), GtkSheet)
54 #define GTK_SHEET_CLASS(klass)  GTK_CHECK_CLASS_CAST (klass, gtk_sheet_get_type (), GtkSheetClass)
55 #define GTK_IS_SHEET(obj)       GTK_CHECK_TYPE (obj, gtk_sheet_get_type ())
56
57
58 typedef struct _GtkSheetClass GtkSheetClass;
59 typedef struct _GtkSheetCellAttr     GtkSheetCellAttr;
60
61 typedef struct _GtkSheetHoverTitle GtkSheetHoverTitle;
62
63
64 struct _GtkSheetCellAttr
65 {
66   GtkJustification justification;
67   const PangoFontDescription *font_desc;
68   GdkColor foreground;
69   GdkColor background;
70   GtkSheetCellBorder border;
71   gboolean is_editable;
72   gboolean is_visible;
73 };
74
75 struct _GtkSheetHoverTitle
76 {
77   GtkWidget *window;
78   GtkWidget *label;
79   gint row, column;
80 };
81
82 enum
83   {
84     BG_COLOR,
85     GRID_COLOR,
86     n_COLORS
87   };
88
89 struct _GtkSheet
90 {
91   GtkBin parent;
92
93   gboolean dispose_has_run;
94   GSheetColumn *column_geometry;
95   GSheetRow *row_geometry;
96
97   guint16 flags;
98
99   GSheetModel *model;
100
101   GtkSelectionMode selection_mode;
102
103   /* Component colors */
104   GdkColor color[n_COLORS];
105   gboolean show_grid;
106
107   /* allocation rectangle after the container_border_width
108      and the width of the shadow border */
109   GdkRectangle internal_allocation;
110
111   gint16 column_requisition;
112   gint16 row_requisition;
113
114   gboolean rows_resizable;
115   gboolean columns_resizable;
116
117   /* active cell */
118   GtkSheetCell active_cell;
119
120   /* The GtkEntry used for editing the cells */
121   GtkWidget *entry_widget;
122
123   /* The widget containing entry_widget, or
124      entry_widget itself if no container */
125   GtkWidget *entry_container;
126
127   /* The type of entry_widget */
128   GtkType entry_type;
129
130   /* Handler of the "changed" callback for the entry widget */
131   glong entry_handler_id;
132
133   /* expanding selection */
134   GtkSheetCell selection_cell;
135
136   /* global selection button */
137   GtkWidget *button;
138
139   /* sheet state */
140   gint state;
141
142   /* selected range */
143   GtkSheetRange range;
144
145   /* the scrolling window and its height and width to
146    * make things a little speedier */
147   GdkWindow *sheet_window;
148
149   /* border shadow style */
150   GtkShadowType shadow_type;
151
152   /* Column Titles */
153   GdkRectangle column_title_area;
154   GdkWindow *column_title_window;
155   gboolean column_titles_visible;
156   /* TRUE if the cursor is over the column title window */
157   gboolean column_title_under;
158
159   /* Row Titles */
160   GdkRectangle row_title_area;
161   GdkWindow *row_title_window;
162   gboolean row_titles_visible;
163   /* TRUE if the cursor is over the row title window */
164   gboolean row_title_under;
165
166   /*scrollbars*/
167   GtkAdjustment *hadjustment;
168   GtkAdjustment *vadjustment;
169
170   /* xor GC for the verticle drag line */
171   GdkGC *xor_gc;
172
173   /* gc for drawing unselected cells */
174   GdkGC *fg_gc;
175   GdkGC *bg_gc;
176
177   /* cursor used to indicate dragging */
178   GdkCursor *cursor_drag;
179
180   /* the current x-pixel location of the xor-drag vline */
181   gint x_drag;
182
183   /* the current y-pixel location of the xor-drag hline */
184   gint y_drag;
185
186   /* current cell being dragged */
187   GtkSheetCell drag_cell;
188   /* current range being dragged */
189   GtkSheetRange drag_range;
190
191   /* Used for the subtitle (popups) */
192   gint motion_timer;
193   GtkSheetHoverTitle *hover_window;
194 };
195
196 struct _GtkSheetClass
197 {
198   GtkBinClass parent_class;
199
200  void (*set_scroll_adjustments) (GtkSheet *sheet,
201                                  GtkAdjustment *hadjustment,
202                                  GtkAdjustment *vadjustment);
203
204  void (*select_row)             (GtkSheet *sheet, gint row);
205
206  void (*select_column)          (GtkSheet *sheet, gint column);
207
208  void (*select_range)           (GtkSheet *sheet, GtkSheetRange *range);
209
210  void (*resize_range)           (GtkSheet *sheet,
211                                 GtkSheetRange *old_range,
212                                 GtkSheetRange *new_range);
213
214  void (*move_range)             (GtkSheet *sheet,
215                                 GtkSheetRange *old_range,
216                                 GtkSheetRange *new_range);
217
218  gboolean (*traverse)           (GtkSheet *sheet,
219                                 gint row, gint column,
220                                 gint *new_row, gint *new_column);
221
222  gboolean (*activate)           (GtkSheet *sheet,
223                                 gint row, gint column);
224
225  void (*changed)                (GtkSheet *sheet,
226                                 gint row, gint column);
227 };
228
229 GType gtk_sheet_get_type (void);
230 GtkType gtk_sheet_range_get_type (void);
231
232
233 /* create a new sheet */
234 GtkWidget * gtk_sheet_new (GSheetRow *vgeo, GSheetColumn *hgeo,
235                            GSheetModel *model);
236
237 /* create a new sheet with custom entry */
238 GtkWidget *
239 gtk_sheet_new_with_custom_entry         (GSheetRow *vgeo,
240                                          GSheetColumn *hgeo,
241                                          GtkType entry_type);
242 void
243 gtk_sheet_construct_with_custom_entry   (GtkSheet *sheet,
244                                          GSheetRow *vgeo,
245                                          GSheetColumn *hgeo,
246                                          GtkType entry_type);
247 /* Change entry */
248 void gtk_sheet_change_entry             (GtkSheet *sheet, GtkType entry_type);
249
250 GtkWidget *gtk_sheet_get_entry    (GtkSheet *sheet);
251
252
253 void gtk_sheet_get_selected_range (GtkSheet *sheet,
254                                          GtkSheetRange *range);
255
256 void gtk_sheet_show_grid          (GtkSheet *sheet,
257                                          gboolean show);
258
259 gboolean gtk_sheet_grid_visible   (GtkSheet *sheet);
260
261
262 /* scroll the viewing area of the sheet to the given column
263  * and row; row_align and col_align are between 0-1 representing the
264  * location the row should appear on the screen, 0.0 being top or left,
265  * 1.0 being bottom or right; if row or column is negative then there
266  * is no change */
267 void gtk_sheet_moveto (GtkSheet *sheet,
268                   gint row,
269                   gint column,
270                   gfloat row_align,
271                   gfloat col_align);
272
273
274 void gtk_sheet_show_row_titles          (GtkSheet *sheet);
275 void gtk_sheet_hide_row_titles          (GtkSheet *sheet);
276 void gtk_sheet_show_column_titles       (GtkSheet *sheet);
277 void gtk_sheet_hide_column_titles       (GtkSheet *sheet);
278
279 /* select the row. The range is then highlighted, and the bounds are stored
280  * in sheet->range  */
281 void gtk_sheet_select_row    (GtkSheet * sheet,  gint row);
282
283 /* select the column. The range is then highlighted, and the bounds are stored
284  * in sheet->range  */
285 void gtk_sheet_select_column (GtkSheet * sheet,  gint column);
286
287 /* highlight the selected range and store bounds in sheet->range */
288 void gtk_sheet_select_range (GtkSheet *sheet, const GtkSheetRange *range);
289
290 void gtk_sheet_get_visible_range (GtkSheet *sheet, GtkSheetRange *range);
291
292
293 /* obvious */
294 void gtk_sheet_unselect_range           (GtkSheet *sheet);
295
296 /* set active cell where the entry will be displayed */
297 void gtk_sheet_set_active_cell (GtkSheet *sheet,
298                                 gint row, gint column);
299
300 /* Sets *ROW and *COLUMN to be the coordinates of the active cell.
301    ROW and/or COLUMN may be null if the caller is not interested in their
302    values */
303 void gtk_sheet_get_active_cell (GtkSheet *sheet,
304                                         gint *row, gint *column);
305
306 /* get cell contents */
307 gchar *gtk_sheet_cell_get_text (const GtkSheet *sheet, gint row, gint col);
308
309
310 /* get cell attributes of the given cell */
311 /* TRUE means that the cell is currently allocated */
312 gboolean gtk_sheet_get_attributes       (const GtkSheet *sheet,
313                                         gint row, gint col,
314                                         GtkSheetCellAttr *attributes);
315
316 void gtk_sheet_set_model (GtkSheet *sheet,
317                                    GSheetModel *model);
318
319 GSheetModel * gtk_sheet_get_model (const GtkSheet *sheet);
320
321
322 G_END_DECLS
323
324
325 #endif /* __GTK_SHEET_H__ */
326
327