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
|
/* Generated by wbuild from "Slider2.w"
** (generator version $Revision: 2.0 $ of $Date: 93/07/06 16:08:04 $)
*/
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#include "stip4.bm"
#include <stdio.h>
#include "Slider2P.h"
static void start(
#if NeedFunctionPrototypes
Widget,XEvent*,String*,Cardinal*
#endif
);
static void finish(
#if NeedFunctionPrototypes
Widget,XEvent*,String*,Cardinal*
#endif
);
static void drag(
#if NeedFunctionPrototypes
Widget,XEvent*,String*,Cardinal*
#endif
);
static XtActionsRec actionsList[] = {
{"start", start},
{"finish", finish},
{"drag", drag},
};
static char defaultTranslations[] = "\
<Btn1Down>: start() \n\
<Btn1Motion>: drag() \n\
<Btn1Up>: finish() \n\
";
static void _resolve_inheritance(
#if NeedFunctionPrototypes
WidgetClass
#endif
);
static void compute_thumb(
#if NeedFunctionPrototypes
Widget,Position *,Position *,Dimension *,Dimension *
#endif
);
static void compute_inside(
#if NeedFunctionPrototypes
Widget,Position *,Position *,Dimension *,Dimension *
#endif
);
static void expose(
#if NeedFunctionPrototypes
Widget,XEvent *,Region
#endif
);
static void initialize(
#if NeedFunctionPrototypes
Widget ,Widget,ArgList ,Cardinal *
#endif
);
static void move_thumb(
#if NeedFunctionPrototypes
Widget,int ,int ,int ,int ,int ,int
#endif
);
static void compute_info(
#if NeedFunctionPrototypes
Widget,Position *,Position *,Dimension *,Dimension *,float *,float *,float *,float *
#endif
);
static Boolean set_values(
#if NeedFunctionPrototypes
Widget ,Widget ,Widget,ArgList ,Cardinal *
#endif
);
static void scroll_response(
#if NeedFunctionPrototypes
Widget ,XtPointer ,XtPointer
#endif
);
static void create_gc(
#if NeedFunctionPrototypes
Widget
#endif
);
static void create_graygc(
#if NeedFunctionPrototypes
Widget
#endif
);
static void create_thumbgc(
#if NeedFunctionPrototypes
Widget
#endif
);
static void create_thumblightgc(
#if NeedFunctionPrototypes
Widget
#endif
);
static void create_thumbdarkgc(
#if NeedFunctionPrototypes
Widget
#endif
);
/*ARGSUSED*/static void create_gc(self)Widget self;
{
XtGCMask mask;
XGCValues values;
if (((XfwfSlider2Widget)self)->xfwfLabel.gc != NULL) XtReleaseGC(self, ((XfwfSlider2Widget)self)->xfwfLabel.gc);
values.background = ((XfwfSlider2Widget)self)->xfwfSlider2.thumbColor;
values.foreground = ((XfwfSlider2Widget)self)->xfwfLabel.foreground;
values.font = ((XfwfSlider2Widget)self)->xfwfLabel.font->fid;
mask = GCFont | GCBackground | GCForeground;
((XfwfSlider2Widget)self)->xfwfLabel.gc = XtGetGC(self, mask, &values);
if (((XfwfSlider2Widget)self)->xfwfLabel.rv_gc != NULL) XtReleaseGC(self, ((XfwfSlider2Widget)self)->xfwfLabel.rv_gc);
values.foreground = ((XfwfSlider2Widget)self)->xfwfSlider2.thumbColor;
values.background = ((XfwfSlider2Widget)self)->xfwfLabel.foreground;
values.font = ((XfwfSlider2Widget)self)->xfwfLabel.font->fid;
mask = GCFont | GCBackground | GCForeground;
((XfwfSlider2Widget)self)->xfwfLabel.rv_gc = XtGetGC(self, mask, &values);
}
/*ARGSUSED*/static void create_graygc(self)Widget self;
{
XtGCMask mask;
XGCValues values;
if (((XfwfSlider2Widget)self)->xfwfLabel.graygc != NULL) XtReleaseGC(self, ((XfwfSlider2Widget)self)->xfwfLabel.graygc);
values.foreground = ((XfwfSlider2Widget)self)->xfwfSlider2.thumbColor;
values.stipple =
XCreateBitmapFromData(XtDisplay(self),
RootWindowOfScreen(XtScreen(self)),
stip4_bits, stip4_width, stip4_height);
values.fill_style = FillStippled;
mask = GCForeground | GCStipple | GCFillStyle;
((XfwfSlider2Widget)self)->xfwfLabel.graygc = XtGetGC(self, mask, &values);
}
/*ARGSUSED*/static void create_thumbgc(self)Widget self;
{
XtGCMask mask;
XGCValues values;
if (((XfwfSlider2Widget)self)->xfwfSlider2.thumbgc != NULL) XtReleaseGC(self, ((XfwfSlider2Widget)self)->xfwfSlider2.thumbgc);
if (((XfwfSlider2Widget)self)->xfwfSlider2.thumbPixmap != NULL) {
mask = GCTile | GCFillStyle;
values.tile = ((XfwfSlider2Widget)self)->xfwfSlider2.thumbPixmap;
values.fill_style = FillTiled;
} else {
mask = GCForeground;
values.foreground = ((XfwfSlider2Widget)self)->xfwfSlider2.thumbColor;
}
((XfwfSlider2Widget)self)->xfwfSlider2.thumbgc = XtGetGC(self, mask, &values);
}
/*ARGSUSED*/static void create_thumblightgc(self)Widget self;
{
XtGCMask mask;
XGCValues values;
if (((XfwfSlider2Widget)self)->xfwfSlider2.thumblightgc != NULL) XtReleaseGC(self, ((XfwfSlider2Widget)self)->xfwfSlider2.thumblightgc);
switch (((XfwfSlider2Widget)self)->xfwfFrame.shadowScheme) {
case XfwfColor:
mask = GCForeground;
values.foreground = ((XfwfSlider2Widget)self)->xfwfFrame.topShadowColor;
break;
case XfwfStipple:
mask = GCFillStyle | GCStipple | GCForeground | GCBackground;
values.fill_style = FillOpaqueStippled;
values.background = ((XfwfSlider2Widget)self)->xfwfSlider2.thumbColor;
values.stipple = ((XfwfSlider2Widget)self)->xfwfFrame.topShadowStipple;
values.foreground = WhitePixelOfScreen(XtScreen(self));
break;
case XfwfAuto:
if (DefaultDepthOfScreen(XtScreen(self)) > 4
&& ((XfwfSlider2WidgetClass)self->core.widget_class)->xfwfCommon_class.lighter_color(self, ((XfwfSlider2Widget)self)->xfwfSlider2.thumbColor, &values.foreground)) {
mask = GCForeground;
} else {
mask = GCFillStyle | GCBackground | GCForeground | GCStipple;
values.fill_style = FillOpaqueStippled;
values.background = ((XfwfSlider2Widget)self)->xfwfSlider2.thumbColor;
values.foreground = WhitePixelOfScreen(XtScreen(self));
values.stipple =
XCreateBitmapFromData(XtDisplay(self),
RootWindowOfScreen(XtScreen(self)),
stip4_bits, stip4_width, stip4_height);
}
break;
}
((XfwfSlider2Widget)self)->xfwfSlider2.thumblightgc = XtGetGC(self, mask, &values);
}
/*ARGSUSED*/static void create_thumbdarkgc(self)Widget self;
{
XtGCMask mask;
XGCValues values;
if (((XfwfSlider2Widget)self)->xfwfSlider2.thumbdarkgc != NULL) XtReleaseGC(self, ((XfwfSlider2Widget)self)->xfwfSlider2.thumbdarkgc);
switch (((XfwfSlider2Widget)self)->xfwfFrame.shadowScheme) {
case XfwfColor:
mask = GCForeground;
values.foreground = ((XfwfSlider2Widget)self)->xfwfFrame.bottomShadowColor;
break;
case XfwfStipple:
mask = GCFillStyle | GCStipple | GCForeground | GCBackground;
values.fill_style = FillOpaqueStippled;
values.stipple = ((XfwfSlider2Widget)self)->xfwfFrame.bottomShadowStipple;
values.foreground = BlackPixelOfScreen(XtScreen(self));
values.background = ((XfwfSlider2Widget)self)->xfwfSlider2.thumbColor;
break;
case XfwfAuto:
if (DefaultDepthOfScreen(XtScreen(self)) > 4
&& ((XfwfSlider2WidgetClass)self->core.widget_class)->xfwfCommon_class.darker_color(self, ((XfwfSlider2Widget)self)->xfwfSlider2.thumbColor, &values.foreground)) {
mask = GCForeground;
} else {
mask = GCFillStyle | GCBackground | GCForeground | GCStipple;
values.fill_style = FillOpaqueStippled;
values.background = ((XfwfSlider2Widget)self)->xfwfSlider2.thumbColor;
values.foreground = WhitePixelOfScreen(XtScreen(self));
values.stipple =
XCreateBitmapFromData(XtDisplay(self),
RootWindowOfScreen(XtScreen(self)),
stip4_bits, stip4_width, stip4_height);
}
break;
}
((XfwfSlider2Widget)self)->xfwfSlider2.thumbdarkgc = XtGetGC(self, mask, &values);
}
static XtResource resources[] = {
{XtNthumbColor,XtCThumbColor,XtRPixel,sizeof(((XfwfSlider2Rec*)NULL)->xfwfSlider2.thumbColor),XtOffsetOf(XfwfSlider2Rec,xfwfSlider2.thumbColor),XtRString,(XtPointer)XtDefaultBackground },
{XtNthumbPixmap,XtCThumbPixmap,XtRPixmap,sizeof(((XfwfSlider2Rec*)NULL)->xfwfSlider2.thumbPixmap),XtOffsetOf(XfwfSlider2Rec,xfwfSlider2.thumbPixmap),XtRImmediate,(XtPointer)NULL },
{XtNminsize,XtCMinsize,XtRDimension,sizeof(((XfwfSlider2Rec*)NULL)->xfwfSlider2.minsize),XtOffsetOf(XfwfSlider2Rec,xfwfSlider2.minsize),XtRImmediate,(XtPointer)20 },
{XtNthumbFrameWidth,XtCThumbFrameWidth,XtRDimension,sizeof(((XfwfSlider2Rec*)NULL)->xfwfSlider2.thumbFrameWidth),XtOffsetOf(XfwfSlider2Rec,xfwfSlider2.thumbFrameWidth),XtRImmediate,(XtPointer)2 },
{XtNthumbFrameType,XtCThumbFrameType,XtRFrameType,sizeof(((XfwfSlider2Rec*)NULL)->xfwfSlider2.thumbFrameType),XtOffsetOf(XfwfSlider2Rec,xfwfSlider2.thumbFrameType),XtRImmediate,(XtPointer)XfwfRaised },
{XtNscrollCallback,XtCScrollCallback,XtRCallback,sizeof(((XfwfSlider2Rec*)NULL)->xfwfSlider2.scrollCallback),XtOffsetOf(XfwfSlider2Rec,xfwfSlider2.scrollCallback),XtRImmediate,(XtPointer)NULL },
{XtNscrollResponse,XtCScrollResponse,XtRXTCallbackProc,sizeof(((XfwfSlider2Rec*)NULL)->xfwfSlider2.scrollResponse),XtOffsetOf(XfwfSlider2Rec,xfwfSlider2.scrollResponse),XtRImmediate,(XtPointer)scroll_response },
{XtNframeWidth,XtCFrameWidth,XtRDimension,sizeof(((XfwfSlider2Rec*)NULL)->xfwfFrame.frameWidth),XtOffsetOf(XfwfSlider2Rec,xfwfFrame.frameWidth),XtRImmediate,(XtPointer)2 },
{XtNframeType,XtCFrameType,XtRFrameType,sizeof(((XfwfSlider2Rec*)NULL)->xfwfFrame.frameType),XtOffsetOf(XfwfSlider2Rec,xfwfFrame.frameType),XtRImmediate,(XtPointer)XfwfSunken },
};
XfwfSlider2ClassRec xfwfSlider2ClassRec = {
{ /* core_class part */
(WidgetClass) &xfwfLabelClassRec,
"Slider2d",
sizeof(XfwfSlider2Rec),
NULL,
_resolve_inheritance,
FALSE,
initialize,
NULL,
XtInheritRealize,
actionsList,
3,
resources,
9,
NULLQUARK,
False ,
XtExposeCompressMultiple |XtExposeGraphicsExpose ,
False ,
False ,
NULL,
XtInheritResize,
expose,
set_values,
NULL,
XtInheritSetValuesAlmost,
NULL,
XtInheritAcceptFocus,
XtVersion,
NULL,
defaultTranslations,
XtInheritQueryGeometry,
XtInheritDisplayAccelerator,
NULL
},
{ /* composite_class part */
XtInheritGeometryManager,
XtInheritChangeManaged,
XtInheritInsertChild,
XtInheritDeleteChild,
NULL
},
{ /* XfwfCommon_class part */
compute_inside,
XtInherit_highlight_border,
XtInherit_unhighlight_border,
XtInherit_would_accept_focus,
XtInherit_traverse,
XtInherit_choose_color,
XtInherit_lighter_color,
XtInherit_darker_color,
NULL ,
},
{ /* XfwfFrame_class part */
0
},
{ /* XfwfBoard_class part */
XtInherit_set_abs_location,
},
{ /* XfwfLabel_class part */
XtInherit_set_label,
},
{ /* XfwfSlider2_class part */
compute_thumb,
move_thumb,
compute_info,
scroll_response,
},
};
WidgetClass xfwfSlider2WidgetClass = (WidgetClass) &xfwfSlider2ClassRec;
/*ARGSUSED*/
static void start(self,event,params,num_params)Widget self;XEvent*event;String*params;Cardinal*num_params;
{
Dimension w, h;
Position x, y;
XfwfScrollInfo info;
Boolean outside = False;
if (event->type != ButtonPress && event->type != ButtonRelease
&& event->type != MotionNotify)
XtError("The start action must be bound to a mouse event");
((XfwfSlider2WidgetClass)self->core.widget_class)->xfwfSlider2_class.compute_thumb(self, &x, &y, &w, &h);
if (event->xbutton.x < x) { /* Left of thumb */
info.reason = XfwfSPageLeft;
info.flags = XFWF_HPOS; /* Suggest a value: */
info.hpos = max(0.0, ((XfwfSlider2Widget)self)->xfwfSlider2.thumb_x - ((XfwfSlider2Widget)self)->xfwfSlider2.thumb_wd);
outside = True;
XtCallCallbackList(self, ((XfwfSlider2Widget)self)->xfwfSlider2.scrollCallback, &info);
}
if (event->xbutton.x >= x + w) { /* Right of thumb */
info.reason = XfwfSPageRight;
info.flags = XFWF_HPOS; /* Suggest a value: */
info.hpos = min(1.0, ((XfwfSlider2Widget)self)->xfwfSlider2.thumb_x + ((XfwfSlider2Widget)self)->xfwfSlider2.thumb_wd);
outside = True;
XtCallCallbackList(self, ((XfwfSlider2Widget)self)->xfwfSlider2.scrollCallback, &info);
}
if (event->xbutton.y < y) { /* Above thumb */
info.reason = XfwfSPageUp;
info.flags = XFWF_VPOS; /* Suggest a value: */
info.vpos = max(0.0, ((XfwfSlider2Widget)self)->xfwfSlider2.thumb_y - ((XfwfSlider2Widget)self)->xfwfSlider2.thumb_ht);
outside = True;
XtCallCallbackList(self, ((XfwfSlider2Widget)self)->xfwfSlider2.scrollCallback, &info);
}
if (event->xbutton.y >= y + h) { /* Below thumb */
info.reason = XfwfSPageDown;
info.flags = XFWF_VPOS; /* Suggest a value: */
info.vpos = min(1.0, ((XfwfSlider2Widget)self)->xfwfSlider2.thumb_y + ((XfwfSlider2Widget)self)->xfwfSlider2.thumb_ht);
outside = True;
XtCallCallbackList(self, ((XfwfSlider2Widget)self)->xfwfSlider2.scrollCallback, &info);
}
if (! outside) { /* Inside the thumb */
((XfwfSlider2Widget)self)->xfwfSlider2.drag_in_progress = True;
((XfwfSlider2Widget)self)->xfwfSlider2.m_delta_x = x - event->xbutton.x;
((XfwfSlider2Widget)self)->xfwfSlider2.m_delta_y = y - event->xbutton.y;
}
}
/*ARGSUSED*/
static void finish(self,event,params,num_params)Widget self;XEvent*event;String*params;Cardinal*num_params;
{
XfwfScrollInfo info;
if (((XfwfSlider2Widget)self)->xfwfSlider2.drag_in_progress) {
((XfwfSlider2Widget)self)->xfwfSlider2.drag_in_progress = False;
info.reason = XfwfSMove;
info.flags = XFWF_VPOS | XFWF_HPOS;
info.hpos = ((XfwfSlider2Widget)self)->xfwfSlider2.thumb_x;
info.vpos = ((XfwfSlider2Widget)self)->xfwfSlider2.thumb_y;
XtCallCallbackList(self, ((XfwfSlider2Widget)self)->xfwfSlider2.scrollCallback, &info);
}
}
/*ARGSUSED*/
static void drag(self,event,params,num_params)Widget self;XEvent*event;String*params;Cardinal*num_params;
{
XfwfScrollInfo info;
Dimension wd, ht, fwd, fht;
Position oldx, oldy, newx, newy, fx, fy;
float dum1, dum2;
if (! ((XfwfSlider2Widget)self)->xfwfSlider2.drag_in_progress) return;
if (event->type != ButtonPress && event->type != ButtonRelease
&& event->type != MotionNotify)
XtError("The drag action must be bound to a mouse event");
((XfwfSlider2WidgetClass)self->core.widget_class)->xfwfSlider2_class.compute_thumb(self, &oldx, &oldy, &wd, &ht);
newx = event->xbutton.x + ((XfwfSlider2Widget)self)->xfwfSlider2.m_delta_x;
newy = event->xbutton.y + ((XfwfSlider2Widget)self)->xfwfSlider2.m_delta_y;
((XfwfSlider2WidgetClass)self->core.widget_class)->xfwfSlider2_class.compute_info(self, &newx, &newy, &wd, &ht, &((XfwfSlider2Widget)self)->xfwfSlider2.thumb_x, &((XfwfSlider2Widget)self)->xfwfSlider2.thumb_y,&dum1,&dum2);
((XfwfSlider2WidgetClass)self->core.widget_class)->xfwfSlider2_class.move_thumb(self, oldx, oldy, wd, ht, newx, newy);
info.reason = XfwfSDrag;
info.flags = XFWF_VPOS | XFWF_HPOS;
info.hpos = ((XfwfSlider2Widget)self)->xfwfSlider2.thumb_x;
info.vpos = ((XfwfSlider2Widget)self)->xfwfSlider2.thumb_y;
XtCallCallbackList(self, ((XfwfSlider2Widget)self)->xfwfSlider2.scrollCallback, &info);
}
static void _resolve_inheritance(class)
WidgetClass class;
{
XfwfSlider2WidgetClass c = (XfwfSlider2WidgetClass) class;
XfwfSlider2WidgetClass super;
static CompositeClassExtensionRec extension_rec = {
NULL, NULLQUARK, XtCompositeExtensionVersion,
sizeof(CompositeClassExtensionRec), True};
CompositeClassExtensionRec *ext;
ext = (XtPointer)XtMalloc(sizeof(*ext));
*ext = extension_rec;
ext->next_extension = c->composite_class.extension;
c->composite_class.extension = ext;
if (class == xfwfSlider2WidgetClass) return;
super = (XfwfSlider2WidgetClass)class->core_class.superclass;
if (c->xfwfSlider2_class.compute_thumb == XtInherit_compute_thumb)
c->xfwfSlider2_class.compute_thumb = super->xfwfSlider2_class.compute_thumb;
if (c->xfwfSlider2_class.move_thumb == XtInherit_move_thumb)
c->xfwfSlider2_class.move_thumb = super->xfwfSlider2_class.move_thumb;
if (c->xfwfSlider2_class.compute_info == XtInherit_compute_info)
c->xfwfSlider2_class.compute_info = super->xfwfSlider2_class.compute_info;
if (c->xfwfSlider2_class.scroll_response == XtInherit_scroll_response)
c->xfwfSlider2_class.scroll_response = super->xfwfSlider2_class.scroll_response;
}
/*ARGSUSED*/static void compute_thumb(self,x,y,width,height)Widget self;Position * x;Position * y;Dimension * width;Dimension * height;
{
Position fx, fy;
Dimension fw, fh;
xfwfLabelClassRec.xfwfCommon_class.compute_inside(self, &fx, &fy, &fw, &fh);
*width = ((XfwfSlider2Widget)self)->xfwfSlider2.thumb_wd * fw + 0.5;
*height = ((XfwfSlider2Widget)self)->xfwfSlider2.thumb_ht * fh + 0.5;
if (*width < ((XfwfSlider2Widget)self)->xfwfSlider2.minsize) *width = min(fw, ((XfwfSlider2Widget)self)->xfwfSlider2.minsize);
if (*height < ((XfwfSlider2Widget)self)->xfwfSlider2.minsize) *height = min(fh, ((XfwfSlider2Widget)self)->xfwfSlider2.minsize);
*x = fx + ((XfwfSlider2Widget)self)->xfwfSlider2.thumb_x * (fw - *width) + 0.5;
*y = fy + ((XfwfSlider2Widget)self)->xfwfSlider2.thumb_y * (fh - *height) + 0.5;
}
/*ARGSUSED*/static void compute_inside(self,x,y,w,h)Widget self;Position * x;Position * y;Dimension * w;Dimension * h;
{
int tmp;
((XfwfSlider2WidgetClass)self->core.widget_class)->xfwfSlider2_class.compute_thumb(self, x, y, w, h);
*x += ((XfwfSlider2Widget)self)->xfwfSlider2.thumbFrameWidth;
*y += ((XfwfSlider2Widget)self)->xfwfSlider2.thumbFrameWidth;
tmp = *w - 2 * ((XfwfSlider2Widget)self)->xfwfSlider2.thumbFrameWidth; *w = (tmp < 0) ? 0 : tmp;
tmp = *h - 2 * ((XfwfSlider2Widget)self)->xfwfSlider2.thumbFrameWidth; *h = (tmp < 0) ? 0 : tmp;
}
/*ARGSUSED*/static void expose(self,event,region)Widget self;XEvent * event;Region region;
{
Position x, y;
Dimension wd, ht;
if (! XtIsRealized(self)) return;
if (region != NULL) {
XSetRegion(XtDisplay(self), ((XfwfSlider2Widget)self)->xfwfSlider2.thumbgc, region);
XSetRegion(XtDisplay(self), ((XfwfSlider2Widget)self)->xfwfSlider2.thumbdarkgc, region);
XSetRegion(XtDisplay(self), ((XfwfSlider2Widget)self)->xfwfSlider2.thumblightgc, region);
}
((XfwfSlider2WidgetClass)self->core.widget_class)->xfwfSlider2_class.compute_thumb(self, &x, &y, &wd, &ht);
XFillRectangle(XtDisplay(self), XtWindow(self), ((XfwfSlider2Widget)self)->xfwfSlider2.thumbgc, x, y, wd, ht);
XfwfDrawFrame(self, x, y, wd, ht, ((XfwfSlider2Widget)self)->xfwfSlider2.thumbFrameType, ((XfwfSlider2Widget)self)->xfwfSlider2.thumbFrameWidth,
((XfwfSlider2Widget)self)->xfwfSlider2.thumblightgc, ((XfwfSlider2Widget)self)->xfwfSlider2.thumbdarkgc);
if (region != NULL) {
XSetClipMask(XtDisplay(self), ((XfwfSlider2Widget)self)->xfwfSlider2.thumbgc, None);
XSetClipMask(XtDisplay(self), ((XfwfSlider2Widget)self)->xfwfSlider2.thumbdarkgc, None);
XSetClipMask(XtDisplay(self), ((XfwfSlider2Widget)self)->xfwfSlider2.thumblightgc, None);
}
xfwfLabelClassRec.core_class.expose(self, event, region);
}
/*ARGSUSED*/static void initialize(request,self,args,num_args)Widget request;Widget self;ArgList args;Cardinal * num_args;
{
((XfwfSlider2Widget)self)->xfwfSlider2.thumb_x = ((XfwfSlider2Widget)self)->xfwfSlider2.thumb_y = 0.0;
((XfwfSlider2Widget)self)->xfwfSlider2.thumb_wd = ((XfwfSlider2Widget)self)->xfwfSlider2.thumb_ht = 1.0;
((XfwfSlider2Widget)self)->xfwfSlider2.drag_in_progress = False;
create_thumbgc(self);
create_gc(self);
create_graygc(self);
((XfwfSlider2Widget)self)->xfwfSlider2.thumblightgc = NULL; create_thumblightgc(self);
((XfwfSlider2Widget)self)->xfwfSlider2.thumbdarkgc = NULL; create_thumbdarkgc(self);
}
/*ARGSUSED*/static void move_thumb(self,oldx,oldy,wd,ht,newx,newy)Widget self;int oldx;int oldy;int wd;int ht;int newx;int newy;
{
int h;
XCopyArea(XtDisplay(self), XtWindow(self), XtWindow(self),
DefaultGCOfScreen(XtScreen(self)),
oldx, oldy, wd, ht, newx, newy);
/* First check if the old and new areas do not overlap */
if (newx + wd <= oldx || oldx + wd <= newx
|| newy + ht <= oldy || oldy + ht <= newy) {
XClearArea(XtDisplay(self), XtWindow(self), oldx, oldy, wd, ht, False);
return;
} else { /* They do overlap */
h = oldy - newy;
if (h > 0)
XClearArea(XtDisplay(self), XtWindow(self), oldx, newy + ht, wd,h,False);
else if (h < 0)
XClearArea(XtDisplay(self), XtWindow(self), oldx, oldy, wd, -h, False);
if (newx < oldx)
XClearArea(XtDisplay(self), XtWindow(self), newx + wd,
max(oldy, newy), oldx - newx, ht - abs(h), False);
else if (oldx < newx)
XClearArea(XtDisplay(self), XtWindow(self), oldx, max(oldy, newy),
newx - oldx, ht - abs(h), False);
}
}
/*ARGSUSED*/static void compute_info(self,x,y,w,h,thumb_x,thumb_y,thumb_wd,thumb_ht)Widget self;Position * x;Position * y;Dimension * w;Dimension * h;float * thumb_x;float * thumb_y;float * thumb_wd;float * thumb_ht;
{
Dimension fw, fh;
Position fx, fy;
xfwfLabelClassRec.xfwfCommon_class.compute_inside(self, &fx, &fy, &fw, &fh);
*w = min(fw, max(((XfwfSlider2Widget)self)->xfwfSlider2.minsize, *w));
*h = min(fh, max(((XfwfSlider2Widget)self)->xfwfSlider2.minsize, *h));
*x = min(fx + fw - *w, max(fx, *x));
*y = min(fy + fh - *h, max(fy, *y));
*thumb_wd = ((float) *w)/fw;
*thumb_ht = ((float) *h)/fh;
*thumb_x = (*w == fw) ? 0.0 : ((float) (*x - fx))/(fw - *w);
*thumb_y = (*h == fh) ? 0.0 : ((float) (*y - fy))/(fh - *h);
}
/*ARGSUSED*/static Boolean set_values(old,request,self,args,num_args)Widget old;Widget request;Widget self;ArgList args;Cardinal * num_args;
{
Boolean need_redisplay = False;
Position x, y;
Dimension w, h;
if (((XfwfSlider2Widget)self)->xfwfSlider2.thumbPixmap != ((XfwfSlider2Widget)old)->xfwfSlider2.thumbPixmap) {
create_thumbgc(self);
need_redisplay = True;
} else if (((XfwfSlider2Widget)self)->xfwfSlider2.thumbColor != ((XfwfSlider2Widget)old)->xfwfSlider2.thumbColor) {
((XfwfSlider2Widget)self)->xfwfSlider2.thumbPixmap = NULL;
create_thumbgc(self);
need_redisplay = True;
}
if (((XfwfSlider2Widget)self)->xfwfSlider2.thumbFrameWidth != ((XfwfSlider2Widget)old)->xfwfSlider2.thumbFrameWidth)
need_redisplay = True;
if (((XfwfSlider2Widget)self)->xfwfSlider2.thumbFrameType != ((XfwfSlider2Widget)old)->xfwfSlider2.thumbFrameType)
need_redisplay = True;
if (((XfwfSlider2Widget)self)->xfwfSlider2.minsize != ((XfwfSlider2Widget)old)->xfwfSlider2.minsize) {
compute_thumb(old, &x, &y, &w, &h);
if (w < ((XfwfSlider2Widget)self)->xfwfSlider2.minsize || h < ((XfwfSlider2Widget)self)->xfwfSlider2.minsize) need_redisplay = True;
}
if (((XfwfSlider2Widget)self)->xfwfSlider2.scrollResponse != ((XfwfSlider2Widget)old)->xfwfSlider2.scrollResponse) {
((XfwfSlider2Widget)self)->xfwfSlider2.scrollResponse = ((XfwfSlider2Widget)old)->xfwfSlider2.scrollResponse;
XtWarning("scrollResponse resource may only be queried, not set");
}
return need_redisplay;
}
/*ARGSUSED*/static void scroll_response(wdg,client_data,call_data)Widget wdg;XtPointer client_data;XtPointer call_data;
{
Widget self = (Widget) client_data;
XfwfScrollInfo *inf = (XfwfScrollInfo *)call_data;
XfwfScrollInfo new_info;
float x, y, w, h;
Position newx, newy, oldx, oldy;
Dimension newwd, newht, oldwd, oldht, wd, ht;
XEvent event;
XRectangle rect;
Region clip;
Display *dpy = XtDisplay(self);
x = (inf->flags&XFWF_HPOS) && range(inf->hpos) ? inf->hpos : ((XfwfSlider2Widget)self)->xfwfSlider2.thumb_x;
y = (inf->flags&XFWF_VPOS) && range(inf->vpos) ? inf->vpos : ((XfwfSlider2Widget)self)->xfwfSlider2.thumb_y;
w = (inf->flags&XFWF_HSIZE) && range(inf->hsize) ? inf->hsize : ((XfwfSlider2Widget)self)->xfwfSlider2.thumb_wd;
h = (inf->flags&XFWF_VSIZE) && range(inf->vsize) ? inf->vsize : ((XfwfSlider2Widget)self)->xfwfSlider2.thumb_ht;
if (((XfwfSlider2Widget)self)->xfwfSlider2.thumb_wd != w || ((XfwfSlider2Widget)self)->xfwfSlider2.thumb_ht != h) { /* Size changed */
if (XtIsRealized(self))
((XfwfSlider2WidgetClass)self->core.widget_class)->xfwfSlider2_class.compute_thumb(self, &oldx, &oldy, &oldwd, &oldht);
((XfwfSlider2Widget)self)->xfwfSlider2.thumb_wd = w;
((XfwfSlider2Widget)self)->xfwfSlider2.thumb_ht = h;
((XfwfSlider2Widget)self)->xfwfSlider2.thumb_x = x;
((XfwfSlider2Widget)self)->xfwfSlider2.thumb_y = y;
if (XtIsRealized(self)) {
((XfwfSlider2WidgetClass)self->core.widget_class)->xfwfSlider2_class.compute_thumb(self, &newx, &newy, &newwd, &newht);
XClearArea(dpy, XtWindow(self), oldx, oldy, oldwd, oldht, False);
event.xexpose.x = rect.x = newx;
event.xexpose.y = rect.y = newy;
event.xexpose.width = rect.width = newwd;
event.xexpose.height = rect.height = newht;
clip = XCreateRegion();
XUnionRectWithRegion(&rect, clip, clip);
((XfwfSlider2WidgetClass)self->core.widget_class)->core_class.expose(self, &event, clip);
XDestroyRegion(clip);
}
} else if (((XfwfSlider2Widget)self)->xfwfSlider2.thumb_x != x || ((XfwfSlider2Widget)self)->xfwfSlider2.thumb_y != y) { /* Only position changed */
if (XtIsRealized(self))
((XfwfSlider2WidgetClass)self->core.widget_class)->xfwfSlider2_class.compute_thumb(self, &oldx, &oldy, &wd, &ht);
((XfwfSlider2Widget)self)->xfwfSlider2.thumb_x = x;
((XfwfSlider2Widget)self)->xfwfSlider2.thumb_y = y;
if (XtIsRealized(self)) {
((XfwfSlider2WidgetClass)self->core.widget_class)->xfwfSlider2_class.compute_thumb(self, &newx, &newy, &wd, &ht);
((XfwfSlider2WidgetClass)self->core.widget_class)->xfwfSlider2_class.move_thumb(self, oldx, oldy, wd, ht, newx, newy);
}
}
if (inf->reason != XfwfSNotify) {
new_info = *inf;
new_info.reason = XfwfSNotify;
XtCallCallbackList(self, ((XfwfSlider2Widget)self)->xfwfSlider2.scrollCallback, &new_info);
}
}
/*ARGSUSED*/void XfwfGetThumb(self,info)Widget self;XfwfScrollInfo * info;
{
if (! XtIsSubclass(self, xfwfSlider2WidgetClass))
XtError("XfwfGetThumb called with incorrect widget type");
info->reason = XfwfSNotify;
info->flags = XFWF_VPOS | XFWF_VSIZE | XFWF_HPOS | XFWF_HSIZE;
info->vpos = ((XfwfSlider2Widget)self)->xfwfSlider2.thumb_y;
info->vsize = ((XfwfSlider2Widget)self)->xfwfSlider2.thumb_ht;
info->hpos = ((XfwfSlider2Widget)self)->xfwfSlider2.thumb_x;
info->hsize = ((XfwfSlider2Widget)self)->xfwfSlider2.thumb_wd;
}
/*ARGSUSED*/void XfwfMoveThumb(self,x,y)Widget self;double x;double y;
{
XfwfScrollInfo info;
if (! XtIsSubclass(self, xfwfSlider2WidgetClass))
XtError("XfwfMoveThumb called with incorrect widget type");
if (x < 0.0 || x > 1.0 || y < 0.0 || y > 1.0)
XtError("XfwfMoveThumb called with incorrect arguments");
info.flags = XFWF_VPOS | XFWF_HPOS;
info.reason = XfwfSNotify;
info.vpos = y;
info.hpos = x;
((XfwfSlider2WidgetClass)self->core.widget_class)->xfwfSlider2_class.scroll_response(NULL, self, &info);
}
/*ARGSUSED*/void XfwfResizeThumb(self,wd,ht)Widget self;double wd;double ht;
{
XfwfScrollInfo info;
if (! XtIsSubclass(self, xfwfSlider2WidgetClass))
XtError("XfwfResizeThumb called with incorrect widget type");
if (wd < 0.0 || wd > 1.0 || ht < 0.0 || ht > 1.0)
XtError("XfwfResizeThumb called with incorrect arguments");
info.reason = XfwfSNotify;
info.flags = XFWF_VSIZE | XFWF_HSIZE;
info.vsize = ht;
info.hsize = wd;
((XfwfSlider2WidgetClass)self->core.widget_class)->xfwfSlider2_class.scroll_response(NULL, self, &info);
}
|