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