sheet.h 12.4 KB
Newer Older
1 2
#ifndef GNUMERIC_SHEET_H
#define GNUMERIC_SHEET_H
3

4 5 6
#define SHEET_MAX_ROWS (16 * 1024)
#define SHEET_MAX_COLS 256

7 8
typedef GList ColStyleList;

9 10 11 12 13 14 15 16 17 18 19
typedef struct {
	int start_col, start_row;
	int end_col, end_row;
} Range;

gboolean   range_contains (Range *range, int col, int row);

typedef struct {
	Range  range;
	Style  *style;
} StyleRegion;
20 21

typedef struct {
22 23
	char       *filename;
	
Arturo Espinosa's avatar
Arturo Espinosa committed
24 25
	GtkWidget  *toplevel;
	GtkWidget  *notebook;
26 27 28 29 30 31
	GtkWidget  *table;

	/* Edit area */
	GtkWidget  *ea_status;
	GtkWidget  *ea_button_box;
	GtkWidget  *ea_input;
Arturo Espinosa's avatar
Arturo Espinosa committed
32 33 34

	/* The auto-expression */
	ExprTree   *auto_expr;
35
	String     *auto_expr_desc;
Arturo Espinosa's avatar
Arturo Espinosa committed
36
	GnomeCanvasItem  *auto_expr_label;
Arturo Espinosa's avatar
Arturo Espinosa committed
37
	
Arturo Espinosa's avatar
Arturo Espinosa committed
38
	/* Styles */
Arturo Espinosa's avatar
Arturo Espinosa committed
39
	Style      style;
40 41

	/* The sheets */ 
Arturo Espinosa's avatar
Arturo Espinosa committed
42
	GHashTable *sheets;	/* keeps a list of the Sheets on this workbook */
43

44
	
45 46 47
	/* A list with all of the formulas */
	GList      *formula_cell_list;

Arturo Espinosa's avatar
Arturo Espinosa committed
48 49
	/* A queue with the cells to be evaluated */
	GList      *eval_queue;
50
	int        max_iterations;
51

52
	int        generation;
53

54 55
	/* The clipboard for this workbook */
	CellRegion *clipboard_contents;
56 57

	gboolean   have_x_selection;
58 59 60 61 62 63

	/*
	 * This is  used during the clipboard paste command to pass information
	 * to the asyncronous paste callback
	 */
	void       *clipboard_paste_callback_data;
Arturo Espinosa's avatar
Arturo Espinosa committed
64 65
} Workbook;

66 67 68 69 70 71
typedef struct {
	int        base_col, base_row;
	int        start_col, start_row;
	int        end_col, end_row;
} SheetSelection;

72 73 74 75 76
typedef enum {
	SHEET_MODE_SHEET,
	SHEET_MODE_CREATE_LINE,
	SHEET_MODE_CREATE_BOX,
	SHEET_MODE_CREATE_OVAL,
Miguel de Icaza's avatar
New:  
Miguel de Icaza committed
77 78
	SHEET_MODE_CREATE_ARROW,
	SHEET_MODE_OBJECT_SELECTED,
79 80
} SheetModeType;

Arturo Espinosa's avatar
Arturo Espinosa committed
81
typedef struct {
82 83
	int        signature;
	
Arturo Espinosa's avatar
Arturo Espinosa committed
84
	Workbook   *workbook;
Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
85
	GList      *sheet_views;
86
	
87
	char       *name;
88 89

	GList      *style_list;	/* The list of styles applied to the sheets */
90

91
	ColRowInfo default_col_style;
92
	GList      *cols_info;
93

94
	ColRowInfo default_row_style;
95
	GList      *rows_info;
Arturo Espinosa's avatar
Arturo Espinosa committed
96

97
	GHashTable *cell_hash;	/* The cells in hashed format */
98 99 100 101 102

	GList      *selections;

	int        max_col_used;
	int        max_row_used;
103

Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
104 105
	int         cursor_col, cursor_row;
	
106 107
	/* The list of formulas */
	GList      *formula_cell_list;
108

Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
109 110
	double     last_zoom_factor_used;

111 112 113 114
	/* Objects */
	SheetModeType mode;	/* Sheet mode */
	GList      *objects;	/* List of objects in the spreadsheet */
	GList      *coords;	/* During creation time: keeps click coordinates */
115
	void       *current_object;
116
	
Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
117 118 119 120 121 122 123 124
	/*
	 * When editing a cell: the cell (may be NULL) and
	 * the original text of the cell
	 */
	String    *editing_saved_text;
	Cell      *editing_cell;
	int        editing;
	
125 126
	gboolean   modified;
	
127 128 129 130
	/* For walking trough a selection */
	struct {
		SheetSelection *current;
	} walk_info;
131 132
} Sheet;

