home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume19 / xfig / part05 / e_delete.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-27  |  5.9 KB  |  255 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 "mode.h"
  16. #include "object.h"
  17. #include "paintop.h"
  18. #include "u_create.h"
  19. #include "u_draw.h"
  20. #include "u_elastic.h"
  21. #include "u_search.h"
  22. #include "u_list.h"
  23. #include "u_undo.h"
  24. #include "w_canvas.h"
  25. #include "w_mousefun.h"
  26. #include "w_setup.h"
  27.  
  28. static int    init_delete();
  29. static int    init_delete_region(), delete_region(), cancel_delete_region();
  30. static int    init_delete_to_scrap();
  31.  
  32. delete_selected()
  33. {
  34.     set_mousefun("delete object", "delete region", "del to cut buf");
  35.     canvas_kbd_proc = null_proc;
  36.     canvas_locmove_proc = null_proc;
  37.     init_searchproc_left(init_delete);
  38.     init_searchproc_right(init_delete_to_scrap);
  39.     canvas_leftbut_proc = object_search_left;
  40.     canvas_rightbut_proc = object_search_right;
  41.     canvas_middlebut_proc = init_delete_region;
  42.     set_cursor(buster_cursor);
  43.     reset_action_on();
  44. }
  45.  
  46. static
  47. init_delete(p, type, x, y, px, py)
  48.     char       *p;
  49.     int            type;
  50.     int            x, y;
  51.     int            px, py;
  52. {
  53.     switch (type) {
  54.     case O_COMPOUND:
  55.     cur_c = (F_compound *) p;
  56.     delete_compound(cur_c);
  57.     redisplay_compound(cur_c);
  58.     break;
  59.     case O_POLYLINE:
  60.     cur_l = (F_line *) p;
  61.     delete_line(cur_l);
  62.     redisplay_line(cur_l);
  63.     break;
  64.     case O_TEXT:
  65.     cur_t = (F_text *) p;
  66.     delete_text(cur_t);
  67.     redisplay_text(cur_t);
  68.     break;
  69.     case O_ELLIPSE:
  70.     cur_e = (F_ellipse *) p;
  71.     delete_ellipse(cur_e);
  72.     redisplay_ellipse(cur_e);
  73.     break;
  74.     case O_ARC:
  75.     cur_a = (F_arc *) p;
  76.     delete_arc(cur_a);
  77.     redisplay_arc(cur_a);
  78.     break;
  79.     case O_SPLINE:
  80.     cur_s = (F_spline *) p;
  81.     delete_spline(cur_s);
  82.     redisplay_spline(cur_s);
  83.     break;
  84.     default:
  85.     return;
  86.     }
  87. }
  88.  
  89. static
  90. init_delete_region(x, y)
  91.     int            x, y;
  92. {
  93.     init_box_drawing(x, y);
  94.     set_mousefun("", "final corner", "cancel");
  95.     draw_mousefun_canvas();
  96.     canvas_leftbut_proc = null_proc;
  97.     canvas_middlebut_proc = delete_region;
  98.     canvas_rightbut_proc = cancel_delete_region;
  99. }
  100.  
  101. static
  102. cancel_delete_region()
  103. {
  104.     elastic_box(fix_x, fix_y, cur_x, cur_y);
  105.     delete_selected();
  106.     draw_mousefun_canvas();
  107. }
  108.  
  109. static
  110. delete_region(x, y)
  111.     int            x, y;
  112. {
  113.     F_compound       *c;
  114.  
  115.     if ((c = create_compound()) == NULL)
  116.     return;
  117.  
  118.     elastic_box(fix_x, fix_y, cur_x, cur_y);
  119.     c->nwcorner.x = min2(fix_x, x);
  120.     c->nwcorner.y = min2(fix_y, y);
  121.     c->secorner.x = max2(fix_x, x);
  122.     c->secorner.y = max2(fix_y, y);
  123.     tag_obj_in_region(c->nwcorner.x,c->nwcorner.y,c->secorner.x,c->secorner.y);
  124.     if (compose_compound(c) == 0) {
  125.     free((char *) c);
  126.     delete_selected();
  127.     draw_mousefun_canvas();
  128.     put_msg("Empty region, figure unchanged");
  129.     return;
  130.     }
  131.     clean_up();
  132.     toggle_markers_in_compound(c);
  133.     set_tags(c,0);
  134.     set_latestobjects(c);
  135.     tail(&objects, &object_tails);
  136.     append_objects(&objects, &saved_objects, &object_tails);
  137.     cut_objects(&objects, &object_tails);
  138.     set_action_object(F_DELETE, O_ALL_OBJECT);
  139.     set_modifiedflag();
  140.     redisplay_compound(c);
  141.     delete_selected();
  142.     draw_mousefun_canvas();
  143. }
  144.  
  145. static
  146. init_delete_to_scrap(p, type, x, y, px, py)
  147.     char       *p;
  148.     int            type;
  149.     int            x, y;
  150.     int            px, py;
  151. {
  152.     extern char        cut_buf_name[];
  153.     extern char        file_header[];
  154.  
  155.     FILE       *fp;
  156.     struct stat        file_status;
  157.  
  158.     if (stat(cut_buf_name, &file_status) == 0) {    /* file exists */
  159.     if (file_status.st_mode & S_IFDIR) {
  160.         put_msg("Error: \"%s\" is a directory", cut_buf_name);
  161.         return;
  162.     }
  163.     if (file_status.st_mode & S_IWRITE) {    /* writing is permitted */
  164.         if (file_status.st_uid != geteuid()) {
  165.         put_msg("Error: access denied to cut file");
  166.         return;
  167.         }
  168.     } else {
  169.         put_msg("Error: cut file is read only");
  170.         return;
  171.     }
  172.     } else if (errno != ENOENT) {
  173.     put_msg("Error: cut file didn't pass stat check");
  174.     return;            /* file does exist but stat fails */
  175.     }
  176.     if ((fp = fopen(cut_buf_name, "w")) == NULL) {
  177.     put_msg("Error: couldn't open cut file %s", sys_errlist[errno]);
  178.     return;
  179.     } else {
  180.     (void) fprintf(fp, "%s\n", file_header);
  181.     (void) fprintf(fp, "%d %d\n", PIX_PER_INCH, 2);
  182.     }
  183.  
  184.     switch (type) {
  185.     case O_COMPOUND:
  186.     cur_c = (F_compound *) p;
  187.     write_compound(fp, cur_c);
  188.     delete_compound(cur_c);
  189.     redisplay_compound(cur_c);
  190.     break;
  191.     case O_POLYLINE:
  192.     cur_l = (F_line *) p;
  193.     write_line(fp, cur_l);
  194.     delete_line(cur_l);
  195.     redisplay_line(cur_l);
  196.     break;
  197.     case O_TEXT:
  198.     cur_t = (F_text *) p;
  199.     write_text(fp, cur_t);
  200.     delete_text(cur_t);
  201.     redisplay_text(cur_t);
  202.     break;
  203.     case O_ELLIPSE:
  204.     cur_e = (F_ellipse *) p;
  205.     write_ellipse(fp, cur_e);
  206.     delete_ellipse(cur_e);
  207.     redisplay_ellipse(cur_e);
  208.     break;
  209.     case O_ARC:
  210.     cur_a = (F_arc *) p;
  211.     write_arc(fp, cur_a);
  212.     delete_arc(cur_a);
  213.     redisplay_arc(cur_a);
  214.     break;
  215.     case O_SPLINE:
  216.     cur_s = (F_spline *) p;
  217.     write_spline(fp, cur_s);
  218.     delete_spline(cur_s);
  219.     redisplay_spline(cur_s);
  220.     break;
  221.     default:
  222.     fclose(fp);
  223.     return;
  224.     }
  225.     put_msg("Object deleted to scrap");
  226.     fclose(fp);
  227. }
  228.  
  229. delete_all()
  230. {
  231.     clean_up();
  232.     set_action_object(F_DELETE, O_ALL_OBJECT);
  233.  
  234.     /*
  235.      * Aggregate assignment between variables is allowed, but not from
  236.      * constant (weird!?)
  237.      */
  238.  
  239.     set_latestobjects(&objects);
  240.  
  241.     objects.arcs = NULL;
  242.     objects.compounds = NULL;
  243.     objects.ellipses = NULL;
  244.     objects.lines = NULL;
  245.     objects.splines = NULL;
  246.     objects.texts = NULL;
  247.  
  248.     object_tails.arcs = NULL;
  249.     object_tails.compounds = NULL;
  250.     object_tails.ellipses = NULL;
  251.     object_tails.lines = NULL;
  252.     object_tails.splines = NULL;
  253.     object_tails.texts = NULL;
  254. }
  255.