983c5f0aa45d27ae7d9918564c3a1f87e44f7a36
[pspp] / 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
40 typedef enum
41 {
42   GTK_SHEET_FOREGROUND,
43   GTK_SHEET_BACKGROUND,
44   GTK_SHEET_FONT,
45   GTK_SHEET_JUSTIFICATION,
46   GTK_SHEET_BORDER,
47   GTK_SHEET_BORDER_COLOR,
48   GTK_SHEET_IS_EDITABLE,
49   GTK_SHEET_IS_VISIBLE
50 } GtkSheetAttrType;
51
52 /* sheet->state */
53
54 enum
55 {
56   GTK_SHEET_NORMAL,
57   GTK_SHEET_ROW_SELECTED,
58   GTK_SHEET_COLUMN_SELECTED,
59   GTK_SHEET_RANGE_SELECTED
60 };
61
62
63 #define GTK_TYPE_SHEET_RANGE (gtk_sheet_range_get_type ())
64 #define GTK_TYPE_SHEET (gtk_sheet_get_type ())
65
66 #define GTK_SHEET(obj)          GTK_CHECK_CAST (obj, gtk_sheet_get_type (), GtkSheet)
67 #define GTK_SHEET_CLASS(klass)  GTK_CHECK_CLASS_CAST (klass, gtk_sheet_get_type (), GtkSheetClass)
68 #define GTK_IS_SHEET(obj)       GTK_CHECK_TYPE (obj, gtk_sheet_get_type ())
69
70
71
72
73 typedef struct _GtkSheetClass GtkSheetClass;
74 typedef struct _GtkSheetCellAttr     GtkSheetCellAttr;
75 typedef struct _GtkSheetCell GtkSheetCell;
76 typedef struct _GtkSheetHoverTitle GtkSheetHoverTitle;
77
78
79 struct _GtkSheetCellAttr
80 {
81   GtkJustification justification;
82   const PangoFontDescription *font_desc;
83   GdkColor foreground;
84   GdkColor background;
85   GtkSheetCellBorder border;
86   gboolean is_editable;
87   gboolean is_visible;
88 };
89
90 struct _GtkSheetCell
91 {
92   gint row;
93   gint col;
94 };
95
96
97 struct _GtkSheetHoverTitle
98 {
99   GtkWidget *window;
100   GtkWidget *label;
101   gint row, column;
102 };
103
104 enum
105   {
106     BG_COLOR,
107     GRID_COLOR,
108     n_COLORS
109   };
110
111 struct _GtkSheet
112 {
113   GtkBin parent;
114
115   gboolean dispose_has_run;
116   GSheetColumn *column_geometry;
117   GSheetRow *row_geometry;
118
119   guint16 flags;
120
121   GSheetModel *model;
122
123   GtkSelectionMode selection_mode;
124
125   /* Component colors */
126   GdkColor color[n_COLORS];
127   gboolean show_grid;
128
129   /* allocation rectangle after the container_border_width
130      and the width of the shadow border */
131   GdkRectangle internal_allocation;
132
133   gint16 column_requisition;
134   gint16 row_requisition;
135
136   gboolean rows_resizable;
137   gboolean columns_resizable;
138
139   /* active cell */
140   GtkSheetCell active_cell;
141
142   /* The GtkEntry used for editing the cells */
143   GtkWidget *entry_widget;
144
145   /* The widget containing entry_widget, or
146      entry_widget itself if no container */
147   GtkWidget *entry_container;
148
149   /* The type of entry_widget */
150   GtkType entry_type;
151
152   /* expanding selection */
153   GtkSheetCell selection_cell;
154
155   /* global selection button */
156   GtkWidget *button;
157
158   /* sheet state */
159   gint state;
160
161   /* selected range */
162   GtkSheetRange range;
163
164   /*the scrolling window and it's height and width to
165    * make things a little speedier */
166   GdkWindow *sheet_window;
167   guint sheet_window_width;
168   guint sheet_window_height;
169
170   /* sheet backing pixmap */
171   GdkPixmap *pixmap;
172
173   /* border shadow style */
174   GtkShadowType shadow_type;
175
176   /* Column Titles */
177   GdkRectangle column_title_area;
178   GdkWindow *column_title_window;
179   gboolean column_titles_visible;
180   /* TRUE if the cursor is over the column title window */
181   gboolean column_title_under;
182
183   /* Row Titles */
184   GdkRectangle row_title_area;
185   GdkWindow *row_title_window;
186   gboolean row_titles_visible;
187   /* TRUE if the cursor is over the row title window */
188   gboolean row_title_under;
189
190   /*scrollbars*/
191   GtkAdjustment *hadjustment;
192   GtkAdjustment *vadjustment;
193
194   /* xor GC for the verticle drag line */
195   GdkGC *xor_gc;
196
197   /* gc for drawing unselected cells */
198   GdkGC *fg_gc;
199   GdkGC *bg_gc;
200
201   /* cursor used to indicate dragging */
202   GdkCursor *cursor_drag;
203
204   /* the current x-pixel location of the xor-drag vline */
205   gint x_drag;
206
207   /* the current y-pixel location of the xor-drag hline */
208   gint y_drag;
209
210   /* current cell being dragged */
211   GtkSheetCell drag_cell;
212   /* current range being dragged */
213   GtkSheetRange drag_range;
214
215   /* Used for the subtitle (popups) */
216   gint motion_timer;
217   GtkSheetHoverTitle *hover_window;
218 };
219
220 struct _GtkSheetClass
221 {
222   GtkBinClass parent_class;
223
224  void (*set_scroll_adjustments) (GtkSheet *sheet,
225                                  GtkAdjustment *hadjustment,
226                                  GtkAdjustment *vadjustment);
227
228  void (*select_row)             (GtkSheet *sheet, gint row);
229
230  void (*select_column)          (GtkSheet *sheet, gint column);
231
232  void (*select_range)           (GtkSheet *sheet, GtkSheetRange *range);
233
234  void (*resize_range)           (GtkSheet *sheet,
235                                 GtkSheetRange *old_range,
236                                 GtkSheetRange *new_range);
237
238  void (*move_range)             (GtkSheet *sheet,
239                                 GtkSheetRange *old_range,
240                                 GtkSheetRange *new_range);
241
242  gboolean (*traverse)           (GtkSheet *sheet,
243                                 gint row, gint column,
244                                 gint *new_row, gint *new_column);
245
246  gboolean (*deactivate)         (GtkSheet *sheet,
247                                 gint row, gint column);
248
249  gboolean (*activate)           (GtkSheet *sheet,
250                                 gint row, gint column);
251
252  void (*changed)                (GtkSheet *sheet,
253                                 gint row, gint column);
254 };
255
256 GType gtk_sheet_get_type (void);
257 GtkType gtk_sheet_range_get_type (void);
258
259
260 /* create a new sheet */
261 GtkWidget * gtk_sheet_new (GSheetRow *vgeo, GSheetColumn *hgeo,
262                            GSheetModel *model);
263
264 /* create a new sheet with custom entry */
265 GtkWidget *
266 gtk_sheet_new_with_custom_entry         (GSheetRow *vgeo,
267                                          GSheetColumn *hgeo,
268                                          GtkType entry_type);
269 void
270 gtk_sheet_construct_with_custom_entry   (GtkSheet *sheet,
271                                          GSheetRow *vgeo,
272                                          GSheetColumn *hgeo,
273                                          GtkType entry_type);
274 /* Change entry */
275 void gtk_sheet_change_entry             (GtkSheet *sheet, GtkType entry_type);
276
277 GtkWidget *gtk_sheet_get_entry    (GtkSheet *sheet);
278
279
280 void gtk_sheet_get_selected_range (GtkSheet *sheet,
281                                          GtkSheetRange *range);
282
283 void gtk_sheet_show_grid          (GtkSheet *sheet,
284                                          gboolean show);
285
286 gboolean gtk_sheet_grid_visible   (GtkSheet *sheet);
287
288
289 /* scroll the viewing area of the sheet to the given column
290  * and row; row_align and col_align are between 0-1 representing the
291  * location the row should appear on the screen, 0.0 being top or left,
292  * 1.0 being bottom or right; if row or column is negative then there
293  * is no change */
294 void gtk_sheet_moveto (GtkSheet *sheet,
295                   gint row,
296                   gint column,
297                   gfloat row_align,
298                   gfloat col_align);
299
300
301 void gtk_sheet_show_row_titles          (GtkSheet *sheet);
302 void gtk_sheet_hide_row_titles          (GtkSheet *sheet);
303 void gtk_sheet_show_column_titles       (GtkSheet *sheet);
304 void gtk_sheet_hide_column_titles       (GtkSheet *sheet);
305
306 /* select the row. The range is then highlighted, and the bounds are stored
307  * in sheet->range  */
308 void gtk_sheet_select_row    (GtkSheet * sheet,  gint row);
309
310 /* select the column. The range is then highlighted, and the bounds are stored
311  * in sheet->range  */
312 void gtk_sheet_select_column (GtkSheet * sheet,  gint column);
313
314 /* highlight the selected range and store bounds in sheet->range */
315 void gtk_sheet_select_range (GtkSheet *sheet, const GtkSheetRange *range);
316
317 void gtk_sheet_get_visible_range (GtkSheet *sheet, GtkSheetRange *range);
318
319
320 /* obvious */
321 void gtk_sheet_unselect_range           (GtkSheet *sheet);
322
323 /* set active cell where the entry will be displayed
324  * returns FALSE if current cell can't be deactivated or
325  * requested cell can't be activated */
326 gboolean gtk_sheet_set_active_cell (GtkSheet *sheet,
327                                         gint row, gint column);
328
329 /* Sets *ROW and *COLUMN to be the coordinates of the active cell.
330    ROW and/or COLUMN may be null if the caller is not interested in their
331    values */
332 void gtk_sheet_get_active_cell (GtkSheet *sheet,
333                                         gint *row, gint *column);
334
335 /* get cell contents */
336 gchar *gtk_sheet_cell_get_text (const GtkSheet *sheet, gint row, gint col);
337
338 /* clear cell contents */
339 void gtk_sheet_cell_clear      (GtkSheet *sheet, gint row, gint col);
340
341 /* clear range contents. If range==NULL the whole sheet will be cleared */
342 void gtk_sheet_range_clear      (GtkSheet *sheet,
343                                          const GtkSheetRange *range);
344
345
346 /* get cell attributes of the given cell */
347 /* TRUE means that the cell is currently allocated */
348 gboolean gtk_sheet_get_attributes       (const GtkSheet *sheet,
349                                         gint row, gint col,
350                                         GtkSheetCellAttr *attributes);
351
352 void           gtk_sheet_set_model (GtkSheet *sheet,
353                                    GSheetModel *model);
354
355 GSheetModel * gtk_sheet_get_model (const GtkSheet *sheet);
356
357
358 G_END_DECLS
359
360
361 #endif /* __GTK_SHEET_H__ */
362
363