1 #ifndef CELLH 2 #define CELLH 3 4 /* 5 * $Id: cell.h,v 1.14 2001/02/13 23:38:05 danny Exp $ 6 * 7 * Copyright � 1990-1999, 2001, Free Software Foundation, Inc. 8 * 9 * This file is part of Oleo, the GNU Spreadsheet. 10 * 11 * Oleo is free software; you can redistribute it and/or modify 12 * it under the terms of the GNU General Public License as published by 13 * the Free Software Foundation; either version 2, or (at your option) 14 * any later version. 15 * 16 * Oleo is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU General Public License for more details. 20 * 21 * You should have received a copy of the GNU General Public License 22 * along with Oleo; see the file COPYING. If not, write to 23 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 24 */ 25 26 /* Various structures and stuff for the spreadsheet */ 27 28 /* A union of possible values for a location in the spreadsheet 29 (or a location to evaluate to: This includes c_r, which 30 a VAR, etc may evaluate to, but which no cell can ever contain */ 31 #include "global.h" 32 #include "font.h" 33 34 union vals 35 { 36 double c_d; 37 char *c_s; 38 long c_l; 39 int c_i; 40 struct rng c_r; 41 }; 42 43 /* An actual cell structure. These cannot be variable-length, since they are 44 allocated as a variable-length array on a col structure. */ 45 46 struct cell 47 { 48 /* char *cell_string; */ 49 struct cell_flags { 50 unsigned int cell_unused: 1; /* Was 2 */ 51 unsigned int cell_lock: 2; 52 unsigned int cell_type: 3; 53 unsigned int cell_justify: 2; 54 unsigned int cell_format: 4; /* Was 3 */ 55 unsigned int cell_precision: 4; 56 } cell_flags; 57 unsigned short cell_cycle; 58 struct font_memo *cell_font; 59 struct ref_fm *cell_refs_from; 60 struct ref_to *cell_refs_to; 61 unsigned char *cell_formula; 62 union vals c_z; 63 }; 64 65 struct var 66 { 67 struct var *var_next; 68 69 short var_flags; 70 struct rng v_rng; 71 72 /* This is a list of the cells that reference this variable. If the 73 * variable changes, all the cells in the vars new range must be given 74 * ref_froms that point to these variables 75 */ 76 struct ref_fm *var_ref_fm; 77 78 /* A variable sized array that holds the var-name. */ 79 char var_name[1]; 80 }; 81 82 typedef struct cell CELL; 83 84 #define VAR_UNDEF 1 85 #define VAR_CELL 2 86 #define VAR_RANGE 3 87 /* A var is only of this type between calls to start_shift_var and 88 * finish_shift_var 89 */ 90 #define VAR_DANGLING_RANGE 4 91 92 /* Shorthand for the cell union */ 93 #define cell_flt c_z.c_d 94 #define cell_str c_z.c_s 95 #define cell_int c_z.c_l 96 #define cell_bol c_z.c_i 97 #define cell_err c_z.c_i 98 99 #define GET_LCK(p) ((p)->cell_flags.cell_lock) 100 #define SET_LCK(p,x) ((p)->cell_flags.cell_lock = (x)) 101 102 #define LCK_DEF 0 103 #define LCK_UNL 1 104 #define LCK_LCK 2 105 106 /* The type of a cell, or of a eval_expression() value */ 107 #define GET_TYP(p) ((p)->cell_flags.cell_type) 108 #define SET_TYP(p,x) ((p)->cell_flags.cell_type = (x)) 109 110 #define TYP_FLT 1 /* Float */ 111 #define TYP_INT 2 /* Integer */ 112 #define TYP_STR 3 /* String */ 113 #define TYP_BOL 4 /* Boolean */ 114 #define TYP_ERR 5 /* Error */ 115 116 #define TYP_RNG 7 /* This for the expression evaluator: 117 NO cell should be this type */ 118 119 #define GET_JST(p) ((p == 0) ? JST_DEF : ((p)->cell_flags.cell_justify)) 120 #define SET_JST(p,x) ((p)->cell_flags.cell_justify = (x)) 121 #define JST_DEF 0 122 #define JST_LFT 1 123 #define JST_RGT 2 124 #define JST_CNT 3 125 126 /* 127 * Actually get/set both Format *and* precision 128 */ 129 #define FMT_MASK 0xF0 130 #define PREC_MASK 0x0F 131 #define FMT_SHIFT 4 132 133 #define GET_FORMAT(p) ((p)->cell_flags.cell_format) 134 #define SET_FORMAT(p,x) ((p)->cell_flags.cell_format = (x)) 135 136 #define GET_PRECISION(p) ((p)->cell_flags.cell_precision) 137 #define SET_PRECISION(p,x) ((p)->cell_flags.cell_precision = (x)) 138 139 #define FLOAT_PRECISION 15 140 141 #define FMT_DEF 0 /* Default */ 142 #define FMT_HID 1 /* Hidden */ 143 #define FMT_GPH 2 /* Graph */ 144 #define FMT_DOL 3 /* Dollar */ 145 #define FMT_CMA 4 /* Comma */ 146 #define FMT_PCT 5 /* Percent */ 147 #define FMT_USR 6 /* User defined */ 148 #define FMT_FXT 7 149 #define FMT_EXP 8 150 #define FMT_GEN 9 151 #define FMT_DATE 10 /* Date */ 152 153 #define FMT_MAX 15 154 155 /* README README README 156 * 157 * The _make_ functions may cause the addresses of cells previously returned by 158 * find_ functions to change. By extention, any function that calls a make_ 159 * function can have that effect. This is particularly nasty because pointers 160 * to cells are stored in the global my_cell, and in various stack frames. 161 * Several bugs have been traced to this questionable design -- please be 162 * careful not to add new ones. 163 */ 164 165 extern CELL *find_cell (CELLREF, CELLREF); 166 extern CELL *find_or_make_cell (CELLREF, CELLREF); 167 extern void find_cells_in_range (struct rng *); 168 extern void make_cells_in_range (struct rng *); 169 extern CELL *next_cell_in_range (void); 170 extern CELL *next_row_col_in_range (CELLREF *, CELLREF *); 171 extern void no_more_cells (void); 172 extern char *decomp (CELLREF, CELLREF, CELL *); 173 extern char *decomp_formula (CELLREF, CELLREF, CELL *, int); 174 extern void decomp_free (void); 175 176 #endif 177