1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
|
."remove .ig hn for full docs
.de hi
.ig eh
..
.de eh
..
.TH "" 3 "" "Version 3.0" "Free Widget Foundation"
.SH NAME
XfwfArrow
.SH DESCRIPTION
The Arrow widget is usually part of a composite scrollbar widget. It
draws a triangle pointing up, down, left or right, depending on the
\fIdirection\fP resource. It has a single callback, that is repeatedly
called as long as a mouse button -- button 1 by default -- is pressed.
The triangle has a 3D shadow, the size of which can be controlled with
a resource. The shadow is either stippled or colored, depending on the
\fIshadowScheme\fP and associated resources (see the XfwfFrame widget).
.SS "Public variables"
.ps-2
.TS
center box;
cBsss
lB|lB|lB|lB
l|l|l|l.
XfwfArrow
Name Class Type Default
XtNdirection XtCDirection Alignment XfwfTop
XtNforeground XtCForeground Pixel XtDefaultBackground
XtNarrowShadow XtCArrowShadow Dimension 2
XtNinitialDelay XtCInitialDelay Cardinal 500
XtNrepeatDelay XtCRepeatDelay Cardinal 200
XtNcallback XtCCallback Callback NULL
.TE
.ps
.TP
.I "XtNdirection"
The direction of the arrow (triangle) is given by the \fIdirection\fP
resource, which is of type \fIAlignment\fP. Only \fI"top"\fP (\fIXfwfTop\fP),
\fI"bottom"\fP (\fIXfwfBottom\fP), \fI"left"\fP (\fIXfwfLeft\fP) and \fI"right"\fP
(\fIXfwfRight\fP) are valid directions. Other directions result in a
warning.
.hi
.nf
Alignment direction = XfwfTop
.fi
.eh
.TP
.I "XtNforeground"
The color of the arrow also determines the color of the 3D shadow,
at least if \fIshadowScheme\fP is set to \fIXfwfAuto\fP, as it is by default.
.hi
.nf
Pixel foreground = <String>XtDefaultBackground
.fi
.eh
.TP
.I "XtNarrowShadow"
The width of the arrow's shadow is by default 2 pixels.
.hi
.nf
Dimension arrowShadow = 2
.fi
.eh
.TP
.I "XtNinitialDelay"
When the user presses and then holds the mouse button, the action
function waits some milliseconds before it starts repeating the
callbacks.
.hi
.nf
Cardinal initialDelay = 500
.fi
.eh
.TP
.I "XtNrepeatDelay"
Between repeated calls to the callback routines, the arrow widget
will wait a few milliseconds.
.hi
.nf
Cardinal repeatDelay = 200
.fi
.eh
.TP
.I "XtNcallback"
The \fIcallback\fP function is called by the \fIactivate\fP action. It is
called repeatedly until the mouse button that triggered the action is
released again.
.hi
.nf
<Callback> XtCallbackList callback = NULL
.fi
.eh
.ps-2
.TS
center box;
cBsss
lB|lB|lB|lB
l|l|l|l.
XfwfBoard
Name Class Type Default
XtNabs_x XtCAbs_x Position 0
XtNrel_x XtCRel_x Float "0.0"
XtNabs_y XtCAbs_y Position 0
XtNrel_y XtCRel_y Float "0.0"
XtNabs_width XtCAbs_width Position 0
XtNrel_width XtCRel_width Float "1.0"
XtNabs_height XtCAbs_height Position 0
XtNrel_height XtCRel_height Float "1.0"
XtNhunit XtCHunit Float "1.0"
XtNvunit XtCVunit Float "1.0"
XtNlocation XtCLocation String NULL
.TE
.ps
.ps-2
.TS
center box;
cBsss
lB|lB|lB|lB
l|l|l|l.
XfwfFrame
Name Class Type Default
XtNcursor XtCCursor Cursor None
XtNframeType XtCFrameType FrameType XfwfRaised
XtNframeWidth XtCFrameWidth Dimension 0
XtNouterOffset XtCOuterOffset Dimension 0
XtNinnerOffset XtCInnerOffset Dimension 0
XtNshadowScheme XtCShadowScheme ShadowScheme XfwfAuto
XtNtopShadowColor XtCTopShadowColor Pixel compute_topcolor
XtNbottomShadowColor XtCBottomShadowColor Pixel compute_bottomcolor
XtNtopShadowStipple XtCTopShadowStipple Bitmap NULL
XtNbottomShadowStipple XtCBottomShadowStipple Bitmap NULL
.TE
.ps
.ps-2
.TS
center box;
cBsss
lB|lB|lB|lB
l|l|l|l.
XfwfCommon
Name Class Type Default
XtNtraversalOn XtCTraversalOn Boolean True
XtNhighlightThickness XtCHighlightThickness Dimension 2
XtNhighlightColor XtCHighlightColor Pixel XtDefaultForeground
XtNhighlightPixmap XtCHighlightPixmap Pixmap None
XtNnextTop XtCNextTop Callback NULL
XtNuserData XtCUserData Pointer NULL
.TE
.ps
.ps-2
.TS
center box;
cBsss
lB|lB|lB|lB
l|l|l|l.
Composite
Name Class Type Default
XtNchildren XtCChildren WidgetList NULL
insertPosition XtCInsertPosition XTOrderProc NULL
numChildren XtCNumChildren Cardinal 0
.TE
.ps
.ps-2
.TS
center box;
cBsss
lB|lB|lB|lB
l|l|l|l.
Core
Name Class Type Default
XtNx XtCX Position 0
XtNy XtCY Position 0
XtNwidth XtCWidth Dimension 0
XtNheight XtCHeight Dimension 0
borderWidth XtCBorderWidth Dimension 0
XtNcolormap XtCColormap Colormap NULL
XtNdepth XtCDepth Int 0
destroyCallback XtCDestroyCallback XTCallbackList NULL
XtNsensitive XtCSensitive Boolean True
XtNtm XtCTm XTTMRec NULL
ancestorSensitive XtCAncestorSensitive Boolean False
accelerators XtCAccelerators XTTranslations NULL
borderColor XtCBorderColor Pixel 0
borderPixmap XtCBorderPixmap Pixmap NULL
background XtCBackground Pixel 0
backgroundPixmap XtCBackgroundPixmap Pixmap NULL
mappedWhenManaged XtCMappedWhenManaged Boolean True
XtNscreen XtCScreen Screen * NULL
.TE
.ps
.SS "Translations"
.nf
<Btn1Down>: activate_and_start_timer()
.fi
.nf
<Btn1Up>: stop_timer()
.fi
.hi
.SS "Actions"
.TP
.I "activate_and_start_timer
The \fIactivate\fP action calls the \fIcallback\fP routine once and installs
a timeout routine.
.hi
.nf
void activate_and_start_timer($, XEvent* event, String* params, Cardinal* num_params)
{
if (event->type != ButtonPress) {
XtWarning("The Arrow activate action isn't bound to a BtnDown event");
return;
}
XtCallCallbackList($, $callback, NULL);
$timer = XtAppAddTimeOut(XtWidgetToApplicationContext($),
$initialDelay, timer_callback, $);
}
.fi
.eh
.TP
.I "stop_timer
.hi
.nf
void stop_timer($, XEvent* event, String* params, Cardinal* num_params)
{
XtRemoveTimeOut($timer);
}
.fi
.eh
.hi
.hi
.SH "Importss"
The stipple for the shadows are loaded from a bitmap file.
.nf
.B incl
"stip4.bm"
.fi
.nf
.B incl
<stdio.h>
.fi
.nf
.B incl
<assert.h>
.fi
.hi
.hi
.SS "Private variables"
The three GC's are used for drawing the arrow and its shadows.
.nf
GC arrowgc
.fi
.nf
GC arrowlightgc
.fi
.nf
GC arrowdarkgc
.fi
The repeating callback is implemented with a time out routine. The
timer is a private variable of the widget.
.nf
XtIntervalId timer
.fi
.hi
.hi
.SS "Methods"
The \fIinitialize\fP method sets initial values for the three GC's and
checks the \fIdirection\fP resource.
.nf
initialize(Widget request, $, ArgList args, Cardinal * num_args)
{
if ($direction != XfwfTop $direction != XfwfLeft
$direction != XfwfRight $direction != XfwfBottom) {
XtWarning("direction of Arrow widget incorrect; set to `top'");
$direction = XfwfTop;
}
$arrowgc = NULL; create_arrowgc($);
$arrowlightgc = NULL; create_arrowlightgc($);
$arrowdarkgc = NULL; create_arrowdarkgc($);
}
.fi
When the \fIforeground\fP, \fIarrowShadow\fP or \fIdirection\fP resource changes,
the widget has to be redrawn. Like in the \fIinitialize\fP method, the
\fIdirection\fP resource needs to be checked for valid values.
If the inherited resource \fIshadowScheme\fP or one of its family changes, new
GC's need to be created.
.nf
Boolean set_values(Widget old, Widget request, $, ArgList args, Cardinal * num_args)
{
Boolean need_redisplay = False;
if ($direction != XfwfTop $direction != XfwfLeft
$direction != XfwfRight $direction != XfwfBottom) {
XtWarning("direction of Arrow widget incorrect; set to `top'");
$direction = XfwfTop;
}
if ($old$direction != $direction)
need_redisplay = True;
if ($old$foreground != $foreground) {
create_arrowgc($);
need_redisplay = True;
}
if ($old$arrowShadow != $arrowShadow)
need_redisplay = True;
if ($shadowScheme != $old$shadowScheme) {
create_arrowdarkgc($);
create_arrowlightgc($);
need_redisplay = True;
} else if ($shadowScheme == XfwfColor) {
if ($topShadowColor != $old$topShadowColor) {
create_arrowlightgc($);
need_redisplay = True;
}
if ($bottomShadowColor != $old$bottomShadowColor) {
create_arrowdarkgc($);
need_redisplay = True;
}
} else if ($shadowScheme = XfwfStipple) {
if ($topShadowStipple != $old$topShadowStipple) {
create_arrowlightgc($);
need_redisplay = True;
}
if ($bottomShadowStipple != $old$bottomShadowStipple) {
create_arrowdarkgc($);
need_redisplay = True;
}
}
return need_redisplay;
}
.fi
The arrow is drawn as large as possible. The arrow is actually a triangle
with 3D shadows. \fIp1\fP is the triangle itself, \fIp2\fP, \fIp3\fP and \fIp4\fP are the
shadows.
\fBdef\fP point(p, i, xx, yy) =
(p[i ].x =xx ),(p[i ].y =yy )
.nf
expose($, XEvent * event, Region region)
{
XPoint p1[3], p2[4], p3[4], p4[4];
Position x, y;
Dimension width, height, a, a2, a3;
assert($direction == XfwfTop || $direction == XfwfLeft
|| $direction == XfwfRight || $direction == XfwfBottom);
if (! XtIsRealized($)) return;
if (region != NULL) {
XSetRegion(XtDisplay($), $arrowgc, region);
XSetRegion(XtDisplay($), $arrowlightgc, region);
XSetRegion(XtDisplay($), $arrowdarkgc, region);
}
$compute_inside($, x, y, width, height);
a = $arrowShadow;
switch ($direction) {
case XfwfTop:
a2 = (1.0 + 0.71*width/height) * a;
a3 = (1.0 + 0.83*height/width) * a;
point(p1, 0, x + width/2, y + a3);
point(p1, 1, x + a2, y + height - a);
point(p1, 2, x + width - a2, y + height - a);
XFillPolygon(XtDisplay($), $window, $arrowgc, p1, 3, Convex,
CoordModeOrigin);
if (a == 0) break;
point(p2, 0, x + width/2, y);
point(p2, 1, x + width/2, y + a3);
point(p2, 2, x + width - a2, y + height - a);
point(p2, 3, x + width, y + height);
point(p3, 0, x + a2, y + height - a);
point(p3, 1, x, y + height);
point(p3, 2, x + width, y + height);
point(p3, 3, x + width - a2, y + height - a);
point(p4, 0, x + width/2, y);
point(p4, 1, x, y + height);
point(p4, 2, x + a2, y + height - a);
point(p4, 3, x + width/2, y + a3);
XFillPolygon(XtDisplay($), $window, $arrowdarkgc, p2, 4, Convex,
CoordModeOrigin);
XFillPolygon(XtDisplay($), $window, $arrowdarkgc, p3, 4, Convex,
CoordModeOrigin);
XFillPolygon(XtDisplay($), $window, $arrowlightgc, p4, 4, Convex,
CoordModeOrigin);
break;
case XfwfLeft:
a2 = (1.0 + 0.83*width/height) * a;
a3 = (1.0 + 0.71*height/width) * a;
point(p1, 0, x + a2, y + height/2);
point(p1, 1, x + width - a, y + a3);
point(p1, 2, x + width - a, y + height - a3);
XFillPolygon(XtDisplay($), $window, $arrowgc, p1, 3, Convex,
CoordModeOrigin);
if ($arrowShadow == 0) break;
point(p2, 0, x + width, y);
point(p2, 1, x, y + height/2);
point(p2, 2, x + a2, y + height/2);
point(p2, 3, x + width - a, y + a3);
point(p3, 0, x, y + height/2);
point(p3, 1, x + width, y + height);
point(p3, 2, x + width - a, y + height - a3);
point(p3, 3, x + a2, y + height/2);
point(p4, 0, x + width, y);
point(p4, 1, x + width - a, y + a3);
point(p4, 2, x + width - a, y + height - a3);
point(p4, 3, x + width, y + height);
XFillPolygon(XtDisplay($), $window, $arrowlightgc, p2, 4, Convex,
CoordModeOrigin);
XFillPolygon(XtDisplay($), $window, $arrowdarkgc, p3, 4, Convex,
CoordModeOrigin);
XFillPolygon(XtDisplay($), $window, $arrowdarkgc, p4, 4, Convex,
CoordModeOrigin);
break;
case XfwfBottom:
a2 = (1.0 + 0.71*width/height) * a;
a3 = (1.0 + 0.83*height/width) * a;
point(p1, 0, x + width/2, y + height - a3);
point(p1, 1, x + a2, y + a);
point(p1, 2, x + width - a2, y + a);
XFillPolygon(XtDisplay($), $window, $arrowgc, p1, 3, Convex,
CoordModeOrigin);
if ($arrowShadow == 0) break;
point(p2, 0, x, y);
point(p2, 1, x + width/2, y + height);
point(p2, 2, x + width/2, y + height - a3);
point(p2, 3, x + a2, y + a);
point(p3, 0, x + width, y);
point(p3, 1, x + width - a2, y + a);
point(p3, 2, x + width/2, y + height - a3);
point(p3, 3, x + width/2, y + height);
point(p4, 0, x, y);
point(p4, 1, x + a2, y + a);
point(p4, 2, x + width - a2, y + a);
point(p4, 3, x + width, y);
XFillPolygon(XtDisplay($), $window, $arrowlightgc, p2, 4, Convex,
CoordModeOrigin);
XFillPolygon(XtDisplay($), $window, $arrowdarkgc, p3, 4, Convex,
CoordModeOrigin);
XFillPolygon(XtDisplay($), $window, $arrowlightgc, p4, 4, Convex,
CoordModeOrigin);
break;
case XfwfRight:
a2 = (1.0 + 0.83*width/height) * a;
a3 = (1.0 + 0.71*height/width) * a;
point(p1, 0, x + width - $arrowShadow, y + height/2);
point(p1, 1, x + $arrowShadow, y + $arrowShadow);
point(p1, 2, x + $arrowShadow, y + height - $arrowShadow);
XFillPolygon(XtDisplay($), $window, $arrowgc, p1, 3, Convex,
CoordModeOrigin);
if ($arrowShadow == 0) break;
point(p2, 0, x, y + height);
point(p2, 1, x + width, y + height/2);
point(p2, 2, x + width - a2, y + height/2);
point(p2, 3, x + a, y + height - a3);
point(p3, 0, x, y);
point(p3, 1, x + a, y + a3);
point(p3, 2, x + width - a2, y + height/2);
point(p3, 3, x + width, y + height/2);
point(p4, 0, x, y);
point(p4, 1, x, y + height);
point(p4, 2, x + a, y + height - a3);
point(p4, 3, x + a, y + a3);
XFillPolygon(XtDisplay($), $window, $arrowdarkgc, p2, 4, Convex,
CoordModeOrigin);
XFillPolygon(XtDisplay($), $window, $arrowlightgc, p3, 4, Convex,
CoordModeOrigin);
XFillPolygon(XtDisplay($), $window, $arrowlightgc, p4, 4, Convex,
CoordModeOrigin);
break;
}
if (region != NULL) {
XSetClipMask(XtDisplay($), $arrowgc, None);
XSetClipMask(XtDisplay($), $arrowlightgc, None);
XSetClipMask(XtDisplay($), $arrowdarkgc, None);
}
}
.fi
.hi
.hi
.SH "Utilities"
The time-out calls the \fItimer_callback\fP routine. The routine
re-installs the time-out and calls the \fIcallback\fP function (but in the
reverse order, because we do not want time-outs to overtake each
other). The delay is now \fIrepeatDelay\fP instead of \fIinitialDelay\fP.
.nf
timer_callback(XtPointer client_data, XtIntervalId * timer)
{
Widget $ = (Widget) client_data;
XtCallCallbackList($, $callback, NULL);
$timer = XtAppAddTimeOut(XtWidgetToApplicationContext($),
$repeatDelay, timer_callback, $);
}
.fi
The GC for the triangle is created by a utility function. It destroys the
old GC and then creates a new one, based on the \fIforeground\fP resource.
.nf
create_arrowgc($)
{
XtGCMask mask;
XGCValues values;
if ($arrowgc != NULL) XtReleaseGC($, $arrowgc);
mask = GCForeground;
values.foreground = $foreground;
$arrowgc = XtGetGC($, mask, values);
}
.fi
The GC for the light shadow is dependent on the inherited \fIshadowScheme\fP
resource. It is the same routine as for the shadows in the XfwfFrame widget.
.nf
create_arrowlightgc($)
{
XtGCMask mask;
XGCValues values;
if ($arrowlightgc != NULL) XtReleaseGC($, $arrowlightgc);
switch ($shadowScheme) {
case XfwfColor:
mask = GCForeground;
values.foreground = $topShadowColor;
break;
case XfwfStipple:
mask = GCFillStyle | GCStipple | GCForeground | GCBackground;
values.fill_style = FillOpaqueStippled;
values.background = $background_pixel;
values.stipple = $topShadowStipple;
values.foreground = WhitePixelOfScreen(XtScreen($));
break;
case XfwfAuto:
if (DefaultDepthOfScreen(XtScreen($)) > 4
$lighter_color($, $foreground, values.foreground)) {
mask = GCForeground;
} else {
mask = GCFillStyle | GCBackground | GCForeground | GCStipple;
values.fill_style = FillOpaqueStippled;
values.background = $foreground;
values.foreground = WhitePixelOfScreen(XtScreen($));
values.stipple =
XCreateBitmapFromData(XtDisplay($),
RootWindowOfScreen(XtScreen($)),
stip4_bits, stip4_width, stip4_height);
}
break;
}
$arrowlightgc = XtGetGC($, mask, values);
}
.fi
The routine for the dark part of the shadow is analogous.
.nf
create_arrowdarkgc($)
{
XtGCMask mask;
XGCValues values;
if ($arrowdarkgc != NULL) XtReleaseGC($, $arrowdarkgc);
switch ($shadowScheme) {
case XfwfColor:
mask = GCForeground;
values.foreground = $bottomShadowColor;
break;
case XfwfStipple:
mask = GCFillStyle | GCStipple | GCForeground | GCBackground;
values.fill_style = FillOpaqueStippled;
values.stipple = $bottomShadowStipple;
values.foreground = BlackPixelOfScreen(XtScreen($));
values.background = $background_pixel;
break;
case XfwfAuto:
if (DefaultDepthOfScreen(XtScreen($)) > 4
$darker_color($, $foreground, values.foreground)) {
mask = GCForeground;
} else {
mask = GCFillStyle | GCBackground | GCForeground | GCStipple;
values.fill_style = FillOpaqueStippled;
values.background = $foreground;
values.foreground = WhitePixelOfScreen(XtScreen($));
values.stipple =
XCreateBitmapFromData(XtDisplay($),
RootWindowOfScreen(XtScreen($)),
stip4_bits, stip4_width, stip4_height);
}
break;
}
$arrowdarkgc = XtGetGC($, mask, values);
}
.fi
.hi
|