home *** CD-ROM | disk | FTP | other *** search
/ Encyclopedia of Graphics File Formats Companion / GFF_CD.ISO / software / unix / saoimage / sao1_07.tar / wndwcre.c < prev    next >
C/C++ Source or Header  |  1991-01-09  |  6KB  |  157 lines

  1. #ifndef lint
  2. static char SccsId[] = "%W%  %G%";
  3. #endif
  4.  
  5. /* Module:    wndwcre.c (Window Create)
  6.  * Purpose:    Create a window with proper X11 protocol
  7.  * Subroutine:    create_window()            returns: void
  8.  * Subroutine:    get_window_dimensions()        returns: void
  9.  * Xlib calls:    XCreateWindow(), XMapWindow()
  10.  * Xlib calls:    XSetStandardProperties(), XSetWMHints()
  11.  * Xlib calls:    XWindowEvent(), XIfEvent(), XGetGeometry()
  12.  * Copyright:    1989 Smithsonian Astrophysical Observatory
  13.  *        You may do anything you like with this file except remove
  14.  *        this copyright.  The Smithsonian Astrophysical Observatory
  15.  *        makes no representations about the suitability of this
  16.  *        software for any purpose.  It is provided "as is" without
  17.  *        express or implied warranty.
  18.  * Modified:    {0} Michael VanHilst    initial version        30 April 1989
  19.  *        {1} David Muchmore (astro.umontreal.ca) for SGI  23 June 1990
  20.  *        {n} <who> -- <does what> -- <when>
  21.  */
  22.  
  23. #include <stdio.h>        /* stderr, NULL, etc. */
  24. #include <X11/Xlib.h>        /* X window stuff */
  25. #include <X11/Xutil.h>        /* window manager hint stuff */
  26. #include "hfiles/window.h"
  27.  
  28. #ifdef VMS
  29. #ifdef IMTOOL
  30. /* get the VMS event flag number that will be used to detect events
  31.  * from all windows and mailbox connections */
  32. extern int XZ_efn;
  33. #endif
  34. #endif
  35.  
  36. /*
  37.  * Subroutine:    create_window
  38.  * Purpose:    Send window request to X server or window manager
  39.  * Xlib calls:    XCreateWindow(), XMapWindow()
  40.  * Xlib calls:    XSetStandardProperties(), XSetWMHints()
  41.  * PostState:    The first created window (dispbox) becomes the group leader
  42.  */
  43. void create_window ( window, title, argc, argv, set, map )
  44.      struct windowRec *window;    /* i: window info record */
  45.      char *title;        /* i: name for use by window manager */
  46.      int argc;            /* i: command line arg count param */
  47.      char **argv;        /* i: command line args */
  48.      int set;            /* i: adopt the parameters untested */
  49.      int map;            /* i: map window immediately */
  50. {
  51.   XWMHints wmhints;
  52.   void exit_errmsg();
  53.  
  54.   /* Create the window */
  55.   window->ID =
  56.     XCreateWindow(window->display, window->parent, window->hints.x,
  57.           window->hints.y, window->hints.width, window->hints.height,
  58.           window->bdrwidth, CopyFromParent, InputOutput,
  59.           window->visual, window->valuemask, &window->attrs);
  60. /* Old code (prior to SGI version which reserves its own colormap     *
  61.  *          CopyFromParent, window->valuemask, &window->attrs); */
  62.   if( !window->ID ) {
  63.     if( title != NULL )
  64.       (void)fprintf(stderr, "Window: %s - ", title);
  65.     exit_errmsg("XCreateWindow window failed");
  66.   }
  67.   /* Hint desired dimensions or adopt them immediately */
  68.   if( window->hints.flags )
  69.     XSetStandardProperties(window->display, window->ID, title, NULL, None,
  70.                argv, argc, &window->hints);
  71.   if( window->attrs.event_mask & KeyPressMask ) {
  72.     /* Tell window manager to handle keyboard focus for us */
  73.     wmhints.input = True;
  74.     wmhints.flags = InputHint;
  75.     XSetWMHints(window->display, window->ID, &wmhints);
  76.   }
  77.   if( set ) {
  78.     window->x = window->hints.x;
  79.     window->y = window->hints.y;
  80.     window->width = window->hints.width;
  81.     window->height = window->hints.height;
  82.     window->xwidth = window->width - (window->xzero + window->xzero);
  83.     window->yheight = window->height - (window->yzero + window->yzero);
  84.     window->rightx = window->x + window->width + window->bdrtotal;
  85.     window->lowery = window->y + window->height + window->bdrtotal;
  86.   }
  87.   if( map )
  88.     XMapWindow(window->display, window->ID);
  89. #ifdef VMS
  90. #ifdef IMTOOL
  91.   {
  92.     int    all_events = 0xFFFFFFFF;
  93.     void XZ_ast();
  94.     XSelectAsyncInput(window->display, window->ID, all_events, XZ_ast, XZ_efn);
  95.   }
  96. #endif
  97. #endif
  98. }
  99.  
  100. /*
  101.  * Subroutine:    check_expose
  102.  * Purpose:    Function callable by XIfEvent from within xlib to check if
  103.  *        event is Expose for given window.
  104.  * Note:    Calling sequence is fixed, no xlib calls may be made.
  105.  */
  106. Bool check_expose ( display, event, arg )
  107.      Display *display;        /* i: server ID */
  108.      XEvent *event;        /* i: pointer to xlib event */
  109.      char *arg;            /* i: generic pointer passed to XIfEvent */
  110. {
  111.   struct windowRec *window;    /* i: arg is actually a struct pointer */
  112.  
  113.   window = (struct windowRec *)arg;
  114.   if( (display == window->display) &&
  115.       (event->type == Expose) &&
  116.       (event->xexpose.window == window->ID) )
  117.     return( True );
  118.   else
  119.     return( False );
  120. }
  121.  
  122. /*
  123.  * Subroutine:    get_window_dimensions
  124.  * Purpose:    Get window dimensions after window is first mapped
  125.  * PreState:    Window's existence announced by Expose event.
  126.  * PostState:    Window struct's dimensions filled in.
  127.  * Xlib calls:    XWindowEvent(), XIfEvent(), XGetGeometry()
  128.  * Method:    If disposing the Expose events, we dispose of all of the
  129.  *        window,s expose events (they count down to 0).
  130.  */
  131. void get_window_dimensions ( window, wait, discard )
  132.      struct windowRec *window;
  133.      int wait;        /* i: look for an expose event for this window */
  134.      int discard;    /* i: dispose of the expose event */
  135. {
  136.   Window parent;    /* l: returned parent of this window */
  137.   XEvent event;        /* l: event
  138.   Bool check_expose();    /* l: function to identify window's expose event
  139.  
  140.   /* if waiting for an Expose event before querying window */
  141.   if( wait ) {
  142.     if( discard ) {
  143.       do {
  144.     XWindowEvent(window->display, window->ID, ExposureMask, &event);
  145.       } while( event.xexpose.count != 0 );
  146.     } else {
  147.       XIfEvent(window->display, &event, check_expose, window);
  148.     }
  149.   }
  150.   (void)XGetGeometry(window->display, window->ID, &parent,
  151.              &window->x, &window->y, &window->width, &window->height,
  152.              &window->bdrwidth, &window->depth);
  153.   window->bdrtotal = 2 * window->bdrwidth;
  154.   window->xwidth = window->width - (window->xzero + window->xzero);
  155.   window->yheight = window->height - (window->yzero + window->yzero);
  156. }
  157.