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

« back to all changes in this revision

Viewing changes to lefty/ws/x11/gscroll.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
int GScreatewidget (Gwidget_t *parent, Gwidget_t *widget,
 
9
        int attrn, Gwattr_t *attrp) {
 
10
    PIXsize_t ps;
 
11
#if XlibSpecificationRelease < 5
 
12
    Widget w;
 
13
#endif
 
14
    int ai;
 
15
    XColor c;
 
16
    int color;
 
17
 
 
18
    if (!parent) {
 
19
        Gerr (POS, G_ERRNOPARENTWIDGET);
 
20
        return -1;
 
21
    }
 
22
    ps.x = ps.y = MINSWSIZE;
 
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, MINSWSIZE);
 
28
            break;
 
29
        case G_ATTRBORDERWIDTH:
 
30
            ADD2ARGS (XtNborderWidth, attrp[ai].u.i);
 
31
            break;
 
32
        case G_ATTRCHILDCENTER:
 
33
            Gerr (POS, G_ERRCANNOTSETATTR1, "childcenter");
 
34
            return -1;
 
35
        case G_ATTRMODE:
 
36
            if (Strcmp ("forcebars", attrp[ai].u.t) == 0)
 
37
                ADD2ARGS (XtNforceBars, True);
 
38
            else {
 
39
                Gerr (POS, G_ERRBADATTRVALUE, attrp[ai].u.t);
 
40
                return -1;
 
41
            }
 
42
            break;
 
43
        case G_ATTRCOLOR:
 
44
            color = attrp[ai].u.c.index;
 
45
            if (color != 0 && color != 1) {
 
46
                Gerr (POS, G_ERRBADCOLORINDEX, color);
 
47
                return -1;
 
48
            }
 
49
            c.red = attrp[ai].u.c.r * 257;
 
50
            c.green = attrp[ai].u.c.g * 257;
 
51
            c.blue = attrp[ai].u.c.b * 257;
 
52
            if (XAllocColor (
 
53
                Gdisplay, DefaultColormap (Gdisplay, Gscreenn), &c
 
54
            ))
 
55
                if (color == 0)
 
56
                    ADD2ARGS (XtNbackground, c.pixel);
 
57
                else
 
58
                    ADD2ARGS (XtNforeground, c.pixel);
 
59
            break;
 
60
        case G_ATTRWINDOWID:
 
61
            Gerr (POS, G_ERRCANNOTSETATTR1, "windowid");
 
62
            return -1;
 
63
        case G_ATTRUSERDATA:
 
64
            widget->udata = attrp[ai].u.u;
 
65
            break;
 
66
        default:
 
67
            Gerr (POS, G_ERRBADATTRID, attrp[ai].id);
 
68
            return -1;
 
69
        }
 
70
    }
 
71
    ADD2ARGS (XtNallowHoriz, True);
 
72
    ADD2ARGS (XtNallowVert, True);
 
73
    ADD2ARGS (XtNwidth, ps.x);
 
74
    ADD2ARGS (XtNheight, ps.y);
 
75
    if (!(widget->w = XtCreateWidget ("scroll", viewportWidgetClass,
 
76
            parent->w, argp, argn))) {
 
77
        Gerr (POS, G_ERRCANNOTCREATEWIDGET);
 
78
        return -1;
 
79
    }
 
80
#if XlibSpecificationRelease < 5
 
81
    RESETARGS;
 
82
    ADD2ARGS (XtNwidth, ps.x);
 
83
    ADD2ARGS (XtNheight, ps.y);
 
84
    if (!(w = XtCreateWidget ("owsucks", formWidgetClass,
 
85
            widget->w, argp, argn))) {
 
86
        Gerr (POS, G_ERRCANNOTCREATEWIDGET);
 
87
        return -1;
 
88
    }
 
89
    Glazymanage (w);
 
90
    Glazymanage (widget->w);
 
91
    XtDestroyWidget (w);
 
92
#else
 
93
    Glazymanage (widget->w);
 
94
#endif
 
95
    return 0;
 
96
}
 
97
 
 
98
int GSsetwidgetattr (Gwidget_t *widget, int attrn, Gwattr_t *attrp) {
 
99
    PIXpoint_t po;
 
100
    PIXsize_t ps;
 
101
    Dimension width, height;
 
102
    int ai;
 
103
    XColor c;
 
104
    int color;
 
105
 
 
106
    RESETARGS;
 
107
    for (ai = 0; ai < attrn; ai++) {
 
108
        switch (attrp[ai].id) {
 
109
        case G_ATTRSIZE:
 
110
            GETSIZE (attrp[ai].u.s, ps, MINSWSIZE);
 
111
            ADD2ARGS (XtNwidth, ps.x);
 
112
            ADD2ARGS (XtNheight, ps.y);
 
113
            break;
 
114
        case G_ATTRBORDERWIDTH:
 
115
            ADD2ARGS (XtNborderWidth, attrp[ai].u.i);
 
116
            break;
 
117
        case G_ATTRCHILDCENTER:
 
118
            GETORIGIN (attrp[ai].u.p, po);
 
119
            ADD2ARGS (XtNwidth, &width);
 
120
            ADD2ARGS (XtNheight, &height);
 
121
            XtGetValues (widget->w, argp, argn);
 
122
            po.x -= width / 2, po.y -= height / 2;
 
123
            if (po.x < 0)
 
124
                po.x = 0;
 
125
            if (po.y < 0)
 
126
                po.y = 0;
 
127
            XawViewportSetCoordinates (widget->w, po.x, po.y);
 
128
            break;
 
129
        case G_ATTRMODE:
 
130
            if (Strcmp ("forcebars", attrp[ai].u.t) == 0)
 
131
                ADD2ARGS (XtNforceBars, True);
 
132
            else {
 
133
                Gerr (POS, G_ERRBADATTRVALUE, attrp[ai].u.t);
 
134
                return -1;
 
135
            }
 
136
            break;
 
137
        case G_ATTRCOLOR:
 
138
            color = attrp[ai].u.c.index;
 
139
            if (color != 0 && color != 1) {
 
140
                Gerr (POS, G_ERRBADCOLORINDEX, color);
 
141
                return -1;
 
142
            }
 
143
            c.red = attrp[ai].u.c.r * 257;
 
144
            c.green = attrp[ai].u.c.g * 257;
 
145
            c.blue = attrp[ai].u.c.b * 257;
 
146
            if (XAllocColor (
 
147
                Gdisplay, DefaultColormap (Gdisplay, Gscreenn), &c
 
148
            ))
 
149
                if (color == 0)
 
150
                    ADD2ARGS (XtNbackground, c.pixel);
 
151
                else
 
152
                    ADD2ARGS (XtNforeground, c.pixel);
 
153
            break;
 
154
        case G_ATTRWINDOWID:
 
155
            Gerr (POS, G_ERRCANNOTSETATTR2, "windowid");
 
156
            return -1;
 
157
        case G_ATTRUSERDATA:
 
158
            widget->udata = attrp[ai].u.u;
 
159
            break;
 
160
        default:
 
161
            Gerr (POS, G_ERRBADATTRID, attrp[ai].id);
 
162
            return -1;
 
163
        }
 
164
    }
 
165
    XtSetValues (widget->w, argp, argn);
 
166
    return 0;
 
167
}
 
