sheet.h 5.68 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
23
24
	
	Style      style;
	GHashTable *sheets;	/* keeps a list of the Sheets on this workbook */
} Workbook;

25
26
27
28
29
30
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
31
typedef struct {
32
33
	int        signature;
	
Arturo Espinosa's avatar
Arturo Espinosa committed
34
	Workbook   *parent_workbook;
35
	GtkWidget  *toplevel, *col_canvas, *row_canvas;
Arturo Espinosa's avatar
Arturo Espinosa committed
36
	GtkWidget  *sheet_view;
37
38
39
	GnomeCanvasItem *col_item, *row_item;
	
	double     last_zoom_factor_used;
40
41
42
	char       *name;
		   
	Style      style;
43

44
	ColRowInfo default_col_style;
45
	GList      *cols_info;
46

47
	ColRowInfo default_row_style;
48
	GList      *rows_info;
Arturo Espinosa's avatar
Arturo Espinosa committed
49

50
	GHashTable *cell_hash;	/* The cells in hashed format */
51
52
53
54
55
56
57
58
59

	GList      *selections;

	/* Scrolling information */
	GtkWidget  *vs, *hs;	/* The scrollbars */
	GtkObject  *va, *ha;    /* The adjustments */
	
	int        max_col_used;
	int        max_row_used;
60
61
} Sheet;

62
63
64
#define SHEET_SIGNATURE 0x12349876
#define IS_SHEET(x) (((Sheet *) x)->signature == SHEET_SIGNATURE)

Arturo Espinosa's avatar
Arturo Espinosa committed
65
66
67
68
69
typedef  void (*sheet_col_row_callback)(Sheet *sheet, ColRowInfo *ci,
					void *user_data);

typedef  void (*sheet_cell_foreach_callback)(Sheet *sheet, int col, int row,
					     Cell *cell, void *user_data);
70

71
72
73
74
75
76
77
78
Sheet      *sheet_new                 (Workbook *wb, char *name);
void        sheet_destroy             (Sheet *sheet);
void        sheet_foreach_col         (Sheet *sheet, sheet_col_row_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);

/* Selection management */
79
void        sheet_select_all             (Sheet *sheet);
80
81
82
83
84
85
86
87
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);
void        sheet_selection_append_range (Sheet *sheet, int base_col,  int base_row,
					  int start_col, int start_row,
					  int end_col,   int end_row);
88

89
90
91
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
92

93
94
void        sheet_brute_force_recompute       (Sheet *sheet);

Arturo Espinosa's avatar
Arturo Espinosa committed
95
96
97
98
99
100
101
102
103
104
105
/* Cell management */
Cell       *sheet_cell_new            (Sheet *sheet, int col, int row);
void        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        cell_set_text             (Sheet *sheet, Cell *cell, char *text);
void        cell_set_formula          (Sheet *sheet, Cell *cell, char *text);

Arturo Espinosa's avatar
Arturo Espinosa committed
106
/* Create new ColRowInfos from the default sheet style */
107
108
ColRowInfo *sheet_col_new             (Sheet *sheet);
ColRowInfo *sheet_row_new             (Sheet *sheet);
109
110
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
111
112

/* Duplicates the information of a col/row */
113
ColRowInfo *sheet_duplicate_colrow    (ColRowInfo *original);
Arturo Espinosa's avatar
Arturo Espinosa committed
114
115

/* Retrieve information from a col/row */
116
117
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
118

Arturo Espinosa's avatar
Arturo Espinosa committed
119
120
121
122
/* 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
123
/* Add a ColRowInfo to the Sheet */
124
125
void        sheet_col_add             (Sheet *sheet, ColRowInfo *cp);
void        sheet_row_add             (Sheet *sheet, ColRowInfo *cp);
Arturo Espinosa's avatar
Arturo Espinosa committed
126
127

/* Measure distances in pixels from one col/row to another */
128
129
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
130
131

/* Sets the width/height of a column row in terms of pixels */
132
133
void        sheet_col_set_width       (Sheet *sheet, int col, int width);
void        sheet_row_set_height      (Sheet *sheet, int row, int width);
134
135
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
136

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

139
140
141
142
/* Redraw */
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);
Arturo Espinosa's avatar
Arturo Espinosa committed
143
void        sheet_redraw_all          (Sheet *sheet);
Arturo Espinosa's avatar
Arturo Espinosa committed
144

145
146
147
148
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
149
Sheet      *workbook_get_current_sheet   (Workbook *wb);
Arturo Espinosa's avatar
Arturo Espinosa committed
150

151
152
153
154
/*
 * Callback routine: invoked when the first view ItemGrid
 * is realized to allocate the default styles
 */
155
void     workbook_realized            (Workbook *, GdkWindow *);
156

157
extern   Workbook *current_workbook;
158
#endif