home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume8 / xfig2.8 / part17 / panel.c
Encoding:
C/C++ Source or Header  |  1990-07-03  |  37.1 KB  |  1,401 lines

  1. /* 
  2.  *    FIG : Facility for Interactive Generation of figures
  3.  *
  4.  *    panel.c - Button panel
  5.  *
  6.  *    Copyright (c) 1985 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU)
  7.  *    January 1985.
  8.  *    1st revision : Aug 1985.
  9.  *
  10.  *    %W%    %G%
  11. */
  12. #include "fig.h"
  13. #include "resources.h"
  14. #include "const.h"
  15. #include "font.h"
  16. #include "func.h"
  17. #include "object.h"
  18. #include "paintop.h"
  19.  
  20. extern        null_proc();
  21. extern        read_file();
  22. extern        save_file();
  23. extern        edit_file();
  24. extern        change_directory();
  25. extern        print_wdir();
  26. extern        print_figure();
  27. extern    int    line_thickness;
  28. extern    int    cur_radius;
  29. extern    int    cur_areafill;
  30. extern    int    fill_mode;
  31. extern    int    foreground_color;
  32. extern    char    current_file[];
  33. extern    int    print_landscape;
  34. extern    int    size_button;
  35. extern    int    type_button;
  36. extern    char    *printer;
  37. extern    int    cur_printer;
  38. extern    char    *printer_list[];
  39. extern    TOOL    fontmenu;        /* popup menu for printer fonts */
  40. extern    appresStruct    appres;
  41. extern    int    font_button;        /* "current" font */
  42. extern    int    *font_sel;        /* pointer to store font selected from popup */
  43. extern    TOOL    image_widget;        /* which widget to store image of font in */
  44.  
  45. /**************     local variables and routines   **************/
  46.  
  47. #include "panel.h"
  48. #include "panel2.h"
  49. #include "switch.h"
  50.  
  51. static        panel_selected();
  52. static        panel_sighandler();
  53. static        init_switch();
  54. static F_switch    *switch_selected();
  55. static        panel_selected();
  56. static        switch_handler();
  57. static        switch_action();
  58. static        mode_on();
  59. static        mode_off();
  60. static        set_command();
  61. static        set_geometry();
  62. static        set_grid();
  63. static        set_style();
  64. static        dec_thick();
  65. static        inc_thick();
  66. #ifndef TFX
  67. static        dec_radius();
  68. static        inc_radius();
  69. #endif TFX
  70. static        darken_fill();
  71. static        lighten_fill();
  72. extern        turn_off();
  73.  
  74. /* second panel (lower part of window */
  75. static        panel_button();
  76. static        text_just_button();
  77. static        popup_fonts();
  78. static        inc_size_button();
  79. static        dec_size_button();
  80. static        land_button();
  81.  
  82. static    Pixmap    Lp_pm;    /* pixmaps for print-Landscape/Portrait button */
  83. static    Pixmap    lP_pm;
  84. static    Pixmap    print_sel_pm;    /* pixmap for printer selection widget */
  85. static    Pixmap    font_size_pm;    /* pixmap for printer selection widget */
  86. static    Pixmap    text_just_pm[3]; /* pixmaps for left/center/right just widget */
  87. static    Widget    print_sel_widget;
  88. static    Widget    font_size_widget;
  89. static    F_switch *text_just_sw;    /* text justification button */
  90. static    F_switch *land_port_sw;    /* landscape/portrait button */
  91.  
  92. TOOL    ind_box;    /* allow main() to access this widget */
  93.  
  94. #define        on_action(z)    (z->on_func)(z)
  95. #define        off_action(z)    (z->off_func)(z)
  96.  
  97. static F_switch     switches[] = { 
  98.     { 0, 0, 0, 0, &cirrad_ic, F_CIRCLE_BY_RAD, set_command, null_proc, S_ON, },
  99.     { 0, 0, 0, 0, &cirdia_ic, F_CIRCLE_BY_DIA, set_command, null_proc, S_ON, },
  100.     { 0, 0, 0, 0, &ellrad_ic, F_ELLIPSE_BY_RAD, set_command, null_proc, S_ON, },
  101.     { 0, 0, 0, 0, &elldia_ic, F_ELLIPSE_BY_DIA, set_command, null_proc, S_ON, },
  102.     { 0, 0, 0, 0, &c_spl_ic, F_CLOSED_SPLINE, set_command, null_proc, S_ON, },
  103.     { 0, 0, 0, 0, &spl_ic, F_SPLINE, set_command, null_proc, S_ON, },
  104.     { 0, 0, 0, 0, &c_intspl_ic, F_CLOSED_INTSPLINE, set_command, null_proc, S_ON, },
  105.     { 0, 0, 0, 0, &intspl_ic, F_INTSPLINE, set_command, null_proc, S_ON, },
  106.     { 0, 0, 0, 0, &line_ic, F_POLYLINE, set_command, null_proc, S_ON, },
  107.     { 0, 0, 0, 0, &polygon_ic, F_POLYGON, set_command, null_proc, S_ON, },
  108.     { 0, 0, 0, 0, &box_ic, F_BOX, set_command, null_proc, S_ON, },
  109. #ifdef TFX
  110.     /* place holders to keep a multiple of 3 buttons */
  111.     /* TFX does not allow arc_boxes */
  112.     { 0, -1, 0, 0, &blank_ic, F_NOP, null_proc, null_proc, S_MOMENT, },
  113. #else
  114.     { 0, 0, 0, 0, &arc_box_ic, F_ARC_BOX, set_command, null_proc, S_ON, },
  115. #endif
  116.     { 0, 0, 0, 0, &text_ic, F_TEXT, set_command, null_proc, S_ON, },
  117.     { 0, 0, 0, 0, &arc_ic, F_CIRCULAR_ARC, set_command, null_proc, S_ON, },
  118.     { 0, 0, 0, 0, &turn_ic, F_TURN, set_command, null_proc, S_ON, },
  119.     { 0, 0, 0, 0, &glue_ic, F_GLUE, set_command, null_proc, S_ON, },
  120.     { 0, 0, 0, 0, &break_ic, F_BREAK, set_command, null_proc, S_ON, },
  121.     { 0, 0, 0, 0, &scale_ic, F_SCALE, set_command, null_proc, S_ON, },
  122.     { 0, 0, 0, 0, &autoarrow_ic, F_AUTOARROW, set_command, null_proc, S_ON, },
  123.     { 0, 0, 0, 0, &addpt_ic, F_ADD_POINT, set_command, null_proc, S_ON, },
  124.     { 0, 0, 0, 0, &deletept_ic, F_DELETE_POINT, set_command, null_proc, S_ON, },
  125.     { 0, 0, 0, 0, &move_ic, F_MOVE, set_command, null_proc, S_ON, },
  126.     { 0, 0, 0, 0, &movept_ic, F_MOVE_POINT, set_command, null_proc, S_ON, },
  127.     { 0, 0, 0, 0, ©_ic, F_COPY, set_command, null_proc, S_ON, },
  128.     { 0, 0, 0, 0, &remove_ic, F_REMOVE, set_command, null_proc, S_ON, },
  129.     { 0, 0, 0, 0, &flip_x_ic, F_FLIP_XAXIS, set_command, null_proc, S_ON, },
  130.     { 0, 0, 0, 0, &flip_y_ic, F_FLIP_YAXIS, set_command, null_proc, S_ON, },
  131.     { 0, 0, 0, 0, &rot90_ic, F_ROTATE90, set_command, null_proc, S_ON, },
  132.     { 0, 0, 0, 0, &rot270_ic, F_ROTATE270, set_command, null_proc, S_ON, },
  133.         { 0, 0, 0, 0, &change_ic, F_CHANGE, set_command, null_proc, S_ON, },
  134.     { 1, 2, 0, 0, &unconstraint_ic, F_UNCONSTRAINT, set_geometry, null_proc, S_ON, },
  135.     { 0, 2, 0, 0, &latexline_ic, F_LATEX_LINE, set_geometry, null_proc, S_ON, },
  136.     { 0, 2, 0, 0, &latexarrow_ic, F_LATEX_ARROW, set_geometry, null_proc, S_ON, },
  137.     { 0, 2, 0, 0, &mounthattan_ic, F_MOUNTHATTAN, set_geometry, null_proc, S_ON, },
  138.     { 0, 2, 0, 0, &manhattan_ic, F_MANHATTAN, set_geometry, null_proc, S_ON, },
  139.     { 0, 2, 0, 0, &mountain_ic, F_MOUNTAIN, set_geometry, null_proc, S_ON, },
  140.     { 1, 3, 0, 0, &solidline_ic, F_SET_SOLID_LINE, set_style, null_proc, S_ON, },
  141.     { 0, 3, 0, 0, &dashline_ic, F_SET_DASH_LINE, set_style, null_proc, S_ON, },
  142.     { 0, 3, 0, 0, &dottedline_ic, F_SET_DOTTED_LINE, set_style, null_proc, S_ON, },
  143.     { 0, 1, 0, 0, &grid1_ic, F_GRID1, set_grid, set_grid, S_TOG, },
  144.     { 0,-1, 0, 0, &backarrow_ic, F_AUTOB_ARROW, mode_on, mode_off, S_TOG, },
  145.     { 0,-1, 0, 0, &forarrow_ic, F_AUTOF_ARROW, mode_on, mode_off, S_TOG, },
  146.     { 0, 1, 0, 0, &grid2_ic, F_GRID2, set_grid, set_grid, S_TOG, },
  147. #ifdef TFX
  148.     { 0,-1, 0, 0, &fill_ic, F_FILL, mode_on, mode_off, S_TOG, },
  149.     { 1,-1, 0, 0, &magnet_ic, F_MAGNET, mode_on, mode_off, S_TOG, },
  150. #else
  151.     { 1,-1, 0, 0, &magnet_ic, F_MAGNET, mode_on, mode_off, S_TOG, },
  152.     { 0,-1, 0, 0, &fill_ic, F_FILL, mode_on, mode_off, S_TOG, },
  153. #endif
  154.     { 0,-1, 0, 0, &incdec_thick_ic, F_INCDECTHICK, dec_thick, null_proc, S_MOMENT,},
  155. #ifndef TFX
  156.     { 0,-1, 0, 0, &incdec_radius_ic, F_INCDECRADIUS, dec_radius, null_proc, S_MOMENT,},
  157. #endif
  158.     { 0,-1, 0, 0, &fill_color_ic, F_FILLCOLOR, lighten_fill, null_proc, S_MOMENT,},
  159.  
  160.     };
  161.  
  162. #define        N_SWITCHES    (sizeof(switches) / sizeof(F_switch))
  163. #define        NUM_GROUP    4
  164. static F_switch    *group[NUM_GROUP];
  165.  
  166. /* second panel of switches below the lower ruler */
  167. static F_switch        switches2[] = { 
  168.     { 0, -1, 0, 0, &save_n_exit_ic,F_SAVE_N_EXIT,panel_button,null_proc,S_MOMENT,},
  169.     { 0, -1, 0, 0, &quit_ic, F_QUIT, panel_button, null_proc, S_MOMENT, },
  170.     { 0, -1, 0, 0, &save_ic, F_SAVE, panel_button, null_proc, S_MOMENT, },
  171.     { 0, -1, 0, 0, &save_in_ic, F_SAVE_IN, panel_button, null_proc, S_MOMENT, },
  172.     { 0, -1, 0, 0, &read_ic, F_READ, panel_button, null_proc, S_MOMENT, },
  173.     { 0, -1, 0, 0, &edit_ic, F_EDIT, panel_button, null_proc, S_MOMENT, },
  174.     { 0, -1, 0, 0, &cdir_ic, F_CHDIR, panel_button, null_proc, S_MOMENT, },
  175.     { 0, -1, 0, 0, &pdir_ic, F_PWDIR, panel_button, null_proc, S_MOMENT, },
  176.     { 0, -1, 0, 0, &print_ic, F_PRINT, panel_button, null_proc, S_MOMENT, },
  177.     { 0, -1, 0, 0, &print_sel_ic, F_PRINTSEL, panel_button, null_proc, S_MOMENT,},
  178.     { 0, -1, 0, 0, &font_ic, F_FONT, popup_fonts, null_proc, S_MOMENT, },
  179.     { 0, -1, 0, 0, &size_ic, F_SIZE, dec_size_button, null_proc, S_MOMENT, },
  180.     { 0, -1, 0, 0, &textL_ic, F_JUST, text_just_button, null_proc, S_MOMENT, },
  181.     { 0, -1, 0, 0, &land_ic, F_LAND, land_button, null_proc, S_MOMENT, },
  182.     { 0, -1, 0, 0, &undo_ic, F_UNDO, panel_button, null_proc, S_MOMENT, },
  183.     { 0, -1, 0, 0, &redisp_ic, F_REDISPLAY, panel_button, null_proc, S_MOMENT, },
  184.     };
  185.  
  186. #define        N_SWITCHES2    (sizeof(switches2) / sizeof(F_switch))
  187.  
  188. /*
  189.  *    Panel subwindow section
  190.  */
  191.  
  192. static Arg    panel_args[] =
  193. {
  194.     /* 0 */ { XtNwidth, (XtArgVal) 0 },
  195.     /* 1 */ { XtNhSpace, (XtArgVal)SWITCH_ICON_SPACING },
  196.     /* 2 */ { XtNvSpace, (XtArgVal)SWITCH_ICON_SPACING },
  197.     /* Fix the size of the panel window by chaining both top & bottom
  198.        to the top of the form, and both left & right to the right.
  199.        If RHS_PANEL, then chain left/right to RIGHT of form */
  200.     /* 3 */ { XtNtop,    (XtArgVal)XtChainTop  },
  201.     /* 4 */ { XtNbottom, (XtArgVal)XtChainTop  },
  202.     /* 5 */ { XtNleft,   (XtArgVal)XtChainLeft },
  203.     /* 6 */ { XtNright,  (XtArgVal)XtChainLeft },
  204.     /* 7 */ { XtNresizable, (XtArgVal) False },
  205.     /* 8 */ { XtNborderWidth, (XtArgVal) 2 },
  206.     /* 9 */ { XtNvertDistance, (XtArgVal) 0 },    /* touching top of form */
  207. };
  208.  
  209. static Arg    panel2_args[] =
  210. {
  211.     /*  0 */ { XtNwidth, (XtArgVal)0 },
  212.     /*  1 */ { XtNhSpace, (XtArgVal) 1 },
  213.     /*  2 */ { XtNvSpace, (XtArgVal) 1 },
  214.     /*  3 */ { XtNresizable, (XtArgVal) False },
  215.     /*  4 */ { XtNfromVert, (XtArgVal) NULL },    /* will be from psfont */
  216.     /*  5 */ { XtNvertDistance, (XtArgVal) -1 },
  217.     /*  6 */ { XtNhorizDistance, (XtArgVal) 1 },
  218.     /* Fix the size of the panel window by chaining both top & bottom
  219.        to the top of the form, and both left & right to the right */
  220.     /*  7 */ { XtNtop,    (XtArgVal)XtChainBottom },
  221.     /*  8 */ { XtNbottom, (XtArgVal)XtChainBottom },
  222.     /*  9 */ { XtNleft,   (XtArgVal)XtChainLeft   },
  223.     /* 10 */ { XtNright,  (XtArgVal)XtChainLeft   },
  224. };
  225.  
  226. static Arg    ind_box_args[] =
  227. {
  228.     /* 0 */ { XtNwidth, (XtArgVal) 0 },
  229.     /* 1 */ { XtNhSpace, (XtArgVal)SWITCH_ICON_SPACING },
  230.     /* 2 */ { XtNfromVert, (XtArgVal) NULL },    /* will be from panel_sw */
  231.     /* 3 */ { XtNvertDistance, (XtArgVal) 0 },
  232.     /* 4 */ { XtNborderWidth, (XtArgVal) 2 },
  233.     /* Fix the size of the panel window by chaining both top & bottom
  234.        to the top of the form, and both left & right to the right
  235.        If RHS_PANEL, then chain left/right to RIGHT of form */
  236.     /* 5 */ { XtNtop,    (XtArgVal)XtChainTop  },
  237.     /* 6 */ { XtNbottom, (XtArgVal)XtChainTop  },
  238.     /* 7 */ { XtNleft,   (XtArgVal)XtChainLeft },
  239.     /* 8 */ { XtNright,  (XtArgVal)XtChainLeft },
  240. };
  241.  
  242. /* widget arguments to show the current fill color and line thickness*/
  243.  
  244. static Arg    indicator_panel_args[] =
  245. {
  246.     /*  0 */ { XtNlabel, (XtArgVal)"        " },
  247.     /*  1 */ { XtNwidth, (XtArgVal)  SWITCH_ICON_WIDTH },
  248.     /*  2 */ { XtNheight, (XtArgVal) SWITCH_ICON_HEIGHT },
  249.     /*  3 */ { XtNresizable, (XtArgVal) False },
  250.     /*  4 */ { XtNborderWidth, (XtArgVal) 1 },
  251.     /*  5 */ { XtNbackgroundPixmap, (XtArgVal) NULL },
  252. };
  253.  
  254. static void button_select();
  255.  
  256. static Arg    button_args[] =
  257. {
  258.     /* 0 */ { XtNlabel, (XtArgVal)"        " },
  259.     /* 1 */ { XtNwidth, (XtArgVal)  0 },
  260.     /* 2 */ { XtNheight, (XtArgVal) 0 },
  261.     /* 3 */ { XtNbackgroundPixmap, (XtArgVal)NULL },
  262.     /* 4 */ { XtNresizable, (XtArgVal) False },
  263.     /* 5 */ { XtNborderWidth, (XtArgVal) 1 },
  264.     /* 6 */ { XtNresize, (XtArgVal) False },   /* this keeps the damned buttons from
  265.                               being resized when there are not a
  266.                               multiple of three of them */
  267. };
  268.  
  269. extern int    PANEL_LEFT, PANEL_TOP, PANEL_HEIGHT, PANEL_WID;
  270. extern int    PANEL2_LEFT, PANEL2_TOP, PANEL2_HEIGHT, PANEL2_WID;
  271. extern int    CANVAS_HEIGHT, ICON_COLUMN;
  272.  
  273. static right_but();
  274.  
  275. /* button selection event handler */
  276. static sel_but();
  277.  
  278. int 
  279. init_panel(tool)
  280.     TOOL        tool;
  281. {
  282.     register int        i;
  283.     register F_switch    *sw;
  284.  
  285.     /* width */
  286.     panel_args[0].value = PANEL_WID =
  287.         (SWITCH_ICON_WIDTH + 2 + SWITCH_ICON_SPACING) * ICON_COLUMN
  288.         + SWITCH_ICON_SPACING;
  289.     panel_sw = XtCreateWidget("side_panel", boxWidgetClass, tool, 
  290.             panel_args, XtNumber(panel_args));
  291.  
  292.     for (i = 0; i < N_SWITCHES; ++i)
  293.     {
  294.         sw = &switches[i];
  295.         button_args[1].value = sw->icon->width;        /* button width */
  296.         button_args[2].value = sw->icon->height;    /* button height */
  297.         sw->but.widget = XtCreateManagedWidget(
  298.             "button", commandWidgetClass,
  299.             panel_sw, button_args, XtNumber(button_args));
  300.         /* allow left & right buttons (callbacks pass same data for ANY button) */
  301.         XtAddEventHandler(sw->but.widget,ButtonPressMask,(Boolean) 0, 
  302.             sel_but, (caddr_t) sw);
  303.     }
  304.  
  305.     return (1);
  306. }
  307.  
  308. int     /* second panel */
  309. init_panel2(tool)
  310.     TOOL        tool;
  311. {
  312.     register int        i;
  313.     register F_switch    *sw;
  314.  
  315.  
  316.     /* panel width */
  317.     panel2_args[0].value = PANEL2_WID = 2 * N_SWITCHES2 *
  318.             (SWITCH_ICON_WIDTH + SWITCH_ICON_SPACING)
  319.             + SWITCH_ICON_SPACING;
  320.     panel2_args[4].value = (XtArgVal) psfont;  /* vert offset from font window */
  321.  
  322.     panel2_sw = XtCreateWidget("bottom_panel", boxWidgetClass, tool, panel2_args,
  323.         XtNumber(panel2_args));
  324.     for (i = 0; i < N_SWITCHES2; ++i)
  325.     {
  326.         sw = &switches2[i];
  327.         button_args[1].value = sw->icon->width;        /* button width */
  328.         button_args[2].value = sw->icon->height;    /* button height */
  329.         sw->but.widget = XtCreateManagedWidget(
  330.             "button", commandWidgetClass,
  331.             panel2_sw, button_args, XtNumber(button_args));
  332.         /* allow left and right buttons (callbacks pass same data for ANY button) */
  333.         XtAddEventHandler(sw->but.widget,ButtonPressMask,(Boolean) 0, 
  334.             sel_but, (caddr_t) sw);
  335.     }
  336.     return (1);
  337. }
  338.  
  339. #define NUM_IND 3    /* number of indicator widgets */
  340.  
  341. init_indicator_panel(tool)
  342. TOOL tool;
  343.     {
  344.     /* width */
  345.     ind_box_args[0].value = 
  346.         (SWITCH_ICON_WIDTH + 2 + SWITCH_ICON_SPACING)*NUM_IND
  347.             + SWITCH_ICON_SPACING;
  348.  
  349.     /* put below bottom of panel_sw */
  350.     ind_box_args[2].value = (XtArgVal) panel_sw;
  351.  
  352.     ind_box = XtCreateWidget("indicator", boxWidgetClass, tool, ind_box_args,
  353.         XtNumber(ind_box_args));
  354.  
  355.     indicator_panel_args[5].value = (XtArgVal) ind_fill_pm[0];/* white pixmap */
  356.  
  357.     /* line thickness indicator */
  358.     line_thick_panel = XtCreateManagedWidget( "linewidth_indicator", boxWidgetClass,
  359.         ind_box, indicator_panel_args, XtNumber(indicator_panel_args));
  360.  
  361. #ifndef TFX
  362.     /* rounded-corner box radius indicator */
  363.     radius_panel = XtCreateManagedWidget( "radius_indicator", boxWidgetClass,
  364.         ind_box, indicator_panel_args, XtNumber(indicator_panel_args));
  365. #endif TFX
  366.             
  367.     /* fill_area color */
  368.     fill_panel = XtCreateManagedWidget( "fill_indicator", boxWidgetClass,
  369.         ind_box, indicator_panel_args, XtNumber(indicator_panel_args));
  370.     }
  371.  
  372. static GC button_gc;
  373.  
  374. /* come here after panel widget is realized to put some bitmaps etc. things in it */
  375.  
  376. setup_panel()
  377. {
  378.     register int        i;
  379.     register F_switch    *sw;
  380.     register Display    *d = tool_d;
  381.     register Screen        *s = tool_s;
  382.     register Pixmap        p;
  383.     Arg            tmp_arg[3];
  384.     unsigned long        bg, fg;
  385.     
  386.     button_gc = XCreateGC(d, XtWindow(panel_sw), (unsigned long)0, NULL);
  387.     XtSetArg(tmp_arg[0], XtNbackground, &bg);
  388.     XtSetArg(tmp_arg[1], XtNforeground, &fg);
  389.     XtGetValues(switches[0].but.widget, tmp_arg, 2);
  390.     XSetForeground(d, button_gc, fg);
  391.     XSetBackground(d, button_gc, bg);
  392.     XSetFont(d, button_gc, button_font->fid); /* set button font */
  393.  
  394.     for (i = 0; i < N_SWITCHES; ++i)
  395.     {
  396.         sw = &switches[i];
  397.         p = XCreatePixmapFromBitmapData(d, XtWindow(sw->but.widget),
  398.                 sw->icon->data,
  399.                 sw->icon->width, sw->icon->height,fg,bg,
  400.                 DefaultDepthOfScreen(s));
  401.  
  402.         sw->but.normal = button_args[3].value = (XtArgVal)p;
  403.         XtSetValues(sw->but.widget, &button_args[3], 1);
  404.     }
  405. /*
  406. **    Create reversed bitmaps for displaying activated state
  407. */
  408.     for (i = 0; i < N_SWITCHES; ++i)
  409.     {
  410.         sw = &switches[i];
  411.         p = XCreatePixmapFromBitmapData(d, XtWindow(sw->but.widget),
  412.                 sw->icon->data,
  413.                 sw->icon->width, sw->icon->height,bg,fg,
  414.                 DefaultDepthOfScreen(s));
  415.  
  416.         sw->but.reverse = (XtArgVal)p;
  417.     }
  418.  
  419.     /*******************************/
  420.     /* now do the same for panel 2 */
  421.     /*******************************/
  422.  
  423.     for (i = 0; i < N_SWITCHES2; ++i)
  424.     {
  425.         sw = &switches2[i];
  426.         p = XCreatePixmapFromBitmapData(d, XtWindow(sw->but.widget),
  427.                 sw->icon->data,
  428.                 sw->icon->width, sw->icon->height,fg,bg,
  429.                 DefaultDepthOfScreen(s));
  430.         if (sw->value == F_LAND) /* create portrait pixmap for land/portrait button */
  431.             {
  432.             Lp_pm = p;    /* save pointer to default */
  433.             lP_pm = XCreatePixmapFromBitmapData(d, XtWindow(sw->but.widget),
  434.                 port_ic.data,
  435.                 port_ic.width, port_ic.height,fg,bg,
  436.                 DefaultDepthOfScreen(s));
  437.             if (!appres.landscape)    /* use portrait for startup image */
  438.                 p = lP_pm;
  439.             land_port_sw = sw;    /* save pointer to this switch */
  440.             }
  441.         else if (sw->value == F_SIZE) /* save pointer to pixmap/widget for font size */
  442.             {
  443.             font_size_pm = p;
  444.             font_size_widget = sw->but.widget;
  445.             }
  446.         else if (sw->value == F_JUST) /* save ptr to pixmap/widget for text justification */
  447.             {
  448.             text_just_sw = sw;
  449.             /* create the other bitmaps for Center and Right */
  450.             text_just_pm[T_LEFT_JUSTIFIED] = p;    /* left just */
  451.             text_just_pm[T_CENTER_JUSTIFIED] =     /* center just */
  452.                 XCreatePixmapFromBitmapData(d, XtWindow(sw->but.widget),
  453.                     textC_ic.data,
  454.                     textC_ic.width, textC_ic.height,fg,bg,
  455.                     DefaultDepthOfScreen(s));
  456.             text_just_pm[T_RIGHT_JUSTIFIED] =    /* right just */
  457.                 XCreatePixmapFromBitmapData(d, XtWindow(sw->but.widget),
  458.                     textR_ic.data,
  459.                     textR_ic.width, textR_ic.height,fg,bg,
  460.                     DefaultDepthOfScreen(s));
  461.             }
  462.         else if (sw->value == F_PRINTSEL) /* save pointer to pixmap for print sel */
  463.             {
  464.             print_sel_pm = p;
  465.             print_sel_widget=sw->but.widget;
  466.             }
  467.  
  468.         sw->but.normal = button_args[3].value = (XtArgVal)p;
  469.         XtSetValues(sw->but.widget, &button_args[3], 1);
  470.     }
  471. /*
  472. **    Create reversed bitmaps for displaying activated state
  473. */
  474.     for (i = 0; i < N_SWITCHES2; ++i)
  475.     {
  476.         sw = &switches2[i];
  477.         p = XCreatePixmapFromBitmapData(d, XtWindow(sw->but.widget),
  478.                 sw->icon->data,
  479.                 sw->icon->width, sw->icon->height,fg,bg,
  480.                 DefaultDepthOfScreen(s));
  481.         sw->but.reverse = (XtArgVal)p;
  482.     }
  483.  
  484.     init_switch();
  485.     XDefineCursor(d, XtWindow(panel_sw), (Cursor)arrow_cursor.bitmap);
  486.     XDefineCursor(d, XtWindow(panel2_sw), (Cursor)arrow_cursor.bitmap);
  487.  
  488. }
  489.  
  490. /* come here when a button is pressed in either of the panels */
  491.  
  492. static
  493. sel_but(widget, sw, event)
  494. Widget widget;
  495. F_switch *sw;
  496. XButtonEvent *event;
  497.     {
  498.     if (event->button == Button1)        /* left button */
  499.         button_select(widget, sw);
  500.     else if (event->button == Button3)    /* right button */
  501.         right_but(widget, sw);
  502.     }
  503.  
  504. static
  505. right_but(widget, sw)
  506. Widget    widget;
  507. F_switch *sw;
  508.     {
  509.     switch (sw->value)    /* do the opposite of the function declared in the switch */
  510.         {
  511.         case F_INCDECTHICK:
  512.             inc_thick(sw);
  513.             break;
  514.         case F_FILLCOLOR:
  515.             darken_fill(sw);
  516.             break;
  517. #ifndef TFX
  518.         case F_INCDECRADIUS:
  519.             inc_radius(sw);
  520.             break;
  521. #endif
  522.         case F_SIZE:
  523.             inc_size_button(sw);
  524.             break;
  525.         }
  526.     }
  527.  
  528. static void 
  529. button_select(widget, s)
  530.     TOOL        widget;
  531.     F_switch    *s;
  532. {
  533.     switch_action(s);
  534. }
  535.  
  536. static
  537. init_switch()
  538. {
  539.     extern int    manhattan_mode;
  540.     extern int    mountain_mode;
  541.     extern int    autoforwardarrow_mode;
  542.     extern int    autobackwardarrow_mode;
  543.     extern int    latexline_mode;
  544.     extern int    latexarrow_mode;
  545.     extern int    magnet_mode;
  546.     extern int    line_style;
  547.     extern float    cur_styleval;
  548.     extern float    cur_dashlength;
  549.     extern float    cur_dotgap;
  550.     int        i;
  551.     F_switch    *sw;
  552.  
  553.     for (sw = switches, i = 0; i < N_SWITCHES; sw++, i++) {
  554.         sw->x *= SWITCH_ICON_WIDTH;
  555.         sw->y *= SWITCH_ICON_HEIGHT;
  556.         }
  557.     /* don't forget the second panel */
  558.     for (sw = switches2, i = 0; i < N_SWITCHES2; sw++, i++) {
  559.         sw->x *= SWITCH_ICON_WIDTH;
  560.         sw->y *= SWITCH_ICON_HEIGHT;
  561.         }
  562.  
  563.     for (i = 0; i < NUM_GROUP; ) 
  564.         group[i++] = NULL;
  565.  
  566.     for (sw = switches, i = 0; i < N_SWITCHES; sw++, i++) {
  567.         if (sw->on) {
  568.         /* Only the following switch can be preset */
  569.         switch (sw->value) {
  570.             case F_UNCONSTRAINT :
  571.             manhattan_mode = 0;
  572.             mountain_mode = 0;
  573.             latexline_mode = 0;
  574.             latexarrow_mode = 0;
  575.             group[sw->group] = sw;
  576.             break;
  577.             case F_MOUNTHATTAN :
  578.             manhattan_mode = 1;
  579.             mountain_mode = 1;
  580.             group[sw->group] = sw;
  581.             break;
  582.             case F_MANHATTAN :
  583.             manhattan_mode = 1;
  584.             group[sw->group] = sw;
  585.             break;
  586.             case F_MOUNTAIN :
  587.             mountain_mode = 1;
  588.             group[sw->group] = sw;
  589.             break;
  590.             case F_LATEX_LINE :
  591.             latexline_mode = 1;
  592.             group[sw->group] = sw;
  593.             break;
  594.             case F_LATEX_ARROW :
  595.             latexarrow_mode = 1;
  596.             group[sw->group] = sw;
  597.             break;
  598.             case F_AUTOF_ARROW :
  599.             autoforwardarrow_mode = 1;
  600.             break;
  601.             case F_AUTOB_ARROW :
  602.             autobackwardarrow_mode = 1;
  603.             break;
  604.             case F_SET_SOLID_LINE :
  605.             line_style = SOLID_LINE;
  606.             cur_styleval = 0.0;
  607.             break;
  608.             case F_SET_DASH_LINE :
  609.             line_style = DASH_LINE;
  610.             cur_styleval = cur_dashlength;
  611.             break;
  612.             case F_SET_DOTTED_LINE :
  613.             line_style = DOTTED_LINE;
  614.             cur_styleval = cur_dotgap;
  615.             break;
  616.             case F_MAGNET :
  617.             magnet_mode = 1;
  618.             break;
  619.             default :
  620.             continue;
  621.             }
  622.         turn_on(sw);
  623.         if (sw->group != -1) 
  624.             group[sw->group] = sw;
  625.         }
  626.         }
  627.     }
  628.  
  629. static
  630. set_command(sw)
  631. F_switch    *sw;
  632. {
  633.     extern int    cur_command;
  634.     extern int    rotate_angle;
  635.     extern int    flip_axis;
  636.  
  637.     switch (sw->value) {
  638.         case F_CIRCLE_BY_RAD :
  639.         circlebyradius_drawing_selected();
  640.         erase_pointmarker();
  641.         erase_compoundbox();
  642.         put_msg("CIRCLE drawing: specify RADIUS");
  643.         break;
  644.         case F_CIRCLE_BY_DIA :
  645.         circlebydiameter_drawing_selected();
  646.         erase_pointmarker();
  647.         erase_compoundbox();
  648.         put_msg("CIRCLE drawing: specify DIAMETER");
  649.         break;
  650.         case F_ELLIPSE_BY_RAD :
  651.         ellipsebyradius_drawing_selected();
  652.         erase_pointmarker();
  653.         erase_compoundbox();
  654.         put_msg("ELLIPSE drawing: specify RADIUSES");
  655.         break;
  656.         case F_ELLIPSE_BY_DIA :
  657.         ellipsebydiameter_drawing_selected();
  658.         erase_pointmarker();
  659.         erase_compoundbox();
  660.         put_msg("ELLIPSE drawing: specify DIAMETERS");
  661.         break;
  662.         case F_BOX :
  663.         box_drawing_selected();
  664.         erase_pointmarker();
  665.         erase_compoundbox();
  666.         put_msg("Rectangular BOX drawing");
  667.         break;
  668. #ifndef TFX
  669.         case F_ARC_BOX :
  670.         arc_box_drawing_selected();
  671.         erase_pointmarker();
  672.         erase_compoundbox();
  673.         put_msg("Rectangular BOX drawing with ROUNDED CORNERS");
  674.         break;
  675. #endif
  676.         case F_POLYGON :
  677.         line_drawing_selected();
  678.         erase_pointmarker();
  679.         erase_compoundbox();
  680.         put_msg("POLYGON drawing");
  681.         break;
  682.         case F_POLYLINE :
  683.         line_drawing_selected();
  684.         erase_pointmarker();
  685.         erase_compoundbox();
  686.         put_msg("POLYLINE drawing");
  687.         break;
  688.         case F_TEXT :
  689.         text_drawing_selected();
  690.         erase_pointmarker();
  691.         erase_compoundbox();
  692.         put_msg("TEXT input (from keyboard)");
  693.         break;
  694.         case F_CIRCULAR_ARC :
  695.         arc_drawing_selected();
  696.         erase_pointmarker();
  697.         erase_compoundbox();
  698.         put_msg("ARC drawing: specify three points on the arc");
  699.         break;
  700.         case F_SPLINE :
  701.         draw_spline_selected();
  702.         erase_pointmarker();
  703.         erase_compoundbox();
  704.         put_msg("SPLINE drawing: specify control points");
  705.         break;
  706.         case F_CLOSED_SPLINE :
  707.         draw_spline_selected();
  708.         erase_pointmarker();
  709.         erase_compoundbox();
  710.         put_msg("CLOSED SPLINE drawing: specify control points");
  711.         break;
  712.         case F_INTSPLINE :
  713.         draw_intspline_selected();
  714.         erase_pointmarker();
  715.         erase_compoundbox();
  716.         put_msg("INTERPOLATED SPLINE drawing");
  717.         break;
  718.         case F_CLOSED_INTSPLINE :
  719.         draw_intspline_selected();
  720.         erase_pointmarker();
  721.         erase_compoundbox();
  722.         put_msg("CLOSED INTERPOLATED SPLINE drawing");
  723.         break;
  724.         case F_GLUE :
  725.         compound_selected();
  726.         erase_pointmarker();
  727.         show_compoundbox();
  728.         put_msg("GLUE objects into COMPOUND object with bounding box");
  729.         break;
  730.         case F_BREAK :
  731.         break_selected();
  732.         erase_pointmarker();
  733.         show_compoundbox();
  734.         put_msg("BREAK COMPOUND object");
  735.         break;
  736.         case F_SCALE :
  737.         scale_compound_selected();
  738.         erase_pointmarker();
  739.         show_compoundbox();
  740.         put_msg("SCALE COMPOUND object");
  741.         break;
  742.         case F_ADD_POINT :
  743.         point_adding_selected();
  744.         show_pointmarker();
  745.         erase_compoundbox();
  746.         put_msg("ADD POINTs (to POLYLINE, POLYGON, CLOSED-SPLINE and SPLINE)");
  747.         break;
  748.         case F_DELETE_POINT :
  749.         delete_point_selected();
  750.         show_pointmarker();
  751.         erase_compoundbox();
  752.         put_msg("DELETE POINTs (from POLYLINE, POLYGON, CLOSED-SPLINE and SPLINE)");
  753.         break;
  754.         case F_MOVE :
  755.         move_selected();
  756.         show_pointmarker();
  757.         show_compoundbox();
  758.         put_msg("MOVE objects");
  759.         break;
  760.         case F_MOVE_POINT :
  761.         move_point_selected();
  762.         show_pointmarker();
  763.         erase_compoundbox();
  764.         put_msg("MOVE POINTs (of POLYLINE, POLYGON, CLOSED-SPLINE, SPLINE and BOX)");
  765.         break;
  766.         case F_REMOVE :
  767.         remove_selected();
  768.         show_pointmarker();
  769.         show_compoundbox();
  770.         put_msg("REMOVE objects");
  771.         break;
  772.         case F_COPY :
  773.         copy_selected();
  774.         show_pointmarker();
  775.         show_compoundbox();
  776.         put_msg("COPY objects");
  777.         break;
  778.         case F_ROTATE270 :
  779.         rotate_selected();
  780.         show_pointmarker();
  781.         show_compoundbox();
  782.         rotate_angle = 270;
  783.         put_msg("ROTATE objects (middle button) or COPY & ROTATE (left button) -90 degree");
  784.         break;
  785.         case F_ROTATE90 :
  786.         rotate_selected();
  787.         show_pointmarker();
  788.         show_compoundbox();
  789.         rotate_angle = 90;
  790.         put_msg("ROTATE objects (middle button) or COPY & ROTATE (left button) 90 degree");
  791.         break;
  792.         case F_FLIP_XAXIS :
  793.         flip_selected();
  794.         show_pointmarker();
  795.         show_compoundbox();
  796.         flip_axis = 1;
  797.         put_msg("FLIP objects (middle button) or COPY & FLIP (left button) up or down");
  798.         break;
  799.         case F_FLIP_YAXIS :
  800.         flip_selected();
  801.         show_pointmarker();
  802.         show_compoundbox();
  803.         flip_axis = 2;
  804.         put_msg("FLIP objects (middle button) or COPY & FLIP (left button) left or right");
  805.         break;
  806.         case F_TURN :
  807.         turn_selected();
  808.         show_pointmarker();
  809.         erase_compoundbox();
  810.         put_msg("Turn POLYGON (POLYLINE) into CLOSED-SPLINE (SPLINE) or vice versa");
  811.         break;
  812.         case F_AUTOARROW :
  813.         arrow_head_selected();
  814.         show_pointmarker();
  815.         erase_compoundbox();
  816.         put_msg("ADD arrow head (left button); DELETE arrow head (middle button)");
  817.         break;
  818.         case F_CHANGE:
  819.                 change_item_selected();
  820.                 show_pointmarker();
  821.                 show_compoundbox();
  822.                 put_msg("CHANGE OBJECT");
  823.                 break;
  824.  
  825.  
  826.         }
  827.     cur_command = sw->value;
  828.     }
  829.  
  830. static
  831. set_geometry(sw)
  832. F_switch    *sw;
  833. {
  834.     extern int    manhattan_mode;
  835.     extern int    mountain_mode;
  836.     extern int    latexline_mode;
  837.     extern int    latexarrow_mode;
  838.  
  839.     switch (sw->value) {
  840.         case F_UNCONSTRAINT :
  841.         manhattan_mode = 0;
  842.         mountain_mode = 0;
  843.         latexline_mode = 0;
  844.         latexarrow_mode = 0;
  845.         put_msg("UNCONSTRAINT geometry (for POLYLINE and SPLINE)");
  846.         break;
  847.         case F_MOUNTHATTAN :
  848.         mountain_mode = 1;
  849.         manhattan_mode = 1;
  850.         latexline_mode = 0;
  851.         latexarrow_mode = 0;
  852.         put_msg("MOUNT-HATTAN geometry (for POLYLINE and SPLINE)");
  853.         break;
  854.         case F_MANHATTAN :
  855.         manhattan_mode = 1;
  856.         mountain_mode = 0;
  857.         latexline_mode = 0;
  858.         latexarrow_mode = 0;
  859.         put_msg("MANHATTAN geometry (for POLYLINE and SPLINE)");
  860.         break;
  861.         case F_MOUNTAIN :
  862.         mountain_mode = 1;
  863.         manhattan_mode = 0;
  864.         latexline_mode = 0;
  865.         latexarrow_mode = 0;
  866.         put_msg("MOUNTAIN geometry (for POLYLINE and SPLINE)");
  867.         break;
  868.         case F_LATEX_LINE :
  869.         latexline_mode = 1;
  870.         manhattan_mode = 0;
  871.         mountain_mode = 0;
  872.         latexarrow_mode = 0;
  873.         put_msg("LATEX LINE geometry: allow only LaTeX line slopes");
  874.         break;
  875.         case F_LATEX_ARROW :
  876.         latexarrow_mode = 1;
  877.         manhattan_mode = 0;
  878.         mountain_mode = 0;
  879.         latexline_mode = 0;
  880.         put_msg("LATEX ARROW geometry: allow only LaTeX arrow slopes");
  881.         break;
  882.         }
  883.     }
  884.  
  885. static
  886. set_grid(sw)
  887. F_switch    *sw;
  888. {
  889.     setup_grid(sw->value);
  890.     }
  891.  
  892. static
  893. mode_on(sw)
  894. F_switch    *sw;
  895. {
  896.     extern int    autoforwardarrow_mode;
  897.     extern int    autobackwardarrow_mode;
  898.     extern int    magnet_mode;
  899.  
  900.     switch (sw->value) {
  901.         case F_AUTOF_ARROW :
  902.         autoforwardarrow_mode = 1;
  903.         put_msg("AUTO FORWARD ARROW (for ARC, POLYLINE and SPLINE)");
  904.         break;
  905.         case F_AUTOB_ARROW :
  906.         autobackwardarrow_mode = 1;
  907.         put_msg("AUTO BACKWARD ARROW (for ARC, POLYLINE and SPLINE)");
  908.         break;
  909.         case F_MAGNET :
  910.         magnet_mode = 1;
  911.         put_msg("MAGNET: round entered points to the nearest %s increment",
  912.                 (appres.INCHES? "1/16\"": "2 mm"));
  913.         break;
  914.         case F_FILL :
  915.         fill_mode = 1;
  916.         put_fmsg("FILL MODE (gray level = %.2lf)",
  917.              (double)1.0-(cur_areafill-1.0)/(NUMFILLPATS-1.0));
  918.         break;
  919.         }
  920.     }
  921.  
  922. static
  923. mode_off(sw)
  924. F_switch    *sw;
  925. {
  926.     extern int    autoforwardarrow_mode;
  927.     extern int    autobackwardarrow_mode;
  928.     extern int    magnet_mode;
  929.  
  930.     switch (sw->value) {
  931.         case F_AUTOF_ARROW :
  932.         autoforwardarrow_mode = 0;
  933.         break;
  934.         case F_AUTOB_ARROW :
  935.         autobackwardarrow_mode = 0;
  936.         break;
  937.         case F_MAGNET :
  938.         magnet_mode = 0;
  939.         break;
  940.         case F_FILL :
  941.         fill_mode = 0;
  942.         put_msg("NO-FILL MODE");
  943.         break;
  944.         }
  945.     }
  946.  
  947. static
  948. set_style(sw)
  949. F_switch    *sw;
  950. {
  951.     extern int    line_style;
  952.     extern float    cur_styleval;
  953.     extern float    cur_dashlength;
  954.     extern float    cur_dotgap;
  955.  
  956.     switch (sw->value) {
  957.         case F_SET_SOLID_LINE :
  958.         line_style = SOLID_LINE;
  959.         cur_styleval = 0.0;
  960.         put_msg("SOLID LINE STYLE (for BOX, POLYGON and POLYLINE)");
  961.         break;
  962.         case F_SET_DASH_LINE :
  963.         line_style = DASH_LINE;
  964.         cur_styleval = cur_dashlength;
  965.         put_msg("DASH LINE STYLE (for BOX, POLYGON and POLYLINE)");
  966.         break;
  967.         case F_SET_DOTTED_LINE :
  968.         line_style = DOTTED_LINE;
  969.         cur_styleval = cur_dotgap;
  970.         put_msg("DOTTED LINE STYLE (for BOX, POLYGON and POLYLINE)");
  971.         break;
  972.         }
  973.     }
  974.  
  975.  
  976. static
  977. dec_thick(sw)
  978. F_switch *sw;
  979.     {
  980.     if (line_thickness > 0)
  981.         --line_thickness;
  982.     show_line_thickness();
  983.     }
  984.  
  985. #define MAXLINETHICK 200
  986.  
  987. static
  988. inc_thick(sw)
  989. F_switch *sw;
  990.     {
  991.     if (line_thickness < MAXLINETHICK)
  992.         ++line_thickness;
  993.     show_line_thickness();
  994.     }
  995.  
  996. static    Pixmap line_pm=0;
  997.  
  998. show_line_thickness()
  999.     {
  1000.     if (line_pm == 0)
  1001.         line_pm = XCreatePixmap(tool_d, XtWindow(line_thick_panel),
  1002.             SWITCH_ICON_WIDTH, SWITCH_ICON_HEIGHT,
  1003.             DefaultDepthOfScreen(tool_s));
  1004.     /* erase by drawing wide, inverted (white) line */
  1005.     pw_vector(line_pm, 0, SWITCH_ICON_HEIGHT/2,
  1006.         SWITCH_ICON_WIDTH, SWITCH_ICON_HEIGHT/2, ERASE, 
  1007.         SWITCH_ICON_HEIGHT, SOLID_LINE, 0.0);
  1008.     /* draw current line thickness into pixmap */
  1009.     if (line_thickness > 0)        /* don't draw line for zero-thickness */
  1010.         pw_vector(line_pm, 0, SWITCH_ICON_HEIGHT/2, 
  1011.         SWITCH_ICON_WIDTH, SWITCH_ICON_HEIGHT/2, PAINT, 
  1012.         line_thickness, SOLID_LINE, 0.0);
  1013.  
  1014.     /* Fool the toolkit by changing the background pixmap to 0
  1015.        then giving it the modified one again.  Otherwise, it sees
  1016.        that the pixmap ID is not changed and doesn't actually draw
  1017.        it into the widget window */
  1018.     indicator_panel_args[5].value = 0;
  1019.     XtSetValues(line_thick_panel, &indicator_panel_args[5], 1);
  1020.  
  1021.     /* put the pixmap in the widget background */
  1022.     indicator_panel_args[5].value = line_pm;
  1023.     XtSetValues(line_thick_panel, &indicator_panel_args[5], 1);
  1024.     put_msg("LINE Thickness = %d",line_thickness);
  1025.     }
  1026.  
  1027.  
  1028. #ifndef TFX
  1029.  
  1030. static
  1031. dec_radius(sw)
  1032. F_switch *sw;
  1033.     {
  1034.     --cur_radius;
  1035.     show_radius();
  1036.     }
  1037.  
  1038. #define MAXRADIUS 30
  1039.  
  1040. static
  1041. inc_radius(sw)
  1042. F_switch *sw;
  1043.     {
  1044.     ++cur_radius;
  1045.     show_radius();
  1046.     }
  1047.  
  1048. static    Pixmap radius_pm=0;
  1049.  
  1050. show_radius()
  1051.     {
  1052.     if (cur_radius > MAXRADIUS)
  1053.         cur_radius = MAXRADIUS;
  1054.     else if (cur_radius < 3)
  1055.         cur_radius = 3;
  1056.     if (radius_pm == 0)
  1057.         radius_pm = XCreatePixmap(tool_d, XtWindow(radius_panel),
  1058.             SWITCH_ICON_WIDTH, SWITCH_ICON_HEIGHT,
  1059.             DefaultDepthOfScreen(tool_s));
  1060.     /* erase by drawing wide, inverted (white) line */
  1061.     pw_vector(radius_pm, 0, SWITCH_ICON_HEIGHT/2,
  1062.         SWITCH_ICON_WIDTH, SWITCH_ICON_HEIGHT/2, ERASE, 
  1063.         SWITCH_ICON_HEIGHT, SOLID_LINE, 0.0);
  1064.     /* draw current radius into pixmap */
  1065.     curve(radius_pm, 0, cur_radius, cur_radius, 0, 0,
  1066.         cur_radius, cur_radius,
  1067.         1, SWITCH_ICON_HEIGHT-2, foreground_color, 
  1068.         1, SOLID_LINE, 0.0, 0);
  1069.  
  1070.     /* Fool the toolkit by changing the background pixmap to 0
  1071.        then giving it the modified one again.  Otherwise, it sees
  1072.        that the pixmap ID is not changed and doesn't actually draw
  1073.        it into the widget window */
  1074.     indicator_panel_args[5].value = 0;
  1075.     XtSetValues(radius_panel, &indicator_panel_args[5], 1);
  1076.  
  1077.     /* put the pixmap in the widget background */
  1078.     indicator_panel_args[5].value = radius_pm;
  1079.     XtSetValues(radius_panel, &indicator_panel_args[5], 1);
  1080.     put_msg("ROUNDED-CORNER BOX Radius = %d",cur_radius);
  1081.     }
  1082. #endif TFX
  1083.  
  1084. static
  1085. darken_fill(sw)
  1086. F_switch *sw;
  1087.     {
  1088.     if (cur_areafill < NUMFILLPATS)
  1089.         ++cur_areafill;
  1090.     show_fill_color();
  1091.     }
  1092.  
  1093. static
  1094. lighten_fill(sw)
  1095. F_switch *sw;
  1096.     {
  1097.     if (cur_areafill > 1)
  1098.         --cur_areafill;
  1099.     show_fill_color();
  1100.     }
  1101.  
  1102. show_fill_color()
  1103.     {
  1104.     /* put fill pixmap in widget background */
  1105.     indicator_panel_args[5].value = ind_fill_pm[cur_areafill-1]; 
  1106.     XtSetValues(fill_panel, &indicator_panel_args[5], 1);
  1107.     put_fmsg("FILL GRAY = %.2lf", 
  1108.          (double)1.0-(cur_areafill-1.0)/(NUMFILLPATS-1.0));
  1109.     }
  1110.  
  1111. /* Come here when most any lower panel button is pressed */
  1112.  
  1113. static
  1114. panel_button(sw)
  1115. F_switch *sw;
  1116.     {
  1117.     char_handler(CR);        /* finish any text in progress */
  1118.     switch (sw->value) {
  1119.         case F_UNDO : 
  1120.         undo();
  1121.         break;
  1122.         case F_READ :
  1123.         init_msg_receiving(read_file, "Read file : ");
  1124.         break;
  1125.         case F_SAVE :
  1126.         (void)save_current_file();
  1127.         break;
  1128.         case F_SAVE_IN : 
  1129.         if (no_object()) {
  1130.             put_msg("No figure to save; ignored");
  1131.             break;
  1132.             }
  1133.         init_msg_receiving(save_file, "Save in file : ");
  1134.         break;
  1135.         case F_REDISPLAY :
  1136.         redisplay_canvas();
  1137.         break;
  1138.         case F_EDIT :
  1139.         edit();
  1140.         break;
  1141.         case F_PRINT:
  1142.         print_figure();
  1143.         break;
  1144.         case F_PRINTSEL:
  1145.         printer_select();
  1146.         break;
  1147.         case F_CHDIR :
  1148.         init_msg_receiving(change_directory, "Directory : ");
  1149.         break;
  1150.         case F_PWDIR:
  1151.         print_directory();
  1152.         break;
  1153.         case F_SAVE_N_EXIT :
  1154.         save_n_exit();
  1155.         break;
  1156.         case F_QUIT : 
  1157.         quit();
  1158.         break;
  1159.         }
  1160.     }
  1161.  
  1162. printer_select()
  1163.     {
  1164.     if (*printer != '\0')    /* increment printer number if not first time here */
  1165.         {
  1166.         if (++cur_printer >= MAXPRINTERS)
  1167.             cur_printer=0;
  1168.         }
  1169.     printer=printer_list[cur_printer];
  1170.     put_msg("SELECT PRINTER: %s",printer);
  1171.  
  1172.     /* first erase any existing string in pixmap */
  1173.     XDrawImageString(tool_d, print_sel_pm, button_gc, 
  1174.             6, 24, "        ", 8);
  1175.     /* write the printer name in the background pixmap */
  1176.     XDrawImageString(tool_d, print_sel_pm, button_gc, 
  1177.             6, 24, printer, strlen(printer));
  1178.  
  1179.     /* Fool the toolkit by changing the background pixmap to 0
  1180.        then giving it the modified one again.  Otherwise, it sees
  1181.        that the pixmap ID is not changed and doesn't actually draw
  1182.        it into the widget window */
  1183.     button_args[3].value = 0;
  1184.     XtSetValues(print_sel_widget, &button_args[3], 1);
  1185.  
  1186.     /* put the pixmap in the widget background */
  1187.     button_args[3].value = print_sel_pm;
  1188.     XtSetValues(print_sel_widget, &button_args[3], 1);
  1189.     }
  1190.  
  1191. /* popup menu of printer fonts */
  1192.  
  1193. static
  1194. popup_fonts(sw)
  1195. F_switch *sw;
  1196.     {
  1197.     font_sel = &font_button;    /* store selected font number in font_button */
  1198.     image_widget = psfont;        /* and image in this widget */
  1199.     XtPopup(fontmenu,XtGrabNonexclusive);
  1200.     setup_fontmenu_cursor();    /* now define the cursor for the font menu */
  1201.     }
  1202.  
  1203. /* set text justification to left/center or right */
  1204.  
  1205. static
  1206. text_just_button(sw)
  1207. F_switch *sw;
  1208.     {
  1209.     if (++type_button > T_RIGHT_JUSTIFIED)    /* increment to next (L/C/R) */
  1210.         type_button = 0;
  1211.     /* put the pixmap in the widget background */
  1212.     text_just_sw->but.normal = text_just_sw->but.reverse = 
  1213.         button_args[3].value = (XtArgVal) text_just_pm[type_button];
  1214.     XtSetValues(text_just_sw->but.widget, &button_args[3], 1);
  1215.     if (type_button==T_LEFT_JUSTIFIED)
  1216.         put_msg("Left justify text");
  1217.     else if (type_button==T_CENTER_JUSTIFIED)
  1218.         put_msg("Center text");
  1219.     else
  1220.         put_msg("Right justify text");
  1221.     }
  1222.  
  1223. /* increase font size for print */
  1224.  
  1225. static
  1226. inc_size_button(sw)
  1227. F_switch *sw;
  1228.     {
  1229.     if (size_button >= 100)
  1230.         {
  1231.         size_button = (size_button/10) * 10; /* round first */
  1232.         size_button += 10;
  1233.         }
  1234.     else if (size_button >= 50)
  1235.         {
  1236.         size_button = (size_button/5) * 5;
  1237.         size_button += 5;
  1238.         }
  1239.     else if (size_button >= 20)
  1240.         {
  1241.         size_button = (size_button/2) * 2;
  1242.         size_button += 2;
  1243.         }
  1244.     else
  1245.         size_button++;
  1246.     show_fontsize();
  1247.     }
  1248.  
  1249.  
  1250. /* decrease font size for print */
  1251.  
  1252. static
  1253. dec_size_button(sw)
  1254. F_switch *sw;
  1255.     {
  1256.     if (size_button > 100)
  1257.         {
  1258.         size_button = (size_button/10) * 10; /* round first */
  1259.         size_button -= 10;
  1260.         }
  1261.     else if (size_button > 50)
  1262.         {
  1263.         size_button = (size_button/5) * 5;
  1264.         size_button -= 5;
  1265.         }
  1266.     else if (size_button > 20)
  1267.         {
  1268.         size_button = (size_button/2) * 2;
  1269.         size_button -= 2;
  1270.         }
  1271.     else if (size_button > 4)
  1272.         size_button--;
  1273.     show_fontsize();
  1274.     }
  1275.  
  1276. static char tmpsiz[5];
  1277.  
  1278. show_fontsize()
  1279.     {
  1280.     put_msg("Font size %d",size_button);
  1281.     /* write the font size in the background pixmap */
  1282.     tmpsiz[0]=tmpsiz[1]=tmpsiz[2]=tmpsiz[3]=tmpsiz[4]='\0';
  1283.     sprintf(tmpsiz,"%3d",size_button);
  1284.     XDrawImageString(tool_d, font_size_pm, button_gc, 
  1285.             31, 12, tmpsiz, strlen(tmpsiz));
  1286.  
  1287.     /* Fool the toolkit by changing the background pixmap to 0
  1288.        then giving it the modified one again.  Otherwise, it sees
  1289.        that the pixmap ID is not changed and doesn't actually draw
  1290.        it into the widget window */
  1291.     button_args[3].value = 0;
  1292.     XtSetValues(font_size_widget, &button_args[3], 1);
  1293.  
  1294.     /* put the pixmap in the widget background */
  1295.     button_args[3].value = font_size_pm;
  1296.     XtSetValues(font_size_widget, &button_args[3], 1);
  1297.     }
  1298.  
  1299. /* change landscape/portrait flag for print */
  1300.  
  1301. static
  1302. land_button(sw)
  1303. F_switch *sw;
  1304.     {
  1305.     print_landscape = 1-print_landscape;
  1306.     land_port();    /* display new state */
  1307.     }
  1308.  
  1309. /* this is callable from the 'edit' file routine */
  1310.  
  1311. land_port()
  1312.     {
  1313.     land_port_sw->but.normal = land_port_sw->but.reverse = 
  1314.         button_args[3].value = (XtArgVal) (print_landscape? Lp_pm: lP_pm);
  1315.     XtSetValues(land_port_sw->but.widget, &button_args[3], 1);
  1316.     put_msg("Print in %s mode",print_landscape? "LANDSCAPE": "PORTRAIT");
  1317.     }
  1318.  
  1319. /* undo last operation */
  1320.  
  1321. static
  1322. undo_button(sw)
  1323. F_switch *sw;
  1324.     {
  1325.     undo();
  1326.     }
  1327.  
  1328. /* redisplay */
  1329.  
  1330. static
  1331. redisp_button(sw)
  1332. F_switch *sw;
  1333.     {
  1334.     redisplay_canvas();
  1335.     }
  1336.  
  1337. turn_on(s)
  1338.     F_switch    *s;
  1339. {
  1340.     s->on = 1;
  1341.     button_args[3].value = (XtArgVal)s->but.reverse;
  1342.     XtSetValues(s->but.widget, &button_args[3], 1);
  1343. }
  1344.  
  1345. turn_off(s)
  1346.     F_switch    *s;
  1347. {
  1348.     s->on = 0;
  1349.     button_args[3].value = (XtArgVal)s->but.normal;
  1350.     XtSetValues(s->but.widget, &button_args[3], 1);
  1351. }
  1352.  
  1353. static 
  1354. switch_action(sw)
  1355. F_switch    *sw;
  1356. {
  1357.     F_switch    *old;
  1358.  
  1359.     if (sw == NULL) return;
  1360.  
  1361.     if (sw->group == -1) {
  1362.         if (sw->on) {
  1363.         turn_off(sw);
  1364.         off_action(sw);
  1365.         }
  1366.         else {
  1367.         turn_on(sw);
  1368.         on_action(sw);
  1369.         }
  1370.         if (sw->type == S_MOMENT)    /* added B.V.Smith */
  1371.         {
  1372.         turn_off(sw);
  1373.         off_action(sw);
  1374.         }
  1375.         return;
  1376.         }
  1377.  
  1378.     old = group[sw->group];
  1379.     if (old == sw) {
  1380.         if (old->type != S_ON) {
  1381.         turn_off(old);
  1382.         off_action(old);
  1383.         group[old->group] = NULL;
  1384.         }
  1385.         return;
  1386.         }
  1387.     else if (old) {
  1388.         turn_off(old);
  1389.         off_action(old);
  1390.         }
  1391.  
  1392.     turn_on(sw);
  1393.     on_action(sw);
  1394.     group[sw->group] = sw;
  1395.     if (sw->type == S_MOMENT)    /* added B.V.Smith */
  1396.         {
  1397.         turn_off(sw);
  1398.         off_action(sw);
  1399.         }
  1400.     }
  1401.