1# data file for the Fltk User Interface Designer (fluid)
2version 1.0300
3header_name {.h}
4code_name {.cxx}
5decl {\#include <stdint.h>} {private global
6}
7
8decl {\#include <limits.h>} {private global
9}
10
11decl {\#include <fcntl.h>} {private global
12}
13
14decl {\#define shadow _shadow} {private global
15}
16
17decl {\#define transparent _transparent} {private global
18}
19
20decl {\#define MenuChoice _MenuChoice} {private global
21}
22
23decl {\#define Cell _Cell} {private global
24}
25
26decl {\#include <FL/fl_message.H>} {private local
27}
28
29decl {\#include <FL/fl_draw.H>} {private global
30}
31
32decl {\#include <FL/Fl_Native_File_Chooser.H>} {private global
33}
34
35decl {\#include <FL/Fl_File_Icon.H>} {private global
36}
37
38decl {\#include <FL/filename.H>} {private global
39}
40
41decl {\#include <FL/Fl_Table.H>} {public global
42}
43
44decl {\#include <FL/Fl_Select_Browser.H>} {public global
45}
46
47decl {\#include <FL/Fl_Sys_Menu_Bar.H>} {public global
48}
49
50decl {\#undef shadow} {private global
51}
52
53decl {\#undef transparent} {private global
54}
55
56decl {\#undef MenuChoice} {private global
57}
58
59decl {\#undef Cell} {private global
60}
61
62decl {\#include "misc.h"} {private global
63}
64
65decl {\#include "display.h"} {public global
66}
67
68decl {\#define SHEET(s,x,y,z) (*(s->sheet+(x)*s->dimz*s->dimy+(y)*s->dimz+(z)))} {private global
69}
70
71decl {\#define SHADOWED(sheet,x,y,z) (x<sheet->dimx && y<sheet->dimy && z<sheet->dimz && SHEET(sheet,x,y,z)!=(Cell*)0 && SHEET(sheet,x,y,z)->shadowed)} {private global
72}
73
74class TeapotTable {open : {public Fl_Table}
75} {
76  decl {Sheet *cursheet;} {protected local
77  }
78  decl {bool cut, updating;} {protected local
79  }
80  decl {static const TableContext ACTION = (TableContext)(1<<8);} {public local
81  }
82  decl {static const TableContext REFRESH = (TableContext)(1<<9);} {public local
83  }
84  Function {TeapotTable(int x, int y, int w, int h, const char *l=0) : Fl_Table(x, y, w, h, l), cut(false), updating(false)} {open
85  } {
86	code {end();
87col_resize_min(10);
88col_resize(true);
89col_header(header);
90row_resize(false);
91row_header(header);
92set_visible_focus();
93table_box(FL_THIN_UP_FRAME);} {}
94  }
95  Function {~TeapotTable()} {} {
96	code {} {}
97  }
98  Function {sheet(Sheet *s)} {open return_type void
99  } {
100	code {cursheet = s;
101s->display = (void *)this;
102clear();
103update_table();
104do_callback(CONTEXT_NONE, 0, 0);} {}
105  }
106  Function {sheet()} {return_type {Sheet *}
107  } {
108	code {return cursheet;} {}
109  }
110  Function {draw_cell(TableContext context, int R, int C, int X, int Y, int W, int H)} {open return_type void
111  } {
112	code {char s[1024];
113//printf("DRAW: %i @%i,%i - (%i,%i) %ix%i\\n", context, C,R, X,Y, W,H);
114switch (context) {
115case CONTEXT_ENDPAGE:
116	W = X-x()-2;
117	H = Y-y()-2;
118	X = x()+2;
119	Y = y()+2;
120	fl_font(FL_HELVETICA | FL_BOLD, 14);
121	fl_push_clip(X, Y, W, H);
122	fl_draw_box(FL_DIAMOND_UP_BOX, X, Y, W, H, col_header_color());
123	fl_color(FL_INACTIVE_COLOR);
124	sprintf(s, "%d", cursheet->curz);
125	fl_draw(s, X, Y, W, H, FL_ALIGN_CENTER);
126	fl_pop_clip();
127	break;
128
129case CONTEXT_STARTPAGE:
130	adjust_outside();
131	if (Fl::event_button1()) update_sheet();
132	break;
133
134case CONTEXT_COL_HEADER:
135	fl_font(FL_HELVETICA | FL_BOLD, 14);
136	fl_push_clip(X, Y, W, H);
137	fl_draw_box(FL_THIN_UP_BOX, X, Y, W, H, col_header_color());
138	fl_color(FL_FOREGROUND_COLOR);
139	sprintf(s, "%d", C);
140	fl_draw(s, X, Y, W, H, FL_ALIGN_CENTER);
141	fl_pop_clip();
142	return;
143
144case CONTEXT_ROW_HEADER:
145	fl_font(FL_HELVETICA | FL_BOLD, 14);
146	fl_push_clip(X, Y, W, H);
147	fl_draw_box(FL_THIN_UP_BOX, X, Y, W, H, row_header_color());
148	fl_color(FL_FOREGROUND_COLOR);
149	sprintf(s, "%d", R);
150	fl_draw(s, X, Y, W, H, FL_ALIGN_CENTER);
151	fl_pop_clip();
152	return;
153
154case CONTEXT_CELL: {
155	while (SHADOWED(cursheet, C, R, cursheet->curz)) X -= W = col_width(--C);
156	int x = C+1;
157	while (SHADOWED(cursheet,x,R,cursheet->curz)) W += col_width(x), x++;
158
159	fl_push_clip(X, Y, W, H);
160	bool selected = false;
161	if (cursheet->mark1x >= 0) {
162		int x1 = cursheet->mark1x, x2 = cursheet->mark2x, y1 = cursheet->mark1y, y2 = cursheet->mark2y, z1 = cursheet->mark1z, z2 = cursheet->mark2z;
163		posorder(&x1, &x2);
164		posorder(&y1, &y2);
165		posorder(&z1, &z2);
166		selected = cursheet->mark1x >= 0 && C >= x1 && C <= x2 && R >= y1 && R <= y2 && cursheet->curz >= z1 && cursheet->curz <= z2;
167	}
168	fl_draw_box(C == cursheet->curx && R == cursheet->cury?FL_BORDER_BOX:FL_THIN_DOWN_BOX, X, Y, W, H, selected?FL_SELECTION_COLOR:FL_BACKGROUND2_COLOR);
169	if (Fl::focus() == this && C == cursheet->curx && R == cursheet->cury) draw_focus(FL_BORDER_BOX, X, Y, W, H);
170	fl_pop_clip();
171
172	fl_push_clip(X+3, Y+3, W-6, H-6);
173	fl_color(FL_FOREGROUND_COLOR);
174	fl_font(FL_HELVETICA | (isbold(cursheet, C, R, cursheet->curz)? FL_BOLD:0), 14);
175
176	printvalue(s, sizeof(s), 0, 0, getscientific(cursheet, C, R, cursheet->curz), getprecision(cursheet, C, R, cursheet->curz), cursheet, C, R, cursheet->curz);
177	int ww = 0, hh = 0;
178	fl_measure(s, ww, hh, 0);
179	if (ww > W-6) for (int i = 0; s[i]; i++) s[i] = '\#';
180
181	int adj = getadjust(cursheet, C, R, cursheet->curz);
182	fl_draw(s, X+3, Y+3, W-6, H-6, adj == RIGHT?FL_ALIGN_RIGHT:adj == LEFT?FL_ALIGN_LEFT:FL_ALIGN_CENTER);
183	if (underlined(cursheet, C, R, cursheet->curz)) fl_xyline(X, Y+H-7, X+W);
184	fl_pop_clip();
185
186	return;
187}
188
189default:
190	return;
191}} {selected
192	}
193  }
194  Function {update_table()} {open return_type void
195  } {
196	code {if (updating) return;
197
198updating = true;
199//printf("update_table: %ix%i@%i,%i; %i[%i], %i[%i]\\n", cursheet->dimx, cursheet->dimy, cursheet->curx, cursheet->cury, cursheet->offx, cursheet->maxx, cursheet->offy, cursheet->maxy);
200
201if (cursheet->dimx > cols()) cols(cursheet->dimx);
202if (cursheet->dimy > rows()) rows(cursheet->dimy);
203adjust_outside();
204
205for (int x = 0; x < cursheet->dimx; x++) {
206	int w = columnwidth(cursheet, x, cursheet->curz)*10;
207	if (col_width(x) != w) col_width(x, w);
208}
209col_position(cursheet->offx);
210row_position(cursheet->offy);
211set_selection(cursheet->cury, cursheet->curx, cursheet->cury, cursheet->curx);
212move_cursor(0,0);
213updating = false;} {}
214  }
215  Function {update_sheet()} {return_type void
216  } {
217	code {int x1, x2, y1, y2;
218
219if (updating) return;
220updating = true;
221
222get_selection(y1, x1, y2, x2);
223if (x1 != x2 || y1 != y2) {
224	cursheet->mark1x = x1;
225	cursheet->mark1y = y1;
226	cursheet->mark2x = x2;
227	cursheet->mark2y = y2;
228	cursheet->mark1z = cursheet->mark2z = cursheet->curz;
229	cursheet->marking = 0;
230}
231moveto(cursheet, current_col, current_row, -1);
232visible_cells(cursheet->offy, cursheet->maxy, cursheet->offx, cursheet->maxx);
233cursheet->maxx -= cursheet->offx;
234cursheet->maxy -= cursheet->offy;
235
236if (is_interactive_resize()) {
237		for (int C = 0; C < cursheet->dimx; C++) {
238				int w = (col_width(C) + 5)/10;
239				if (w != columnwidth(cursheet, C, cursheet->curz)) setwidth(cursheet, C, cursheet->curz, w);
240		}
241}
242
243
244updating = false;
245//printf("update_sheet: %ix%i@%i,%i; %i[%i], %i[%i] (%i,%i)-(%i,%i)\\n", cols(), rows(), cursheet->curx, cursheet->cury, cursheet->offx, cursheet->maxx, cursheet->offy, cursheet->maxy, x1, y1, x2, y2);} {}
246  }
247  Function {handle(int event)} {open return_type int
248  } {
249	code {if (event == FL_KEYDOWN) {
250	int ctrl = Fl::event_ctrl();
251	int alt = Fl::event_alt();
252	int shift = Fl::event_shift();
253	Key k = (Key)Fl::event_key();
254
255	switch ((unsigned int)k) {
256	case FL_Escape: k = K_INVALID; break;
257	case FL_BackSpace: k = K_BACKSPACE; break;
258	case FL_F+1: k = ctrl?K_ABOUT:K_HELP; break;
259	case FL_F+8: k = ctrl?K_RECALC:K_CLOCK; break;
260	case FL_F+9: k = ctrl?K_RECALC:K_CLOCK; break;
261	case FL_F+10: k = (Key)'/'; break;
262	case FL_Enter:
263	case FL_KP_Enter: k = alt?K_MENTER:K_ENTER; break;
264	case 'c': if (ctrl) { do_mark(cursheet, 2); cut = false; k = K_NONE; } break;
265	case 'v': k = ctrl?(cut?BLOCK_MOVE:BLOCK_COPY):(Key)'v'; break;
266	case 'x': if (ctrl) { do_mark(cursheet, 2); cut = true, k = K_NONE; } break;
267	case FL_Insert: if (ctrl) { do_mark(cursheet, 2); cut = false; } k = !shift?K_NONE:cut?BLOCK_MOVE:BLOCK_COPY; break;
268	case FL_Delete: if (shift) { do_mark(cursheet, 2); cut = true; } k = shift?K_NONE:BLOCK_CLEAR; break;
269	case FL_Home: k = ctrl?K_FIRSTL:shift?K_FSHEET:K_HOME; break;
270	case FL_End: k = ctrl?K_LASTL:shift?K_LSHEET:K_END; break;
271	case FL_Up: if (shift && !cursheet->marking) do_mark(cursheet, 1); k = ctrl?K_PPAGE:K_UP; break;
272	case FL_Down: if (shift && !cursheet->marking) do_mark(cursheet, 1); k = ctrl?K_NPAGE:K_DOWN; break;
273	case FL_Right: if (shift && !cursheet->marking) do_mark(cursheet, 1); k = ctrl?K_FPAGE:K_RIGHT; break;
274	case FL_Left: if (shift && !cursheet->marking) do_mark(cursheet, 1); k = ctrl?K_BPAGE:K_LEFT; break;
275	case FL_Page_Down: k = shift?K_NSHEET:ctrl?K_LASTL :K_NPAGE; break;
276	case FL_Page_Up: k = shift?K_PSHEET:ctrl?K_FIRSTL:K_PPAGE; break;
277	}
278
279	if (k > 0 && (ctrl || alt))  return 0;
280
281	// Quick and dirty upper-case fix, fails for international chars on keyboards...
282	if (shift && !alt && !ctrl && k >= 'a' && k <= 'z') k = (Key)(k - 'a' + 'A');
283
284	do_sheetcmd(cursheet, k, cursheet->moveonly);
285	do_callback(ACTION, 0, 0);
286	redraw();
287} else if (event == FL_FOCUS) {
288	do_callback(REFRESH, 0, 0);
289	return 1;
290} else if (event == FL_PUSH) {
291	int ex = Fl::event_x() - x(), ey = Fl::event_y() - y();
292	if (ex >= row_header_width() || ey >= col_header_height()) {
293		int rc = Fl_Table::handle(event);
294		do_callback(ACTION, 0, 0);
295		return rc;
296	}
297	if (ex < row_header_width()/2) relmoveto(cursheet, 0, 0, -1);
298	else relmoveto(cursheet, 0, 0, 1);
299	return 1;
300} else if (event != FL_KEYUP) {
301	return Fl_Table::handle(event);
302}
303
304return 1;} {}
305  }
306  Function {adjust_outside()} {open protected return_type void
307  } {
308	code {int x1, x2, y1, y2;
309
310if (!cols() || !rows()) {
311	cols(1);
312	rows(1);
313}
314
315visible_cells(y1, y2, x1, x2);
316//printf("adj: (%i,%i)-(%i,%i) %ix%i\\n", x1, y1, x2, y2, cols(), rows());
317if (x2+2 < cols() && cols() > cursheet->dimx) cols(x2+2 < cursheet->dimx?cursheet->dimx:x2+2);
318else if (x2+1 == cols()) {
319	int xpos = col_scroll_position(cols());
320	int w = col_width(cols()-1);
321	x2 += (tow + hscrollbar->value() - xpos) / w + 2;
322	//printf("   : t: %i, w: %i, p: %i, r: %i\\n", tow, w, xpos, x2+1);
323	cols(x2+1);
324}
325
326if (y2+2 < rows() && rows() > cursheet->dimy) rows(y2+2 < cursheet->dimy?cursheet->dimy:y2+2);
327else if (y2+1 == rows()) {
328	int ypos = row_scroll_position(rows());
329	int h = row_height(rows()-1);
330	y2 += (toh + vscrollbar->value() - ypos) / h + 2;
331	rows(y2+1);
332}} {}
333  }
334}
335
336class MainWindow {open
337} {
338  decl {static MainWindow *current;} {protected local
339  }
340  decl {int edit_rc;} {private local
341  }
342  Function {MainWindow(Sheet *sheet)} {open
343  } {
344	Fl_Window window {
345	  label teapot
346	  callback {if (Fl::event_key(FL_Escape)) table->take_focus();
347else if (do_sheetcmd(table->sheet(), K_QUIT, 0) && doanyway(table->sheet(), _("Sheet modified, leave anyway?"))) {
348	line_label->deactivate();
349	window->hide();
350}} open
351	  protected xywh {866 342 800 600} type Double when 0 hide resizable
352	} {
353	  Fl_Menu_Bar menu {
354		callback {Sheet *sheet = table->sheet();
355Key action = (Key)(intptr_t)o->mvalue()->user_data();
356
357if (do_sheetcmd(sheet, action, sheet->moveonly) && doanyway(sheet, _("Sheet modified, leave anyway?"))) {
358	window->hide();
359	return;
360}
361
362table->update_table();
363table->redraw();} open
364		xywh {0 0 800 25}
365		class Fl_Sys_Menu_Bar
366	  } {
367		Submenu {} {
368		  label {&File}
369		  xywh {25 25 67 24}
370		} {
371		  MenuItem {} {
372			label {&Open...}
373			user_data K_LOADMENU
374			xywh {5 5 30 20} shortcut 0x4006f
375		  }
376		  MenuItem {} {
377			label {&Save}
378			user_data K_SAVE
379			xywh {0 0 30 20} shortcut 0x40073
380		  }
381		  MenuItem {} {
382			label {Save &As...}
383			user_data K_NAME
384			xywh {0 0 30 20} shortcut 0x50053 divider
385		  }
386		  MenuItem {} {
387			label {&Quit}
388			user_data K_QUIT
389			xywh {0 0 30 20} shortcut 0x40071
390		  }
391		}
392		Submenu {} {
393		  label {&Block}
394		  xywh {25 25 67 24}
395		} {
396		  MenuItem {} {
397			label {&Insert}
398			user_data BLOCK_INSERT
399			xywh {0 0 30 20} shortcut 0x90069
400		  }
401		  MenuItem {} {
402			label {&Delete}
403			user_data BLOCK_DELETE
404			xywh {0 0 30 20} shortcut 0x90064 divider
405		  }
406		  MenuItem {} {
407			label {&Move}
408			user_data BLOCK_MOVE
409			xywh {0 0 30 20} shortcut 0x9006d
410		  }
411		  MenuItem {} {
412			label {&Copy}
413			user_data BLOCK_COPY
414			xywh {0 0 36 21} shortcut 0x90063 divider
415		  }
416		  MenuItem {} {
417			label {&Fill}
418			user_data BLOCK_FILL
419			xywh {0 0 36 21} shortcut 0x90066
420		  }
421		  MenuItem {} {
422			label {C&lear}
423			user_data BLOCK_CLEAR
424			xywh {0 0 36 21} shortcut 0x9006c divider
425		  }
426		  MenuItem {} {
427			label {&Sort}
428			user_data BLOCK_SORT
429			xywh {0 0 36 21} shortcut 0x90073
430		  }
431		  MenuItem {} {
432			label {Mi&rror}
433			user_data BLOCK_MIRROR
434			xywh {0 0 36 21} shortcut 0x90072
435		  }
436		}
437		Submenu {} {
438		  label {&View}
439		  xywh {0 0 70 21}
440		} {
441		  MenuItem {} {
442			label {Column &Width...}
443			user_data K_COLWIDTH
444			xywh {0 0 36 21} shortcut 0x80077
445		  }
446		  MenuItem {} {
447			label {&Goto}
448			user_data K_GOTO
449			xywh {0 0 36 21} shortcut 0x40067
450		  }
451		}
452		Submenu {} {
453		  label {F&ormat} open
454		  xywh {5 5 70 21}
455		} {
456		  MenuItem {} {
457			label {L&abel...}
458			user_data ADJUST_LABEL
459			xywh {0 0 36 21} shortcut 0x80061 divider
460		  }
461		  MenuItem bold {
462			label {&Bold}
463			user_data ADJUST_BOLD
464			protected xywh {0 0 34 21} shortcut 0x80062
465			code0 {o->flags |= FL_MENU_TOGGLE;}
466		  }
467		  MenuItem underline {
468			label {&Underline}
469			user_data ADJUST_UNDERLINE
470			protected xywh {0 0 34 21} shortcut 0x80075 divider
471			code0 {o->flags |= FL_MENU_TOGGLE;}
472		  }
473		  MenuItem left {
474			label {&Left}
475			user_data ADJUST_LEFT
476			protected xywh {0 0 36 21} shortcut 0x8006c
477			code0 {o->flags |= FL_MENU_RADIO;}
478		  }
479		  MenuItem right {
480			label {&Right}
481			user_data ADJUST_RIGHT
482			protected xywh {0 0 36 21} shortcut 0x80072
483			code0 {o->flags |= FL_MENU_RADIO;}
484		  }
485		  MenuItem center {
486			label {&Center}
487			user_data ADJUST_CENTER
488			protected xywh {0 0 36 21} shortcut 0x80063 divider
489			code0 {o->flags |= FL_MENU_RADIO;}
490		  }
491		  MenuItem {} {
492			label {&Precision...}
493			user_data ADJUST_PRECISION
494			xywh {0 0 36 21} shortcut 0x80070 divider
495		  }
496		  MenuItem sci {
497			label {&Scientific}
498			user_data ADJUST_SCIENTIFIC
499			protected xywh {0 0 36 21} shortcut 0x80073
500			code0 {o->flags |= FL_MENU_TOGGLE;}
501		  }
502		  MenuItem shadow {
503			label {Shadow&ed}
504			user_data ADJUST_SHADOW
505			protected xywh {0 0 36 21} shortcut 0x80065
506			code0 {o->flags |= FL_MENU_TOGGLE;}
507		  }
508		  MenuItem transparent {
509			label {&Transparent}
510			user_data ADJUST_TRANSPARENT
511			protected xywh {0 0 36 21} shortcut 0x80074 divider
512			code0 {o->flags |= FL_MENU_TOGGLE;}
513		  }
514		  MenuItem lock {
515			label {Lo&ck}
516			user_data ADJUST_LOCK
517			protected xywh {0 0 36 21} shortcut 0x80063
518			code0 {o->flags |= FL_MENU_TOGGLE;}
519		  }
520		  MenuItem ignore {
521			label {&Ignore}
522			user_data ADJUST_IGNORE
523			protected xywh {0 0 36 21} shortcut 0x80069
524			code0 {o->flags |= FL_MENU_TOGGLE;}
525		  }
526		}
527		Submenu {} {
528		  label {&Help} open
529		  xywh {25 25 67 24}
530		} {
531		  MenuItem {} {
532			label {&Manual}
533			user_data K_HELP
534			xywh {0 0 30 20} shortcut 0xffbe
535		  }
536		  MenuItem {} {
537			label {&About}
538			user_data K_ABOUT
539			xywh {0 0 30 20}
540		  }
541		}
542	  }
543	  Fl_Group line_label {
544		label { Input:} open
545		protected xywh {0 25 800 25} box ROUND_UP_BOX align 20 deactivate
546	  } {
547		Fl_Input line_input {
548		  callback {bool enterkey = Fl::event_key(FL_Enter) || Fl::event_key(FL_KP_Enter);
549if (Fl::focus() && (Fl::focus() != table || enterkey || Fl::event_key(FL_Escape))) {
550	if (enterkey) edit_rc = 0;
551	line_label->deactivate();
552}}
553		  protected xywh {75 27 723 21} box ROUND_DOWN_BOX labeltype NO_LABEL align 20 when 6 deactivate
554		}
555	  }
556	  Fl_Box table {
557		callback {Sheet *sheet = table->sheet();
558table->update_sheet();
559
560const char *label = getlabel(sheet,sheet->curx,sheet->cury,sheet->curz);
561char moveonly=sheet->moveonly ? *_("V") : *_("E");
562
563char buf[1024];
564if (*label == 0) snprintf(buf, sizeof(buf), "%c @@(%d,%d,%d)=", moveonly, sheet->curx, sheet->cury, sheet->curz);
565else snprintf(buf, sizeof(buf), "%c @@(%s)=", moveonly, label);
566
567if (moveonly && table->callback_context() == TeapotTable::ACTION) {
568	char valbuf[1024] = "";
569	if (Fl::event_key() == 'p' || Fl::event_button1()) sprintf(valbuf, "(%i,%i,%i)", sheet->curx, sheet->cury, sheet->curz);
570	else if (Fl::event_key() == 'v') printvalue(valbuf,sizeof(valbuf),0,1,getscientific(sheet,sheet->curx,sheet->cury,sheet->curz),-1,sheet,sheet->curx,sheet->cury,sheet->curz);
571	else if (Fl::event_key(FL_Tab)) line_input->take_focus();
572	if (valbuf[0]) {
573		line_input->insert(valbuf);
574		line_input->take_focus();
575	}
576}
577
578
579char *err;
580char val[1024];
581if ((err = geterror(sheet, sheet->curx, sheet->cury, sheet->curz))) {
582		strncpy(val,err,sizeof(val));
583		free(err);
584		val[sizeof(val)-1] = 0;
585} else {
586		print(val,sizeof(val),0,1,getscientific(sheet,sheet->curx,sheet->cury,sheet->curz),-1,getcont(sheet,sheet->curx,sheet->cury,sheet->curz,0));
587		if (getcont(sheet,sheet->curx,sheet->cury,sheet->curz,1)) {
588				snprintf(val+strlen(val),sizeof(val)-strlen(val)," -> ");
589				print(val+strlen(val),sizeof(val)-strlen(val),0,1,getscientific(sheet,sheet->curx,sheet->cury,sheet->curz),-1,getcont(sheet,sheet->curx,sheet->cury,sheet->curz,1));
590		}
591}
592
593line_edit(sheet, val, 0, buf, 0, 0);
594int x = sheet->curx, y = sheet->cury, z = sheet->curz;
595int adj = getadjust(sheet, x, y, z);
596if (adj == LEFT) left->setonly();
597else if (adj == RIGHT) right->setonly();
598else if (adj == CENTER) center->setonly();
599if (shadowed(sheet, x+1, y, z)) shadow->set();
600else shadow->clear();
601if (::transparent(sheet, x, y, z)) transparent->set();
602else transparent->clear();
603if (locked(sheet, x, y, z)) lock->set();
604else lock->clear();
605if (ignored(sheet, x, y, z)) ignore->set();
606else ignore->clear();
607if (isbold(sheet, x, y, z)) bold->set();
608else bold->clear();
609if (underlined(sheet, x, y, z)) underline->set();
610else underline->clear();
611if (getscientific(sheet, x, y, z)) sci->set();
612else sci->clear();}
613		protected xywh {0 50 800 525} box DOWN_FRAME labeltype NO_LABEL resizable
614		code0 {table->sheet(sheet);}
615		class TeapotTable
616	  }
617	  Fl_Box status {
618		label {teapot ready.}
619		protected xywh {0 575 800 25} box GTK_ROUND_DOWN_BOX align 20
620	  }
621	}
622	code {current = this;} {}
623  }
624  Function {line_edit(Sheet *sheet, char *buf, size_t size, const char *prompt, size_t *x, size_t *offx)} {open return_type int
625  } {
626	code {if (line_label->active()) {
627	if (x) line_msg(NULL, "Action not possible at this time.");
628	return -1;
629}
630
631line_label->copy_label(prompt);
632
633int ww = 0, hh = 0;
634line_label->measure_label(ww, hh);
635line_input->resize(line_label->x()+ww+5, line_input->y(), line_label->w()-ww-7, line_input->h());
636line_input->value(buf);
637
638if (!x) return 0;
639
640line_input->maximum_size(size);
641line_input->position(*x, *x);
642line_label->activate();
643line_input->activate();
644table->sheet()->moveonly = 1;
645line_input->take_focus();
646
647edit_rc = -1;
648while (line_label->active()) Fl::wait();
649
650memcpy(buf, line_input->value(), size);
651line_input->deactivate();
652table->sheet()->moveonly = 0;
653table->take_focus();
654return edit_rc;} {}
655  }
656  Function {line_msg(const char *prompt, const char *msg)} {return_type void
657  } {
658	code {char label[1024];
659snprintf(label, sizeof(label), "%s%s%s", prompt?prompt:"", prompt?" ":"", msg);
660status->copy_label(label);} {}
661  }
662  decl {friend void line_msg(const char*, const char*);} {private local
663  }
664}
665
666Function {line_file(const char *file, const char *pattern, const char *title, int create)} {open C return_type {const char *}
667} {
668  code {static char buf[PATH_MAX];
669Fl_Native_File_Chooser chooser;
670
671chooser.title(title);
672chooser.type(create?Fl_Native_File_Chooser::BROWSE_SAVE_FILE:Fl_Native_File_Chooser::BROWSE_FILE);
673chooser.filter(pattern);
674chooser.options((create?Fl_Native_File_Chooser::NEW_FOLDER:0)|Fl_Native_File_Chooser::SAVEAS_CONFIRM);
675
676if (file) {
677	fl_filename_absolute(buf, sizeof(buf), file);
678	char *p = (char *)fl_filename_name(buf);
679	*p = 0;
680	chooser.directory(buf);
681}
682if (chooser.show()) return NULL;
683
684strncpy(buf, chooser.filename(), sizeof(buf));
685buf[sizeof(buf)-1] = 0;
686return buf;} {}
687}
688
689Function {line_edit(Sheet *sheet, char *buf, size_t size, const char *prompt, size_t *x, size_t *offx)} {C return_type int
690} {
691  code {if (sheet) return ((MainWindow*)((TeapotTable*)sheet->display)->parent()->user_data())->line_edit(sheet, buf, size, prompt, x, offx);
692
693const char *val = fl_input("%s", buf, prompt);
694if (val) {
695	strncpy(buf, val, size);
696	buf[size-1] = 0;
697}
698
699return !val;} {}
700}
701
702Function {line_ok(const char *prompt, int curx)} {C return_type int
703} {
704  code {int rc = !!fl_choice("%s", "&No", NULL, "&Yes", prompt);
705if (Fl::event_key(FL_Escape)) return -1;
706return rc;} {}
707}
708
709Function {line_msg(const char *prompt, const char *msg)} {C return_type void
710} {
711  code {MainWindow::current->line_msg(prompt, msg);} {}
712}
713
714Function {keypressed()} {open C return_type int
715} {
716  code {while (Fl::wait(.01)) if (Fl::event_key(FL_Escape)) return 1;
717return 0;} {}
718}
719
720Function {line_menu(const char *prompt, const MenuChoice *choice, int curx)} {C return_type int
721} {
722  Fl_Window line_menu_menu {
723	label {Please Choose} open
724	xywh {706 58 250 245} type Double hide resizable modal
725  } {
726	Fl_Group {} {
727	  label {Please Choose:} open
728	  xywh {0 0 250 200} box ENGRAVED_BOX align 21
729	} {
730	  Fl_Browser line_menu_browser {
731		callback {line_menu_menu->hide();}
732		xywh {5 25 240 170}
733		class Fl_Select_Browser
734	  }
735	}
736	Fl_Button {} {
737	  label Cancel
738	  callback {line_menu_menu->hide();}
739	  xywh {5 205 240 35}
740	}
741  }
742  code {line_menu_browser->clear();
743while (choice->str) {
744	line_menu_browser->add(choice->str+1);
745	choice++;
746}
747
748line_menu_menu->show();
749while (line_menu_menu->shown()) Fl::wait();
750
751return line_menu_browser->value()-1;} {}
752}
753
754Function {redraw_sheet(Sheet *sheet)} {C return_type void
755} {
756  code {TeapotTable *t = (TeapotTable*)sheet->display;
757t->update_table();
758t->redraw();} {}
759}
760
761Function {redraw_cell(Sheet *sheet, int x, int y, int z)} {C return_type void
762} {
763  code {redraw_sheet(sheet);} {}
764}
765
766Function {display_init(Sheet *sheet, int always_redraw)} {open C return_type void
767} {
768  code {Fl::get_system_colors();
769\#ifdef ENABLE_HELP
770Fl_File_Icon::load_system_icons();
771\#endif
772Fl::scheme("gtk+");
773int ch = sheet->changed;
774resize(sheet, 1, 1, 1);
775sheet->changed = ch;
776new MainWindow(sheet);} {}
777}
778
779Function {display_end()} {C return_type void
780} {
781  code {} {}
782}
783
784Function {display_main(Sheet *cursheet)} {C return_type void
785} {
786  code {((TeapotTable *)cursheet->display)->parent()->show();
787Fl::run();} {}
788}
789
790Function {show_menu(Sheet *sheet)} {C return_type Key
791} {
792  code {return K_NONE;} {}
793}
794
795decl {MainWindow *MainWindow::current;} {private global
796}
797
798declblock {\#ifdef ENABLE_HELP} {after {\#endif}
799} {
800  decl {\#include <FL/Fl_Help_Dialog.H>} {private global
801  }
802  Function {show_text(const char *text)} {open C return_type void
803  } {
804	code {Fl_Help_Dialog *d = new Fl_Help_Dialog();
805if (strchr(text, '<')) {
806	d->value(text);
807} else {
808	d->load(text);
809}
810d->resize(d->x(), d->y(), d->w()*3/2, d->h()*3/2);
811d->show();} {}
812  }
813}
814
815declblock {\#ifndef ENABLE_HELP} {after {\#endif}
816} {
817  Function {show_text(const char *text)} {open C return_type void
818  } {
819	code {char *txt = striphtml(text);
820fl_message("%s", txt);
821free(txt);} {}
822  }
823}
824
825Function {find_helpfile(char *buf, int size, const char *argv0)} {open C return_type void
826} {
827  code {fl_filename_absolute(buf, size, argv0);
828char *p = (char *)fl_filename_name(buf);
829strncpy(p, "../share/doc/teapot/html/index.html", buf+size-p);
830buf[size-1] = 0;
831
832// Check if help exists in default installed location, fallback value is valid for build directory
833int test = open(buf, O_RDONLY);
834if (test < 0) strncpy(p, "html/index.html", buf+size-p);
835else close(test);
836buf[size-1] = 0;
837
838// Try the configure-time determined value
839test = open(buf, O_RDONLY);
840if (test < 0) strncpy(buf, HELPFILE, size);
841else close(test);
842buf[size-1] = 0;
843
844// Fall back to a sane value for unixoid systems
845test = open(buf, O_RDONLY);
846if (test < 0) strncpy(buf, "/usr/share/doc/teapot/html/index.html", size);
847else close(test);
848buf[size-1] = 0;
849
850} {}
851}
852