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

4 5 6 7
#ifdef ENABLE_BONOBO
#    include <bonobo/gnome-container.h>
#endif

8 9
#include "solver.h"

10 11 12
#define SHEET_MAX_ROWS (16 * 1024)
#define SHEET_MAX_COLS 256

13 14
typedef GList ColStyleList;

15 16 17 18 19 20 21 22 23 24 25
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;
26 27

typedef struct {
28
	char       *filename;
29 30

        GtkWidget  *toplevel; 
Arturo Espinosa's avatar
Arturo Espinosa committed
31
	GtkWidget  *notebook;
32 33 34 35 36 37
	GtkWidget  *table;

	/* Edit area */
	GtkWidget  *ea_status;
	GtkWidget  *ea_button_box;
	GtkWidget  *ea_input;
Arturo Espinosa's avatar
Arturo Espinosa committed
38

39 40 41
        /* The status bar */
        GnomeAppBar * appbar;
  
Arturo Espinosa's avatar
Arturo Espinosa committed
42 43
	/* The auto-expression */
	ExprTree   *auto_expr;
44
	String     *auto_expr_desc;
Arturo Espinosa's avatar
Arturo Espinosa committed
45
	GnomeCanvasItem  *auto_expr_label;
Arturo Espinosa's avatar
Arturo Espinosa committed
46
	
Arturo Espinosa's avatar
Arturo Espinosa committed
47
	/* Styles */
Arturo Espinosa's avatar
Arturo Espinosa committed
48
	Style      style;
49 50

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

53
	
54 55 56
	/* A list with all of the formulas */
	GList      *formula_cell_list;

Arturo Espinosa's avatar
Arturo Espinosa committed
57 58
	/* A queue with the cells to be evaluated */
	GList      *eval_queue;
59
	int        max_iterations;
60

61
	int        generation;
62

63 64
	/* The clipboard for this workbook */
	CellRegion *clipboard_contents;
65 66

	gboolean   have_x_selection;
67

Miguel de Icaza's avatar
Miguel de Icaza committed
68 69 70
	/* The Symbol table used for naming cell ranges in the workbook */
	SymbolTable *symbol_names;
	
71 72 73 74 75
	/*
	 * This is  used during the clipboard paste command to pass information
	 * to the asyncronous paste callback
	 */
	void       *clipboard_paste_callback_data;
76 77

	void       *toolbar;
78

79 80
#ifdef ENABLE_BONOBO
	/* A GnomeContainer */
81
	GnomeContainer *gnome_container;
82
	
83
#endif
Arturo Espinosa's avatar
Arturo Espinosa committed
84 85
} Workbook;

86 87 88 89 90 91
typedef struct {
	int        base_col, base_row;
	int        start_col, start_row;
	int        end_col, end_row;
} SheetSelection;

92
typedef enum {
93
	/* Normal editing mode of the Sheet */
94
	SHEET_MODE_SHEET,
95 96

	/* Drawing object creation */
97 98 99
	SHEET_MODE_CREATE_LINE,
	SHEET_MODE_CREATE_BOX,
	SHEET_MODE_CREATE_OVAL,
Miguel de Icaza's avatar
New:  
Miguel de Icaza committed
100
	SHEET_MODE_CREATE_ARROW,
101 102 103 104 105

	/* Selection for the region for a Graphics object */
	SHEET_MODE_CREATE_GRAPHIC,

	/* Object is selected */
Miguel de Icaza's avatar
New:  
Miguel de Icaza committed
106
	SHEET_MODE_OBJECT_SELECTED,
107 108
} SheetModeType;

