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

« back to all changes in this revision

Viewing changes to lefty/ws/x11/glabel.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 WLU widget->u.l
 
9
 
 
10
int GLcreatewidget (Gwidget_t *parent, Gwidget_t *widget,
 
11
        int attrn, Gwattr_t *attrp) {
 
12
    PIXsize_t ps;
 
13
    int ai;
 
14
    XColor c;
 
15
    int color;
 
16
 
 
17
    if (!parent) {
 
18
        Gerr (POS, G_ERRNOPARENTWIDGET);
 
19
        return -1;
 
20
    }
 
21
    WLU->func = NULL;
 
22
    ps.x = ps.y = MINLWSIZE;
 
23
    RESETARGS;
 
24
    for (ai = 0; ai < attrn; ai++) {
 
25
        switch (attrp[ai].id) {
 
26
        case G_ATTRSIZE:
 
27
            GETSIZE (attrp[ai].u.s, ps, MINLWSIZE);
 
28
            break;
 
29
        case G_ATTRBORDERWIDTH:
 
30
            ADD2ARGS (XtNborderWidth, attrp[ai].u.i);
 
31
            break;
 
32
        case G_ATTRTEXT:
 
33
            ADD2ARGS (XtNlabel, attrp[ai].u.t);
 
34
            break;
 
35
        case G_ATTRCOLOR:
 
36
            color = attrp[ai].u.c.index;
 
37
            if (color != 0 && color != 1) {
 
38
                Gerr (POS, G_ERRBADCOLORINDEX, color);
 
39
                return -1;
 
40
            }
 
41
            c.red = attrp[ai].u.c.r * 257;
 
42
            c.green = attrp[ai].u.c.g * 257;
 
43
            c.blue = attrp[ai].u.c.b * 257;
 
44
            if (XAllocColor (
 
45
                Gdisplay, DefaultColormap (Gdisplay, Gscreenn), &c
 
46
            ))
 
47
                if (color == 0)
 
48
                    ADD2ARGS (XtNbackground, c.pixel);
 
49
                else
 
50
                    ADD2ARGS (XtNforeground, c.pixel);
 
51
            break;
 
52
        case G_ATTRWINDOWID:
 
53
            Gerr (POS, G_ERRCANNOTSETATTR1, "windowid");
 
54
            return -1;
 
55
        case G_ATTREVENTCB:
 
56
            WLU->func = (Glabelcb) attrp[ai].u.func;
 
57
            break;
 
58
        case G_ATTRUSERDATA:
 
59
            widget->udata = attrp[ai].u.u;
 
60
            break;
 
61
        default:
 
62
            Gerr (POS, G_ERRBADATTRID, attrp[ai].id);
 
63
            return -1;
 
64
        }
 
65
    }
 
66
    ADD2ARGS (XtNwidth, ps.x);
 
67
    ADD2ARGS (XtNheight, ps.y);
 
68
    ADD2ARGS (XtNhighlightThickness, 0);
 
69
    ADD2ARGS (XtNinternalHeight, 0);
 
70
    ADD2ARGS (XtNinternalWidth, 0);
 
71
    ADD2ARGS (XtNjustify, XtJustifyLeft);
 
72
    if (!(widget->w = XtCreateWidget ("label", labelWidgetClass,
 
73
            parent->w, argp, argn))) {
 
74
        Gerr (POS, G_ERRCANNOTCREATEWIDGET);
 
75
        return -1;
 
76
    }
 
77
    XtOverrideTranslations (widget->w, Glwanytable);
 
78
    Glazymanage (widget->w);
 
79
    return 0;
 
80
}
 
81
 
 
82
int GLsetwidgetattr (Gwidget_t *widget, int attrn, Gwattr_t *attrp) {
 
83
    PIXsize_t ps;
 
84
    int ai;
 
85
    XColor c;
 
86
    int color;
 
87
 
 
88
    RESETARGS;
 
89
    for (ai = 0; ai < attrn; ai++) {
 
90
        switch (attrp[ai].id) {
 
91
        case G_ATTRSIZE:
 
92
            GETSIZE (attrp[ai].u.s, ps, MINLWSIZE);
 
93
            ADD2ARGS (XtNwidth, ps.x);
 
94
            ADD2ARGS (XtNheight, ps.y);
 
95
            break;
 
96
        case G_ATTRBORDERWIDTH:
 
97
            ADD2ARGS (XtNborderWidth, attrp[ai].u.i);
 
98
            break;
 
99
        case G_ATTRTEXT:
 
100
            ADD2ARGS (XtNlabel, attrp[ai].u.t);
 
101
            break;
 
102
        case G_ATTRCOLOR:
 
103
            color = attrp[ai].u.c.index;
 
104
            if (color != 0 && color != 1) {
 
105
                Gerr (POS, G_ERRBADCOLORINDEX, color);
 
106
                return -1;
 
107
            }
 
108
            c.red = attrp[ai].u.c.r * 257;
 
109
            c.green = attrp[ai].u.c.g * 257;
 
110
            c.blue = attrp[ai].u.c.b * 257;
 
111
            if (XAllocColor (
 
112
                Gdisplay, DefaultColormap (Gdisplay, Gscreenn), &c
 
113
            ))
 
114
                if (color == 0)
 
115
                    ADD2ARGS (XtNbackground, c.pixel);
 
116
                else
 
117
                    ADD2ARGS (XtNforeground, c.pixel);
 
118
            break;
 
119
        case G_ATTRWINDOWID:
 
120
            Gerr (POS, G_ERRCANNOTSETATTR2, "windowid");
 
121
            return -1;
 
122
        case G_ATTREVENTCB:
 
123
            WLU->func = (Glabelcb) attrp[ai].u.func;
 
124
            break;
 
125
        case G_ATTRUSERDATA:
 
126
            widget->udata = attrp[ai].u.u;
 
127
            break;
 
128
        default:
 
129
            Gerr (POS, G_ERRBADATTRID, attrp[ai].id);
 
130
            return -1;
 
131
        }
 
132
    }
 
133
    XtSetValues (widget->w, argp, argn);
 
134
    return 0;
 
135
}
 
