"Fossies" - the Fresh Open Source Software Archive

Member "teapot-2.3.0/fteapot.fl" (6 Feb 2012, 23852 Bytes) of package /linux/privat/old/teapot-2.3.0.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 # data file for the Fltk User Interface Designer (fluid)
    2 version 1.0300
    3 header_name {.h}
    4 code_name {.cxx}
    5 decl {\#include <stdint.h>} {private global
    6 }
    7 
    8 decl {\#include <limits.h>} {private global
    9 }
   10 
   11 decl {\#include <fcntl.h>} {private global
   12 }
   13 
   14 decl {\#define shadow _shadow} {private global
   15 }
   16 
   17 decl {\#define transparent _transparent} {private global
   18 }
   19 
   20 decl {\#define MenuChoice _MenuChoice} {private global
   21 }
   22 
   23 decl {\#define Cell _Cell} {private global
   24 }
   25 
   26 decl {\#include <FL/fl_message.H>} {private local
   27 }
   28 
   29 decl {\#include <FL/fl_draw.H>} {private global
   30 }
   31 
   32 decl {\#include <FL/Fl_Native_File_Chooser.H>} {private global
   33 }
   34 
   35 decl {\#include <FL/Fl_File_Icon.H>} {private global
   36 }
   37 
   38 decl {\#include <FL/filename.H>} {private global
   39 }
   40 
   41 decl {\#include <FL/Fl_Table.H>} {public global
   42 }
   43 
   44 decl {\#include <FL/Fl_Select_Browser.H>} {public global
   45 }
   46 
   47 decl {\#include <FL/Fl_Sys_Menu_Bar.H>} {public global
   48 }
   49 
   50 decl {\#undef shadow} {private global
   51 }
   52 
   53 decl {\#undef transparent} {private global
   54 }
   55 
   56 decl {\#undef MenuChoice} {private global
   57 }
   58 
   59 decl {\#undef Cell} {private global
   60 }
   61 
   62 decl {\#include "misc.h"} {private global
   63 }
   64 
   65 decl {\#include "display.h"} {public global
   66 }
   67 
   68 decl {\#define SHEET(s,x,y,z) (*(s->sheet+(x)*s->dimz*s->dimy+(y)*s->dimz+(z)))} {private global
   69 }
   70 
   71 decl {\#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 
   74 class 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();
   87 col_resize_min(10);
   88 col_resize(true);
   89 col_header(header);
   90 row_resize(false);
   91 row_header(header);
   92 set_visible_focus();
   93 table_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;
  101 s->display = (void *)this;
  102 clear();
  103 update_table();
  104 do_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);
  114 switch (context) {
  115 case 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 
  129 case CONTEXT_STARTPAGE:
  130 	adjust_outside();
  131 	if (Fl::event_button1()) update_sheet();
  132 	break;
  133 
  134 case 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 
  144 case 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 
  154 case 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 
  189 default:
  190 	return;
  191 }} {selected
  192 	}
  193   }
  194   Function {update_table()} {open return_type void
  195   } {
  196 	code {if (updating) return;
  197 
  198 updating = 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 
  201 if (cursheet->dimx > cols()) cols(cursheet->dimx);
  202 if (cursheet->dimy > rows()) rows(cursheet->dimy);
  203 adjust_outside();
  204 
  205 for (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 }
  209 col_position(cursheet->offx);
  210 row_position(cursheet->offy);
  211 set_selection(cursheet->cury, cursheet->curx, cursheet->cury, cursheet->curx);
  212 move_cursor(0,0);
  213 updating = false;} {}
  214   }
  215   Function {update_sheet()} {return_type void
  216   } {
  217 	code {int x1, x2, y1, y2;
  218 
  219 if (updating) return;
  220 updating = true;
  221 
  222 get_selection(y1, x1, y2, x2);
  223 if (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 }
  231 moveto(cursheet, current_col, current_row, -1);
  232 visible_cells(cursheet->offy, cursheet->maxy, cursheet->offx, cursheet->maxx);
  233 cursheet->maxx -= cursheet->offx;
  234 cursheet->maxy -= cursheet->offy;
  235 
  236 if (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 
  244 updating = 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 
  304 return 1;} {}
  305   }
  306   Function {adjust_outside()} {open protected return_type void
  307   } {
  308 	code {int x1, x2, y1, y2;
  309 
  310 if (!cols() || !rows()) {
  311 	cols(1);
  312 	rows(1);
  313 }
  314 
  315 visible_cells(y1, y2, x1, x2);
  316 //printf("adj: (%i,%i)-(%i,%i) %ix%i\\n", x1, y1, x2, y2, cols(), rows());
  317 if (x2+2 < cols() && cols() > cursheet->dimx) cols(x2+2 < cursheet->dimx?cursheet->dimx:x2+2);
  318 else 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 
  326 if (y2+2 < rows() && rows() > cursheet->dimy) rows(y2+2 < cursheet->dimy?cursheet->dimy:y2+2);
  327 else 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 
  336 class 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();
  347 else 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();
  355 Key action = (Key)(intptr_t)o->mvalue()->user_data();
  356 
  357 if (do_sheetcmd(sheet, action, sheet->moveonly) && doanyway(sheet, _("Sheet modified, leave anyway?"))) {
  358 	window->hide();
  359 	return;
  360 }
  361 
  362 table->update_table();
  363 table->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);
  549 if (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();
  558 table->update_sheet();
  559 
  560 const char *label = getlabel(sheet,sheet->curx,sheet->cury,sheet->curz);
  561 char moveonly=sheet->moveonly ? *_("V") : *_("E");
  562 
  563 char buf[1024];
  564 if (*label == 0) snprintf(buf, sizeof(buf), "%c @@(%d,%d,%d)=", moveonly, sheet->curx, sheet->cury, sheet->curz);
  565 else snprintf(buf, sizeof(buf), "%c @@(%s)=", moveonly, label);
  566 
  567 if (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 
  579 char *err;
  580 char val[1024];
  581 if ((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 
  593 line_edit(sheet, val, 0, buf, 0, 0);
  594 int x = sheet->curx, y = sheet->cury, z = sheet->curz;
  595 int adj = getadjust(sheet, x, y, z);
  596 if (adj == LEFT) left->setonly();
  597 else if (adj == RIGHT) right->setonly();
  598 else if (adj == CENTER) center->setonly();
  599 if (shadowed(sheet, x+1, y, z)) shadow->set();
  600 else shadow->clear();
  601 if (::transparent(sheet, x, y, z)) transparent->set();
  602 else transparent->clear();
  603 if (locked(sheet, x, y, z)) lock->set();
  604 else lock->clear();
  605 if (ignored(sheet, x, y, z)) ignore->set();
  606 else ignore->clear();
  607 if (isbold(sheet, x, y, z)) bold->set();
  608 else bold->clear();
  609 if (underlined(sheet, x, y, z)) underline->set();
  610 else underline->clear();
  611 if (getscientific(sheet, x, y, z)) sci->set();
  612 else 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 
  631 line_label->copy_label(prompt);
  632 
  633 int ww = 0, hh = 0;
  634 line_label->measure_label(ww, hh);
  635 line_input->resize(line_label->x()+ww+5, line_input->y(), line_label->w()-ww-7, line_input->h());
  636 line_input->value(buf);
  637 
  638 if (!x) return 0;
  639 
  640 line_input->maximum_size(size);
  641 line_input->position(*x, *x);
  642 line_label->activate();
  643 line_input->activate();
  644 table->sheet()->moveonly = 1;
  645 line_input->take_focus();
  646 
  647 edit_rc = -1;
  648 while (line_label->active()) Fl::wait();
  649 
  650 memcpy(buf, line_input->value(), size);
  651 line_input->deactivate();
  652 table->sheet()->moveonly = 0;
  653 table->take_focus();
  654 return edit_rc;} {}
  655   }
  656   Function {line_msg(const char *prompt, const char *msg)} {return_type void
  657   } {
  658 	code {char label[1024];
  659 snprintf(label, sizeof(label), "%s%s%s", prompt?prompt:"", prompt?" ":"", msg);
  660 status->copy_label(label);} {}
  661   }
  662   decl {friend void line_msg(const char*, const char*);} {private local
  663   }
  664 }
  665 
  666 Function {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];
  669 Fl_Native_File_Chooser chooser;
  670 
  671 chooser.title(title);
  672 chooser.type(create?Fl_Native_File_Chooser::BROWSE_SAVE_FILE:Fl_Native_File_Chooser::BROWSE_FILE);
  673 chooser.filter(pattern);
  674 chooser.options((create?Fl_Native_File_Chooser::NEW_FOLDER:0)|Fl_Native_File_Chooser::SAVEAS_CONFIRM);
  675 
  676 if (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 }
  682 if (chooser.show()) return NULL;
  683 
  684 strncpy(buf, chooser.filename(), sizeof(buf));
  685 buf[sizeof(buf)-1] = 0;
  686 return buf;} {}
  687 }
  688 
  689 Function {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 
  693 const char *val = fl_input("%s", buf, prompt);
  694 if (val) {
  695 	strncpy(buf, val, size);
  696 	buf[size-1] = 0;
  697 }
  698 
  699 return !val;} {}
  700 }
  701 
  702 Function {line_ok(const char *prompt, int curx)} {C return_type int
  703 } {
  704   code {int rc = !!fl_choice("%s", "&No", NULL, "&Yes", prompt);
  705 if (Fl::event_key(FL_Escape)) return -1;
  706 return rc;} {}
  707 }
  708 
  709 Function {line_msg(const char *prompt, const char *msg)} {C return_type void
  710 } {
  711   code {MainWindow::current->line_msg(prompt, msg);} {}
  712 }
  713 
  714 Function {keypressed()} {open C return_type int
  715 } {
  716   code {while (Fl::wait(.01)) if (Fl::event_key(FL_Escape)) return 1;
  717 return 0;} {}
  718 }
  719 
  720 Function {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();
  743 while (choice->str) {
  744 	line_menu_browser->add(choice->str+1);
  745 	choice++;
  746 }
  747 
  748 line_menu_menu->show();
  749 while (line_menu_menu->shown()) Fl::wait();
  750 
  751 return line_menu_browser->value()-1;} {}
  752 }
  753 
  754 Function {redraw_sheet(Sheet *sheet)} {C return_type void
  755 } {
  756   code {TeapotTable *t = (TeapotTable*)sheet->display;
  757 t->update_table();
  758 t->redraw();} {}
  759 }
  760 
  761 Function {redraw_cell(Sheet *sheet, int x, int y, int z)} {C return_type void
  762 } {
  763   code {redraw_sheet(sheet);} {}
  764 }
  765 
  766 Function {display_init(Sheet *sheet, int always_redraw)} {open C return_type void
  767 } {
  768   code {Fl::get_system_colors();
  769 \#ifdef ENABLE_HELP
  770 Fl_File_Icon::load_system_icons();
  771 \#endif
  772 Fl::scheme("gtk+");
  773 int ch = sheet->changed;
  774 resize(sheet, 1, 1, 1);
  775 sheet->changed = ch;
  776 new MainWindow(sheet);} {}
  777 }
  778 
  779 Function {display_end()} {C return_type void
  780 } {
  781   code {} {}
  782 }
  783 
  784 Function {display_main(Sheet *cursheet)} {C return_type void
  785 } {
  786   code {((TeapotTable *)cursheet->display)->parent()->show();
  787 Fl::run();} {}
  788 }
  789 
  790 Function {show_menu(Sheet *sheet)} {C return_type Key
  791 } {
  792   code {return K_NONE;} {}
  793 }
  794 
  795 decl {MainWindow *MainWindow::current;} {private global
  796 }
  797 
  798 declblock {\#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();
  805 if (strchr(text, '<')) {
  806 	d->value(text);
  807 } else {
  808 	d->load(text);
  809 }
  810 d->resize(d->x(), d->y(), d->w()*3/2, d->h()*3/2);
  811 d->show();} {}
  812   }
  813 }
  814 
  815 declblock {\#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);
  820 fl_message("%s", txt);
  821 free(txt);} {}
  822   }
  823 }
  824 
  825 Function {find_helpfile(char *buf, int size, const char *argv0)} {open C return_type void
  826 } {
  827   code {fl_filename_absolute(buf, size, argv0);
  828 char *p = (char *)fl_filename_name(buf);
  829 strncpy(p, "../share/doc/teapot/html/index.html", buf+size-p);
  830 buf[size-1] = 0;
  831 
  832 // Check if help exists in default installed location, fallback value is valid for build directory
  833 int test = open(buf, O_RDONLY);
  834 if (test < 0) strncpy(p, "html/index.html", buf+size-p);
  835 else close(test);
  836 buf[size-1] = 0;
  837 
  838 // Try the configure-time determined value
  839 test = open(buf, O_RDONLY);
  840 if (test < 0) strncpy(buf, HELPFILE, size);
  841 else close(test);
  842 buf[size-1] = 0;
  843 
  844 // Fall back to a sane value for unixoid systems
  845 test = open(buf, O_RDONLY);
  846 if (test < 0) strncpy(buf, "/usr/share/doc/teapot/html/index.html", size);
  847 else close(test);
  848 buf[size-1] = 0;
  849 
  850 } {}
  851 }