~ubuntu-branches/ubuntu/lucid/graphviz/lucid-security

« back to all changes in this revision

Viewing changes to lefty/ws/x11/gview.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen M Moraco
  • Date: 2002-02-05 18:52:12 UTC
  • Revision ID: james.westby@ubuntu.com-20020205185212-8i04c70te00rc40y
Tags: upstream-1.7.16
ImportĀ upstreamĀ versionĀ 1.7.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#pragma prototyped
 
2
/* Lefteris Koutsofios - AT&T Bell Laboratories */
 
3
 
 
4
#include "common.h"
 
5
#include "g.h"
 
6
#include "gcommon.h"
 
7
 
 
8
#define WVU widget->u.v
 
9
 
 
10
int GVcreatewidget (Gwidget_t *parent, Gwidget_t *widget,
 
11
        int attrn, Gwattr_t *attrp) {
 
12
    PIXpoint_t po;
 
13
    PIXsize_t ps;
 
14
    XSizeHints hints;
 
15
    char *s;
 
16
    int haveorigin, ai;
 
17
    XColor c;
 
18
    int color;
 
19
 
 
20
    WVU->func = NULL;
 
21
    WVU->closing = FALSE;
 
22
    s = "LEFTY";
 
23
    ps.x = ps.y = MINVWSIZE;
 
24
    haveorigin = FALSE;
 
25
    RESETARGS;
 
26
    for (ai = 0; ai < attrn; ai++) {
 
27
        switch (attrp[ai].id) {
 
28
        case G_ATTRORIGIN:
 
29
            haveorigin = TRUE;
 
30
            GETORIGIN (attrp[ai].u.p, po);
 
31
            ADD2ARGS (XtNx, po.x);
 
32
            ADD2ARGS (XtNy, po.y);
 
33
            break;
 
34
        case G_ATTRSIZE:
 
35
            GETSIZE (attrp[ai].u.s, ps, MINVWSIZE);
 
36
            break;
 
37
        case G_ATTRNAME:
 
38
            s = attrp[ai].u.t;
 
39
            break;
 
40
        case G_ATTRCOLOR:
 
41
            color = attrp[ai].u.c.index;
 
42
            if (color != 0 && color != 1) {
 
43
                Gerr (POS, G_ERRBADCOLORINDEX, color);
 
44
                return -1;
 
45
            }
 
46
            c.red = attrp[ai].u.c.r * 257;
 
47
            c.green = attrp[ai].u.c.g * 257;
 
48
            c.blue = attrp[ai].u.c.b * 257;
 
49
            if (XAllocColor (
 
50
                Gdisplay, DefaultColormap (Gdisplay, Gscreenn), &c
 
51
            ))
 
52
                if (color == 0)
 
53
                    ADD2ARGS (XtNbackground, c.pixel);
 
54
                else
 
55
                    ADD2ARGS (XtNforeground, c.pixel);
 
56
            break;
 
57
        case G_ATTRZORDER:
 
58
            Gerr (POS, G_ERRCANNOTSETATTR1, "zorder");
 
59
            return -1;
 
60
        case G_ATTRWINDOWID:
 
61
            Gerr (POS, G_ERRCANNOTSETATTR1, "windowid");
 
62
            return -1;
 
63
        case G_ATTREVENTCB:
 
64
            WVU->func = (Gviewcb) attrp[ai].u.func;
 
65
            break;
 
66
        case G_ATTRUSERDATA:
 
67
            widget->udata = attrp[ai].u.u;
 
68
            break;
 
69
        default:
 
70
            Gerr (POS, G_ERRBADATTRID, attrp[ai].id);
 
71
            return -1;
 
72
        }
 
73
    }
 
74
    ADD2ARGS (XtNwidth, ps.x);
 
75
    ADD2ARGS (XtNheight, ps.y);
 
76
    if (!(widget->w = XtAppCreateShell (s, "LEFTY",
 
77
            topLevelShellWidgetClass, Gdisplay, argp, argn))) {
 
78
        Gerr (POS, G_ERRCANNOTCREATEWIDGET);
 
79
        return -1;
 
80
    }
 
81
    if (haveorigin) {
 
82
        hints.x = po.x, hints.y = po.y;
 
83
        hints.width = ps.x, hints.height = ps.y;
 
84
        hints.flags = USPosition;
 
85
        Glazyrealize (widget->w, TRUE, &hints);
 
86
    } else
 
87
        Glazyrealize (widget->w, FALSE, NULL);
 
88
    return 0;
 
89
}
 
