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