~ubuntu-branches/ubuntu/jaunty/xvidcap/jaunty-proposed

« back to all changes in this revision

Viewing changes to Xw/Base.c

  • Committer: Bazaar Package Importer
  • Author(s): Christian Marillat
  • Date: 2004-08-29 10:53:42 UTC
  • Revision ID: james.westby@ubuntu.com-20040829105342-qgmnry37eadfkoxx
Tags: upstream-1.1.3
ImportĀ upstreamĀ versionĀ 1.1.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Base.c; vi: tabstop=4
 
3
 *
 
4
 * Copyright (C) 1998 Rasca, Berlin
 
5
 * EMail: thron@gmx.de
 
6
 *
 
7
 * This library is free software; you can redistribute it and/or
 
8
 * modify it under the terms of the GNU Library General Public
 
9
 * License as published by the Free Software Foundation; either
 
10
 * version 2 of the License, or (at your option) any later version.
 
11
 *
 
12
 * This library is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
 * Library General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU Library General Public
 
18
 * License along with this library; if not, write to the Free Software
 
19
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
20
 */
 
21
 
 
22
#ifndef __FILE__
 
23
#define __FILE__ "Base.c"
 
24
#endif
 
25
#include <stdio.h>
 
26
#include <X11/StringDefs.h>
 
27
#include <X11/IntrinsicP.h>
 
28
#include <Xw/BaseP.h>
 
29
 
 
30
/* resource list */
 
31
#define offset(member) XtOffsetOf (XwBaseRec, member)
 
32
 
 
33
static XtResource resources [] = {
 
34
        /* base defaults
 
35
         */
 
36
        {       XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
 
37
                offset(base.foreground_pixel), XtRString, "black" },
 
38
        {       XtNhighlight, XtCHighlight, XtRPixel, sizeof(Pixel),
 
39
                offset(base.highlight_pixel), XtRString, "blue4" },
 
40
        {       XtNnotSensitiveColor, XtCNotSensitiveColor, XtRPixel, sizeof(Pixel),
 
41
                offset (base.not_sensitive_pixel), XtRString, "grey60" },
 
42
        {       XtNshadowTopColor, XtCShadowTopColor, XtRPixel, sizeof(Pixel),
 
43
                offset(base.shadow_top_pixel), XtRString, "grey95" },
 
44
        {       XtNshadowBottomColor, XtCShadowBottomColor, XtRPixel, sizeof(Pixel),
 
45
                offset (base.shadow_bottom_pixel), XtRString, "grey70" },
 
46
        {       XtNshadowWidth, XtCShadowWidth, XtRDimension, sizeof(Dimension),
 
47
                offset(base.shadow_width), XtRImmediate, (XtPointer)2 },
 
48
        {       XtNshadowType, XtCShadowType, XtRInt, sizeof(int),
 
49
                offset(base.shadow_type), XtRImmediate, (XtPointer)XtShadowNone },
 
50
        {       XtNresize, XtCResize, XtRBoolean, sizeof(Boolean),
 
51
                offset(base.resize), XtRImmediate, (XtPointer)0 },
 
52
        {       XtNacceptDrop, XtCAcceptDrop, XtRBoolean, sizeof(Boolean),
 
53
                offset(base.acceptDrop), XtRImmediate, (XtPointer)0 },
 
54
        {       XtNtabCallback, XtCCallback, XtRCallback, sizeof(XtPointer),
 
55
                offset(base.tab_callbacks), XtRCallback, NULL },
 
56
        {       XtNprev, XtCPrev, XtRWidget, sizeof (XtPointer),
 
57
                offset(base.prev), XtRImmediate, NULL},
 
58
        {       XtNnext, XtCNext, XtRWidget, sizeof (XtPointer),
 
59
                offset(base.next), XtRImmediate, NULL},
 
60
        {       XtNuserData, XtCUserData, XtRPointer, sizeof(XtPointer),
 
61
                offset(base.data), XtRImmediate, NULL },
 
62
        /* core defaults
 
63
         */
 
64
        {       XtNborderWidth, XtCBorderWidth, XtRDimension, sizeof(Dimension),
 
65
                offset(core.border_width), XtRImmediate, (XtPointer)1 },
 
66
        {       XtNbackground, XtCBackground, XtRPixel, sizeof(Pixel),
 
67
                offset(core.background_pixel), XtRString, "grey90" },
 
68
        {       XtNborderColor, XtCBorderColor, XtRPixel, sizeof(Pixel),
 
69
                offset(core.border_pixel), XtRString, "grey90" },
 
70
};
 
