~ubuntu-branches/ubuntu/trusty/xfig/trusty

« back to all changes in this revision

Viewing changes to e_compound.c

  • Committer: Bazaar Package Importer
  • Author(s): Roland Rosenfeld
  • Date: 2002-03-22 10:39:49 UTC
  • Revision ID: james.westby@ubuntu.com-20020322103949-63082hoxulq6n7u1
Tags: upstream-3.2.3.d-rel
ImportĀ upstreamĀ versionĀ 3.2.3.d-rel

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * FIG : Facility for Interactive Generation of figures
 
3
 * Copyright (c) 1985-1988 by Supoj Sutanthavibul
 
4
 * Parts Copyright (c) 1989-2000 by Brian V. Smith
 
5
 * Parts Copyright (c) 1991 by Paul King
 
6
 * Parts Copyright (c) 1994 by Bill Taylor
 
7
 *       "Enter Compound" written by Bill Taylor (bill@mainstream.com) 1994
 
8
 *
 
9
 * Any party obtaining a copy of these files is granted, free of charge, a
 
10
 * full and unrestricted irrevocable, world-wide, paid up, royalty-free,
 
11
 * nonexclusive right and license to deal in this software and
 
12
 * documentation files (the "Software"), including without limitation the
 
13
 * rights to use, copy, modify, merge, publish, distribute, sublicense,
 
14
 * and/or sell copies of the Software, and to permit persons who receive
 
15
 * copies from any such party to do so, with the only requirement being
 
16
 * that this copyright notice remain intact.
 
17
 *
 
18
 */
 
19
 
 
20
/*
 
21
 * open_compound lets the user select a compound with the left button,
 
22
 * then replaces the current drawing with that compound alone so that the
 
23
 * user can edit the insides of that compound without taking it apart.
 
24
 * 
 
25
 * close_compound pops out one compound; close_all_compounds pops all the way out.
 
26
 *
 
27
 */
 
28
 
 
29
#include "fig.h"
 
30
#include "figx.h"
 
31
#include "resources.h"
 
32
#include "mode.h"
 
33
#include "object.h"
 
34
#include "u_create.h"
 
35
#include "u_search.h"
 
36
#include "w_canvas.h"
 
37
#include "w_icons.h"
 
38
#include "w_setup.h"
 
39
#include "w_util.h"
 
40
#include "w_zoom.h"
 
41
 
 
42
Widget  close_compound_popup;
 
43
Boolean close_popup_isup = False;
 
44
void    open_this_compound();
 
45
 
 
46
static void
 
47
init_open_compound(c, type, x, y, px, py, loc_tag)
 
48
    F_compound     *c;
 
49
    int             type;
 
50
    int             x, y;
 
51
    int             px, py;
 
52
    int             loc_tag;
 
53
{
 
54
  if (type != O_COMPOUND)
 
55
    return;
 
56
        open_this_compound(c);
 
57
}
 
58
 
 
59
void
 
60
open_this_compound(c)
 
61
 F_compound *c;
 
62
{
 
63
  F_compound *d;
 
64
 
 
65
  mask_toggle_compoundmarker(c);
 
66
 
 
67
  c->parent = d = create_compound();
 
68
  *d = objects;                 /* Preserve the parent, it points to c */
 
69
  objects = *c;
 
70
  objects.GABPtr = c;           /* Where original compound came from */
 
71
  if (!close_popup_isup)
 
72
        popup_close_compound();
 
73
  redisplay_canvas();
 
74
}
 
75
 
 
76
void
 
77
open_compound()
 
78
{
 
79
  /* prepatory functions done for mode operations by sel_mode_but */
 
80
  update_markers((int)M_COMPOUND);
 
81
 
 
82
  set_mousefun("open compound", "", "", LOC_OBJ, LOC_OBJ, LOC_OBJ);
 
83
  canvas_kbd_proc = null_proc;
 
84
  canvas_locmove_proc = null_proc;
 
85
  init_searchproc_left(init_open_compound);
 
86
  canvas_leftbut_proc = object_search_left;
 
87
  canvas_middlebut_proc = null_proc;
 
88
  canvas_rightbut_proc = null_proc;
 
89
  set_cursor(pick15_cursor);
 
90
}
 
91
 
 
92
void
 
93
close_compound()
 
94
{
 
95
  F_compound *c;
 
96
  F_compound *d;                /* Destination */
 
97
 
 
98
  /* if trying to close compound while drawing an object, don't allow it */
 
99
  if (check_action_on())
 
100
        return;
 
101
  if (c = (F_compound *)objects.parent) {
 
102
    objects.parent = NULL;
 
103
    d = (F_compound *)objects.GABPtr;   /* Where this compound was */
 
104
    objects.GABPtr   = NULL;
 
105
    /* compute new bounding box if changed */
 
106
    compound_bound(&objects, &objects.nwcorner.x, &objects.nwcorner.y,
 
107
                        &objects.secorner.x, &objects.secorner.y);
 
108
    *d = objects;               /* Put in any changes */
 
109
    objects = *c;               /* Restore compound above */
 
110
    /* user may have deleted all objects inside the compound */
 
111
    if (object_count(d)==0) {
 
112
        list_delete_compound(&objects.compounds, d);
 
113
    }
 
114
    free(c);
 
115
    /* popdown close panel if this is the last one */
 
116
    if ((F_compound *)objects.parent == NULL) {
 
117
        XtPopdown(close_compound_popup);
 
118
        XtDestroyWidget(close_compound_popup);
 
119
        close_popup_isup = False;
 
120
    }
 
121
    redisplay_canvas();
 
122
    /* re-select open compound mode */
 
123
    change_mode(&open_comp_ic);
 
124
  }
 
125
}
 