133 134 135
#define SHEET_SIGNATURE 0x12349876
#define IS_SHEET(x) (((Sheet *) x)->signature == SHEET_SIGNATURE)

Arturo Espinosa's avatar
Arturo Espinosa committed
136 137 138
typedef  void (*sheet_col_row_callback)(Sheet *sheet, ColRowInfo *ci,
					void *user_data);

Arturo Espinosa's avatar
Arturo Espinosa committed
139 140
typedef  int (*sheet_cell_foreach_callback)(Sheet *sheet, int col, int row,
					    Cell *cell, void *user_data);
141

Arturo Espinosa's avatar
Arturo Espinosa committed
142 143 144 145 146 147 148 149 150
Sheet      *sheet_new                  	 (Workbook *wb, char *name);
void        sheet_destroy              	 (Sheet *sheet);
void        sheet_foreach_col          	 (Sheet *sheet,
					  sheet_col_row_callback callback,
					  void *user_data);
void        sheet_foreach_row          	 (Sheet *sheet,
					  sheet_col_row_callback,
					  void *user_data);
void        sheet_set_zoom_factor      	 (Sheet *sheet, double factor);
Arturo Espinosa's avatar
Arturo Espinosa committed
151 152 153 154
void        sheet_cursor_set             (Sheet *sheet,
					  int start_col, int start_row,
					  int end_col,   int end_row);
void        sheet_cursor_move            (Sheet *sheet, int col, int row);
155 156

/* Selection management */
157
void        sheet_select_all             (Sheet *sheet);
158
int         sheet_is_all_selected        (Sheet *sheet);
159 160
void        sheet_selection_append       (Sheet *sheet, int col, int row);
void        sheet_selection_extend_to    (Sheet *sheet, int col, int row);
161 162 163
void	    sheet_selection_set		 (Sheet *sheet,
					  int start_col, int start_row,
					  int end_col, int end_row);
Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
164 165
void        sheet_selection_reset        (Sheet *sheet);
void        sheet_selection_reset_only   (Sheet *sheet);
166
int         sheet_selection_equal        (SheetSelection *a, SheetSelection *b);
Arturo Espinosa's avatar
Arturo Espinosa committed
167 168
void        sheet_selection_append_range (Sheet *sheet,
					  int base_col,  int base_row,
169 170
					  int start_col, int start_row,
					  int end_col,   int end_row);
Miguel de Icaza's avatar
Today:  
Miguel de Icaza committed
171
CellList   *sheet_selection_to_list      (Sheet *sheet);
172

Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
173
/* Operations on the selection */
174 175 176
void        sheet_selection_clear_content     (Sheet *sheet);
void        sheet_selection_clear_formats     (Sheet *sheet);
void        sheet_selection_clear             (Sheet *sheet);
Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
177

178
/* Cut/Copy/Paste on the workbook selection */
179 180 181
gboolean    sheet_selection_copy              (Sheet *sheet);
gboolean    sheet_selection_cut               (Sheet *sheet);
void        sheet_selection_paste             (Sheet *sheet,
182 183
					       int dest_col,    int dest_row,
					       int paste_flags, guint32 time);
184 185 186 187
int         sheet_selection_walk_step         (Sheet *sheet,
					       int   forward,     int horizontal,
					       int   current_col, int current_row,
					       int   *new_col,    int *new_row);
188 189 190
void        sheet_selection_extend_horizontal (Sheet *sheet, int count);
void        sheet_selection_extend_vertical   (Sheet *sheet, int count);
int         sheet_selection_is_cell_selected  (Sheet *sheet, int col, int row);
Arturo Espinosa's avatar
Arturo Espinosa committed
191

Miguel de Icaza's avatar
Today:  
Miguel de Icaza committed
192 193
gboolean    sheet_verify_selection_simple     (Sheet *sheet, char *command_name);

Arturo Espinosa's avatar
Arturo Espinosa committed
194
/* Cell management */
Miguel de Icaza's avatar
Miguel de Icaza committed
195 196
void        sheet_set_text                (Sheet *sheet, int col, int row,
					   char *str);
197 198 199 200 201 202 203 204 205 206
Cell       *sheet_cell_new                (Sheet *sheet, int col, int row);
void        sheet_cell_add                (Sheet *sheet, Cell *cell,
				           int col, int row);
