1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
|
/*
* FIG : Facility for Interactive Generation of figures
* Copyright (c) 1985-1988 by Supoj Sutanthavibul
* Parts Copyright (c) 1989-2000 by Brian V. Smith
* Parts Copyright (c) 1991 by Paul King
*
* Any party obtaining a copy of these files is granted, free of charge, a
* full and unrestricted irrevocable, world-wide, paid up, royalty-free,
* nonexclusive right and license to deal in this software and
* documentation files (the "Software"), including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons who receive
* copies from any such party to do so, with the only requirement being
* that this copyright notice remain intact.
*
*/
#include "fig.h"
#include "resources.h"
#include "mode.h"
#include "object.h"
#include "paintop.h"
#include "d_line.h"
#include "u_create.h"
#include "u_draw.h"
#include "u_elastic.h"
#include "u_redraw.h"
#include "u_search.h"
#include "u_list.h"
#include "u_undo.h"
#include "w_canvas.h"
#include "w_layers.h"
#include "w_mousefun.h"
#include "w_msgpanel.h"
#include "w_setup.h"
static void init_delete();
static void init_delete_region(), delete_region(), cancel_delete_region();
static void init_delete_to_scrap();
void
delete_selected()
{
set_mousefun("delete object", "delete region", "del to cut buf",
LOC_OBJ, "", LOC_OBJ);
canvas_kbd_proc = null_proc;
canvas_locmove_proc = null_proc;
init_searchproc_left(init_delete);
init_searchproc_right(init_delete_to_scrap);
canvas_leftbut_proc = object_search_left;
canvas_middlebut_proc = init_delete_region;
canvas_rightbut_proc = object_search_right;
set_cursor(buster_cursor);
reset_action_on();
}
static void
init_delete(p, type, x, y, px, py)
F_line *p;
int type;
int x, y;
int px, py;
{
switch (type) {
case O_COMPOUND:
cur_c = (F_compound *) p;
delete_compound(cur_c);
redisplay_compound(cur_c);
break;
case O_POLYLINE:
cur_l = (F_line *) p;
delete_line(cur_l);
redisplay_line(cur_l);
break;
case O_TEXT:
cur_t = (F_text *) p;
delete_text(cur_t);
redisplay_text(cur_t);
break;
case O_ELLIPSE:
cur_e = (F_ellipse *) p;
delete_ellipse(cur_e);
redisplay_ellipse(cur_e);
break;
case O_ARC:
cur_a = (F_arc *) p;
delete_arc(cur_a);
redisplay_arc(cur_a);
break;
case O_SPLINE:
cur_s = (F_spline *) p;
delete_spline(cur_s);
redisplay_spline(cur_s);
break;
default:
return;
}
}
static void
init_delete_region(x, y)
int x, y;
{
init_box_drawing(x, y);
set_mousefun("", "final corner", "cancel", "", "", "");
draw_mousefun_canvas();
canvas_leftbut_proc = null_proc;
canvas_middlebut_proc = delete_region;
canvas_rightbut_proc = cancel_delete_region;
}
static void
cancel_delete_region()
{
elastic_box(fix_x, fix_y, cur_x, cur_y);
/* erase last lengths if appres.showlengths is true */
erase_lengths();
delete_selected();
draw_mousefun_canvas();
}
static void
delete_region(x, y)
int x, y;
{
F_compound *c;
if ((c = create_compound()) == NULL)
return;
elastic_box(fix_x, fix_y, cur_x, cur_y);
/* erase last lengths if appres.showlengths is true */
erase_lengths();
c->nwcorner.x = min2(fix_x, x);
c->nwcorner.y = min2(fix_y, y);
c->secorner.x = max2(fix_x, x);
c->secorner.y = max2(fix_y, y);
tag_obj_in_region(c->nwcorner.x,c->nwcorner.y,c->secorner.x,c->secorner.y);
if (compose_compound(c) == 0) {
free((char *) c);
delete_selected();
draw_mousefun_canvas();
put_msg("Empty region, figure unchanged");
return;
}
clean_up();
toggle_markers_in_compound(c);
set_tags(c,0);
set_latestobjects(c);
tail(&objects, &object_tails);
append_objects(&objects, &saved_objects, &object_tails);
cut_objects(&objects, &object_tails);
set_action_object(F_DELETE, O_ALL_OBJECT);
set_modifiedflag();
redisplay_compound(c);
delete_selected();
draw_mousefun_canvas();
}
static void
init_delete_to_scrap(p, type, x, y, px, py)
F_line *p;
int type;
int x, y;
int px, py;
{
FILE *fp;
FILE *open_cut_file();
if ((fp=open_cut_file())==NULL)
return;
write_file_header(fp);
switch (type) {
case O_COMPOUND:
cur_c = (F_compound *) p;
write_compound(fp, cur_c);
delete_compound(cur_c);
redisplay_compound(cur_c);
break;
case O_POLYLINE:
cur_l = (F_line *) p;
write_line(fp, cur_l);
delete_line(cur_l);
redisplay_line(cur_l);
break;
case O_TEXT:
cur_t = (F_text *) p;
write_text(fp, cur_t);
delete_text(cur_t);
redisplay_text(cur_t);
break;
case O_ELLIPSE:
cur_e = (F_ellipse *) p;
write_ellipse(fp, cur_e);
delete_ellipse(cur_e);
redisplay_ellipse(cur_e);
break;
case O_ARC:
cur_a = (F_arc *) p;
write_arc(fp, cur_a);
delete_arc(cur_a);
redisplay_arc(cur_a);
break;
case O_SPLINE:
cur_s = (F_spline *) p;
write_spline(fp, cur_s);
delete_spline(cur_s);
redisplay_spline(cur_s);
break;
default:
fclose(fp);
return;
}
put_msg("Object deleted to scrapfile %s",cut_buf_name);
fclose(fp);
}
FILE *
open_cut_file()
{
FILE *fp;
struct stat file_status;
if (stat(cut_buf_name, &file_status) == 0) { /* file exists */
if (file_status.st_mode & S_IFDIR) {
put_msg("Error: \"%s\" is a directory", cut_buf_name);
return NULL;
}
if (file_status.st_mode & S_IWRITE) { /* writing is permitted */
if (file_status.st_uid != geteuid()) {
put_msg("Error: access denied to cut file");
return NULL;
}
} else {
put_msg("Error: cut file is read only");
return NULL;
}
} else if (errno != ENOENT) {
put_msg("Error: cut file didn't pass stat check");
return NULL; /* file does exist but stat fails */
}
if ((fp = fopen(cut_buf_name, "w")) == NULL) {
put_msg("Error: couldn't open cut file %s", sys_errlist[errno]);
return NULL;
}
return fp;
}
delete_all()
{
clean_up();
set_action_object(F_DELETE, O_ALL_OBJECT);
/* initialize layer/depth info */
reset_layers();
save_depths(saved_depths);
save_counts(&saved_counts[0]);
reset_depths();
clearallcounts();
/* in case the user is inside any compounds */
close_all_compounds();
set_latestobjects(&objects);
objects.arcs = NULL;
objects.compounds = NULL;
objects.ellipses = NULL;
objects.lines = NULL;
objects.splines = NULL;
objects.texts = NULL;
objects.comments = NULL;
object_tails.arcs = NULL;
object_tails.compounds = NULL;
object_tails.ellipses = NULL;
object_tails.lines = NULL;
object_tails.splines = NULL;
object_tails.texts = NULL;
}
|