sheet.h 8.01 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 9 10 11
typedef GList ColStyleList;

struct Workbook;

typedef struct {
Arturo Espinosa's avatar
Arturo Espinosa committed
12 13
	GtkWidget  *toplevel;
	GtkWidget  *notebook;
14 15 16 17 18 19
	GtkWidget  *table;

	/* Edit area */
	GtkWidget  *ea_status;
	GtkWidget  *ea_button_box;
	GtkWidget  *ea_input;
Arturo Espinosa's avatar
Arturo Espinosa committed
20 21 22

	/* The auto-expression */
	ExprTree   *auto_expr;
23
	String     *auto_expr_desc;
Arturo Espinosa's avatar
Arturo Espinosa committed
24
	GnomeCanvasItem  *auto_expr_label;
Arturo Espinosa's avatar
Arturo Espinosa committed
25
	
Arturo Espinosa's avatar
Arturo Espinosa committed
26
	/* Styles */
Arturo Espinosa's avatar
Arturo Espinosa committed
27 28
	Style      style;
	GHashTable *sheets;	/* keeps a list of the Sheets on this workbook */
29 30 31 32

	/* A list with all of the formulas */
	GList      *formula_cell_list;

Arturo Espinosa's avatar
Arturo Espinosa committed
33 34
	/* A queue with the cells to be evaluated */
	GList      *eval_queue;
35
	int        max_iterations;
36
	guchar     generation;
37 38 39

	/* The clipboard for this workbook */
	CellRegion *clipboard_contents;
Arturo Espinosa's avatar
Arturo Espinosa committed
40 41
} Workbook;

42 43 44 45 46 47
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
48
typedef struct {
49 50
	int        signature;
	
Arturo Espinosa's avatar
Arturo Espinosa committed
51
	Workbook   *workbook;
52
	GtkWidget  *toplevel, *col_canvas, *row_canvas;
Arturo Espinosa's avatar
Arturo Espinosa committed
53
	GtkWidget  *sheet_view;
54 55 56
	GnomeCanvasItem *col_item, *row_item;
	
	double     last_zoom_factor_used;
57 58 59
	char       *name;
		   
	Style      style;
60

61
	ColRowInfo default_col_style;
62
	GList      *cols_info;
63

64
	ColRowInfo default_row_style;
65
	GList      *rows_info;
Arturo Espinosa's avatar
Arturo Espinosa committed
66

67
	GHashTable *cell_hash;	/* The cells in hashed format */
68 69 70 71 72 73 74 75 76

	GList      *selections;

	/* Scrolling information */
	GtkWidget  *vs, *hs;	/* The scrollbars */
	GtkObject  *va, *ha;    /* The adjustments */
	
	int        max_col_used;
	int        max_row_used;
77 78 79

	/* The list of formulas */
	GList      *formula_cell_list;
80 81 82 83 84

	/* For walking trough a selection */
	struct {
		SheetSelection *current;
	} walk_info;
85 86
} Sheet;

87 88 89
#define SHEET_SIGNATURE 0x12349876
#define IS_SHEET(x) (((Sheet *) x)->signature == SHEET_SIGNATURE)

Arturo Espinosa's avatar
Arturo Espinosa committed
90 91 92
typedef  void (*sheet_col_row_callback)(Sheet *sheet, ColRowInfo *ci,
					void *user_data);

Arturo Espinosa's avatar
Arturo Espinosa committed
93 94
typedef  int (*sheet_cell_foreach_callback)(Sheet *sheet, int col, int row,
					    Cell *cell, void *user_data);
95

Arturo Espinosa's avatar
Arturo Espinosa committed
96 97 98 99 100 101 102 103 104 105 106 107 108
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);
Miguel de Icaza's avatar
Miguel de Icaza committed
109
void        sheet_cursor_set             (Sheet *sheet, int col, int row);
110 111

/* Selection management */
112
void        sheet_select_all             (Sheet *sheet);
113 114 115 116 117
void        sheet_selection_append       (Sheet *sheet, int col, int row);
void        sheet_selection_extend_to    (Sheet *sheet, int col, int row);
void        sheet_selection_clear        (Sheet *sheet);
void        sheet_selection_clear_only   (Sheet *sheet);
int         sheet_selection_equal        (SheetSelection *a, SheetSelection *b);
Arturo Espinosa's avatar
Arturo Espinosa committed
118 119
void        sheet_selection_append_range (Sheet *sheet,
					  int base_col,  int base_row,
120 121
					  int start_col, int start_row,
					  int end_col,   int end_row);
Miguel de Icaza's avatar
Today:  
Miguel de Icaza committed
122
CellList   *sheet_selection_to_list      (Sheet *sheet);
123

124
/* Cut/Copy/Paste on the workbook selection */
125 126
gboolean    sheet_selection_copy         (Sheet *sheet);
gboolean    sheet_selection_cut          (Sheet *sheet);
127 128 129
void        sheet_selection_paste        (Sheet *sheet,
					  int dest_col, int dest_row,
					  int paste_flags);