void        sheet_cell_remove             (Sheet *sheet, Cell *cell);
int         sheet_cell_foreach_range      (Sheet *sheet, int only_existing,
				           int start_col, int start_row,
				           int end_col, int end_row,
				           sheet_cell_foreach_callback callback,
				           void *closure);
Cell       *sheet_cell_get                (Sheet *sheet, int col, int row);
207
Cell       *sheet_cell_fetch              (Sheet *sheet, int col, int row);
208 209
void        sheet_cell_formula_link       (Cell *cell);
void        sheet_cell_formula_unlink     (Cell *cell);
Arturo Espinosa's avatar
Arturo Espinosa committed
210

Arturo Espinosa's avatar
Arturo Espinosa committed
211
/* Create new ColRowInfos from the default sheet style */
212 213 214 215
ColRowInfo *sheet_col_new                  (Sheet *sheet);
ColRowInfo *sheet_row_new                  (Sheet *sheet);
int         sheet_row_check_bound          (int row, int diff);
int         sheet_col_check_bound          (int col, int diff);
Arturo Espinosa's avatar
Arturo Espinosa committed
216 217

/* Duplicates the information of a col/row */
218
ColRowInfo *sheet_duplicate_colrow        (ColRowInfo *original);
Arturo Espinosa's avatar
Arturo Espinosa committed
219 220

/* Retrieve information from a col/row */
221 222
ColRowInfo *sheet_col_get_info            (Sheet *sheet, int col);
ColRowInfo *sheet_row_get_info            (Sheet *sheet, int row);
Arturo Espinosa's avatar
Arturo Espinosa committed
223

Arturo Espinosa's avatar
Arturo Espinosa committed
224
/* Returns a pointer to a ColRowInfo: existed or freshly created */
225 226
ColRowInfo *sheet_row_get                 (Sheet *sheet, int pos);
ColRowInfo *sheet_col_get                 (Sheet *sheet, int pos);
Arturo Espinosa's avatar
Arturo Espinosa committed
227

Arturo Espinosa's avatar
Arturo Espinosa committed
228
/* Add a ColRowInfo to the Sheet */
229 230
void        sheet_col_add                 (Sheet *sheet, ColRowInfo *cp);
void        sheet_row_add                 (Sheet *sheet, ColRowInfo *cp);
Arturo Espinosa's avatar
Arturo Espinosa committed
231 232

/* Measure distances in pixels from one col/row to another */
233 234
int         sheet_col_get_distance        (Sheet *sheet, int from_col, int to_col);
int         sheet_row_get_distance        (Sheet *sheet, int from_row, int to_row);
Arturo Espinosa's avatar
Arturo Espinosa committed
235
 
236 237 238 239 240 241 242 243 244
void        sheet_clear_region            (Sheet *sheet,
				           int start_col, int start_row,
				           int end_col,   int end_row);
void        sheet_clear_region_formats    (Sheet *sheet,
				           int start_col, int start_row,
				           int end_col,   int end_row);
void        sheet_clear_region_content    (Sheet *sheet,
				           int start_col, int start_row,
				           int end_col,   int end_row);
Arturo Espinosa's avatar
Arturo Espinosa committed
245 246

/* Sets the width/height of a column row in terms of pixels */
247 248
void        sheet_col_set_width           (Sheet *sheet,
				           int col, int width);
249 250
void        sheet_col_info_set_width      (Sheet *sheet,
				           ColRowInfo *ci, int width);
251 252 253
void        sheet_row_set_height          (Sheet *sheet,
				           int row, int width,
				           gboolean height_set_by_user);
254 255 256
void        sheet_row_info_set_height     (Sheet *sheet,
				           ColRowInfo *ri, int width,
				           gboolean height_set_by_user);
257 258 259 260 261
void        sheet_row_set_internal_height (Sheet *sheet, ColRowInfo *ri, int height);
void        sheet_col_set_selection       (Sheet *sheet,
					   ColRowInfo *ci, int value);
void        sheet_row_set_selection       (Sheet *sheet,
					   ColRowInfo *ri, int value);
Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
262
				       
263 264 265
Style      *sheet_style_compute           (Sheet *sheet,
					   int col, int row,
					   int *non_default_style_flags);
Arturo Espinosa's avatar
Arturo Espinosa committed
266

267
/* Redraw */
268 269 270 271 272 273
void        sheet_compute_visible_ranges  (Sheet *sheet);
void        sheet_redraw_cell_region      (Sheet *sheet,
				           int start_col, int start_row,
				           int end_col,   int end_row);
void        sheet_redraw_selection        (Sheet *sheet, SheetSelection *ss);
void        sheet_redraw_all              (Sheet *sheet);
Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
274
				       