71
 
 
72
/*
 
73
 * action function declarations
 
74
 */
 
75
static void Tab (Widget, XEvent*, String*, Cardinal*);
 
76
static void Focus (Widget, XEvent*, String *, Cardinal *);
 
77
static void GetFocus (Widget, XEvent*, String *, Cardinal *);
 
78
 
 
79
/*
 
80
 * action table
 
81
 */
 
82
static XtActionsRec actions [] = {
 
83
        {"tab",                 Tab},
 
84
        {"focus",               Focus },
 
85
        {"get-focus",   GetFocus },
 
86
        };
 
87
 
 
88
/*
 
89
 * default translation table
 
90
 */
 
91
static char defaultTranslations [] = "<FocusIn>: focus(in)\n<FocusOut>: focus(out)\n<Key>Tab:   tab()";
 
92
 
 
93
/*
 
94
 * method function declarations
 
95
 */
 
96
static void
 
97
        ClassPartInitialize (WidgetClass wc),
 
98
        Initialize (Widget t, Widget n, ArgList args, Cardinal *num_args),
 
99
        Destroy (Widget w);
 
100
static void Resize (Widget w);
 
101
static void Redisplay (Widget aw, XEvent *event, Region region);
 
102
static Boolean SetValues (Widget, Widget, Widget, ArgList, Cardinal *);
 
103
/* */
 
104
 
 
105
#define SuperClass ((CoreWidgetClass)&coreClassRec)
 
106
/*
 
107
 * class record initialization
 
108
 */
 
109
XwBaseClassRec xwBaseClassRec = {
 
110
        {       /* core_class fields     */
 
111
                /* superclass            */ (WidgetClass) SuperClass,
 
112
                /* class_name            */ "XwBase",
 
113
                /* widget_size           */ sizeof(XwBaseRec),
 
114
                /* class_initialize      */ NULL,
 
115
                /* class_part_initialize */ ClassPartInitialize,
 
116
                /* class_inited          */ False,
 
117
                /* initialize            */ Initialize,
 
118
                /* initialize_hook       */ NULL,
 
119
                /* realize               */ XtInheritRealize,
 
120
                /* actions               */ actions,
 
121
                /* num_actions           */ XtNumber(actions),
 
122
                /* resources             */ resources,
 
123
                /* num_resources         */ XtNumber(resources),
 
124
                /* xrm_class             */ NULLQUARK,
 
125
                /* compress_motion       */ True,
 
126
                /* compress_exposure     */ XtExposeCompressMultiple,
 
127
                /* compress_enterleave   */ True,
 
128
                /* visible_interest      */ True,
 
129
                /* destroy               */ Destroy,
 
130
                /* resize                */ Resize,
 
131
                /* expose                */ Redisplay,
 
132
                /* set_values            */ SetValues,
 
133
                /* set_values_hook       */ NULL,
 
134
                /* set_values_almost     */ XtInheritSetValuesAlmost,
 
135
                /* get_values_hook       */ NULL,
 
136
                /* accept_focus          */ NULL,
 
137
                /* version               */ XtVersion,
 
138
                /* callback_private      */ NULL,
 
139
                /* tm_table              */ defaultTranslations,
 
140
                /* query_geometry               */ XtInheritQueryGeometry,
 
141
                /* display_accelerator  */ XtInheritDisplayAccelerator,
 
142
                /* extension                    */ NULL
 
143
        },
 
144
        {       /* base_class fields */
 
145
                /* tab_action                   */      Tab,
 
146
                /* focus_action                 */      Focus,
 
147
                /* getfocus_action              */      GetFocus,
 
148
        },
 
149
};
 
150
 
 
151
WidgetClass xwBaseWidgetClass = (WidgetClass) &xwBaseClassRec;
 
152
 
 
153
/*
 
154
 * downward chained: first this one and then subclasses
 
155
 */
 
156
static void
 
157
ClassPartInitialize (WidgetClass wc)
 
158
{
 
159
        XwBaseWidgetClass c = (XwBaseWidgetClass) wc;
 
160
        if (c->base_class.tab_action == XtInheritTabAction)
 
161
                c->base_class.tab_action = Tab;
 
162
        if (c->base_class.focus_action == XtInheritFocusAction)
 
163
                c->base_class.focus_action = Focus;
 
164
        if (c->base_class.getfocus_action == XtInheritGetFocusAction)
 
165
                c->base_class.getfocus_action = GetFocus;
 
166
}
 
