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

  1. #ifndef lint
  2. static char SccsId[] = "%W%  %G%";
  3. #endif
  4.  
  5. /*
  6.  * Module:    mount.c (Mount Box)
  7.  * Project:    PROS -- ROSAT RSDC
  8.  * Purpose:    Map and unmap buttonbox windows and replace active submenus
  9.  * Subroutine:    MountButtonMenu()            returns: void
  10.  * Subroutine:    static btn_MapButtonbox()        returns: void
  11.  * Subroutine:    static btn_UnmapButtonbox()        returns: void
  12.  * Subroutine:    btn_ReplaceSubmenus()            returns: void
  13.  * Subroutine:    btn_ReplaceCosubmenus()            returns: void
  14.  * Xlib calls:    XMapWindow(), XUnmapWindow()
  15.  * Copyright:    1989 Smithsonian Astrophysical Observatory
  16.  *        You may do anything you like with this file except remove
  17.  *        this copyright.  The Smithsonian Astrophysical Observatory
  18.  *        makes no representations about the suitability of this
  19.  *        software for any purpose.  It is provided "as is" without
  20.  *        express or implied warranty.
  21.  * Modified:    {0} Michael VanHilst    initial version        31 March 1989
  22.  *        {n} <who> -- <does what> -- <when>
  23.  */
  24.  
  25. #include <stdio.h>    /* define stderr */
  26. #include <X11/Xlib.h>    /* needed for Buttons.h */
  27. #include "buttons.h"
  28.  
  29. /*
  30.  * Subroutine:    MountButtonMenu
  31.  * Purpose:    User call to initially display the button-panels
  32.  * Returns:    void
  33.  * Called by:    Application program
  34.  * Uses:    btn_MapButtonbox()
  35.  * Xlib calls:    none
  36.  * Note:    This routine moves latterally to cover co-menus
  37.  */
  38. void MountButtonMenu ( buttonbox )
  39.      ButtonBox buttonbox;
  40. {
  41.   int i;
  42.   static void btn_MapButtonbox();
  43.  
  44.   btn_MapButtonbox(buttonbox);
  45.   for( i = 0; i < buttonbox->co_menu_count; i++ )
  46.     btn_MapButtonbox(buttonbox->co_menu[i]);
  47. }
  48.  
  49. /*
  50.  * Subroutine:    btn_MapButtonbox
  51.  * Purpose:    Make the buttonbox and its current submenus visible
  52.  * Returns:    void
  53.  * Called by:    MountButtonbox() above
  54.  * Called by:    btn_ReplaceSubmenus(), btn_ReplaceCosubmenus() below
  55.  * Uses:    recursion
  56.  * Xlib calls:    XMapWindow
  57.  * Method:    Map the buttonbox and recurse on its submenus.
  58.  */
  59. static void btn_MapButtonbox ( buttonbox )
  60.      ButtonBox buttonbox;
  61. {
  62.   int i;
  63.  
  64.   if( buttonbox != NULL ) {
  65.     /* map this button box */
  66.     XMapWindow(buttonbox->display, buttonbox->wndwID);
  67.     /* mount the submenu(s) */
  68.     for( i = 0; i < buttonbox->cosubmenu_count; i++ )
  69.       btn_MapButtonbox(buttonbox->cosubmenu[i]);
  70.     for( i = 0; i < buttonbox->submenu_count; i++ )
  71.       btn_MapButtonbox(buttonbox->submenu[i]);
  72.   }
  73. }
  74.  
  75. /*
  76.  * Subroutine:    btn_UnmapButtonbox
  77.  * Purpose:    Make the buttonbox window vanish
  78.  * Returns:    void
  79.  * Called by:    btn_ReplaceSubmenus(), btn_ReplaceCosubmenus() below
  80.  * Uses:    recursion
  81.  * Xlib calls:    XUnmapWindow
  82.  * Method:    Unmap the buttonbox and recurse on its submenus.
  83.  */
  84. static void btn_UnmapButtonbox ( buttonbox )
  85.      ButtonBox buttonbox;
  86. {
  87.   int i;
  88.  
  89.   if( buttonbox != NULL ) {
  90.     /* unmap this set of buttons */
  91.     XUnmapWindow(buttonbox->display, buttonbox->wndwID);
  92.     /* clear the submenu(s) */
  93.     for( i = 0; i < buttonbox->cosubmenu_count; i++ )
  94.       btn_UnmapButtonbox(buttonbox->cosubmenu[i]);
  95.     for( i = 0; i < buttonbox->submenu_count; i++ )
  96.       btn_UnmapButtonbox(buttonbox->submenu[i]);
  97.   }
  98. }
  99.  
  100. /*
  101.  * Subroutine:    btn_ReplaceSubmenus
  102.  * Purpose:    Change the currently active submenus from those from before to
  103.  *        those of the identified button.
  104.  * Returns:    void
  105.  * Called by:    btn_PushButton() in PushButton.c
  106.  * Uses:    btn_MapButtonbox(), btn_UnmapButtonbox() above.
  107.  * Xlib calls:    none
  108.  * Method:    Unmap the current submenus, link to buttonbox active list and
  109.  *        map submenus of new button.
  110.  * Note:    Unmapping submenus is harmless if they were not mapped.
  111.  */
  112. void btn_ReplaceSubmenus ( buttonbox, btn, op_num, mapping )
  113.      ButtonBox buttonbox;
  114.      int btn;
  115.      int op_num;
  116.      int mapping;        /* i: switch allows suppression of mapping */
  117. {
  118.   int i;
  119.   static void btn_UnmapButtonbox(), btn_MapButtonbox();
  120.  
  121.   /* clear out the old submenus */
  122.   for( i=0; i < buttonbox->submenu_count; i++ )
  123.     btn_UnmapButtonbox(buttonbox->submenu[i]);
  124.   /* install the new submenus */
  125.   for( i=0; i < buttonbox->buttons[btn].submenu_count[op_num]; i++ ) {
  126.     /* put submenus in list of active submenus */
  127.     buttonbox->submenu[i] =
  128.       (ButtonBox)buttonbox->buttons[btn].submenu[op_num][i];
  129.     /* identify master to submenu */
  130.     buttonbox->submenu[i]->parentmenu = buttonbox;
  131.     /* display the new submenus */
  132.     if( mapping )
  133.       btn_MapButtonbox(buttonbox->submenu[i]);
  134.   }
  135.   /* update the count of active submenus */
  136.   buttonbox->submenu_count = buttonbox->buttons[btn].submenu_count[op_num];
  137. }
  138.  
  139. /*
  140.  * Subroutine:    btn_ReplaceCosubmenus
  141.  * Purpose:    Change the currently active cosubmenus from those from before
  142.  *        to those of the identified button.
  143.  * Returns:    void
  144.  * Called by:    btn_PushButton() in PushButton.c
  145.  * Uses:    btn_MapButtonbox(), btn_UnmapButtonbox() above.
  146.  * Xlib calls:    none
  147.  * Method:    Unmap the current cosubmenus, link to buttonbox active list and
  148.  *        map cosubmenus of new button.
  149.  * Note:    Requires search through co-menus
  150.  * Note:    Unmapping cosubmenus is harmless if they were not mapped.
  151.  */
  152. void btn_ReplaceCosubmenus ( buttonbox, btn, op_num, mapping )
  153.      ButtonBox buttonbox;
  154.      int btn;
  155.      int op_num;
  156.      int mapping;        /* i: switch allows suppression of mapping */
  157. {
  158.   int i, j;
  159.   static void btn_UnmapButtonbox(), btn_MapButtonbox();
  160.  
  161.   /* check to see if we have the co-mode submenus */
  162.   if( buttonbox->cosubmenu_count > 0 ) {
  163.     /* clear out the old cosubmenus */
  164.     for( i=0; i < buttonbox->cosubmenu_count; i++ )
  165.       btn_UnmapButtonbox(buttonbox->cosubmenu[i]);
  166.   } else {
  167.     /* clear any co-mode submenus in our co_menus */
  168.     for( j = 0; j < buttonbox->co_menu_count; j++ ) {
  169.       if( buttonbox->co_menu[j]->cosubmenu_count > 0 ) {
  170.     /* clear out the old cosubmenus */
  171.     for( i=0; i < buttonbox->co_menu[j]->cosubmenu_count; i++ )
  172.       btn_UnmapButtonbox(buttonbox->co_menu[j]->cosubmenu[i]);
  173.     buttonbox->co_menu[j]->cosubmenu_count = 0;
  174.       }
  175.     }
  176.   }
  177.   /* install the new cosubmenus */
  178.   for( i=0; i < buttonbox->buttons[btn].submenu_count[op_num]; i++ ) {
  179.     /* put submenus in list of active submenus */
  180.     buttonbox->cosubmenu[i] =
  181.       (ButtonBox)buttonbox->buttons[btn].submenu[op_num][i];
  182.     /* identify master to submenu */
  183.     buttonbox->cosubmenu[i]->parentmenu = buttonbox;
  184.     /* display the new submenus */
  185.     if( mapping )
  186.       btn_MapButtonbox(buttonbox->cosubmenu[i]);
  187.   }
  188.   /* update the count of active submenus */
  189.   buttonbox->cosubmenu_count = buttonbox->buttons[btn].submenu_count[op_num];
  190. }
  191.