109
typedef struct _Sheet {
Miguel de Icaza's avatar
Miguel de Icaza committed
110
	int         signature;
111
	
Miguel de Icaza's avatar
Miguel de Icaza committed
112 113
	Workbook    *workbook;
	GList       *sheet_views;
114
	
Miguel de Icaza's avatar
Miguel de Icaza committed
115
	char        *name;
116

Miguel de Icaza's avatar
Miguel de Icaza committed
117
	GList       *style_list;	/* The list of styles applied to the sheets */
118

Miguel de Icaza's avatar
Miguel de Icaza committed
119 120
	ColRowInfo  default_col_style;
	GList       *cols_info;
121

Miguel de Icaza's avatar
Miguel de Icaza committed
122 123
	ColRowInfo  default_row_style;
	GList       *rows_info;
Arturo Espinosa's avatar
Arturo Espinosa committed
124

Miguel de Icaza's avatar
Miguel de Icaza committed
125
	GHashTable  *cell_hash;	/* The cells in hashed format */
126

Miguel de Icaza's avatar
Miguel de Icaza committed
127
	GList       *selections;
128

Miguel de Icaza's avatar
Miguel de Icaza committed
129 130
	int         max_col_used;
	int         max_row_used;
131

Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
132 133
	int         cursor_col, cursor_row;
	
134 135 136
	/* The list of cells that have a comment */
	GList       *comment_list;
	
Miguel de Icaza's avatar
Miguel de Icaza committed
137
	double      last_zoom_factor_used;
Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
138

139 140
	/* Objects */
	SheetModeType mode;	/* Sheet mode */
Miguel de Icaza's avatar
Miguel de Icaza committed
141 142 143 144
	GList       *objects;	/* List of objects in the spreadsheet */
	GList       *coords;	/* During creation time: keeps click coordinates */
	void        *current_object;

Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
145 146 147 148
	/*
	 * When editing a cell: the cell (may be NULL) and
	 * the original text of the cell
	 */
Miguel de Icaza's avatar
Miguel de Icaza committed
149 150 151
	String      *editing_saved_text;
	Cell        *editing_cell;
	int         editing;
Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
152
	
Miguel de Icaza's avatar
Miguel de Icaza committed
153
	gboolean    modified;
154
	
155 156 157 158
	/* For walking trough a selection */
	struct {
		SheetSelection *current;
	} walk_info;
159 160 161

        /* Solver parameters */
        SolverParameters solver_parameters;
162 163
} Sheet;

164 165 166
#define SHEET_SIGNATURE 0x12349876
#define IS_SHEET(x) (((Sheet *) x)->signature == SHEET_SIGNATURE)

Arturo Espinosa's avatar
Arturo Espinosa committed
167 168 169
typedef  void (*sheet_col_row_callback)(Sheet *sheet, ColRowInfo *ci,
					void *user_data);

Arturo Espinosa's avatar
Arturo Espinosa committed
170 171
typedef  int (*sheet_cell_foreach_callback)(Sheet *sheet, int col, int row,
					    Cell *cell, void *user_data);
172

173
Sheet      *sheet_new                  	 (Workbook *wb, const char *name);
Miguel de Icaza's avatar
Miguel de Icaza committed
174
void        sheet_rename                 (Sheet *sheet, const char *new_name);
Arturo Espinosa's avatar
Arturo Espinosa committed
175 176 177 178 179 180 181 182
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
183
void        sheet_cursor_set             (Sheet *sheet,
184
					  int base_col,  int base_row,
Arturo Espinosa's avatar
Arturo Espinosa committed
185 186 187
					  int start_col, int start_row,
					  int end_col,   int end_row);
void        sheet_cursor_move            (Sheet *sheet, int col, int row);
188
void        sheet_make_cell_visible      (Sheet *sheet, int col, int row);
189 190

/* Selection management */
191
void        sheet_select_all             (Sheet *sheet);
192
int         sheet_is_all_selected        (Sheet *sheet);
193 194
void        sheet_selection_append       (Sheet *sheet, int col, int row);
void        sheet_selection_extend_to    (Sheet *sheet, int col, int row);
195 196 197
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
198 199
void        sheet_selection_reset        (Sheet *sheet);
void        sheet_selection_reset_only   (Sheet *sheet);
200
int         sheet_selection_equal        (SheetSelection *a, SheetSelection *b);
Arturo Espinosa's avatar
Arturo Espinosa committed
201 202
void        sheet_selection_append_range (Sheet *sheet,
					  int base_col,  int base_row,
203 204
					  int start_col, int start_row,
					  int end_col,   int end_row);
205 206 207 208
int         sheet_selection_first_range  (Sheet *sheet,
					  int *base_col,  int *base_row,
					  int *start_col, int *start_row,
					  int *end_col,   int *end_row);
Miguel de Icaza's avatar
Today:  
Miguel de Icaza committed
209
CellList   *sheet_selection_to_list      (Sheet *sheet);
210

Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
211
/* Operations on the selection */
212
void        sheet_selection_clear             (Sheet *sheet);
213
void        sheet_selection_clear_content     (Sheet *sheet);
214
void        sheet_selection_clear_comments    (Sheet *sheet);
215
void        sheet_selection_clear_formats     (Sheet *sheet);
Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
216