167
 
 
168
/*
 
169
 * method function definitions
 
170
 */
 
171
static void
 
172
InitGC (XwBaseWidget bw)
 
173
{
 
174
        Widget w = (Widget) bw;
 
175
        XGCValues gcv;
 
176
        XtGCMask mask;
 
177
 
 
178
#ifdef DEBUG_BASE
 
179
        printf ("%s: InitGC (%s)\n", __FILE__, bw->core.name);
 
180
#endif
 
181
        mask = GCLineStyle | GCLineWidth | GCForeground ;
 
182
        gcv.line_style = LineSolid;
 
183
        gcv.line_width = 0;
 
184
 
 
185
        gcv.foreground = bw->base.shadow_bottom_pixel;
 
186
        bw->base.downGC = XtGetGC (w, mask, &gcv);
 
187
 
 
188
        gcv.foreground = bw->base.shadow_top_pixel;
 
189
        bw->base.upGC = XtGetGC (w, mask, &gcv);
 
190
 
 
191
        gcv.foreground =BlackPixel(XtDisplay(w),XScreenNumberOfScreen(XtScreen(w)));
 
192
        bw->base.blackGC = XtGetGC (w, mask, &gcv);
 
193
}
 
194
 
 
195
/*
 
196
 * initialize Method
 
197
 */
 
198
static void
 
199
Initialize (Widget treq, Widget tnew, ArgList args, Cardinal *num_args)
 
200
{
 
201
        XwBaseWidget new = (XwBaseWidget) tnew;
 
202
#ifdef DEBUG_BASE
 
203
        printf ("%s: Initialize (%s)\n", __FILE__, new->core.name);
 
204
#endif
 
205
        InitGC (new);
 
206
}
 
207
 
 
208
/*
 
209
 * set_values method
 
210
 */
 
211
static Boolean
 
212
SetValues (Widget curr, Widget req, Widget reply, ArgList args, Cardinal *nargs)
 
213
{
 
214
        Boolean redraw = False;
 
215
        XwBaseWidget bw = (XwBaseWidget) curr;
 
216
        XwBaseWidget new= (XwBaseWidget) reply;
 
217
        
 
218
        if ((bw->base.shadow_top_pixel != new->base.shadow_top_pixel) ||
 
219
                (bw->base.shadow_bottom_pixel != new->base.shadow_bottom_pixel))
 
220
        {
 
221
                XtReleaseGC (curr, bw->base.upGC);
 
222
                XtReleaseGC (curr, bw->base.downGC);
 
223
                XtReleaseGC (curr, bw->base.blackGC);
 
224
                InitGC (new);
 
225
                redraw = True;
 
226
        }
 
227
        if ((bw->base.shadow_type  != new->base.shadow_type) ||
 
228
                (bw->base.shadow_width != new->base.shadow_width)) {
 
229
                redraw = True;
 
230
        }
 
231
#ifdef DEBUG_BASE
 
232
        printf("%s: SetValues (%s ..) rv=%d\n",__FILE__,new->core.name,(int)redraw);
 
233
#endif
 
234
        return (redraw);
 
235
}
 
236
 
 
237
/*
 
238
 * destroy method
 
239
 */
 
240
static void
 
241
Destroy (Widget w)
 
242
{
 
243
        XwBaseWidget bw = (XwBaseWidget) w;
 
244
#ifdef DEBUG_BASE
 
245
        printf ("%s: Destroy (%s)\n", __FILE__, w->core.name);
 
246
#endif
 
247
        XtReleaseGC (w, bw->base.upGC);
 
248
        XtReleaseGC (w, bw->base.downGC);
 
249
        XtReleaseGC (w, bw->base.blackGC);
 
250
}
 
251
 
 
252
 
 
253
/*
 
254
 * resize method
 
255
 */
 
256
static void
 
257
Resize (Widget w)
 
258
{
 
259
#ifdef DEBUG_BASE
 
260
        printf ("%s: Resize (%s)\n", __FILE__, w->core.name);
 
261
#endif
 
262
}
 
263
 
 
264
/*
 
265
 * expose method
 
266
 * redisplay the widget (draw 3d frame)
 
267
 */
 
268
static void
 
269
Redisplay (Widget w, XEvent *event, Region region)
 
