GUI: Move .ui files from goffice resources to glib resources
[gnumeric.git] / src / sheet.h
blob589f00c1855b724be0ff4b4fa4dd847fab086664
1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 #ifndef _GNM_SHEET_H_
3 # define _GNM_SHEET_H_
5 #include "gnumeric.h"
6 #include "colrow.h"
7 #include "position.h"
8 #include <pango/pango.h>
9 #include <goffice/goffice.h>
10 #include "libgnumeric.h"
12 G_BEGIN_DECLS
14 GNM_VAR_DECL Sheet *invalid_sheet;
16 struct _GnmSheetSize {
17 int max_cols, max_rows;
19 GType gnm_sheet_size_get_type (void);
21 struct _ColRowCollection {
22 int max_used;
23 ColRowInfo default_style;
24 GPtrArray * info;
25 int max_outline_level;
28 typedef struct _SheetPrivate SheetPrivate;
29 GType gnm_sheet_type_get_type (void);
30 #define GNM_SHEET_TYPE_TYPE (gnm_sheet_type_get_type ())
32 GType gnm_sheet_visibility_get_type (void);
33 #define GNM_SHEET_VISIBILITY_TYPE (gnm_sheet_visibility_get_type ())
35 struct _Sheet {
36 GObject base;
38 int index_in_wb;
39 Workbook *workbook;
40 gboolean being_invalidated;
41 gboolean being_constructed;
43 GOUndoGroup *revive;
45 GPtrArray *sheet_views;
47 char *name_quoted;
48 char *name_unquoted;
49 char *name_unquoted_collate_key;
50 char *name_case_insensitive;
52 GnmSheetStyleData *style_data; /* See sheet-style.c */
54 ColRowCollection cols, rows;
56 GHashTable *cell_hash; /* The cells in hashed format */
58 GnmNamedExprCollection *names;
60 /* This should eventually be moved to the views. */
61 double last_zoom_factor_used;
62 GnmRenderedValueCollection *rendered_values;
64 GSList *sheet_objects; /* List of objects in this sheet */
65 GnmCellPos max_object_extent;
67 /* Sheet level preferences */
68 GnmConventions *convs;
69 gboolean display_formulas;
70 gboolean hide_zero;
71 gboolean hide_grid;
72 gboolean hide_col_header;
73 gboolean hide_row_header;
74 gboolean is_protected;
75 struct {
76 gboolean edit_objects; /* TODO */
77 gboolean edit_scenarios; /* TODO */
78 gboolean cell_formatting; /* TODO */
79 gboolean column_formatting; /* TODO */
80 gboolean row_formatting; /* TODO */
81 gboolean insert_columns; /* TODO */
82 gboolean insert_rows; /* TODO */
83 gboolean insert_hyperlinks; /* TODO */
84 gboolean delete_columns; /* TODO */
85 gboolean delete_rows; /* TODO */
86 gboolean select_locked_cells; /* Partial : TODO range selection */
87 gboolean sort_ranges; /* TODO */
88 gboolean edit_auto_filters; /* TODO */
89 gboolean edit_pivottable; /* TODO */
90 gboolean select_unlocked_cells; /* Partial : TODO range selection */
91 } protected_allow;
93 GnmSheetVisibility visibility;
95 gboolean display_outlines;
96 gboolean outline_symbols_below;
97 gboolean outline_symbols_right;
98 gboolean text_is_rtl;
100 gboolean has_filtered_rows;
102 GnmSolverParameters *solver_parameters;
103 GList *scenarios;
104 GHashTable *sort_setups;
106 gint simulation_round;
108 GnmDepContainer *deps;
110 GSList *slicers;
111 GSList *filters;
112 GSList *list_merged;
113 GHashTable *hash_merged;
114 SheetPrivate *priv;
115 GnmPrintInformation *print_info;
116 GnmColor *tab_color;
117 GnmColor *tab_text_color;
118 GnmSheetType sheet_type;
120 GnmSheetSize size;
122 /* tile related data */
123 int tile_top_level;
126 #define GNM_SHEET_TYPE (gnm_sheet_get_type ())
127 #define SHEET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNM_SHEET_TYPE, Sheet))
128 #define IS_SHEET(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNM_SHEET_TYPE))
129 #define GNM_SHEET_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GNM_SHEET_TYPE, GnmSheetClass))
130 GType gnm_sheet_get_type (void);
132 Sheet *sheet_new (Workbook *wb, char const *name, int columns, int rows);
133 Sheet *sheet_new_with_type (Workbook *wb, char const *name,
134 GnmSheetType type, int columns, int rows);
135 Sheet *sheet_dup (Sheet const *source_sheet);
136 void sheet_destroy_contents (Sheet *sheet);
138 gboolean gnm_sheet_valid_size (int cols, int rows);
139 void gnm_sheet_suggest_size (int *cols, int *rows);
141 GOUndo *gnm_sheet_resize (Sheet *sheet, int cols, int rows,
142 GOCmdContext *cc, gboolean *perr);
144 GnmSheetSize const *gnm_sheet_get_size (Sheet const *sheet);
145 GnmSheetSize const *gnm_sheet_get_size2 (Sheet const *sheet,
146 Workbook const *wb);
147 #define gnm_sheet_get_max_rows(sheet) (gnm_sheet_get_size(sheet)->max_rows)
148 #define gnm_sheet_get_max_cols(sheet) (gnm_sheet_get_size(sheet)->max_cols)
149 #define gnm_sheet_get_last_col(sheet) (gnm_sheet_get_max_cols(sheet) - 1)
150 #define gnm_sheet_get_last_row(sheet) (gnm_sheet_get_max_rows(sheet) - 1)
152 /* GnmCell management */
153 GnmCell *sheet_cell_get (Sheet const *sheet, int col, int row);
154 GnmCell *sheet_cell_fetch (Sheet *sheet, int col, int row);
155 GnmCell *sheet_cell_create (Sheet *sheet, int col, int row);
156 void sheet_cell_remove (Sheet *sheet, GnmCell *cell,
157 gboolean redraw, gboolean queue_recalc);
158 /* TODO TODO TODO
159 * Merge with sheet_cell_foreach
162 struct _GnmCellIter {
163 GnmCell *cell;
164 GnmParsePos pp;
165 ColRowInfo *ci, *ri;
167 GnmValue *sheet_foreach_cell_in_region (Sheet *sheet, CellIterFlags flags,
168 int start_col, int start_row,
169 int end_col, int end_row,
170 CellIterFunc callback,
171 gpointer closure);
172 GnmValue *sheet_foreach_cell_in_range (Sheet *sheet, CellIterFlags flags,
173 GnmRange const *r,
174 CellIterFunc callback,
175 gpointer closure);
176 void sheet_cell_foreach (Sheet const *sheet,
177 GHFunc callback, gpointer data);
178 unsigned sheet_cells_count (Sheet const *sheet);
179 GPtrArray *sheet_cell_positions (Sheet *sheet, gboolean comments);
181 GPtrArray *sheet_cells (Sheet *sheet, const GnmRange *r);
183 void sheet_recompute_spans_for_col (Sheet *sheet, int col);
185 gboolean sheet_is_region_empty (Sheet *sheet, GnmRange const *r);
186 gboolean sheet_is_cell_empty (Sheet *sheet, int col, int row);
188 gboolean sheet_col_is_hidden (Sheet const *sheet, int col);
189 gboolean sheet_row_is_hidden (Sheet const *sheet, int row);
191 GnmComment *sheet_get_comment (Sheet const *sheet,
192 GnmCellPos const *pos);
194 int sheet_find_boundary_horizontal (Sheet *sheet, int col, int move_row,
195 int base_row, int count,
196 gboolean jump_to_boundaries);
197 int sheet_find_boundary_vertical (Sheet *sheet, int move_col, int row,
198 int base_col, int count,
199 gboolean jump_to_boundaries);
201 ColRowInfo const *sheet_colrow_get_default (Sheet const *sheet,
202 gboolean is_cols);
204 void sheet_colrow_optimize (Sheet *sheet);
206 /* Returns a pointer to a ColRowInfo: existing or NULL */
207 ColRowInfo *sheet_col_get (Sheet const *sheet, int col);
208 ColRowInfo *sheet_row_get (Sheet const *sheet, int row);
209 ColRowInfo *sheet_colrow_get (Sheet const *sheet,
210 int colrow, gboolean is_cols);
211 /* Returns a pointer to a ColRowInfo: existing or freshly created */
212 ColRowInfo *sheet_col_fetch (Sheet *sheet, int col);
213 ColRowInfo *sheet_row_fetch (Sheet *sheet, int row);
214 ColRowInfo *sheet_colrow_fetch (Sheet *sheet,
215 int colrow, gboolean is_cols);
216 /* Returns a pointer to a ColRowInfo: existing or default */
217 ColRowInfo const *sheet_col_get_info (Sheet const *sheet, int col);
218 ColRowInfo const *sheet_row_get_info (Sheet const *sheet, int row);
219 ColRowInfo const *sheet_colrow_get_info (Sheet const *sheet,
220 int colrow, gboolean is_cols);
222 gboolean sheet_colrow_foreach (Sheet const *sheet,
223 gboolean is_cols,
224 int first, int last,
225 ColRowHandler callback,
226 gpointer user_data);
229 * Definitions of row/col size terminology :
231 * _pixels == measurments are in screen pixels.
232 * _pts == measurments are in 'points' and should be the same size on all displays
233 * (printers and monitors).
235 * distance == pixels from the leading edge of the 'from' col/row
236 * to the leading edge of the 'to' col/row
237 * INCLUDING all internal margins.
238 * INCLUDING the leading grid line
239 * EXCLUDING the trailing grid line.
241 * _default == The size of all cols/rows that do not have explicit sizes.
243 /* Col width */
244 double sheet_col_get_distance_pts (Sheet const *sheet, int from_col, int to_col);
245 int sheet_col_get_distance_pixels (Sheet const *sheet, int from_col, int to_col);
246 void sheet_col_set_size_pts (Sheet *sheet, int col, double width_pts,
247 gboolean set_by_user);
248 void sheet_col_set_size_pixels (Sheet *sheet, int col, int width_pixels,
249 gboolean set_by_user);
250 double sheet_col_get_default_size_pts (Sheet const *sheet);
251 int sheet_col_get_default_size_pixels (Sheet const *sheet);
252 void sheet_col_set_default_size_pts (Sheet *sheet, double width_pts);
253 void sheet_col_set_default_size_pixels (Sheet *sheet, int width_pixels);
255 /* Row height */
256 double sheet_row_get_distance_pts (Sheet const *sheet, int from_row, int to_row);
257 int sheet_row_get_distance_pixels (Sheet const *sheet, int from, int to);
258 void sheet_row_set_size_pts (Sheet *sheet, int row, double height_pts,
259 gboolean set_by_user);
260 void sheet_row_set_size_pixels (Sheet *sheet, int row, int height_pixels,
261 gboolean set_by_user);
262 double sheet_row_get_default_size_pts (Sheet const *sheet);
263 int sheet_row_get_default_size_pixels (Sheet const *sheet);
264 void sheet_row_set_default_size_pts (Sheet *sheet, double height_pts);
265 void sheet_row_set_default_size_pixels (Sheet *sheet, int height_pixels);
267 /* Find minimum pixel size to display contents (including margins and far grid line) */
268 int sheet_col_size_fit_pixels (Sheet *sheet, int col,
269 int srow, int erow,
270 gboolean ignore_strings);
271 int sheet_row_size_fit_pixels (Sheet *sheet, int row,
272 int scol, int ecol,
273 gboolean ignore_strings);
275 gboolean sheet_colrow_can_group (Sheet *sheet, GnmRange const *r,
276 gboolean is_cols);
277 gboolean sheet_colrow_group_ungroup (Sheet *sheet, GnmRange const *r,
278 gboolean is_cols, gboolean inc);
279 void sheet_colrow_gutter (Sheet *sheet,
280 gboolean is_cols, int max_outline);
282 gboolean sheet_range_splits_array (Sheet const *sheet,
283 GnmRange const *r, GnmRange const *ignore,
284 GOCmdContext *cc, char const *cmd);
285 gboolean sheet_range_splits_region (Sheet const *sheet,
286 GnmRange const *r, GnmRange const *ignore,
287 GOCmdContext *cc, char const *cmd);
288 gboolean sheet_ranges_split_region (Sheet const *sheet, GSList const *ranges,
289 GOCmdContext *cc, char const *cmd);
290 gboolean sheet_range_contains_merges_or_arrays (Sheet const *sheet,
291 GnmRange const *r,
292 GOCmdContext *cc,
293 char const *cmd,
294 gboolean merges,
295 gboolean arrays);
296 void sheet_range_bounding_box (Sheet const *sheet, GnmRange *r);
297 gboolean sheet_range_trim (Sheet const *sheet, GnmRange *r,
298 gboolean cols, gboolean rows);
299 gboolean sheet_range_has_heading (Sheet const *sheet, GnmRange const *src,
300 gboolean top, gboolean ignore_styles);
303 void gnm_sheet_foreach_name (Sheet const *sheet, GHFunc func, gpointer data);
305 void gnm_sheet_set_solver_params (Sheet *sheet, GnmSolverParameters *param);
307 GnmScenario *gnm_sheet_scenario_new (Sheet *sheet, const char *name);
308 GnmScenario *gnm_sheet_scenario_find (Sheet *sheet, const char *name);
309 void gnm_sheet_scenario_add (Sheet *sheet, GnmScenario *sc);
310 void gnm_sheet_scenario_remove (Sheet *sheet, GnmScenario *sc);
312 GHashTable *gnm_sheet_get_sort_setups (Sheet *sheet);
313 void gnm_sheet_add_sort_setup (Sheet *sheet, char *key, gpointer setup);
314 gconstpointer gnm_sheet_find_sort_setup (Sheet *sheet, char const *key);
316 /* Redraw */
317 #define sheet_is_visible(_sheet) ((_sheet)->visibility == GNM_SHEET_VISIBILITY_VISIBLE)
318 void sheet_redraw_all (Sheet const *sheet, gboolean header);
319 void sheet_redraw_range (Sheet const *sheet, GnmRange const *r);
320 void sheet_redraw_region (Sheet const *sheet,
321 int start_col, int start_row,
322 int end_col, int end_row);
324 void sheet_flag_status_update_cell (GnmCell const *cell);
325 void sheet_flag_status_update_range (Sheet const *sheet, GnmRange const *range);
326 void sheet_flag_style_update_range (Sheet const *sheet, GnmRange const *range);
327 void sheet_flag_recompute_spans (Sheet const *sheet);
328 void sheet_update_only_grid (Sheet const *sheet);
329 void sheet_update (Sheet const *sheet);
330 void sheet_scrollbar_config (Sheet const *sheet);
332 void sheet_mark_dirty (Sheet *sheet);
333 GnmRange sheet_get_extent (Sheet const *sheet,
334 gboolean spans_and_merges_extend,
335 gboolean include_hidden);
336 GnmRange sheet_get_cells_extent (Sheet const *sheet);
337 GnmRange sheet_get_printarea (Sheet const *sheet,
338 gboolean include_styles,
339 gboolean ignore_printarea);
340 GnmRange *sheet_get_nominal_printarea (Sheet const *sheet);
343 * Utilities to set cell contents, queueing recalcs,
344 * redraws and rendering as required. Does NOT check for
345 * division of arrays.
347 void sheet_cell_set_expr (GnmCell *cell, GnmExprTop const *texpr);
348 void sheet_cell_set_value (GnmCell *cell, GnmValue *v);
349 void sheet_cell_set_text (GnmCell *cell, char const *str,
350 PangoAttrList *markup);
351 GnmValue const *sheet_cell_get_value(Sheet *sheet, int col, int row);
352 void sheet_range_set_text (GnmParsePos const *pos,
353 GnmRange const *r, char const *str);
354 GOUndo * sheet_range_set_text_undo (GnmSheetRange *sr,
355 char const *text);
356 GOUndo * sheet_range_set_expr_undo (GnmSheetRange *sr,
357 GnmExprTop const *texpr);
358 GOUndo * sheet_range_set_markup_undo (GnmSheetRange *sr,
359 PangoAttrList *markup);
360 void sheet_apply_style (Sheet *sheet, GnmRange const *range, GnmStyle *style);
361 GOUndo * sheet_apply_style_undo (GnmSheetRange *sr,
362 GnmStyle *style);
363 void sheet_apply_border (Sheet *sheet, GnmRange const *range, GnmBorder **borders);
364 void sheet_queue_respan (Sheet const *sheet, int start_row, int end_row);
365 void sheet_cell_queue_respan (GnmCell *cell);
366 void sheet_range_calc_spans (Sheet *sheet, GnmRange const *r, GnmSpanCalcFlags flags);
368 void sheet_set_outline_direction (Sheet *sheet, gboolean is_cols);
369 gboolean sheet_selection_is_allowed (Sheet const *sheet, GnmCellPos const *pos);
371 GnmConventions const *sheet_get_conventions (Sheet const *sheet);
373 gboolean sheet_insert_cols (Sheet *sheet, int col, int count,
374 GOUndo **pundo, GOCmdContext *cc);
375 gboolean sheet_delete_cols (Sheet *sheet, int col, int count,
376 GOUndo **pundo, GOCmdContext *cc);
377 gboolean sheet_insert_rows (Sheet *sheet, int row, int count,
378 GOUndo **pundo, GOCmdContext *cc);
379 gboolean sheet_delete_rows (Sheet *sheet, int row, int count,
380 GOUndo **pundo, GOCmdContext *cc);
381 void sheet_move_range (GnmExprRelocateInfo const *rinfo,
382 GOUndo **pundo, GOCmdContext *cc);
384 typedef enum {
385 CLEAR_VALUES = 0x01,
386 CLEAR_FORMATS = 0x02,
387 CLEAR_COMMENTS = 0x04,
388 CLEAR_NOCHECKARRAY = 0x08,
389 CLEAR_NORESPAN = 0x10,
390 CLEAR_RECALC_DEPS = 0x20,
391 CLEAR_MERGES = 0x40,
392 CLEAR_OBJECTS = 0x80,
393 CLEAR_FILTERED_ONLY = 0x100
394 } SheetClearFlags;
396 void sheet_clear_region (Sheet *sheet,
397 int start_col, int start_row,
398 int end_col, int end_row,
399 int clear_flags, GOCmdContext *cc);
401 GOUndo *sheet_clear_region_undo (GnmSheetRange *sr,
402 int clear_flags);
404 SheetView *sheet_get_view (Sheet const *sheet, WorkbookView const *wbv);
406 GODateConventions const *sheet_date_conv (Sheet const *sheet);
408 // Introspection support
409 void sheet_cell_set_value_gi (Sheet *sheet, int col, int row, GnmValue *v);
410 void sheet_cell_set_text_gi (Sheet *sheet, int col, int row, char const *str);
411 void sheet_apply_style_gi (Sheet *sheet, GnmRange const *range, GnmStyle *style);
414 #define SHEET_FOREACH_VIEW(sheet, view, code) \
415 do { \
416 int InD; \
417 GPtrArray *views = (sheet)->sheet_views; \
418 if (views != NULL) /* Reverse is important during destruction */ \
419 for (InD = views->len; InD-- > 0; ) { \
420 SheetView *view = g_ptr_array_index (views, InD); \
421 code \
423 } while (0)
425 #define SHEET_FOREACH_CONTROL(sheet, view, control, code) \
426 SHEET_FOREACH_VIEW((sheet), view, \
427 SHEET_VIEW_FOREACH_CONTROL(view, control, code);)
430 * Walk the dependents. WARNING: Note, that it is only valid to muck with
431 * the current dependency in the code.
433 #define SHEET_FOREACH_DEPENDENT(sheet, dep, code) \
434 do { \
435 /* Maybe external deps here. */ \
437 if ((sheet)->deps) { \
438 DEPENDENT_CONTAINER_FOREACH_DEPENDENT ((sheet)->deps, dep, code); \
440 } while (0)
442 G_END_DECLS
444 #endif /* _GNM_SHEET_H_ */