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

  1. #ifndef lint
  2. static char SccsId[] = "%W%  %G%";
  3. #endif
  4.  
  5. /* Module:    wndwconf.c (Window Configure)
  6.  * Purpose:    Determine size of desktop and mode of presentation to
  7.  *        display screen window manager (to later establish location
  8.  *        and dimension of individual windows - see WndwConfig.c
  9.  * Subroutine:    init_desktop()            returns: void
  10.  * Subroutine:    configure_windowgroup()        returns: void
  11.  * Subroutine:    configure_graphbox()        returns: void
  12.  * Subroutine:    parse_geometry()        returns: int
  13.  * Xlib calls:    XParseGeometry(), XTranslateCoordinates()
  14.  * Copyright:    1989 Smithsonian Astrophysical Observatory
  15.  *        You may do anything you like with this file except remove
  16.  *        this copyright.  The Smithsonian Astrophysical Observatory
  17.  *        makes no representations about the suitability of this
  18.  *        software for any purpose.  It is provided "as is" without
  19.  *        express or implied warranty.
  20.  * Modified:    {0} Michael VanHilst    initial version        30 April 1989
  21.  *              {1} MVH BSDonly strings.h compatability           19 Feb 1990
  22.  *        {n} <who> -- <does what> -- <when>
  23.  */
  24.  
  25. #include <stdio.h>            /* stderr, NULL, etc. */
  26.  
  27. #ifndef VMS
  28. #ifdef SYSV
  29. #include <string.h>        /* strlen, strcat, strcpy, strrchr */
  30. #else
  31. #include <strings.h>        /* strlen, strcat, strcpy, rindex */
  32. #endif
  33. #else
  34. #include <string.h>        /* strlen, strcat, strcpy, strrchr */
  35. #endif
  36.  
  37. #include <X11/Xlib.h>            /* X window stuff */
  38. #include <X11/Xutil.h>            /* X window manager stuff */
  39. #include "hfiles/define.h"        /* MIN, MAX, and more */
  40. #include "hfiles/struct.h"        /* all struct record types */
  41. #include "hfiles/extern.h"        /* major declared structs */
  42.  
  43. extern struct windowRec desktop;
  44. extern int screen_width, screen_height;    /* screen dimensions in WndwInit.c */
  45.  
  46. static int geo_flag = 0;        /* flag & vals from XParseGeometry */
  47. static int geo_x, geo_y;
  48. static unsigned int geo_width, geo_height;
  49.  
  50. /*
  51.  * Subroutine:    init_desktop
  52.  * Purpose:    Select the SAOimage window area.
  53.  * PostState:    Windows size hints altered or set
  54.  * Called by:    init_windows() in WndwInit.c
  55.  * Method:    The size can be given or set to norm.  If given but less
  56.  *        than min (i.e. 0,0) it becomes the minimum configuration.
  57.  */
  58. void init_desktop ( )
  59. {
  60.   static void set_parsed_geometry();
  61.  
  62.   desktop.hints.min_width =
  63.     (2 * desktop.xzero) + (2 * dispbox.bdrwidth) + dispbox.hints.min_width;
  64.   desktop.hints.max_width =
  65.     (2 * desktop.xzero) + (2 * dispbox.bdrwidth) + dispbox.hints.width;
  66.   desktop.hints.min_height = desktop.yzero +
  67.     panbox.bdrtotal + panbox.hints.min_height +
  68.       btnbox.bdrtotal + btnbox.hints.min_height + 2 +
  69.     dispbox.bdrtotal + dispbox.hints.min_height +
  70.       colorbox.bdrtotal + colorbox.hints.min_height;
  71.   desktop.hints.max_height = desktop.yzero +
  72.     panbox.bdrtotal + panbox.hints.height +
  73.       btnbox.bdrtotal + btnbox.hints.height + 2 +
  74.     dispbox.bdrtotal + dispbox.hints.height +
  75.       colorbox.bdrtotal + colorbox.hints.height;
  76.   /* if the user specified geometry */
  77.   if( geo_flag )
  78.     set_parsed_geometry();
  79.   if( (geo_flag & WidthValue) == 0 )
  80.     desktop.hints.width = desktop.hints.max_width;
  81.   if( (geo_flag & HeightValue) == 0 )
  82.     desktop.hints.height = desktop.hints.max_height;
  83. }
  84.  
  85. /*
  86.  * Subroutine:    configure_windowgroup
  87.  * Purpose:    Set the x, y, width, and height, of all windows
  88.  * Called by:    init_windows in WndwInit.c
  89.  * Called by:    regroup_windows in WndwAdjust.c
  90.  */
  91. void configure_windowgroup ( adjust_defaults )
  92.      int adjust_defaults;
  93. {
  94.   void init_panbox_dimensions();
  95.  
  96.   if( adjust_defaults ) {
  97.     /* choose relative sizes based on overall desktop area */
  98.     if( desktop.width < desktop.hints.max_width ) {
  99.       magnibox.hints.width = magnibox.hints.min_width;
  100.       panbox.hints.max_width = panbox.hints.min_width;
  101.     }
  102.     if( desktop.height < desktop.hints.max_height ) {
  103.       magnibox.hints.height = magnibox.hints.min_height;
  104.       panbox.hints.max_height = panbox.hints.min_height;
  105.       btnbox.hints.height = btnbox.hints.min_height;
  106.       if( desktop.height < 500 ) {
  107.     colorbox.hints.height = colorbox.hints.min_height;
  108.     graphbox.hints.height = graphbox.hints.min_height;
  109.     graphbox.hints.width = graphbox.hints.min_width;
  110.       }
  111.     }
  112.     /* choose a panbox size within the guidelines */
  113.     init_panbox_dimensions();
  114.   }
  115.   /* sizes now known, fill in the rest based on the configuration */
  116.   magnibox.hints.y = desktop.yzero;
  117.   magnibox.hints.x = desktop.width -
  118.     (desktop.xzero + magnibox.bdrtotal + magnibox.hints.width);
  119.   panbox.hints.y = magnibox.hints.y;
  120.   panbox.hints.x = magnibox.hints.x -
  121.     ((2 * desktop.xzero) + panbox.bdrtotal + panbox.hints.width);
  122.   btnbox.hints.y = MAX(magnibox.hints.height, panbox.hints.height) +
  123.     btnbox.bdrwidth + magnibox.hints.y + magnibox.bdrtotal + 1;
  124.   if( btnbox.bdrwidth > 0 ) {
  125.     btnbox.hints.x = desktop.xzero;
  126.     btnbox.hints.width = desktop.xwidth -  btnbox.bdrtotal;
  127.   } else {
  128.     btnbox.hints.x = 0;
  129.     btnbox.hints.width = desktop.width;
  130.   }
  131.   colorbox.hints.y = desktop.height -
  132.     (colorbox.bdrwidth + colorbox.hints.height + colorbox.bdrtotal);
  133.   if( colorbox.bdrwidth > 0 ) {
  134.     colorbox.hints.x = desktop.xzero;
  135.     colorbox.hints.width = desktop.xwidth - colorbox.bdrtotal;
  136.   } else {
  137.     colorbox.hints.x = 0;
  138.     colorbox.hints.width = desktop.width;
  139.   }
  140.   dispbox.hints.x = desktop.xzero;
  141.   dispbox.hints.y = 1 +
  142.     btnbox.hints.y + btnbox.bdrtotal + btnbox.hints.height + btnbox.bdrwidth;
  143.   dispbox.hints.width = desktop.width -
  144.     ((2 * desktop.xzero) + dispbox.bdrtotal);
  145.   dispbox.hints.height = (colorbox.hints.y - dispbox.hints.y) -
  146.     (dispbox.bdrtotal + btnbox.bdrwidth + colorbox.bdrwidth);
  147. }
  148.  
  149. /*
  150.  * Subroutine:    configure_graphbox
  151.  * Purpose:    Set the graphbox to appear undereath colorbar
  152.  * Xlib calls:    XTranslateCoordinates()
  153.  */
  154. void configure_graphbox ()
  155. {
  156.   Window child, *ch;
  157.   Window parent, root;
  158.   int left_x, right_x, lo_y, hi_y;
  159.   int head_y, head_height;
  160.   unsigned int nch;
  161.  
  162.   /* get desktop's parent and root */
  163.   if( XQueryTree(desktop.display, desktop.ID, &root, &parent, &ch, &nch) == 0 )
  164.     return;
  165.   XFree((char *)ch);
  166.   /* get current root window coords of desktop */
  167.   (void)XTranslateCoordinates(desktop.display, desktop.ID, root,
  168.                   desktop.width, desktop.height,
  169.                   &right_x, &lo_y, &child);
  170.   (void)XTranslateCoordinates(desktop.display, desktop.ID, root,
  171.                   0, 0, &left_x, &hi_y, &child);
  172.   /* if desktop's parent is not root, window manager gave it a header */
  173.   if( parent != root ) {
  174.     (void)XTranslateCoordinates(desktop.display, parent, root,
  175.                 0, 0, &left_x, &head_y, &child);
  176.     head_height = hi_y - head_y;
  177.   } else {
  178.     head_height = 0;
  179.     head_y = hi_y;
  180.   }
  181.   if( graphbox.hints.height > graphbox.hints.width ) {
  182.     graphbox.hints.y = hi_y - 2;
  183.     if( (right_x + graphbox.hints.width) < screen_width )
  184.       graphbox.hints.x = right_x + 2;
  185.     else
  186.       graphbox.hints.x = left_x - (graphbox.hints.width + 4);
  187.   } else {
  188.     graphbox.hints.x = left_x - 2;
  189.     graphbox.hints.width = desktop.width;
  190.     /* put graphbox above colorbox if desktop is too close to bottom */
  191.     if( (screen_height - lo_y) <
  192.        (graphbox.hints.height + head_height + graphbox.bdrtotal) )
  193.       graphbox.hints.y = MAX(head_y - (head_height + 4), 0);
  194.     else
  195.       graphbox.hints.y = lo_y + head_height + 3;
  196.   }
  197. }
  198.  
  199. /*
  200.  * Subroutine:    parse_geometry
  201.  * Purpose:    Parse a user given geometry string
  202.  * Returns:    0 if no values were successfully parsed, else 1
  203.  * Xlib calls:    XParseGeometry()
  204.  */
  205. int parse_geometry ( geometry, disp_size )
  206.      char *geometry;
  207.      int disp_size;    /* i: apply size to: 1=dispbox, 0=desktop */
  208. {
  209.   geo_flag = XParseGeometry(geometry, &geo_x, &geo_y, &geo_width, &geo_height);
  210.   if( geo_flag != 0 ) {
  211.     if( disp_size ) {
  212.       if( geo_flag & WidthValue ) {
  213.     dispbox.hints.width = geo_width;
  214.     geo_flag ^= WidthValue;
  215.       }
  216.       if( geo_flag & HeightValue ) {
  217.     dispbox.hints.height = geo_height;
  218.     geo_flag ^= HeightValue;
  219.       }
  220.     }
  221.     return( 1 );
  222.   } else
  223.     return( 0 );
  224. }
  225.  
  226. /*
  227.  * Subroutine:    set_parsed_geometry
  228.  * Purpose:    Set up the desktop window's size_hints as per any parsed
  229.  *        user specified geometry
  230.  */
  231. static void set_parsed_geometry ( )
  232. {
  233.   if( geo_flag == 0 )
  234.     return;
  235.   if( geo_flag & WidthValue )
  236.     desktop.hints.width = (unsigned int)
  237.       MIN(MAX(geo_width, desktop.hints.min_width), screen_width);
  238.   if( geo_flag & HeightValue )
  239.     desktop.hints.height = (unsigned int)
  240.       MIN(MAX(geo_height, desktop.hints.min_height), screen_height);
  241.   if( geo_flag & XValue ) {
  242.     if( geo_flag & XNegative ) {
  243.       /* I'm not sure what the standard is supposed to be here */
  244.       if( geo_x < 0 )
  245.     desktop.hints.x = screen_width - (desktop.hints.width - geo_x);
  246.       else
  247.     desktop.hints.x = screen_width - (desktop.hints.width + geo_x);
  248.       desktop.hints.x -= desktop.bdrtotal;
  249.     } else
  250.       desktop.hints.x = geo_x;
  251.   }
  252.   if( geo_flag & YValue ) {
  253.     if( geo_flag & YNegative ) {
  254.       if( geo_y < 0 )
  255.     desktop.hints.y = screen_height - (desktop.hints.height - geo_y);
  256.       else
  257.     desktop.hints.y = screen_height - (desktop.hints.height + geo_y);
  258.       desktop.hints.y -= desktop.bdrtotal;
  259.     } else
  260.       desktop.hints.y = geo_y;
  261.   }
  262.   if( (geo_flag & XValue) || (geo_flag & YValue) ) {
  263.     desktop.hints.flags =
  264.       (USPosition | USSize) | (desktop.hints.flags & (~(PPosition | PSize)));
  265.   } else if( (geo_flag & WidthValue) || (geo_flag & HeightValue) ) {
  266.     desktop.hints.flags = USSize | (desktop.hints.flags & (~PSize));
  267.   }
  268. }
  269.