This repository has been archived by the owner on Jun 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
xvpopup.c
1340 lines (1044 loc) · 37.1 KB
/
xvpopup.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
/*
* xvpopup.c - pop up "Are you sure? Yes/No/Maybe" sort of dialog box
*
* callable functions:
*
* SetMinSizeWindow(win,w,h) - set minimum allowed size
* SetMaxSizeWindow(win,w,h) - set maximum allowed size
* SetSizeIncWindow(win,dx,dy) - set resize increment stepping
* CenterMapFlexWindow(win,x,y,keep) - maps and centers a window around the mouse
* CenterMapWindow(win,x,y) - maps and centers a window around the mouse
* PopUp(str,...) - maps, sets up popW
* ErrPopUp(str,str) - maps, sets up popW
* GetStrPopUp(...) - opens a 1-line, editable text popup window
* GrabPopUp(*hide,*del) - opens 'grab' popup dialog
* PadPopUp() - opens 'grab' popup dialog
* ClosePopUp() - closes pop-up or alert window, if open
* OpenAlert(str) - maps a button-less window
* CloseAlert() - closes a button-less window
* PUCheckEvent(event) - called by event handler
*/
#include "copyright.h"
#include "xv.h"
#define OMIT_ICON_BITS
#include "bits/icon" /* icon_bits[] not used, but icon_width/height are */
#define PUWIDE 480
#define PUHIGH 170
#define PAD_PUWIDE 480
#define PAD_PUHIGH 215
#define BUTTH 24
static int doPopUp PARM((const char *, const char **, int, int, const char *));
static void attachPUD PARM((void));
static void TextRect PARM((Window, const char *, int, int, int, int, u_long));
static void createPUD PARM((void));
static void drawPUD PARM((int, int, int, int));
static void drawPadOMStr PARM((void));
static void clickPUD PARM((int, int));
static void doGetStrKey PARM((int));
static int doGSKey PARM((int));
static void changedGSBuf PARM((void));
static void drawGSBuf PARM((void));
static void buildPadLists PARM((void));
static void build1PadList PARM((const char *, const char **, const char **, int *,
const char **, const char **, int));
/* values 'popUp' can take */
#define ISPOPUP 1
#define ISALERT 2
#define ISGETSTR 3
#define ISGRAB 4
#define ISPAD 5
#define DELAYSTR "Delay:"
#define SECSTR "seconds"
#define HIDESTR "Hide XV windows"
/* local variables */
static Window popW;
static int nbts, selected, popUp=0, firsttime=1;
static int puwide = PUWIDE;
static int puhigh = PUHIGH;
static BUTT *bts;
static const char *text;
static char accel[8];
static char *gsBuf; /* stuff needed for GetStrPopUp() handling */
static const char *gsFilter;
static int gsBufLen, gsAllow, gsCurPos, gsStPos, gsEnPos;
static int gsx, gsy, gsw, gsh;
/* stuff for GrabPopUp */
static CBUTT ahideCB;
/*** stuff for PadPopUp ***/
static char padSbuf[256], padBbuf[256], padLbuf[256], padBuf[256];
static char *padInst, padSinst[200], padBinst[200], padLinst[200];
static MBUTT padDfltMB, padMthdMB;
static BUTT padDButt, padOMButt;
static int padHaveDooDads = 0;
static int padMode, padOMode;
static DIAL padWDial, padHDial, padODial;
static int padMthdLen=3;
static const char *padMthdNames[] = { "Solid Fill", "Run 'bggen'", "Load Image" };
static int padColDefLen = 9;
static const char *padColDefNames[] = { "black", "red", "yellow", "green",
"cyan", "blue", "magenta", "white",
"50% gray" };
static const char *padColDefVals[] = { "black", "red", "yellow", "green",
"cyan", "blue", "magenta", "white",
"gray50" };
static int padBgDefLen = 8;
static const char *padBgDefNames[] = { "Black->White",
"Blue Gradient",
"RGB Rainbow",
"Full Rainbow",
"Color Assortment",
"Green Tiles",
"Red Balls",
"Red+Yellow Diamonds" };
static const char *padBgDefVals[] = { "black white",
"100 100 255 50 50 150",
"red green blue",
"black red yellow green blue purple black",
"black white red black yellow white green black cyan white blue black magenta white red yellow green cyan blue magenta red",
"green black -r 30 -G 32x32",
"red black -r 45 -G 32x32",
"red yellow -r 45 -G 32x32" };
/* this should match with PAD_O* defs in xv.h */
static const char *padOMStr[] = { "RGB", "Int.", "Hue", "Sat." };
#define PAD_MAXDEFLEN 10
static int padColLen = 0;
static const char *padColNames [PAD_MAXDEFLEN];
static const char *padColVals [PAD_MAXDEFLEN];
static int padBgLen = 0;
static const char *padBgNames [PAD_MAXDEFLEN];
static const char *padBgVals [PAD_MAXDEFLEN];
static int padLoadLen = 0;
static const char *padLoadNames[PAD_MAXDEFLEN];
static const char *padLoadVals [PAD_MAXDEFLEN];
#ifndef NOSIGNAL
extern XtAppContext context;
#endif
/***************************************************/
void SetMinSizeWindow(win, w, h)
Window win;
int w, h;
{
XSizeHints hints;
if (!XGetNormalHints(theDisp, win, &hints)) hints.flags = 0;
hints.min_width = w;
hints.min_height = h;
hints.flags |= PMinSize;
XSetNormalHints(theDisp, win, &hints);
}
/***************************************************/
void SetMaxSizeWindow(win, w, h)
Window win;
int w, h;
{
XSizeHints hints;
if (!XGetNormalHints(theDisp, win, &hints)) hints.flags = 0;
hints.max_width = w;
hints.max_height = h;
hints.flags |= PMaxSize;
XSetNormalHints(theDisp, win, &hints);
}
/***************************************************/
void SetSizeIncWindow(win, dx, dy)
Window win;
int dx, dy;
{
XSizeHints hints;
if (!XGetNormalHints(theDisp, win, &hints)) hints.flags = 0;
hints.base_width = 0;
hints.base_height = 0;
hints.flags |= PBaseSize;
hints.width_inc = dx;
hints.height_inc = dy;
hints.flags |= PResizeInc;
XSetNormalHints(theDisp, win, &hints);
}
/***************************************************/
void CenterMapFlexWindow(win, dx, dy, w, h, keepsize)
Window win;
int dx, dy, w, h, keepsize;
{
XSizeHints hints;
Window rW,cW;
int rx,ry,x,y,wx,wy;
unsigned int mask;
if (!XQueryPointer(theDisp,rootW,&rW,&cW,&rx,&ry,&x,&y,&mask)) {
/* couldn't query mouse. just center on screen */
wx = (dispWIDE-w)/2; wy = (dispHIGH-h)/2;
}
else {
wx = x - dx;
wy = y - dy;
if (wx<0) wx = 0;
if (wy<0) wy = 0;
if (wx + w > dispWIDE) wx = dispWIDE - w;
if (wy + h > dispHIGH) wy = dispHIGH - h;
}
#if 0
if (winCtrPosKludge) {
wx -= (p_offx + ch_offx);
wy -= (p_offy + ch_offy);
}
else {
wx -= (ch_offx);
wy -= (ch_offy);
}
#endif
/* do this first so the WM can override us */
XMoveWindow(theDisp, win, wx, wy);
if (!XGetNormalHints(theDisp, win, &hints)) hints.flags = 0;
hints.x = wx; hints.y = wy;
hints.width = w;
hints.height = h;
hints.flags |= PPosition | PSize;
if (keepsize) {
hints.min_width = hints.max_width = w;
hints.min_height = hints.max_height = h;
hints.flags |= PMinSize | PMaxSize;
}
XSetNormalHints(theDisp, win, &hints);
XMapRaised(theDisp, win);
}
void CenterMapWindow(win, dx, dy, w, h)
Window win;
int dx, dy, w, h;
{
CenterMapFlexWindow(win, dx, dy, w, h, TRUE);
}
/***************************************************/
int PopUp(txt, labels, n)
const char *txt;
const char *labels[];
int n;
{
return doPopUp(txt, labels, n, ISPOPUP, "xv confirm");
}
/***************************************************/
static int doPopUp(txt, labels, n, poptyp, wname)
const char *txt;
const char *labels[];
int n, poptyp;
const char *wname;
{
int i;
XEvent event;
if (firsttime) createPUD();
if (poptyp != ISPAD) { puwide = PUWIDE; puhigh = PUHIGH; }
else { puwide = PAD_PUWIDE; puhigh = PAD_PUHIGH; }
/* attach controls to popW, now that it exists */
if (poptyp==ISGRAB) ahideCB.win = popW;
else if (poptyp == ISPAD) {
if (!padHaveDooDads) {
DCreate(&padWDial, popW, 16, puhigh-16-100-1,75,100,
1.0, 2048.0, (double)pWIDE, 1.0, 10.0,
infofg, infobg, hicol, locol, "Width", NULL);
DCreate(&padHDial, popW, 16+1+75, puhigh-16-100-1,75,100,
1.0, 2048.0, (double)pHIGH, 1.0, 10.0,
infofg, infobg, hicol, locol, "Height", NULL);
DCreate(&padODial, popW, 16+1+75+75+9, puhigh-16-100-1,75,100,
0.0, 100.0, 100.0, 1.0, 10.0,
infofg, infobg, hicol, locol, "Opaque", NULL);
MBCreate(&padMthdMB, popW, 100-2+44, 10, 140, 19, NULL,
padMthdNames, padMthdLen, infofg, infobg, hicol, locol);
padMthdMB.hascheck = 1;
padMthdMB.flags[0] = 1;
MBCreate(&padDfltMB, popW, 250-2+44, 10, 140, 19, "Defaults",
padColNames, padColLen, infofg, infobg, hicol, locol);
BTCreate(&padDButt, popW, padHDial.x+padHDial.w-12, puhigh-140+6,
13,13, "", infofg, infobg, hicol, locol);
BTCreate(&padOMButt, popW, padODial.x+padODial.w-12, puhigh-140+6,
13,13, "", infofg, infobg, hicol, locol);
padHaveDooDads = 1;
}
XMapWindow(theDisp, padWDial.win);
XMapWindow(theDisp, padHDial.win);
XMapWindow(theDisp, padODial.win);
}
XResizeWindow(theDisp, popW, (u_int) puwide, (u_int) puhigh);
XStoreName (theDisp, popW, wname);
XSetIconName (theDisp, popW, wname);
attachPUD();
bts = (BUTT *) malloc(n * sizeof(BUTT));
if (!bts) FatalError("unable to malloc buttons in popup\n");
nbts = n;
selected = 0;
text = txt;
for (i=0; i<n; i++) {
BTCreate(&bts[i], popW, puwide - (n-i) * (80 + 10), puhigh - 10 - BUTTH,
80, BUTTH, labels[i]+1, infofg, infobg, hicol, locol);
accel[i] = labels[i][0];
}
if (poptyp == ISGRAB) {
BTSetActive(&bts[0], (int) strlen(gsBuf));
BTSetActive(&bts[1], (strlen(gsBuf)>(size_t)0 && atoi(gsBuf)>(size_t)0));
}
else if (poptyp == ISPAD) {
BTSetActive(&bts[0], (int) strlen(gsBuf));
i = pWIDE * 3; RANGE(i,2048,9999);
DSetRange(&padWDial, 1.0, (double)i, padWDial.val, 1.0, 10.0);
i = pHIGH * 3; RANGE(i,2048,9999);
DSetRange(&padHDial, 1.0, (double)i, padHDial.val, 1.0, 10.0);
DSetActive(&padWDial, (padMode!=PAD_LOAD)); /* DSetRange activates dial */
DSetActive(&padHDial, (padMode!=PAD_LOAD));
DSetActive(&padODial, 1);
switch (padMode) {
case PAD_SOLID:
padDfltMB.list = padColNames;
padDfltMB.nlist = padColLen;
break;
case PAD_BGGEN:
padDfltMB.list = padBgNames;
padDfltMB.nlist = padBgLen;
break;
case PAD_LOAD:
padDfltMB.list = padLoadNames;
padDfltMB.nlist = padLoadLen;
break;
default: break; /* shouldn't happen */
}
}
/* center first button in window around mouse position, with constraint that
window be fully on the screen */
popUp = poptyp;
if (startGrab == 2)
startGrab = 4;
else {
CenterMapWindow(popW, 40 + bts[0].x, BUTTH/2 + bts[0].y, puwide, puhigh);
/* MUST wait for VisibilityNotify event to come in, else we run the risk
of UnMapping the window *before* the Map request completed. This
appears to be bad, (It leaves an empty window frame up.) though it
generally only happens on slow servers. Better safe than screwed... */
XWindowEvent(theDisp, popW, VisibilityChangeMask, &event);
}
/* block until this window gets closed */
while (popUp) {
#ifndef NOSIGNAL
XtAppNextEvent(context, &event);
#else
XNextEvent(theDisp, &event);
#endif
HandleEvent(&event, &i);
}
/* free stuff */
XUnmapWindow(theDisp, popW);
free(bts);
return(selected);
}
/***************************************************/
void ErrPopUp(txt, label)
const char *txt;
const char *label;
{
/* simplified interface to PopUp. Takes a string and the label for the
(one) button */
PopUp(txt, &label, 1);
}
/***************************************************/
int GetStrPopUp(txt, labels, n, buf, buflen, filstr, allow)
const char *txt;
const char *labels[];
char *buf;
const char *filstr;
int n, buflen, allow;
{
/* pops up a window with a prompt string, a 1-line editable
text thingy, and a row of buttons. 'txt' is the prompt
string, 'labels' are the labels for the buttons, 'n' is the
number of buttons, 'buf' is the buffer displayed and edited
in the window, buflen is its length, filstr is a filter string, of
characters to block from entry (or, if 'allow' is '1', a list
of the *only* characters allowed for entry)
It returns the index of the button clicked on. Note that the
button labels have 1-character accellerators at the front, same
as in PopUp(). Note that it would be suboptimal to make any
of the 1-character accellerators be the same character as one of
the edit-text command keys
Also note that the filter string should only contain normal printable
characters (' ' through '\177'), as ctrl chars are pre-filtered
(ie, interpreted as emacs-like commands) */
gsBuf = buf; gsBufLen = buflen;
gsFilter = filstr; gsAllow = allow;
gsCurPos = strlen(gsBuf);
gsStPos = gsEnPos = 0;
gsh = LINEHIGH+5;
gsx = 10 + icon_width + 20;
gsy = 10+(PUHIGH-30-BUTTH-gsh)/2;
if (strlen(txt) > (size_t) 60)
gsy = PUHIGH - 10 - BUTTH - 10 - gsh - 20;
gsw = PUWIDE - gsx - 10;
changedGSBuf(); /* careful! popW doesn't exist yet! */
return doPopUp(txt, labels, n, ISGETSTR, "xv prompt");
}
/***************************************************/
int GrabPopUp(pHide, pDelay)
int *pHide, *pDelay;
{
/* pops up Grab options dialog box */
int rv;
char delaybuf[32], grabTxt[1024];
static const char *grabLabels[] = { "\nGrab", "aAutoGrab", "\033Cancel" };
sprintf(delaybuf,"%d", *pDelay);
gsBuf = delaybuf; gsBufLen = 3;
gsFilter = "0123456789"; gsAllow = 1;
gsCurPos = strlen(gsBuf);
gsStPos = gsEnPos = 0;
gsw = 32;
gsh = LINEHIGH+5;
gsx = 10 + StringWidth(DELAYSTR) + 5;
gsy = (PUHIGH-BUTTH-10-5-gsh);
changedGSBuf(); /* careful! popW doesn't exist yet! */
/* window value gets filled in in doPopUp() */
CBCreate(&ahideCB, (Window) None,
PUWIDE-10-18-StringWidth(HIDESTR),
gsy+2, HIDESTR, infofg, infobg, hicol, locol);
ahideCB.val = *pHide;
sprintf(grabTxt, "Grab: after delay, Left button grabs a window, ");
strcat (grabTxt, "Middle button ");
strcat (grabTxt, "grabs a rectangular area, Right button cancels.\n\n");
strcat (grabTxt, "AutoGrab: after delay, grabs ");
strcat (grabTxt, "the window the cursor is positioned in. ");
strcat (grabTxt, "Delay must be non-zero.");
rv = doPopUp(grabTxt, grabLabels, 3, ISGRAB, "xv grab");
*pHide = ahideCB.val;
*pDelay = atoi(delaybuf);
return rv;
}
/***************************************************/
int PadPopUp(pMode, pStr, pWide,pHigh, pOpaque, pOmode)
int *pMode, *pWide, *pHigh, *pOpaque, *pOmode;
char **pStr;
{
/* pops up 'Pad' options dialog box */
int rv, oldW, oldH, oldO;
static int firsttime=1;
static const char *labels[] = { "\nOk", "\033Cancel" };
if (firsttime) {
padSbuf[0] = '\0';
padBbuf[0] = '\0';
padLbuf[0] = '\0';
sprintf(padSinst, "Enter a color name ('orange'), %s%s",
"or an RGB color specification. ",
"(e.g. 'r,g,b' or '0xrrggbb')");
sprintf(padBinst, "Enter command line options for 'bggen'. (%s)",
"No '-w', '-h', or '-g' options allowed.");
sprintf(padLinst, "Enter a filename. The padded image %s",
"will be the same size as the loaded image.");
/* can't create MBUTT or DIALs here, parent window must exist first... */
padMode = PAD_SOLID;
padInst = padSinst;
padOMode = PAD_ORGB;
firsttime = 0;
}
buildPadLists();
switch (padMode) {
case PAD_SOLID: strcpy(padBuf, padSbuf); break;
case PAD_BGGEN: strcpy(padBuf, padBbuf); break;
case PAD_LOAD: strcpy(padBuf, padLbuf); break;
}
gsBuf = padBuf; gsBufLen = 256;
gsFilter = ""; gsAllow = 0;
gsCurPos = strlen(gsBuf);
gsStPos = gsEnPos = 0;
gsw = PAD_PUWIDE - 20;
gsh = LINEHIGH+5;
gsx = 10;
gsy = 40;
changedGSBuf(); /* careful! popW doesn't exist yet! */
if (padHaveDooDads) {
oldW = (int)padWDial.val;
oldH = (int)padHDial.val;
oldO = (int)padODial.val;
}
else { oldW = pWIDE; oldH = pHIGH; oldO = 100; }
rv = doPopUp("", labels, 2, ISPAD, "xv pad");
if (rv == 0) { /* copy padBuf to appropriate mode buffer */
switch (padMode) {
case PAD_SOLID: strcpy(padSbuf, padBuf); break;
case PAD_BGGEN: strcpy(padBbuf, padBuf); break;
case PAD_LOAD: strcpy(padLbuf, padBuf); break;
}
}
if (rv == 1) { /* cancelled: restore normal values */
DSetVal(&padWDial, (double)oldW);
DSetVal(&padHDial, (double)oldH);
DSetVal(&padODial, (double)oldO);
}
XUnmapWindow(theDisp, padWDial.win);
XUnmapWindow(theDisp, padHDial.win);
XUnmapWindow(theDisp, padODial.win);
/* load up return values */
*pMode = padMode;
*pStr = padBuf;
*pWide = (int)padWDial.val;
*pHigh = (int)padHDial.val;
*pOpaque = (int)padODial.val;
*pOmode = padOMode;
return rv;
}
/***************************************************/
static void buildPadLists()
{
/* generates padCol* and padBg* lists used in 'Defaults' MBUTT. Grabs
all the X resources values it can, and adds appropriate defaults */
rd_str_cl("foo", "", 1); /* rebuild database */
build1PadList("color", padColVals, padColNames, &padColLen,
padColDefVals, padColDefNames, padColDefLen);
build1PadList("bggen", padBgVals, padBgNames, &padBgLen,
padBgDefVals, padBgDefNames, padBgDefLen);
build1PadList("load", padLoadVals, padLoadNames, &padLoadLen,
(const char **) NULL, (const char **) NULL, 0);
}
/***************************************************/
static void build1PadList(typstr, vals, nams, lenp, dvals, dnams, dlen)
const char *typstr;
const char **vals, **nams;
const char **dvals, **dnams;
int *lenp, dlen;
{
int i;
char resname[128];
char *copy;
for (i=0; i<*lenp; i++) { /* kill old lists */
free((char *) nams[i]);
free((char *) vals[i]);
}
*lenp = 0;
for (i=0; i<10; i++) {
sprintf(resname, "pad.%s.val%d", typstr, i);
if (rd_str_cl(resname, "Dialog.Menu.Slot",0)) { /* got one! */
copy = strdup(def_str);
if (!copy) continue;
vals[*lenp] = copy;
sprintf(resname, "pad.%s.name%d", typstr, i);
if (rd_str_cl(resname, "Dialog.Menu.Slot",0)) { /* and it has a name! */
copy = strdup(def_str);
if (!copy) { free((char *) vals[*lenp]); continue; }
}
else { /* it doesn't have a name. fabricate one */
copy = malloc((size_t) 32);
if (!copy) { free((char *) vals[*lenp]); continue; }
strncpy(copy, vals[*lenp], (size_t) 31);
copy[31] = '\0';
}
if (strlen(copy) > (size_t) 20) { /* fix long names */
char *sp = copy + 18;
*sp++ = '.'; *sp++ = '.'; *sp++ = '.'; *sp++ = '\0';
}
nams[*lenp] = copy;
*lenp = (*lenp) + 1;
}
}
/* add 'built-in' defaults to the lists */
for (i=0; i<dlen && *lenp<PAD_MAXDEFLEN; i++) {
copy = strdup(dvals[i]);
if (!copy) break;
vals[*lenp] = copy;
copy = strdup(dnams[i]);
if (!copy) { free((char *) vals[*lenp]); break; }
nams[*lenp] = copy;
*lenp = (*lenp) + 1;
}
}
/***************************************************/
void ClosePopUp()
{
/* closes popW: if it's a pop-up, returns 'cancel'. If it's an alert,
simply closes it */
if (popUp == ISALERT) CloseAlert();
else if (popUp == ISPOPUP) {
popUp = 0;
selected = nbts-1;
}
}
/***************************************************/
void OpenAlert(txt)
const char *txt;
{
/* pops up a window with txt displayed in it (*no buttons*).
returns immediately. window is closed by 'CloseAlert()'.
No 'PopUp()' calls are allowed while an Alert is displayed. */
XEvent event;
if (firsttime) createPUD();
XStoreName(theDisp, popW, "xv notice");
XSetIconName(theDisp, popW, "xv notice");
attachPUD();
nbts = 0;
selected = 0;
text = txt;
puwide = PUWIDE; puhigh = PUHIGH;
XResizeWindow(theDisp, popW, (u_int) puwide, (u_int) puhigh);
/* center last button in window around mouse position, with constraint that
window be fully on the screen */
CenterMapWindow(popW, puwide/2, puhigh/2, puwide, puhigh);
popUp = ISALERT;
/* MUST wait for VisibilityNotify event to come in, else we run the risk
of UnMapping the window *before* the Map request completed. This
appears to be bad, (It leaves an empty window frame up.) though it
generally only happens on slow servers. Better safe than screwed... */
XWindowEvent(theDisp, popW, VisibilityChangeMask, &event);
drawPUD(0, 0, puwide, puhigh);
XFlush(theDisp);
}
/***************************************************/
void CloseAlert()
{
popUp = 0;
XUnmapWindow(theDisp, popW);
}
/***************************************************/
int PUCheckEvent(xev)
XEvent *xev;
{
/* check event to see if it's for us. If so, return 1, otherwise 0 */
int rv = 0;
if (!popUp) return(0);
if (xev->type == Expose) {
XExposeEvent *e = (XExposeEvent *) xev;
if (e->window == popW) {
drawPUD(e->x, e->y, e->width, e->height);
rv = 1;
}
else if (popUp == ISPAD && padHaveDooDads && e->window == padWDial.win)
{ DRedraw(&padWDial); rv = 1; }
else if (popUp == ISPAD && padHaveDooDads && e->window == padHDial.win)
{ DRedraw(&padHDial); rv = 1; }
else if (popUp == ISPAD && padHaveDooDads && e->window == padODial.win)
{ DRedraw(&padODial); rv = 1; }
}
else if (xev->type == ButtonPress) {
XButtonEvent *e = (XButtonEvent *) xev;
if (e->button == Button1) {
if (e->window == popW) {
clickPUD(e->x,e->y);
rv = 1;
}
else if (popUp == ISPAD && padHaveDooDads && e->window == padWDial.win)
{ DTrack(&padWDial, e->x, e->y); rv = 1; }
else if (popUp == ISPAD && padHaveDooDads && e->window == padHDial.win)
{ DTrack(&padHDial, e->x, e->y); rv = 1; }
else if (popUp == ISPAD && padHaveDooDads && e->window == padODial.win)
{ DTrack(&padODial, e->x, e->y); rv = 1; }
}
}
else if (xev->type == KeyPress) {
XKeyEvent *e = (XKeyEvent *) xev;
char buf[128]; KeySym ks;
int stlen, i, shift, ck;
stlen = XLookupString(e,buf,128,&ks,(XComposeStatus *) NULL);
shift = e->state & ShiftMask;
ck = CursorKey(ks, shift, 0);
buf[stlen] = '\0';
RemapKeyCheck(ks, buf, &stlen);
/* check cursor keys, which may or may not have a str assoc'd with them */
if (popUp==ISGETSTR || popUp==ISGRAB || popUp==ISPAD) {
if (ck==CK_LEFT) { doGetStrKey('\002'); rv = 1; }
else if (ck==CK_RIGHT) { doGetStrKey('\006'); rv = 1; }
}
if (stlen && !rv) { /* note: we accept kbd accel's in any win */
if (buf[0] == '\r') buf[0] = '\n';
/* search for character in accel table */
for (i=0; i<nbts; i++) {
if (buf[0] == accel[i] && buf[0] != ' ') {
FakeButtonPress(&bts[i]);
rv = 1;
}
}
if (!rv && buf[0]=='\033' && nbts==1) { /* ESC accepted in 1-but pu's */
FakeButtonPress(&bts[0]);
rv = 1;
}
if (!rv && (popUp==ISGETSTR || popUp==ISGRAB || popUp==ISPAD)) {
if (e->window == popW) { doGetStrKey(buf[0]); rv = 1; }
}
}
if (!stlen) rv = 1; /* quietly eat mute keys */
}
else if (xev->type == ClientMessage) {
Atom proto, delwin;
XClientMessageEvent *client_event = (XClientMessageEvent *) xev;
proto = XInternAtom(theDisp, "WM_PROTOCOLS", FALSE);
delwin = XInternAtom(theDisp, "WM_DELETE_WINDOW", FALSE);
if (client_event->message_type == proto &&
client_event->data.l[0] == delwin) {
/* it's a WM_DELETE_WINDOW event */
if (client_event->window == popW) {
FakeButtonPress(&bts[(nbts>1) ? nbts-1 : 0]);
rv = 1;
}
}
}
if (rv==0 && (xev->type == KeyPress || xev->type == ButtonPress)) {
XBell(theDisp, 0);
rv = 1; /* eat it */
}
return rv;
}
#define TR_MAXLN 10
/***************************************************/
static void TextRect(win, txt, x, y, w, h, fg)
Window win;
const char *txt;
int x,y,w,h;
u_long fg;
{
/* draws semi-complex strings in a rectangle */
const char *sp;
const char *ep;
const char *oldep;
const char *start[TR_MAXLN];
int i, inbreak, lineno, top, hardcr, maxln, len[TR_MAXLN];
XSetForeground(theDisp, theGC, fg);
sp = txt; lineno = hardcr = 0;
maxln = h / LINEHIGH;
RANGE(maxln,0,TR_MAXLN);
while (*sp && lineno<maxln) {
/* drop off any leading spaces (except on first line or after \n) */
if (sp!=txt && !hardcr) {
while (*sp==' ') sp++;
}
hardcr = 0; ep = sp;
/* increment ep until we A) get too wide, B) hit eos or
C) hit a '\n' character */
/* NOTE: ep points to the character AFTER the end of the line */
while (XTextWidth(mfinfo, sp, (int)(ep-sp))<= w && *ep && *ep!='\n') ep++;
if (*ep=='\n') { ep++; hardcr=1; } /* eat newline */
/* if we got too wide, back off until we find a break position
(last char before a space or a '/') */
if (XTextWidth(mfinfo, sp, (int)(ep-sp)) > w) {
oldep = ep; inbreak = 0;
while (ep!=sp) {
ep--;
if ( inbreak && *ep!=' ') { ep++; break; }
if (!inbreak && *ep==' ') inbreak = 1;
if (*ep=='/') { ep++; break; }
}
if (ep==sp) ep = oldep-1; /* can't break this line. oh well */
}
start[lineno] = sp; len[lineno] = ep-sp;
/* make sure we don't print a trailing '\n' character! */
if (len[lineno] > 0) {
while (sp[len[lineno]-1] == '\n') len[lineno] = len[lineno] - 1;
}
sp = ep;
lineno++;
}
top = y + h/2 + (ASCENT-DESCENT)/2 - ((lineno-1)*LINEHIGH)/2;
if (top<y+ASCENT) top = y+ASCENT;
for (i=0, y=top; i<lineno; i++, y+=LINEHIGH) {
if (start[i][0] != '\n')
XDrawString(theDisp, win, theGC, x, y, start[i], len[i]);
}
}
/***************************************************/
static void createPUD()
{
popW = CreateWindow("xv confirm", "XVconfirm", "+0+0",
PUWIDE, PUHIGH, infofg, infobg, FALSE);
if (!popW) FatalError("can't create popup window!");
XSelectInput(theDisp, popW, ExposureMask | ButtonPressMask | KeyPressMask
| VisibilityChangeMask);
/* XSetTransientForHint(theDisp, popW, mainW); */
XDefineCursor(theDisp, popW, arrow);
bts = (BUTT *) NULL;
nbts = selected = firsttime = 0;
}
/***************************************************/
static void attachPUD()
{
/* used to make PUD a transient window of something. Doesn't
do anything anymore, as I got tired of having window layering
shifted around everytime a popup window happened. Screw the
business about having the popup iconify when you iconify the
appropriate XV window. There generally ISN'T an appropriate
XV window... */
}
/***************************************************/
static void drawPUD(x,y,w,h)
int x,y,w,h;
{
int i,xt,yt;
XRectangle xr;
xr.x = x; xr.y = y; xr.width = w; xr.height = h;
XSetClipRectangles(theDisp, theGC, 0,0, &xr, 1, Unsorted);
XSetForeground(theDisp, theGC, infofg);
XSetBackground(theDisp, theGC, infobg);
if (popUp == ISGRAB) {
xt = 10; yt = 10;
TextRect(popW, text, xt, yt, puwide-10-xt, gsy-20, infofg);
drawGSBuf();
XSetForeground(theDisp, theGC, infofg);
DrawString(popW, 10, gsy+ASCENT+4, DELAYSTR);
DrawString(popW, gsx+gsw+5, gsy+ASCENT+4, SECSTR);
CBRedraw(&ahideCB);
}
else if (popUp == ISPAD) {
drawGSBuf();
XSetForeground(theDisp, theGC, infofg);
DrawString(popW, 10+44,10+ASCENT+4,"Pad Method:");
MBRedraw(&padMthdMB);
MBRedraw(&padDfltMB);
DRedraw (&padWDial);
DRedraw (&padHDial);
BTRedraw(&padDButt);
BTRedraw(&padOMButt);