Merge commit 'origin/stable'
[pspp-builds.git] / lib / gtk-contrib / psppire-sheet.h
1 /*
2    Copyright (C) 2006, 2008 Free Software Foundation
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17
18  This file is derived from the gtksheet.c and extensively modified for the
19  requirements of PSPPIRE.  The changes are copyright by the
20  Free Software Foundation.  The copyright notice for the original work is
21  below.
22
23
24  GtkSheet widget for Gtk+.
25  * Copyright (C) 1999-2001 Adrian E. Feiguin <adrian@ifir.ifir.edu.ar>
26  *
27  * Based on GtkClist widget by Jay Painter, but major changes.
28  * Memory allocation routines inspired on SC (Spreadsheet Calculator)
29  *
30  * This library is free software; you can redistribute it and/or
31  * modify it under the terms of the GNU Lesser General Public
32  * License as published by the Free Software Foundation; either
33  * version 2.1 of the License, or (at your option) any later version.
34  *
35  * This library is distributed in the hope that it will be useful,
36  * but WITHOUT ANY WARRANTY; without even the implied warranty of
37  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
38  * Lesser General Public License for more details.
39  *
40  * You should have received a copy of the GNU Lesser General Public
41  * License along with this library; if not, write to the Free Software
42  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
43  */
44
45 #ifndef __PSPPIRE_SHEET_H__
46 #define __PSPPIRE_SHEET_H__
47
48 #include <gtk/gtk.h>
49
50 #include "gtkextra-sheet.h"
51 #include <ui/gui/sheet/psppire-sheetmodel.h>
52 #include <ui/gui/sheet/psppire-axis.h>
53
54 G_BEGIN_DECLS
55
56 /* sheet->state */
57 enum
58 {
59   PSPPIRE_SHEET_NORMAL,
60   PSPPIRE_SHEET_ROW_SELECTED,
61   PSPPIRE_SHEET_COLUMN_SELECTED,
62   PSPPIRE_SHEET_RANGE_SELECTED
63 };
64
65
66 #define PSPPIRE_TYPE_SHEET_RANGE (psppire_sheet_range_get_type ())
67 #define PSPPIRE_TYPE_SHEET_CELL (psppire_sheet_cell_get_type ())
68 #define PSPPIRE_TYPE_SHEET (psppire_sheet_get_type ())
69
70 #define PSPPIRE_SHEET(obj)          GTK_CHECK_CAST (obj, psppire_sheet_get_type (), PsppireSheet)
71 #define PSPPIRE_SHEET_CLASS(klass)  GTK_CHECK_CLASS_CAST (klass, psppire_sheet_get_type (), PsppireSheetClass)
72 #define PSPPIRE_IS_SHEET(obj)       GTK_CHECK_TYPE (obj, psppire_sheet_get_type ())
73
74
75 typedef struct _PsppireSheetClass PsppireSheetClass;
76 typedef struct _PsppireSheetCellAttr     PsppireSheetCellAttr;
77
78 typedef struct _PsppireSheetHoverTitle PsppireSheetHoverTitle;
79
80
81 struct _PsppireSheetCellAttr
82 {
83   GtkJustification justification;
84   GdkColor foreground;
85   GdkColor background;
86   PsppireSheetCellBorder border;
87   gboolean is_editable;
88 };
89
90 struct _PsppireSheetHoverTitle
91 {
92   GtkWidget *window;
93   GtkWidget *label;
94   gint row, column;
95 };
96
97 enum
98   {
99     BG_COLOR,
100     GRID_COLOR,
101     n_COLORS
102   };
103
104 struct _PsppireSheet
105 {
106   GtkBin parent;
107
108   gboolean dispose_has_run;
109   PsppireAxis *haxis;
110   PsppireAxis *vaxis;
111
112   guint16 flags;
113
114   PsppireSheetModel *model;
115
116   GtkSelectionMode selection_mode;
117
118   /* Component colors */
119   GdkColor color[n_COLORS];
120   gboolean show_grid;
121
122   /* active cell */
123   PsppireSheetCell active_cell;
124
125   /* The GtkEntry used for editing the cells */
126   GtkWidget *entry_widget;
127
128   /* The type of entry_widget */
129   GtkType entry_type;
130
131   /* expanding selection */
132   PsppireSheetCell selection_cell;
133
134   /* global selection button */
135   GtkWidget *button;
136
137   /* sheet state */
138   gint state;
139
140   /* selected range */
141   PsppireSheetRange 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   PsppireSheetCell drag_cell;
186   /* current range being dragged */
187   PsppireSheetRange drag_range;
188
189   /* Used for the subtitle (popups) */
190   gint motion_timer;
191   PsppireSheetHoverTitle *hover_window;
192
193   gulong update_handler_id;
194 };
195
196 struct _PsppireSheetClass
197 {
198   GtkBinClass parent_class;
199
200  gboolean (*set_scroll_adjustments) (PsppireSheet *sheet,
201                                  GtkAdjustment *hadjustment,
202                                  GtkAdjustment *vadjustment);
203
204  void (*select_row)             (PsppireSheet *sheet, gint row);
205
206  void (*select_column)          (PsppireSheet *sheet, gint column);
207
208  void (*select_range)           (PsppireSheet *sheet, PsppireSheetRange *range);
209
210  void (*resize_range)           (PsppireSheet *sheet,
211                                 PsppireSheetRange *old_range,
212                                 PsppireSheetRange *new_range);
213
214  void (*move_range)             (PsppireSheet *sheet,
215                                 PsppireSheetRange *old_range,
216                                 PsppireSheetRange *new_range);
217
218  gboolean (*traverse)           (PsppireSheet *sheet,
219                                 gint row, gint column,
220                                 gint *new_row, gint *new_column);
221
222  gboolean (*activate)           (PsppireSheet *sheet,
223                                 gint row, gint column);
224
225  void (*changed)                (PsppireSheet *sheet,
226                                 gint row, gint column);
227 };
228
229 GType psppire_sheet_get_type (void);
230 GtkType psppire_sheet_range_get_type (void);
231
232
233 /* create a new sheet */
234 GtkWidget * psppire_sheet_new (PsppireSheetModel *model);
235
236 /* create a new sheet with custom entry */
237 GtkWidget *
238 psppire_sheet_new_with_custom_entry (GtkType entry_type);
239
240 /* Change entry */
241 void psppire_sheet_change_entry         (PsppireSheet *sheet, GtkType entry_type);
242
243 GtkEntry *psppire_sheet_get_entry    (PsppireSheet *sheet);
244
245
246 void psppire_sheet_get_selected_range (PsppireSheet *sheet,
247                                          PsppireSheetRange *range);
248
249 void psppire_sheet_show_grid      (PsppireSheet *sheet,
250                                          gboolean show);
251
252 gboolean psppire_sheet_grid_visible   (PsppireSheet *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 psppire_sheet_moveto (PsppireSheet *sheet,
261                   gint row,
262                   gint column,
263                   gfloat row_align,
264                   gfloat col_align);
265
266
267 void psppire_sheet_show_row_titles              (PsppireSheet *sheet);
268 void psppire_sheet_hide_row_titles              (PsppireSheet *sheet);
269 void psppire_sheet_show_column_titles       (PsppireSheet *sheet);
270 void psppire_sheet_hide_column_titles   (PsppireSheet *sheet);
271
272 /* select the row. The range is then highlighted, and the bounds are stored
273  * in sheet->range  */
274 void psppire_sheet_select_row    (PsppireSheet * sheet,  gint row);
275
276 /* select the column. The range is then highlighted, and the bounds are stored
277  * in sheet->range  */
278 void psppire_sheet_select_column (PsppireSheet * sheet,  gint column);
279
280 /* highlight the selected range and store bounds in sheet->range */
281 void psppire_sheet_select_range (PsppireSheet *sheet, const PsppireSheetRange *range);
282
283 void psppire_sheet_get_visible_range (PsppireSheet *sheet, PsppireSheetRange *range);
284
285
286 /* obvious */
287 void psppire_sheet_unselect_range               (PsppireSheet *sheet);
288
289 /* set active cell where the entry will be displayed */
290 void psppire_sheet_set_active_cell (PsppireSheet *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 psppire_sheet_get_active_cell (PsppireSheet *sheet,
297                                         gint *row, gint *column);
298
299 /* get cell contents */
300 gchar *psppire_sheet_cell_get_text (const PsppireSheet *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 psppire_sheet_get_attributes       (const PsppireSheet *sheet,
306                                         gint row, gint col,
307                                         PsppireSheetCellAttr *attributes);
308
309 void psppire_sheet_set_model (PsppireSheet *sheet,
310                                    PsppireSheetModel *model);
311
312 PsppireSheetModel * psppire_sheet_get_model (const PsppireSheet *sheet);
313
314
315 G_END_DECLS
316
317
318 #endif /* __PSPPIRE_SHEET_H__ */
319
320