1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
8 #include <pango/pango.h>
9 #include <goffice/goffice.h>
10 #include "libgnumeric.h"
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
{
23 ColRowInfo default_style
;
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 ())
40 gboolean being_invalidated
;
41 gboolean being_constructed
;
45 GPtrArray
*sheet_views
;
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
;
72 gboolean hide_col_header
;
73 gboolean hide_row_header
;
74 gboolean is_protected
;
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 */
93 GnmSheetVisibility visibility
;
95 gboolean display_outlines
;
96 gboolean outline_symbols_below
;
97 gboolean outline_symbols_right
;
100 gboolean has_filtered_rows
;
102 GnmSolverParameters
*solver_parameters
;
104 GHashTable
*sort_setups
;
106 gint simulation_round
;
108 GnmDepContainer
*deps
;
113 GHashTable
*hash_merged
;
115 GnmPrintInformation
*print_info
;
117 GnmColor
*tab_text_color
;
118 GnmSheetType sheet_type
;
122 /* tile related data */
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
,
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
);
159 * Merge with sheet_cell_foreach
162 struct _GnmCellIter
{
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
,
172 GnmValue
*sheet_foreach_cell_in_range (Sheet
*sheet
, CellIterFlags flags
,
174 CellIterFunc callback
,
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
,
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
,
225 ColRowHandler callback
,
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.
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
);
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
,
270 gboolean ignore_strings
);
271 int sheet_row_size_fit_pixels (Sheet
*sheet
, int row
,
273 gboolean ignore_strings
);
275 gboolean
sheet_colrow_can_group (Sheet
*sheet
, GnmRange
const *r
,
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
,
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
);
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
,
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
,
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
);
386 CLEAR_FORMATS
= 0x02,
387 CLEAR_COMMENTS
= 0x04,
388 CLEAR_NOCHECKARRAY
= 0x08,
389 CLEAR_NORESPAN
= 0x10,
390 CLEAR_RECALC_DEPS
= 0x20,
392 CLEAR_OBJECTS
= 0x80,
393 CLEAR_FILTERED_ONLY
= 0x100
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
,
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) \
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); \
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) \
435 /* Maybe external deps here. */ \
437 if ((sheet)->deps) { \
438 DEPENDENT_CONTAINER_FOREACH_DEPENDENT ((sheet)->deps, dep, code); \
444 #endif /* _GNM_SHEET_H_ */