1 /* 2 Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd. 3 All rights reserved. 4 5 Redistribution and use in source and binary forms, with or without 6 modification, are permitted provided that the following conditions are 7 met: 8 9 - Redistributions of source code must retain the above copyright 10 notice, this list of conditions and the following disclaimer. 11 12 - Redistributions in binary form must reproduce the above copyright 13 notice, this list of conditions and the following disclaimer in 14 the documentation and/or other materials provided with the 15 distribution. 16 17 - Neither the name of The Numerical ALgorithms Group Ltd. nor the 18 names of its contributors may be used to endorse or promote products 19 derived from this software without specific prior written permission. 20 21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 22 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 23 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 24 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 25 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 #ifndef _HYPER_H_ 35 #define _HYPER_H_ 1 36 37 #include "fricas_c_macros.h" 38 #include <stdio.h> 39 #include <stdlib.h> 40 #include <unistd.h> 41 #include <limits.h> 42 43 #include <X11/Xlib.h> 44 #include <X11/Xutil.h> 45 #include <X11/Xos.h> 46 47 #include "com.h" 48 #include "token.h" 49 #include "hash.h" 50 51 #define boolean unsigned short int 52 53 #ifndef TRUE 54 #define TRUE ((boolean) 0x1) 55 #endif 56 #ifndef FALSE 57 #define FALSE ((boolean) 0x0) 58 #endif 59 60 /* Struct forward declarations */ 61 62 struct text_node; 63 struct input_box; 64 struct input_window; 65 struct paste_node; 66 struct radio_boxes; 67 struct group_item; 68 69 #define Scrollupbutton 1 70 #define Scrolldownbutton 2 71 #define Noopbutton 6 72 73 #define Scrolling 1 74 #define Header 2 75 #define Footer 3 76 #define Title 4 77 78 extern int MenuServerOpened; 79 80 /* These are all the colors one can use in HyperDoc. */ 81 82 extern int gActiveColor, 83 fricas_color, 84 gBackgroundColor, 85 gBfColor, 86 gControlBackgroundColor, 87 gControlForegroundColor, 88 gEmColor, 89 gInputBackgroundColor, 90 gInputForegroundColor, 91 gItColor, 92 gRmColor, 93 gSlColor, 94 gTtColor; 95 96 /* These are all the different fonts one can use in HyperDoc. */ 97 98 extern XFontStruct *gActiveFont, 99 * fricas_font, 100 *gBfFont, 101 *gEmFont, 102 *gInputFont, 103 *gItFont, 104 *gRmFont, 105 *gSlFont, 106 *gTitleFont, 107 *gTtFont; 108 109 110 /** I am implementing a state node stack, this is the structure I store **/ 111 112 typedef struct state_node { 113 int last_ch, last_token, input_type; 114 long fpos, keyword_fpos; 115 long page_start_fpos; 116 Token token; 117 char *input_string; 118 FILE *cfile; 119 int keyword; 120 struct state_node *next; 121 } StateNode; 122 123 /** pointer to the top of the state node graph **/ 124 extern StateNode *top_state_node; 125 126 127 /* structure for a hyper text link */ 128 typedef struct hyper_link { 129 int type; /* Memolink, Spadlink, Downlink etc. */ 130 Window win; /* X11 window containing active area */ 131 union { 132 struct text_node *node; /* ID of link to which link refers */ 133 struct input_box *box; 134 struct input_window *string; 135 struct paste_node *paste; /* the paste node area */ 136 } reference; 137 int x,y; /* relative position inside page */ 138 } HyperLink; 139 140 141 typedef struct if_node { 142 struct text_node *cond; /* the condition nodes*/ 143 struct text_node *thennode; 144 struct text_node *elsenode; 145 } IfNode; 146 147 typedef struct item_stack { 148 int indent; 149 int item_indent; 150 int in_item; 151 struct item_stack *next; 152 } ItemStack; 153 154 typedef struct paste_node { 155 char *name; 156 int where; /* where should I be parsing from? */ 157 short int hasbutton; 158 short int haspaste; 159 struct group_item *group; 160 ItemStack *item_stack; 161 struct text_node *arg_node; 162 struct text_node *end_node; 163 struct text_node *begin_node; 164 struct input_window *paste_item; 165 } PasteNode; 166 167 /* Structure for formatted hypertext */ 168 169 typedef struct text_node { 170 short type; /* type of node (text, link, etc.) */ 171 int x,y, width, height; /* relative location on screen */ 172 int space; /* was there space in front of me ? */ 173 union { 174 char *text; /* piece of text to display */ 175 struct text_node *node; /* argument text */ 176 struct if_node *ifnode; 177 } data; 178 HyperLink *link; /* link for active text */ 179 union { 180 Pixmap pm; /* pixmap for bit images */ 181 XImage *xi; /* pixmap image */ 182 } image; 183 struct text_node *next; /* next node in formatted text */ 184 } TextNode; 185 186 /** Structure used to store pixmaps and bitmaps **/ 187 188 typedef struct image_struct { 189 int width,height; /** It's width and height **/ 190 union { 191 Pixmap pm; 192 XImage *xi; 193 } image; 194 char *filename; /** The filename used to reference it **/ 195 } ImageStruct; 196 197 /* Structure for locating HyperDoc pages in a source file */ 198 199 typedef struct { 200 char *name; /* file name */ 201 long pos; /* position in file */ 202 int ln; /* the line number */ 203 } FilePosition; 204 205 /*** The structure needed for storing a macro **/ 206 207 typedef struct macro_store { 208 short int loaded; 209 FilePosition fpos; 210 char *name; 211 char *macro_string; 212 short number_parameters; 213 } MacroStore; 214 215 216 /** Structure needed for storing a patch **/ 217 typedef struct patch_store { 218 short int loaded; 219 FilePosition fpos; 220 char *name; 221 char *string; 222 } PatchStore; 223 224 /* Here are the structures needed for doing input to HyperDoc windows. */ 225 226 typedef struct line_struct { 227 char *buffer; 228 int changed; /* Has the line changed */ 229 int line_number; 230 int buff_pntr; 231 int len; 232 struct line_struct *prev, *next; 233 } LineStruct; 234 235 typedef struct input_window { 236 char *name; /* symbol name **/ 237 int size; /* the length of the window **/ 238 int cursor_x; /* x-coordinate for the cursor **/ 239 int entered; /* tells me whether I have typed here 240 before */ 241 int num_lines; /* number of lines needed to store 242 buffer */ 243 LineStruct *lines; 244 LineStruct *curr_line; /* the current line on which the cursor */ 245 Window win; 246 struct input_window *next; 247 } InputItem; 248 249 250 /* structure for storing input boxes **/ 251 typedef struct input_box { 252 char *name; 253 ImageStruct *selected, *unselected; 254 short int picked; 255 struct input_box *next; 256 struct radio_boxes *rbs; 257 Window win; 258 } InputBox; 259 260 typedef struct radio_boxes { 261 char *name; 262 InputBox *boxes; 263 ImageStruct *selected, *unselected; 264 int width, height; 265 struct radio_boxes *next; 266 } RadioBoxes; 267 268 /* Structure for spadcommand dependencies hash table entries */ 269 typedef struct spadcom_depend { 270 char *label; /* dependency label */ 271 TextNode *spadcom; /* spadcommand defining the label */ 272 short executed; /* true iff spadcommand has benn executed */ 273 } SpadcomDepend; 274 275 typedef struct button_list { 276 int x0,y0,x1,y1; 277 HyperLink *link; 278 Window win; 279 struct button_list *next; 280 } ButtonList; 281 282 /* Structure for unformatted hyper text page */ 283 284 typedef struct hyperdoc_page { 285 short type; /* Normal, Quitbutton, Upbutton etc. */ 286 char *name; /* ID of page */ 287 char *filename; /* The name of the file in which the page 288 occurs, Null if not */ 289 int scroll_off; /* The offset in the scrolling region */ 290 int bot_scroll_margin; /* bottom of the scrolling region */ 291 int top_scroll_margin; /* top of the scrolling region */ 292 TextNode *title; /* the title of the page */ 293 TextNode *header; /* formatted version of page */ 294 TextNode *scrolling; /* Top of scrolling region */ 295 TextNode *footer; /* top of non-scrolling region at bottom */ 296 Sock *sock; /* socket connection for spad buffer */ 297 HashTable *fLinkHashTable; /* active link hash table */ 298 ButtonList *s_button_list; /* active buttons on page */ 299 ButtonList *button_list; /* active buttons on page */ 300 HashTable *depend_hash; /* Hash tables of spadcommand dependencies */ 301 InputItem *input_list; /* List of input structures */ 302 InputItem *current_item; /* a pntr to the currently active item */ 303 HashTable *box_hash; /* place where all the boxes are stored */ 304 RadioBoxes *radio_boxes; /* a linked list of radio boxes */ 305 short page_flags; /* A list of flags for the page */ 306 char *helppage; /* the name of the helppage */ 307 } HyperDocPage; 308 309 /* Structure for an unloaded page */ 310 311 typedef struct unloaded_page { 312 short type; /* indicator of unloaded page */ 313 char *name; /* name of page */ 314 FilePosition fpos; /* where to find the page */ 315 } UnloadedPage; 316 317 /* Structure for a HyperDoc Window */ 318 319 typedef struct { 320 Window fMainWindow; /* The main text field window. */ 321 Window fScrollWindow; /* The scrolling area of the window */ 322 Window fDisplayedWindow; /* The current window of the above two, */ 323 /* being filled by display */ 324 325 Window fScrollUpWindow; /* Window for scrolling up a line */ 326 Window fScrollDownWindow; /* Window for scrolling down a line */ 327 328 Window scrollbar; /* the window for scrolling */ 329 Window scroller; /* the scroller window */ 330 331 Window fTitleBarButton1; /* 1st titlebar bitmap button */ 332 Window fTitleBarButton2; /* 2nd titlebar bitmap button */ 333 Window fTitleBarButton3; /* 3rd titlebar bitmap button */ 334 Window fTitleBarButton4; /* 4th titlebar bitmap button */ 335 336 int fScrollerTopPos; /* where the top of the scroller is */ 337 int fScrollerHeight; /* the height of the scroller */ 338 int fScrollBarHeight; /* the height for the scrollbar */ 339 340 int scrollwidth; /* the width of the scrolling area */ 341 int scrollheight; /* the height of the scrolling area */ 342 int scrollupy; /* Current y position of the scroll up */ 343 /* button */ 344 int scrolldowny; /* Current y position of the scroll */ 345 /* downbutton */ 346 int scrollbary; /* Current y position of the scrollbar */ 347 int scrollx; /* X coordinates for all of the above */ 348 int border_width; /* Width of the border */ 349 HyperDocPage *page; /* currently displayed page */ 350 int width, height; /* in pixels */ 351 int columns; /* Width in characters, only setable */ 352 /* for form pages */ 353 HyperDocPage **fMemoStack; /* stack of memo links */ 354 HyperDocPage **fDownLinkStack;/* stack of down links */ 355 356 int *fDownLinkStackTop; /* stack of down links */ 357 int fMemoStackIndex; /* memo stack pointer */ 358 int fDownLinkStackIndex; /* downlink stack pointer */ 359 360 HashTable *fWindowHashTable; /* hash table of active subwindows */ 361 HashTable *fPageHashTable; /* hash table of HyperDoc pages */ 362 HashTable *fPasteHashTable; /* hash table for paste in areas */ 363 HashTable *fMacroHashTable; /* hash table of HyperDoc macros */ 364 HashTable *fCondHashTable; /* hash table for values */ 365 HashTable *fPatchHashTable; /* hash table for patch locations */ 366 367 int fricas_frame; /* FriCAS frame number initializing window */ 368 GC fStandardGC; /* Graphics context for window */ 369 GC fInputGC; /* Graphics context for the input windows */ 370 GC fCursorGC; /* Graphics context for the cursors */ 371 GC fControlGC; /* Graphics context for the buttons */ 372 Cursor fDisplayedCursor; /* The currently displayed cursor */ 373 } HDWindow; 374 375 /* Structure for identifying appropriate link hash tables */ 376 377 typedef struct { 378 int code; /* code of active area */ 379 HyperDocPage *page; /* page for which hash table applies */ 380 } LinkHashID; 381 382 /*** Flags for the page ***/ 383 384 #define NOLINES 0000001 /* Ibid, for the bottom of the page ***/ 385 386 387 /* external variables and functions. See the source file for a description 388 of their purposes */ 389 390 extern HashTable gSessionHashTable; /* hash table of HD windows */ 391 392 extern HDWindow *gParentWindow; /* the parent window. The one that 393 * appears when you first start HD */ 394 395 extern HyperLink *quitLink; /** a special link to the protected quit page **/ 396 397 398 /* From hyper.c */ 399 extern int gXScreenNumber; 400 extern Display *gXDisplay; 401 extern int gSwitch_to_mono; 402 extern unsigned long * spadColors; 403 extern int gIsEndOfOutput; 404 extern HDWindow *gWindow; 405 extern Sock *session_server; 406 extern Sock *spad_socket; 407 extern HashTable gFileHashTable; 408 extern HashTable gImageHashTable; /* A global hash table for images */ 409 extern Cursor gNormalCursor; /* The normal mouse cursor */ 410 extern Cursor gActiveCursor; /* The cursor in active regions */ 411 extern Cursor gBusyCursor; /* The clock cursor for when I am busy */ 412 /* true iff HyperDoc is acting as a FriCAS server */ 413 extern int is_fricas_server; 414 extern int gArgc; /* original argc from main */ 415 extern char **gArgv; /* original argv from main */ 416 /* from lex.c */ 417 extern long fpos, keyword_fpos; 418 extern Token token; 419 extern int last_token, input_type, last_ch; 420 extern char *input_string; 421 extern FILE *cfile; 422 /* from input.c */ 423 extern XImage *picked; 424 extern int picked_height; 425 extern int picked_width; 426 extern XImage *unpicked; 427 extern int unpicked_height; 428 extern int unpicked_width; 429 /* from display.c */ 430 extern int line_height; 431 extern int need_scroll_up_button; 432 extern int scrolling; 433 extern int need_scroll_down_button; 434 extern int space_width; 435 436 /* Here are some of the functions and constants declared and needed in 437 htadd.c ******/ 438 439 #define NoChar -9999 440 #define temp_dir "/tmp/" 441 #define db_file_name "ht.db" 442 443 444 /* Types of HyperDoc pages */ 445 446 #define UlUnknownPage 9993 /*I hate this hack, but I have to know whether*/ 447 #define UnknownPage 9994 /*this page has been loaded or not. */ 448 #define ErrorPage 9995 449 #define Unixfd 9996 450 #define SpadGen 9997 451 #define Normal 9998 452 #define UnloadedPageType 9999 453 454 /* Commands from FriCAS */ 455 456 #define EndOfPage 99 457 #define SendLine 98 458 #define StartPage 97 /* A normal HyperDoc page */ 459 #define LinkToPage 96 460 #define PopUpPage 95 /* A pop-up page */ 461 #define PopUpNamedPage 94 462 #define KillPage 93 463 #define ReplacePage 92 464 #define ReplaceNamedPage 91 465 #define SpadError 90 466 467 /* Constants declaring size of page stacks */ 468 469 #define MaxMemoDepth 25 /* max nesting level for memolinks */ 470 #define MaxDownlinkDepth 50 /* max downlink nesting depth */ 471 472 /* Constants defining the size of various hash tables */ 473 474 #define PageHashSize 1000 475 #define FileHashSize 30 476 #define SessionHashSize 10 477 #define MacroHashSize 100 478 #define ImageHashSize 100 479 #define CondHashSize 100 480 #define BoxHashSize 20 481 #define PasteHashSize 100 482 #define PatchHashSize 100 483 484 /* A couple of macros for memo and down links */ 485 486 #define need_up_button \ 487 (gWindow->fMemoStackIndex ? gWindow->fDownLinkStackIndex >= \ 488 gWindow->fDownLinkStackTop[gWindow->fMemoStackIndex-1] \ 489 : gWindow->fDownLinkStackIndex) 490 491 #define need_return_button (gWindow->fMemoStackIndex) 492 493 #define need_help_button (gWindow->page->helppage != NULL) 494 495 #define max(x,y) ((x) > (y) ? (x) : (y)) 496 497 498 #define pick_box(box) fill_box(box->win, box->selected) 499 #define unpick_box(box) fill_box(box->win, box->unselected) 500 501 #define TopLevelHelpPage "ugHyperPage" 502 #define NoMoreHelpPage "NoMoreHelpPage" 503 #define KeyDefsHelpPage "ugHyperKeysPage" 504 #define InputAreaHelpPage "ugHyperInputPage" 505 506 /* definitions for connecting to the FriCAS server */ 507 508 #define Connected 0 509 #define NotConnected 1 510 #define SpadBusy 2 511 512 /* some GUI-dependent stuff */ 513 514 #define BeepAtTheUser() /* (XBell(gXDisplay, 5)) */ 515 #define LoudBeepAtTheUser() /* (XBell(gXDisplay, 50)) */ 516 517 518 /*** default fonts ***/ 519 520 #define RmFontDefault "-adobe-courier-medium-r-normal--18-*-*-*-m-*-iso8859-1" 521 #define TtFontDefault "-adobe-courier-medium-r-normal--18-*-*-*-m-*-iso8859-1" 522 #define ActiveFontDefault "-adobe-courier-bold-r-normal--18-*-*-*-m-*-iso8859-1" 523 #define fricas_font_default "-adobe-courier-bold-o-normal--18-*-*-*-m-*-iso8859-1" 524 #define EmphasizeFontDefault "-adobe-courier-medium-o-normal--18-*-*-*-m-*-iso8859-1" 525 #define BoldFontDefault "-adobe-courier-bold-r-normal--18-*-*-*-m-*-iso8859-1" 526 527 528 529 530 531 532 typedef struct group_item { 533 int cur_color; 534 XFontStruct *cur_font; 535 int center; 536 struct group_item *next; 537 } GroupItem; 538 539 540 extern GroupItem *gTopOfGroupStack; 541 542 543 typedef struct cond_node { 544 char *label; 545 char *cond; 546 } CondNode; 547 548 typedef struct parameter_list_type { 549 char **list; /** The parameters in string form **/ 550 short number; /** How many parameters are there **/ 551 struct parameter_list_type *next; 552 } *ParameterList; 553 554 extern char *gDatabasePath; 555 556 extern int gBorderColor; 557 558 extern GroupItem *gTopOfGroupStack; 559 560 extern short int gDisplayRegion; 561 extern int gRegionOffset; 562 563 extern Window gActiveWindow; 564 extern int gNeedIconName; 565 566 extern int gScrollbarWidth; 567 568 /* the width and height for all windows in the title bar */ 569 extern int twwidth, twheight; 570 571 extern short int gInPaste; 572 573 #define ucharp_to_charp(x) ((char *)x) 574 575 #endif 576