home *** CD-ROM | disk | FTP | other *** search
/ Encyclopedia of Graphics File Formats Companion / GFF_CD.ISO / software / unix / saoimage / sao1_07.tar / btnlib / resize.c < prev    next >
C/C++ Source or Header  |  1990-04-20  |  5KB  |  140 lines

  1. #ifndef lint
  2. static char SccsId[] = "%W%  %G%";
  3. #endif
  4.  
  5. /*
  6.  * Module:    resize.c (Resize Box)
  7.  * Project:    PROS -- ROSAT RSDC
  8.  * Purpose:    Resize boxes and buttons for parent resize
  9.  * Subroutines:    ResizeButtons()            returns: void
  10.  * Subroutines:    static btn_ChkResize()        returns: void
  11.  * Subroutines:    ResizeBox()            returns: void
  12.  * Xlib calls:    XResizeWindow(), XDestroyImage(), XMoveResizeWindow()
  13.  * Copyright:    1989 Smithsonian Astrophysical Observatory
  14.  *        You may do anything you like with this file except remove
  15.  *        this copyright.  The Smithsonian Astrophysical Observatory
  16.  *        makes no representations about the suitability of this
  17.  *        software for any purpose.  It is provided "as is" without
  18.  *        express or implied warranty.
  19.  * Modified:    {0} Michael VanHilst    initial version        31 March 1989
  20.  *        {n} <who> -- <does what> -- <when>
  21.  */
  22.  
  23. #include <X11/Xlib.h>
  24. #include "buttons.h"
  25.  
  26. /*
  27.  * Subroutine:    ResizeButtons
  28.  * Purpose:    Resize all buttons affected by resize of parent window
  29.  * Returns:    void
  30.  * Called by:    Application program
  31.  * Uses:    btn_ChkResize()
  32.  * Xlib calls:    none
  33.  * Post-state:    All buttonboxes having given parent are resized to fill
  34.  * Method:    Call btn_ChkResize with this menu and then its co-menus.
  35.  */
  36. void ResizeButtons ( buttonbox, parent )
  37.      ButtonBox buttonbox;    /* i: top handle for button menu group */
  38.      BoxParent *parent;        /* i: record describing parent window */
  39. {
  40.   int i;        /* l: loop counter */
  41.   static void btn_ChkResize();
  42.  
  43.   /* check this buttonbox */
  44.   btn_ChkResize(buttonbox, parent);
  45.   /* check co-buttonboxes */
  46.   for( i = 0; i < buttonbox->co_menu_count; i++ )
  47.     btn_ChkResize(buttonbox->co_menu[i], parent);
  48. }
  49.  
  50. /*
  51.  * Subroutine:    btn_ChkResize
  52.  * Purpose:    Resize all buttons affected by resize of parent window in
  53.  *        this menu or any of the submenus of its buttons.
  54.  * Returns:    void
  55.  * Called by:    ButtonResize()
  56.  * Uses:    ResizeBox() below, btn_ChkResize()-recursive
  57.  * Xlib calls:    none
  58.  * Post-state:    All buttonboxes having given parent are resized to fill
  59.  * Method:    Check parentage of this box, then recurse on each submenu of
  60.  *        each button.
  61.  */
  62. static void btn_ChkResize ( buttonbox, parent )
  63.      ButtonBox buttonbox;    /* i: top handle for button menu tree */
  64.      BoxParent *parent;        /* i: record describing parent window */
  65. {
  66.   int btn;        /* l: index of active button */
  67.   int op;        /* l: index of button pressing modifier mask */
  68.   int i;        /* l: index of button submenu */
  69.  
  70.   /* go through our window list to find a match */
  71.   if( buttonbox->parentID == parent->wndwID )
  72.     ResizeBox(buttonbox, parent);
  73.   /* continue search through buttons' submenus (for each button) */
  74.   for( btn = 0; btn < buttonbox->btn_cnt; btn++ ) {
  75.     /* submenus can be specific to a selection option (for each op) */
  76.     for( op = 0; op < buttonbox->buttons[btn].feel->nfunctions; op++ ) {
  77.       /* if a button has submenus, check them out */
  78.       if( buttonbox->buttons[btn].submenu_count[op] > 0 ) {
  79.     /* for each submenu */
  80.     for( i = 0; i < buttonbox->buttons[btn].submenu_count[op]; i++ )
  81.       btn_ChkResize((ButtonBox)buttonbox->buttons[btn].submenu[op][i],
  82.             parent);
  83.       }
  84.     }
  85.   }
  86. }
  87.  
  88. /*
  89.  * Subroutine:    ResizeBox
  90.  * Purpose:    Resize all buttons in this box to given dimensions.
  91.  * Returns:    void
  92.  * Called by:    btn_ChkResize() above, application program
  93.  * Uses:    btn_LabelButtons() in MakeBox.c
  94.  * Xlib calls:    XResizeWindow(), XDestroyImage(), XMoveResizeWindow()
  95.  * Post-state:    Buttonbox subwindow and buttons are resized to fill given size
  96.  * Method:    Adjust subwindow exactly covering parent window.  Adjust
  97.  *        button subwindows, destroy and recreate drawing stuff for
  98.  *        each button.
  99.  */
  100. void ResizeBox ( buttonbox, parent )
  101.      ButtonBox buttonbox;    /* i: handle for buttonbox record */
  102.      BoxParent *parent;        /* i: record describing parent window */
  103. {
  104.   int btn_wdth, btn_hght;    /* l: dimensions for each button in box */
  105.   int x, y;            /* l: pixel coord of button */
  106.   unsigned int width, height;    /* l: pixel size of overall box */
  107.   int i, j;            /* l: column and row loop counters */
  108.   int btn;            /* l: index of accessed button */
  109.   BoxGeometry *geo;        /* l: buttonbox's geometry parameters */
  110.   void btn_Dimensions(), btn_LabelButtons();
  111.  
  112.   if( (buttonbox->parent_width == parent->width) &&
  113.       (buttonbox->parent_height == parent->height) )
  114.     return;
  115.   /* resize the buttonbox subwindow */
  116.   /* get the basic box and button dimensions */
  117.   geo = buttonbox->geometry;
  118.   btn_Dimensions(parent, geo, &btn_wdth, &btn_hght, &x, &y, &width, &height);
  119.   XMoveResizeWindow(parent->display, buttonbox->wndwID, x, y, width, height);
  120.   btn = 0;
  121.   for( j = 0; j < geo->box_rows; j++ ) {
  122.     for( i = 0; i < geo->box_cols; i++ ) {
  123.       if( btn < geo->btn_cnt ) {
  124.     XDestroyImage(buttonbox->buttons[btn].image[OFF_OUT]);
  125.     XDestroyImage(buttonbox->buttons[btn].image[ON_OUT]);
  126.     XDestroyImage(buttonbox->buttons[btn].image[OFF_IN]);
  127.     XDestroyImage(buttonbox->buttons[btn].image[ON_IN]);
  128.       }
  129.       x = btn_wdth * i;
  130.       y = btn_hght * j;
  131.       XMoveResizeWindow(parent->display, buttonbox->buttons[btn].wndwID,
  132.             x, y, btn_wdth, btn_hght);
  133.       btn++;
  134.     }
  135.   }
  136.   /* create XImage bitmaps for button visuals */
  137.   btn_LabelButtons(buttonbox, btn_wdth, btn_hght,
  138.            geo->off_inverse, geo->on_inverse);
  139. }
  140.