home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / amiga / gui / x / xfig.lha / src / x11 / e_update.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-26  |  12.0 KB  |  425 lines

  1. /*
  2.  * FIG : Facility for Interactive Generation of figures
  3.  * Copyright (c) 1985 by Supoj Sutanthavibul
  4.  *
  5.  * "Permission to use, copy, modify, distribute, and sell this software and its
  6.  * documentation for any purpose is hereby granted without fee, provided that
  7.  * the above copyright notice appear in all copies and that both the copyright
  8.  * notice and this permission notice appear in supporting documentation. 
  9.  * No representations are made about the suitability of this software for 
  10.  * any purpose.  It is provided "as is" without express or implied warranty."
  11.  */
  12.  
  13. #include "fig.h"
  14. #include "resources.h"
  15. #include "object.h"
  16. #include "mode.h"
  17. #include "paintop.h"
  18. #include "u_create.h"
  19. #include "u_list.h"
  20. #include "u_search.h"
  21. #include "w_canvas.h"
  22. #include "w_drawprim.h"
  23. #include "w_indpanel.h"
  24. #include "w_mousefun.h"
  25.  
  26. extern        update_current_settings();
  27. static int    init_update_object();
  28. static int    init_update_settings();
  29.  
  30. #define    up_part(lv,rv,mask) \
  31.         if (cur_updatemask & (mask)) \
  32.             (lv) = (rv)
  33.  
  34. update_selected()
  35. {
  36.     set_mousefun("update object", "update settings", "");
  37.     canvas_kbd_proc = null_proc;
  38.     canvas_locmove_proc = null_proc;
  39.     init_searchproc_left(init_update_object);
  40.     init_searchproc_middle(init_update_settings);
  41.     canvas_leftbut_proc = object_search_left;
  42.     canvas_middlebut_proc = object_search_middle;
  43.     canvas_rightbut_proc = null_proc;
  44.     set_cursor(pick9_cursor);
  45.     /* manage on the update buttons */
  46.     manage_update_buts();
  47. }
  48.  
  49. static
  50. get_arrow_mode(object)
  51.     F_line       *object;
  52. {
  53.     if (!object->for_arrow && !object->back_arrow)
  54.     return L_NOARROWS;
  55.     else if (object->for_arrow && !object->back_arrow)
  56.     return L_FARROWS;
  57.     else if (!object->for_arrow && object->back_arrow)
  58.     return L_BARROWS;
  59.     else
  60.     return L_FBARROWS;
  61. }
  62.     
  63. static
  64. init_update_settings(p, type, x, y, px, py)
  65.     char       *p;
  66.     int            type;
  67.     int            x, y;
  68.     int            px, py;
  69. {
  70.     int        old_psfont_flag, new_psfont_flag;
  71.  
  72.     switch (type) {
  73.     case O_COMPOUND:
  74.     put_msg("There is no support for updating settings from a compound object");
  75.     return;
  76.     case O_POLYLINE:
  77.     cur_l = (F_line *) p;
  78.     if (cur_l->type != T_EPS_BOX) {
  79.         up_part(cur_linewidth, cur_l->thickness, I_LINEWIDTH);
  80.         up_part(cur_fillstyle, cur_l->fill_style, I_FILLSTYLE);
  81.         up_part(cur_color, cur_l->color, I_COLOR);
  82.         up_part(cur_linestyle, cur_l->style, I_LINESTYLE);
  83.         up_part(cur_styleval, cur_l->style_val, I_LINESTYLE);
  84.         up_part(cur_arrowmode, get_arrow_mode(cur_l), I_ARROWMODE);
  85.         }
  86.     up_part(cur_depth, cur_l->depth, I_DEPTH);
  87.     if (cur_l->type == T_ARC_BOX)
  88.         up_part(cur_boxradius, cur_l->radius, I_BOXRADIUS);
  89.     break;
  90.     case O_TEXT:
  91.     cur_t = (F_text *) p;
  92.     up_part(cur_textjust, cur_t->type, I_TEXTJUST);
  93.     up_part(cur_color, cur_t->color, I_COLOR);
  94.     up_part(cur_depth, cur_t->depth, I_DEPTH);
  95.     up_part(cur_elltextangle, cur_t->angle/M_PI*180.0, I_ELLTEXTANGLE);
  96.     old_psfont_flag = (cur_t->flags & PSFONT_TEXT);
  97.     new_psfont_flag = (cur_textflags & PSFONT_TEXT);
  98.     up_part(cur_textflags, cur_t->flags & ~PSFONT_TEXT, I_TEXTFLAGS);
  99.     if (cur_updatemask & I_FONT)
  100.         cur_textflags |= new_psfont_flag;
  101.     else
  102.         cur_textflags |= old_psfont_flag;
  103.     if (using_ps)
  104.         {    /* must use {} because macro has 'if' */
  105.         up_part(cur_ps_font, cur_t->font, I_FONT);
  106.         }
  107.     else
  108.         {    /* must use {} because macro has 'if' */
  109.         up_part(cur_latex_font, cur_t->font, I_FONT);
  110.         }
  111.     up_part(cur_fontsize, cur_t->size, I_FONTSIZE);
  112.     break;
  113.     case O_ELLIPSE:
  114.     cur_e = (F_ellipse *) p;
  115.     up_part(cur_linewidth, cur_e->thickness, I_LINEWIDTH);
  116.     up_part(cur_elltextangle, cur_e->angle/M_PI*180.0, I_ELLTEXTANGLE);
  117.     up_part(cur_fillstyle, cur_e->fill_style, I_FILLSTYLE);
  118.     up_part(cur_color, cur_e->color, I_COLOR);
  119.     up_part(cur_linestyle, cur_e->style, I_LINESTYLE);
  120.     up_part(cur_styleval, cur_e->style_val, I_LINESTYLE);
  121.     up_part(cur_depth, cur_e->depth, I_DEPTH);
  122.     break;
  123.     case O_ARC:
  124.     cur_a = (F_arc *) p;
  125.     up_part(cur_linewidth, cur_a->thickness, I_LINEWIDTH);
  126.     up_part(cur_fillstyle, cur_a->fill_style, I_FILLSTYLE);
  127.     up_part(cur_color, cur_a->color, I_COLOR);
  128.     up_part(cur_linestyle, cur_a->style, I_LINESTYLE);
  129.     up_part(cur_styleval, cur_a->style_val, I_LINESTYLE);
  130.     up_part(cur_depth, cur_a->depth, I_DEPTH);
  131.     up_part(cur_arrowmode, get_arrow_mode(cur_a), I_ARROWMODE);
  132.     break;
  133.     case O_SPLINE:
  134.     cur_s = (F_spline *) p;
  135.     up_part(cur_linewidth, cur_s->thickness, I_LINEWIDTH);
  136.     up_part(cur_fillstyle, cur_s->fill_style, I_FILLSTYLE);
  137.     up_part(cur_color, cur_s->color, I_COLOR);
  138.     up_part(cur_linestyle, cur_s->style, I_LINESTYLE);
  139.     up_part(cur_styleval, cur_s->style_val, I_LINESTYLE);
  140.     up_part(cur_depth, cur_s->depth, I_DEPTH);
  141.     up_part(cur_arrowmode, get_arrow_mode(cur_s), I_ARROWMODE);
  142.     break;
  143.     default:
  144.     return;
  145.     }
  146.     update_current_settings();
  147.     put_msg("Settings UPDATED");
  148. }
  149.  
  150. static
  151. init_update_object(p, type, x, y, px, py)
  152.     char       *p;
  153.     int            type;
  154.     int            x, y;
  155.     int            px, py;
  156. {
  157.     switch (type) {
  158.     case O_COMPOUND:
  159.     set_temp_cursor(wait_cursor);
  160.     cur_c = (F_compound *) p;
  161.     toggle_compoundmarker(cur_c);
  162.     new_c = copy_compound(cur_c);
  163.     update_compound(new_c);
  164.     change_compound(cur_c, new_c);
  165.     toggle_compoundmarker(new_c);
  166.     break;
  167.     case O_POLYLINE:
  168.     set_temp_cursor(wait_cursor);
  169.     cur_l = (F_line *) p;
  170.     toggle_linemarker(cur_l);
  171.     new_l = copy_line(cur_l);
  172.     update_line(new_l);
  173.     change_line(cur_l, new_l);
  174.     toggle_linemarker(new_l);
  175.     break;
  176.     case O_TEXT:
  177.     set_temp_cursor(wait_cursor);
  178.     cur_t = (F_text *) p;
  179.     toggle_textmarker(cur_t);
  180.     new_t = copy_text(cur_t);
  181.     update_text(new_t);
  182.     change_text(cur_t, new_t);
  183.     toggle_textmarker(new_t);
  184.     break;
  185.     case O_ELLIPSE:
  186.     set_temp_cursor(wait_cursor);
  187.     cur_e = (F_ellipse *) p;
  188.     toggle_ellipsemarker(cur_e);
  189.     new_e = copy_ellipse(cur_e);
  190.     update_ellipse(new_e);
  191.     change_ellipse(cur_e, new_e);
  192.     toggle_ellipsemarker(new_e);
  193.     break;
  194.     case O_ARC:
  195.     set_temp_cursor(wait_cursor);
  196.     cur_a = (F_arc *) p;
  197.     toggle_arcmarker(cur_a);
  198.     new_a = copy_arc(cur_a);
  199.     update_arc(new_a);
  200.     change_arc(cur_a, new_a);
  201.     toggle_arcmarker(new_a);
  202.     break;
  203.     case O_SPLINE:
  204.     set_temp_cursor(wait_cursor);
  205.     cur_s = (F_spline *) p;
  206.     toggle_splinemarker(cur_s);
  207.     new_s = copy_spline(cur_s);
  208.     update_spline(new_s);
  209.     change_spline(cur_s, new_s);
  210.     toggle_splinemarker(new_s);
  211.     break;
  212.     default:
  213.     return;
  214.     }
  215.     reset_cursor();
  216.     put_msg("Object(s) UPDATED");
  217. }
  218.  
  219. update_ellipse(ellipse)
  220.     F_ellipse       *ellipse;
  221. {
  222.     draw_ellipse(ellipse, ERASE);
  223.     up_part(ellipse->thickness, cur_linewidth, I_LINEWIDTH);
  224.     up_part(ellipse->angle, cur_elltextangle*M_PI/180.0, I_ELLTEXTANGLE);
  225.     up_part(ellipse->style, cur_linestyle, I_LINESTYLE);
  226.     up_part(ellipse->style_val, cur_styleval * (cur_linewidth + 1) / 2, 
  227.         I_LINESTYLE);
  228.     up_part(ellipse->fill_style, cur_fillstyle, I_FILLSTYLE);
  229.     up_part(ellipse->color, cur_color, I_COLOR);
  230.     up_part(ellipse->depth, cur_depth, I_DEPTH);
  231.     draw_ellipse(ellipse, PAINT);
  232. }
  233.  
  234. update_arc(arc)
  235.     F_arc       *arc;
  236. {
  237.     draw_arc(arc, ERASE);
  238.     up_part(arc->thickness, cur_linewidth, I_LINEWIDTH);
  239.     up_part(arc->style, cur_linestyle, I_LINESTYLE);
  240.     up_part(arc->style_val, cur_styleval * (cur_linewidth + 1) / 2, 
  241.         I_LINESTYLE);
  242.     up_part(arc->fill_style, cur_fillstyle, I_FILLSTYLE);
  243.     up_part(arc->color, cur_color, I_COLOR);
  244.     up_part(arc->depth, cur_depth, I_DEPTH);
  245.     if (autoforwardarrow_mode)
  246.     {    /* must use {} because macro has 'if' */
  247.     up_part(arc->for_arrow, forward_arrow(), I_ARROWMODE);
  248.     }
  249.     else
  250.     {    /* must use {} because macro has 'if' */
  251.     up_part(arc->for_arrow, NULL, I_ARROWMODE);
  252.     }
  253.     if (autobackwardarrow_mode)
  254.     {    /* must use {} because macro has 'if' */
  255.     up_part(arc->back_arrow, backward_arrow(), I_ARROWMODE);
  256.     }
  257.     else
  258.     {    /* must use {} because macro has 'if' */
  259.     up_part(arc->back_arrow, NULL, I_ARROWMODE);
  260.     }
  261.     draw_arc(arc, PAINT);
  262. }
  263.  
  264. update_line(line)
  265.     F_line       *line;
  266. {
  267.     draw_line(line, ERASE);
  268.     if (line->type != T_EPS_BOX) {
  269.     up_part(line->thickness, cur_linewidth, I_LINEWIDTH);
  270.     up_part(line->style, cur_linestyle, I_LINESTYLE);
  271.     up_part(line->style_val, cur_styleval * (cur_linewidth + 1) / 2, 
  272.         I_LINESTYLE);
  273.     up_part(line->color, cur_color, I_COLOR);
  274.     up_part(line->radius, cur_boxradius, I_BOXRADIUS);
  275.     up_part(line->fill_style, cur_fillstyle, I_FILLSTYLE);
  276.     }
  277.     up_part(line->depth, cur_depth, I_DEPTH);
  278.     if (line->type == T_POLYLINE && line->points->next != NULL) {
  279.     if (autoforwardarrow_mode)
  280.         {    /* must use {} because macro has 'if' */
  281.         up_part(line->for_arrow, forward_arrow(), I_ARROWMODE);
  282.         }
  283.     else
  284.         {    /* must use {} because macro has 'if' */
  285.         up_part(line->for_arrow, NULL, I_ARROWMODE);
  286.         }
  287.     if (autobackwardarrow_mode)
  288.         {    /* must use {} because macro has 'if' */
  289.         up_part(line->back_arrow, backward_arrow(), I_ARROWMODE);
  290.         }
  291.     else
  292.         {    /* must use {} because macro has 'if' */
  293.         up_part(line->back_arrow, NULL, I_ARROWMODE);
  294.         }
  295.     }
  296.     draw_line(line, PAINT);
  297. }
  298.  
  299. update_text(text)
  300.     F_text       *text;
  301. {
  302.     PR_SIZE        size;
  303.     int        old_psfont_flag, new_psfont_flag;
  304.  
  305.     draw_text(text, ERASE);
  306.     up_part(text->type, cur_textjust, I_TEXTJUST);
  307.     up_part(text->font, using_ps ? cur_ps_font : cur_latex_font, I_FONT);
  308.     old_psfont_flag = (text->flags & PSFONT_TEXT);
  309.     new_psfont_flag = (cur_textflags & PSFONT_TEXT);
  310.     up_part(text->flags, cur_textflags & ~PSFONT_TEXT, I_TEXTFLAGS);
  311.     if (cur_updatemask & I_FONT)
  312.     text->flags |= new_psfont_flag;
  313.     else
  314.     text->flags |= old_psfont_flag;
  315.     up_part(text->size, cur_fontsize, I_FONTSIZE);
  316.     up_part(text->angle, cur_elltextangle*M_PI/180.0, I_ELLTEXTANGLE);
  317.     up_part(text->color, cur_color, I_COLOR);
  318.     up_part(text->depth, cur_depth, I_DEPTH);
  319.     size = pf_textwidth(lookfont(x_fontnum(text->flags, text->font), text->size,
  320.             cur_elltextangle), strlen(text->cstring), text->cstring);
  321.     text->length = size.x;    /* in pixels */
  322.     text->height = size.y;    /* in pixels */
  323.     reload_text_fstruct(text);    /* make sure fontstruct is current */
  324.     draw_text(text, PAINT);
  325. }
  326.  
  327. update_spline(spline)
  328.     F_spline       *spline;
  329. {
  330.     draw_spline(spline, ERASE);
  331.     up_part(spline->thickness, cur_linewidth, I_LINEWIDTH);
  332.     up_part(spline->style, cur_linestyle, I_LINESTYLE);
  333.     up_part(spline->style_val, cur_styleval * (cur_linewidth + 1) / 2, 
  334.         I_LINESTYLE);
  335.     up_part(spline->fill_style, cur_fillstyle, I_FILLSTYLE);
  336.     up_part(spline->color, cur_color, I_COLOR);
  337.     up_part(spline->depth, cur_depth, I_DEPTH);
  338.     if (open_spline(spline)) {
  339.     if (autoforwardarrow_mode)
  340.         {    /* must use {} because macro has 'if' */
  341.         up_part(spline->for_arrow, forward_arrow(), I_ARROWMODE);
  342.         }
  343.     else
  344.         {    /* must use {} because macro has 'if' */
  345.         up_part(spline->for_arrow, NULL, I_ARROWMODE);
  346.         }
  347.     if (autobackwardarrow_mode)
  348.         {    /* must use {} because macro has 'if' */
  349.         up_part(spline->back_arrow, backward_arrow(), I_ARROWMODE);
  350.         }
  351.     else
  352.         {    /* must use {} because macro has 'if' */
  353.         up_part(spline->back_arrow, NULL, I_ARROWMODE);
  354.         }
  355.     }
  356.     draw_spline(spline, PAINT);
  357. }
  358.  
  359. update_compound(compound)
  360.     F_compound       *compound;
  361. {
  362.     update_lines(compound->lines);
  363.     update_splines(compound->splines);
  364.     update_ellipses(compound->ellipses);
  365.     update_arcs(compound->arcs);
  366.     update_texts(compound->texts);
  367.     update_compounds(compound->compounds);
  368.     compound_bound(compound, &compound->nwcorner.x, &compound->nwcorner.y,
  369.            &compound->secorner.x, &compound->secorner.y);
  370. }
  371.  
  372. update_arcs(arcs)
  373.     F_arc       *arcs;
  374. {
  375.     F_arc       *a;
  376.  
  377.     for (a = arcs; a != NULL; a = a->next)
  378.     update_arc(a);
  379. }
  380.  
  381. update_compounds(compounds)
  382.     F_compound       *compounds;
  383. {
  384.     F_compound       *c;
  385.  
  386.     for (c = compounds; c != NULL; c = c->next)
  387.     update_compound(c);
  388. }
  389.  
  390. update_ellipses(ellipses)
  391.     F_ellipse       *ellipses;
  392. {
  393.     F_ellipse       *e;
  394.  
  395.     for (e = ellipses; e != NULL; e = e->next)
  396.     update_ellipse(e);
  397. }
  398.  
  399. update_lines(lines)
  400.     F_line       *lines;
  401. {
  402.     F_line       *l;
  403.  
  404.     for (l = lines; l != NULL; l = l->next)
  405.     update_line(l);
  406. }
  407.  
  408. update_splines(splines)
  409.     F_spline       *splines;
  410. {
  411.     F_spline       *s;
  412.  
  413.     for (s = splines; s != NULL; s = s->next)
  414.     update_spline(s);
  415. }
  416.  
  417. update_texts(texts)
  418.     F_text       *texts;
  419. {
  420.     F_text       *t;
  421.  
  422.     for (t = texts; t != NULL; t = t->next)
  423.     update_text(t);
  424. }
  425.