270
{
 
271
        XwBaseWidget bw = (XwBaseWidget) w;
 
272
        int i;
 
273
 
 
274
#ifdef DEBUG_BASE
 
275
        printf ("%s: Redisplay (%s) sw=%d type=%d\n",
 
276
                __FILE__, w->core.name, bw->base.shadow_width, bw->base.shadow_type);
 
277
#endif
 
278
 
 
279
        if (!XtIsRealized(w))
 
280
                return;
 
281
 
 
282
        if (bw->base.shadow_width < 1)
 
283
                return;
 
284
 
 
285
/* seems not to work :(
 
286
        if ((region != NULL) && (!XEmptyRegion(region))) {
 
287
                int rc;
 
288
 
 
289
                rc = XRectInRegion (region, w->core.x, w->core.y,
 
290
                                w->core.width, w->core.height);
 
291
                if ((rc != RectanglePart) && (rc != RectangleIn)) {
 
292
                        return;
 
293
                }
 
294
        } */
 
295
 
 
296
        if (bw->base.shadow_type == XtShadowUp) {
 
297
                for (i = 0; i < bw->base.shadow_width; i++) {
 
298
                        if (i < bw->base.shadow_width -1) {
 
299
                                /* top horizontal line
 
300
                                 */
 
301
                                XDrawLine (XtDisplay(w), XtWindow(w), bw->base.upGC,
 
302
                                        i + 1, i, w->core.width - i - 1, i);
 
303
                                /* left vertical line
 
304
                                 */
 
305
                                XDrawLine (XtDisplay(w), XtWindow(w), bw->base.upGC,
 
306
                                        i, i, i, w->core.height - i - 1);
 
307
                        }
 
308
                        if (!i) {
 
309
                                /* draw black line */
 
310
                                /* bottom horizontal line
 
311
                                 */
 
312
                                XDrawLine (XtDisplay(w), XtWindow(w), bw->base.blackGC,
 
313
                                        1, w->core.height-1, w->core.width-1, w->core.height-1);
 
314
                                /* right vertical line
 
315
                                 */
 
316
                                XDrawLine (XtDisplay(w), XtWindow(w), bw->base.blackGC,
 
317
                                        w->core.width-1-i, i, w->core.width-1-i, w->core.height-i);
 
318
                        } else {
 
319
                                /* bottom horizontal line */
 
320
                                XDrawLine (XtDisplay(w), XtWindow(w), bw->base.downGC,
 
321
                                        i + 1, w->core.height - 1- i,
 
322
                                        w->core.width - i - 1, w->core.height-1-i);
 
323
                                /* right vertical line */
 
324
                                XDrawLine (XtDisplay(w), XtWindow(w), bw->base.downGC,
 
325
                                        w->core.width-1-i, i,
 
326
                                        w->core.width-1-i, w->core.height-i-1);
 
327
                        }
 
328
                }
 
329
        } else if (bw->base.shadow_type == XtShadowDown) {
 
330
                for (i = 0; i < bw->base.shadow_width; i++) {
 
331
                        if (!i && bw->base.shadow_width > 1) {
 
332
                                /* top horizontal line */
 
333
                                XDrawLine (XtDisplay(w), XtWindow(w), bw->base.blackGC,
 
334
                                        i + 1, i, w->core.width - i - 1, i);
 
335
                                /* left vertical line */
 
336
                                XDrawLine (XtDisplay(w), XtWindow(w), bw->base.blackGC,
 
337
                                        i, i, i, w->core.height - i);
 
338
                        } else {
 
339
                                /* top horizontal line */
 
340
                                XDrawLine (XtDisplay(w), XtWindow(w), bw->base.downGC,
 
341
                                        i + 1, i, w->core.width - i - 1, i);
 
342
                                /* left vertical line */
 
343
                                XDrawLine (XtDisplay(w), XtWindow(w), bw->base.downGC,
 
344
                                        i, i, i, w->core.height - i - 1);
 
345
                        }
 
346
                        if ((i < bw->base.shadow_width - 1) ||bw->base.shadow_width<2) {
 
347
                                /* bottom horizontal line */
 
348
                                XDrawLine (XtDisplay(w), XtWindow(w), bw->base.upGC,
 
349
                                        i + 1, w->core.height - 1- i, w->core.width - i - 1,
 
350
                                        w->core.height-1-i);
 
351
                                /* right vertical line */
 
352
                                XDrawLine (XtDisplay(w), XtWindow(w), bw->base.upGC,
 
353
                                        w->core.width-1-i, i, w->core.width-1-i, w->core.height-i);
 
354
                        }
 
355
                }
 
356
        } else if (bw->base.shadow_type == XtShadowFlat) {
 
357
                GC top, bottom, tmp;
 
358
                int half = bw->base.shadow_width /2;
 
359
                top = bw->base.downGC;
 
360
                bottom = bw->base.upGC;
 
361
                for (i = 0; i < bw->base.shadow_width; i++) {
 
362
                        if (i == half) {
 
363
                                tmp = bottom;
 
364
                                bottom = top;
 
365
                                top = tmp;
 
366
                        }
 
367
                        /* top horizontal line */
 
368
                        XDrawLine (XtDisplay(w), XtWindow(w), top,
 
369
                                i + 1, i, w->core.width - i - 1, i);
 
370
                        /* left vertical line */
 
371
                        XDrawLine (XtDisplay(w), XtWindow(w), top,
 
372
                                i, i, i, w->core.height - i - 2);
 
373
                        /* bottom horizontal line */
 
374
                        XDrawLine (XtDisplay(w), XtWindow(w), bottom,
 
375
                                i + 1, w->core.height - 1- i, w->core.width - i - 1,
 
376
                                w->core.height-1-i);
 
377
                        /* right vertical line */
 
378
                        XDrawLine (XtDisplay(w), XtWindow(w), bottom,
 
379
                                w->core.width-1-i, i, w->core.width-1-i, w->core.height-i-1);
 
380
                }
 
381
        }
 
382
#ifdef DEBUG_BASE2
 
383
        printf ("%s:  Redisplay() ..end\n", __FILE__);
 
384
#endif
 
385
}
 
