2
* Base.c; vi: tabstop=4
4
* Copyright (C) 1998 Rasca, Berlin
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.
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.
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.
23
#define __FILE__ "Base.c"
26
#include <X11/StringDefs.h>
27
#include <X11/IntrinsicP.h>
31
#define offset(member) XtOffsetOf (XwBaseRec, member)
33
static XtResource resources [] = {
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 },
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" },
73
* action function declarations
75
static void Tab (Widget, XEvent*, String*, Cardinal*);
76
static void Focus (Widget, XEvent*, String *, Cardinal *);
77
static void GetFocus (Widget, XEvent*, String *, Cardinal *);
82
static XtActionsRec actions [] = {
85
{"get-focus", GetFocus },
89
* default translation table
91
static char defaultTranslations [] = "<FocusIn>: focus(in)\n<FocusOut>: focus(out)\n<Key>Tab: tab()";
94
* method function declarations
97
ClassPartInitialize (WidgetClass wc),
98
Initialize (Widget t, Widget n, ArgList args, Cardinal *num_args),
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 *);
105
#define SuperClass ((CoreWidgetClass)&coreClassRec)
107
* class record initialization
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,
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,
144
{ /* base_class fields */
145
/* tab_action */ Tab,
146
/* focus_action */ Focus,
147
/* getfocus_action */ GetFocus,
151
WidgetClass xwBaseWidgetClass = (WidgetClass) &xwBaseClassRec;
154
* downward chained: first this one and then subclasses
157
ClassPartInitialize (WidgetClass wc)
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;
169
* method function definitions
172
InitGC (XwBaseWidget bw)
174
Widget w = (Widget) bw;
179
printf ("%s: InitGC (%s)\n", __FILE__, bw->core.name);
181
mask = GCLineStyle | GCLineWidth | GCForeground ;
182
gcv.line_style = LineSolid;
185
gcv.foreground = bw->base.shadow_bottom_pixel;
186
bw->base.downGC = XtGetGC (w, mask, &gcv);
188
gcv.foreground = bw->base.shadow_top_pixel;
189
bw->base.upGC = XtGetGC (w, mask, &gcv);
191
gcv.foreground =BlackPixel(XtDisplay(w),XScreenNumberOfScreen(XtScreen(w)));
192
bw->base.blackGC = XtGetGC (w, mask, &gcv);
199
Initialize (Widget treq, Widget tnew, ArgList args, Cardinal *num_args)
201
XwBaseWidget new = (XwBaseWidget) tnew;
203
printf ("%s: Initialize (%s)\n", __FILE__, new->core.name);
212
SetValues (Widget curr, Widget req, Widget reply, ArgList args, Cardinal *nargs)
214
Boolean redraw = False;
215
XwBaseWidget bw = (XwBaseWidget) curr;
216
XwBaseWidget new= (XwBaseWidget) reply;
218
if ((bw->base.shadow_top_pixel != new->base.shadow_top_pixel) ||
219
(bw->base.shadow_bottom_pixel != new->base.shadow_bottom_pixel))
221
XtReleaseGC (curr, bw->base.upGC);
222
XtReleaseGC (curr, bw->base.downGC);
223
XtReleaseGC (curr, bw->base.blackGC);
227
if ((bw->base.shadow_type != new->base.shadow_type) ||
228
(bw->base.shadow_width != new->base.shadow_width)) {
232
printf("%s: SetValues (%s ..) rv=%d\n",__FILE__,new->core.name,(int)redraw);
243
XwBaseWidget bw = (XwBaseWidget) w;
245
printf ("%s: Destroy (%s)\n", __FILE__, w->core.name);
247
XtReleaseGC (w, bw->base.upGC);
248
XtReleaseGC (w, bw->base.downGC);
249
XtReleaseGC (w, bw->base.blackGC);
260
printf ("%s: Resize (%s)\n", __FILE__, w->core.name);
266
* redisplay the widget (draw 3d frame)
269
Redisplay (Widget w, XEvent *event, Region region)
271
XwBaseWidget bw = (XwBaseWidget) w;
275
printf ("%s: Redisplay (%s) sw=%d type=%d\n",
276
__FILE__, w->core.name, bw->base.shadow_width, bw->base.shadow_type);
279
if (!XtIsRealized(w))
282
if (bw->base.shadow_width < 1)
285
/* seems not to work :(
286
if ((region != NULL) && (!XEmptyRegion(region))) {
289
rc = XRectInRegion (region, w->core.x, w->core.y,
290
w->core.width, w->core.height);
291
if ((rc != RectanglePart) && (rc != RectangleIn)) {
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
301
XDrawLine (XtDisplay(w), XtWindow(w), bw->base.upGC,
302
i + 1, i, w->core.width - i - 1, i);
303
/* left vertical line
305
XDrawLine (XtDisplay(w), XtWindow(w), bw->base.upGC,
306
i, i, i, w->core.height - i - 1);
309
/* draw black line */
310
/* bottom horizontal line
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
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);
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);
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);
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);
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,
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);
356
} else if (bw->base.shadow_type == XtShadowFlat) {
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++) {
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,
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);
383
printf ("%s: Redisplay() ..end\n", __FILE__);
389
* action function definitions
394
* called if TAB was pressed
397
Tab (Widget w, XEvent *event, String *params, Cardinal *num_params)
399
XwBaseWidget bw = (XwBaseWidget) w, nw;
400
static Time t = CurrentTime;
402
/* let's pass the event - may be it's usefull .. */
404
printf ("%s: Tab('%s', ..)\n", __FILE__, w->core.name);
406
XtCallCallbackList (w, ((XwBaseWidget)w)->base.tab_callbacks, event);
410
if (!XtIsXwWidget(nw))
412
if (*params[0] == 'p') {
414
nw = (XwBaseWidget)nw->base.prev;
417
nw = (XwBaseWidget)nw->base.next;
421
if (XtCallAcceptFocus ((Widget)nw, &t)) {
423
/* XtSetKeyboardFocus (XtParent(w), w); */
431
* change border color
435
Focus (Widget w, XEvent *event, String *params, Cardinal *num_params)
439
printf ("%s: Focus ('%s', .., %s)\n", __FILE__, w->core.name, *params);
441
if (*params[0] == 'i') {
442
XtVaGetValues (w, XtNforeground, &c, NULL);
444
XtVaGetValues (w, XtNbackground, &c, NULL);
446
XtVaSetValues (w, XtNborderColor, c, NULL);
451
GetFocus (Widget w, XEvent *event, String *params, Cardinal *num_params)
453
static Time t = CurrentTime;
455
printf ("%s: GetFocus(%s)\n", __FILE__, XtName(w));
457
if (XtCallAcceptFocus(w, &t)) {
458
/* XtSetKeyboardFocus (XtParent(w), w); */