1 #ifndef _GNM_CELL_H_
2 # define _GNM_CELL_H_
3
4 #include <gnumeric.h>
5 #include <dependent.h>
6
7 G_BEGIN_DECLS
8
9 typedef enum {
10 /* MUST BE > 0xFFF,FFFF to avoid conflict with GnmDependentFlags */
11 /* GnmCell is linked into the sheet */
12 GNM_CELL_IN_SHEET_LIST = 0x10000000,
13 /* Is the top left corner of a merged region */
14 GNM_CELL_IS_MERGED = 0x20000000,
15 /* Cells expression was changed, recalc before rendering */
16 GNM_CELL_HAS_NEW_EXPR = 0x40000000
17 } GnmCellFlags;
18
19 /* Definition of a GnmCell */
20 #define GNM_DEP_TO_CELL(dep) ((GnmCell *)(dep))
21 #define GNM_CELL_TO_DEP(cell) (&(cell)->base)
22 struct _GnmCell {
23 GnmDependent base;
24
25 /* Mandatory state information */
26 GnmCellPos pos;
27
28 GnmValue *value; /* computed or entered (Must be non NULL) */
29 };
30
31 GType gnm_cell_get_type (void);
32
33 /*
34 * GnmCell state checking
35 */
36 #ifdef __GI_SCANNER__
37 gboolean gnm_cell_has_expr (GnmCell const *cell);
38 #else
39 inline gboolean
gnm_cell_has_expr(GnmCell const * cell)40 gnm_cell_has_expr (GnmCell const *cell) {
41 return cell->base.texpr != NULL;
42 }
43 #endif
44
45 #define gnm_cell_needs_recalc(cell) ((cell)->base.flags & DEPENDENT_NEEDS_RECALC)
46 #define gnm_cell_expr_is_linked(cell) ((cell)->base.flags & DEPENDENT_IS_LINKED)
47 #define gnm_cell_is_merged(cell) ((cell)->base.flags & GNM_CELL_IS_MERGED)
48 gboolean gnm_cell_is_empty (GnmCell const *cell);
49 gboolean gnm_cell_is_blank (GnmCell const *cell); /* empty, or "" */
50 GnmValue *gnm_cell_is_error (GnmCell const *cell);
51 gboolean gnm_cell_is_number (GnmCell const *cell);
52 gboolean gnm_cell_is_zero (GnmCell const *cell);
53 GnmValue *gnm_cell_get_value (GnmCell const *cell);
54
55 gboolean gnm_cell_is_array (GnmCell const *cell);
56 gboolean gnm_cell_is_nonsingleton_array (GnmCell const *cell);
57 gboolean gnm_cell_array_bound (GnmCell const *cell, GnmRange *res);
58
59 /*
60 * Utilities to assign the contents of a cell
61 */
62 void gnm_cell_set_text (GnmCell *cell, char const *text);
63 void gnm_cell_assign_value (GnmCell *cell, GnmValue *v);
64 void gnm_cell_set_value (GnmCell *c, GnmValue *v);
65 void gnm_cell_set_expr_and_value(GnmCell *cell,
66 GnmExprTop const *texpr, GnmValue *v,
67 gboolean link_expr);
68 void gnm_cell_set_expr (GnmCell *cell, GnmExprTop const *texpr);
69 void gnm_cell_set_expr_unsafe (GnmCell *cell, GnmExprTop const *texpr);
70 void gnm_cell_set_array_formula (Sheet *sheet,
71 int cola, int rowa, int colb, int rowb,
72 GnmExprTop const *texpr);
73 GOUndo *gnm_cell_set_array_formula_undo (GnmSheetRange *sr,
74 GnmExprTop const *texpr);
75 gboolean gnm_cell_set_array (Sheet *sheet,
76 const GnmRange *r,
77 GnmExprTop const *texpr);
78 void gnm_cell_cleanout (GnmCell *cell);
79 void gnm_cell_convert_expr_to_value (GnmCell *cell);
80
81 /*
82 * Manipulate GnmCell attributes
83 */
84 GnmStyle const *gnm_cell_get_style (GnmCell const *cell);
85 GnmStyle const *gnm_cell_get_effective_style (GnmCell const *cell);
86 GOFormat const *gnm_cell_get_format (GnmCell const *cell);
87 GOFormat const *gnm_cell_get_format_given_style (GnmCell const *cell, GnmStyle const *style);
88
89 GnmRenderedValue *gnm_cell_get_rendered_value (GnmCell const *cell);
90 GnmRenderedValue *gnm_cell_fetch_rendered_value (GnmCell const *cell,
91 gboolean allow_variable_width);
92 GnmRenderedValue *gnm_cell_render_value (GnmCell const *cell,
93 gboolean allow_variable_width);
94 void gnm_cell_unrender (GnmCell const *cell);
95
96 int gnm_cell_rendered_height (GnmCell const * cell);
97 int gnm_cell_rendered_width (GnmCell const * cell); /* excludes offset */
98 int gnm_cell_rendered_offset (GnmCell const * cell);
99 GOColor gnm_cell_get_render_color (GnmCell const * cell);
100 char * gnm_cell_get_entered_text (GnmCell const * cell);
101 char * gnm_cell_get_text_for_editing (GnmCell const * cell,
102 gboolean *quoted, int *cursor_pos);
103 char * gnm_cell_get_rendered_text (GnmCell *cell);
104
105 G_END_DECLS
106
107 #endif /* _GNM_CELL_H_ */
108