home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume19 / xfig / part25 / e_edit.c
Encoding:
C/C++ Source or Header  |  1993-05-27  |  63.0 KB  |  2,332 lines

  1. /*
  2.  * FIG : Facility for Interactive Generation of figures
  3.  * Copyright (c) 1985 by Supoj Sutanthavibul
  4.  * Change function implemented by Frank Schmuck (schmuck@svax.cs.cornell.edu)
  5.  * X version by Jon Tombs <jon@uk.ac.oxford.robots>
  6.  *
  7.  * "Permission to use, copy, modify, distribute, and sell this software and its
  8.  * documentation for any purpose is hereby granted without fee, provided that
  9.  * the above copyright notice appear in all copies and that both the copyright
  10.  * notice and this permission notice appear in supporting documentation. 
  11.  * No representations are made about the suitability of this software for 
  12.  * any purpose.  It is provided "as is" without express or implied warranty."
  13.  */
  14.  
  15. #include "fig.h"
  16. #include "figx.h"
  17. #include "resources.h"
  18. #include "mode.h"
  19. #include "object.h"
  20. #include "paintop.h"
  21. #include "u_fonts.h"
  22. #include "u_search.h"
  23. #include "u_list.h"
  24. #include "u_create.h"
  25. #include "w_canvas.h"
  26. #include "w_drawprim.h"
  27. #include "w_icons.h"
  28. #include "w_util.h"
  29. #include "w_mousefun.h"
  30.  
  31. extern char    *panel_get_value();
  32. extern PIX_ROT_FONT lookfont();
  33. Widget        make_popup_menu();
  34. static Widget    make_color_popup_menu();
  35.  
  36. extern Pixmap    psfont_menu_bitmaps[];
  37. extern Pixmap    latexfont_menu_bitmaps[];
  38. extern void    Quit();
  39. extern        fontpane_popup();
  40.  
  41. static void    new_generic_values();
  42. static void    new_arrow_values();
  43. static        generic_window();
  44. static        font_image_panel();
  45. static        color_selection_panel();
  46. static        float_panel();
  47. static        float_label();
  48. static        int_panel();
  49. static        int_label();
  50. static        str_panel();
  51. static        xy_panel();
  52. static        f_pos_panel();
  53. static        get_f_pos();
  54. static        points_panel();
  55. static        get_points();
  56. int        panel_set_value();
  57. static XtCallbackProc done_button(), apply_button(), cancel_button();
  58. static XtCallbackProc toggle_for_arrow(), toggle_back_arrow();
  59. static void    line_style_select();
  60. static void    textjust_select();
  61. static void    fill_style_select();
  62. static void    flip_eps_select();
  63. static void    hidden_text_select();
  64. static void    rigid_text_select();
  65. static void    special_text_select();
  66. static void    color_select();
  67. static void    set_color_name();
  68. static Widget    popup, form;
  69. static Widget    below, beside;
  70.  
  71. #define NUM_IMAGES    16
  72.  
  73. static int    done_line();
  74. static int    done_text();
  75. static int    done_arc();
  76. static int    done_ellipse();
  77. static int    done_spline();
  78. static int    done_compound();
  79.  
  80. static Widget    origsize;
  81. static Widget    shrink, expand;
  82. static Widget    label;
  83. static Widget    thickness_panel;
  84. static Widget    color_panel;
  85. static Widget    depth_panel;
  86. static Widget    angle_panel;
  87. static Widget    textjust_panel;
  88. static Widget    hidden_text_panel;
  89. static Widget    rigid_text_panel;
  90. static Widget    special_text_panel;
  91. static Widget    fill_style_panel;
  92. static Widget    flip_eps_panel;
  93. static Widget    style_val_label;
  94. static Widget    fill_style_label;
  95. static Widget    style_panel;
  96. static Widget    style_val_panel;
  97. static Widget    for_arrow_height,for_arrow_width,for_arrow_thick;
  98. static Widget    back_arrow_height,back_arrow_width,back_arrow_thick;
  99. static Widget    for_thick_label,for_height_label,for_width_label;
  100. static Widget    back_thick_label,back_height_label,back_width_label;
  101. static Widget    for_thick_val,for_height_val,for_width_val;
  102. static Widget    back_thick_val,back_height_val,back_width_val;
  103. static Boolean    for_arrow, back_arrow;
  104.  
  105. static Widget    text_panel;
  106. static Widget    eps_name_panel;
  107. static Widget    x1_panel, y1_panel;
  108. static Widget    x2_panel, y2_panel;
  109. static Widget    x3_panel, y3_panel;
  110. static Widget    hw_ratio_panel;
  111. static Widget    orig_hw_panel;
  112. static Widget    rotn_panel;
  113. static Widget    font_panel;
  114. static Widget    cur_fontsize_panel;
  115. static Widget    fill_flag_panel;
  116. static Widget    radius, num_objects;
  117. static Widget    menu, hidden_text_menu, textjust_menu;
  118. static Widget    special_text_menu, rigid_text_menu;
  119. static Widget    but1;
  120.  
  121. DeclareStaticArgs(12);
  122. static char    buf[64];
  123.  
  124. static Widget    px_panel[MAXNUMPTS];
  125. static Widget    py_panel[MAXNUMPTS];
  126.  
  127. static int    ellipse_flag;
  128. static int    fill_flag;
  129. static int    flip_eps_flag;
  130. static int    (*done_proc) ();
  131. static int    button_result;
  132. static int    textjust;
  133. static Color    color;
  134. static int    hidden_text_flag;
  135. static int    special_text_flag;
  136. static int    rigid_text_flag;
  137. static int    new_ps_font, new_latex_font;
  138. static int    new_psflag;
  139. static int    changed;
  140.  
  141. static String   edit_translations =
  142.     "<Message>WM_PROTOCOLS: DoneEdit()\n";
  143. static void     edit_cancel();
  144. static XtActionsRec     edit_actions[] =
  145. {
  146.     {"DoneEdit", (XtActionProc) edit_cancel},
  147. };
  148.  
  149.  
  150. #define CANCEL        0
  151. #define DONE        1
  152. #define APPLY        2
  153.  
  154. static struct {
  155.     int            thickness;
  156.     Color        color;
  157.     int            depth;
  158.     int            style;
  159.     float        style_val;
  160.     int            pen;
  161.     int            fill_style;
  162.     F_arrow       *for_arrow;
  163.     F_arrow       *back_arrow;
  164. }        generic_vals;
  165.  
  166. #define put_generic_vals(x) \
  167.     generic_vals.thickness    = x->thickness; \
  168.     generic_vals.color    = x->color; \
  169.     generic_vals.depth    = x->depth; \
  170.     generic_vals.style    = x->style; \
  171.     generic_vals.style_val    = x->style_val; \
  172.     generic_vals.pen    = x->pen; \
  173.     generic_vals.fill_style = x->fill_style
  174.  
  175. #define get_generic_vals(x) \
  176.     new_generic_values(); \
  177.     x->thickness    = generic_vals.thickness; \
  178.     x->color    = generic_vals.color; \
  179.     x->depth    = generic_vals.depth; \
  180.     x->style    = generic_vals.style; \
  181.     x->style_val    = generic_vals.style_val; \
  182.     x->pen        = generic_vals.pen; \
  183.     x->fill_style    = generic_vals.fill_style
  184.  
  185. #define put_generic_arrows(x) \
  186.     generic_vals.for_arrow    = x->for_arrow; \
  187.     generic_vals.back_arrow = x->back_arrow
  188.  
  189. #define get_generic_arrows(x) \
  190.     new_arrow_values(); \
  191.     x->for_arrow  = (for_arrow?  generic_vals.for_arrow  : NULL); \
  192.     x->back_arrow = (back_arrow? generic_vals.back_arrow : NULL)
  193.  
  194. int        edit_item();
  195.  
  196. edit_item_selected()
  197. {
  198.     set_mousefun("edit object", "", "");
  199.     canvas_kbd_proc = null_proc;
  200.     canvas_locmove_proc = null_proc;
  201.     init_searchproc_left(edit_item);
  202.     canvas_leftbut_proc = object_search_left;
  203.     canvas_middlebut_proc = null_proc;
  204.     canvas_rightbut_proc = null_proc;
  205.     set_cursor(pick9_cursor);
  206.     reset_action_on();
  207. }
  208.  
  209. edit_item(p, type, x, y)
  210.     char       *p;
  211.     int            type;
  212.     int            x, y;
  213. {
  214.     extern Atom wm_delete_window;
  215.  
  216.     changed = 0;
  217.     switch (type) {
  218.     case O_POLYLINE:
  219.     make_window_line((F_line *) p);
  220.     break;
  221.     case O_TEXT:
  222.     make_window_text((F_text *) p);
  223.     break;
  224.     case O_ELLIPSE:
  225.     make_window_ellipse((F_ellipse *) p);
  226.     break;
  227.     case O_ARC:
  228.     make_window_arc((F_arc *) p);
  229.     break;
  230.     case O_SPLINE:
  231.     make_window_spline((F_spline *) p);
  232.     break;
  233.     case O_COMPOUND:
  234.     make_window_compound((F_compound *) p);
  235.     break;
  236.     }
  237.  
  238.     XtPopup(popup, XtGrabExclusive);
  239.     (void) XSetWMProtocols(XtDisplay(popup), XtWindow(popup),
  240.                  &wm_delete_window, 1);
  241.  
  242. }
  243.  
  244. static void
  245. expand_eps(w, ev)
  246.     Widget        w;
  247.     XButtonEvent   *ev;
  248. {
  249.     struct f_point  p1, p2;
  250.     int            dx, dy, rotation;
  251.     float        ratio;
  252.     register float  orig_ratio = new_l->eps->hw_ratio;
  253.  
  254.     p1.x = atoi(panel_get_value(x1_panel));
  255.     p1.y = atoi(panel_get_value(y1_panel));
  256.     p2.x = atoi(panel_get_value(x2_panel));
  257.     p2.y = atoi(panel_get_value(y2_panel));
  258.     dx = p2.x - p1.x;
  259.     dy = p2.y - p1.y;
  260.     rotation = 0;
  261.     if (dx < 0 && dy < 0)
  262.     rotation = 180;
  263.     else if (dx < 0 && dy >= 0)
  264.     rotation = 270;
  265.     else if (dy < 0 && dx >= 0)
  266.     rotation = 90;
  267.     if (dx == 0 || dy == 0 || orig_ratio == 0.0)
  268.     return;
  269.     if (((rotation == 0 || rotation == 180) && !flip_eps_flag) ||
  270.     (rotation != 0 && rotation != 180 && flip_eps_flag)) {
  271.     ratio = fabs((float) dy / (float) dx);
  272.     if (ratio < orig_ratio)
  273.         p2.y = p1.y + signof(dy) * (int) (fabs((float) dx) * orig_ratio);
  274.     else
  275.         p2.x = p1.x + signof(dx) * (int) (fabs((float) dy) / orig_ratio);
  276.     } else {
  277.     ratio = fabs((float) dx / (float) dy);
  278.     if (ratio < orig_ratio)
  279.         p2.x = p1.x + signof(dx) * (int) (fabs((float) dy) * orig_ratio);
  280.     else
  281.         p2.y = p1.y + signof(dy) * (int) (fabs((float) dx) / orig_ratio);
  282.     }
  283.     sprintf(buf, "%d", p2.x);
  284.     panel_set_value(x2_panel, buf);
  285.     sprintf(buf, "%d", p2.y);
  286.     panel_set_value(y2_panel, buf);
  287.     sprintf(buf, "%1.1f", orig_ratio);
  288.     FirstArg(XtNlabel, buf);
  289.     SetValues(hw_ratio_panel);
  290. }
  291.  
  292. static void
  293. shrink_eps(w, ev)
  294.     Widget        w;
  295.     XButtonEvent   *ev;
  296. {
  297.     struct f_point  p1, p2;
  298.     int            dx, dy, rotation;
  299.     float        ratio;
  300.     register float  orig_ratio = new_l->eps->hw_ratio;
  301.  
  302.     p1.x = atoi(panel_get_value(x1_panel));
  303.     p1.y = atoi(panel_get_value(y1_panel));
  304.     p2.x = atoi(panel_get_value(x2_panel));
  305.     p2.y = atoi(panel_get_value(y2_panel));
  306.     dx = p2.x - p1.x;
  307.     dy = p2.y - p1.y;
  308.     rotation = 0;
  309.     if (dx < 0 && dy < 0)
  310.     rotation = 180;
  311.     else if (dx < 0 && dy >= 0)
  312.     rotation = 270;
  313.     else if (dy < 0 && dx >= 0)
  314.     rotation = 90;
  315.     if (dx == 0 || dy == 0 || orig_ratio == 0.0)
  316.     return;
  317.     if (((rotation == 0 || rotation == 180) && !flip_eps_flag) ||
  318.     (rotation != 0 && rotation != 180 && flip_eps_flag)) {
  319.     ratio = fabs((float) dy / (float) dx);
  320.     if (ratio > orig_ratio)
  321.         p2.y = p1.y + signof(dy) * (int) (fabs((float) dx) * orig_ratio);
  322.     else
  323.         p2.x = p1.x + signof(dx) * (int) (fabs((float) dy) / orig_ratio);
  324.     } else {
  325.     ratio = fabs((float) dx / (float) dy);
  326.     if (ratio > orig_ratio)
  327.         p2.x = p1.x + signof(dx) * (int) (fabs((float) dy) * orig_ratio);
  328.     else
  329.         p2.y = p1.y + signof(dy) * (int) (fabs((float) dx) / orig_ratio);
  330.     }
  331.     sprintf(buf, "%d", p2.x);
  332.     panel_set_value(x2_panel, buf);
  333.     sprintf(buf, "%d", p2.y);
  334.     panel_set_value(y2_panel, buf);
  335.     sprintf(buf, "%1.1f", orig_ratio);
  336.     FirstArg(XtNlabel, buf);
  337.     SetValues(hw_ratio_panel);
  338. }
  339.  
  340. static void
  341. origsize_eps(w, ev)
  342.     Widget        w;
  343.     XButtonEvent   *ev;
  344. {
  345.     struct f_point  p1, p2;
  346.     int            dx, dy, rotation;
  347.     float        ratio;
  348.     register float  orig_ratio = new_l->eps->hw_ratio;
  349.  
  350.     p1.x = atoi(panel_get_value(x1_panel));
  351.     p1.y = atoi(panel_get_value(y1_panel));
  352.     p2.x = atoi(panel_get_value(x2_panel));
  353.     p2.y = atoi(panel_get_value(y2_panel));
  354.     dx = p2.x - p1.x;
  355.     dy = p2.y - p1.y;
  356.  
  357.     if (dx == 0 || dy == 0 || orig_ratio == 0.0)
  358.     return;
  359.  
  360.     p2.x = p1.x + signof(dx) * new_l->eps->size_x;
  361.     p2.y = p1.y + signof(dy) * new_l->eps->size_y;
  362.     sprintf(buf, "%d", p2.x);
  363.     panel_set_value(x2_panel, buf);
  364.     sprintf(buf, "%d", p2.y);
  365.     panel_set_value(y2_panel, buf);
  366.     sprintf(buf, "%1.1f", orig_ratio);
  367.     FirstArg(XtNlabel, buf);
  368.     SetValues(hw_ratio_panel);
  369. }
  370.  
  371.  
  372. static char    *flip_eps_items[] = {"Normal            ",
  373. "Flipped about diag"};
  374.  
  375. make_window_compound(c)
  376.     F_compound       *c;
  377. {
  378.     set_temp_cursor(panel_cursor);
  379.     mask_toggle_compoundmarker(c);
  380.     new_c = copy_compound(c);
  381.     new_c->next = c;
  382.     generic_window("COMPOUND", "", &glue_ic, done_compound, 0, 0);
  383.     f_pos_panel(&c->nwcorner, "Top Left Corner:", &x1_panel, &y1_panel);
  384.     f_pos_panel(&c->secorner, "Bottom Right Corner:", &x2_panel, &y2_panel);
  385.     int_label(object_count(c), "Num Objects: ", &num_objects);
  386. }
  387.  
  388. static
  389. get_new_compound_values()
  390. {
  391.     int            dx, dy, nw_x, nw_y, se_x, se_y;
  392.     float        scalex, scaley;
  393.  
  394.     nw_x = atoi(panel_get_value(x1_panel));
  395.     nw_y = atoi(panel_get_value(y1_panel));
  396.     se_x = atoi(panel_get_value(x2_panel));
  397.     se_y = atoi(panel_get_value(y2_panel));
  398.     dx = nw_x - new_c->nwcorner.x;
  399.     dy = nw_y - new_c->nwcorner.y;
  400.     scalex = (float) (nw_x - se_x) /
  401.     (float) (new_c->nwcorner.x - new_c->secorner.x);
  402.     scaley = (float) (nw_y - se_y) /
  403.     (float) (new_c->nwcorner.y - new_c->secorner.y);
  404.  
  405.     translate_compound(new_c, dx, dy);
  406.     scale_compound(new_c, scalex, scaley, nw_x, nw_y);
  407.  
  408.     sprintf(buf, "%d", new_c->nwcorner.x);
  409.     panel_set_value(x1_panel, buf);
  410.     sprintf(buf, "%d", new_c->nwcorner.y);
  411.     panel_set_value(y1_panel, buf);
  412.     sprintf(buf, "%d", new_c->secorner.x);
  413.     panel_set_value(x2_panel, buf);
  414.     sprintf(buf, "%d", new_c->secorner.y);
  415.     panel_set_value(y2_panel, buf);
  416. }
  417.  
  418. static
  419. done_compound()
  420. {
  421.     old_c = new_c->next;
  422.     switch (button_result) {
  423.     case APPLY:
  424.     draw_compoundelements(new_c, ERASE);
  425.     changed = 1;
  426.     get_new_compound_values();
  427.     draw_compoundelements(new_c, PAINT);
  428.     break;
  429.     case DONE:
  430.     draw_compoundelements(new_c, ERASE);
  431.     get_new_compound_values();
  432.     new_c->next = NULL;
  433.     change_compound(old_c, new_c);
  434.     draw_compoundelements(new_c, PAINT);
  435.     toggle_compoundmarker(new_c);
  436.     reset_cursor();
  437.     break;
  438.     case CANCEL:
  439.     if (changed) {
  440.         draw_compoundelements(new_c, ERASE);
  441.         draw_compoundelements(old_c, PAINT);
  442.     }
  443.     new_c->next = NULL;
  444.     free_compound(&new_c);
  445.     toggle_compoundmarker(old_c);
  446.     new_c = old_c;
  447.     reset_cursor();
  448.     break;
  449.     }
  450. }
  451.  
  452. make_window_line(l)
  453.     F_line       *l;
  454. {
  455.     struct f_point  p1, p2;
  456.     int            dx, dy, rotation;
  457.     float        ratio;
  458.  
  459.     set_temp_cursor(panel_cursor);
  460.     mask_toggle_linemarker(l);
  461.     new_l = copy_line(l);
  462.     new_l->next = l;
  463.     put_generic_vals(new_l);
  464.     color = new_l->color;
  465.     switch (new_l->type) {
  466.     case T_POLYLINE:
  467.     put_generic_arrows(new_l);
  468.     generic_window("POLYLINE", "Polyline", &line_ic, done_line, 1, 1);
  469.     points_panel(new_l->points, 0);
  470.     break;
  471.     case T_POLYGON:
  472.     generic_window("POLYLINE", "Polygon", &polygon_ic, done_line, 1, 0);
  473.     points_panel(new_l->points, 1);
  474.     break;
  475.     case T_BOX:
  476.     generic_window("POLYLINE", "Box", &box_ic, done_line, 1, 0);
  477.     p1 = *new_l->points;
  478.     p2 = *new_l->points->next->next;
  479.     xy_panel(p1.x, p1.y, "First Corner:", &x1_panel, &y1_panel);
  480.     xy_panel(p2.x, p2.y, "Opposite Corner:", &x2_panel, &y2_panel);
  481.     break;
  482.     case T_ARC_BOX:
  483.     generic_window("POLYLINE", "ArcBox", &arc_box_ic, done_line, 1, 0);
  484.     p1 = *new_l->points;
  485.     p2 = *new_l->points->next->next;
  486.     xy_panel(p1.x, p1.y, "First Corner:", &x1_panel, &y1_panel);
  487.     xy_panel(p2.x, p2.y, "Opposite Corner:", &x2_panel, &y2_panel);
  488.     int_panel(new_l->radius, form, "Radius =", &radius);
  489.     break;
  490.     case T_EPS_BOX:
  491.     generic_window("POLYLINE", "EPS", &epsobj_ic, done_line, 0, 0);
  492.     int_panel(new_l->depth, form, "Depth =", &depth_panel);
  493.     if (!strcmp(new_l->eps->file, EMPTY_EPS))
  494.         new_l->eps->file[0] = '\0';
  495.     str_panel(new_l->eps->file, "EPS Filename =", &eps_name_panel);
  496.     p1 = *new_l->points;
  497.     p2 = *new_l->points->next->next;
  498.     xy_panel(p1.x, p1.y, "First Corner:", &x1_panel, &y1_panel);
  499.     xy_panel(p2.x, p2.y, "Opposite corner:", &x2_panel, &y2_panel);
  500.  
  501.     /* make popup flipped menu */
  502.     FirstArg(XtNfromVert, below);
  503.     NextArg(XtNborderWidth, 0);
  504.     beside = XtCreateManagedWidget("Orientation =", labelWidgetClass,
  505.                        form, Args, ArgCount);
  506.     FirstArg(XtNfromVert, below);
  507.     NextArg(XtNfromHoriz, beside);
  508.     flip_eps_flag = new_l->eps->flipped;
  509.     flip_eps_panel = XtCreateManagedWidget(
  510.            flip_eps_items[flip_eps_flag ? 1 : 0], menuButtonWidgetClass,
  511.                            form, Args, ArgCount);
  512.     below = flip_eps_panel;
  513.     menu = make_popup_menu(flip_eps_items, XtNumber(flip_eps_items),
  514.                    flip_eps_panel, flip_eps_select);
  515.  
  516.     dx = p2.x - p1.x;
  517.     dy = p2.y - p1.y;
  518.     rotation = 0;
  519.     if (dx < 0 && dy < 0)
  520.         rotation = 180;
  521.     else if (dx < 0 && dy >= 0)
  522.         rotation = 270;
  523.     else if (dy < 0 && dx >= 0)
  524.         rotation = 90;
  525.     if (dx == 0 || dy == 0)
  526.         ratio = 0.0;
  527.     else if (((rotation == 0 || rotation == 180) && !flip_eps_flag) ||
  528.          (rotation != 0 && rotation != 180 && flip_eps_flag))
  529.         ratio = fabs((float) dy / (float) dx);
  530.     else
  531.         ratio = fabs((float) dx / (float) dy);
  532.  
  533.     int_label(rotation, "Rotation =       ", &rotn_panel);
  534.     float_label(ratio, "Curr h/w Ratio =", &hw_ratio_panel);
  535.     float_label(new_l->eps->hw_ratio, "Orig h/w Ratio =", &orig_hw_panel);
  536.     below = orig_hw_panel;
  537.     FirstArg(XtNfromVert, below);
  538.     NextArg(XtNborderWidth, 0);
  539.     beside = XtCreateManagedWidget("Change h/w ratio", labelWidgetClass,
  540.                        form, Args, ArgCount);
  541.     FirstArg(XtNfromVert, below);
  542.     NextArg(XtNsensitive, new_l->eps->hw_ratio ? True : False);
  543.     NextArg(XtNfromHoriz, beside);
  544.     shrink = XtCreateManagedWidget("Shrink to orig", commandWidgetClass,
  545.                        form, Args, ArgCount);
  546.     XtAddEventHandler(shrink, ButtonReleaseMask, (Boolean) 0,
  547.               (XtEventHandler)shrink_eps, (XtPointer) NULL);
  548.     beside = shrink;
  549.  
  550.     ArgCount--;
  551.     NextArg(XtNfromHoriz, beside);
  552.     expand = XtCreateManagedWidget("Expand to orig", commandWidgetClass,
  553.                        form, Args, ArgCount);
  554.     XtAddEventHandler(expand, ButtonReleaseMask, (Boolean) 0,
  555.               (XtEventHandler)expand_eps, (XtPointer) NULL);
  556.  
  557.     below = expand;
  558.     FirstArg(XtNfromVert, below);
  559.     NextArg(XtNsensitive, new_l->eps->hw_ratio ? True : False);
  560.     origsize = XtCreateManagedWidget("Use orig. size",
  561.                      commandWidgetClass, form, Args,
  562.                      ArgCount);
  563.     XtAddEventHandler(origsize, ButtonReleaseMask, (Boolean) 0,
  564.               (XtEventHandler)origsize_eps, (XtPointer) NULL);
  565.     break;
  566.     }
  567. }
  568.  
  569. static
  570. get_new_line_values()
  571. {
  572.     struct f_point  p1, p2, *p;
  573.     char       *s;
  574.     int            dx, dy, rotation;
  575.     float        ratio;
  576.  
  577.     switch (new_l->type) {
  578.     case T_POLYLINE:
  579.     get_generic_vals(new_l);
  580.     get_generic_arrows(new_l);
  581.     get_points(new_l->points, False);
  582.     return;
  583.     case T_POLYGON:
  584.     get_generic_vals(new_l);
  585.     get_points(new_l->points, True);
  586.     return;
  587.     case T_ARC_BOX:
  588.     new_l->radius = atoi(panel_get_value(radius));
  589.     case T_BOX:
  590.     get_generic_vals(new_l);
  591.     p1.x = atoi(panel_get_value(x1_panel));
  592.     p1.y = atoi(panel_get_value(y1_panel));
  593.     p2.x = atoi(panel_get_value(x2_panel));
  594.     p2.y = atoi(panel_get_value(y2_panel));
  595.     break;
  596.     case T_EPS_BOX:
  597.     new_l->color = color;
  598.     new_l->depth = atoi(panel_get_value(depth_panel));
  599.     p1.x = atoi(panel_get_value(x1_panel));
  600.     p1.y = atoi(panel_get_value(y1_panel));
  601.     p2.x = atoi(panel_get_value(x2_panel));
  602.     p2.y = atoi(panel_get_value(y2_panel));
  603.  
  604.     dx = p2.x - p1.x;
  605.     dy = p2.y - p1.y;
  606.     rotation = 0;
  607.     if (dx < 0 && dy < 0)
  608.         rotation = 180;
  609.     else if (dx < 0 && dy >= 0)
  610.         rotation = 270;
  611.     else if (dy < 0 && dx >= 0)
  612.         rotation = 90;
  613.     if (dx == 0 || dy == 0)
  614.         ratio = 0.0;
  615.     else if (((rotation == 0 || rotation == 180) && !flip_eps_flag) ||
  616.          (rotation != 0 && rotation != 180 && flip_eps_flag))
  617.         ratio = fabs((float) dy / (float) dx);
  618.     else
  619.         ratio = fabs((float) dx / (float) dy);
  620.  
  621.     sprintf(buf, "%d", rotation);
  622.     FirstArg(XtNlabel, buf);
  623.     SetValues(rotn_panel);
  624.     new_l->eps->flipped = flip_eps_flag;
  625.     sprintf(buf, "%1.1f", ratio);
  626.     FirstArg(XtNlabel, buf);
  627.     SetValues(hw_ratio_panel);
  628.     s = panel_get_value(eps_name_panel);
  629.     if (s[0] == '\0')
  630.         s = EMPTY_EPS;
  631.     if (strcmp(s, new_l->eps->file)) {
  632.         if (new_l->eps->bitmap) {
  633.         free((char *) new_l->eps->bitmap);
  634.         new_l->eps->bitmap = NULL;
  635.         }
  636.         strcpy(new_l->eps->file, s);
  637.         new_l->eps->hw_ratio = 0.0;
  638.         if (strcmp(new_l->eps->file, EMPTY_EPS))
  639.         read_epsf(new_l->eps);
  640.     }
  641.     sprintf(buf, "%1.1f", new_l->eps->hw_ratio);
  642.     FirstArg(XtNlabel, buf);
  643.     SetValues(orig_hw_panel);
  644.     FirstArg(XtNsensitive, new_l->eps->hw_ratio ? True : False);
  645.     SetValues(shrink);
  646.     SetValues(expand);
  647.     SetValues(origsize);
  648.     break;
  649.     }
  650.     p = new_l->points;
  651.     p->x = p1.x;
  652.     p->y = p1.y;
  653.     p = p->next;
  654.     p->x = p2.x;
  655.     p->y = p1.y;
  656.     p = p->next;
  657.     p->x = p2.x;
  658.     p->y = p2.y;
  659.     p = p->next;
  660.     p->x = p1.x;
  661.     p->y = p2.y;
  662.     p = p->next;
  663.     p->x = p1.x;
  664.     p->y = p1.y;
  665. }
  666.  
  667. static
  668. done_line()
  669. {
  670.     old_l = new_l->next;
  671.     switch (button_result) {
  672.     case APPLY:
  673.     changed = 1;
  674.     draw_line(new_l, ERASE);
  675.     get_new_line_values();
  676.     draw_line(new_l, PAINT);
  677.     break;
  678.     case DONE:
  679.     get_new_line_values();
  680.     new_l->next = NULL;
  681.     change_line(old_l, new_l);
  682.     redisplay_lines(old_l, new_l);
  683.     reset_cursor();
  684.     break;
  685.     case CANCEL:
  686.     if (changed)
  687.         redisplay_lines(old_l, new_l);
  688.     else
  689.         mask_toggle_linemarker(old_l);
  690.     new_l->next = NULL;
  691.     free_line(&new_l);
  692.     reset_cursor();
  693.     break;
  694.     }
  695.  
  696. }
  697.  
  698. make_window_text(t)
  699.     F_text       *t;
  700. {
  701.     static char       *textjust_items[] = {
  702.     "Left Justified ", "Centered       ", "Right Justified"};
  703.     static char       *hidden_text_items[] = {
  704.     "Normal ", "Hidden "};
  705.     static char       *rigid_text_items[] = {
  706.     "Normal ", "Rigid  "};
  707.     static char       *special_text_items[] = {
  708.     "Normal ", "Special"};
  709.  
  710.     set_temp_cursor(panel_cursor);
  711.     toggle_textmarker(t);
  712.     new_t = copy_text(t);
  713.     new_t->next = t;
  714.  
  715.     textjust = new_t->type;    /* get current justification */
  716.     hidden_text_flag = hidden_text(new_t) ? 1 : 0;
  717.     new_psflag = psfont_text(new_t) ? 1 : 0;
  718.     rigid_text_flag = rigid_text(new_t) ? 1 : 0;
  719.     special_text_flag = special_text(new_t) ? 1 : 0;
  720.     new_ps_font = cur_ps_font;
  721.     new_latex_font = cur_latex_font;
  722.     generic_vals.color = new_t->color;
  723.  
  724.     color = new_t->color;
  725.     if (new_psflag)
  726.     new_ps_font = new_t->font;    /* get current font */
  727.     else
  728.     new_latex_font = new_t->font;    /* get current font */
  729.     generic_window("TEXT", "", &text_ic, done_text, 0, 0);
  730.  
  731.     int_panel(new_t->size, form, "Size  =", &cur_fontsize_panel);
  732.     color_selection_panel();
  733.     int_panel(new_t->depth, form, "Depth =", &depth_panel);
  734.     int_panel(round(180 / M_PI * new_t->angle), form, "Angle (degrees) =",
  735.           &angle_panel);
  736.  
  737.     /* make text justification menu */
  738.  
  739.     FirstArg(XtNfromVert, below);
  740.     NextArg(XtNborderWidth, 0);
  741.     beside = XtCreateManagedWidget("Justification   =", labelWidgetClass,
  742.                    form, Args, ArgCount);
  743.  
  744.     FirstArg(XtNlabel, textjust_items[textjust]);
  745.     NextArg(XtNfromVert, below);
  746.     NextArg(XtNfromHoriz, beside);
  747.     textjust_panel = XtCreateManagedWidget(
  748.                 "justify", menuButtonWidgetClass,
  749.                        form, Args, ArgCount);
  750.     below = textjust_panel;
  751.     textjust_menu = make_popup_menu(textjust_items, XtNumber(textjust_items),
  752.                     textjust_panel, textjust_select);
  753.  
  754.     /* make hidden text menu */
  755.  
  756.     FirstArg(XtNfromVert, below);
  757.     NextArg(XtNborderWidth, 0);
  758.     beside = XtCreateManagedWidget("Hidden Flag     =", labelWidgetClass,
  759.                    form, Args, ArgCount);
  760.  
  761.     FirstArg(XtNfromVert, below);
  762.     NextArg(XtNfromHoriz, beside);
  763.     hidden_text_panel = XtCreateManagedWidget(
  764.          hidden_text_items[hidden_text_flag], menuButtonWidgetClass,
  765.                           form, Args, ArgCount);
  766.     below = hidden_text_panel;
  767.     hidden_text_menu = make_popup_menu(hidden_text_items,
  768.                        XtNumber(hidden_text_items),
  769.                      hidden_text_panel, hidden_text_select);
  770.  
  771.     /* make rigid text menu */
  772.  
  773.     FirstArg(XtNfromVert, below);
  774.     NextArg(XtNborderWidth, 0);
  775.     beside = XtCreateManagedWidget("Rigid Flag      =", labelWidgetClass,
  776.                    form, Args, ArgCount);
  777.  
  778.     FirstArg(XtNfromVert, below);
  779.     NextArg(XtNfromHoriz, beside);
  780.     rigid_text_panel = XtCreateManagedWidget(
  781.            rigid_text_items[rigid_text_flag], menuButtonWidgetClass,
  782.                          form, Args, ArgCount);
  783.     below = rigid_text_panel;
  784.     rigid_text_menu = make_popup_menu(rigid_text_items,
  785.                       XtNumber(rigid_text_items),
  786.                       rigid_text_panel, rigid_text_select);
  787.  
  788.     /* make special text menu */
  789.  
  790.     FirstArg(XtNfromVert, below);
  791.     NextArg(XtNborderWidth, 0);
  792.     beside = XtCreateManagedWidget("Special Flag    =", labelWidgetClass,
  793.                    form, Args, ArgCount);
  794.  
  795.     FirstArg(XtNfromVert, below);
  796.     NextArg(XtNfromHoriz, beside);
  797.     special_text_panel = XtCreateManagedWidget(
  798.                       special_text_items[special_text_flag],
  799.                    menuButtonWidgetClass, form, Args, ArgCount);
  800.     below = special_text_panel;
  801.     special_text_menu = make_popup_menu(special_text_items,
  802.                     XtNumber(special_text_items),
  803.                    special_text_panel, special_text_select);
  804.  
  805.     xy_panel(new_t->base_x, new_t->base_y, "Origin:", &x1_panel, &y1_panel);
  806.     font_image_panel(new_psflag ? psfont_menu_bitmaps[new_t->font + 1] :
  807.          latexfont_menu_bitmaps[new_t->font], "Font:", &font_panel);
  808.     str_panel(new_t->cstring, "Text:", &text_panel);
  809. }
  810.  
  811. static
  812. get_new_text_values()
  813. {
  814.     char       *s;
  815.     PR_SIZE        size;
  816.  
  817.     new_t->type = textjust;
  818.     new_t->flags =
  819.     (rigid_text_flag ? RIGID_TEXT : 0)
  820.     | (special_text_flag ? SPECIAL_TEXT : 0)
  821.     | (hidden_text_flag ? HIDDEN_TEXT : 0)
  822.     | (new_psflag ? PSFONT_TEXT : 0);
  823.     if (psfont_text(new_t))
  824.     new_t->font = new_ps_font;
  825.     else
  826.     new_t->font = new_latex_font;
  827.     new_t->size = atoi(panel_get_value(cur_fontsize_panel));
  828.     if (new_t->size < 1) {
  829.     new_t->size = 1;
  830.     panel_set_value(cur_fontsize_panel, "1");
  831.     }
  832.     new_t->color = color;
  833.     new_t->depth = atoi(panel_get_value(depth_panel));
  834.     new_t->angle = M_PI / 180 * atoi(panel_get_value(angle_panel));
  835.     new_t->base_x = atoi(panel_get_value(x1_panel));
  836.     new_t->base_y = atoi(panel_get_value(y1_panel));
  837.     if (new_t->cstring)
  838.     free(new_t->cstring);
  839.     s = panel_get_value(text_panel);
  840.     new_t->cstring = new_string(strlen(s) + 1);
  841.     strcpy(new_t->cstring, s);
  842.     canvas_font = lookfont(x_fontnum(new_t->flags, new_t->font), 
  843.             new_t->size, new_t->angle*180.0/M_PI);
  844.     new_t->fontstruct = canvas_font;
  845.     size = pf_textwidth(canvas_font, strlen(s), s);
  846.     new_t->height = size.y;
  847.     new_t->length = size.x;
  848. }
  849.  
  850. static
  851. done_text()
  852. {
  853.     int            xmin, ymin, xmax, ymax;
  854.  
  855.     old_t = new_t->next;
  856.     switch (button_result) {
  857.     case APPLY:
  858.     draw_text(new_t, ERASE);
  859.     changed = 1;
  860.     get_new_text_values();
  861.     draw_text(new_t, PAINT);
  862.     break;
  863.     case DONE:
  864.     draw_text(old_t, ERASE);
  865.     get_new_text_values();
  866.     new_t->next = NULL;
  867.     change_text(old_t, new_t);
  868.     text_bound(new_t, &xmin, &ymin, &xmax, &ymax);
  869.     redisplay_zoomed_region(xmin, ymin, xmax, ymax);
  870.     reset_cursor();
  871.     break;
  872.     case CANCEL:
  873.     if (changed) {
  874.         draw_text(new_t, ERASE);
  875.         text_bound(old_t, &xmin, &ymin, &xmax, &ymax);
  876.         redisplay_zoomed_region(xmin, ymin, xmax, ymax);
  877.     } else {
  878.         toggle_textmarker(old_t);
  879.     }
  880.     new_t->next = NULL;
  881.     free_text(&new_t);
  882.     new_t = old_t;
  883.     reset_cursor();
  884.     break;
  885.     }
  886. }
  887.  
  888. make_window_ellipse(e)
  889.     F_ellipse       *e;
  890. {
  891.     char       *s1, *s2;
  892.     PIXRECT        image;
  893.  
  894.     set_temp_cursor(panel_cursor);
  895.     toggle_ellipsemarker(e);
  896.     new_e = copy_ellipse(e);
  897.     new_e->next = e;
  898.     color = new_e->color;
  899.     switch (new_e->type) {
  900.     case T_ELLIPSE_BY_RAD:
  901.     s1 = "ELLIPSE";
  902.     s2 = "specified by radius";
  903.     ellipse_flag = 1;
  904.     image = &ellrad_ic;
  905.     break;
  906.     case T_ELLIPSE_BY_DIA:
  907.     s1 = "ELLIPSE";
  908.     s2 = "specified by diameter";
  909.     ellipse_flag = 1;
  910.     image = &elldia_ic;
  911.     break;
  912.     case T_CIRCLE_BY_RAD:
  913.     s1 = "CIRCLE";
  914.     s2 = "specified by radius";
  915.     ellipse_flag = 0;
  916.     image = &cirrad_ic;
  917.     break;
  918.     case T_CIRCLE_BY_DIA:
  919.     s1 = "CIRCLE";
  920.     s2 = "specified by diameter";
  921.     ellipse_flag = 0;
  922.     image = &cirdia_ic;
  923.     break;
  924.     }
  925.     put_generic_vals(new_e);
  926.     generic_window(s1, s2, image, done_ellipse, 1, 0);
  927.     int_panel(round(180 / M_PI * new_e->angle), form, "Angle (degrees) =",
  928.           &angle_panel);
  929.  
  930.     if (ellipse_flag) {
  931.     f_pos_panel(&new_e->center, "Center:",
  932.             &x1_panel, &y1_panel);
  933.     f_pos_panel(&new_e->radiuses, "Radiuses:",
  934.             &x2_panel, &y2_panel);
  935.     } else {
  936.     f_pos_panel(&new_e->center, "Center:",
  937.             &x1_panel, &y1_panel);
  938.     int_panel(new_e->radiuses.x, form, "Radius =",
  939.           &x2_panel);
  940.     }
  941. }
  942.  
  943. static
  944. get_new_ellipse_values()
  945. {
  946.     get_generic_vals(new_e);
  947.     new_e->angle = M_PI / 180 * atoi(panel_get_value(angle_panel));
  948.     get_f_pos(&new_e->center, x1_panel, y1_panel);
  949.     if (ellipse_flag)
  950.     get_f_pos(&new_e->radiuses, x2_panel, y2_panel);
  951.     else
  952.     new_e->radiuses.x = new_e->radiuses.y =
  953.         atoi(panel_get_value(x2_panel));
  954.  
  955.     if (new_e->type == T_ELLIPSE_BY_RAD || new_e->type == T_CIRCLE_BY_RAD) {
  956.     new_e->start = new_e->center;
  957.     } else {
  958.     new_e->start.x = new_e->center.x - new_e->radiuses.x;
  959.     new_e->start.y = new_e->center.y - new_e->radiuses.y;
  960.     }
  961.     new_e->end.x = new_e->center.x + new_e->radiuses.x;
  962.     new_e->end.y = new_e->center.y + new_e->radiuses.y;
  963. }
  964.  
  965. static
  966. done_ellipse()
  967. {
  968.     int            xmin, ymin, xmax, ymax;
  969.  
  970.     old_e = new_e->next;
  971.     switch (button_result) {
  972.     case APPLY:
  973.     draw_ellipse(new_e, ERASE);
  974.     changed = 1;
  975.     get_new_ellipse_values();
  976.     draw_ellipse(new_e, PAINT);
  977.     break;
  978.     case DONE:
  979.     draw_ellipse(new_e, ERASE);
  980.     get_new_ellipse_values();
  981.     new_e->next = NULL;
  982.     change_ellipse(old_e, new_e);
  983.     draw_ellipse(new_e, PAINT);
  984.     toggle_ellipsemarker(new_e);
  985.     reset_cursor();
  986.     break;
  987.     case CANCEL:
  988.     if (changed) {
  989.         draw_ellipse(new_e, ERASE);
  990.         draw_ellipse(old_e, PAINT);
  991.     }
  992.     new_e->next = NULL;
  993.     free_ellipse(&new_e);
  994.     toggle_ellipsemarker(old_e);
  995.     reset_cursor();
  996.     break;
  997.     }
  998.  
  999. }
  1000.  
  1001. make_window_arc(a)
  1002.     F_arc       *a;
  1003. {
  1004.     set_temp_cursor(panel_cursor);
  1005.     toggle_arcmarker(a);
  1006.     new_a = copy_arc(a);
  1007.     new_a->next = a;
  1008.     color = new_a->color;
  1009.     put_generic_vals(new_a);
  1010.     put_generic_arrows(new_a);
  1011.     generic_window("ARC", "Specified by 3 points", &arc_ic, done_arc, 1, 1);
  1012.     f_pos_panel(&new_a->point[0], "p1:", &x1_panel, &y1_panel);
  1013.     f_pos_panel(&new_a->point[1], "p2:", &x2_panel, &y2_panel);
  1014.     f_pos_panel(&new_a->point[2], "p3:", &x3_panel, &y3_panel);
  1015. }
  1016.  
  1017. static
  1018. get_new_arc_values()
  1019. {
  1020.     F_pos        p0, p1, p2;
  1021.     float        cx, cy;
  1022.  
  1023.     get_generic_vals(new_a);
  1024.     get_generic_arrows(new_a);
  1025.     get_f_pos(&p0, x1_panel, y1_panel);
  1026.     get_f_pos(&p1, x2_panel, y2_panel);
  1027.     get_f_pos(&p2, x3_panel, y3_panel);
  1028.     if (compute_arccenter(p0, p1, p2, &cx, &cy)) {
  1029.     new_a->point[0] = p0;
  1030.     new_a->point[1] = p1;
  1031.     new_a->point[2] = p2;
  1032.     new_a->center.x = cx;
  1033.     new_a->center.y = cy;
  1034.     new_a->direction = compute_direction(p0, p1, p2);
  1035.     } else
  1036.     put_msg("Invalid ARC points!");
  1037. }
  1038.  
  1039. static
  1040. done_arc()
  1041. {
  1042.     int            xmin, ymin, xmax, ymax;
  1043.  
  1044.     old_a = new_a->next;
  1045.     switch (button_result) {
  1046.     case APPLY:
  1047.     draw_arc(new_a, ERASE);
  1048.     changed = 1;
  1049.     get_new_arc_values();
  1050.     draw_arc(new_a, PAINT);
  1051.     break;
  1052.     case DONE:
  1053.     draw_arc(new_a, ERASE);
  1054.     get_new_arc_values();
  1055.     new_a->next = NULL;
  1056.     change_arc(old_a, new_a);
  1057.     draw_arc(new_a, PAINT);
  1058.     toggle_arcmarker(new_a);
  1059.     reset_cursor();
  1060.     break;
  1061.     case CANCEL:
  1062.     if (changed) {
  1063.         draw_arc(new_a, ERASE);
  1064.         draw_arc(old_a, PAINT);
  1065.     }
  1066.     new_a->next = NULL;
  1067.     free_arc(&new_a);
  1068.     toggle_arcmarker(old_a);
  1069.     reset_cursor();
  1070.     break;
  1071.     }
  1072.  
  1073. }
  1074.  
  1075. make_window_spline(s)
  1076.     F_spline       *s;
  1077. {
  1078.     set_temp_cursor(panel_cursor);
  1079.     toggle_splinemarker(s);
  1080.     new_s = copy_spline(s);
  1081.     new_s->next = s;
  1082.     color = new_s->color;
  1083.     put_generic_vals(new_s);
  1084.     put_generic_arrows(new_s);
  1085.     switch (new_s->type) {
  1086.     case T_OPEN_NORMAL:
  1087.     generic_window("SPLINE", "Normal open", &spl_ic,
  1088.                done_spline, 1, 1);
  1089.     points_panel(new_s->points, 0);
  1090.     break;
  1091.     case T_CLOSED_NORMAL:
  1092.     generic_window("SPLINE", "Normal closed", &c_spl_ic,
  1093.                done_spline, 1, 1);
  1094.     points_panel(new_s->points, 1);
  1095.     break;
  1096.     case T_OPEN_INTERP:
  1097.     generic_window("SPLINE", "Interpolated open", &intspl_ic,
  1098.                done_spline, 1, 1);
  1099.     points_panel(new_s->points, 0);
  1100.     break;
  1101.     case T_CLOSED_INTERP:
  1102.     generic_window("SPLINE", "Interpolated closed", &c_intspl_ic,
  1103.                done_spline, 1, 1);
  1104.     points_panel(new_s->points, 1);
  1105.     break;
  1106.     }
  1107. }
  1108.  
  1109. static
  1110. done_spline()
  1111. {
  1112.     int            xmin, ymin, xmax, ymax;
  1113.  
  1114.     old_s = new_s->next;
  1115.     switch (button_result) {
  1116.     case APPLY:
  1117.     draw_spline(new_s, ERASE);
  1118.     changed = 1;
  1119.     get_generic_vals(new_s);
  1120.     get_generic_arrows(new_s);
  1121.     get_points(new_s->points, closed_spline(new_s));
  1122.     if (int_spline(new_s))
  1123.         remake_control_points(new_s);
  1124.     draw_spline(new_s, PAINT);
  1125.     break;
  1126.     case DONE:
  1127.     draw_spline(new_s, ERASE);
  1128.     get_generic_vals(new_s);
  1129.     get_generic_arrows(new_s);
  1130.     get_points(new_s->points, closed_spline(new_s));
  1131.     if (int_spline(new_s))
  1132.         remake_control_points(new_s);
  1133.     new_s->next = NULL;
  1134.     change_spline(old_s, new_s);
  1135.     draw_spline(new_s, PAINT);
  1136.     toggle_splinemarker(new_s);
  1137.     reset_cursor();
  1138.     break;
  1139.     case CANCEL:
  1140.     if (changed) {
  1141.         draw_spline(new_s, ERASE);
  1142.         draw_spline(old_s, PAINT);
  1143.     }
  1144.     new_s->next = NULL;
  1145.     free_spline(&new_s);
  1146.     toggle_splinemarker(old_s);
  1147.     reset_cursor();
  1148.     break;
  1149.     }
  1150. }
  1151.  
  1152. static void
  1153. new_generic_values()
  1154. {
  1155.     int            fill;
  1156.     char       *val;
  1157.  
  1158.     generic_vals.thickness = atoi(panel_get_value(thickness_panel));
  1159.     generic_vals.color = color;
  1160.     generic_vals.depth = atoi(panel_get_value(depth_panel));
  1161.     /* include dash length in panel, too */
  1162.     generic_vals.style_val = (float) atof(panel_get_value(style_val_panel));
  1163.     if (fill_flag) {
  1164.     val = panel_get_value(fill_style_panel);
  1165.     if (*val >= ' ' && *val <= '9') {
  1166.         if ((fill = atoi(val)) > 100)
  1167.         fill = 100;
  1168.         generic_vals.fill_style = (fill / (100 / (NUMFILLPATS - 1))) + 1;
  1169.     }
  1170.     fill = (generic_vals.fill_style - 1) * (100 / (NUMFILLPATS - 1));
  1171.     sprintf(buf, "%d", fill);
  1172.     panel_set_value(fill_style_panel, buf);
  1173.     } else
  1174.     generic_vals.fill_style = 0;
  1175. }
  1176.  
  1177. static void
  1178. new_arrow_values()
  1179. {
  1180.     generic_vals.for_arrow->thickness = 
  1181.                 (float) atof(panel_get_value(for_arrow_thick));
  1182.     generic_vals.for_arrow->wid = 
  1183.                 (float) atof(panel_get_value(for_arrow_width));
  1184.     generic_vals.for_arrow->ht = 
  1185.                 (float) atof(panel_get_value(for_arrow_height));
  1186.     generic_vals.back_arrow->thickness = 
  1187.                 (float) atof(panel_get_value(back_arrow_thick));
  1188.     generic_vals.back_arrow->wid = 
  1189.                 (float) atof(panel_get_value(back_arrow_width));
  1190.     generic_vals.back_arrow->ht = 
  1191.                 (float) atof(panel_get_value(back_arrow_height));
  1192. }
  1193.  
  1194. static        XtCallbackProc
  1195. done_button(panel_local, item, event)
  1196.     Widget        panel_local;
  1197.     Widget       *item;
  1198.     int           *event;
  1199. {
  1200.     button_result = DONE;
  1201.     done_proc();
  1202.     Quit(NULL, NULL, NULL);
  1203. }
  1204.  
  1205. static        XtCallbackProc
  1206. apply_button(panel_local, item, event)
  1207.     Widget        panel_local;
  1208.     Widget       *item;
  1209.     int           *event;
  1210. {
  1211.     button_result = APPLY;
  1212.     done_proc();
  1213. }
  1214.  
  1215. static        XtCallbackProc
  1216. cancel_button(panel_local, item, event)
  1217.     Widget        panel_local;
  1218.     Widget       *item;
  1219.     int           *event;
  1220. {
  1221.     button_result = CANCEL;
  1222.     done_proc();
  1223.     Quit(NULL, NULL, NULL);
  1224. }
  1225.  
  1226. static void
  1227. edit_cancel(w, ev)
  1228.     Widget          w;
  1229.     XButtonEvent   *ev;
  1230. {
  1231.     cancel_button(w, NULL, NULL);
  1232. }
  1233.  
  1234.  
  1235. /*
  1236.  * the following pix_table entries are guaranteed to be initialized to 0 by
  1237.  * the compiler
  1238.  */
  1239.  
  1240. static struct {
  1241.     PIXRECT        image;
  1242.     Pixmap        image_pm;
  1243. }        pix_table[NUM_IMAGES];
  1244.  
  1245. static
  1246. generic_window(object_type, sub_type, icon, d_proc, generics, arrows)
  1247.     char       *object_type, *sub_type;
  1248.     PIXRECT        icon;
  1249.     int            (*d_proc) ();
  1250.     int            generics, arrows;
  1251.  
  1252. {
  1253.     Position        x_val, y_val;
  1254.     Dimension        width, height;
  1255.     Dimension        label_height, image_height;
  1256.     int            button_distance;
  1257.     int            i, fill, dist;
  1258.     Widget        image;
  1259.     Pixmap        image_pm;
  1260.     static int      actions_added=0;
  1261.  
  1262. #ifdef OPENWIN_BUG
  1263.     /* to cater for OpenWindows bug - see below */
  1264.     Pixel        fg, bg;
  1265.  
  1266. #endif
  1267.  
  1268.     static char       *linestyle_items[] = {
  1269.     "Solid Line ", "Dashed Line", "Dotted Line"};
  1270.     static char       *fill_style_items[] = {
  1271.     "No fill", "Filled "};
  1272.  
  1273.     FirstArg(XtNwidth, &width);
  1274.     NextArg(XtNheight, &height);
  1275.     GetValues(tool);
  1276.     XtTranslateCoords(tool, (Position) (width / 2), (Position) (height / 5),
  1277.               &x_val, &y_val);
  1278.  
  1279.     FirstArg(XtNx, x_val);
  1280.     NextArg(XtNy, y_val);
  1281.     NextArg(XtNtitle, "Xfig: Edit panel");
  1282.     popup = XtCreatePopupShell("xfig_edit_panel",
  1283.                    transientShellWidgetClass, tool,
  1284.                    Args, ArgCount);
  1285.     XtOverrideTranslations(popup,
  1286.             XtParseTranslationTable(edit_translations));
  1287.     if (!actions_added) {
  1288.         XtAppAddActions(tool_app, edit_actions, XtNumber(edit_actions));
  1289.     actions_added = 1;
  1290.     }
  1291.  
  1292.     form = XtCreateManagedWidget("form", formWidgetClass, popup, NULL, 0);
  1293.  
  1294.     done_proc = d_proc;
  1295.  
  1296.     sprintf(buf, "%s:%s", object_type, sub_type);
  1297.     FirstArg(XtNborderWidth, 0);
  1298.     label = XtCreateManagedWidget(buf, labelWidgetClass, form, Args, ArgCount);
  1299.  
  1300.     FirstArg(XtNfromHoriz, label);
  1301.     NextArg(XtNbottom, XtChainTop);
  1302.     NextArg(XtNleft, XtChainRight);
  1303.     NextArg(XtNright, XtChainRight);
  1304.     image = XtCreateManagedWidget("image", labelWidgetClass, form,
  1305.                   Args, ArgCount);
  1306.  
  1307.     /* put in the image */
  1308.     /* search to see if that pixmap has already been created */
  1309.     image_pm = 0;
  1310.     for (i = 0; i < NUM_IMAGES; i++) {
  1311.     if (pix_table[i].image == 0)
  1312.         break;
  1313.     if (pix_table[i].image == icon) {
  1314.         image_pm = pix_table[i].image_pm;
  1315.         break;
  1316.     }
  1317.     }
  1318.  
  1319.     /* doesn't already exist, create a pixmap from the data (ala panel.c) */
  1320.     /* OpenWindows bug doesn't handle a 1-plane bitmap on a n-plane display */
  1321.     if (!image_pm) {
  1322. #ifdef OPENWIN_BUG
  1323.     /* get the foreground/background of the widget */
  1324.     FirstArg(XtNforeground, &fg);
  1325.     NextArg(XtNbackground, &bg);
  1326.     GetValues(image);
  1327.  
  1328.     image_pm = XCreatePixmapFromBitmapData(tool_d, canvas_win,
  1329.                      (char *) icon->data, icon->width, icon->height,
  1330.                      fg, bg, XDefaultDepthOfScreen(tool_s));
  1331. #else
  1332.     image_pm = XCreateBitmapFromData(tool_d, canvas_win,
  1333.                      (char *) icon->data, icon->width, icon->height);
  1334. #endif
  1335.     pix_table[i].image_pm = image_pm;
  1336.     pix_table[i].image = icon;
  1337.     }
  1338.     FirstArg(XtNbitmap, image_pm);
  1339.     SetValues(image);
  1340.  
  1341.     /* get height of label widget and distance between widgets */
  1342.     FirstArg(XtNheight, &label_height);
  1343.     NextArg(XtNvertDistance, &button_distance);
  1344.     GetValues(label);
  1345.     /* do the same for the image widget */
  1346.     FirstArg(XtNheight, &image_height);
  1347.     GetValues(image);
  1348.  
  1349.     if (image_height > label_height)
  1350.     dist = image_height - label_height + button_distance;
  1351.     else
  1352.     dist = button_distance;
  1353.     FirstArg(XtNfromVert, label);
  1354.     NextArg(XtNvertDistance, dist);
  1355.     but1 = XtCreateManagedWidget("done", commandWidgetClass, form, Args, ArgCount);
  1356.     XtAddCallback(but1, XtNcallback, (XtCallbackProc)done_button, (XtPointer) NULL);
  1357.  
  1358.     below = but1;
  1359.     FirstArg(XtNfromHoriz, but1);
  1360.     NextArg(XtNfromVert, label);
  1361.     NextArg(XtNvertDistance, dist);
  1362.     but1 = XtCreateManagedWidget("apply", commandWidgetClass, form, Args, ArgCount);
  1363.     XtAddCallback(but1, XtNcallback, (XtCallbackProc)apply_button, (XtPointer) NULL);
  1364.  
  1365.     FirstArg(XtNfromHoriz, but1);
  1366.     NextArg(XtNfromVert, label);
  1367.     NextArg(XtNvertDistance, dist);
  1368.     but1 = XtCreateManagedWidget("cancel", commandWidgetClass, form, Args, ArgCount);
  1369.     XtAddCallback(but1, XtNcallback, (XtCallbackProc)cancel_button, (XtPointer) NULL);
  1370.  
  1371.     FirstArg(XtNborderWidth, 0);
  1372.     NextArg(XtNfromVert, below);
  1373.     below = XtCreateManagedWidget(" ", labelWidgetClass, form, Args, ArgCount);
  1374.  
  1375.     if (generics) {
  1376.     int_panel(generic_vals.thickness, form, "Width =", &thickness_panel);
  1377.  
  1378.     /* make color menu */
  1379.     color_selection_panel();
  1380.  
  1381.     int_panel(generic_vals.depth, form, "Depth =", &depth_panel);
  1382.  
  1383.     if (generic_vals.fill_style == 0) {
  1384.         fill = 0;
  1385.         fill_flag = False;
  1386.     } else {
  1387.         fill = (generic_vals.fill_style - 1) * (100 / (NUMFILLPATS - 1));
  1388.         fill_flag = True;
  1389.     }
  1390.  
  1391.     /* make popup fill style menu */
  1392.     FirstArg(XtNfromVert, below);
  1393.     NextArg(XtNborderWidth, 0);
  1394.     beside = XtCreateManagedWidget("Fill style =", labelWidgetClass,
  1395.                        form, Args, ArgCount);
  1396.     FirstArg(XtNfromVert, below);
  1397.     NextArg(XtNfromHoriz, beside);
  1398.     fill_flag_panel = XtCreateManagedWidget(
  1399.          fill_style_items[fill_flag ? 1 : 0], menuButtonWidgetClass,
  1400.                         form, Args, ArgCount);
  1401.     below = fill_flag_panel;
  1402.     menu = make_popup_menu(fill_style_items, XtNumber(fill_style_items),
  1403.                    fill_flag_panel, fill_style_select);
  1404.  
  1405.     if (generic_vals.color==BLACK)
  1406.         int_panel(fill, form, "Fill density % =", &fill_style_panel);
  1407.     else
  1408.         int_panel(fill, form, "Fill intensity % =", &fill_style_panel);
  1409.     fill_style_label = beside;    /* save pointer to fill label */
  1410.     FirstArg(XtNsensitive, fill_flag ? True : False);
  1411.     SetValues(fill_style_panel);
  1412.     NextArg(XtNhorizDistance, 30);
  1413.     SetValues(fill_style_label);
  1414.     /* if fill is off, blank out fill % value */
  1415.     if (!fill_flag)
  1416.         panel_clear_value(fill_style_panel);
  1417.  
  1418.     /* make popup line style menu */
  1419.     FirstArg(XtNfromVert, below);
  1420.     NextArg(XtNborderWidth, 0);
  1421.     beside = XtCreateManagedWidget("Line style =", labelWidgetClass,
  1422.                        form, Args, ArgCount);
  1423.     FirstArg(XtNfromVert, below);
  1424.     NextArg(XtNfromHoriz, beside);
  1425.     style_panel = XtCreateManagedWidget(
  1426.          linestyle_items[generic_vals.style], menuButtonWidgetClass,
  1427.                         form, Args, ArgCount);
  1428.     below = style_panel;
  1429.     menu = make_popup_menu(linestyle_items, XtNumber(linestyle_items),
  1430.                    style_panel, line_style_select);
  1431.  
  1432.     /* new field for style_val */
  1433.     float_panel(generic_vals.style_val, form, "Dash length/Dot gap =",
  1434.             &style_val_panel);
  1435.     /* save pointer to dash/dot gap label panel */
  1436.     style_val_label = beside;
  1437.     FirstArg(XtNhorizDistance, 30);
  1438.     SetValues(style_val_label);
  1439.     if (generic_vals.style == SOLID_LINE) {
  1440.         FirstArg(XtNsensitive, False);
  1441.         SetValues(style_val_panel);
  1442.         SetValues(style_val_label);
  1443.         /* and clear any value from the dash length panel */
  1444.         panel_clear_value(style_val_panel);
  1445.     }
  1446.  
  1447.     if (arrows) {
  1448.         Widget    arrow_label,for_aform,back_aform,w;
  1449.  
  1450.         FirstArg(XtNfromVert, below);
  1451.         NextArg(XtNborderWidth, 0);
  1452.         arrow_label = XtCreateManagedWidget("Arrows", labelWidgetClass,
  1453.                        form, Args, ArgCount);
  1454.         FirstArg(XtNfromVert, arrow_label);
  1455.         for_aform = XtCreateManagedWidget("arrow_form", formWidgetClass, 
  1456.                       form, Args, ArgCount);
  1457.         FirstArg(XtNborderWidth, 0);
  1458.         w = XtCreateManagedWidget("Forward", labelWidgetClass,
  1459.                        for_aform, Args, ArgCount);
  1460.         FirstArg(XtNfromHoriz, w);
  1461.         NextArg(XtNhorizDistance, 10);
  1462.         NextArg(XtNlabel, "->");
  1463.         NextArg(XtNstate, (generic_vals.for_arrow? True: False));
  1464.         beside = XtCreateManagedWidget("for.arrow", toggleWidgetClass,
  1465.                        for_aform, Args, ArgCount);
  1466.         XtAddCallback(beside, XtNcallback, (XtCallbackProc) toggle_for_arrow,
  1467.               (XtPointer) NULL);
  1468.         below = w;
  1469.         for_arrow=True;
  1470.         if (!generic_vals.for_arrow)
  1471.         {
  1472.         for_arrow=False;
  1473.         generic_vals.for_arrow = forward_arrow();
  1474.         }
  1475.         float_panel(generic_vals.for_arrow->thickness, for_aform, 
  1476.             "Thick  =", &for_arrow_thick);
  1477.         for_thick_label = beside;
  1478.         for_thick_val = below;
  1479.         float_panel(generic_vals.for_arrow->wid, for_aform, 
  1480.             "Width  =", &for_arrow_width);
  1481.         for_width_label = beside;
  1482.         for_width_val = below;
  1483.         float_panel(generic_vals.for_arrow->ht, for_aform, 
  1484.             "Height =", &for_arrow_height);
  1485.         for_height_label = beside;
  1486.         for_height_val = below;
  1487.         if (!for_arrow)    /* make insensitive */
  1488.         {
  1489.         for_arrow = True;
  1490.         toggle_for_arrow((Widget)0, (XtPointer)0, (XtPointer)0);
  1491.         for_arrow = False;
  1492.         }
  1493.  
  1494.         FirstArg(XtNfromVert, arrow_label);
  1495.         NextArg(XtNfromHoriz, for_aform);
  1496.         back_aform = XtCreateManagedWidget("arrow_form", formWidgetClass, 
  1497.                       form, Args, ArgCount);
  1498.         FirstArg(XtNborderWidth, 0);
  1499.         w = XtCreateManagedWidget("Backward", labelWidgetClass,
  1500.                        back_aform, Args, ArgCount);
  1501.         FirstArg(XtNfromHoriz, w);
  1502.         NextArg(XtNhorizDistance, 10);
  1503.         NextArg(XtNlabel, "<-");
  1504.         NextArg(XtNstate, (generic_vals.back_arrow? True: False));
  1505.         beside = XtCreateManagedWidget("back.arrow", toggleWidgetClass,
  1506.                        back_aform, Args, ArgCount);
  1507.         XtAddCallback(beside, XtNcallback, (XtCallbackProc) toggle_back_arrow,
  1508.               (XtPointer) NULL);
  1509.         below = w;
  1510.         back_arrow=True;
  1511.         if (!generic_vals.back_arrow)
  1512.         {
  1513.         back_arrow=False;
  1514.         generic_vals.back_arrow = backward_arrow();
  1515.         }
  1516.         float_panel(generic_vals.back_arrow->thickness, back_aform, 
  1517.             "Thick  =", &back_arrow_thick);
  1518.         back_thick_label = beside;
  1519.         back_thick_val = below;
  1520.         float_panel(generic_vals.back_arrow->wid, back_aform, 
  1521.             "Width  =", &back_arrow_width);
  1522.         back_width_label = beside;
  1523.         back_width_val = below;
  1524.         float_panel(generic_vals.back_arrow->ht, back_aform, 
  1525.             "Height =", &back_arrow_height);
  1526.         back_height_label = beside;
  1527.         back_height_val = below;
  1528.         if (!back_arrow)    /* make insensitive */
  1529.         {
  1530.         back_arrow = True;
  1531.         toggle_back_arrow((Widget)0, (XtPointer)0, (XtPointer)0);
  1532.         back_arrow = False;
  1533.         }
  1534.         below = for_aform;    /* for the widget that follows us in the panel */
  1535.     }
  1536.     }
  1537. }
  1538.  
  1539. static
  1540. XtCallbackProc
  1541. toggle_for_arrow(w, dummy, dummy2)
  1542.     Widget       w;
  1543.     XtPointer       dummy;
  1544.     XtPointer       dummy2;
  1545. {
  1546.     /* either add or delete arrowhead */
  1547.     for_arrow = !for_arrow;
  1548.     FirstArg(XtNsensitive, (for_arrow? True: False));
  1549.     SetValues(for_arrow_thick);
  1550.     SetValues(for_thick_label);
  1551.     SetValues(for_thick_val);
  1552.     SetValues(for_arrow_width);
  1553.     SetValues(for_width_label);
  1554.     SetValues(for_width_val);
  1555.     SetValues(for_arrow_height);
  1556.     SetValues(for_height_label);
  1557.     SetValues(for_height_val);
  1558. }
  1559.  
  1560. static
  1561. XtCallbackProc
  1562. toggle_back_arrow(w, dummy, dummy2)
  1563.     Widget       w;
  1564.     XtPointer       dummy;
  1565.     XtPointer       dummy2;
  1566. {
  1567.     /* either add or delete arrowhead */
  1568.     back_arrow = !back_arrow;
  1569.     FirstArg(XtNsensitive, (back_arrow? True: False));
  1570.     SetValues(back_arrow_thick);
  1571.     SetValues(back_thick_label);
  1572.     SetValues(back_thick_val);
  1573.     SetValues(back_arrow_width);
  1574.     SetValues(back_width_label);
  1575.     SetValues(back_width_val);
  1576.     SetValues(back_arrow_height);
  1577.     SetValues(back_height_label);
  1578.     SetValues(back_height_val);
  1579. }
  1580.  
  1581. /* make a button panel with the image 'pixmap' in it */
  1582. /* for the font selection */
  1583.  
  1584. void        f_menu_popup();
  1585.  
  1586. static XtCallbackRec f_sel_callback[] =
  1587. {
  1588.     {f_menu_popup, NULL},
  1589.     {NULL, NULL},
  1590. };
  1591.  
  1592. set_font_image(widget)
  1593.     TOOL        widget;
  1594. {
  1595.     FirstArg(XtNbitmap, new_psflag ?
  1596.          psfont_menu_bitmaps[new_ps_font + 1] :
  1597.          latexfont_menu_bitmaps[new_latex_font]);
  1598.     SetValues(widget);
  1599. }
  1600.  
  1601. static
  1602. font_image_panel(pixmap, label, pi_x)
  1603.     Pixmap        pixmap;
  1604.     char       *label;
  1605.     Widget       *pi_x;
  1606. {
  1607.     FirstArg(XtNfromVert, below);
  1608.     NextArg(XtNlabel, label);
  1609.     NextArg(XtNborderWidth, 0);
  1610.     below = XtCreateManagedWidget(label, labelWidgetClass, form, Args, ArgCount);
  1611.  
  1612.     FirstArg(XtNfromVert, below);
  1613.     NextArg(XtNvertDistance, 2);
  1614.     NextArg(XtNbitmap, pixmap);
  1615.     NextArg(XtNcallback, f_sel_callback);
  1616.     *pi_x = XtCreateManagedWidget(label, commandWidgetClass, form, Args, ArgCount);
  1617.     below = *pi_x;
  1618. }
  1619.  
  1620. /* come here when user presses font image button */
  1621.  
  1622. void
  1623. f_menu_popup()
  1624. {
  1625.     fontpane_popup(&new_ps_font, &new_latex_font, &new_psflag,
  1626.            set_font_image, font_panel);
  1627. }
  1628.  
  1629. /*
  1630.  * make a popup menu with "nent" button entries (labels) that call "callback"
  1631.  * when pressed
  1632.  */
  1633.  
  1634. Widget
  1635. make_popup_menu(entries, nent, parent, callback)
  1636.     char       *entries[];
  1637.     Cardinal        nent;
  1638.     Widget        parent;
  1639.     XtCallbackProc  callback;
  1640.  
  1641. {
  1642.     Widget        pop_menu, entry;
  1643.     int            i;
  1644.  
  1645.     pop_menu = XtCreatePopupShell("menu", simpleMenuWidgetClass, parent,
  1646.                   NULL, ZERO);
  1647.  
  1648.     for (i = 0; i < nent; i++) {
  1649.     entry = XtCreateManagedWidget(entries[i], smeBSBObjectClass, pop_menu,
  1650.                       NULL, ZERO);
  1651.     XtAddCallback(entry, XtNcallback, callback, (XtPointer) i);
  1652.     }
  1653.     return pop_menu;
  1654. }
  1655.  
  1656. static
  1657. color_selection_panel()
  1658. {
  1659.     FirstArg(XtNfromVert, below);
  1660.     NextArg(XtNborderWidth, 0);
  1661.     beside = XtCreateManagedWidget("Drawing color =", labelWidgetClass,
  1662.                    form, Args, ArgCount);
  1663.     /* warning: set_color_names uses FirstArg() etc. - put it here */
  1664.     set_color_name(generic_vals.color);
  1665.     FirstArg(XtNfromVert, below);
  1666.     NextArg(XtNfromHoriz, beside);
  1667.     color_panel = XtCreateManagedWidget(
  1668.              "colors", menuButtonWidgetClass, form, Args, ArgCount);
  1669.     /*
  1670.      * cheat a little - set the initial fore/background colors by calling the
  1671.      * callback
  1672.      */
  1673.     /* also set the label */
  1674.     color_select(color_panel, generic_vals.color, NULL);
  1675.     below = color_panel;
  1676.     menu = make_color_popup_menu(color_panel, color_select);
  1677. }
  1678.  
  1679.  
  1680. static        Widget
  1681. make_color_popup_menu(parent, callback)
  1682.     Widget        parent;
  1683.     XtCallbackProc  callback;
  1684.  
  1685. {
  1686.     Widget        pop_menu, entry;
  1687.     int            i;
  1688.  
  1689.     pop_menu = XtCreatePopupShell("menu", simpleMenuWidgetClass, parent,
  1690.                   NULL, ZERO);
  1691.  
  1692.     for (i = 0; i < NUMCOLORS; i++) {
  1693.     set_color_name(i);
  1694.     if (all_colors_available)
  1695.         FirstArg(XtNforeground, appres.color[i])
  1696.         else
  1697.         ArgCount = 0;
  1698.     entry = XtCreateManagedWidget(buf, smeBSBObjectClass, pop_menu,
  1699.                       Args, ArgCount);
  1700.     XtAddCallback(entry, XtNcallback, callback, (XtPointer) i);
  1701.     }
  1702.     set_color_name(DEFAULT_COLOR);
  1703.     FirstArg(XtNforeground, x_fg_color.pixel);
  1704.     entry = XtCreateManagedWidget(buf, smeBSBObjectClass, pop_menu,
  1705.                   Args, ArgCount);
  1706.     XtAddCallback(entry, XtNcallback, callback, (XtPointer) - 1);
  1707.     return pop_menu;
  1708. }
  1709.  
  1710. static
  1711. int_panel(x, parent, label, pi_x)
  1712.     int            x;
  1713.     Widget        parent;
  1714.     char       *label;
  1715.     Widget       *pi_x;
  1716. {
  1717.     FirstArg(XtNfromVert, below);
  1718.     NextArg(XtNlabel, label);
  1719.     NextArg(XtNborderWidth, 0);
  1720.     beside = XtCreateManagedWidget(label, labelWidgetClass, parent, Args, ArgCount);
  1721.  
  1722.     sprintf(buf, "%d", x);
  1723.     ArgCount = 1;
  1724.     NextArg(XtNstring, buf);
  1725.     NextArg(XtNinsertPosition, strlen(buf));
  1726.     NextArg(XtNfromHoriz, beside);
  1727.     NextArg(XtNeditType, "append");
  1728.     NextArg(XtNwidth, 40);
  1729.     *pi_x = XtCreateManagedWidget(label, asciiTextWidgetClass, parent, Args, ArgCount);
  1730.     below = *pi_x;
  1731. }
  1732.  
  1733. static
  1734. float_panel(x, parent, label, pi_x)
  1735.     float        x;
  1736.     Widget        parent;
  1737.     char       *label;
  1738.     Widget       *pi_x;
  1739. {
  1740.     FirstArg(XtNfromVert, below);
  1741.     NextArg(XtNlabel, label);
  1742.     NextArg(XtNborderWidth, 0);
  1743.     beside = XtCreateManagedWidget(label, labelWidgetClass, parent,
  1744.                    Args, ArgCount);
  1745.     sprintf(buf, "%1.1f", x);
  1746.     FirstArg(XtNfromVert, below);
  1747.     NextArg(XtNstring, buf);
  1748.     NextArg(XtNinsertPosition, strlen(buf));
  1749.     NextArg(XtNfromHoriz, beside);
  1750.     NextArg(XtNeditType, "append");
  1751.     NextArg(XtNwidth, 40);
  1752.     *pi_x = XtCreateManagedWidget(label, asciiTextWidgetClass, parent,
  1753.                   Args, ArgCount);
  1754.     below = *pi_x;
  1755. }
  1756.  
  1757. static
  1758. float_label(x, label, pi_x)
  1759.     float        x;
  1760.     char       *label;
  1761.     Widget       *pi_x;
  1762. {
  1763.     FirstArg(XtNfromVert, below);
  1764.     NextArg(XtNlabel, label);
  1765.     NextArg(XtNborderWidth, 0);
  1766.     beside = XtCreateManagedWidget(label, labelWidgetClass, form,
  1767.                    Args, ArgCount);
  1768.     sprintf(buf, "%1.1f", x);
  1769.     FirstArg(XtNfromVert, below);
  1770.     NextArg(XtNlabel, buf);
  1771.     NextArg(XtNfromHoriz, beside);
  1772.     NextArg(XtNwidth, 40);
  1773.     NextArg(XtNborderWidth, 0);
  1774.     *pi_x = XtCreateManagedWidget(label, labelWidgetClass, form,
  1775.                   Args, ArgCount);
  1776.     below = *pi_x;
  1777. }
  1778.  
  1779. static
  1780. int_label(x, label, pi_x)
  1781.     int            x;
  1782.     char       *label;
  1783.     Widget       *pi_x;
  1784. {
  1785.     FirstArg(XtNfromVert, below);
  1786.     NextArg(XtNlabel, label);
  1787.     NextArg(XtNborderWidth, 0);
  1788.     beside = XtCreateManagedWidget(label, labelWidgetClass, form,
  1789.                    Args, ArgCount);
  1790.     sprintf(buf, "%d", x);
  1791.     FirstArg(XtNfromVert, below);
  1792.     NextArg(XtNlabel, buf);
  1793.     NextArg(XtNfromHoriz, beside);
  1794.     NextArg(XtNwidth, 40);
  1795.     NextArg(XtNborderWidth, 0);
  1796.     *pi_x = XtCreateManagedWidget(label, labelWidgetClass, form,
  1797.                   Args, ArgCount);
  1798.     below = *pi_x;
  1799. }
  1800.  
  1801. /* don't allow newlines in text until we handle multiple line texts */
  1802. String        text_translations =
  1803.     "<Key>Return: no-op(RingBell)\n\
  1804.     Ctrl<Key>J: no-op(RingBell)\n\
  1805.     Ctrl<Key>M: no-op(RingBell)\n\
  1806.     Ctrl<Key>X: EmptyTextKey()\n\
  1807.     Ctrl<Key>U: multiply(4)\n\
  1808.     <Key>F18: PastePanelKey()\n";
  1809.  
  1810. static
  1811. str_panel(string, label, pi_x)
  1812.     char       *string;
  1813.     char       *label;
  1814.     Widget       *pi_x;
  1815. {
  1816.     int            width, nlines, i;
  1817.     Dimension        pwidth;
  1818.     PIX_FONT        temp_font;
  1819.  
  1820.     FirstArg(XtNfromVert, below);
  1821.     NextArg(XtNlabel, label);
  1822.     NextArg(XtNborderWidth, 0);
  1823.     beside = XtCreateManagedWidget(label, labelWidgetClass, form, Args, ArgCount);
  1824.  
  1825.     /* get the font and width of above label widget */
  1826.     FirstArg(XtNfont, &temp_font);
  1827.     NextArg(XtNwidth, &pwidth);
  1828.     GetValues(beside);
  1829.     /* make panel as wide as image pane above less the label widget's width */
  1830.     /* but at least 200 pixels wide */
  1831.     width = max2(PS_FONTPANE_WD - pwidth + 2, 200);
  1832.  
  1833.     /* count number of lines in this text string */
  1834.     nlines = 1;            /* number of lines in string */
  1835.     for (i = 0; i < strlen(string); i++) {
  1836.     if (string[i] == '\n') {
  1837.         nlines++;
  1838.     }
  1839.     }
  1840.     if (nlines > 4)    /* limit to displaying 4 lines and show scrollbars */
  1841.     nlines = 4;
  1842.     if (nlines == 1)    /* if only one line, allow space for scrollbar */
  1843.     nlines = 2;
  1844.     FirstArg(XtNfromVert, below);
  1845.     NextArg(XtNstring, string);
  1846.     NextArg(XtNinsertPosition, strlen(string));
  1847.     NextArg(XtNfromHoriz, beside);
  1848.     NextArg(XtNeditType, "edit");
  1849.     NextArg(XtNwidth, width);
  1850.     /* allow enough height for scrollbar */
  1851.     NextArg(XtNheight, char_height(temp_font) * nlines + 10);
  1852.     NextArg(XtNscrollHorizontal, XawtextScrollWhenNeeded);
  1853.     NextArg(XtNscrollVertical, XawtextScrollWhenNeeded);
  1854.  
  1855.     *pi_x = XtCreateManagedWidget(label, asciiTextWidgetClass, form, Args, ArgCount);
  1856.  
  1857.     /* make Newline do nothing for now */
  1858.     XtOverrideTranslations(*pi_x, XtParseTranslationTable(text_translations));
  1859.  
  1860.     /* read personal key configuration */
  1861.     XtOverrideTranslations(*pi_x, XtParseTranslationTable(local_translations));
  1862.  
  1863.     below = *pi_x;
  1864. }
  1865.  
  1866. static
  1867. xy_panel(x, y, label, pi_x, pi_y)
  1868.     int            x, y;
  1869.     char       *label;
  1870.     Widget       *pi_x, *pi_y;
  1871. {
  1872.     FirstArg(XtNfromVert, below);
  1873.     NextArg(XtNlabel, label);
  1874.     NextArg(XtNborderWidth, 0);
  1875.     below = XtCreateManagedWidget(label, labelWidgetClass, form, Args, ArgCount);
  1876.     FirstArg(XtNfromVert, below);
  1877.     NextArg(XtNhorizDistance, 30);
  1878.     NextArg(XtNlabel, "X =");
  1879.     NextArg(XtNborderWidth, 0);
  1880.     beside = XtCreateManagedWidget(label, labelWidgetClass, form, Args, ArgCount);
  1881.  
  1882.     sprintf(buf, "%d", x);
  1883.     ArgCount = 1;
  1884.     NextArg(XtNstring, buf);
  1885.     NextArg(XtNinsertPosition, strlen(buf));
  1886.     NextArg(XtNfromHoriz, beside);
  1887.     NextArg(XtNeditType, "append");
  1888.     NextArg(XtNwidth, 40);
  1889.     *pi_x = XtCreateManagedWidget(label, asciiTextWidgetClass, form, Args, ArgCount);
  1890.  
  1891.     ArgCount = 1;
  1892.     NextArg(XtNlabel, "Y =");
  1893.     NextArg(XtNborderWidth, 0);
  1894.     NextArg(XtNfromHoriz, *pi_x);
  1895.     beside = XtCreateManagedWidget(label, labelWidgetClass, form, Args, ArgCount);
  1896.  
  1897.     sprintf(buf, "%d", y);
  1898.     ArgCount = 1;
  1899.     NextArg(XtNstring, buf);
  1900.     NextArg(XtNfromHoriz, beside);
  1901.     NextArg(XtNinsertPosition, strlen(buf));
  1902.     NextArg(XtNeditType, "append");
  1903.     NextArg(XtNwidth, 40);
  1904.     *pi_y = XtCreateManagedWidget(label, asciiTextWidgetClass, form, Args, ArgCount);
  1905.  
  1906.     below = *pi_x;
  1907. }
  1908.  
  1909. static
  1910. f_pos_panel(fp, label, pi_x, pi_y)
  1911.     F_pos       *fp;
  1912.     char       *label;
  1913.     Widget       *pi_x, *pi_y;
  1914. {
  1915.     FirstArg(XtNfromVert, below);
  1916.     NextArg(XtNborderWidth, 0);
  1917.     below = XtCreateManagedWidget(label, labelWidgetClass, form, Args, ArgCount);
  1918.     FirstArg(XtNfromVert, below);
  1919.     NextArg(XtNhorizDistance, 30);
  1920.     NextArg(XtNlabel, "X =");
  1921.     NextArg(XtNborderWidth, 0);
  1922.     beside = XtCreateManagedWidget(label, labelWidgetClass, form, Args, ArgCount);
  1923.     sprintf(buf, "%d", fp->x);
  1924.     ArgCount = 1;
  1925.     NextArg(XtNstring, buf);
  1926.     NextArg(XtNinsertPosition, strlen(buf));
  1927.     NextArg(XtNfromHoriz, beside);
  1928.     NextArg(XtNeditType, "append");
  1929.     NextArg(XtNwidth, 40);
  1930.     *pi_x = XtCreateManagedWidget(label, asciiTextWidgetClass, form, Args, ArgCount);
  1931.     ArgCount = 1;
  1932.     NextArg(XtNlabel, "Y =");
  1933.     NextArg(XtNborderWidth, 0);
  1934.     NextArg(XtNfromHoriz, *pi_x);
  1935.     beside = XtCreateManagedWidget(label, labelWidgetClass, form, Args, ArgCount);
  1936.     sprintf(buf, "%d", fp->y);
  1937.     ArgCount = 1;
  1938.     NextArg(XtNstring, buf);
  1939.     NextArg(XtNinsertPosition, strlen(buf));
  1940.     NextArg(XtNfromHoriz, beside);
  1941.     NextArg(XtNeditType, "append");
  1942.     NextArg(XtNwidth, 40);
  1943.     *pi_y = XtCreateManagedWidget(label, asciiTextWidgetClass, form, Args, ArgCount);
  1944.     below = *pi_x;
  1945. }
  1946.  
  1947. static
  1948. get_f_pos(fp, pi_x, pi_y)
  1949.     F_pos       *fp;
  1950.     Widget        pi_x, pi_y;
  1951. {
  1952.     fp->x = (atoi(panel_get_value(pi_x)));
  1953.     fp->y = (atoi(panel_get_value(pi_y)));
  1954. }
  1955.  
  1956. static
  1957. points_panel(p, closed)
  1958.     struct f_point *p;
  1959.     int            closed;
  1960. {
  1961.     struct f_point *pts;
  1962.     char        buf[32];
  1963.     char        bufxy[32];
  1964.     int            i;
  1965.     Widget        viewp,formw;
  1966.  
  1967.     FirstArg(XtNfromVert, below);
  1968.     NextArg(XtNborderWidth, 0);
  1969.     below = XtCreateManagedWidget("Points", labelWidgetClass, form,
  1970.                   Args, ArgCount);
  1971.     FirstArg(XtNallowVert, True);
  1972.     NextArg(XtNfromVert, below);
  1973.     pts = p;
  1974.     for (i = 0; pts != NULL; i++)
  1975.     pts = pts->next;
  1976.     /* limit size of points panel and scroll if more than 8 points */
  1977.     if (i>8)
  1978.         NextArg(XtNheight, 200);
  1979.     viewp = XtCreateManagedWidget("Pointspanel", viewportWidgetClass, form,
  1980.                   Args, ArgCount);
  1981.     formw = XtCreateManagedWidget("pointsform", formWidgetClass, viewp,
  1982.                   NULL, 0);
  1983.     below = 0;
  1984.     for (i = 0; p != NULL; i++) {
  1985.     if (i >= MAXNUMPTS)
  1986.         break;
  1987.     FirstArg(XtNfromVert, below);
  1988.     NextArg(XtNhorizDistance, 30);
  1989.     NextArg(XtNborderWidth, 0);
  1990.     sprintf(buf, "X%d =", i);
  1991.     beside = XtCreateManagedWidget(buf, labelWidgetClass, formw,
  1992.                        Args, ArgCount);
  1993.     sprintf(bufxy, "%d", p->x);
  1994.     ArgCount = 1;
  1995.     NextArg(XtNstring, bufxy);
  1996.     NextArg(XtNinsertPosition, strlen(bufxy));
  1997.     NextArg(XtNfromHoriz, beside);
  1998.     NextArg(XtNeditType, "append");
  1999.     NextArg(XtNwidth, 40);
  2000.     px_panel[i] = XtCreateManagedWidget("xy", asciiTextWidgetClass,
  2001.                         formw, Args, ArgCount);
  2002.  
  2003.     sprintf(buf, "Y%d =", i);
  2004.     ArgCount = 1;
  2005.     NextArg(XtNfromHoriz, px_panel[i]);
  2006.     NextArg(XtNborderWidth, 0);
  2007.     beside = XtCreateManagedWidget(buf, labelWidgetClass,
  2008.                        formw, Args, ArgCount);
  2009.  
  2010.     sprintf(bufxy, "%d", p->y);
  2011.     ArgCount = 1;
  2012.     NextArg(XtNstring, bufxy);
  2013.     NextArg(XtNinsertPosition, strlen(bufxy));
  2014.     NextArg(XtNfromHoriz, beside);
  2015.     NextArg(XtNeditType, "append");
  2016.     NextArg(XtNwidth, 40);
  2017.  
  2018.     py_panel[i] = XtCreateManagedWidget("xy", asciiTextWidgetClass,
  2019.                         formw, Args, ArgCount);
  2020.     below = px_panel[i];
  2021.  
  2022.     p = p->next;
  2023.     if (closed && (p == NULL || p->next == NULL))
  2024.         break;
  2025.     }
  2026. }
  2027.  
  2028. static
  2029. get_points(p, closed)
  2030.     struct f_point *p;
  2031.     Boolean       closed;
  2032. {
  2033.     struct f_point *q;
  2034.     int            i;
  2035.  
  2036.     for (q = p, i = 0; q != NULL; i++) {
  2037.     if (i >= MAXNUMPTS)
  2038.         break;
  2039.     q->x = (atoi(panel_get_value(px_panel[i])));
  2040.     q->y = (atoi(panel_get_value(py_panel[i])));
  2041.     q = q->next;
  2042.     if (closed) {
  2043.         if (q == NULL)
  2044.         break;
  2045.         else if (q->next == NULL) {
  2046.         q->x = p->x;
  2047.         q->y = p->y;
  2048.         break;
  2049.         }
  2050.     }
  2051.     }
  2052. }
  2053.  
  2054. void
  2055. Quit(widget, client_data, call_data)
  2056.     Widget        widget;
  2057.     XtPointer        client_data, call_data;
  2058. {
  2059.     XtDestroyWidget(popup);
  2060. }
  2061.  
  2062. char           *
  2063. panel_get_value(widg)
  2064.     Widget        widg;
  2065. {
  2066.     char       *val;
  2067.  
  2068.     FirstArg(XtNstring, &val);
  2069.     GetValues(widg);
  2070.     return val;
  2071.  
  2072. }
  2073.  
  2074. panel_clear_value(widg)
  2075.     Widget        widg;
  2076. {
  2077.     FirstArg(XtNstring, " ");
  2078.     NextArg(XtNinsertPosition, 0);
  2079.     SetValues(widg);
  2080. }
  2081.  
  2082. int
  2083. panel_set_value(widg, val)
  2084.     Widget        widg;
  2085.     char       *val;
  2086. {
  2087.     FirstArg(XtNstring, val);
  2088.     /* I don't know why this doesn't work? */
  2089.     /* NextArg(XtNinsertPosition, strlen(val)); */
  2090.     SetValues(widg);
  2091.     XawTextSetInsertionPoint(widg, strlen(val));
  2092. }
  2093.  
  2094. static void
  2095. line_style_select(w, new_style, garbage)
  2096.     Widget        w;
  2097.     XtPointer        new_style, garbage;
  2098. {
  2099.     FirstArg(XtNlabel, XtName(w));
  2100.     SetValues(style_panel);
  2101.  
  2102.     generic_vals.style = (int) new_style;
  2103.  
  2104.     switch (generic_vals.style) {
  2105.     case SOLID_LINE:
  2106.     panel_clear_value(style_val_panel);
  2107.     FirstArg(XtNsensitive, False);
  2108.     break;
  2109.     case DASH_LINE:
  2110.     /*
  2111.      * if style_val contains no useful value, set it to the default
  2112.      * dashlength, scaled by the line thickness
  2113.      */
  2114.     if (generic_vals.style_val < 0.1)
  2115.         generic_vals.style_val = cur_dashlength * (cur_linewidth + 1) / 2;
  2116.     sprintf(buf, "%1.1f", generic_vals.style_val);
  2117.     panel_set_value(style_val_panel, buf);
  2118.     FirstArg(XtNsensitive, True);
  2119.     break;
  2120.     case DOTTED_LINE:
  2121.     if (generic_vals.style_val < 0.1)
  2122.         generic_vals.style_val = cur_dotgap * (cur_linewidth + 1) / 2;
  2123.     sprintf(buf, "%1.1f", generic_vals.style_val);
  2124.     panel_set_value(style_val_panel, buf);
  2125.     FirstArg(XtNsensitive, True);
  2126.     break;
  2127.     }
  2128.     /* make both the label and value panels sensitive or insensitive */
  2129.     SetValues(style_val_panel);
  2130.     SetValues(style_val_label);
  2131. }
  2132.  
  2133. static void
  2134. color_select(w, new_color, garbage)
  2135.     Widget        w;
  2136.     XtPointer        new_color, garbage;
  2137. {
  2138.     XFontStruct       *f;
  2139.     int            len;
  2140.  
  2141.     FirstArg(XtNlabel, XtName(w));
  2142.     SetValues(color_panel);
  2143.     color = (Color) new_color;
  2144.     set_color_name(color);
  2145.     FirstArg(XtNfont, &f);
  2146.     GetValues(w);
  2147.     FirstArg(XtNlabel, buf);
  2148.     len = XTextWidth(f, buf, strlen(buf)) + 8;
  2149.     NextArg(XtNwidth, len);    /* set width of panel to width of colorname */
  2150.     NextArg(XtNresizable, True);
  2151.  
  2152.     if (all_colors_available) { /* set color if possible */
  2153.     XColor        xcolor;
  2154.     Pixel        col;
  2155.  
  2156.     /* foreground in the color selected */
  2157.     col = (color < 0 || color >= NUMCOLORS) ? x_fg_color.pixel : appres.color[color];
  2158.     NextArg(XtNforeground, col);
  2159.     xcolor.pixel = col;
  2160.     /* get RGB of the color to check intensity */
  2161.     XQueryColor(tool_d, DefaultColormapOfScreen(tool_s), &xcolor);
  2162.     /* set the background in a contrasting color (white or black) */
  2163.     if ((0.3 * xcolor.red + 0.59 * xcolor.green + 0.11 * xcolor.blue) < 0.55 * (255 << 8))
  2164.         col = appres.color[WHITE];
  2165.     else
  2166.         col = appres.color[BLACK];
  2167.     NextArg(XtNbackground, col);
  2168.     }
  2169.     SetValues(color_panel);
  2170. }
  2171.  
  2172. static void
  2173. set_color_name(color)
  2174.     Color        color;
  2175. {
  2176.     if (color == DEFAULT_COLOR || (color >= 0 && color < NUMCOLORS))
  2177.     sprintf(buf, "%s", colorNames[color + 1]);
  2178.     else
  2179.     sprintf(buf, "%d", color);
  2180. }
  2181.  
  2182. static void
  2183. hidden_text_select(w, new_hidden_text, garbage)
  2184.     Widget        w;
  2185.     XtPointer        new_hidden_text, garbage;
  2186. {
  2187.     FirstArg(XtNlabel, XtName(w));
  2188.     SetValues(hidden_text_panel);
  2189.     hidden_text_flag = (int) new_hidden_text;
  2190. }
  2191.  
  2192. static void
  2193. rigid_text_select(w, new_rigid_text, garbage)
  2194.     Widget        w;
  2195.     XtPointer        new_rigid_text, garbage;
  2196. {
  2197.     FirstArg(XtNlabel, XtName(w));
  2198.     SetValues(rigid_text_panel);
  2199.     rigid_text_flag = (int) new_rigid_text;
  2200. }
  2201.  
  2202. static void
  2203. special_text_select(w, new_special_text, garbage)
  2204.     Widget        w;
  2205.     XtPointer        new_special_text, garbage;
  2206. {
  2207.     FirstArg(XtNlabel, XtName(w));
  2208.     SetValues(special_text_panel);
  2209.     special_text_flag = (int) new_special_text;
  2210. }
  2211.  
  2212. static void
  2213. textjust_select(w, new_textjust, garbage)
  2214.     Widget        w;
  2215.     XtPointer        new_textjust, garbage;
  2216. {
  2217.     FirstArg(XtNlabel, XtName(w));
  2218.     SetValues(textjust_panel);
  2219.     textjust = (int) new_textjust;
  2220. }
  2221.  
  2222. static void
  2223. flip_eps_select(w, new_flipflag, garbage)
  2224.     Widget        w;
  2225.     XtPointer        new_flipflag, garbage;
  2226. {
  2227.     struct f_point  p1, p2;
  2228.     int            dx, dy, rotation;
  2229.     float        ratio;
  2230.  
  2231.     FirstArg(XtNlabel, XtName(w));
  2232.     SetValues(flip_eps_panel);
  2233.     flip_eps_flag = (int) new_flipflag;
  2234.     p1.x = atoi(panel_get_value(x1_panel));
  2235.     p1.y = atoi(panel_get_value(y1_panel));
  2236.     p2.x = atoi(panel_get_value(x2_panel));
  2237.     p2.y = atoi(panel_get_value(y2_panel));
  2238.     dx = p2.x - p1.x;
  2239.     dy = p2.y - p1.y;
  2240.     rotation = 0;
  2241.     if (dx < 0 && dy < 0)
  2242.     rotation = 180;
  2243.     else if (dx < 0 && dy >= 0)
  2244.     rotation = 270;
  2245.     else if (dy < 0 && dx >= 0)
  2246.     rotation = 90;
  2247.     if (dx == 0 || dy == 0)
  2248.     ratio = 0.0;
  2249.     else if (((rotation == 0 || rotation == 180) && !flip_eps_flag) ||
  2250.          (rotation != 0 && rotation != 180 && flip_eps_flag))
  2251.     ratio = fabs((float) dy / (float) dx);
  2252.     else
  2253.     ratio = fabs((float) dx / (float) dy);
  2254.     sprintf(buf, "%1.1f", ratio);
  2255.     FirstArg(XtNlabel, buf);
  2256.     SetValues(hw_ratio_panel);
  2257. }
  2258.  
  2259. static void
  2260. fill_style_select(w, new_fillflag, garbage)
  2261.     Widget        w;
  2262.     XtPointer        new_fillflag, garbage;
  2263. {
  2264.     int            fill;
  2265.  
  2266.     FirstArg(XtNlabel, XtName(w));
  2267.     SetValues(fill_flag_panel);
  2268.     fill_flag = (int) new_fillflag;
  2269.  
  2270.     if (fill_flag) {
  2271.     fill = (generic_vals.fill_style - 1) * (100 / (NUMFILLPATS - 1));
  2272.     if (fill < 0)
  2273.         fill = 0;
  2274.     /* if no fill, blank out fill density value */
  2275.     sprintf(buf, "%d", fill);
  2276.     panel_set_value(fill_style_panel, buf);
  2277.     } else {
  2278.     panel_clear_value(fill_style_panel);
  2279.     }
  2280.  
  2281.     /* make fill% panel sensitive or insensitive depending on fill flag */
  2282.     FirstArg(XtNsensitive, fill_flag ? True : False);
  2283.     SetValues(fill_style_panel);
  2284.     SetValues(fill_style_label);
  2285. }
  2286.  
  2287. void clear_text_key(w)
  2288. Widget w;
  2289. {
  2290.     panel_set_value(w, "");
  2291. }
  2292.  
  2293. static void get_clipboard();
  2294.  
  2295. void paste_panel_key(w, event)
  2296. Widget w;
  2297. XKeyEvent *event;
  2298. {
  2299.     Time event_time;
  2300.  
  2301.         event_time = event->time;
  2302.         XtGetSelectionValue(w, XA_PRIMARY, XA_STRING, get_clipboard, w, event_time);
  2303. }
  2304.  
  2305. static void get_clipboard(w, client_data, selection, type, buf, length, format)
  2306. Widget w;
  2307. XtPointer client_data;
  2308. Atom *selection;
  2309. Atom *type;
  2310. XtPointer buf;
  2311. unsigned long *length;
  2312. int *format;
  2313. {
  2314.     char *c, *p;
  2315.     int i;
  2316.     char s[256];
  2317.  
  2318.     strcpy (s, panel_get_value(client_data));
  2319.     p = strchr(s, '\0');
  2320.     c = buf;
  2321.     for (i=0; i<*length; i++) {
  2322.         if (*c=='\0' || *c=='\n' || *c=='\r' || strlen(s)>=sizeof(s)-1)
  2323.             break;
  2324.         *p = *c;
  2325.         p++;
  2326.         *p = '\0';
  2327.         c++;
  2328.     }
  2329.     XtFree(buf);
  2330.     panel_set_value(client_data, s);
  2331. }
  2332.