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
|
/*
* FIG : Facility for Interactive Generation of figures
* Copyright (c) 1985-1988 by Supoj Sutanthavibul
* Parts Copyright (c) 1989-1998 by Brian V. Smith
* Parts Copyright (c) 1991 by Paul King
* Parts Copyright (c) 1994 by Bill Taylor
* "Enter Compound" written by Bill Taylor (bill@mainstream.com) 1994
*
* 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.
*
*/
/*
* open_compound lets the user select a compound with the left button,
* then replaces the current drawing with that compound alone so that the
* user can edit the insides of that compound without taking it apart.
*
* close_compound pops out one compound; close_all_compounds pops all the way out.
*
*/
#include "fig.h"
#include "figx.h"
#include "resources.h"
#include "mode.h"
#include "object.h"
#include "u_search.h"
#include "w_canvas.h"
#include "w_setup.h"
#include "w_util.h"
Widget close_compound_popup;
Boolean close_popup_isup = False;
static void
init_open_compound(c, type, x, y, px, py, loc_tag)
F_compound *c;
int type;
int x, y;
int px, py;
int loc_tag;
{
F_compound *d;
if (type != O_COMPOUND)
return;
mask_toggle_compoundmarker(c);
c->parent = d = malloc(sizeof(F_compound));
*d = objects; /* Preserve the parent, it points to c */
objects = *c;
objects.GABPtr = c; /* Where original compound came from */
if (!close_popup_isup)
popup_close_compound();
redisplay_canvas();
}
void
open_compound()
{
/* prepatory functions done for mode operations by sel_mode_but */
update_markers((int)M_COMPOUND);
set_mousefun("open compound", "", "", LOC_OBJ, LOC_OBJ, LOC_OBJ);
canvas_kbd_proc = null_proc;
canvas_locmove_proc = null_proc;
init_searchproc_left(init_open_compound);
canvas_leftbut_proc = object_search_left;
canvas_middlebut_proc = null_proc;
canvas_rightbut_proc = null_proc;
set_cursor(pick15_cursor);
}
void
close_compound()
{
F_compound *c;
F_compound *d; /* Destination */
/* if trying to close compound while drawing an object, don't allow it */
if (check_action_on())
return;
if (c = (F_compound *)objects.parent) {
objects.parent = NULL;
d = (F_compound *)objects.GABPtr; /* Where this compound was */
objects.GABPtr = NULL;
/* compute new bounding box if changed */
compound_bound(&objects, &objects.nwcorner.x, &objects.nwcorner.y,
&objects.secorner.x, &objects.secorner.y);
*d = objects; /* Put in any changes */
objects = *c; /* Restore compound above */
/* user may have deleted all objects inside the compound */
if (object_count(d)==0) {
list_delete_compound(&objects.compounds, d);
}
free(c);
/* popdown close panel if this is the last one */
if ((F_compound *)objects.parent == NULL) {
XtPopdown(close_compound_popup);
XtDestroyWidget(close_compound_popup);
close_popup_isup = False;
}
redisplay_canvas();
}
}
void
close_all_compounds()
{
F_compound *c;
F_compound *d; /* Destination */
/* if trying to close compound while drawing an object, don't allow it */
if (check_action_on())
return;
if (objects.parent) {
while (c = (F_compound *)objects.parent) {
objects.parent = NULL;
d = (F_compound *)objects.GABPtr; /* Where this compound was */
objects.GABPtr = NULL;
/* compute new bounding box if changed */
compound_bound(&objects, &objects.nwcorner.x, &objects.nwcorner.y,
&objects.secorner.x, &objects.secorner.y);
*d = objects; /* Put in any changes */
objects = *c;
/* user may have deleted all objects inside the compound */
if (object_count(d)==0) {
list_delete_compound(&objects.compounds, d);
}
free(c);
}
/* popdown close panel */
XtPopdown(close_compound_popup);
XtDestroyWidget(close_compound_popup);
close_popup_isup = False;
redisplay_canvas();
}
}
popup_close_compound()
{
Widget close_compound_form;
Widget close_compoundw, close_compound_allw;
int xposn, yposn;
Window win;
DeclareArgs(10);
/* put the window in the upper-left corner of the canvas */
XTranslateCoordinates(tool_d, main_canvas, XDefaultRootWindow(tool_d),
20, 20, &xposn, &yposn, &win);
FirstArg(XtNallowShellResize, True);
NextArg(XtNx, xposn);
NextArg(XtNy, yposn);
NextArg(XtNtitle, "Xfig: Close Compound");
NextArg(XtNcolormap, tool_cm);
close_compound_popup = XtCreatePopupShell("close_compound_popup", transientShellWidgetClass,
tool, Args, ArgCount);
close_compound_form = XtCreateManagedWidget("close_compound_form", formWidgetClass,
close_compound_popup, (XtPointer) NULL, 0);
FirstArg(XtNlabel, "Close This Compound")
close_compoundw = XtCreateManagedWidget("close_compound", commandWidgetClass,
close_compound_form, Args, ArgCount);
XtAddEventHandler(close_compoundw, ButtonReleaseMask, (Boolean) 0,
(XtEventHandler)close_compound, (XtPointer) NULL);
FirstArg(XtNlabel, "Close All Compounds");
NextArg(XtNfromHoriz, close_compoundw);
close_compound_allw = XtCreateManagedWidget("close_all_compounds", commandWidgetClass,
close_compound_form, Args, ArgCount);
XtAddEventHandler(close_compound_allw, ButtonReleaseMask, (Boolean) 0,
(XtEventHandler)close_all_compounds, (XtPointer) NULL);
XtPopup(close_compound_popup, XtGrabNone);
/* insure that the most recent colormap is installed */
set_cmap(XtWindow(close_compound_popup));
(void) XSetWMProtocols(XtDisplay(close_compound_popup), XtWindow(close_compound_popup),
&wm_delete_window, 1);
XDefineCursor(tool_d, XtWindow(close_compound_popup), arrow_cursor);
close_popup_isup = True;
}
|