www.c
上传用户:zlh9724
上传日期:2007-01-04
资源大小:1991k
文件大小:61k
源码类别:

浏览器

开发平台:

Unix_Linux

  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include <stdio.h>
  4. #include <signal.h>
  5. #include <sys/types.h>
  6. #include <sys/time.h>
  7. #if 0
  8. #include <X11/Xlib.h>
  9. #include <X11/Xutil.h>
  10. #include <X11/Xos.h>
  11. #include <X11/Xatom.h>
  12. #include <X11/keysym.h>
  13. #include <X11/cursorfont.h>
  14. #ifdef __hpux
  15. #include <X11/HPkeysym.h>
  16. #endif
  17. #endif
  18. #ifndef NFDBITS
  19. #define NFDBITS 0
  20. #endif
  21. #include "www.h"
  22. #include "popup.h"
  23. #include "style.h"
  24. #include "neweditor.h"
  25. #ifndef XK_DeleteChar
  26. #define XK_DeleteChar XK_Delete
  27. #endif
  28. #define BITMAPDEPTH 1
  29. /* values for window_size in main, is window big enough to be useful */
  30. #define SMALL 1
  31. #define OK 0
  32. extern int statusHeight;
  33. extern int sbar_width;
  34. extern int ToolBarHeight;
  35. extern long PixelOffset;
  36. extern long buf_height;
  37. extern int PixelIndent;
  38. extern int buf_width;
  39. extern char *buffer;
  40. extern int hdrlen;
  41. extern int Authorize;
  42. extern int OpenURL;
  43. extern int IsIndex;
  44. extern int SaveFile;
  45. extern int FindStr;
  46. extern char *FindStrVal, *FindNextStr;
  47. extern int font;
  48. extern Field *focus;
  49. extern Frame background;
  50. extern Byte *paint;
  51. extern Bool TextFieldFocus;
  52. extern double lens_factor;
  53. extern GC disp_gc, gc_fill;
  54. int debug = 0;        /* used to control reporting of errors */
  55. int initialised = 0;  /* avoid X output until this is true! */
  56. int busy = 0;         /* blocks hypertext links etc while receiving data */
  57. int UseHTTP2 = 1;     /* use new HTRQ/HTTP protocol */
  58. int OpenSubnet = 0;   /* if true host is on OpenSubnet */
  59. int UsePaper = 1; 
  60. int fontsize = 0;
  61. int NoTerminal = 0; /* howcome 5/11/94: can we ask for passwd? */
  62. char *CacheRoot = "/tmp"; /* howcome 5/10/94: command line option to turn caching on */
  63. char *Printer = NULL; /* howcome 5/10/94: command line option enables printing */
  64. char *Editor = NULL; /* howcome 5/10/94: command line option turns the editor on */
  65. int  Badflags = 5; /* howcome 5/10/94: how many badflags do we want in the output */
  66. char *Icon = NULL; /* howcome 5/10/94: command line option turns the use of icon */
  67. double Gamma = 2.2; /* howcome 7/11/94: made into command line option */
  68. int NoMailcap = 0; /* howcome 7/11/94 */
  69. BOOL NoStyle = FALSE; /* howcome 2/3/95 */
  70. BOOL Quiet = FALSE; /* howcome 10/8/95 */
  71. BOOL OwnColorMap = FALSE; /* howcome 10/8/95 */
  72. Atom ARENA_LOCATION; 
  73. Atom ARENA_COMMAND;
  74. long main_stack[256];
  75. long *stack;
  76. int library_trace = 0; /* howcome 20/11/94 */
  77. Doc *CurrentDoc;
  78. Context *context;
  79. /* Display and screen are used as arguments to nearly every Xlib
  80.  * routine, so it simplifies routine calls to declare them global.
  81.  * If there were additional source files, these variables would be
  82.  * declared `extern' in them.
  83.  */
  84. Display *display;
  85. Visual *visual;
  86. Colormap colormap;
  87. int screen;
  88. int depth;
  89. Window win;
  90. int ExposeCount;   /* used to monitor GraphicsExpose events during scrolling */
  91. char *prog;        /* name of invoking program */
  92. int default_pixmap_width, default_pixmap_height;
  93. Pixmap background_pixmap, default_pixmap;
  94. Pixmap icon_pixmap;
  95. Cursor hourglass;
  96. int shape;
  97. unsigned long textColor, labelColor, windowColor, strikeColor, statusColor,
  98.        transparent, windowTopShadow, windowBottomShadow, windowShadow;
  99. #ifdef SELECTION
  100. unsigned long statusSelectColor; /* howcome */
  101. static char *selectStr=NULL; /* howcome 2/8/94 */
  102. #endif
  103. int charWidth, charHeight, charAscent, lineHeight;
  104. unsigned int win_width, win_height, tileWidth, tileHeight;
  105. unsigned char *tileData;
  106. /*int document;*/
  107. int gadget;
  108. int gatewayport = 3000; /* GATEWAYPORT; */
  109. char *gateway;      /* gateway if can't access server directly */
  110. char *help;
  111. /* char *printer; */ /* howcome 16/10/94 */
  112. char *startwith;    /* default initial document */
  113. char *user;
  114. int RepeatButtonDown = 0;
  115. XFontStruct *fixed_font;
  116. XFontStruct *Fonts[FONTS];  /* array of fonts */
  117. char *FontsName[FONTS];
  118. int LineSpacing[FONTS];
  119. int BaseLine[FONTS];
  120. int StrikeLine[FONTS];
  121. int LineThickness[FONTS];
  122. int ListIndent1, ListIndent2;
  123. GC gc_fill;
  124. static GC gc_scrollbar, gc_status, gc_text;
  125. static char *display_name = NULL;
  126. static int window_size = 0;    /* OK or SMALL to display contents */
  127. static int button_x, button_y;
  128. static XSizeHints size_hints;
  129. int ColorStyle;
  130. unsigned int display_width, display_height;
  131. double display_pt2px;
  132. struct itimerval itimer, old_itimer;
  133. void ShowBusy()
  134. {
  135.     XDefineCursor(display, win, hourglass);
  136.     XFlush(display);
  137.     busy = 1;
  138. }
  139. void HideBusy()
  140. {
  141.     XUndefineCursor(display, win);
  142.     XFlush(display);
  143.     busy = 0;
  144. }
  145. /* From Scott Nelson <snelson@canopus.llnl.gov> 24 bit color  1/12/94 */
  146. /* these are here for speed reasons */
  147. int RPixelShift=16, GPixelShift=8, BPixelShift=0;
  148. int RPixelMask=0xff, GPixelMask=0xff, BPixelMask=0xff;
  149. /* pause for delay milliseconds */
  150. /* howcome moved this from tcp.c 20/9/94 */
  151. void Pause(int delay)
  152. {
  153.     struct timeval timer;
  154.     timer.tv_sec = 0;
  155.     timer.tv_usec = delay * 1000;
  156.     select(NFDBITS, 0, 0, 0, &timer);
  157. }
  158. void CatchCore()
  159. {
  160.     fprintf(stderr,"CATCH_CORE %d%cn",(int)getpid(),7);
  161.     Exit(1);
  162. }
  163. void CatchQuit()
  164. {
  165.     fprintf(stderr,"CATCH_QUITn");
  166.     Exit(1);
  167. }
  168. void CatchX(Display * err_dpy_p, XErrorEvent *err_event)
  169. {
  170.     fprintf(stderr,"catchX pid %dn", (int)getpid());
  171. }
  172. /* howcome 4/10/94: need to clean the library cache.. */
  173. int Exit(int i)
  174. {
  175.     if (VERBOSE_TRACE)
  176.         printf("bridge.c: Exitn");
  177.     libExit(0);
  178.     printf("nThanks for using %s %s. The authors -- Dave, Hakon, Henrik nand Yves -- can be reached at arena@w3.org. nPlease check %s nbefore reporting bugs.n", BANNER, VERSION, HELP_URL);
  179.     exit(i);
  180. }
  181. /* find best visual for specified visual class */
  182. Visual *BestVisual(int class, int *depth)
  183. {
  184.     long visual_info_mask;
  185.     int number_visuals, i, best_depth;
  186.     XVisualInfo *visual_array, visual_info_template;
  187.     Visual *best_visual;
  188.     visual_info_template.class = class;
  189.     visual_info_template.screen = DefaultScreen(display);
  190.     visual_info_mask = VisualClassMask | VisualScreenMask;
  191.     visual_array = XGetVisualInfo(display, visual_info_mask,
  192.                         &visual_info_template,
  193.                         &number_visuals);
  194.     *depth = 0;
  195.     best_depth = 0; /* *depth */
  196.     best_visual = 0;
  197.  
  198.     for (i = 0; i < number_visuals; ++i)
  199.     {
  200.         if (visual_array[i].depth > *depth)
  201.         {
  202.             best_visual = visual_array[i].visual;
  203.             *depth = visual_array[i].depth;
  204.         }
  205.         if (*depth == best_depth)
  206.             break;
  207.     }
  208.     XFree((void *)visual_array);
  209.     return best_visual;
  210. }
  211. #ifdef SELECTION
  212. void SetSelection(char *s) /* howcome 2/8/94 */
  213. {
  214.   Free(selectStr);
  215.   selectStr = strdup(s);
  216.   XSetSelectionOwner(display, XA_PRIMARY, win, CurrentTime);
  217.   XStoreBytes(display, selectStr, strlen(selectStr));
  218. }
  219. #endif
  220. /* send myself an expose event to force redrawing of give rectangle */
  221. void Redraw(int x, int y, int w, int h)
  222. {
  223.     XExposeEvent event;
  224.     event.type = Expose;
  225.     event.serial = 0;
  226.     event.send_event = 1;
  227.     event.display = display;
  228.     event.window = win;
  229.     event.x = x;
  230.     event.y = y;
  231.     event.width = w;
  232.     event.height = h;
  233.     event.count = 0;
  234.     if (X_TRACE)
  235. fprintf(stderr,"Redrawn");
  236.     XSendEvent(display, win, 0, ExposureMask, (XEvent *)&event);
  237. }
  238. void SetBanner(char *title)
  239. {
  240.     XTextProperty textprop;
  241.      /* Support multiple <TITLE>s in a document */
  242.     if(CurrentDoc->title)
  243. free(CurrentDoc->title);
  244.     CurrentDoc->title = strdup(title);
  245.     XStoreName(display, win, title);
  246.     if(CurrentDoc->url)
  247.     {
  248. char *v;
  249. int v_size;
  250. v_size = strlen(title)+strlen(CurrentDoc->url)+13; /* 13: 'URL='(string)'TITLE='(string)  */ 
  251. v = (char *)calloc(v_size, sizeof(char));
  252. sprintf(v, "URL=%s%cTITLE=%s",CurrentDoc->url,0,title);
  253. XChangeProperty(display, win, ARENA_LOCATION, XA_STRING, 8, PropModeReplace,
  254. v, v_size);
  255. free(v);
  256.     }
  257. /*
  258.     if (strlen(title) > 8 && (p = strrchr(title, '/')))
  259.     {
  260.             if (p[1] != '')
  261.                 ++p;
  262.             title = p;
  263.     }
  264. */
  265.     textprop.value = (unsigned char *)title;
  266.     textprop.encoding = XA_STRING;
  267.     textprop.format = 8;
  268.     textprop.nitems = strlen(title);
  269.     XSetWMIconName(display, win, &textprop);
  270. }
  271. void LoadFont(int idx, char *font_name, char *fall_back)
  272. {
  273.     int direction_hint, font_ascent, font_descent;
  274.     XFontStruct *font;
  275.     XCharStruct overall;
  276.     char *test = "Testing";
  277.     if ((Fonts[idx] = XLoadQueryFont(display, font_name)) == NULL)
  278.     {
  279.         (void) fprintf(stderr, "Cannot open %s fontn", font_name);
  280.         if ((Fonts[idx] = XLoadQueryFont(display, fall_back)) == NULL)
  281.         {
  282.             (void) fprintf(stderr, "Cannot open alternate font: %sn", fall_back);
  283.             Exit(1);
  284.         }
  285.         fprintf(stderr, "Using alternate font: %sn", fall_back);
  286.     }
  287.     font = Fonts[idx];
  288.     XTextExtents(font, test, strlen(test),
  289.                     &direction_hint,
  290.                     &font_ascent,
  291.                     &font_descent,
  292.                     &overall);
  293.     charWidth = overall.width/strlen(test);
  294.     charHeight = overall.ascent + overall.descent;
  295.     charAscent = overall.ascent;
  296.     lineHeight = charHeight + overall.ascent/4 + 2;
  297.     LineSpacing[idx] = SPACING(font);
  298.     BaseLine[idx] = BASELINE(font);
  299.     StrikeLine[idx] = STRIKELINE(font);
  300. }
  301. #if 0
  302. janet 21/07/95: commented, function not used at all
  303. static int hex(char *s)
  304. {
  305.     int n, c;
  306.     n = toupper((unsigned char *)*s++) - '0';
  307.     n = toupper((int)*s++) - '0'; /* howcome changing cast 22/8/94  */
  308.     if (n > 9)
  309. n += '0' - 'A' + 10;
  310.     
  311.     c = toupper((unsigned char *)*s) - '0';
  312.     c = toupper((int)*s) - '0'; /* howcome changing cast 22/8/94 */
  313.     if (c > 9)
  314. c += '0' - 'A' + 10;
  315.     return c + (n << 4);
  316. }
  317. #endif
  318. /* From Scott Nelson <snelson@canopus.llnl.gov> 24bit color  1/12/94  Dec 1 1994 */
  319. /*
  320.    For efficiency, these should be computed after the visual is
  321. changed and then stored and reused, or stored in each routine
  322. as a static variable, or as a global variable.
  323. */
  324. /*
  325. int RPixelShift(){
  326.    int i = 0;
  327.    long int maskval;
  328. maskval = (*visual).red_mask;
  329. while ((maskval & 1) == 0) { i++; maskval = maskval >> 1; }
  330. return i;
  331. }
  332. int GPixelShift(){
  333.    int i = 0;
  334.    long int maskval;
  335. maskval = (*visual).green_mask;
  336. while ((maskval & 1) == 0) { i++; maskval = maskval >> 1; }
  337. return i;
  338. }
  339. int BPixelShift(){
  340.    int i = 0;
  341.    long int maskval;
  342. maskval = (*visual).blue_mask;
  343. while ((maskval & 1) == 0) { i++; maskval = maskval >> 1; }
  344. return i;
  345. }
  346. */
  347. void CalcPixelShift(){
  348. /* this needs to be called after the visual has changed */
  349.    int i = 0;
  350.    long int maskval;
  351. maskval = (*visual).red_mask;
  352. while ((maskval & 1) == 0) { i++; maskval = maskval >> 1; }
  353. RPixelShift = i;
  354.    i = 0;
  355. maskval = (*visual).green_mask;
  356. while ((maskval & 1) == 0) { i++; maskval = maskval >> 1; }
  357. GPixelShift = i;
  358. i = 0;
  359. maskval = (*visual).blue_mask;
  360. while ((maskval & 1) == 0) { i++; maskval = maskval >> 1; }
  361. BPixelShift = i;
  362. }
  363. int Pixel4Color(XColor *color, unsigned long *pixel)
  364. {
  365.     unsigned long r, g, b;
  366.     r = color->red >> 8;
  367.     g = color->green >> 8;
  368.     b = color->blue >> 8;
  369. /*    *pixel = (b | g << 8 | r << 16); */ /* From Scott Nelson <snelson@canopus.llnl.gov> 24bit color  1/12/94  Dec 1 1994 */
  370. /*    *pixel = (r | g << 8 | b << 16);*/  /* some systems use RGB masks, others use BGR masks */
  371.     *pixel = (b << BPixelShift | g << GPixelShift | r << RPixelShift ); 
  372.  
  373.     return 1;
  374. }
  375. int Pixel2Color(XColor *color, unsigned long *pixel)
  376. {
  377.     unsigned long r, g, b;
  378.     r = (color->red * (long)(RPixelMask+1)) >> 16;
  379.     g = (color->green *(long)(GPixelMask+1)) >> 16;
  380.     b = (color->blue *(long)(BPixelMask+1)) >> 16;
  381.     *pixel = (b << BPixelShift | g << GPixelShift | r << RPixelShift );
  382.     return 1;
  383. }
  384. int GetNamedColor(char *name, unsigned long *pix)
  385. {
  386.     XColor color;
  387.     if (depth == 24)
  388.     {
  389.         if (XParseColor(display, colormap, name, &color) == 0)
  390.         {
  391.             if (X_TRACE)
  392.                 fprintf(stderr, "www: can't allocate named color `%s'n", name);
  393.             return 0;
  394.         }
  395.         return Pixel4Color(&color, pix);
  396.     }
  397.     if (depth == 16)
  398.     {
  399.         if (XParseColor(display, colormap, name, &color) == 0)
  400.         {
  401.             if (X_TRACE)
  402.                 fprintf(stderr, "www: can't allocate named color `%s'n", name);
  403.             return 0;
  404.         }
  405.         return Pixel2Color(&color, pix);
  406.     }
  407.     else if (XParseColor(display, colormap, name, &color) == 0 ||
  408.                      XAllocColor(display, colormap, &color) == 0)
  409.     {
  410.         if (X_TRACE)
  411.             fprintf(stderr, "www: can't allocate named color `%s'n", name);
  412.         return 0;
  413.     }
  414.     *pix = color.pixel;
  415.     return 1;
  416. }
  417. int GetColor(int red, int green, int blue, unsigned long *pix)
  418. {
  419.     XColor color;
  420. /*
  421.     if (red == 255 && green == 255 && blue == 255)
  422.     {
  423.         *pix = WhitePixel(display, screen);
  424.         return 1;
  425.     }
  426.     if (red == 0 && green == 0 && blue == 0)
  427.     {
  428.         *pix = BlackPixel(display, screen);
  429.         return 1;
  430.     }
  431. */
  432.     color.red = red << 8;
  433.     color.green = green << 8;
  434.     color.blue = blue  << 8;
  435.     if (depth == 24)
  436.         return Pixel4Color(&color, pix);
  437.     else if (depth == 16)
  438. return Pixel2Color(&color, pix);
  439.     else if (XAllocColor(display, colormap, &color) == 0)
  440.     {
  441. /*        if (X_TRACE)*/
  442.             fprintf(stderr, "www: can't allocate color %d:%d:%dn", red, green, blue);
  443. *pix = BlackPixel(display, screen);
  444.         return 0;
  445.     }
  446.     *pix = color.pixel;
  447.     return 1;
  448. }
  449. char *DetermineValue(char *prog, char *param, char *def)
  450. {
  451.     char *value;
  452.     if ((value = XGetDefault(display, prog, param)) == NULL)
  453.         value = def;
  454.     return value;
  455. }
  456. int DetermineColor(char *prog, char *param,
  457.         int r, int g, int b,
  458.         unsigned long *pix)
  459. {
  460.     char *colorname, *p1, *p2;
  461.     colorname = XGetDefault(display, prog, param);
  462.     if (colorname)  /* parse and GetColor() or GetNamedColor() */
  463.     {
  464.         /* "red:green:blue" e.g."205:184:157" or named color */
  465.         p1 = strchr(colorname, ':');
  466.         p2 = strrchr(colorname, ':');
  467.         if (p1 && p2 && p1 != p2)
  468.         {
  469.             sscanf(colorname, "%d:", &r);
  470.             sscanf(p1+1, "%d:", &g);
  471.             sscanf(p2+1, "%d", &b);
  472.             return GetColor(r, g, b, pix);
  473.         }
  474.         return GetNamedColor(colorname, pix);
  475.     }
  476.     return GetColor(r, g, b, pix);
  477. }
  478. void ButtonDown(unsigned int button, unsigned int state, int x, int y, int x_root, int y_root)
  479. {
  480.     if (X_TRACE)
  481.         fprintf(stderr, "ButtonDown %d %dn",x,y);
  482.     if (y < WinTop){
  483.         if (y < StatusTop)
  484.             gadget = ToolBarButtonDown(x, y);
  485.         else 
  486.             gadget = StatusButtonDown(button, x, y);
  487.     }
  488.     else if (x < WinRight && y < WinBottom)
  489. #ifdef POPUP
  490.         if (button == Button3)
  491.         {            
  492.             Popup(x_root, y_root);   
  493.         }
  494.         else
  495. #endif
  496.     if (button == Button2)   /* spif -> button2 shows URL */
  497.     {
  498. ShowLink(x, y);
  499.     }
  500.     else
  501. gadget = WindowButtonDown(x, y);
  502.     else if ( (x >= WinRight && y < WinBottom) ||
  503.               (x <= WinRight && y >= WinBottom) )
  504.     {
  505.         button_x = x;
  506.         button_y = y;
  507.         gadget = ScrollButtonDown(x, y);
  508.     }
  509.     else
  510.         gadget = VOID;
  511. }
  512. void ButtonUp(unsigned int button, unsigned int state, int x, int y)
  513. {
  514.     int shifted;
  515.     RepeatButtonDown = 0;
  516.     shifted = ShiftMask & state;
  517.     if (gadget == WINDOW)
  518.         WindowButtonUp(shifted, x, y);
  519.     else if (gadget == SCROLLBAR)
  520.         ScrollButtonUp(x, y);
  521.     else if (gadget == TOOLBAR)
  522.         ToolBarButtonUp(x, y);
  523.     else if (gadget == STATUS)
  524.         StatusButtonUp(x, y);
  525. }
  526. int GuiEvents(int s, HTRequest * rq, int f)
  527. {
  528.     char keybuf[20];
  529.     int keybufsize = 20;
  530.     int count;
  531.     KeySym key;
  532.     XEvent event;
  533.     XComposeStatus cs;
  534.     int block = 0;
  535.     int w, h;
  536.     
  537.     while (block || XEventsQueued(display, QueuedAfterReading) != 0)
  538.     {
  539. /*
  540. if (RepeatButtonDown) {
  541.     XButtonEvent e;
  542.     e.type = ButtonPress;
  543.     XSendEvent(event.xselectionrequest.display, event.xselectionrequest.requestor, False, 0, (XEvent *) &selEv);
  544. */
  545. /*
  546.         if (RepeatButtonDown && !ExposeCount &&
  547.                 XEventsQueued(display, QueuedAfterReading) == 0)
  548.         {
  549.             XFlush(display);
  550.             ButtonDown(event.xbutton.button, event.xbutton.state, button_x, button_y);
  551.             Pause(10);
  552.             continue;
  553.         }
  554. */
  555.         XNextEvent(display, &event);
  556.         switch(event.type)
  557.         {
  558.             case Expose:
  559.                     /* the following commented by janet: redrawing won't work, you get a trail  */
  560.                     /* get rid of all other Expose events on the queue */
  561.                     /*                 while (XCheckTypedEvent(display, Expose, &event)); */
  562.                 if (event.xexpose.y < WinTop) /* janet: added check for whether to draw or not */
  563.                 {
  564.                     DisplayToolBar();
  565.                     DisplayStatusBar();
  566.                     DisplayIcon();
  567.                 }
  568.                 
  569.                 w = event.xexpose.x + event.xexpose.width; /* the real coordinate */
  570.                 h = event.xexpose.y + event.xexpose.height; /* the real coordinate  */
  571. /*                 DisplayIcon(); */
  572. /*                 DisplayDoc(WinLeft, WinTop, WinWidth, WinHeight); */
  573.                 if ((h > WinTop && event.xexpose.x < WinWidth &&   /* checking whether to draw.. */
  574.                      event.xexpose.y < (WinHeight+WinTop)))
  575.                 {
  576.                     
  577.                         /* only redraw pieces that were exposed */
  578.                     DisplayDoc(event.xexpose.x, event.xexpose.y, 
  579.                                event.xexpose.width, event.xexpose.height);
  580.                 }
  581.                     /* we do the scrollbar last, to make sure DisplayDoc is not drawing on top of it */
  582.                 if ((w > WinWidth || h > WinHeight + WinTop))
  583.                     DisplayScrollBar();
  584.                 
  585.                 break;
  586.             case GraphicsExpose:
  587. /* if (event.xexpose.y < WinTop)
  588. {*/
  589.     SetToolBarWin(win);
  590.     SetToolBarGC(gc_status);
  591.     DisplayToolBar();
  592.     
  593.     SetStatusWin(win);
  594.     SetStatusGC(gc_status);
  595.     DisplayStatusBar();
  596.     
  597.     SetIconWin(win);
  598.     SetIconGC(gc_status);
  599.     DisplayIcon();
  600.     /* };*/
  601. SetScrollBarWin(win);
  602. SetScrollBarGC(gc_scrollbar);
  603. DisplayScrollBar();
  604. SetDisplayGC(gc_text);
  605. DisplayDoc(event.xgraphicsexpose.x,
  606.    event.xgraphicsexpose.y,
  607.    event.xgraphicsexpose.width,
  608.    event.xgraphicsexpose.height);
  609. ExposeCount = event.xgraphicsexpose.count;
  610. break;
  611.             case NoExpose:
  612.                 ExposeCount = 0;
  613.                 break;
  614.             case ConfigureNotify:
  615.                 if (win_width == event.xconfigure.width &&
  616.                         win_height == event.xconfigure.height)
  617.                     break;
  618.                 win_width = event.xconfigure.width;
  619.                 win_height = event.xconfigure.height;
  620.                 if ((win_width < size_hints.min_width) ||
  621.                         (win_height < size_hints.min_height))
  622.                     window_size = SMALL;
  623.                 else
  624.                     window_size = OK;
  625.                 if (focus && focus->flags & CHECKED)
  626.                 {
  627.                     focus->flags &= ~CHECKED;
  628.                     focus = NULL;
  629.                 }
  630.                 DisplaySizeChanged(1);
  631. #ifdef RESIZE_BUG
  632. /* 
  633.    howcome 26/7/94: need to expose after redraw 
  634.    this appears to be the case on suu4-sol2, and decstations??
  635.  */
  636.                 Redraw(0,0,WinWidth,WinHeight + WinTop); /* janet: changed height argument */
  637. #endif
  638.                 break;
  639.             case KeyPress:
  640.                 if (X_TRACE)
  641.                     fprintf(stderr, "KeyPressn");
  642.                 count = XLookupString((XKeyEvent*)&event, keybuf, keybufsize, &key, &cs);
  643.                 keybuf[count] = 0;
  644.                 if (key == XK_F8)
  645.                 {
  646.                     XCloseDisplay(display);
  647.                     Exit(1);
  648.                 }
  649.                 else if (key == XK_F2)
  650.                     count = 1;
  651. /*                else if (key == XK_F4)
  652.                     ShowPaint(background.top-paint, 14); */
  653.                 else if (key == XK_F6)
  654.                     ReportVisuals();
  655.                 else if (key == XK_F7)
  656.                 {
  657.                     ReportStandardColorMaps(XA_RGB_DEFAULT_MAP);
  658.                     ReportStandardColorMaps(XA_RGB_BEST_MAP);
  659.                 }
  660. /*
  661. else if (TextFieldFocus && key !=XK_Begin && key !=XK_End && key != XK_Prior && key != XK_Next) {
  662.     if (IsEditChar(*keybuf))
  663. FormEditChar(*keybuf);
  664.     else
  665. FormMoveCursor(key);
  666. }
  667. */
  668. else if (key == XK_v && (event.xkey.state & ControlMask))
  669.     MoveDownPage();
  670. else if (key == XK_v && (event.xkey.state & Mod1Mask))
  671.     MoveUpPage();
  672. /* 28-Nov-95 starting to play with the editor --Spif */
  673. else if ((CurrentDoc->field_editor) && (key == XK_Left))
  674. {
  675.     if(CurrentDoc->field_editor->pos)
  676.     {
  677. CurrentDoc->field_editor->pos--;
  678. PaintField(disp_gc, -1, Abs2Win(CurrentDoc->edited_field->baseline),CurrentDoc->edited_field );
  679. PaintFieldCursorBuffer(disp_gc, strikeColor, CurrentDoc->field_editor, CurrentDoc->edited_field);
  680.     };
  681.                       /* afficher le curseur */
  682. }
  683. else if ((CurrentDoc->field_editor) && (key == XK_Right))
  684. {
  685.     if(CurrentDoc->field_editor->pos < CurrentDoc->field_editor->size)
  686.     {
  687. CurrentDoc->field_editor->pos++;
  688. PaintField(disp_gc, -1, Abs2Win(CurrentDoc->edited_field->baseline),CurrentDoc->edited_field );
  689. PaintFieldCursorBuffer(disp_gc, strikeColor, CurrentDoc->field_editor, CurrentDoc->edited_field);
  690.     };
  691.                         /* afficher le curseur */
  692. }
  693. else if ((CurrentDoc->field_editor) && (key == XK_Delete || key == XK_DeleteChar))
  694. {
  695.     DeleteChar(CurrentDoc->field_editor, CurrentDoc->field_editor->pos);
  696.     free(CurrentDoc->edited_field->value);
  697.     CurrentDoc->edited_field->value = Buffer2Str(CurrentDoc->field_editor);
  698.     CurrentDoc->edited_field->buflen = CurrentDoc->field_editor->size;
  699.     PaintField(disp_gc, -1, Abs2Win(CurrentDoc->edited_field->baseline),CurrentDoc->edited_field );
  700.     PaintFieldCursorBuffer(disp_gc, strikeColor, CurrentDoc->field_editor, CurrentDoc->edited_field);
  701.     /* Afficher tout */
  702. }
  703. else if ((CurrentDoc->field_editor) && ((key < 255)||(key == XK_Return))) /* normal keypress... adding */
  704. {
  705.     /* printf("adding [%c] [%d]n",key, key); */
  706.     if(key == XK_Return)
  707. InsertChar(CurrentDoc->field_editor, CurrentDoc->field_editor->pos , 'n');
  708.     else
  709. InsertChar(CurrentDoc->field_editor, CurrentDoc->field_editor->pos , key);
  710.     CurrentDoc->field_editor->pos++;
  711.     free(CurrentDoc->edited_field->value);
  712.     CurrentDoc->edited_field->value = Buffer2Str(CurrentDoc->field_editor);
  713.     CurrentDoc->edited_field->buflen = CurrentDoc->field_editor->size;
  714.     PaintField(disp_gc, -1, Abs2Win(CurrentDoc->edited_field->baseline),CurrentDoc->edited_field );
  715.     PaintFieldCursorBuffer(disp_gc, strikeColor, CurrentDoc->field_editor, CurrentDoc->edited_field);
  716.                     /* Afficher tout */
  717. }
  718. else if ((CurrentDoc->field_editor) && (key == XK_Up))
  719. {
  720.     PrevLine(CurrentDoc->field_editor);
  721.     PaintField(disp_gc, -1, Abs2Win(CurrentDoc->edited_field->baseline),CurrentDoc->edited_field );
  722.     PaintFieldCursorBuffer(disp_gc, strikeColor, CurrentDoc->field_editor, CurrentDoc->edited_field);
  723. }
  724. else if ((CurrentDoc->field_editor) && (key == XK_Down))
  725. {
  726.     NextLine(CurrentDoc->field_editor);
  727.     PaintField(disp_gc, -1, Abs2Win(CurrentDoc->edited_field->baseline),CurrentDoc->edited_field );
  728.     PaintFieldCursorBuffer(disp_gc, strikeColor, CurrentDoc->field_editor, CurrentDoc->edited_field);
  729. }
  730.                 else if ((Authorize|OpenURL|IsIndex|SaveFile|FindStr) && IsEditChar(*keybuf))
  731.                     EditChar(*keybuf);
  732.                 else if ((Authorize|OpenURL|IsIndex|SaveFile|FindStr) && (key == XK_Left || key == XK_Right))
  733.                     MoveStatusCursor(key);
  734.                 else if ((Authorize|OpenURL|IsIndex|SaveFile|FindStr) && (key == XK_Delete || key == XK_DeleteChar))
  735.                     EditChar(127);
  736. #ifdef _HPUX_SOURCE
  737.                 else if ((Authorize|OpenURL|IsIndex|SaveFile|FindStr) && (key == XK_ClearLine || key == XK_DeleteLine))
  738.                 {
  739.                     ClearStatus();
  740.                     SetStatusString(0); /* force refresh */
  741.                 }
  742. #endif
  743.                 else if (key == XK_Up && !ExposeCount)
  744.                 {
  745.     if (event.xkey.state & ControlMask)
  746. MoveUpPage();
  747.     else
  748. MoveUpLine();
  749.                     XFlush(display);   /* to avoid scrollbar flashing */
  750.                 }
  751.                 else if (key == XK_Down && !ExposeCount)
  752.                 {
  753.     if (event.xkey.state & ControlMask)
  754. MoveDownPage();
  755.     else
  756. MoveDownLine();
  757.                     XFlush(display);   /* to avoid scrollbar flashing */
  758.                 }
  759.                 else if (key == XK_Left && !ExposeCount)
  760.                 {
  761.     if (event.xkey.state & (Mod4Mask | ControlMask))
  762. BackDoc();
  763.     else
  764. MoveLeftLine();
  765.                     XFlush(display);   /* to avoid scrollbar flashing */
  766.                 }
  767.                 else if (key == XK_Right && !ExposeCount)
  768.                 {
  769.     if (event.xkey.state & (Mod4Mask | ControlMask))
  770. ForwardDoc();
  771.     else
  772. MoveRightLine();
  773.                     XFlush(display);   /* to avoid scrollbar flashing */
  774.                 }
  775.                 else if (key == XK_Prior && !ExposeCount)
  776.                     MoveUpPage();
  777.                 else if (key == XK_Next && !ExposeCount)
  778.                     MoveDownPage();
  779.                 else if ((key == XK_Begin || key == XK_Home) && !ExposeCount)
  780.                 {
  781.                     if (event.xkey.state & ShiftMask)
  782.                         MoveToEnd();
  783.                     else
  784.                         MoveToStart();
  785.                 }
  786.                 else if (key == XK_End && !ExposeCount)
  787.                     MoveToEnd();
  788.                 else if (key == XK_Escape)
  789.                 {
  790.                     if (Authorize)
  791.                         HideAuthorizeWidget();
  792.                     else if (busy)
  793.                         Beep();
  794.                     else if (OpenURL)
  795.                     {
  796.                         OpenURL = 0;
  797.                         SetStatusString("");
  798.                     }
  799.                     else if (SaveFile)
  800.                     {
  801.                         SaveFile = 0;
  802.                         SetStatusString("");
  803.                     }
  804.                     else if (FindStr)
  805.                     {
  806.                         FindStr = 0;
  807.                         SetStatusString("");
  808.                     }
  809.                 }
  810.                 else if (busy)
  811.                     Beep();
  812.                 else if (key == XK_F2)
  813.                     BackDoc();
  814.                 else if (key == XK_F3 && FindStrVal)
  815.                     FindString(FindStrVal, &FindNextStr);
  816.                 break;
  817.             case KeyRelease:
  818.                 count = XLookupString((XKeyEvent*)&event, keybuf, keybufsize, &key, &cs);
  819.                 keybuf[count] = 0;
  820.                 break;
  821.             case ButtonRelease:
  822.                 ButtonUp(event.xbutton.button, event.xbutton.state, event.xbutton.x, event.xbutton.y);
  823.                 break;
  824.             case ButtonPress:
  825.                 if (X_TRACE)
  826.                     fprintf(stderr, "ButtonPress %d %dn",event.xbutton.x, event.xbutton.y);
  827. if(CurrentDoc->edited_field)
  828. {
  829.     free(CurrentDoc->edited_field->value);
  830.     CurrentDoc->edited_field->value = Buffer2Str(CurrentDoc->field_editor);
  831.     CurrentDoc->edited_field->flags &= ~CHECKED;
  832.     TextFieldFocus = FALSE;
  833.     PaintField(disp_gc, -1, Abs2Win(CurrentDoc->edited_field->baseline),CurrentDoc->edited_field);
  834.     CurrentDoc->edited_field = NULL;
  835.     FreeBuffer(CurrentDoc->field_editor);
  836.     CurrentDoc->field_editor = NULL;
  837. };
  838.                 ButtonDown(event.xbutton.button, event.xbutton.state, event.xbutton.x, event.xbutton.y, event.xbutton.x_root, event.xbutton.y_root);
  839.                 break;
  840.             case MotionNotify:  /* only sent when Button1 is down! */
  841.               /* ignore event if still repairing holes from earlier copy operation*/
  842.                 if (ExposeCount)
  843.                     break;
  844.                 /* get rid of all other MotionNotify events on the queue */
  845.                 while (XCheckTypedEvent(display, MotionNotify, &event));
  846. #ifdef SELECTION
  847. SelectStatus(event.xbutton.x, event.xbutton.y);
  848. #endif
  849. ScrollButtonDrag(event.xbutton.x, event.xbutton.y);
  850.                 break;
  851.            /* the following is a failed attempt to exit tidily when the user
  852.                 forces an exit through the system menu - I need to do better ! */
  853.             case DestroyNotify:
  854. if (event.xdestroywindow.window == win) {
  855.     if (X_TRACE)
  856.                 fprintf(stderr, "DestroyNotify event receivedn");
  857.     /* XCloseDisplay(display); */
  858.     Exit(1);
  859. }
  860.             case MapNotify:
  861.                 initialised = 1;   /* allow status display now its safe */
  862.                 break;
  863.             case UnmapNotify:
  864.                 if (X_TRACE) /* howcome 31/10/94 */
  865.                     fprintf(stderr, "UnmapNotifyn");
  866.                 break;
  867.             case ReparentNotify:
  868.                 break;
  869.     case PropertyNotify:
  870.     {
  871. /* thanks to Colas Nahaboo */
  872. Atom            actual_type;
  873. int             actual_format;
  874. unsigned long   nitems;
  875. unsigned long   bytes_after;
  876. unsigned char  *buffer = 0;
  877. if (Success == XGetWindowProperty(display, win, ARENA_COMMAND, 0, 8000, TRUE,
  878.   AnyPropertyType, &actual_type,
  879.   &actual_format, &nitems, &bytes_after,
  880.   &buffer))
  881. {
  882.     if(buffer)
  883.     {
  884. buffer[nitems] = '';
  885. if (!(actual_type == XA_STRING && ((signed long)nitems >= 0))) 
  886. {
  887.     XFree(buffer);
  888.     buffer = 0;
  889. } /* else ok */
  890.     } else {
  891. if (buffer) XFree(buffer);
  892. buffer = 0;
  893.     }
  894. }
  895. if(buffer)
  896. {
  897.     ParseCommandLine(buffer, nitems);
  898. }
  899.     }
  900.     break;
  901. #ifdef SELECTION
  902. /* selection event handling added by howcome 2/8/94 */
  903.     case SelectionClear:
  904. ClearStatusSelection();
  905. DisplayStatusBar();
  906. break;
  907.     case SelectionNotify:
  908. fprintf(stderr,"notifyn");
  909. break;
  910.     case SelectionRequest:
  911. {
  912.   XSelectionEvent selEv; 
  913.   if (event.xselectionrequest.target != XA_STRING) {
  914.     selEv.property = None;
  915.   }
  916.   else {
  917.     selEv.property = event.xselectionrequest.property;
  918.     XChangeProperty(event.xselectionrequest.display,
  919.   event.xselectionrequest.requestor,
  920.   event.xselectionrequest.property,
  921.   event.xselectionrequest.target,
  922.   8, PropModeReplace, selectStr,
  923.   strlen(selectStr));
  924.   }
  925.   selEv.type = SelectionNotify;
  926.   selEv.display = event.xselectionrequest.display;
  927.   selEv.requestor = event.xselectionrequest.requestor;
  928.   selEv.selection = event.xselectionrequest.selection;
  929.   selEv.target = event.xselectionrequest.target;
  930.   selEv.time = event.xselectionrequest.time;
  931.   XSendEvent(event.xselectionrequest.display, event.xselectionrequest.requestor, False, 0, (XEvent *) &selEv);
  932. }
  933. break;
  934. #endif /* SELECTION */
  935.             default:  /* handle all other events */
  936.                 if (X_TRACE) 
  937.     fprintf(stderr, "Unexpected Event: %dn", event.type);
  938.                 break;
  939.         }
  940. XFlush(display);
  941.     }
  942.     busy = 0;
  943.     return HT_WOULD_BLOCK; /* howcome 24/7/95: must do this to not insult library */
  944. }
  945. /* get font/colour resources */
  946. void GetResources(void)
  947. {
  948.     if (fontsize == 0)
  949.     {
  950.         LoadFont(IDX_H1FONT, DetermineValue(prog, "h1font", H1FONT), "variable");
  951.         LoadFont(IDX_H2FONT, DetermineValue(prog, "h2font", H2FONT), "variable");
  952.         LoadFont(IDX_H3FONT, DetermineValue(prog, "h3font", H3FONT), "variable");
  953.         LoadFont(IDX_H4FONT, DetermineValue(prog, "h4font", H4FONT), "variable");
  954.         LoadFont(IDX_LABELFONT, DetermineValue(prog, "labelfont", LABELFONT), "fixed");
  955.         LoadFont(IDX_NORMALFONT, DetermineValue(prog, "normalfont", NORMALFONT), "fixed");
  956.         LoadFont(IDX_INORMALFONT, DetermineValue(prog, "italicfont", ITALICFONT), "fixed");
  957.         LoadFont(IDX_BNORMALFONT, DetermineValue(prog, "boldfont", BOLDFONT), "fixed");
  958.         LoadFont(IDX_BINORMALFONT, DetermineValue(prog, "bolditalicfont", BINORMFONT), "fixed");
  959.         LoadFont(IDX_FIXEDFONT, DetermineValue(prog, "fixedfont", RFIXEDFONT), "fixed");
  960.         LoadFont(IDX_IFIXEDFONT, DetermineValue(prog, "ifixedfont", IFIXEDFONT), "fixed");
  961.         LoadFont(IDX_BFIXEDFONT, DetermineValue(prog, "bfixedfont", BFIXEDFONT), "fixed");
  962.         LoadFont(IDX_BIFIXEDFONT, DetermineValue(prog, "bifixedfont", BIFIXEDFONT), "fixed");
  963.         LoadFont(IDX_SYMBOLFONT, DetermineValue(prog, "symbolfont", SYMFONT), "grk-s30");
  964.         LoadFont(IDX_SUBSYMFONT, DetermineValue(prog, "subsymbolfont", SUBSYMFONT), "grk-s25");
  965.         LoadFont(IDX_SMALLFONT, DetermineValue(prog, "smallfont", SUBSCRFONT), "micro");
  966.     }
  967.     else if (fontsize == 1)
  968.     {
  969.         LoadFont(IDX_H1FONT, DetermineValue(prog, "h1font", H1FONTL), "vg-20");
  970.         LoadFont(IDX_H2FONT, DetermineValue(prog, "h2font", H2FONTL), "fg-16");
  971.         LoadFont(IDX_H3FONT, DetermineValue(prog, "h3font", H3FONTL), "variable");
  972.         LoadFont(IDX_H4FONT, DetermineValue(prog, "h4font", H4FONTL), "variable");
  973.         LoadFont(IDX_LABELFONT, DetermineValue(prog, "labelfont", LABELFONT), "fixed");
  974.         LoadFont(IDX_NORMALFONT, DetermineValue(prog, "normalfont", NORMALFONTL), "fixed");
  975.         LoadFont(IDX_INORMALFONT, DetermineValue(prog, "italicfont", ITALICFONTL), "fixed");
  976.         LoadFont(IDX_BNORMALFONT, DetermineValue(prog, "boldfont", BOLDFONTL), "fixed");
  977.         LoadFont(IDX_BINORMALFONT, DetermineValue(prog, "bolditalicfont", BINORMFONTL), "fixed");
  978.         LoadFont(IDX_FIXEDFONT, DetermineValue(prog, "fixedfont", RFIXEDFONTL), "fixed");
  979.         LoadFont(IDX_IFIXEDFONT, DetermineValue(prog, "ifixedfont", IFIXEDFONTL), "fixed");
  980.         LoadFont(IDX_BFIXEDFONT, DetermineValue(prog, "bfixedfont", BFIXEDFONTL), "fixed");
  981.         LoadFont(IDX_BIFIXEDFONT, DetermineValue(prog, "bifixedfont", BIFIXEDFONTL), "fixed");
  982.         LoadFont(IDX_SYMBOLFONT, DetermineValue(prog, "symbolfont", SYMFONTL), "grk-s30");
  983.         LoadFont(IDX_SUBSYMFONT, DetermineValue(prog, "subsymbolfont", SUBSYMFONTL), "grk-s25");
  984.         LoadFont(IDX_SMALLFONT, DetermineValue(prog, "smallfont", SUBSCRFONTL), "micro");
  985.     }
  986.     else if (fontsize >= 2)
  987.     {
  988.         LoadFont(IDX_H1FONT, DetermineValue(prog, "h1font", H1FONTG), "vg-20");
  989.         LoadFont(IDX_H2FONT, DetermineValue(prog, "h2font", H2FONTG), "fg-16");
  990.         LoadFont(IDX_H3FONT, DetermineValue(prog, "h3font", H3FONTG), "variable");
  991.         LoadFont(IDX_H4FONT, DetermineValue(prog, "h4font", H4FONTG), "variable");
  992.         LoadFont(IDX_LABELFONT, DetermineValue(prog, "labelfont", LABELFONT), "fixed");
  993.         LoadFont(IDX_NORMALFONT, DetermineValue(prog, "normalfont", NORMALFONTG), "fixed");
  994.         LoadFont(IDX_INORMALFONT, DetermineValue(prog, "italicfont", ITALICFONTG), "fixed");
  995.         LoadFont(IDX_BNORMALFONT, DetermineValue(prog, "boldfont", BOLDFONTG), "fixed");
  996.         LoadFont(IDX_BINORMALFONT, DetermineValue(prog, "bolditalicfont", BINORMFONTG), "fixed");
  997.         LoadFont(IDX_FIXEDFONT, DetermineValue(prog, "fixedfont", RFIXEDFONTG), "fixed");
  998.         LoadFont(IDX_IFIXEDFONT, DetermineValue(prog, "ifixedfont", IFIXEDFONTG), "fixed");
  999.         LoadFont(IDX_BFIXEDFONT, DetermineValue(prog, "bfixedfont", BFIXEDFONTG), "fixed");
  1000.         LoadFont(IDX_BIFIXEDFONT, DetermineValue(prog, "bifixedfont", BIFIXEDFONTG), "fixed");
  1001.         LoadFont(IDX_SYMBOLFONT, DetermineValue(prog, "symbolfont", SYMFONTG), "grk30s25");
  1002.         LoadFont(IDX_SUBSYMFONT, DetermineValue(prog, "subsymbolfont", SUBSYMFONTG), "grk-s25");
  1003.         LoadFont(IDX_SMALLFONT, DetermineValue(prog, "smallfont", SUBSCRFONTG), "micro");
  1004.     }
  1005.     fixed_font = Fonts[IDX_FIXEDFONT];
  1006.     /* list indents for ordered/unordered lists */
  1007.     ListIndent1 = XTextWidth(Fonts[IDX_NORMALFONT], "ABCabc", 6)/6;
  1008.     ListIndent2 = ListIndent1;
  1009.     ListIndent1 = 2 * ListIndent1;
  1010.     /* check for monchrome displays */
  1011.     if (DefaultDepth(display, screen) == 1)
  1012.     {
  1013.         strikeColor = labelColor = textColor = BlackPixel(display, screen);
  1014.         transparent = statusColor = windowColor = WhitePixel(display, screen);
  1015.         windowShadow = windowTopShadow = windowBottomShadow = textColor;
  1016.     }
  1017.     else   /* try for color but degrade as sensibly as possible */
  1018.     {
  1019.         if (!DetermineColor(prog, "windowColor", 220, 209, 186, &windowColor))
  1020.         {
  1021.             if (GetNamedColor("gray", &windowColor))
  1022.             {
  1023.                 windowBottomShadow = BlackPixel(display, screen);
  1024.                 if (!GetNamedColor("dim gray", &windowShadow))
  1025.                     windowShadow = windowColor;
  1026.                 if (!GetNamedColor("light gray", &windowTopShadow))
  1027.                     windowTopShadow = WhitePixel(display, screen);
  1028.                 strikeColor = textColor = labelColor = WhitePixel(display, screen);
  1029.             }
  1030.             else
  1031.             {
  1032.                 labelColor = strikeColor = textColor = BlackPixel(display, screen);
  1033.                 windowShadow = windowColor = WhitePixel(display, screen);
  1034.                 windowShadow = windowTopShadow = windowBottomShadow = textColor;
  1035.             }
  1036.         }
  1037.         else
  1038.         {
  1039.             DetermineColor(prog, "textColor", 0, 0, 100, &textColor);
  1040.             DetermineColor(prog, "labelColor", 0, 100, 100, &labelColor);
  1041.             DetermineColor(prog, "strikeColor", 170, 0, 0, &strikeColor);
  1042.             DetermineColor(prog, "windowShadow", 200, 188, 169, &windowShadow);
  1043.             DetermineColor(prog, "windowTopShadow", 255, 242, 216, &windowTopShadow);
  1044.             DetermineColor(prog, "windowBottomShadow", 180, 170, 152, &windowBottomShadow);
  1045.             if (windowTopShadow == windowColor)
  1046.                 windowTopShadow = WhitePixel(display, screen);
  1047.             if (windowBottomShadow == windowColor)
  1048.                 windowBottomShadow = BlackPixel(display, screen);
  1049.             if (windowColor == textColor)
  1050.             {
  1051.                 windowShadow = windowColor = BlackPixel(display, screen);
  1052.                 strikeColor = windowTopShadow = windowBottomShadow = textColor;
  1053.             }
  1054.         }
  1055.         transparent = windowColor;
  1056.         statusColor = windowShadow;
  1057.     }
  1058. }
  1059. void MakePaper()
  1060. {
  1061.     XGCValues values;
  1062.     unsigned int valuemask;
  1063.     Pixmap pixmap;
  1064.     XImage *image;
  1065.     GC drawGC;
  1066.     gc_fill = XCreateGC(display, win, 0, 0);
  1067.     XSetFunction(display, gc_fill, GXcopy);
  1068.     InitPaperRGB ();
  1069.     if (! (UsePaper && (depth == 8 || depth == 16 || depth == 24)))
  1070.     {
  1071.         UsePaper = 0;
  1072.         XSetForeground(display, gc_fill, windowColor);
  1073.     }
  1074.     else
  1075.     {
  1076.         tileWidth = tileHeight = 64;
  1077. /* howcome 15/3/95: commented out XQueryTile since it on some
  1078.            platforms set tile* to 0. On other servers it returns a low
  1079.            number which dosn't look good */
  1080. /*        XQueryBestTile(display, win, tileWidth, tileHeight, &tileWidth, &tileHeight); */
  1081.         tileData = CreateBackground(tileWidth, tileHeight, depth);
  1082.         if (!tileData)
  1083.         {
  1084.             UsePaper = 0;
  1085.             XSetForeground(display, gc_fill, windowColor);
  1086.             return;
  1087.         }
  1088.         if ((pixmap = XCreatePixmap(display, win, tileWidth, tileHeight, depth)) == 0)
  1089.         {
  1090.             fprintf(stderr, "Failed to create Pixmap for background!n");
  1091.             Exit(1);
  1092.         }
  1093.         if ((image = XCreateImage(display, DefaultVisual(display, screen),
  1094.   depth, ZPixmap, 0, (char *)tileData,
  1095.   tileWidth, tileHeight, (depth == 24 ? 32 : (depth == 16 ? 16 : 8)), 0)) == 0)
  1096.         {
  1097.             /* Free(tileData); keep for transparent backgrounds */
  1098.             XFreePixmap(display, pixmap);
  1099.             fprintf(stderr, "Failed to create X Image for background!n");
  1100.             Exit(1);
  1101.         }
  1102. /* howcome 22/2/95: do we need to set these?? */
  1103. image->byte_order = MSBFirst;
  1104. image->bitmap_bit_order = BitmapBitOrder(display); /* was MSBFirst*/ ;
  1105.         drawGC = XCreateGC(display, pixmap, 0, 0);
  1106.         XSetFunction(display, drawGC, GXcopy);
  1107.         XPutImage(display, pixmap, drawGC, image, 0, 0, 0, 0, tileWidth, tileHeight);
  1108.         XFreeGC(display, drawGC);
  1109.         image->data = NULL;   /* we don't want to free image data */
  1110.         XDestroyImage(image); /* normally frees image data */
  1111.         valuemask = GCTile|GCFillStyle;
  1112.         values.tile = pixmap;
  1113.         values.fill_style = FillTiled;
  1114.         XChangeGC(display, gc_fill, valuemask, &values);
  1115.     }
  1116. }
  1117. /* create clone of self by forking and duplicating resources
  1118.     creates duplicate of history file and closes
  1119.     all open files, then duplicates stdio ...
  1120.     returns 0 for parent, and 1 for clone
  1121. */
  1122. int CloneSelf(void)
  1123. {
  1124. #if 0
  1125.     int childpid, tty;
  1126.     int x = 0, y = 0;               /* window position */
  1127.     unsigned int border_width = 4;  /* border four pixels wide */
  1128. /*    unsigned int display_width, display_height;*/
  1129.     char *window_name = BANNER;
  1130.     char *icon_name = BANNER;
  1131.     int i, fh, depth;
  1132.     unsigned int class;
  1133.     Visual *visual;
  1134.     unsigned long valuemask, where;
  1135.     XSetWindowAttributes attributes;
  1136.     Pixmap icon_pixmap;
  1137.     if ((tty = open("/dev/tty", 2)) == -1 && (tty = open("/dev/null", 2)) == -1)
  1138.     {
  1139.         Warn("Can't open /dev/tty");
  1140.         return 0;
  1141.     }
  1142.     /* ensure that children won't become zombies */
  1143. #ifdef SIGCHLD
  1144.     signal(SIGCHLD, SIG_IGN);
  1145. #else
  1146.     signal(SIGCLD, SIG_IGN);
  1147. #endif
  1148.     if ((childpid = fork()) < 0)
  1149.     {
  1150.         close(tty);
  1151.         Warn("Can't fork new process");
  1152.         return 0;
  1153.     }
  1154.     if (childpid != 0)
  1155.     {
  1156.         close(tty);
  1157.         return 0;
  1158.     }
  1159.     /* ok child process - so dup stdio  - this leaves other files open! */
  1160.     fprintf(stderr,"CloneSelf: childn");
  1161.     close(0); dup(tty);
  1162.     close(1); dup(tty);
  1163.     close(2); dup(tty);
  1164.     close(tty);
  1165.     close(ConnectionNumber(display));  /* close TCP connection to X server */
  1166.     /* now clone history file and close original */
  1167.     initialised = 0;  /* avoid X output until this is true! */
  1168. /*    XCloseDisplay(display); */ /* close connection for parent display */
  1169.     /* connect to X server */
  1170.     if ( (display = XOpenDisplay(display_name)) == NULL )
  1171.     {
  1172.         (void) fprintf(stderr, "www: cannot connect to X server %sn",
  1173.                         XDisplayName(display_name));
  1174.         exit(-1);
  1175.     }
  1176.     /* free memory but not pixmaps which we no longer own! */
  1177.     FreeImages(1);
  1178.     FreeForms();   /* is this right? */
  1179.                      
  1180.   /* try to allocate 128 fixed colors + 16 grey scales */
  1181.     if (InitImaging(ColorStyle) == MONO)
  1182.         UsePaper = 0;
  1183. /*    GetResources();  *//* load font and colour resources */
  1184.     if (ColorStyle == MONO)
  1185.         statusColor = windowColor;
  1186.     /* get screen size from display structure macro */
  1187.     screen = DefaultScreen(display);
  1188.     depth = DisplayPlanes(display, screen);
  1189.     class = InputOutput;    /* window class*/
  1190.     visual = DefaultVisual(display, screen);
  1191.     valuemask = CWColormap | CWBorderPixel | CWBitGravity |
  1192.              CWBackingStore | CWBackingPlanes;
  1193.     attributes.colormap = colormap;
  1194.     attributes.bit_gravity = ForgetGravity;
  1195.     attributes.backing_planes = 0;
  1196.     attributes.backing_store = NotUseful;
  1197.     win = XCreateWindow(display, RootWindow(display, screen),
  1198.             x,y, win_width, win_height, border_width,
  1199.             depth, class, visual, valuemask, &attributes);
  1200.     XSetWindowBackground(display, win, windowColor);
  1201.     /* Create pixmap of depth 1 (bitmap) for icon */
  1202.     icon_pixmap = XCreateBitmapFromData(display, win, www_bits,
  1203.                                     www_width, www_height);
  1204.     /* Create default pixmap for use when we can't load images */
  1205.     default_pixmap = XCreatePixmapFromBitmapData(display, win, www_bits,
  1206.                       www_width, www_height, textColor, transparent, depth);
  1207.     default_pixmap_width = www_width;
  1208.     default_pixmap_height = www_height;
  1209.     /* initialize size hint property for window manager */
  1210.     size_hints.flags = PPosition | PSize | PMinSize;
  1211.     size_hints.x = x;
  1212.     size_hints.y = y;
  1213.     size_hints.width = win_width;
  1214.     size_hints.height = win_height;
  1215.     size_hints.min_width = 440;
  1216.     size_hints.min_height = 250;
  1217.     /* set properties for window manager (always before mapping) */
  1218.     XSetStandardProperties(display, win, window_name, icon_name,
  1219.         icon_pixmap, (char **)0, 0, &size_hints);
  1220.     /* select events wanted */
  1221.     XSelectInput(display, win, ExposureMask | KeyPressMask | KeyReleaseMask |
  1222.        Button1MotionMask | ButtonPressMask | ButtonReleaseMask | StructureNotifyMask |PropertyChangeMask);
  1223.     /* create hourglass cursor */
  1224.     hourglass = XCreateFontCursor(display, XC_watch);
  1225.     /* create GCs for text and drawing: gc_scrollbar, gc_status, gc_text */
  1226.     gc_scrollbar = XCreateGC(display, win, 0, 0);
  1227.     gc_status = XCreateGC(display, win, 0, 0);
  1228.     gc_text = XCreateGC(display, win, 0, 0);
  1229.     MakePaper();
  1230.     font = -1;
  1231.     if (DocHTML(CurrentDoc))
  1232.         SetBanner(CurrentDoc->url);
  1233.     /* refresh paint buffer to ensure that images resources are created */
  1234.     where = PixelOffset;
  1235.     PixelOffset = 0;
  1236.     ParseHTML(&i);
  1237.     if (where > 0)
  1238.         DeltaHTMLPosition(where);
  1239.     /* Map Display Window */
  1240.     XMapWindow(display, win);
  1241.     return 1;
  1242. #endif
  1243.     return 1;
  1244. }
  1245. Context *NewContext()
  1246. {
  1247.     return ((Context *) calloc (sizeof(Context), 1));
  1248. }
  1249. void myAlarm()
  1250. {
  1251.     fprintf(stderr,"myAlarmn");
  1252. }
  1253. void Push(void *item)
  1254. {
  1255.     *stack = (long)item;
  1256.     stack += sizeof(long);
  1257. }
  1258. void *Pop()
  1259. {
  1260.     if(stack == main_stack)
  1261. return NULL;
  1262.     
  1263.     stack -= sizeof(long);
  1264.     return((void *)*stack);
  1265. }
  1266. void main(int argc, char **argv)
  1267. {
  1268.     int x = 0, y = 0;               /* window position */
  1269.     unsigned int border_width = 2;  /* border four pixels wide */
  1270.     char *window_name = BANNER;
  1271.     char *icon_name = BANNER;
  1272.     int best_depth;    
  1273.     /*    unsigned long *pixels;  janet 21/07/95:  not used */
  1274.     unsigned int class;
  1275.     unsigned long valuemask;
  1276.     XSetWindowAttributes attributes;
  1277.     XClassHint class_hints;
  1278.     mode_t cmask;
  1279.  
  1280. #ifdef SIGWAITING_IGN
  1281.     signal(SIGWAITING, SIG_IGN);           /* howcome: solaris binaries receive this signal, but why? */
  1282. #endif
  1283.     signal(SIGABRT, SIG_IGN);
  1284.     signal(SIGPIPE, SIG_IGN);
  1285. #if !defined __QNX__ 
  1286.     signal(SIGINT, Exit);   /* howcome 4/10/94: trap C-C so that we can delete cache */
  1287. #endif
  1288.     signal(SIGIOT, CatchCore);
  1289. /*    signal(SIGSEGV, CatchCore); */
  1290.     cmask = umask(0000);
  1291.     stack = main_stack;
  1292.     UseHTTP2 = 1;
  1293.     UsePaper = 1;
  1294.     ColorStyle = COLOR888;
  1295.     Editor = getenv("EDITOR"); /* howcome 16/10/94: has to do it before command line arg processing */
  1296.     prog = argv[0];
  1297.     while (argc > 1)
  1298.     {
  1299. if (!strcasecmp(argv[1], "-help")||!strcasecmp(argv[1], "-h"))
  1300. {
  1301.     printf("Usage: arena [-large][-giant][-mono][-grey][-color][-color8]n");
  1302.     printf("             [-plain][-nocache][-noterminal][-nomailcap][-nostyle]n");
  1303.     printf("             [-cm][-quiet][-display display][-editor editor]n");
  1304.     printf("             [-cache dir][-geometry geom] [URL]n");
  1305.     Exit(1);
  1306. }
  1307. if (strcmp(argv[1], "-large") == 0)
  1308.         {
  1309.             fontsize = 1;
  1310.             --argc;
  1311.             ++argv;
  1312.         }
  1313.         else if (strcmp(argv[1], "-giant") == 0)
  1314.         {
  1315.             fontsize = 2;
  1316.             --argc;
  1317.             ++argv;
  1318.         }
  1319.         else if (strcmp(argv[1], "-mono") == 0)
  1320.         {
  1321.             ColorStyle = MONO;
  1322.             --argc;
  1323.             ++argv;
  1324.         }
  1325.         else if (strcmp(argv[1], "-grey") == 0 ||
  1326.                      strcmp(argv[1], "-gray") == 0)
  1327.         {
  1328.             ColorStyle = GREY4;
  1329.             --argc;
  1330.             ++argv;
  1331.         }
  1332.         else if (strcmp(argv[1], "-color") == 0)
  1333.         {
  1334.             ColorStyle = COLOR888;
  1335.             --argc;
  1336.             ++argv;
  1337.         }
  1338.         else if (strcmp(argv[1], "-color8") == 0)
  1339.         {
  1340.             ColorStyle = COLOR232;
  1341.             --argc;
  1342.             ++argv;
  1343.         }
  1344.         else if (strcmp(argv[1], "-plain") == 0)
  1345.         {
  1346.             UsePaper = 0;
  1347.             --argc;
  1348.             ++argv;
  1349.         }
  1350.         else if (strcmp(argv[1], "-nocache") == 0)
  1351.         {
  1352.             CacheRoot = NULL;
  1353.             --argc;
  1354.             ++argv;
  1355.         }
  1356.         else if (strcmp(argv[1], "-noterminal") == 0)
  1357.         {
  1358.             NoTerminal = 1;
  1359.             --argc;
  1360.             ++argv;
  1361.         }
  1362.         else if (strcmp(argv[1], "-nomailcap") == 0)
  1363.         {
  1364.             NoMailcap = 1;
  1365.             --argc;
  1366.             ++argv;
  1367.         }
  1368.         else if (strcmp(argv[1], "-nostyle") == 0)
  1369.         {
  1370.             NoStyle = 1;
  1371.             --argc;
  1372.             ++argv;
  1373.         }
  1374.         else if (strcmp(argv[1], "-cm") == 0)
  1375.         {
  1376.             OwnColorMap = 1;
  1377.             --argc;
  1378.             ++argv;
  1379.         }
  1380.         else if (strcmp(argv[1], "-quiet") == 0)
  1381.         {
  1382.             Quiet = 1;
  1383.             --argc;
  1384.             ++argv;
  1385.         }
  1386.         else if (strcmp(argv[1], "-display") == 0)
  1387.         {
  1388.             --argc;
  1389.             ++argv;
  1390.     if (argc > 1) {
  1391.                 --argc;
  1392.                 ++argv;
  1393.                 display_name = *argv;
  1394.                 if (OPTION_TRACE)
  1395.     printf("cache dir = %sn", CacheRoot);
  1396.             }
  1397.         }
  1398.         /* howcome 5/10/94: added cache command line option */
  1399.         else if (strcmp(argv[1], "-cache") == 0)
  1400.         {
  1401.             --argc;
  1402.             ++argv;
  1403.             if (argc > 1) {
  1404.                 --argc;
  1405.                 ++argv;
  1406.                 CacheRoot = *argv;
  1407.                 if (OPTION_TRACE)
  1408.     printf("cache dir = %sn", CacheRoot);
  1409.             }
  1410.         }
  1411.         /* howcome 10/10/94: added editor command line option */
  1412.         else if (strncmp(argv[1], "-editor",5) == 0)
  1413.         {
  1414.             --argc;
  1415.             ++argv;
  1416.             if (argc > 1) {
  1417.                 --argc;
  1418.                 ++argv;
  1419.                 Editor = *argv;
  1420.                 if (OPTION_TRACE) 
  1421.     printf("Editor = %sn", Editor);
  1422.             }
  1423.         }
  1424.         /* howcome 10/10/94: added badflags command line option */
  1425.         else if (strcmp(argv[1], "-badflags") == 0)
  1426.         {
  1427.             --argc;
  1428.             ++argv;
  1429.             if (argc > 1) {
  1430.                 --argc;
  1431.                 ++argv;
  1432.                 Badflags = atoi(*argv);
  1433.                 if (OPTION_TRACE) 
  1434.     printf("Editor = %sn", Editor);
  1435.             }
  1436.         }
  1437.         /* howcome 13/10/94: added icon command line option */
  1438.         else if (strcmp(argv[1], "-icon") == 0)
  1439.         {
  1440.             --argc;
  1441.             ++argv;
  1442.             if (argc > 1) {
  1443.                 --argc;
  1444.                 ++argv;
  1445.                 Icon = *argv;
  1446.                 if (OPTION_TRACE) 
  1447.     printf("Icon = %sn", Icon);
  1448.             }
  1449.         }
  1450.         /* howcome 10/10/94: added command line option */
  1451.         else if (strncmp(argv[1], "-printer",6) == 0)
  1452.         {
  1453.             --argc;
  1454.             ++argv;
  1455.             if (argc > 1) {
  1456.                 --argc;
  1457.                 ++argv;
  1458.                 Printer = *argv;
  1459.                 if (OPTION_TRACE) 
  1460.     printf("Printer = %sn", Printer);
  1461.             }
  1462.         }
  1463.         /* howcome 7/11/94: added command line option */
  1464.         else if (strncmp(argv[1], "-gamma",6) == 0)
  1465.         {
  1466.             --argc;
  1467.             ++argv;
  1468.             if (argc > 1) {
  1469.                 --argc;
  1470.                 ++argv;
  1471.                 Gamma = (double) atof (*argv);
  1472.                 if (OPTION_TRACE) 
  1473.     printf("Gamma = %fn", Gamma);
  1474.             }
  1475.         }
  1476.         else if (strcmp(argv[1], "-debug") == 0)
  1477.         {
  1478.             debug = 255;
  1479.     library_trace = 255;
  1480.             --argc;
  1481.             ++argv;
  1482.         }
  1483.         /* howcome 7/11/94: added command line option */
  1484.         else if (strncmp(argv[1], "-ct",3) == 0)
  1485.         {
  1486.             --argc;
  1487.             ++argv;
  1488.             if (argc > 1) {
  1489.                 --argc;
  1490.                 ++argv;
  1491.                 debug = (int) atoi(*argv);
  1492. /*                if (debug) */
  1493.     printf("Client trace = %dn", debug);
  1494.             }
  1495.         }
  1496.         /* howcome 9/5/95: added command line option */
  1497.         else if (strncmp(argv[1], "-lens",5) == 0)
  1498.         {
  1499.             --argc;
  1500.             ++argv;
  1501.             if (argc > 1) {
  1502.                 --argc;
  1503.                 ++argv;
  1504.                 lens_factor = (int) atof(*argv);
  1505. fontsize = (int) (lens_factor + 0.5);
  1506. /*                if (debug) */
  1507.     printf("Client trace = %dn", debug);
  1508.             }
  1509.         }
  1510.         /* howcome 7/11/94: added command line option */
  1511.         else if (strncmp(argv[1], "-lt",3) == 0)
  1512.         {
  1513.             --argc;
  1514.             ++argv;
  1515.             if (argc > 1) {
  1516.                 --argc;
  1517.                 ++argv;
  1518. {
  1519.     char *p = *argv;
  1520.     library_trace = 0;
  1521.     for(; *p; p++) {
  1522. switch (*p) {
  1523.     case 'a': library_trace |= SHOW_ANCHOR_TRACE; break;
  1524.     case 'b': library_trace |= SHOW_BIND_TRACE; break;
  1525.     case 'c': library_trace |= SHOW_CACHE_TRACE; break;
  1526.     case 'g': library_trace |= SHOW_SGML_TRACE; break;
  1527.     case 'p': library_trace |= SHOW_PROTOCOL_TRACE; break;
  1528.     case 's': library_trace |= SHOW_STREAM_TRACE; break;
  1529.     case 't': library_trace |= SHOW_THREAD_TRACE; break;
  1530.     case 'u': library_trace |= SHOW_URI_TRACE; break;
  1531.      case 'v': library_trace = SHOW_ALL_TRACE; break;
  1532. }
  1533.     }
  1534. }
  1535. /*                library_trace = (int) atoi(*argv);*/
  1536. /*                if (debug) */
  1537.     printf("Library trace = %dn", library_trace);
  1538.             }
  1539.         }
  1540.        /* pdd 31/10/95: added crippled window position option */
  1541.         else if (strcmp(argv[1], "-geometry") == 0)
  1542.         {
  1543.            --argc;
  1544.            ++argv;
  1545.            if (argc > 1) {
  1546.               --argc;
  1547.               ++argv;
  1548.       sscanf(*argv,"+%d+%d", &x, &y);
  1549.               /* this part may not be necessary... but can't hurt */
  1550.       if (x < 0 || x >= 2048 || y < 0 || y >= 1536) {
  1551. fprintf(stderr,"-geometry: only supports +X+Yn");
  1552. x = 0;
  1553. y = 0;
  1554.       }
  1555.             }
  1556.          }
  1557.         /* pdd 31/10/95: added option to force end of option parsing */
  1558.         else if (strcmp(argv[1],"--") == 0)
  1559.         {
  1560.           --argc;
  1561.           ++argv;
  1562.           break;
  1563.         }
  1564.         /* pdd 31/10/95: silently bypass invalid arguments */
  1565.         else if (strncmp(argv[1],"-",1) == 0)
  1566.         {
  1567.           --argc;
  1568.           ++argv;
  1569.         }
  1570.         /* pdd 31/10/95: treat first argument not starting with a "-"
  1571.            as a new starting URL */
  1572.         else if (strncmp(argv[1],"-",1) != 0)
  1573.         {
  1574.           break;
  1575.         }
  1576.       } /* end of command line option parsing */
  1577.     /* initialise ISO character entity definitions */
  1578.     InitEntities();
  1579.     /* connect to X server */
  1580.     if ( (display=XOpenDisplay(display_name)) == NULL )
  1581.     {
  1582.         (void) fprintf(stderr, "www: cannot connect to X server %sn",
  1583.                         XDisplayName(display_name));
  1584.         Exit(-1);
  1585.     }
  1586. /*    XSetErrorHandler(CatchX);*/
  1587. /* for debuging  - disable buffering of output queue */
  1588. /*    XSynchronize(display, 0); */ /* 0 enable, 1 disable */
  1589. /*    gateway = DetermineValue(prog, "gateway", GATEWAY_HOST); */
  1590.     help = DetermineValue(prog, "help", HELP_URL);
  1591. /*    printer = DetermineValue(prog, "printer", PRINTER);*/ /* howcome 16/10/94: best not to set this */
  1592.     startwith = getenv("WWW_HOME");
  1593.     if (!startwith)
  1594. startwith = DetermineValue(prog, "startwith", DEFAULT_URL);
  1595.     /* get screen size from display structure macro */
  1596.     screen = DefaultScreen(display);
  1597.     depth = DisplayPlanes(display, screen);
  1598.     if (depth == 1)
  1599.       ColorStyle = MONO;
  1600.     
  1601.     visual = BestVisual(TrueColor, &best_depth);
  1602.     if (best_depth == 24){
  1603. /* From Scott Nelson <snelson@canopus.llnl.gov> 24bit color: 12/5/94 */
  1604. /* visual = BestVisual(DirectColor, &best_depth); */ 
  1605. visual=BestVisual(TrueColor, &best_depth); 
  1606. CalcPixelShift();
  1607.     } else {
  1608. visual = BestVisual(DirectColor, &best_depth);
  1609.     }
  1610.     if (ColorStyle != COLOR888 || best_depth <= depth)
  1611.     {
  1612.         colormap = DefaultColormap(display, screen);
  1613.         visual = DefaultVisual(display, screen);
  1614.         if ((ColorStyle = InitImaging(ColorStyle)) == MONO)
  1615.             UsePaper = 0;
  1616.     }
  1617.     else
  1618.     {
  1619.         InitImaging(ColorStyle);
  1620.         depth = best_depth;
  1621.         colormap = XCreateColormap(display, RootWindow(display, screen),
  1622.                                                     visual, AllocNone);
  1623.     }
  1624.     display_width = DisplayWidth(display, screen);
  1625.     display_height = DisplayHeight(display, screen);
  1626.     display_pt2px =  (25.4 / 72.0) * 
  1627. (((double) DisplayWidth(display,screen)) / ((double) DisplayWidthMM(display, screen)));
  1628.     GetResources();  /* load font and colour resources */
  1629.     if (ColorStyle == MONO)
  1630.         statusColor = windowColor;
  1631.     /* size widow with enough room for text */
  1632.     charWidth = XTextWidth(Fonts[IDX_NORMALFONT], "ABCabc", 6)/6; 
  1633.     charHeight = SPACING(Fonts[IDX_NORMALFONT]);
  1634.     win_width = min ( (92 * charWidth), (display_width * 0.9) );
  1635.     win_height = min ( (35 * charHeight + 7), (display_height) );
  1636.     class = InputOutput;    /* window class*/
  1637.     valuemask = CWColormap | CWBorderPixel | CWBitGravity |
  1638.              CWBackingStore | CWBackingPlanes;
  1639.     attributes.colormap = colormap;
  1640.     attributes.bit_gravity = ForgetGravity;
  1641.     attributes.backing_planes = 0;
  1642.     attributes.backing_store = NotUseful;
  1643.     /* create opaque window */
  1644.     win = XCreateWindow(display, RootWindow(display, screen),
  1645.             x,y, win_width, win_height, border_width,
  1646.             depth, class, visual, valuemask, &attributes);
  1647.     class_hints.res_name = (char *)calloc(strlen("Browser")+1, sizeof(char));
  1648.     strcpy(class_hints.res_name, "Browser");
  1649.     class_hints.res_class = (char *)calloc(strlen(BANNER)+1, sizeof(char));
  1650.     strcpy(class_hints.res_class, BANNER);
  1651.     XSetClassHint(display, win, &class_hints);
  1652.     ARENA_LOCATION = XInternAtom(display, "ARENA_LOCATION", False); /* inter client comm */
  1653.     ARENA_COMMAND  = XInternAtom(display, "ARENA_COMMAND" , False);
  1654.     /* Create pixmap of depth 1 (bitmap) for icon */
  1655. /*
  1656.     icon_pixmap = XCreateBitmapFromData(display, win, www_bits,
  1657.                                     www_width, www_height);
  1658. */
  1659. #if 0
  1660.     /* Create default pixmap for use when we can't load images */
  1661.     default_pixmap = XCreatePixmapFromBitmapData(display, win, www_bits,
  1662.                       www_width, www_height, textColor, transparent, depth);
  1663.     default_pixmap_width = www_width;
  1664.     default_pixmap_height = www_height;
  1665.     default_image->pixmap = default_pixmap;
  1666.     default_image->width = default_pixmap_width;
  1667.     default_image->height = default_pixmap_height;
  1668. #endif
  1669.     /* initialize size hint property for window manager */
  1670.     size_hints.flags = PPosition | PSize | PMinSize;
  1671.     size_hints.x = x;
  1672.     size_hints.y = y;
  1673.     size_hints.width = win_width;
  1674.     size_hints.height = win_height;
  1675.     size_hints.min_width = 100;
  1676.     size_hints.min_height = 150;
  1677. /*
  1678.     size_hints.min_width = 440;
  1679.     size_hints.min_height = 350;
  1680. */
  1681.     /* before we can call XSetStandardProperties we need the
  1682.        icon. Befor we can get the icon, we need to initialize the
  1683.        library */
  1684.     context = NewContext();
  1685.     context->registered_anchors = HTList_new();
  1686. /*    context->pending_docs = HTList_new();
  1687.     context->pending_anchors = HTList_new(); */
  1688.     context->style = StyleGetInit();
  1689.     context->history = HTList_new();
  1690.     context->conversions = HTList_new();
  1691.     context->memory_leaks = HTList_new();
  1692.     libEntry(); /* howcome: library init */
  1693.     LoadIcon(); /* howcome 14/10/94 */
  1694.     /* set properties for window manager (always before mapping) */
  1695.     XSetStandardProperties(display, win, window_name, icon_name,
  1696.         icon_pixmap, argv, argc, &size_hints);
  1697.     /* select events wanted */
  1698.     XSelectInput(display, win, ExposureMask | KeyPressMask | KeyReleaseMask |
  1699.        Button1MotionMask | ButtonPressMask | ButtonReleaseMask |
  1700.        StructureNotifyMask | SubstructureNotifyMask| PropertyChangeMask);
  1701.     /* create hourglass cursor */
  1702.     hourglass = XCreateFontCursor(display, XC_watch);
  1703.     /* create GCs for text and drawing: gc_scrollbar, gc_status, gc_text */
  1704.     gc_scrollbar = XCreateGC(display, win, 0, 0);
  1705.     gc_status = XCreateGC(display, win, 0, 0);
  1706.     gc_text = XCreateGC(display, win, 0, 0);
  1707.     /* find user's name */
  1708.      user = getenv("USER");     /* shell variable for user name */
  1709. /*    InitCurrent(CurrentDirectory()); */  /* set current host to self etc. */
  1710.     SetToolBarFont(Fonts[IDX_LABELFONT]);
  1711.     SetStatusFont(Fonts[IDX_LABELFONT]);
  1712.     SetToolBarWin(win);
  1713.     SetToolBarGC(gc_status);
  1714.     SetStatusWin(win);
  1715.     SetStatusGC(gc_status);
  1716.     SetScrollBarWin(win);
  1717.     SetScrollBarGC(gc_scrollbar);
  1718.     SetIconWin(win);
  1719.     SetIconGC(gc_status);
  1720.     SetToolBarGC(gc_status);
  1721.     SetDisplayGC(gc_text);
  1722. #ifdef POPUP
  1723.     initPopup(Fonts[IDX_LABELFONT]);
  1724. #endif    
  1725.     MakePaper();  /* create gc_fill for textured paper */
  1726.     MakeIcons(depth);     /* create images for icons */
  1727.     /* create pixmap for testing initial <img> implementation */
  1728.     /* Map Display Window */
  1729.     XMapWindow(display, win);
  1730.     /* get buffer with named file in it */
  1731.     hdrlen = 0;
  1732.     buffer = NULL;
  1733.     if (argc != 1)
  1734.         startwith = argv[1];
  1735. #if 0
  1736.     signal(SIGALRM, myAlarm);
  1737.     itimer.it_value.tv_sec     = 10;
  1738.     itimer.it_value.tv_usec    = 0;
  1739.     itimer.it_interval.tv_sec  = 0;
  1740.     itimer.it_interval.tv_usec = 500000;
  1741.     setitimer (ITIMER_REAL, &itimer, &old_itimer);
  1742. #endif
  1743.     libEventLoop(ConnectionNumber(display), startwith);
  1744. }