sheet.h 9.51 KB
Newer Older
Arturo Espinosa's avatar
Arturo Espinosa committed
1 2
#ifndef SHEET_H
#define 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 {
Arturo Espinosa's avatar
Arturo Espinosa committed
22 23
	GtkWidget  *toplevel;
	GtkWidget  *notebook;
24 25 26 27 28 29
	GtkWidget  *table;

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

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

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

42
	
43 44 45
	/* A list with all of the formulas */
	GList      *formula_cell_list;

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

50 51
	int        generation;
	
52 53
	/* The clipboard for this workbook */
	CellRegion *clipboard_contents;
Arturo Espinosa's avatar
Arturo Espinosa committed
54 55
} Workbook;

56 57 58 59 60 61
typedef struct {
	int        base_col, base_row;
	int        start_col, start_row;
	int        end_col, end_row;
} SheetSelection;

Arturo Espinosa's avatar
Arturo Espinosa committed
62
typedef struct {
63 64
	int        signature;
	
Arturo Espinosa's avatar
Arturo Espinosa committed
65
	Workbook   *workbook;
66
	GtkWidget  *toplevel, *col_canvas, *row_canvas;
Arturo Espinosa's avatar
Arturo Espinosa committed
67
	GtkWidget  *sheet_view;
68 69 70
	GnomeCanvasItem *col_item, *row_item;
	
	double     last_zoom_factor_used;
71
	char       *name;
72 73

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

75
	ColRowInfo default_col_style;
76
	GList      *cols_info;
77

78
	ColRowInfo default_row_style;
79
	GList      *rows_info;
Arturo Espinosa's avatar
Arturo Espinosa committed
80

81
	GHashTable *cell_hash;	/* The cells in hashed format */
82 83 84 85 86 87

	GList      *selections;

	/* Scrolling information */
	GtkWidget  *vs, *hs;	/* The scrollbars */
	GtkObject  *va, *ha;    /* The adjustments */
Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
88 89

	GtkWidget  *tip;
90 91 92
	
	int        max_col_used;
	int        max_row_used;
93 94 95

	/* The list of formulas */
	GList      *formula_cell_list;
96 97 98 99 100

	/* For walking trough a selection */
	struct {
		SheetSelection *current;
	} walk_info;
101 102
} Sheet;

103 104 105
#define SHEET_SIGNATURE 0x12349876
#define IS_SHEET(x) (((Sheet *) x)->signature == SHEET_SIGNATURE)

Arturo Espinosa's avatar
Arturo Espinosa committed
106 107 108
typedef  void (*sheet_col_row_callback)(Sheet *sheet, ColRowInfo *ci,
					void *user_data);

Arturo Espinosa's avatar
Arturo Espinosa committed
109 110
typedef  int (*sheet_cell_foreach_callback)(Sheet *sheet, int col, int row,
					    Cell *cell, void *user_data);
111

Arturo Espinosa's avatar
Arturo Espinosa committed
112 113 114 115 116 117 118 119 120 121 122 123 124
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);
void        sheet_get_cell_bounds      	 (Sheet *sheet,
					  ColType col, RowType row, 
				       	  int *x, int *y,
				       	  int *w, int *h);
Arturo Espinosa's avatar
Arturo Espinosa committed
125 126 127 128
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);
129 130

/* Selection management */
131
void        sheet_select_all             (Sheet *sheet);
132 133
void        sheet_selection_append       (Sheet *sheet, int col, int row);
void        sheet_selection_extend_to    (Sheet *sheet, int col, int row);
Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
134 135
void        sheet_selection_reset        (Sheet *sheet);
void        sheet_selection_reset_only   (Sheet *sheet);
136
int         sheet_selection_equal        (SheetSelection *a, SheetSelection *b);
Arturo Espinosa's avatar
Arturo Espinosa committed
137 138
void        sheet_selection_append_range (Sheet *sheet,
					  int base_col,  int base_row,
139 140
					  int start_col, int start_row,
					  int end_col,   int end_row);
Miguel de Icaza's avatar
Today:  
Miguel de Icaza committed
141
CellList   *sheet_selection_to_list      (Sheet *sheet);
142

Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
143 144 145 146 147
/* Operations on the selection */
void        sheet_selection_clear_content (Sheet *sheet);
void        sheet_selection_clear_formats (Sheet *sheet);
void        sheet_selection_clear         (Sheet *sheet);