136
 
 
137
int GLgetwidgetattr (Gwidget_t *widget, int attrn, Gwattr_t *attrp) {
 
138
    Dimension width, height;
 
139
    char *s;
 
140
    int ai;
 
141
 
 
142
    for (ai = 0; ai < attrn; ai++) {
 
143
        RESETARGS;
 
144
        switch (attrp[ai].id) {
 
145
        case G_ATTRSIZE:
 
146
            ADD2ARGS (XtNwidth, &width);
 
147
            ADD2ARGS (XtNheight, &height);
 
148
            XtGetValues (widget->w, argp, argn);
 
149
            attrp[ai].u.s.x = width, attrp[ai].u.s.y = height;
 
150
            break;
 
151
        case G_ATTRBORDERWIDTH:
 
152
            ADD2ARGS (XtNborderWidth, &width);
 
153
            XtGetValues (widget->w, argp, argn);
 
154
            attrp[ai].u.i = width;
 
155
            break;
 
156
        case G_ATTRTEXT:
 
157
            ADD2ARGS (XtNlabel, &s);
 
158
            XtGetValues (widget->w, argp, argn);
 
159
            attrp[ai].u.t = s;
 
160
            break;
 
161
        case G_ATTRWINDOWID:
 
162
            sprintf (&Gbufp[0], "0x%lx", XtWindow (widget->w));
 
163
            attrp[ai].u.t = &Gbufp[0];
 
164
            break;
 
165
        case G_ATTREVENTCB:
 
166
            attrp[ai].u.func = WLU->func;
 
167
            break;
 
168
        case G_ATTRUSERDATA:
 
169
            attrp[ai].u.u = widget->udata;
 
170
            break;
 
171
        default:
 
172
            Gerr (POS, G_ERRBADATTRID, attrp[ai].id);
 
173
            return -1;
 
174
        }
 
175
    }
 
176
    return 0;
 
177
}
 
178
 
 
179
int GLdestroywidget (Gwidget_t *widget) {
 
180
    XtDestroyWidget (widget->w);
 
181
    return 0;
 
182
}
 
183
 
 
184
void Glwbutaction (Widget w, XEvent *evp, char **app, unsigned int *anp) {
 
185
    Gwidget_t *widget;
 
186
    Gevent_t gev;
 
187
    int wi, xtype;
 
188
 
 
189
    widget = findwidget ((unsigned long) w, G_LABELWIDGET);
 
190
    switch ((xtype = evp->type)) {
 
191
    case ButtonPress:
 
192
    case ButtonRelease:
 
193
        gev.type = G_MOUSE;
 
194
        gev.code = (xtype == ButtonPress) ? G_DOWN : G_UP;
 
195
        gev.data = evp->xbutton.button - Button1;
 
196
        break;
 
197
    default:
 
198
        return;
 
199
    }
 
200
    wi = gev.wi = widget - &Gwidgets[0];
 
201
    if (WLU->func)
 
202
        (*WLU->func) (&gev);
 
203
    if (Gpopdownflag) {
 
204
        Gpopdownflag = FALSE;
 
205
        if (gev.code == G_DOWN) {
 
206
            gev.code = G_UP;
 
207
            widget = &Gwidgets[wi];
 
208
            if (widget->inuse && WLU->func)
 
209
                (*WLU->func) (&gev);
 
210
        }
 
211
    }
 
212
}
 
213
 
 
214
void Glwkeyaction (Widget w, XEvent *evp, char **app, unsigned int *anp) {
 
215
    Gwidget_t *widget;
 
216
    Gevent_t gev;
 
217
    int xtype;
 
218
    char c;
 
219
 
 
220
    widget = findwidget ((unsigned long) w, G_LABELWIDGET);
 
221
    switch ((xtype = evp->type)) {
 
222
    case KeyPress:
 
223
    case KeyRelease:
 
224
        if (!XLookupString ((XKeyEvent *) evp, &c, 1, NULL, NULL))
 
225
            return;
 
226
        gev.type = G_KEYBD;
 
227
        gev.code = (xtype == KeyPress) ? G_DOWN : G_UP;
 
228
        gev.data = c;
 
229
        break;
 
230
    default:
 
231
        return;
 
232
    }
 
233
    gev.wi = widget - &Gwidgets[0];
 
234
    if (WLU->func)
 
235
        (*WLU->func) (&gev);
 
236
    if (Gpopdownflag)
 
237
        Gpopdownflag = FALSE;
 
238
}