/*1Copyright (C) 1991-2002, The Numerical Algorithms Group Ltd.2All rights reserved.3Copyright (C) 2007-2008, Gabriel Dos Reis.4All rights reserved.56Redistribution and use in source and binary forms, with or without7modification, are permitted provided that the following conditions are8met:910- Redistributions of source code must retain the above copyright11notice, this list of conditions and the following disclaimer.1213- Redistributions in binary form must reproduce the above copyright14notice, this list of conditions and the following disclaimer in15the documentation and/or other materials provided with the16distribution.1718- Neither the name of The Numerical Algorithms Group Ltd. nor the19names of its contributors may be used to endorse or promote products20derived from this software without specific prior written permission.2122THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS23IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED24TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A25PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER26OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,27EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,28PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR29PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF30LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING31NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS32SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.33*/3435#ifndef OPENAXIOM_NODE36#define OPENAXIOM_NODE3738#include "open-axiom.h"39#include "hash.h"4041#ifndef X_DISPLAY_MISSING42# include <X11/Xlib.h>43# include <X11/Xutil.h>44# include <X11/Xos.h>45typedef Window openaxiom_window;46typedef Pixmap openaxiom_pixmap;47typedef XImage openaxiom_image;48typedef GC openaxiom_graphic_context;49typedef XFontStruct openaxiom_font;50typedef Cursor openaxiom_cursor;51#else /* X_DISPLAY_MISSING */52typedef OpenAxiom::Handle openaxiom_window;53typedef OpenAxiom::Handle openaxiom_pixmap;54typedef OpenAxiom::Handle openaxiom_image;55typedef OpenAxiom::Handle openaxiom_graphic_context;56typedef OpenAxiom::Handle openaxiom_cursor;57typedef OpenAxiom::Handle openaxiom_font;58#endif /* X_DISPLAY_MISSING */5960/* Struct forward declarations */6162struct TextNode;63struct InputBox;64struct InputItem;65struct paste_node;66struct RadioBoxes;67struct GroupItem;68struct PasteNode;6970#define Scrollupbutton 171#define Scrolldownbutton 272#define Noopbutton 67374#define Scrolling 175#define Header 276#define Footer 377#define Title 478798081/** I am implementing a state node stack, this is the structure I store **/8283struct StateNode {84int last_ch, last_token;85SourceInputKind input_type;86long fpos, keyword_fpos;87long page_start_fpos;88Token token;89char *input_string;90FILE *cfile;91int keyword;92StateNode *next;93};9495/** pointer to the top of the state node graph **/96extern StateNode *top_state_node;979899/* structure for a hyper text link */100struct HyperLink {101int type; /* Memolink, Spadlink, Downlink etc. */102openaxiom_window win; /* X11 window containing active area */103union {104TextNode *node; /* ID of link to which link refers */105InputBox *box;106InputItem *string;107PasteNode *paste; /* the paste node area */108} reference;109int x,y; /* relative position inside page */110};111112113struct IfNode {114TextNode *cond; /* the condition nodes*/115TextNode *thennode;116TextNode *elsenode;117};118119struct ItemStack {120int indent;121int item_indent;122int in_item;123ItemStack *next;124};125126struct PasteNode {127char *name;128SourceInputKind where; /* where should I be parsing from? */129short int hasbutton;130short int haspaste;131GroupItem *group;132ItemStack *item_stack;133TextNode *arg_node;134TextNode *end_node;135TextNode *begin_node;136InputItem *paste_item;137};138139/* Structure for formatted hypertext */140141struct TextNode {142short type; /* type of node (text, link, etc.) */143int x,y, width, height; /* relative location on screen */144int space; /* was there space in front of me ? */145union {146char *text; /* piece of text to display */147TextNode *node; /* argument text */148IfNode *ifnode;149} data;150HyperLink *link; /* link for active text */151union {152openaxiom_pixmap pm; /* pixmap for bit images */153openaxiom_image *xi; /* pixmap image */154} image;155TextNode *next; /* next node in formatted text */156};157158/** Structure used to store pixmaps and bitmaps **/159160struct ImageStruct {161int width,height; /** It's width and height **/162union {163openaxiom_pixmap pm;164openaxiom_image *xi;165} image;166char *filename; /** The filename used to reference it **/167};168169/* Structure for locating HyperDoc pages in a source file */170171struct FilePosition {172char *name; /* file name */173long pos; /* position in file */174int ln; /* the line number */175};176177/*** The structure needed for storing a macro **/178179struct MacroStore {180short int loaded;181FilePosition fpos;182char *name;183char *macro_string;184short number_parameters;185};186187/** Structure needed for storing a patch **/188struct PatchStore {189short int loaded;190FilePosition fpos;191char *name;192char *string;193};194195/* Here are the structures needed for doing input to HyperDoc windows. */196197struct LineStruct {198char *buffer;199int changed; /* Has the line changed */200int line_number;201int buff_pntr;202int len;203LineStruct *prev, *next;204};205206struct InputItem {207char *name; /* symbol name **/208int size; /* the length of the window **/209int cursor_x; /* x-coordinate for the cursor **/210int entered; /* tells me whether I have typed here211before */212int num_lines; /* number of lines needed to store213buffer */214LineStruct *lines;215LineStruct *curr_line; /* the current line on which the cursor */216openaxiom_window win;217InputItem *next;218};219220221/* structure for storing input boxes **/222struct InputBox {223char *name;224ImageStruct *selected, *unselected;225short int picked;226InputBox *next;227RadioBoxes *rbs;228openaxiom_window win;229};230231struct RadioBoxes {232char *name;233InputBox *boxes;234ImageStruct *selected, *unselected;235int width, height;236RadioBoxes *next;237};238239/* Structure for spadcommand dependencies hash table entries */240struct SpadcomDepend {241char *label; /* dependency label */242TextNode *spadcom; /* spadcommand defining the label */243short executed; /* true iff spadcommand has benn executed */244} ;245246struct ButtonList {247int x0,y0,x1,y1;248HyperLink *link;249openaxiom_window win;250ButtonList *next;251};252253/* Stucture for unformatted hyper text page */254255struct HyperDocPage {256short type; /* Normal, Quitbutton, Upbutton etc. */257const char *name; /* ID of page */258char *filename; /* The name of the file in which the page259occurs, Null if not */260int scroll_off; /* The offset in the scrolling region */261int bot_scroll_margin; /* bottom of the scrolling region */262int top_scroll_margin; /* top of the scrolling region */263TextNode *title; /* the title of the page */264TextNode *header; /* formatted version of page */265TextNode *scrolling; /* Top of scrolling region */266TextNode *footer; /* top of non-scrolling region at bottom */267OpenAxiom::openaxiom_sio *sock; /* socket connection for spad buffer */268HashTable *fLinkHashTable; /* active link hash table */269ButtonList *s_button_list; /* active buttons on page */270ButtonList *button_list; /* active buttons on page */271HashTable *depend_hash; /* Hash tables of spadcommand dependencies */272InputItem *input_list; /* List of input structures */273InputItem *current_item; /* a pntr to the currently active item */274HashTable *box_hash; /* place where all the boxes are stored */275RadioBoxes *radio_boxes; /* a linked list of radio boxes */276short page_flags; /* A list of flags for the page */277char *helppage; /* the name of the helppage */278};279280/* Structure for an unloaded page */281282struct UnloadedPage {283short type; /* indicator of unloaded page */284char *name; /* name of page */285FilePosition fpos; /* where to find the page */286};287288/* Structure for a HyperDoc Window */289290struct HDWindow {291openaxiom_window fMainWindow; /* The main text field window. */292openaxiom_window fScrollWindow; /* The scrolling area of the window. */293openaxiom_window fDisplayedWindow; /* The current window of the above two,*/294/* being filled by display */295296openaxiom_window fScrollUpWindow; /* Window for scrolling up a line. */297openaxiom_window fScrollDownWindow; /* Window for scrolling down a line. */298299openaxiom_window scrollbar; /* the window for scrolling. */300openaxiom_window scroller; /* the scroller window. */301302openaxiom_window fTitleBarButton1; /* 1st titlebar bitmap button. */303openaxiom_window fTitleBarButton2; /* 2nd titlebar bitmap button. */304openaxiom_window fTitleBarButton3; /* 3rd titlebar bitmap button. */305openaxiom_window fTitleBarButton4; /* 4th titlebar bitmap button. */306307int fScrollerTopPos; /* where the top of the scroller is */308int fScrollerHeight; /* the height of the scroller */309int fScrollBarHeight; /* the height for the scrollbar */310311int scrollwidth; /* the width of the scrolling area */312int scrollheight; /* the height of the scrolling area */313int scrollupy; /* Current y position of the scroll up */314/* button */315int scrolldowny; /* Current y position of the scroll */316/* downbutton */317int scrollbary; /* Current y position of teh scrollbar */318int scrollx; /* X coordinates for all of the above */319int border_width; /* Width of the border */320HyperDocPage *page; /* currently displayed page */321int width, height; /* in pixels */322int columns; /* Width in characters, only setable */323/* for form pages */324HyperDocPage **fMemoStack; /* stack of memo links */325HyperDocPage **fDownLinkStack;/* stack of down links */326327int *fDownLinkStackTop; /* stack of down links */328int fMemoStackIndex; /* memo stack pointer */329int fDownLinkStackIndex; /* downlink stack pointer */330331HashTable *fWindowHashTable; /* hash table of active subwindows */332HashTable *fPageHashTable; /* hash table of HyperDoc pages */333HashTable *fPasteHashTable; /* hash table for paste in areas */334HashTable *fMacroHashTable; /* hash table of HyperDoc macros */335HashTable *fCondHashTable; /* hash table for values */336HashTable *fPatchHashTable; /* hash table for patch locations */337338int fAxiomFrame; /* Axiom frame number initializing window */339openaxiom_graphic_context fStandardGC; /* Graphics context for window */340openaxiom_graphic_context fInputGC; /* Graphics context for the input windows */341openaxiom_graphic_context fCursorGC; /* Graphics context for the cursors */342openaxiom_graphic_context fControlGC; /* Graphics context for the buttons */343openaxiom_cursor fDisplayedCursor; /* The currently displayed cursor */344};345346/* Structure for identifying appropriate link hash tables */347348struct LinkHashID {349int code; /* code of active area */350HyperDocPage *page; /* page for which hash table applies */351};352353354355struct GroupItem {356int cur_color;357openaxiom_font *cur_font;358int center;359GroupItem *next;360};361362363struct CondNode {364char *label;365char *cond;366};367368struct parameter_list_type {369char **list; /** The parameters in string form **/370short number; /** How many parameters are there **/371parameter_list_type *next;372};373374using ParameterList = parameter_list_type*;375376/*** Flags for the page ***/377378#define NOLINES 0000001 /* Ibid, for the bottom of the page ***/379380/* Here are some of the functions and constants declared and needed in381htadd.c ******/382383#define NoChar -9999384#define db_file_name "ht.db"385386387/* Types of HyperDoc pages */388389#define UlUnknownPage 9993 /*I hate this hack, but I have to know whether*/390#define UnknownPage 9994 /*this page has been loaded or not. */391#define ErrorPage 9995392#define Unixfd 9996393#define SpadGen 9997394#define Normal 9998395#define UnloadedPageType 9999396397/* Commands from Axiom */398399#define EndOfPage 99400#define SendLine 98401#define StartPage 97 /* A normal HyperDoc page */402#define LinkToPage 96403#define PopUpPage 95 /* A pop-up page */404#define PopUpNamedPage 94405#define KillPage 93406#define ReplacePage 92407#define ReplaceNamedPage 91408#define SpadError 90409410/* Constants declaring size of page stacks */411412#define MaxMemoDepth 25 /* max nesting level for memolinks */413#define MaxDownlinkDepth 50 /* max downlink nesting depth */414415/* Constants defining the size of various hash tables */416417#define PageHashSize 1000418#define FileHashSize 30419#define SessionHashSize 10420#define MacroHashSize 100421#define ImageHashSize 100422#define CondHashSize 100423#define BoxHashSize 20424#define PasteHashSize 100425#define PatchHashSize 100426427/* A couple of macros for memo and down links */428429#define need_up_button \430(gWindow->fMemoStackIndex ? gWindow->fDownLinkStackIndex >= \431gWindow->fDownLinkStackTop[gWindow->fMemoStackIndex-1] \432: gWindow->fDownLinkStackIndex)433434#define need_return_button (gWindow->fMemoStackIndex)435436#define need_help_button (gWindow->page->helppage != NULL)437438#define openaxiom_max(x,y) ((x) > (y) ? (x) : (y))439440441#define pick_box(box) fill_box(box->win, box->selected)442#define unpick_box(box) fill_box(box->win, box->unselected)443444#define TopLevelHelpPage "ugHyperPage"445#define NoMoreHelpPage "NoMoreHelpPage"446#define KeyDefsHelpPage "ugHyperKeysPage"447#define InputAreaHelpPage "ugHyperInputPage"448449/* definitions for connecting to the Axiom server */450451#define Connected 0452#define NotConnected 1453#define SpadBusy 2454455/* some GUI-dependent stuff */456457#define BeepAtTheUser() /* (XBell(gXDisplay, 5)) */458#define LoudBeepAtTheUser() /* (XBell(gXDisplay, 50)) */459460461462#endif /* OPENAXIOM_NODE */463464465