148
/* Cut/Copy/Paste on the workbook selection */
149 150
gboolean    sheet_selection_copy         (Sheet *sheet);
gboolean    sheet_selection_cut          (Sheet *sheet);
151 152 153
void        sheet_selection_paste        (Sheet *sheet,
					  int dest_col, int dest_row,
					  int paste_flags);
154 155 156 157
int         sheet_selection_walk_step    (Sheet *sheet,
					  int   forward,     int horizontal,
					  int   current_col, int current_row,
					  int   *new_col,    int *new_row);
158 159 160
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
161

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

Arturo Espinosa's avatar
Arturo Espinosa committed
164
/* Cell management */
Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
165 166 167 168 169 170 171 172 173 174 175 176
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);
void        sheet_cell_formula_link    (Cell *cell);
void        sheet_cell_formula_unlink  (Cell *cell);
Arturo Espinosa's avatar
Arturo Espinosa committed
177

Arturo Espinosa's avatar
Arturo Espinosa committed
178
/* Create new ColRowInfos from the default sheet style */
Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
179 180 181 182
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
183 184

/* Duplicates the information of a col/row */
Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
185
ColRowInfo *sheet_duplicate_colrow     (ColRowInfo *original);
Arturo Espinosa's avatar
Arturo Espinosa committed
186 187

/* Retrieve information from a col/row */
Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
188 189
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
190

Arturo Espinosa's avatar
Arturo Espinosa committed
191
/* Returns a pointer to a ColRowInfo: existed or freshly created */
Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
192 193
ColRowInfo *sheet_row_get              (Sheet *sheet, int pos);
ColRowInfo *sheet_col_get              (Sheet *sheet, int pos);
Arturo Espinosa's avatar
Arturo Espinosa committed
194

Arturo Espinosa's avatar
Arturo Espinosa committed
195
/* Add a ColRowInfo to the Sheet */
Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
196 197
void        sheet_col_add              (Sheet *sheet, ColRowInfo *cp);
void        sheet_row_add              (Sheet *sheet, ColRowInfo *cp);
Arturo Espinosa's avatar
Arturo Espinosa committed
198 199

/* Measure distances in pixels from one col/row to another */
Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
200 201
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
202
 
Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
203 204 205 206 207 208 209 210 211
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
212 213

/* Sets the width/height of a column row in terms of pixels */
Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
214 215 216 217 218 219 220 221 222 223
void        sheet_col_set_width        (Sheet *sheet,
				       	int col, int width);
void        sheet_row_set_height       (Sheet *sheet,
				       	int row, int width);
void        sheet_col_set_selection    (Sheet *sheet,
				       	ColRowInfo *ci, int value);
void        sheet_row_set_selection    (Sheet *sheet,
				       	ColRowInfo *ri, int value);
				       
Style      *sheet_style_compute        (Sheet *sheet, int col, int row);
Arturo Espinosa's avatar
Arturo Espinosa committed
224

225
/* Redraw */
Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
226 227 228 229 230 231 232
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);
				       
void        sheet_update_auto_expr     (Sheet *sheet);
233

234
/* Sheet information manipulation */
Arturo Espinosa's avatar
Today:  
Arturo Espinosa committed
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
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
Arturo Espinosa committed
251 252 253
/*
 * Workbook
 */
254 255 256 257
Workbook   *workbook_new                 (void);
Workbook   *workbook_new_with_sheets     (int sheet_count);
void        workbook_attach_sheet        (Workbook *, Sheet *);
Sheet      *workbook_focus_current_sheet (Workbook *wb);
Arturo Espinosa's avatar
Arturo Espinosa committed
258
Sheet      *workbook_get_current_sheet   (Workbook *wb);
259
void        workbook_auto_expr_label_set (Workbook *wb, char *text);
260
void        workbook_next_generation     (Workbook *wb);
261 262
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
263

Arturo Espinosa's avatar
Arturo Espinosa committed
264 265 266 267
/*
 * Does any pending recalculations
 */
void        workbook_recalc              (Workbook *wb);
268
void        workbook_recalc_all          (Workbook *wb);
Arturo Espinosa's avatar
Arturo Espinosa committed
269

270 271 272 273
/*
 * Callback routine: invoked when the first view ItemGrid
 * is realized to allocate the default styles
 */
274
void     workbook_realized            (Workbook *, GdkWindow *);
275

276
extern   Workbook *current_workbook;
277
#endif