168
 
 
169
int GSgetwidgetattr (Gwidget_t *widget, int attrn, Gwattr_t *attrp) {
 
170
    Dimension width, height;
 
171
    Position x, y;
 
172
    Boolean tf;
 
173
    Gwidget_t *child;
 
174
    int ai, wi;
 
175
 
 
176
    for (ai = 0; ai < attrn; ai++) {
 
177
        RESETARGS;
 
178
        switch (attrp[ai].id) {
 
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_ATTRBORDERWIDTH:
 
186
            ADD2ARGS (XtNborderWidth, &width);
 
187
            XtGetValues (widget->w, argp, argn);
 
188
            attrp[ai].u.i = width;
 
189
            break;
 
190
        case G_ATTRCHILDCENTER:
 
191
            for (wi = 0; wi < Gwidgetn; wi++) {
 
192
                child = &Gwidgets[wi];
 
193
                if (child->inuse && child->pwi == widget - &Gwidgets[0])
 
194
                    break;
 
195
            }
 
196
            if (wi == Gwidgetn) {
 
197
                Gerr (POS, G_ERRNOCHILDWIDGET);
 
198
                return -1;
 
199
            }
 
200
            ADD2ARGS (XtNwidth, &width);
 
201
            ADD2ARGS (XtNheight, &height);
 
202
            XtGetValues (widget->w, argp, argn);
 
203
            RESETARGS;
 
204
            ADD2ARGS (XtNx, &x);
 
205
            ADD2ARGS (XtNy, &y);
 
206
            XtGetValues (child->w, argp, argn);
 
207
            attrp[ai].u.p.x = width / 2 - x, attrp[ai].u.p.y = height / 2 - y;
 
208
            break;
 
209
        case G_ATTRMODE:
 
210
            ADD2ARGS (XtNforceBars, &tf);
 
211
            attrp[ai].u.t = (tf == True) ? "forcebars" : "";
 
212
            break;
 
213
        case G_ATTRWINDOWID:
 
214
            sprintf (&Gbufp[0], "0x%lx", XtWindow (widget->w));
 
215
            attrp[ai].u.t = &Gbufp[0];
 
216
            break;
 
217
        case G_ATTRUSERDATA:
 
218
            attrp[ai].u.u = widget->udata;
 
219
            break;
 
220
        default:
 
221
            Gerr (POS, G_ERRBADATTRID, attrp[ai].id);
 
222
            return -1;
 
223
        }
 
224
    }
 
225
    return 0;
 
226
}
 
227
 
 
228
int GSdestroywidget (Gwidget_t *widget) {
 
229
    XtDestroyWidget (widget->w);
 
230
    return 0;
 
231
}
 
232
 
 
233
#if XlibSpecificationRelease < 5
 
234
#include <X11/IntrinsicP.h>
 
235
#include <X11/Xaw/ViewportP.h>
 
236
 
 
237
void XawViewportSetCoordinates (Widget gw, Position x, Position y) {
 
238
    ViewportWidget w = (ViewportWidget) gw;
 
239
    Widget child = w->viewport.child;
 
240
    Widget clip = w->viewport.clip;
 
241
    Position mx, my;
 
242
 
 
243
    if (x > (int) child->core.width)
 
244
      x = child->core.width;
 
245
    else if (x < 0)
 
246
      x = child->core.x;
 
247
 
 
248
    if (y > (int) child->core.height)
 
249
      y = child->core.height;
 
250
    else if (y < 0)
 
251
      y = child->core.y;
 
252
 
 
253
    mx = -x, my = -y;
 
254
 
 
255
    if (-mx + (int) clip->core.width > (int) child->core.width)
 
256
        mx = -(child->core.width - clip->core.width);
 
257
 
 
258
    if (-my + (int) clip->core.height > (int) child->core.height)
 
259
        my = -(child->core.height - clip->core.height);
 
260
 
 
261
    /* make sure we never move past left/top borders */
 
262
    if (mx >= 0) mx = 0;
 
263
    if (my >= 0) my = 0;
 
264
 
 
265
    XtMoveWidget (child, mx, my);
 
266
    XtUnmanageChild (child);
 
267
    XtManageChild (child);
 
268
}
 
269
#endif