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

  1. #ifndef lint
  2. static char SccsId[] = "%W%  %G%";
  3. #endif
  4.  
  5. /*
  6.  * Module:    menuctrl.c (Menu Control)
  7.  * Purpose:    Manipulate the button panel under software control
  8.  * Subroutine:    touch_submenu_button()            returns: void
  9.  * Subroutine:    set_submenu_toggle()            returns: void
  10.  * Subroutine:    enable_annuli_button()            returns: void
  11.  * Subroutine:    enable_ortho_button()            returns: void
  12.  * Subroutine:    init_buttonbox_settings()        returns: void
  13.  * Xlib calls:    none
  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           26 April 1989
  21.  *        {n} <who> -- <does what> -- <when>
  22.  */
  23.  
  24. #include <stdio.h>        /* define stderr, NULL */
  25. #include <X11/Xlib.h>        /* X window stuff */
  26. #include <X11/Xutil.h>        /* X window manager stuff */
  27. #include "btnlib/buttons.h"
  28. #include "hfiles/constant.h"
  29. #include "hfiles/struct.h"    /* declare structure types */
  30. #include "hfiles/extern.h"    /* extern main parameter structures */
  31.  
  32. extern ButtonBox MainPanel[1];
  33. extern ButtonBox ColorPanel[1];
  34. extern ButtonBox CursorPanel[2];
  35. extern ButtonBox ScalePanel[1];
  36. extern ButtonBox PanPanel[1];
  37. extern ButtonBox EtcPanel[1];
  38. extern ButtonBox RegionPanel[1];
  39. extern ButtonBox CmapPanel[1];
  40. extern ButtonBox MonoPanel[1];
  41.  
  42. /*
  43.  * Subroutine:    touch_submenu_button
  44.  * Purpose:    Make the button panel respond (as if the given button had been
  45.  *        clicked by the mouse) to set submenu button to agree with
  46.  *        current internal status
  47.  */
  48. void touch_submenu_button ( mode, action )
  49.      int mode;
  50.      int action;
  51. {
  52.   int button;
  53.   GC set_gc_with_background();
  54.  
  55.   /* set the forground and background for drawing buttons */
  56.   (void)set_gc_with_background(&color.gcset.menu, color.gcset.menu.background);
  57.   switch( mode ) {
  58.   case COP:
  59.     if( (button = ButtonNumber(CursorPanel[0], 1, action)) >= 0 )
  60.       (void)TouchButton(CursorPanel[0], button, 0, 0);
  61.     break;
  62.   case ROP:
  63.     if( (button = ButtonNumber(RegionPanel[0], 1, action)) >= 0 )
  64.       (void)TouchButton(RegionPanel[0], button, 0, 0);
  65.     break;
  66.   case VOP:
  67.     if( (button = ButtonNumber(ColorPanel[0], 1, action)) >= 0 )
  68.       (void)TouchButton(ColorPanel[0], button, 0, 0);
  69.     break;
  70.   case MOP:
  71.     if( (button = ButtonNumber(CmapPanel[0], 1, action)) >= 0 )
  72.       (void)TouchButton(CmapPanel[0], button, 0, 0);
  73.     break;
  74.   case BOP:
  75.     if( (button = ButtonNumber(MonoPanel[0], 1, action)) >= 0 )
  76.       (void)TouchButton(MonoPanel[0], button, 0, 0);
  77.     break;
  78.   case SOP:
  79.     if( (button = ButtonNumber(ScalePanel[0], 1, action)) >= 0 )
  80.       (void)TouchButton(ScalePanel[0], button, 0, 0);
  81.     break;
  82.   case ZOP:
  83.     if( (button = ButtonNumber(PanPanel[0], 1, action)) >= 0 )
  84.       (void)TouchButton(PanPanel[0], button, 0, 0);
  85.     break;
  86.   case EOP:
  87.     if( (button = ButtonNumber(EtcPanel[0], 1, action)) >= 0 )
  88.       (void)TouchButton(EtcPanel[0], button, 0, 0);
  89.     break;
  90.   default:
  91.     break;
  92.   }
  93. }
  94.  
  95. /*
  96.  * Subroutine:    set_submenu_toggle
  97.  * Purpose:    Set submenu toggle button to agree with current status
  98.  */
  99. void set_submenu_toggle ( mode, action, status )
  100.      int mode;
  101.      int action;
  102.      int status;
  103. {
  104.   int button;
  105.   GC set_gc_with_background();
  106.  
  107.   /* set the forground and background for drawing buttons */
  108.   (void)set_gc_with_background(&color.gcset.menu, color.gcset.menu.background);
  109.   switch( mode ) {
  110.   case COP:
  111.     if( (button = ButtonNumber(CursorPanel[0], 1, action)) >= 0 )
  112.       (void)SetToggleButton(CursorPanel[0], button, status);
  113.     break;
  114.   case ROP:
  115.     if( (button = ButtonNumber(RegionPanel[0], 1, action)) >= 0 )
  116.       (void)SetToggleButton(RegionPanel[0], button, status);
  117.     break;
  118.   case VOP:
  119.     if( (button = ButtonNumber(ColorPanel[0], 1, action)) >= 0 )
  120.       (void)SetToggleButton(ColorPanel[0], button, status);
  121.     break;
  122.   case MOP:
  123.     if( (button = ButtonNumber(CmapPanel[0], 1, action)) >= 0 )
  124.       (void)SetToggleButton(CmapPanel[0], button, status);
  125.     break;
  126.   case BOP:
  127.     if( (button = ButtonNumber(MonoPanel[0], 1, action)) >= 0 )
  128.       (void)SetToggleButton(MonoPanel[0], button, status);
  129.     break;
  130.   case SOP:
  131.     if( (button = ButtonNumber(ScalePanel[0], 1, action)) >= 0 )
  132.       (void)SetToggleButton(ScalePanel[0], button, status);
  133.   break;
  134.   case ZOP:
  135.     if( (button = ButtonNumber(PanPanel[0], 1, action)) >= 0 )
  136.       (void)SetToggleButton(PanPanel[0], status, button);
  137.     break;
  138.   case EOP:
  139.     if( (button = ButtonNumber(EtcPanel[0], 1, action)) >= 0 )
  140.       (void)SetToggleButton(EtcPanel[0], button, status);
  141.     break;
  142.   default:
  143.     break;
  144.   }
  145. }
  146.  
  147. /*
  148.  * Subroutine:    enable_annuli_button
  149.  * Purpose:    Enable and disable anuulus button depending on current cursor
  150.  */
  151. void enable_annuli_button ( enable )
  152.      int enable;    /* i: enable vs. disable */
  153. {
  154.   int button;
  155.   static int disabled = 0;
  156.   GC set_gc_with_background();
  157.  
  158.   if( (button = ButtonNumber(CursorPanel[0], 1, COP_Annuli)) >= 0 ) {
  159.     if( enable ) {
  160.       if( disabled ) {
  161.     (void)EnableButton(CursorPanel[0], button, BTNToggle);
  162.     disabled = 0;
  163.       }
  164.     } else {
  165.       if( disabled == 0 ) {
  166.     (void)set_gc_with_background(&color.gcset.menu,
  167.                      color.gcset.menu.background);
  168.     (void)SetToggleButton(CursorPanel[0], button, 0);
  169.     (void)DisableButton(CursorPanel[0], button);
  170.     disabled = 1;
  171.       }
  172.     }
  173.   }
  174. }
  175.  
  176. /*
  177.  * Subroutine:    enable_ortho_button
  178.  * Purpose:    Enable and disable ortho button depending on current cursor
  179.  */
  180. void enable_ortho_button ( enable )
  181.      int enable;    /* i: enable vs. disable */
  182. {
  183.   int button;
  184.   static int disabled = 0;
  185.  
  186.   if( (button = ButtonNumber(CursorPanel[0], 1, COP_Orthogonal)) >= 0 ) {
  187.     if( enable ) {
  188.       if( disabled ) {
  189.     (void)EnableButton(CursorPanel[0], button, BTNFlash);
  190.     disabled = 0;
  191.       }
  192.     } else {
  193.       if( disabled == 0 ) {
  194.     (void)DisableButton(CursorPanel[0], button);
  195.     disabled = 1;
  196.       }
  197.     }
  198.   }
  199. }
  200.  
  201. /*
  202.  * Subroutine:    init_buttonbox_settings
  203.  * Purpose:    Set buttons to states corresponding to initial defaults
  204.  * Note:    region's buttons are set from init_region
  205.  */
  206. void init_buttonbox_settings ( )
  207. {
  208.   int button;
  209.  
  210.   /* cursor */
  211.   touch_submenu_button (COP, cursor.type);
  212.   if( (cursor.type == COP_Polygon) || (cursor.type == COP_Point) ) {
  213.     enable_annuli_button(0);
  214.     enable_ortho_button(0);
  215.   } else if( cursor.annuli ) {
  216.     set_submenu_toggle(COP, COP_Annuli, 1);
  217.     enable_ortho_button(0);
  218.   } else if( cursor.type == COP_Circle )
  219.     enable_ortho_button(0);
  220.   /* color */
  221.   if( color.inverse )
  222.     set_submenu_toggle(VOP, VOP_Invert, 1);
  223.   if( color.halftone.inverse )
  224.     set_submenu_toggle (BOP, BOP_Invert, 1);
  225.   /* set the modes */
  226.   button = ButtonNumber(ColorPanel[0], 1, VOP_Halftone);
  227.   if( ((color.screen_depth <= 1) || (color.colormap_mode == VOP_Halftone)) &&
  228.       (button >= 0) ) {
  229.     /* halftone only?, set mono and then freeze (disable) it */
  230.     (void)SetToggleButton (ColorPanel[0], button, 1);
  231.     (void)DisableButton(ColorPanel[0], button);
  232.   } else {
  233.     /* color possible? set control mode, then set mono if chosen */
  234.     touch_submenu_button(VOP, color.control_mode);
  235.     if( color.cells.overlay )
  236.       set_submenu_toggle(VOP, VOP_Overlay, 1);
  237.   }
  238.   if( color.halftone.mode == BOP_Diffuse ) {
  239.     touch_submenu_button(BOP, BOP_Diffuse);
  240.   } else if( color.halftone.matrixID == BOP_Matrix1 ) {
  241.     touch_submenu_button(BOP, BOP_Matrix1);
  242.   } else if( color.halftone.matrixID == BOP_Matrix2 ) {
  243.     touch_submenu_button(BOP, BOP_Matrix2);
  244.   }
  245.   /* scale */
  246.   touch_submenu_button (SOP, color.scale.mode);
  247.   /* control */
  248.   if( control.magni_track )
  249.     set_submenu_toggle(EOP, EOP_Track, 1);
  250.   if( control.coord_track )
  251.     set_submenu_toggle(EOP, EOP_TextTrack, 1);
  252.   if( control.verbose )
  253.     set_submenu_toggle(EOP, EOP_Verbose, 1);
  254.   /* main menu */
  255.   if( (button = ButtonNumber(MainPanel[0], 0, control.mode)) >= 0 )
  256.     (void)TouchButton(MainPanel[0], button, 0, 0);
  257. }
  258.