90
 
 
91
int GVsetwidgetattr (Gwidget_t *widget, int attrn, Gwattr_t *attrp) {
 
92
    PIXpoint_t po;
 
93
    PIXsize_t ps;
 
94
    int ai;
 
95
    XColor c;
 
96
    int color;
 
97
 
 
98
    RESETARGS;
 
99
    for (ai = 0; ai < attrn; ai++) {
 
100
        switch (attrp[ai].id) {
 
101
        case G_ATTRORIGIN:
 
102
            GETORIGIN (attrp[ai].u.p, po);
 
103
            ADD2ARGS (XtNx, po.x);
 
104
            ADD2ARGS (XtNy, po.y);
 
105
            break;
 
106
        case G_ATTRSIZE:
 
107
            GETSIZE (attrp[ai].u.s, ps, MINVWSIZE);
 
108
            ADD2ARGS (XtNwidth, ps.x);
 
109
            ADD2ARGS (XtNheight, ps.y);
 
110
            break;
 
111
        case G_ATTRNAME:
 
112
#if XlibSpecificationRelease < 5
 
113
            return -1;
 
114
#else
 
115
            XmbSetWMProperties (Gdisplay, XtWindow (widget->w),
 
116
                    attrp[ai].u.t, attrp[ai].u.t, NULL, 0, NULL, NULL, NULL);
 
117
#endif
 
118
            break;
 
119
        case G_ATTRCOLOR:
 
120
            color = attrp[ai].u.c.index;
 
121
            if (color != 0 && color != 1) {
 
122
                Gerr (POS, G_ERRBADCOLORINDEX, color);
 
123
                return -1;
 
124
            }
 
125
            c.red = attrp[ai].u.c.r * 257;
 
126
            c.green = attrp[ai].u.c.g * 257;
 
127
            c.blue = attrp[ai].u.c.b * 257;
 
128
            if (XAllocColor (
 
129
                Gdisplay, DefaultColormap (Gdisplay, Gscreenn), &c
 
130
            ))
 
131
                if (color == 0)
 
132
                    ADD2ARGS (XtNbackground, c.pixel);
 
133
                else
 
134
                    ADD2ARGS (XtNforeground, c.pixel);
 
135
            break;
 
136
        case G_ATTRZORDER:
 
137
            Gflushlazyq ();
 
138
            if (Strcmp (attrp[ai].u.t, "top") == 0)
 
139
                XRaiseWindow (Gdisplay, XtWindow (widget->w));
 
140
            else if (Strcmp (attrp[ai].u.t, "bottom") == 0)
 
141
                XLowerWindow (Gdisplay, XtWindow (widget->w));
 
142
            else {
 
143
                Gerr (POS, G_ERRBADATTRVALUE, attrp[ai].u.t);
 
144
                return -1;
 
145
            }
 
146
            break;
 
147
        case G_ATTRWINDOWID:
 
148
            Gerr (POS, G_ERRCANNOTSETATTR2, "windowid");
 
149
            return -1;
 
150
        case G_ATTREVENTCB:
 
151
            WVU->func = (Gviewcb) attrp[ai].u.func;
 
152
            break;
 
153
        case G_ATTRUSERDATA:
 
154
            widget->udata = attrp[ai].u.u;
 
155
            break;
 
156
        default:
 
157
            Gerr (POS, G_ERRBADATTRID, attrp[ai].id);
 
158
            return -1;
 
159
        }
 
160
    }
 
161
    XtSetValues (widget->w, argp, argn);
 
162
    return 0;
 
163
}
 
164
 
 
165
int GVgetwidgetattr (Gwidget_t *widget, int attrn, Gwattr_t *attrp) {
 
166
    Position x, y;
 
167
    Dimension width, height;
 
168
    int ai;
 
169
 
 
170
    for (ai = 0; ai < attrn; ai++) {
 
171
        RESETARGS;
 
172
        switch (attrp[ai].id) {
 
173
        case G_ATTRORIGIN:
 
174
            ADD2ARGS (XtNx, &x);
 
175
            ADD2ARGS (XtNy, &y);
 
176
            XtGetValues (widget->w, argp, argn);
 
177
            attrp[ai].u.p.x = x, attrp[ai].u.p.y = y;
 
178
            break;
 
179
        case G_ATTRSIZE:
 
180
            ADD2ARGS (XtNwidth, &width);
 
181
            ADD2ARGS (XtNheight, &height);
 
182
            XtGetValues (widget->w, argp, argn);
 
183
            attrp[ai].u.s.x = width, attrp[ai].u.s.y = height;
 
184
            break;
 
185
        case G_ATTRNAME:
 
186
            Gerr (POS, G_ERRNOTIMPLEMENTED);
 
187
            return -1;
 
188
        case G_ATTRZORDER:
 
189
            Gerr (POS, G_ERRNOTIMPLEMENTED);
 
190
            return -1;
 
191
        case G_ATTRWINDOWID:
 
192
            sprintf (&Gbufp[0], "0x%lx", XtWindow (widget->w));
 
193
            attrp[ai].u.t = &Gbufp[0];
 
194
            break;
 
195
        case G_ATTREVENTCB:
 
196
            attrp[ai].u.func = WVU->func;
 
197
            break;
 
198
        case G_ATTRUSERDATA:
 
199
            attrp[ai].u.u = widget->udata;
 
200
            break;
 
201
        default:
 
202
            Gerr (POS, G_ERRBADATTRID, attrp[ai].id);
 
203
            return -1;
 
204
        }
 
205
    }
 
206
    return 0;
 
207
}
 
208
 
 
209
int GVdestroywidget (Gwidget_t *widget) {
 
210
    WVU->closing = TRUE;
 
211
    XtDestroyWidget (widget->w);
 
212
    return 0;
 
213
}
 
214
 
 
215
void Gwmdelaction (Widget w, XEvent *evp, char **app, unsigned int *anp) {
 
216
    Gwidget_t *widget;
 
217
    Gevent_t gev;
 
218
 
 
219
    widget = findwidget ((unsigned long) w, G_VIEWWIDGET);
 
220
    if (!widget)
 
221
        exit (0);
 
222
    gev.type = 0, gev.code = 0, gev.data = 0;
 
223
    gev.wi = widget - &Gwidgets[0];
 
224
    if (WVU->func)
 
225
        (*WVU->func) (&gev);
 
226
    else
 
227
        exit (0);
 
228
}