217
/* Cut/Copy/Paste on the workbook selection */
218 219 220
gboolean    sheet_selection_copy              (Sheet *sheet);
gboolean    sheet_selection_cut               (Sheet *sheet);
void        sheet_selection_paste             (Sheet *sheet,
221
					       int dest_col,    int dest_row,
Miguel de Icaza's avatar
Miguel de Icaza committed
222
					       int paste_flags, guint32 time32);
223 224 225 226
int         sheet_selection_walk_step         (Sheet *sheet,
					       int   forward,     int horizontal,
					       int   current_col, int current_row,
					       int   *new_col,    int *new_row);
227 228 229
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
230

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

Arturo Espinosa's avatar
Arturo Espinosa committed
233
/* Cell management */
Miguel de Icaza's avatar
Miguel de Icaza committed
234
void        sheet_set_text                (Sheet *sheet, int col, int row,
235
					   const char *str);
236 237 238 239 240 241 242 243 244 245
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);
246
Cell       *sheet_cell_fetch              (Sheet *sheet, int col, int row);
247 248 249
void        sheet_cell_comment_link       (Cell *cell);
void        sheet_cell_comment_unlink     (Cell *cell);

250 251
void        sheet_cell_formula_link       (Cell *cell);
void        sheet_cell_formula_unlink     (Cell *cell);
252 253
gboolean    sheet_is_region_empty_or_selected (Sheet *sheet, int start_col, int start_row,
					       int end_col, int end_row);
Arturo Espinosa's avatar
Arturo Espinosa committed
254

Arturo Espinosa's avatar
Arturo Espinosa committed
255
/* Create new ColRowInfos from the default sheet style */
256 257 258 259
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
260 261

/* Duplicates the information of a col/row */
262
ColRowInfo *sheet_duplicate_colrow        (ColRowInfo *original);
Arturo Espinosa's avatar
Arturo Espinosa committed
263 264

/* Retrieve information from a col/row */
265 266
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
267

Arturo Espinosa's avatar
Arturo Espinosa committed
268
/* Returns a pointer to a ColRowInfo: existed or freshly created */
269 270
ColRowInfo *sheet_row_get                 (Sheet *sheet, int pos);
ColRowInfo *sheet_col_get                 (Sheet *sheet, int pos);
Arturo Espinosa's avatar
Arturo Espinosa committed
271

Arturo Espinosa's avatar
Arturo Espinosa committed
272
/* Add a ColRowInfo to the Sheet */
273 274
void        sheet_col_add                 (Sheet *sheet, ColRowInfo *cp);
void        sheet_row_add                 (Sheet *sheet, ColRowInfo *cp);
Arturo Espinosa's avatar
Arturo Espinosa committed
275 276

/* Measure distances in pixels from one col/row to another */
277 278
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
279
 
280 281 282 283 284 285 286 287 288
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);
289 290 291
void        sheet_clear_region_comments   (Sheet *sheet,
				           int start_col, int start_row,
				           int end_col,   int end_row);	
Arturo Espinosa's avatar
Arturo Espinosa committed
292 293

/* Sets the width/height of a column row in terms of pixels */
294 295
void        sheet_col_set_width           (Sheet *sheet,
				           int col, int width);
296 297
void        sheet_col_info_set_width      (Sheet *sheet,
				           ColRowInfo *ci, int width);
298 299 300
void        sheet_row_set_height          (Sheet *sheet,
				           int row, int width,
				           gboolean height_set_by_user);
301 302 303
void        sheet_row_info_set_height     (Sheet *sheet,
				           ColRowInfo *ri, int width,
				           gboolean height_set_by_user);
304 305 306 307 308
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
309
				       
310 311 312
Style      *sheet_style_compute           (Sheet *sheet,
					   int col, int row,
					   int *non_default_style_flags);
Arturo Espinosa's avatar
Arturo Espinosa committed
313

314
/* Redraw */
315 316 317 318 319 320
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
321
				       
322
void        sheet_update_auto_expr        (Sheet *sheet);
323

324 325
void        sheet_mark_clean              (Sheet *sheet);

326
/* Sheet information manipulation */
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
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);
343
Sheet      *sheet_lookup_by_name          (Sheet *base, const char *name);
Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
344 345 346 347 348 349

/*
 * Sheet visual editing
 */
void        sheet_start_editing_at_cursor (Sheet *sheet);
void        sheet_set_current_value       (Sheet *sheet);
350
void        sheet_accept_pending_input    (Sheet *sheet);
Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
351 352
void        sheet_cancel_pending_input    (Sheet *sheet);
void        sheet_load_cell_val           (Sheet *sheet);
353 354 355

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
356

357 358 359 360 361 362
/*
 * Event state manipulation (for mode operation)
 */