275
void        sheet_update_auto_expr        (Sheet *sheet);
276

277
/* Sheet information manipulation */
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
void        sheet_insert_col              (Sheet *sheet,  int col, int count);
void        sheet_delete_col              (Sheet *sheet,  int col, int count);
void        sheet_insert_row              (Sheet *sheet,  int row, int count);
void        sheet_delete_row              (Sheet *sheet,  int row, int count);
void        sheet_shift_row               (Sheet *sheet,  int col, int row, int count);
void        sheet_shift_rows              (Sheet *sheet,  int col,
				           int start_row, int end_row, int count);
void        sheet_shift_col               (Sheet *sheet,  int col, int row, int count);
void        sheet_shift_cols              (Sheet *sheet,
				           int start_col, int end_col,
				           int row,       int count);

void        sheet_style_attach            (Sheet *sheet,
					   int    start_col, int start_row,
					   int    end_col,   int end_row,
					   Style  *style);
Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
294 295 296 297 298 299

/*
 * Sheet visual editing
 */
void        sheet_start_editing_at_cursor (Sheet *sheet);
void        sheet_set_current_value       (Sheet *sheet);
300
void        sheet_accept_pending_input    (Sheet *sheet);
Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
301 302
void        sheet_cancel_pending_input    (Sheet *sheet);
void        sheet_load_cell_val           (Sheet *sheet);
303 304 305

int         sheet_col_selection_type      (Sheet *sheet, int col);
int         sheet_row_selection_type      (Sheet *sheet, int row);
Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
306

307 308 309 310 311 312
/*
 * Event state manipulation (for mode operation)
 */
void        sheet_set_mode_type           (Sheet *sheet, SheetModeType type);


Miguel de Icaza's avatar
Miguel de Icaza committed
313 314 315 316 317
/*
 * Callback routines.
 */
void        sheet_fill_selection_with     (Sheet *sheet, char *text);

Miguel de Icaza's avatar
New:  
Miguel de Icaza committed
318 319 320 321 322 323
/*
 * Hiding/showing the cursor
 */
void        sheet_show_cursor             (Sheet *sheet);
void        sheet_hide_cursor             (Sheet *sheet);

Arturo Espinosa's avatar
Arturo Espinosa committed
324 325 326
/*
 * Workbook
 */
327
Workbook   *workbook_new                 (void);
Arturo Espinosa's avatar
Arturo Espinosa committed
328
void        workbook_destroy             (Workbook *wb);
329
Workbook   *workbook_new_with_sheets     (int sheet_count);
330

331 332 333
void        workbook_set_filename        (Workbook *, char *);
void        workbook_set_title           (Workbook *, char *);

334 335
void        workbook_save_as             (Workbook *);
void        workbook_save                (Workbook *);
336 337
void        workbook_attach_sheet        (Workbook *, Sheet *);
Sheet      *workbook_focus_current_sheet (Workbook *wb);
Arturo Espinosa's avatar
Arturo Espinosa committed
338
Sheet      *workbook_get_current_sheet   (Workbook *wb);
339
void        workbook_auto_expr_label_set (Workbook *wb, char *text);
340
void        workbook_next_generation     (Workbook *wb);
341 342
void        workbook_set_region_status   (Workbook *wb, char *str);
int         workbook_parse_and_jump      (Workbook *wb, char *text);
Arturo Espinosa's avatar
Arturo Espinosa committed
343

Arturo Espinosa's avatar
Arturo Espinosa committed
344 345 346 347
/*
 * Does any pending recalculations
 */
void        workbook_recalc              (Workbook *wb);
348
void        workbook_recalc_all          (Workbook *wb);
Arturo Espinosa's avatar
Arturo Espinosa committed
349

350 351 352 353
/*
 * Callback routine: invoked when the first view ItemGrid
 * is realized to allocate the default styles
 */
354
void     workbook_realized            (Workbook *, GdkWindow *);
355

Miguel de Icaza's avatar
New:  
Miguel de Icaza committed
356 357 358 359 360 361 362 363 364 365 366 367
/*
 * Feedback routines
 */
typedef enum {
	WORKBOOK_FEEDBACK_BOLD,
	WORKBOOK_FEEDBACK_ITALIC
} WorkbookFeedbackType;

void     workbook_feedback_set        (Workbook *,
				       WorkbookFeedbackType type,
				       void *data);

368
extern   Workbook *current_workbook;
369
#endif /* GNUMERIC_SHEET_H */
Miguel de Icaza's avatar
New:  
Miguel de Icaza committed
370