Removed unnecessary variable and consequently unreachable code.
[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->select_status */
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 };
88
89 struct _PsppireSheetHoverTitle
90 {
91   GtkWidget *window;
92   GtkWidget *label;
93   gint row, column;
94 };
95
96 enum
97   {
98     BG_COLOR,
99     GRID_COLOR,
100     n_COLORS
101   };
102
103 struct _PsppireSheet
104 {
105   GtkBin parent;
106
107   gboolean dispose_has_run;
108   PsppireAxis *haxis;
109   PsppireAxis *vaxis;
110
111   guint16 flags;
112
113   PsppireSheetModel *model;
114
115   /* Component colors */
116   GdkColor color[n_COLORS];
117   gboolean show_grid;
118
119   /* active cell */
120   PsppireSheetCell active_cell;
121
122   /* The GtkEntry used for editing the cells */
123   GtkWidget *entry_widget;
124
125   /* The type of entry_widget */
126   GtkType entry_type;
127
128   /* global selection button */
129   GtkWidget *button;
130
131   /* sheet state */
132   gint select_status;
133
134   /* selected range */
135   PsppireSheetRange range;
136
137   /* The space between a cell's contents and its border */
138   GtkBorder *cell_padding;
139
140   /* the scrolling window and its height and width to
141    * make things a little speedier */
142   GdkWindow *sheet_window;
143
144   /* border shadow style */
145   GtkShadowType shadow_type;
146
147   /* Column Titles */
148   GdkRectangle column_title_area;
149   GdkWindow *column_title_window;
150   gboolean column_titles_visible;
151   /* TRUE if the cursor is over the column title window */
152   gboolean column_title_under;
153
154   /* Row Titles */
155   GdkRectangle row_title_area;
156   GdkWindow *row_title_window;
157   gboolean row_titles_visible;
158   /* TRUE if the cursor is over the row title window */
159   gboolean row_title_under;
160
161   /*scrollbars*/
162   GtkAdjustment *hadjustment;
163   GtkAdjustment *vadjustment;
164
165   /* xor GC for the verticle drag line */
166   GdkGC *xor_gc;
167
168   /* gc for drawing unselected cells */
169   GdkGC *fg_gc;
170   GdkGC *bg_gc;
171
172   /* cursor used to indicate dragging */
173   GdkCursor *cursor_drag;
174
175   /* the current x-pixel location of the xor-drag vline */
176   gint x_drag;
177
178   /* the current y-pixel location of the xor-drag hline */
179   gint y_drag;
180
181   /* current cell being dragged */
182   PsppireSheetCell drag_cell;
183   /* current range being dragged */
184   PsppireSheetRange drag_range;
185
186   /* Used for the subtitle (popups) */
187   gint motion_timer;
188   PsppireSheetHoverTitle *hover_window;
189
190   gulong update_handler_id;
191 };
192
193 struct _PsppireSheetClass
194 {
195   GtkBinClass parent_class;
196
197  gboolean (*set_scroll_adjustments) (PsppireSheet *sheet,
198                                  GtkAdjustment *hadjustment,
199                                  GtkAdjustment *vadjustment);
200
201  void (*select_row)             (PsppireSheet *sheet, gint row);
202
203  void (*select_column)          (PsppireSheet *sheet, gint column);
204
205  void (*select_range)           (PsppireSheet *sheet, PsppireSheetRange *range);
206
207  void (*resize_range)           (PsppireSheet *sheet,
208                                 PsppireSheetRange *old_range,
209                                 PsppireSheetRange *new_range);
210
211  void (*move_range)             (PsppireSheet *sheet,
212                                 PsppireSheetRange *old_range,
213                                 PsppireSheetRange *new_range);
214
215  gboolean (*traverse)           (PsppireSheet *sheet,
216                                 gint row, gint column,
217                                 gint *new_row, gint *new_column);
218
219  gboolean (*activate)           (PsppireSheet *sheet,
220                                 gint row, gint column);
221
222  void (*changed)                (PsppireSheet *sheet,
223                                 gint row, gint column);
224 };
225
226 GType psppire_sheet_get_type (void);
227 GtkType psppire_sheet_range_get_type (void);
228
229
230 /* create a new sheet */
231 GtkWidget * psppire_sheet_new (PsppireSheetModel *model);
232
233 /* create a new sheet with custom entry */
234 GtkWidget *
235 psppire_sheet_new_with_custom_entry (GtkType entry_type);
236
237 /* Change entry */
238 void psppire_sheet_change_entry         (PsppireSheet *sheet, GtkType entry_type);
239
240 GtkEntry *psppire_sheet_get_entry    (PsppireSheet *sheet);
241
242
243 void psppire_sheet_get_selected_range (PsppireSheet *sheet,
244                                          PsppireSheetRange *range);
245
246 void psppire_sheet_show_grid      (PsppireSheet *sheet,
247                                          gboolean show);
248
249 gboolean psppire_sheet_grid_visible   (PsppireSheet *sheet);
250
251
252 /* scroll the viewing area of the sheet to the given column
253  * and row; row_align and col_align are between 0-1 representing the
254  * location the row should appear on the screen, 0.0 being top or left,
255  * 1.0 being bottom or right; if row or column is negative then there
256  * is no change */
257 void psppire_sheet_moveto (PsppireSheet *sheet,
258                   gint row,
259                   gint column,
260                   gfloat row_align,
261                   gfloat col_align);
262
263
264 void psppire_sheet_show_row_titles              (PsppireSheet *sheet);
265 void psppire_sheet_hide_row_titles              (PsppireSheet *sheet);
266 void psppire_sheet_show_column_titles       (PsppireSheet *sheet);
267 void psppire_sheet_hide_column_titles   (PsppireSheet *sheet);
268
269 /* select the row. The range is then highlighted, and the bounds are stored
270  * in sheet->range  */
271 void psppire_sheet_select_row    (PsppireSheet * sheet,  gint row);
272
273 /* select the column. The range is then highlighted, and the bounds are stored
274  * in sheet->range  */
275 void psppire_sheet_select_column (PsppireSheet * sheet,  gint column);
276
277 /* highlight the selected range and store bounds in sheet->range */
278 void psppire_sheet_select_range (PsppireSheet *sheet, const PsppireSheetRange *range);
279
280 void psppire_sheet_get_visible_range (PsppireSheet *sheet, PsppireSheetRange *range);
281
282
283 /* obvious */
284 void psppire_sheet_unselect_range               (PsppireSheet *sheet);
285
286 /* set active cell where the entry will be displayed */
287 void psppire_sheet_set_active_cell (PsppireSheet *sheet,
288                                 gint row, gint column);
289
290 /* Sets *ROW and *COLUMN to be the coordinates of the active cell.
291    ROW and/or COLUMN may be null if the caller is not interested in their
292    values */
293 void psppire_sheet_get_active_cell (PsppireSheet *sheet,
294                                         gint *row, gint *column);
295
296 /* get cell contents */
297 gchar *psppire_sheet_cell_get_text (const PsppireSheet *sheet, gint row, gint col);
298
299
300 void psppire_sheet_set_model (PsppireSheet *sheet,
301                                    PsppireSheetModel *model);
302
303 PsppireSheetModel * psppire_sheet_get_model (const PsppireSheet *sheet);
304
305
306 G_END_DECLS
307
308
309 #endif /* __PSPPIRE_SHEET_H__ */
310
311