void        sheet_set_mode_type           (Sheet *sheet, SheetModeType type);


Miguel de Icaza's avatar
Miguel de Icaza committed
363 364 365
/*
 * Callback routines.
 */
366
void        sheet_fill_selection_with     (Sheet *sheet, const char *text);
Miguel de Icaza's avatar
Miguel de Icaza committed
367

Miguel de Icaza's avatar
New:  
Miguel de Icaza committed
368 369 370 371 372 373
/*
 * Hiding/showing the cursor
 */
void        sheet_show_cursor             (Sheet *sheet);
void        sheet_hide_cursor             (Sheet *sheet);

374
char        *cellref_name                 (CellRef *cell_ref,
375 376 377 378
					   Sheet *eval_sheet,
					   int eval_col,
					   int eval_row);

379 380 381 382 383
/*
 * Sheet, Bobobo objects
 */
void sheet_insert_object (Sheet *sheet, char *repoid);

Arturo Espinosa's avatar
Arturo Espinosa committed
384 385 386
/*
 * Workbook
 */
387
Workbook   *workbook_new                 (void);
Arturo Espinosa's avatar
Arturo Espinosa committed
388
void        workbook_destroy             (Workbook *wb);
389
Workbook   *workbook_new_with_sheets     (int sheet_count);
390

391 392
void        workbook_set_filename        (Workbook *, const char *);
void        workbook_set_title           (Workbook *, const char *);
393
Workbook   *workbook_read                (const char *filename);
394

395 396
void        workbook_save_as             (Workbook *);
void        workbook_save                (Workbook *);
397
void        workbook_attach_sheet        (Workbook *, Sheet *);
398
gboolean    workbook_detach_sheet        (Workbook *, Sheet *, gboolean);
399
Sheet      *workbook_focus_current_sheet (Workbook *wb);
Arturo Espinosa's avatar
Arturo Espinosa committed
400
Sheet      *workbook_get_current_sheet   (Workbook *wb);
401
char       *workbook_sheet_get_free_name (Workbook *wb);
402
void        workbook_auto_expr_label_set (Workbook *wb, const char *text);
403
void        workbook_next_generation     (Workbook *wb);
404 405
void        workbook_set_region_status   (Workbook *wb, const char *str);
int         workbook_parse_and_jump      (Workbook *wb, const char *text);
406
Sheet      *workbook_sheet_lookup        (Workbook *wb, const char *sheet_name);
407
void        workbook_mark_clean          (Workbook *wb);
408
gboolean    workbook_rename_sheet        (Workbook *wb,
Miguel de Icaza's avatar
Miguel de Icaza committed
409 410
					  const char *old_name,
					  const char *new_name);
411
int         workbook_sheet_count         (Workbook *wb);
Arturo Espinosa's avatar
Arturo Espinosa committed
412
gboolean    workbook_can_detach_sheet    (Workbook *wb, Sheet *sheet);
413
GList      *workbook_sheets              (Workbook *wb);
Arturo Espinosa's avatar
Arturo Espinosa committed
414

Arturo Espinosa's avatar
Arturo Espinosa committed
415 416 417 418
/*
 * Does any pending recalculations
 */
void        workbook_recalc              (Workbook *wb);
419
void        workbook_recalc_all          (Workbook *wb);
Arturo Espinosa's avatar
Arturo Espinosa committed
420

421 422 423 424
/*
 * Callback routine: invoked when the first view ItemGrid
 * is realized to allocate the default styles
 */
425
void     workbook_realized            (Workbook *, GdkWindow *);
426

427 428 429 430 431
typedef gboolean (*WorkbookCallback)(Workbook *, gpointer data);

void     workbook_foreach             (WorkbookCallback cback,
				       gpointer data);

432 433 434 435 436 437 438 439


void	workbook_fixup_references	(Workbook *wb, int col, int row,
					 int coldelta, int rowdelta);

void	workbook_invalidate_references	(Workbook *wb, int col, int row,
					 int colcount, int rowcount);

Miguel de Icaza's avatar
New:  
Miguel de Icaza committed
440 441 442 443 444 445 446 447 448 449 450 451
/*
 * Feedback routines
 */
typedef enum {
	WORKBOOK_FEEDBACK_BOLD,
	WORKBOOK_FEEDBACK_ITALIC
} WorkbookFeedbackType;

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

452
extern   Workbook *current_workbook;
453
#endif /* GNUMERIC_SHEET_H */
Miguel de Icaza's avatar
New:  
Miguel de Icaza committed
454