teapot-spreadsheet/src/common/sheet.h

131 lines
5.1 KiB
C

#ifndef SHEET_H
#define SHEET_H
#include "cell.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum { IN_X, IN_Y, IN_Z } Direction;
/* must be a prime */
#define LABEL_CACHE 29
#define ASCENDING 001
typedef struct
{
int x;
int y;
int z;
int sortkey; /* OR-ed value of the above constants */
} Sortkey;
struct Label
{
const char *label;
Location location;
struct Label *next;
};
typedef enum { MARK_CYCLE = 0, GET_MARK_CUR = 1, GET_MARK_ALL = 2,
MARKING = 3, MARKED = 4, UNMARKED = 5 } MarkState;
typedef struct
{
struct Label *labelcache[LABEL_CACHE];
Location cur;
Location mark1, mark2;
int offx, offy;
Cell **sheet;
int *column;
int dimx, dimy, dimz;
int orix, oriy, maxx, maxy;
int width;
char *name;
void *display;
int max_colors;
void *palette;
MarkState marking;
unsigned int changed:1;
unsigned int moveonly:1;
unsigned int clk:1;
} Sheet;
#define LOC_WITHINC(s,x,y,z) (x<s->dimx && y<s->dimy && z<s->dimz)
#define LOC_WITHIN(s,l) (LOC_WITHINC(s,l[X],l[Y],l[Z]))
#define CELL_ATC(s,x,y,z) (*((s)->sheet + (z)*(s)->dimy*(s)->dimx + (y)*(s)->dimx +(x)))
#define CELL_AT(s,l) (CELL_ATC(s,l[X],l[Y],l[Z]))
#define CELL_IS_NULLC(s,x,y,z) (CELL_ATC(s,x,y,z) == NULLCELL)
#define CELL_IS_NULL(s,l) (CELL_AT(s,l) == NULLCELL)
#define CELL_IS_GOODC(s,x,y,z) (LOC_WITHINC(s,x,y,z) && !CELL_IS_NULLC(s,x,y,z))
#define CELL_IS_GOOD(s,l) (LOC_WITHIN(s,l) && !CELL_IS_NULL(s,l))
#define SHADOWEDC(s,x,y,z) (CELL_IS_GOODC(s,x,y,z) && CELL_ATC(s,x,y,z)->shadowed)
#define SHADOWED(s,l) (CELL_IS_GOOD(s,l) && CELL_AT(s,l)->shadowed)
#define ALL_COORDS_IN_SHEETC(s,x,y,z) x=0; x<(s)->dimx; ++x) for (y=0; y<(s)->dimy; ++y) for (z=0; z<(s)->dimz; ++z
#define ALL_LOCS_IN_SHEET(s,l) l[Z]=0; l[Z]<(s)->dimz; ++(l[Z])) for (l[Y]=0; l[Y]<(s)->dimy; ++(l[Y])) for (l[X]=0; l[X]<(s)->dimx; ++(l[X])
#define ALL_LOCS_IN_REGION(s,l) l[Z]=(s)->mark1[Z]; l[Z]<=(s)->mark2[Z]; ++(l[Z])) for (l[Y]=(s)->mark1[Y]; l[Y]<=(s)->mark2[Y]; ++(l[Y])) for (l[X]=(s)->mark1[X]; l[X]<=(s)->mark2[X]; ++(l[X])
#define ALL_CELLS_IN_SHEET(s,i,c) i=0,c=*((s)->sheet); i<(s)->dimx*(s)->dimy*(s)->dimz; ++i, c=*((s)->sheet+i)
extern Sheet *upd_sheet;
extern Location upd_l;
extern int max_eval;
void initialize_sheet(Sheet *sheet);
void resize(Sheet *sheet, int x, int y, int z, bool *qextended);
Cell *initcellofsheet(Sheet *sheet, const Location at, bool *qnew);
void copycelltosheet(const Cell *fromcell, Sheet *sheet2,
const Location to, LabelHandling lh);
Cell *safe_cell_at(Sheet *sheet, const Location at);
Cell *safe_cell_atc(Sheet *sheet, int x, int y, int z);
Cell *curcell(Sheet *sheet);
void cachelabels(Sheet *sheet);
void freesheet(Sheet *sheet, int all);
void forceupdate(Sheet *sheet);
MarkState getmarkstate(Sheet *sheet);
void dump_current_cell(Sheet *sheet);
void freecellofsheet(Sheet *sheet, const Location at);
int columnwidth(Sheet *sheet, int x, int z);
bool setwidth(Sheet *sheet, int x, int z, int width);
int cellwidth(Sheet *sheet, const Location at);
void puttok(Sheet *sheet, const Location at, Token t, TokVariety v);
Token recompvalue(Sheet *sheet, const Location at);
void update(Sheet *sheet);
char *geterror(Sheet *sheet, const Location at);
void printvalue(char *s, size_t size, size_t chars, StringFormat sf,
FloatFormat ff, int precision, Sheet *sheet, const Location at);
bool setadjust(Sheet *sheet, const Location at, Adjust adjust);
bool shadow(Sheet *sheet, const Location at, bool yep);
bool bold(Sheet *sheet, const Location at, bool yep);
bool underline(Sheet *sheet, const Location at, bool yep);
bool lockcell(Sheet *sheet, const Location at, bool yep);
bool maketrans(Sheet *sheet, const Location at, bool yep);
bool igncell(Sheet *sheet, const Location at, bool yep);
void clk(Sheet *sheet, const Location at);
bool setfltformat(Sheet *sheet, const Location at, FloatFormat ff);
bool setprecision(Sheet *sheet, const Location at, int precision);
void setlabel(Sheet *sheet, const Location at, const char *buf, int update);
Token findlabel(Sheet *sheet, const char *label);
void relabel(Sheet* sheet, const Location at,
const char *oldlabel, const char *newlabel);
const char *savetbl(Sheet *sheet, const char *name, int body, const Location beg, const Location end, unsigned int *count);
const char *savetext(Sheet *sheet, const char *name, const Location beg, const Location end, unsigned int *count);
const char *savecsv(Sheet *sheet, const char *name, char sep, const Location beg, const Location end, unsigned int *count);
const char *saveport(Sheet *sheet, const char *name, unsigned int *count);
const char *loadport(Sheet *sheet, const char *name);
const char *loadcsv(Sheet *sheet, const char *name);
void insertcube(Sheet *sheet, const Location beg, const Location end, Direction ins);
void deletecube(Sheet *sheet, const Location beg, const Location end, Direction ins);
void moveblock(Sheet *sheet, const Location beg, const Location end, const Location dest, int copy);
const char *sortblock(Sheet *sheet, const Location beg, const Location end, Direction dir, Sortkey *sk, size_t sklen);
void mirrorblock(Sheet *sheet, const Location beg, const Location end, Direction dir);
#ifdef __cplusplus
}
#endif
#endif