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