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

  1. #ifndef lint
  2. static char SccsId[] = "%W%  %G%";
  3. #endif
  4.  
  5. /* Module:    wndwinit.c (Window Initialize)
  6.  * Purpose:    Create (and raise) the various windows used by ximage.
  7.  * Declared:    int screen_width, screen_height;
  8.  * Subroutine:  init_windows1()            returns: void
  9.  * Subroutine:  init_windows2()            returns: void
  10.  * Subroutine:    create_graphbox()        returns: void
  11.  * Subroutine:    redraw_window()            returns: void
  12.  * Subroutine:    raise_windows()            returns: void
  13.  * Xlib calls:    DisplayWidth(), DisplayHeight(), XMapWindow(), XRaiseWindow()
  14.  * Xlib calls:    XSetTransientForHint(), XSelectInput()
  15.  * Xlib calls:    XCreateImage(), XDestroyImage()
  16.  * Copyright:    1989 Smithsonian Astrophysical Observatory
  17.  *        You may do anything you like with this file except remove
  18.  *        this copyright.  The Smithsonian Astrophysical Observatory
  19.  *        makes no representations about the suitability of this
  20.  *        software for any purpose.  It is provided "as is" without
  21.  *        express or implied warranty.
  22.  * Modified:    {0} Michael VanHilst    initial version          28 January 1989
  23.  *        {1} MVH            Revised for X11        26 April 1989
  24.  *        {n} <who> -- <does what> -- <when>
  25.  */
  26.  
  27. #include <stdio.h>            /* stderr, FILE, NULL, etc. */
  28. #include <X11/Xlib.h>            /* X window stuff */
  29. #include <X11/Xutil.h>            /* X window manager stuff */
  30. #include "hfiles/constant.h"        /* define codes */
  31. #include "hfiles/define.h"        /* YES, NO, MIN, MAX and more */
  32. #include "hfiles/struct.h"        /* all struct record types */
  33. #include "hfiles/extern.h"        /* major declared structs */
  34.  
  35. extern struct windowRec desktop;
  36.  
  37. /* Root window info used by many routines */
  38. Window root;
  39. int screen_width, screen_height;
  40. int border_color = -1;
  41. char *border_color_name = NULL;
  42. static int cmd_argc;        /* i: command line arg count param */
  43. static char **cmd_argv;        /* i: command line args */
  44.  
  45. /*
  46.  * Subroutine:    init_windows1
  47.  * Purpose:    Send request for desktop area to screen's window manager
  48.  * Uses:    init_desktop() in WndwDesktop.c
  49.  * Uses:    set_configuration() in WndwConfig.c
  50.  * Uses:    create_window() in WndwCreate.c
  51.  * Xlib calls:    DisplayWidth(), DisplayHeight();
  52.  */
  53. void init_windows1 ( argc, argv )
  54.      int argc;            /* i: command line arg count param */
  55.      char **argv;        /* i: command line args */
  56. {
  57.   static void set_window_basics();
  58.   void init_desktop(), create_window();
  59.  
  60.   /* set display screen parameters for all to see */
  61.   root = DefaultRootWindow(desktop.display);
  62.   screen_width = DisplayWidth(desktop.display, desktop.screen);
  63.   screen_height = DisplayHeight(desktop.display, desktop.screen);
  64.   cmd_argc = argc;
  65.   cmd_argv = argv;
  66.   /* determine how much of the screen to use up and get default border color */
  67.   init_desktop();
  68.   set_window_basics(&desktop, root,
  69.             (int)color.hard.std_black, (int)color.hard.std_white,
  70.             NULL);
  71.   create_window(&desktop, "SAOimage", argc, argv, 0, 1);
  72. }
  73.  
  74. /*
  75.  * Subroutine:    init_windows2
  76.  * Purpose:    Create the actual windows used by SAOimage.
  77.  * PreState:    Recieved expose event for desktop window, colors known
  78.  * Uses:    configure_windows() in WndwConfig.c
  79.  * Uses:    get_window_dimensions(), create_window() in WndwCreate.c
  80.  */
  81. void init_windows2 ( )
  82. {
  83.   static void init_window_basics(), set_border_color();
  84.   void get_window_dimensions(), configure_windowgroup(), create_window();
  85.  
  86.   /* install runtime environment parameters for all windows */
  87.   if( border_color_name != NULL )
  88.     set_border_color(border_color_name);
  89.   if( border_color < 0 )
  90.     border_color = (int)color.hard.std_black;
  91.   init_window_basics(border_color);
  92.   /* wait for expose event of desktop */
  93.   get_window_dimensions(&desktop, 1, 1);
  94.   /* set up the window configurations */
  95.   configure_windowgroup (1);
  96.   /* create the windows */
  97.   /* create the main display window (must be first to be group leader) */
  98.   create_window(&dispbox, "display", cmd_argc, cmd_argv, 1, 1);
  99.   /* create the color bar window */
  100.   create_window(&colorbox, "color", cmd_argc, cmd_argv, 1, 1);
  101.   /* create the magnifier window */
  102.   create_window(&magnibox, "magnifier", cmd_argc, cmd_argv, 1, 1);
  103.   /* create the pan window */
  104.   create_window(&panbox, "pan", cmd_argc, cmd_argv, 1, 1);
  105.   /* create the buttonbox window */
  106.   create_window(&btnbox, "buttons", cmd_argc, cmd_argv, 1, 1);
  107. }
  108.  
  109. /*
  110.  * Subroutine:    create_graphbox
  111.  * Purpose:    Create the graphbox window (when needed, i.e. well after init)
  112.  * Xlib calls:    XSetTransientForHint(), XSelectInput()
  113.  */
  114. void create_graphbox ( )
  115. {
  116.   void configure_graphbox(), create_window();
  117.  
  118.   /* set location of graphbox in relation to colorbox */
  119.   configure_graphbox();
  120.   /* create the color graph window (not mapped) and connect to desktop */
  121.   create_window(&graphbox, "RGBgraph", cmd_argc, cmd_argv, 1, 0);
  122. }
  123.  
  124. /*
  125.  * Subroutine:    redraw_window
  126.  * Purpose:    Redraw the specified window.
  127.  * Called by:    control_event_loop in MainEvent.c on an Expose event.
  128.  * Note:    The btnbox handles its own expose events for the buttons.
  129.  */
  130. void redraw_window ( wndwID )
  131.      Window wndwID;
  132. {
  133.   void disp_dispbox(), redraw_magnifier(), draw_colorbar(), label_colorbar();
  134.   void disp_panbox(), draw_cgraph(), label_color_graph(), show_filename();
  135.   void display_graphbox();
  136.  
  137.   if( wndwID == dispbox.ID ) {
  138.     disp_dispbox();
  139.   } else if( wndwID == magnibox.ID ) {
  140.     redraw_magnifier();
  141.   } else if( wndwID == colorbox.ID ) {
  142.     draw_colorbar(0);
  143.   } else if( wndwID == graphbox.ID ) {
  144.     /* window may be mapped by window manager */
  145.     if( graphbox.active == 0 )
  146.       display_graphbox(0, 0);
  147.     else {
  148.       draw_cgraph(0, 0);
  149.       label_color_graph();
  150.       draw_colorbar(1);
  151.       label_colorbar();
  152.     }
  153.   } else if( wndwID == panbox.ID ) {
  154.     disp_panbox();
  155.   } else if( wndwID == desktop.ID )
  156.     show_filename();
  157. }
  158.  
  159. /*
  160.  * Subroutine:    raise_windows
  161.  * Purpose:    Raise the window should they have been obscured
  162.  * Xlib calls:    XRaiseWindow()
  163.  */
  164. void raise_windows ( )
  165. {
  166.   XRaiseWindow(desktop.display, desktop.ID);
  167.   if( graphbox.active )
  168.     XRaiseWindow(graphbox.display, graphbox.ID);
  169. }
  170.  
  171. /*
  172.  * Subroutine:    init_window_basics, set_window_basics
  173.  * Purpose:    Set the runtime environment parameters
  174.  */
  175. static void init_window_basics ( border_pixel )
  176.      int border_pixel;
  177. {
  178.   XImage *ximage;
  179.   static void set_window_basics();
  180.  
  181.   ximage = XCreateImage(desktop.display, color.visual, color.screen_depth,
  182.             dispbox.image.format, 0, malloc(4), 2, 2,
  183.             dispbox.image.bitmap_pad, (unsigned)2);
  184.   set_window_basics(&dispbox, desktop.ID, border_pixel,
  185.             (int)desktop.attrs.background_pixel, ximage);
  186.   set_window_basics(&panbox, desktop.ID, border_pixel,
  187.             (int)desktop.attrs.background_pixel, ximage);
  188.   set_window_basics(&magnibox, desktop.ID, border_pixel,
  189.             (int)desktop.attrs.background_pixel, ximage);
  190.   set_window_basics(&btnbox, desktop.ID, border_pixel,
  191.             (int)desktop.attrs.background_pixel, ximage);
  192.   set_window_basics(&colorbox, desktop.ID, border_pixel,
  193.             (int)desktop.attrs.background_pixel, ximage);
  194.   set_window_basics(&graphbox, root, (int)desktop.attrs.border_pixel,
  195.             (int)desktop.attrs.background_pixel, ximage);
  196.   (void)XDestroyImage(ximage);
  197. }
  198. static void set_window_basics ( window, parent, border_pixel, background,
  199.                     template )
  200.      struct windowRec *window;
  201.      Window parent;
  202.      int border_pixel;
  203.      int background;
  204.      XImage *template;
  205. {
  206.   window->display = color.display;
  207.   window->screen = color.screen;
  208.   window->parent = parent;
  209.   window->depth = color.screen_depth;
  210.   window->image.depth = color.screen_depth;
  211.   window->visual = color.visual;
  212.   window->attrs.colormap = color.colormap;
  213.   if( color.map.private_used )
  214.     window->valuemask |= CWColormap;
  215.   if( color.colormap_mode != VOP_Halftone )
  216.     window->image.format = ZPixmap;
  217.   else
  218.     window->image.format = XYBitmap;
  219.   if( background >= 0 ) {
  220.     window->attrs.background_pixel = (unsigned long)background;
  221.     window->valuemask |= CWBackPixel;
  222.   }
  223.   if( border_pixel >= 0 ) {
  224.     window->attrs.border_pixel = (unsigned long)border_pixel;
  225.     window->valuemask |= CWBorderPixel;
  226.   }
  227.   if( template != NULL )
  228.     window->image.f = template->f;
  229. }
  230.  
  231. /*
  232.  * Subroutine:    set_border_color
  233.  */
  234. static void set_border_color ( color_name )
  235.      char *color_name;
  236. {
  237.   XColor colordef, ideal;
  238.  
  239.   /* set up default border color for all windows */
  240.   if( color_name != NULL ) {
  241.     if( (color.screen_depth > 2) &&
  242.       XAllocNamedColor(desktop.display, color.colormap,
  243.                color_name, &colordef, &ideal) ) {
  244.       border_color = (int)colordef.pixel;
  245.     } else {
  246.       if( (strcmp(color_name, "white") == 0) )
  247.     border_color = (int)WhitePixel(desktop.display, desktop.screen);
  248.       else if( (strcmp(color_name, "black") == 0) )
  249.     border_color = (int)BlackPixel(desktop.display, desktop.screen);
  250.     }
  251.   }
  252. }
  253.