-
Notifications
You must be signed in to change notification settings - Fork 0
/
xvbutt.c
1241 lines (954 loc) · 33.2 KB
/
xvbutt.c
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
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* xvbutt.c - regular, 'radio', 'checkbox', and 'menu' pushbuttons
*
* callable functions:
*
* BTCreate() - create a button
* BTSetActive() - change 'active' status of button
* BTRedraw() - redraw button
* BTTrack() - clicked in button. track until mouse up
*
* RBCreate() - create an RBUTT and append to supplied list
* RBRedraw() - redraw one or all RBUTTs in a list
* RBSelect() - change selected item in list of RBUTTs
* RBWhich() - returns index of selected RBUTT in list
* RBCount() - returns # of RBUTTs in list
* RBSetActive() - sets active status of an RBUTT
* RBClick() - finds clicked-on rb in a list
* RBTrack() - tracks rb after click, until release
*
* CBCreate() - create a CBUTT (checkbox button)
* CBRedraw() - redraw a CBUTT
* CBSetActive() - change active status of a CBUTT
* CBClick() - returns true if given CB was clicked on
* CBTrack() - tracks CBUTT after click, until release
*
* MBCreate() - create a MBUTT (menu button)
* MBRedraw() - redraw a MBUTT
* MBSetActive() - change active status of a MBUTT
* MBWhich() - returns # of first checked selection
* MBSelect() - similar to RBSelect() ...
* MBClick() - returns true if given MB was clicked on
* MBTrack() - tracks MBUTT after click, until release
*/
#include "copyright.h"
#include "xv.h"
#include "bits/cboard50"
#include "bits/rb_frame"
#include "bits/rb_frame1"
#include "bits/rb_top"
#include "bits/rb_bot"
#include "bits/rb_dtop"
#include "bits/rb_dbot"
#include "bits/rb_body"
#include "bits/rb_dot"
#include "bits/cb_check"
#include "bits/mb_chk"
static Pixmap cboard50 = (Pixmap) NULL; /* 50% gray checkerboard */
static int rbpixmade = 0;
static Pixmap rb_on, rb_on1, rb_off, rb_off1;
static int cbpixmade = 0;
static Pixmap cbcheck;
static int mbpixmade = 0;
static Pixmap mbchk;
static void drawRB PARM((RBUTT *, int));
static void drawCB PARM((CBUTT *, int));
/******************* BUTT ROUTINES ************************/
/**********************************************/
void BTCreate(bp,win,x,y,w,h,str,fg,bg,hi,lo)
BUTT *bp;
Window win;
int x,y;
unsigned int w,h;
char *str;
unsigned long fg,bg,hi,lo;
{
bp->win = win;
bp->x = x; bp->y = y; bp->w = w; bp->h = h;
bp->str = str;
bp->fg = fg; bp->bg = bg; bp->hi = hi; bp->lo = lo;
bp->lit = 0;
bp->active = 1;
bp->toggle = 0;
bp->pix = None;
bp->colorpix = 0;
bp->style = 0;
bp->fwidth = 3;
if (!cboard50) {
cboard50 = MakePix1(rootW, cboard50_bits, cboard50_width, cboard50_height);
if (!cboard50) FatalError("Unable to create cboard50 bitmap\n");
}
}
/**********************************************/
void BTSetActive(bp,act)
BUTT *bp;
int act;
{
if (bp->active != act) {
bp->active = act;
BTRedraw(bp);
}
}
/**********************************************/
void BTRedraw(bp)
BUTT *bp;
{
int x,y,r,x1,y1;
unsigned int w,h;
XPoint tpts[10], bpts[10], ipts[5];
x = bp->x; y=bp->y; w=bp->w; h=bp->h; r=bp->fwidth;
if (!bp->active) bp->lit = 0;
if (bp->lit) {
r -= 1;
if (r<0) r = 0;
}
if (!ctrlColor) {
/* set up 'ipts' */
ipts[0].x = x+r; ipts[0].y = y+r; /* topleft */
ipts[1].x = x+r; ipts[1].y = y+h-r; /* botleft */
ipts[2].x = x+w-r; ipts[2].y = y+h-r; /* botright */
ipts[3].x = x+w-r; ipts[3].y = y+r; /* topright */
ipts[4].x = ipts[0].x; ipts[4].y = ipts[0].y; /* close path */
/* top left polygon */
tpts[0].x = x; tpts[0].y = y;
tpts[1].x = x; tpts[1].y = y+h;
tpts[2].x = ipts[1].x; tpts[2].y = ipts[1].y;
tpts[3].x = ipts[0].x; tpts[3].y = ipts[0].y;
tpts[4].x = ipts[3].x; tpts[4].y = ipts[3].y;
tpts[5].x = x+w; tpts[5].y = y;
tpts[6].x = x; tpts[6].y = y;
/* bot left polygon */
bpts[0].x = x; bpts[0].y = y+h;
bpts[1].x = ipts[1].x; bpts[1].y = ipts[1].y;
bpts[2].x = ipts[2].x; bpts[2].y = ipts[2].y;
bpts[3].x = ipts[3].x; bpts[3].y = ipts[3].y;
bpts[4].x = x+w; bpts[4].y = y;
bpts[5].x = x+w; bpts[5].y = y+h;
bpts[6].x = x; bpts[6].y = y+h;
/* clear button and draw frame */
XSetForeground(theDisp, theGC, bp->bg);
XFillRectangle(theDisp, bp->win, theGC, x, y, w, h);
XSetForeground(theDisp, theGC, bp->fg);
XDrawRectangle(theDisp, bp->win, theGC, x, y, w, h);
XSetForeground(theDisp, theGC, bp->fg);
XSetFillStyle(theDisp, theGC, FillStippled);
XSetStipple(theDisp, theGC, cboard50);
XFillPolygon(theDisp, bp->win, theGC, bpts, 7, Nonconvex, CoordModeOrigin);
XSetFillStyle(theDisp,theGC,FillSolid);
XSetForeground(theDisp, theGC, bp->fg);
XDrawLines(theDisp, bp->win, theGC, ipts, 5, CoordModeOrigin); /* inset */
XDrawLine(theDisp, bp->win, theGC, x+1, y + 1,
ipts[0].x, ipts[0].y);
XDrawLine(theDisp, bp->win, theGC, x+1, y + (int) h - 1,
ipts[1].x, ipts[1].y);
XDrawLine(theDisp, bp->win, theGC, x + (int) w - 1, y + (int) h - 1,
ipts[2].x, ipts[2].y);
XDrawLine(theDisp, bp->win, theGC, x + (int) w - 1, y+1,
ipts[3].x, ipts[3].y);
if (bp->lit) {
XDrawRectangle(theDisp, bp->win, theGC, x+2, y+2, w-4, h-4);
XDrawRectangle(theDisp, bp->win, theGC, x+1, y+1, w-2, h-2);
}
}
else { /* ctrlColor */
XSetForeground(theDisp, theGC, bp->bg);
XFillRectangle(theDisp, bp->win, theGC, x+1, y+1, w-1, h-1);
Draw3dRect(bp->win, x+1, y+1, w-2, h-2, R3D_OUT, bp->fwidth,
bp->hi, bp->lo, bp->bg);
XSetForeground(theDisp, theGC, bp->fg);
XDrawRectangle(theDisp, bp->win, theGC, x, y, w, h);
if (bp->lit)
XDrawRectangle(theDisp, bp->win, theGC, x+1, y+1, w-2, h-2);
}
XSetForeground(theDisp, theGC, bp->fg);
if (bp->pix != None) { /* draw pixmap centered in butt */
x1 = x+(1+w-bp->pw)/2;
y1 = y+(1+h-bp->ph)/2;
XSetBackground(theDisp, theGC, bp->bg);
if (bp->colorpix)
XCopyArea (theDisp,bp->pix, bp->win, theGC, 0,0,bp->pw,bp->ph, x1,y1);
else
XCopyPlane(theDisp,bp->pix, bp->win, theGC, 0,0,bp->pw,bp->ph, x1,y1,1L);
if (!bp->active) DimRect(bp->win, x1,y1, bp->pw, bp->ph, bp->bg);
}
else { /* draw string centered in butt */
x1 = CENTERX(mfinfo, x + w/2, bp->str);
y1 = CENTERY(mfinfo, y + h/2);
if (bp->active) {
DrawString(bp->win, x1,y1, bp->str);
}
else { /* stipple if not active */
XSetFillStyle(theDisp, theGC, FillStippled);
XSetStipple(theDisp, theGC, dimStip);
DrawString(bp->win, x1,y1, bp->str);
XSetFillStyle(theDisp,theGC,FillSolid);
}
}
}
/**********************************************/
int BTTrack(bp)
BUTT *bp;
{
/* called when we've gotten a click inside 'bp'. returns 1 if button
was still selected lit when mouse was released. */
Window rW, cW;
int x, y, rx, ry, rval, inval;
unsigned int mask;
if (!bp->active) return 0; /* inactive button */
inval = bp->lit;
bp->lit = !bp->lit;
BTRedraw(bp); XFlush(theDisp);
Timer(120); /* long enough for turn on to be visible */
while (XQueryPointer(theDisp,bp->win,&rW,&cW,&rx,&ry,&x,&y,&mask)) {
if (!(mask & Button1Mask)) break; /* button released */
if (bp->lit==inval && PTINRECT(x, y, bp->x, bp->y, bp->w, bp->h)) {
bp->lit = !inval; BTRedraw(bp); XFlush(theDisp);
}
if (bp->lit!=inval && !PTINRECT(x, y, bp->x, bp->y, bp->w, bp->h)) {
bp->lit = inval; BTRedraw(bp); XFlush(theDisp);
}
}
rval = (bp->lit != inval);
if (bp->lit && !bp->toggle)
{ bp->lit = 0; BTRedraw(bp); XFlush(theDisp); }
return(rval);
}
/******************* RBUTT ROUTINES ************************/
#define RBSIZE rb_frame_width
/***********************************************/
RBUTT *RBCreate(rblist, win, x,y,str, fg, bg, hi, lo)
RBUTT *rblist;
Window win;
int x,y;
char *str;
unsigned long fg,bg,hi,lo;
{
/* mallocs an RBUTT, fills in the fields, and appends it to rblist
if rblist is NULL, this is the first rb in the list. It will
be made the 'selected' one
Note: no need to check return status. It'll fatal error if it
can't malloc */
RBUTT *rb, *rbptr;
Pixmap rb_frame, rb_frame1, rb_top, rb_bot, rb_dtop, rb_dbot, rb_body,
rb_dot;
rb = (RBUTT *) malloc(sizeof(RBUTT));
if (!rb) FatalError("couldn't malloc RBUTT");
/* fill in the fields of the structure */
rb->win = win;
rb->x = x;
rb->y = y;
rb->str = str;
rb->selected = 0;
rb->active = 1;
rb->next = (struct rbutt *) NULL;
rb->fg = fg;
rb->bg = bg;
rb->hi = hi;
rb->lo = lo;
if (rblist) { /* append to end of list */
rbptr = rblist;
while (rbptr->next) rbptr = (RBUTT *) rbptr->next;
rbptr->next = (struct rbutt *) rb;
}
else { /* this is the first one in the list. select it */
rb->selected = 1;
}
/* and, on an unrelated note, if the RB pixmaps haven't been created yet,
do so. We'll be needing them, y'see... */
if (!rbpixmade) {
rb_frame = MakePix1(rootW, rb_frame_bits, RBSIZE, RBSIZE);
rb_frame1 = MakePix1(rootW, rb_frame1_bits, RBSIZE, RBSIZE);
rb_top = MakePix1(rootW, rb_top_bits, RBSIZE, RBSIZE);
rb_bot = MakePix1(rootW, rb_bot_bits, RBSIZE, RBSIZE);
rb_dtop = MakePix1(rootW, rb_dtop_bits, RBSIZE, RBSIZE);
rb_dbot = MakePix1(rootW, rb_dbot_bits, RBSIZE, RBSIZE);
rb_body = MakePix1(rootW, rb_body_bits, RBSIZE, RBSIZE);
rb_dot = MakePix1(rootW, rb_dot_bits, RBSIZE, RBSIZE);
rb_on = XCreatePixmap(theDisp, rootW, RBSIZE, RBSIZE, dispDEEP);
rb_on1 = XCreatePixmap(theDisp, rootW, RBSIZE, RBSIZE, dispDEEP);
rb_off = XCreatePixmap(theDisp, rootW, RBSIZE, RBSIZE, dispDEEP);
rb_off1 = XCreatePixmap(theDisp, rootW, RBSIZE, RBSIZE, dispDEEP);
if (!rb_frame || !rb_frame1 || !rb_top || !rb_bot || !rb_dtop ||
!rb_dbot || !rb_body || !rb_dot || !rb_on || !rb_on1 ||
!rb_off || !rb_off1)
FatalError("unable to create radio-button pixmaps");
/* generate rb_on,on1,off,off1 pixmaps from mask pixmaps */
XSetForeground(theDisp, theGC, bg);
XFillRectangle(theDisp, rb_on, theGC, 0,0,RBSIZE,RBSIZE);
XFillRectangle(theDisp, rb_on1, theGC, 0,0,RBSIZE,RBSIZE);
XFillRectangle(theDisp, rb_off, theGC, 0,0,RBSIZE,RBSIZE);
XFillRectangle(theDisp, rb_off1, theGC, 0,0,RBSIZE,RBSIZE);
XSetFillStyle(theDisp, theGC, FillStippled);
if (ctrlColor) {
XSetStipple(theDisp, theGC, rb_top);
XSetForeground(theDisp, theGC, fg);
XFillRectangle(theDisp, rb_on, theGC, 0,0,RBSIZE,RBSIZE);
XFillRectangle(theDisp, rb_on1, theGC, 0,0,RBSIZE,RBSIZE);
XSetForeground(theDisp, theGC, hi);
XFillRectangle(theDisp, rb_off, theGC, 0,0,RBSIZE,RBSIZE);
XFillRectangle(theDisp, rb_off1, theGC, 0,0,RBSIZE,RBSIZE);
XSetStipple(theDisp, theGC, rb_body);
XSetForeground(theDisp, theGC, lo);
XFillRectangle(theDisp, rb_on, theGC, 0,0,RBSIZE,RBSIZE);
XFillRectangle(theDisp, rb_on1, theGC, 0,0,RBSIZE,RBSIZE);
XSetForeground(theDisp, theGC, bg);
XFillRectangle(theDisp, rb_off, theGC, 0,0,RBSIZE,RBSIZE);
XFillRectangle(theDisp, rb_off1, theGC, 0,0,RBSIZE,RBSIZE);
XSetStipple(theDisp, theGC, rb_bot);
XSetForeground(theDisp, theGC, bg);
XFillRectangle(theDisp, rb_on, theGC, 0,0,RBSIZE,RBSIZE);
XFillRectangle(theDisp, rb_on1, theGC, 0,0,RBSIZE,RBSIZE);
XSetForeground(theDisp, theGC, lo);
XFillRectangle(theDisp, rb_off, theGC, 0,0,RBSIZE,RBSIZE);
XFillRectangle(theDisp, rb_off1, theGC, 0,0,RBSIZE,RBSIZE);
XSetStipple(theDisp, theGC, rb_dtop);
XSetForeground(theDisp, theGC, bg);
XFillRectangle(theDisp, rb_on, theGC, 0,0,RBSIZE,RBSIZE);
XFillRectangle(theDisp, rb_on1, theGC, 0,0,RBSIZE,RBSIZE);
XSetForeground(theDisp, theGC, hi);
XFillRectangle(theDisp, rb_off, theGC, 0,0,RBSIZE,RBSIZE);
XFillRectangle(theDisp, rb_off1, theGC, 0,0,RBSIZE,RBSIZE);
XSetStipple(theDisp, theGC, rb_dbot);
XSetForeground(theDisp, theGC, fg);
XFillRectangle(theDisp, rb_on, theGC, 0,0,RBSIZE,RBSIZE);
XFillRectangle(theDisp, rb_on1, theGC, 0,0,RBSIZE,RBSIZE);
XSetForeground(theDisp, theGC, lo);
XFillRectangle(theDisp, rb_off, theGC, 0,0,RBSIZE,RBSIZE);
XFillRectangle(theDisp, rb_off1, theGC, 0,0,RBSIZE,RBSIZE);
}
else {
XSetStipple(theDisp, theGC, rb_dot);
XSetForeground(theDisp, theGC, fg);
XFillRectangle(theDisp, rb_on, theGC, 0,0,RBSIZE,RBSIZE);
XFillRectangle(theDisp, rb_on1, theGC, 0,0,RBSIZE,RBSIZE);
}
XSetStipple(theDisp, theGC, rb_frame);
XSetForeground(theDisp, theGC, fg);
XFillRectangle(theDisp, rb_on, theGC, 0,0,RBSIZE,RBSIZE);
XFillRectangle(theDisp, rb_off, theGC, 0,0,RBSIZE,RBSIZE);
XSetStipple(theDisp, theGC, rb_frame1);
XSetForeground(theDisp, theGC, fg);
XFillRectangle(theDisp, rb_on1, theGC, 0,0,RBSIZE,RBSIZE);
XFillRectangle(theDisp, rb_off1, theGC, 0,0,RBSIZE,RBSIZE);
XSetFillStyle(theDisp, theGC, FillSolid);
/* destroy mask pixmaps */
XFreePixmap(theDisp, rb_frame);
XFreePixmap(theDisp, rb_frame1);
XFreePixmap(theDisp, rb_top);
XFreePixmap(theDisp, rb_bot);
XFreePixmap(theDisp, rb_dtop);
XFreePixmap(theDisp, rb_dbot);
XFreePixmap(theDisp, rb_body);
rbpixmade = 1;
}
return(rb);
}
/***********************************************/
void RBRedraw(rblist, num)
RBUTT *rblist;
int num;
{
/* redraws the 'num-th' RB in the list. if num < 0, redraws entire list */
RBUTT *rb;
int i;
/* point 'rb' at the appropriate RBUTT, *if* we're not drawing entire list */
if (num>=0) {
i=0; rb=rblist;
while (i!=num && rb) { rb = (RBUTT *) rb->next; i++; }
if (!rb) return; /* num is out of range. do nothing */
drawRB(rb,0);
}
else { /* draw entire list */
rb = rblist;
while (rb) {
drawRB(rb,0);
rb = (RBUTT *) rb->next;
}
}
}
/***********************************************/
static void drawRB(rb, lit)
RBUTT *rb;
int lit;
{
/* draws the rb being pointed at */
Pixmap pix;
if (!rb) return; /* rb = NULL */
XSetForeground(theDisp, theGC, rb->fg);
if (rb->selected) { pix = (lit) ? rb_on1 : rb_on; }
else { pix = (lit) ? rb_off1 : rb_off; }
XCopyArea(theDisp, pix, rb->win, theGC, 0,0,RBSIZE,RBSIZE, rb->x, rb->y);
DrawString(rb->win, rb->x + RBSIZE + 4,
rb->y + RBSIZE/2 - CHIGH/2 + ASCENT, rb->str);
if (!rb->active) { /* if non-active, dim button and string */
DimRect(rb->win, rb->x, rb->y, RBSIZE, RBSIZE, rb->bg);
DimRect(rb->win, rb->x + RBSIZE + 4, rb->y + RBSIZE/2 - CHIGH/2,
(u_int) StringWidth(rb->str), (u_int) CHIGH, rb->bg);
}
}
/***********************************************/
void RBSelect(rblist, n)
RBUTT *rblist;
int n;
{
RBUTT *rbold, *rb;
int i;
/* makes rb #n the selected rb in the list. Does all redrawing. Does
nothing if rb already selected */
/* get pointers to the currently selected rb and the desired rb */
rbold = rblist;
while (rbold && !rbold->selected) rbold = (RBUTT *) rbold->next;
if (!rbold) return; /* no currently selected item. shouldn't happen */
rb = rblist; i=0;
while (rb && i!=n) {rb = (RBUTT *) rb->next; i++; }
if (!rb) return; /* 'n' is out of range */
if (rb == rbold) return; /* 'n' is already selected. do nothing */
rbold->selected = 0;
rb->selected = 1;
drawRB(rbold, 0);
drawRB(rb, 0);
}
/***********************************************/
int RBWhich(rblist)
RBUTT *rblist;
{
int i;
/* returns index of currently selected rb. if none, returns -1 */
i = 0;
while (rblist && !rblist->selected)
{ rblist = (RBUTT *) rblist->next; i++; }
if (!rblist) return -1; /* didn't find one */
return i;
}
/***********************************************/
int RBCount(rblist)
RBUTT *rblist;
{
int i;
/* returns # of rb's in the list */
i = 0;
while (rblist) { rblist = (RBUTT *) rblist->next; i++; }
return i;
}
/***********************************************/
void RBSetActive(rblist, n, act)
RBUTT *rblist;
int n,act;
{
RBUTT *rb;
int i;
/* sets 'active' status of rb #n. does redrawing */
rb=rblist; i=0;
while (rb && i!=n) { rb = (RBUTT *) rb->next; i++; }
if (!rb) return; /* n out of range. do nothing */
if (rb->active != act) {
rb->active = act;
drawRB(rb, 0);
}
}
/***********************************************/
int RBClick(rblist, mx, my)
RBUTT *rblist;
int mx,my;
{
int i;
/* searches through rblist to see if mouse click at mx,my is in the
clickable region of any of the rb's. If it finds one, it returns
it's index in the list. If not, returns -1 */
i = 0;
while (rblist) {
if (PTINRECT(mx, my, rblist->x, rblist->y, RBSIZE, RBSIZE)) break;
rblist = (RBUTT *) rblist->next;
i++;
}
if (!rblist) return -1;
return(i);
}
/***********************************************/
int RBTrack(rblist, n)
RBUTT *rblist;
int n;
{
RBUTT *rb;
Window rW, cW;
int i, x, y, rx, ry, lit, rv;
unsigned int mask;
/* returns '1' if selection changed */
rb=rblist; i=0;
while (rb && i!=n) { rb = (RBUTT *) rb->next; i++; }
if (!rb) return 0; /* n out of range */
/* called once we've figured out that the mouse clicked in 'rb' */
if (!rb->active) return 0;
lit = 1;
drawRB(rb, lit);
XFlush(theDisp);
Timer(75); /* give chance for 'turn on' to become visible */
while (XQueryPointer(theDisp,rb->win,&rW,&cW,&rx,&ry,&x,&y,&mask)) {
if (!(mask & Button1Mask)) break; /* button released */
if (!lit && PTINRECT(x, y, rb->x, rb->y, RBSIZE, RBSIZE)) {
lit=1;
drawRB(rb, lit);
XFlush(theDisp);
}
if (lit && !PTINRECT(x, y, rb->x, rb->y, RBSIZE, RBSIZE)) {
lit=0;
drawRB(rb, lit);
XFlush(theDisp);
}
}
rv = 0;
if (lit) {
drawRB(rb, 0);
if (RBWhich(rblist) != n) rv = 1;
RBSelect(rblist, n);
}
XFlush(theDisp);
return rv;
}
/******************* CBUTT ROUTINES ************************/
#define XVCBSIZE 16
/***********************************************/
void CBCreate(cb, win, x,y, str, fg, bg, hi, lo)
CBUTT *cb;
Window win;
int x,y;
char *str;
unsigned long fg,bg,hi,lo;
{
/* fill in the fields of the structure */
cb->win = win;
cb->x = x;
cb->y = y;
cb->str = str;
cb->val = 0;
cb->active = 1;
cb->fg = fg;
cb->bg = bg;
cb->hi = hi;
cb->lo = lo;
/* and, on an unrelated note, if the CB pixmaps haven't been created yet,
do so. We'll be needing them, y'see... */
if (!cbpixmade) {
cbcheck = XCreatePixmapFromBitmapData(theDisp, rootW,
(char *) cb_check_bits,
cb_check_width, cb_check_height, fg, bg, dispDEEP);
cbpixmade = 1;
}
}
/***********************************************/
void CBRedraw(cb)
CBUTT *cb;
{
/* draws the cb being pointed at */
XSetForeground(theDisp, theGC, cb->bg);
XFillRectangle(theDisp, cb->win, theGC, cb->x+2, cb->y+2,
XVCBSIZE-3,XVCBSIZE-3);
XSetForeground(theDisp, theGC, cb->fg);
XDrawRectangle(theDisp, cb->win, theGC, cb->x, cb->y, XVCBSIZE, XVCBSIZE);
Draw3dRect(cb->win, cb->x+1, cb->y+1, XVCBSIZE-2, XVCBSIZE-2, R3D_OUT, 2,
cb->hi, cb->lo, cb->bg);
if (cb->val) XCopyArea(theDisp, cbcheck, cb->win, theGC,
0, 0, cb_check_width, cb_check_height,
cb->x+3, cb->y+3);
XSetForeground(theDisp, theGC, cb->fg);
DrawString(cb->win, cb->x + XVCBSIZE+4,
cb->y+XVCBSIZE/2 - CHIGH/2 + ASCENT, cb->str);
if (!cb->active) { /* if non-active, dim button and string */
DimRect(cb->win, cb->x, cb->y, XVCBSIZE, XVCBSIZE, cb->bg);
DimRect(cb->win, cb->x + XVCBSIZE+4, cb->y+XVCBSIZE/2 - CHIGH/2,
(u_int) StringWidth(cb->str), (u_int) CHIGH, cb->bg);
}
}
/**********************************************/
void CBSetActive(cb,act)
CBUTT *cb;
int act;
{
if (cb->active != act) {
cb->active = act;
CBRedraw(cb);
}
}
/***********************************************/
int CBClick(cb, mx, my)
CBUTT *cb;
int mx,my;
{
if (PTINRECT(mx, my, cb->x, cb->y, XVCBSIZE,XVCBSIZE)) return 1;
return 0;
}
/***********************************************/
int CBTrack(cb)
CBUTT *cb;
{
Window rW, cW;
int x, y, rx, ry, lit;
unsigned int mask;
/* called once we've figured out that the mouse clicked in 'cb' */
if (!cb->active) return 0;
XSetForeground(theDisp, theGC, cb->fg);
lit = 1;
drawCB(cb, lit);
XFlush(theDisp);
Timer(75); /* give chance for 'turn on' to become visible */
while (XQueryPointer(theDisp,cb->win,&rW,&cW,&rx,&ry,&x,&y,&mask)) {
if (!(mask & Button1Mask)) break; /* button released */
if (!lit && PTINRECT(x, y, cb->x, cb->y, XVCBSIZE, XVCBSIZE)) {
lit=1;
drawCB(cb,lit);
XFlush(theDisp);
}
if (lit && !PTINRECT(x, y, cb->x, cb->y, XVCBSIZE, XVCBSIZE)) {
lit=0;
drawCB(cb,lit);
XFlush(theDisp);
}
}
if (lit) {
cb->val = !cb->val;
drawCB(cb,0);
CBRedraw(cb);
}
XFlush(theDisp);
return(lit);
}
/***********************************************/
static void drawCB(cb, lit)
CBUTT *cb;
int lit;
{
/* draws highlighting */
if (lit) {
if (ctrlColor)
Draw3dRect(cb->win, cb->x+1, cb->y+1, XVCBSIZE-2, XVCBSIZE-2, R3D_IN, 2,
cb->hi, cb->lo, cb->bg);
else {
XSetForeground(theDisp, theGC, cb->fg);
XDrawRectangle(theDisp, cb->win, theGC, cb->x+1, cb->y+1,
XVCBSIZE-2, XVCBSIZE-2);
}
}
else {
if (ctrlColor)
Draw3dRect(cb->win, cb->x+1, cb->y+1, XVCBSIZE-2, XVCBSIZE-2, R3D_OUT, 2,
cb->hi, cb->lo, cb->bg);
else {
XSetForeground(theDisp, theGC, cb->bg);
XDrawRectangle(theDisp, cb->win, theGC, cb->x+1, cb->y+1,
XVCBSIZE-2, XVCBSIZE-2);
}
}
}
/******************* MBUTT ROUTINES ************************/
/***********************************************/
void MBCreate(mb, win, x,y,w,h, str, list, nlist, fg, bg, hi, lo)
MBUTT *mb;
Window win;
int x,y;
unsigned int w,h;
char *str;
char **list;
int nlist;
unsigned long fg,bg,hi,lo;
{
XSetWindowAttributes xswa;
unsigned long xswamask;
int i;
if (!mbpixmade) {
mbchk = XCreatePixmapFromBitmapData(theDisp, rootW, (char *) mb_chk_bits,
mb_chk_width, mb_chk_height, fg, bg, dispDEEP);
mbpixmade = 1;
}
/* fill in the fields of the structure */
mb->win = win;
mb->x = x;
mb->y = y;
mb->w = w;
mb->h = h;
mb->title = str;
mb->active = 1;
mb->list = list;
mb->nlist = nlist;
mb->hascheck = 0;
mb->fg = fg;
mb->bg = bg;
mb->hi = hi;
mb->lo = lo;
mb->pix = (Pixmap) NULL;
mb->pw = mb->ph = 0;
for (i=0; i<MAXMBLEN; i++) {
mb->flags[i] = 0;
mb->dim[i] = 0;
}
/* create popup window (it gets mapped, pos'd and sized later) */
xswa.background_pixel = bg;
xswa.border_pixel = fg;
xswa.save_under = True;
xswamask = CWBackPixel | CWBorderPixel | CWSaveUnder;
mb->mwin = XCreateWindow(theDisp, mb->win, x, y, w, h,
(u_int) 2, (int) dispDEEP, InputOutput,
theVisual, xswamask, &xswa);
if (!mb->mwin) FatalError("can't create popup menu window!");
XSelectInput(theDisp, mb->mwin, ExposureMask | VisibilityChangeMask);
XSetTransientForHint(theDisp, mb->mwin, mb->win);
}
/***********************************************/
void MBRedraw(mb)
MBUTT *mb;
{
/* draws a menu button in it's normal state. (When it's actively being
used (to select an item), all drawing is handled in MBTrack) */
int x,y,i,r,x1,y1;
unsigned int w,h;
r = 2; /* amt of shadow */
x = mb->x; y = mb->y; w = mb->w; h = mb->h;
x1 = x + (int) w;
y1 = y + (int) h;
XSetForeground(theDisp, theGC, mb->bg);
XFillRectangle(theDisp, mb->win, theGC, x+1, y+1, w-1, h-1);
XSetForeground(theDisp, theGC, mb->fg);
XDrawRectangle(theDisp, mb->win, theGC, x, y, w, h);
Draw3dRect(mb->win, x+1, y+1, w-2, h-2, R3D_OUT, 2, mb->hi, mb->lo, mb->bg);
XSetForeground(theDisp, theGC, mb->fg);
/* draw shadow */
for (i=1; i<=r; i++) {
XDrawLine(theDisp, mb->win, theGC, x+r, y1+i, x1+i, y1+i);
XDrawLine(theDisp, mb->win, theGC, x1+i, y1+i, x1+i, y+r);
}
if (mb->pix != None) { /* draw pixmap centered in butt */
x1 = x + (1+w - mb->pw)/2;
y1 = y + (1+h - mb->ph)/2;
XSetForeground(theDisp, theGC, mb->fg);
XSetBackground(theDisp, theGC, mb->bg);
XCopyPlane(theDisp, mb->pix, mb->win, theGC, 0,0,
(u_int) mb->pw, (u_int) mb->ph, x1,y1, 1L);
if (!mb->active)
DimRect(mb->win, x1,y1, (u_int) mb->pw, (u_int) mb->ph, mb->bg);
}
else { /* draw string centered in butt */
char *str, stbuf[256];
if (mb->title) str = mb->title;
else { /* find first checked item, and show that as the title */
int i;
if (mb->list) {
for (i=0; i<mb->nlist && !mb->flags[i]; i++);
if (i==mb->nlist) i = 0; /* shouldn't happen */
str = mb->list[i];
}
else str = "";
}
/* truncate at TAB, if any */
strcpy(stbuf, str);
if ((str = (char *) index(stbuf, '\t')) != NULL) *str = '\0';
str = stbuf;
x1 = CENTERX(mfinfo, x + w/2, str);
y1 = CENTERY(mfinfo, y + h/2);
if (mb->active) {
DrawString(mb->win, x1,y1, str);
}
else { /* stipple if not active */
XSetFillStyle(theDisp, theGC, FillStippled);
XSetStipple(theDisp, theGC, dimStip);
DrawString(mb->win, x1,y1, str);
XSetFillStyle(theDisp,theGC,FillSolid);
}
}
}
/**********************************************/
void MBSetActive(mb,act)
MBUTT *mb;
int act;
{
if (mb->active != act) {
mb->active = act;
MBRedraw(mb);
}
}
/**********************************************/
int MBWhich(mb)
MBUTT *mb;
{
/* returns index of first checked selection, or '-1' if nothing selected */
int i;