130 131 132 133
int         sheet_selection_walk_step    (Sheet *sheet,
					  int   forward,     int horizontal,
					  int   current_col, int current_row,
					  int   *new_col,    int *new_row);
134 135 136
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
137 138 139

/* Cell management */
Cell       *sheet_cell_new            (Sheet *sheet, int col, int row);
140 141
void        sheet_cell_add            (Sheet *sheet, Cell *cell,
				       int col, int row);
Arturo Espinosa's avatar
Arturo Espinosa committed
142
void        sheet_cell_remove         (Sheet *sheet, Cell *cell);
Arturo Espinosa's avatar
Arturo Espinosa committed
143
int         sheet_cell_foreach_range  (Sheet *sheet, int only_existing,
Arturo Espinosa's avatar
Arturo Espinosa committed
144 145 146 147 148
				       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);
149 150
void        sheet_cell_formula_link   (Cell *cell);
void        sheet_cell_formula_unlink (Cell *cell);
Arturo Espinosa's avatar
Arturo Espinosa committed
151

Arturo Espinosa's avatar
Arturo Espinosa committed
152
/* Create new ColRowInfos from the default sheet style */
153 154
ColRowInfo *sheet_col_new             (Sheet *sheet);
ColRowInfo *sheet_row_new             (Sheet *sheet);
155 156
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
157 158

/* Duplicates the information of a col/row */
159
ColRowInfo *sheet_duplicate_colrow    (ColRowInfo *original);
Arturo Espinosa's avatar
Arturo Espinosa committed
160 161

/* Retrieve information from a col/row */
162 163
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
164

Arturo Espinosa's avatar
Arturo Espinosa committed
165 166 167 168
/* Returns a pointer to a ColRowInfo: existed or freshly created */
ColRowInfo *sheet_row_get             (Sheet *sheet, int pos);
ColRowInfo *sheet_col_get             (Sheet *sheet, int pos);

Arturo Espinosa's avatar
Arturo Espinosa committed
169
/* Add a ColRowInfo to the Sheet */
170 171
void        sheet_col_add             (Sheet *sheet, ColRowInfo *cp);
void        sheet_row_add             (Sheet *sheet, ColRowInfo *cp);
Arturo Espinosa's avatar
Arturo Espinosa committed
172 173

/* Measure distances in pixels from one col/row to another */
174 175
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
176 177 178 179
 
void        sheet_clear_region        (Sheet *sheet,
				       int start_col, int start_row,
				       int end_col,   int end_row);
Arturo Espinosa's avatar
Arturo Espinosa committed
180 181

/* Sets the width/height of a column row in terms of pixels */
Arturo Espinosa's avatar
Arturo Espinosa committed
182 183 184 185 186 187 188 189
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);
Arturo Espinosa's avatar
Arturo Espinosa committed
190

Arturo Espinosa's avatar
Arturo Espinosa committed
191 192
Style      *sheet_style_compute       (Sheet *sheet, int col, int row);

193
/* Redraw */
Arturo Espinosa's avatar
Arturo Espinosa committed
194 195 196
void        sheet_redraw_cell_region  (Sheet *sheet,
				       int start_col, int start_row,
				       int end_col,   int end_row);
197
void        sheet_redraw_selection    (Sheet *sheet, SheetSelection *ss);
Arturo Espinosa's avatar
Arturo Espinosa committed
198
void        sheet_redraw_all          (Sheet *sheet);
Arturo Espinosa's avatar
Arturo Espinosa committed
199

200 201
void        sheet_update_auto_expr    (Sheet *sheet);

202
/* Sheet information manipulation */
203 204
void        sheet_insert_col          (Sheet *sheet,
				       int    col, int row,
205
				       int    count);
206 207
void        sheet_insert_row          (Sheet *sheet,
				       int    col, int row,
208
				       int    count);
Miguel de Icaza's avatar
Today:  
Miguel de Icaza committed
209 210 211 212 213

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
214 215 216
/*
 * Workbook
 */
217 218 219 220
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
221
Sheet      *workbook_get_current_sheet   (Workbook *wb);
222
void        workbook_auto_expr_label_set (Workbook *wb, char *text);
223
void        workbook_next_generation     (Workbook *wb);
224 225
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
226

Arturo Espinosa's avatar
Arturo Espinosa committed
227 228 229 230
/*
 * Does any pending recalculations
 */
void        workbook_recalc              (Workbook *wb);
231
void        workbook_recalc_all          (Workbook *wb);
Arturo Espinosa's avatar
Arturo Espinosa committed
232

233 234 235 236
/*
 * Callback routine: invoked when the first view ItemGrid
 * is realized to allocate the default styles
 */
237
void     workbook_realized            (Workbook *, GdkWindow *);
238

239
extern   Workbook *current_workbook;
240
#endif