386
 
 
387
 
 
388
/*
 
389
 * action function definitions
 
390
 */
 
391
 
 
392
 
 
393
/*
 
394
 * called if TAB was pressed
 
395
 */
 
396
static void
 
397
Tab (Widget w, XEvent *event, String *params, Cardinal *num_params)
 
398
{
 
399
        XwBaseWidget bw = (XwBaseWidget) w, nw;
 
400
        static Time t = CurrentTime;
 
401
        
 
402
        /* let's pass the event - may be it's usefull .. */
 
403
#ifdef DEBUG_BASE
 
404
        printf ("%s: Tab('%s', ..)\n", __FILE__, w->core.name);
 
405
#endif
 
406
        XtCallCallbackList (w, ((XwBaseWidget)w)->base.tab_callbacks, event);
 
407
        if (*num_params) {
 
408
                nw = bw;
 
409
                while (1) {
 
410
                        if (!XtIsXwWidget(nw))
 
411
                                break;
 
412
                        if (*params[0] == 'p') {
 
413
                                /* previous */
 
414
                                nw = (XwBaseWidget)nw->base.prev;
 
415
                        } else {
 
416
                                /* next */
 
417
                                nw = (XwBaseWidget)nw->base.next;
 
418
                        }
 
419
                        if (!nw)
 
420
                                break;
 
421
                        if (XtCallAcceptFocus ((Widget)nw, &t)) {
 
422
                                w = (Widget)nw;
 
423
                                /* XtSetKeyboardFocus (XtParent(w), w); */
 
424
                                break;
 
425
                        }
 
426
                }
 
427
        }
 
428
}
 
429
 
 
430
/*
 
431
 * change border color
 
432
 */
 
433
/* ARGSUSED */
 
434
static void
 
435
Focus (Widget w, XEvent *event, String *params, Cardinal *num_params)
 
436
{
 
437
        Pixel c;
 
438
#ifdef DEBUG_BASE
 
439
        printf ("%s: Focus ('%s', .., %s)\n", __FILE__, w->core.name, *params);
 
440
#endif
 
441
        if (*params[0] == 'i') {
 
442
                XtVaGetValues (w, XtNforeground, &c, NULL);
 
443
        } else {
 
444
                XtVaGetValues (w, XtNbackground, &c, NULL);
 
445
        }
 
446
        XtVaSetValues (w, XtNborderColor, c, NULL);
 
447
}
 
448
 
 
449
/* ARGSUSED */
 
450
static void
 
451
GetFocus (Widget w, XEvent *event, String *params, Cardinal *num_params)
 
452
{
 
453
        static Time t = CurrentTime;
 
454
#ifdef DEBUG_BASE
 
455
    printf ("%s: GetFocus(%s)\n", __FILE__, XtName(w));
 
456
#endif
 
457
        if (XtCallAcceptFocus(w, &t)) {
 
458
                /* XtSetKeyboardFocus (XtParent(w), w); */
 
459
        }
 
460
}
 
461
 
 
462
/*EOF*/
 
463