126
 
 
127
void
 
128
close_all_compounds()
 
129
{
 
130
  F_compound *c;
 
131
  F_compound *d;                /* Destination */
 
132
 
 
133
  /* if trying to close compound while drawing an object, don't allow it */
 
134
  if (check_action_on())
 
135
        return;
 
136
  if (objects.parent) {
 
137
    while (c = (F_compound *)objects.parent) {
 
138
      objects.parent = NULL;
 
139
      d = (F_compound *)objects.GABPtr; /* Where this compound was */
 
140
      objects.GABPtr   = NULL;
 
141
      /* compute new bounding box if changed */
 
142
      compound_bound(&objects, &objects.nwcorner.x, &objects.nwcorner.y,
 
143
                        &objects.secorner.x, &objects.secorner.y);
 
144
      *d = objects;             /* Put in any changes */
 
145
      objects = *c;
 
146
      /* user may have deleted all objects inside the compound */
 
147
      if (object_count(d)==0) {
 
148
        list_delete_compound(&objects.compounds, d);
 
149
      }
 
150
      free(c);
 
151
    }
 
152
    /* popdown close panel */
 
153
    XtPopdown(close_compound_popup);
 
154
    XtDestroyWidget(close_compound_popup);
 
155
    close_popup_isup = False;
 
156
    redisplay_canvas();
 
157
    /* re-select open compound mode */
 
158
    change_mode(&open_comp_ic);
 
159
  }
 
160
}
 
161
 
 
162
popup_close_compound()
 
163
{
 
164
    Widget          close_compound_form;
 
165
    Widget          close_compoundw, close_compound_allw;
 
166
    Position        xposn, yposn;
 
167
    Window          win;
 
168
    XtWidgetGeometry xtgeom,comp;
 
169
    int              llx, lly, urx, ury, dum;
 
170
 
 
171
    DeclareArgs(10);
 
172
 
 
173
    /* position the popup above the compound we're opening */
 
174
    compound_bound(&objects, &llx, &lly, &urx, &ury);
 
175
 
 
176
    /* translate object coords to screen coords relative to the canvas */
 
177
    llx = ZOOMX(llx);
 
178
    lly = ZOOMY(lly);
 
179
 
 
180
    /* translate those to absolute screen coords */
 
181
    XtTranslateCoords(canvas_sw, llx, lly, &xposn, &yposn);
 
182
 
 
183
    FirstArg(XtNallowShellResize, True);
 
184
    NextArg(XtNx, xposn-40);
 
185
    NextArg(XtNy, yposn-65);
 
186
    NextArg(XtNtitle, "Xfig: Close Compound");
 
187
    NextArg(XtNcolormap, tool_cm);
 
188
    close_compound_popup = XtCreatePopupShell("close_compound_popup", transientShellWidgetClass,
 
189
                                     tool, Args, ArgCount);
 
190
    close_compound_form = XtCreateManagedWidget("close_compound_form", formWidgetClass,
 
191
                                       close_compound_popup, (XtPointer) NULL, 0);
 
192
 
 
193
    FirstArg(XtNlabel, "Close This Compound")
 
194
    close_compoundw = XtCreateManagedWidget("close_compound", commandWidgetClass,
 
195
                                      close_compound_form, Args, ArgCount);
 
196
    XtAddEventHandler(close_compoundw, ButtonReleaseMask, (Boolean) 0,
 
197
                      (XtEventHandler)close_compound, (XtPointer) NULL);
 
198
 
 
199
    FirstArg(XtNlabel, "Close All Compounds");
 
200
    NextArg(XtNfromHoriz, close_compoundw);
 
201
    close_compound_allw = XtCreateManagedWidget("close_all_compounds", commandWidgetClass,
 
202
                                 close_compound_form, Args, ArgCount);
 
203
    XtAddEventHandler(close_compound_allw, ButtonReleaseMask, (Boolean) 0,
 
204
                          (XtEventHandler)close_all_compounds, (XtPointer) NULL);
 
205
 
 
206
    /* now pop it up */
 
207
    XtPopup(close_compound_popup, XtGrabNone);
 
208
 
 
209
    /* insure that the most recent colormap is installed */
 
210
    set_cmap(XtWindow(close_compound_popup));
 
211
    (void) XSetWMProtocols(tool_d, XtWindow(close_compound_popup),
 
212
                           &wm_delete_window, 1);
 
213
    XDefineCursor(tool_d, XtWindow(close_compound_popup), arrow_cursor);
 
214
    close_popup_isup = True;
 
215
}