-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontrols.c
More file actions
3223 lines (2867 loc) · 82.6 KB
/
controls.c
File metadata and controls
3223 lines (2867 loc) · 82.6 KB
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
/*
* $Id: controls.c,v 1.2 2003/03/19 16:45:47 jd Exp $
* Groovit Copyright (C) 1998,1999 Jean-Daniel PAUGET
* making accurate and groovy sound/noise
*
* groovit@disjunkt.com - http://groovit.disjunkt.com/
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* you can also try the web at http://www.gnu.org/
*
* $Log: controls.c,v $
* Revision 1.2 2003/03/19 16:45:47 jd
* major changes everywhere while retrieving source history up to this almost final release
*
* Revision 1.2.0.24.0.3 2000/10/01 21:07:03 jd
* mhhh I dunno
*
* Revision 1.2.0.24.0.2 1999/10/19 19:29:45 jd
* *** empty log message ***
*
* Revision 1.2.0.24.0.1 1999/10/11 18:36:29 jd
* *** empty log message ***
*
* Revision 1.2.0.24 1999/10/11 15:30:51 jd
* second pre-tel-aviv revision
*
* Revision 1.2.0.23.0.5 1999/10/11 15:05:55 jd
* added jmeta, first try
* corrected F-Keys with console
*
* Revision 1.2.0.23.0.3 1999/10/05 23:04:46 jd
* added member nbmodif and exported function for it
*
* Revision 1.2.0.23 1999/09/15 10:20:39 jd
* second pre tel-aviv public revision, for testing
*
* Revision 1.2.0.22.0.6 1999/09/15 09:23:30 jd
* corrected bug with undefined hslides
* added positions relative to contexts and moveable contexts
* corrected CONTNOCOL bug with buttons
* corrected bug in range of polltime
*
* Revision 1.2.0.22.0.4 1999/09/05 22:30:16 jd
* corrected curses inclusion
* corrected (one more time ?) handling of back and suppr
*
* Revision 1.2.0.22.0.3 1999/08/30 22:16:03 jd
* added transmission of lastpressed to context's actionnes
* corrected vslide defaults colors
*
* Revision 1.2.0.22.0.2 1999/08/29 16:58:26 jd
* added dialogs
*
*/
// #define MEGASTATIC
#define SIMPLE_MEMPROFILE
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include "config.h"
#ifdef USEERRNOH
#include <errno.h>
#endif
/* JDJDJDJD this was for gpm excluding gpm-xterm #ifdef HAVE_LIBGPM #include <gpm.h> #else
#include "gpm-xterm.h" #endif */
#ifdef HAVE_LIBGPM
#include "gpm.h" /* JDJDJDJD devrait etre dans la distrib... */
#endif
#include "gpm-xterm.h"
#ifdef HAVENCURSES
#include <ncurses.h>
#else
#ifdef HAVECURSES
#include <curses.h>
#else
/* maybe curses.h is somewhere we don't know but cc knows ?? */
#include <curses.h>
#endif
#endif
#include <sys/time.h>
#include "semaphore.h"
#define MAINCONTR
#include "controls.h"
static int lastpressed = -1; /* le dernier controls utilise */
int usetimer = 1; /* devons-nous utiliser le timer ? */
int usexterm = 0; /* sommes-nous dans un xterm ? */
static int uselibgpm = 0; /* utilisons-nous libgpm ??? */
int (*Pgpm_getc) (FILE * f) = NULL; /* pointeur sur la fonction de lecture de
char */
int wasmodified = 0; /* un champ pattern modifie ?? */
int focus = 0;
typedef union tcontain /* data-container for controls */
{
struct
{
int minv, /* valeur mini ... */
maxv; /* ... et maxi */
}
mm; /* mnemo: mm = "MinMax" */
struct
{
int nbrow, /* nombre courant de colonnes */
maxrow, /* nombre max de colonnes */
radio; /* radio handle (-1 if not) */
Radio *rdata; /* radio pointer */
}
pf; /* mnemo: pf = "PatternField" */
struct
{
int nbrow, /* nombre courant de colonnes */
maxrow, /* nombre max de colonnes */
nbligne, /* nombre de ligne */
radio; /* radio handle (-1 if not) */
Radio *rdata; /* radio pointer */
}
es; /* mnemo: es = "ScoreEdit" */
struct
{
char *s[NBBUTSTR]; /* strings for button/state */
int radio; /* radio handle (-1 if not) */
}
bs; /* mnemo: bs = "ButtonStrings" */
struct
{
int nb, /* number of handles of group */
*h; /* address of first handle */
}
gr; /* mnemo: gr = "GRoup" */
struct
{
char **list; /* pointeur sur tableau de nom d'items */
int larg, /* largeur de la listbox */
haut, /* hauteur de la listbox */
nbelem, /* nombre d'elements dans la liste */
curoff, /* offset actuel dans la liste */
cursur; /* celui actuellement surligne */
}
lb; /* mnemo: lb = "ListBox" */
struct
{
int larg, /* largeur de la fenetre d'edition */
offset, /* offset actuel du texte */
curpos, /* position actuelle du curseur */
curlen, /* longueur actuelle du buffer */
len, /* longueur max du buffer */
defaulth; /* handle du controls de default action */
}
te; /* mnemo te = "TextEdit" */
struct
{
int len, /* longueur de la chaine texte */
color; /* la couleur de ladite... */
char *text; /* la chaine de texte */
}
ts; /* mnemo ts = "Text String" */
}
Contain;
typedef struct tcontrol /* structure de gestion de zone reactives */
{
int type; /* nature du controle */
int x, y; /* coordonees en haut a gauche du controle */
int o; /* handle du contexte proprietaire */
int hjmeta; /* no de jmeta handle qui controle */
int toberefreshed; /* le controls doit-il etre rafraichi ? */
int nbmodif; /* le nombre de modifs subies */
int isfreezed; /* le controle est-il gele par un autre contexte */
int associated; /* handle d'un eventuel controls associe */
char c; /* raccourci clavier ??? JDJDJD */
Tpression pression; /* pointeur sur l'action a effectuer en cas de pression */
int evtype; /* type d'evenement */
int voice; /* la voie affectée */
void *p; /* valeur maintenue par le controle */
Contain d; /* data contained... */
}
Controls;
static Controls controls[MAXNBCONTROLS]; /* les controls proprement dits */
static short toberefreshed[MAXNBCONTROLS], /* les controles a rafraichir au prochain
polling */
nbtoberefreshed = 0, /* combien on doit en rafraichir */
refreshing = 0; /* somme nous en phase de refresh ? */
/* --------------------------variables de contexts---------------------------------------- */
#define CONTCTXFREE 0
#define CONTCTXUSED 1
typedef struct tcontext /* la structure de context */
{
int type, /* type de context / utilisation */
isinstalled, /* le context est installe ? */
x, /* coordonnee en haut a gauche de la sous fenetre */
y, /* coordonnee en haut a gauche de la sous fenetre */
lx, /* largeur */
ly, /* hauteur */
color, /* background color */
parent, /* context parent */
/* nbconttofreeze, *//* nombre de controls a geler */
nbconttoinstall; /* nombre de controls a installer */
/* quel controls en xy pour ce context ? */
Tactionne actionne; /* pointeur sur l'actionnement du contexts */
/* tofreeze [MAXNBCONTROLS], *//* les controls a geler */
#ifdef MEGASTATIC
int whichcontrols[MAXSCREENHEIGHT][MAXSCREENWIDTH];
#else
int *whichcontrols;
#endif
int toinstall[MAXNBCONTROLS]; /* les controls a installer */
char name[CONTEXTNAMESIZE + 1];
}
Contexts;
Contexts contexts[MAXCONTEXTS];
int curcontext = -1, /* identifiant du context en cours ??? */
nbctx = -1; /* nombre de contextes deja installes ??? */
static int contextfilo[MAXCONTEXTS], /* empilement des contextes */
freezedlist[MAXCONTEXTS][MAXNBCONTROLS], /* controles geles au nieme contexte */
nbcontfreez[MAXCONTEXTS]; /* nombre de contexte gele */
/* contextes de clicks */
static int tabwhichcontrols[MAXCONTEXTS][MAXSCREENHEIGHT][MAXSCREENWIDTH], /* quel
controls
en xy ? */
(*whichcontrols)[MAXSCREENHEIGHT][MAXSCREENWIDTH] = &(tabwhichcontrols[0]);
static int keyhandler[MAXKEYHANDLER]; /* quel controls pour la touche z ? */
static char *backstr[MAXBACKSTR]; /* les chaines de char de background */
static int nbbackstr = 0; /* nombre de chaine de background */
typedef struct tjmeta /* la structure de jmeta controls */
{
int nb; /* le nombre de membres */
int member[MAXMETAMEMBER]; /* les membres */
}
JMeta;
JMeta jmeta[8]; /* les handles des jmeta */
#ifdef SIMPLE_MEMPROFILE
static long totdivs = 0;
#endif
#ifdef SHOWRCS
static char *rcsid = "$Id: controls.c,v 1.2 2003/03/19 16:45:47 jd Exp $";
#endif
static int firstuse = 1;
#define MAXHEADROOM 42
static int scorelook[MAXHEADROOM] =
{0, 0, 0, 0, 0, /* low note from C */
1, 0, /* low G on F'score */
1, 0, /* B */
1, 0, /* D */
1, 0, /* F */
1, 0, /* A */
0, 0, 0, /* empty's B,C,D */
1, 0, /* med E on G'score */
1, 0, /* G */
1, 0, /* G */
1, 0, /* B */
1, 0, /* D */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* something else to say ??? */
};
/* --------------------------variables de polling----------------------------------------- */
static int fmouse; /* mouse events file handle for polling */
static Gpm_Event gevent; /* for mouse coord */
#ifdef JDSEMAPHORE
static int semid;
#else
static int pollreintrance = 0; /* test de reentrance du polling */
#endif
static fd_set readfdset; /* pour le polling */
/* --------------------------------------------------------------------------------------- */
char *bgcol[8][2] =
{
{"\033[40m", "\033[40m\033[36m"},
{"\033[41m", "\033[41m\033[36m"},
{"\033[42m", "\033[42m\033[36m"},
{"\033[43m", "\033[43m\033[36m"},
{"\033[44m", "\033[44m\033[36m"},
{"\033[45m", "\033[45m\033[36m"},
{"\033[46m", "\033[46m\033[36m"},
{"\033[47m", "\033[47m\033[36m"},
};
char *strlevel[10] =
{
"\033[1m|-------\033[m",
"\033[1m-|------\033[m",
"\033[1m--|-----\033[m",
"\033[1m---|----\033[m",
"\033[1m----|---\033[m",
"\033[1m-----|--\033[m",
"\033[1m------|-\033[m",
"\033[1m-------|\033[m",
"\033[1m------->\033[m",
"\033[m "
}, *strhlevel[10][2] =
{
{"\033[m\016 \033[B\010 \033[B\010 \033[B\010s\017",
"\033[1m\033[36m\016 \033[B\010 \033[B\010 \033[B\010s\017"},
{"\033[m\016 \033[B\010 \033[B\010 \033[B\010w\017",
"\033[1m\033[36m\016 \033[B\010 \033[B\010 \033[B\010w\017"},
{"\033[m\016 \033[B\010 \033[B\010s\033[B\010x\017",
"\033[1m\033[36m\016 \033[B\010 \033[B\010s\033[B\010x\017"},
{"\033[m\016 \033[B\010 \033[B\010w\033[B\010x\017",
"\033[1m\033[36m\016 \033[B\010 \033[B\010w\033[B\010x\017"},
{"\033[m\016 \033[B\010s\033[B\010x\033[B\010x\017",
"\033[1m\033[36m\016 \033[B\010s\033[B\010x\033[B\010x\017"},
{"\033[m\016 \033[B\010w\033[B\010x\033[B\010x\017",
"\033[1m\033[36m\016 \033[B\010w\033[B\010x\033[B\010x\017"},
{"\033[m\016s\033[B\010x\033[B\010x\033[B\010x\017",
"\033[1m\033[36m\016s\033[B\010x\033[B\010x\033[B\010x\017"},
{"\033[m\016w\033[B\010x\033[B\010x\033[B\010x\017",
"\033[1m\033[36m\016w\033[B\010x\033[B\010x\033[B\010x\017"},
{"\033[m\016x\033[B\010x\033[B\010x\033[B\010x\017",
"\033[1m\033[36m\016x\033[B\010x\033[B\010x\033[B\010x\017"},
{"\033[m \033[B\010 \033[B\010 \033[B\010 ",
"\033[1m\033[36m \033[B\010 \033[B\010 \033[B\010 "}
}, *strfocus[2] =
{"", "\033[1m"};
/*
* small debug to screen without scrolling....
*/
void scrflush (void); /* small anti-declaration for coherence */
int registertocontexts (int ctx, int ctl); /* another one ... JDJDJDJD */
void pdebug (int n, char *s)
{
if (usexterm)
printf ("\033]2; %04x %-60s\007", n, s);
#ifdef DEBUGINCONSOLE
else
printf ("\033[%d;%dH\033[1m\033[40m\033[33m %04x \033[36m%-60s", 26 + MAXSAMPLE - 16, 1, n, s);
#endif
scrflush ();
}
inline int controlsx (h)
{
return controls[h].x + contexts[controls[h].o].x;
}
inline int controlsy (h)
{
return controls[h].y + contexts[controls[h].o].y;
}
void settitle (char *title1, char *title2)
{
if (usexterm)
printf ("\033]2;%s - %s\007", title1, title2);
}
int refreshcontrols (int h) /* rafraichit l'affichage d'un controls */
{
if ((refreshing) && (!controls[h].isfreezed))
{
controls[h].toberefreshed = 0;
switch (controls[h].type)
{
case CONTRHSLIDE: /* slide horizontal - refreshcontrols */
if (controls[h].p == NULL)
printf ("\033[%d;%dH%s%s", controlsy (h), controlsx (h),
bgcol[controls[h].hjmeta][focus == h],
strlevel[9]);
else
printf ("\033[%d;%dH%s%s", controlsy (h), controlsx (h),
bgcol[controls[h].hjmeta][focus == h],
strlevel[(*(int *) controls[h].p) >> 5]);
break;
case CONTRVSLIDE: /* slide vertical - refreshcontrols */
if (controls[h].p == NULL)
printf ("\033[%d;%dH%s", controlsy (h), controlsx (h),
strhlevel[9][focus == h]);
else
printf ("\033[%d;%dH%s", controlsy (h), controlsx (h),
strhlevel[(*(int *) controls[h].p) >> 5][focus == h]);
break;
case CONTRNUMRANGE: /* numerical range - refreshcontrols */
if (controls[h].p == NULL)
printf ("\033[%d;%dH%s«\033[41m\033[33m\033[1m---\033[m%s»\033[m", controlsy (h), controlsx (h),
strfocus[focus == h], strfocus[focus == h]);
else
printf ("\033[%d;%dH%s«\033[41m\033[33m\033[1m%3d\033[m%s»\033[m", controlsy (h), controlsx (h),
strfocus[focus == h],
*(int *) controls[h].p, strfocus[focus == h]);
break;
case CONTRPFIELD: /* pattern row - refreshcontrols */
{
int i, *p;
if (controls[h].p == NULL)
{
printf ("\033[%d;%dH%s", controlsy (h), controlsx (h), strfocus[focus == h]);
for (i = 0; i < controls[h].d.pf.maxrow; i++)
printf (" ");
printf ("\033[m");
}
else
{
p = controls[h].p;
/* printf ("\033[%d;%dH\016%s", controls[h].y, controls[h].x, strfocus[focus == h]); */
printf ("\033[%d;%dH\016%s", controlsy (h), controlsx (h),
(controls[h].d.pf.rdata != NULL) ?
strfocus[controls[h].d.pf.rdata->value == controls[h].d.pf.radio]
: strfocus[focus == h]);
for (i = 0; i < controls[h].d.pf.maxrow; i++)
printf ("%s%c",
(i < controls[h].d.pf.nbrow) ?
((i % 4) ? "\033[37m" : "\033[33m") :
"\033[34m",
*p++ ? '`' : '·');
printf ("\017\033[m");
}
}
break;
case CONTNOTEEDIT: /* editable score - refreshcontrols */
{
int i, j, k, *p;
if (controls[h].p == NULL)
{
for (j = 0; j < controls[h].d.es.nbligne; j++)
{
printf ("\033[%d;%dH%s", controlsy (h) + j, controlsx (h), strfocus[0]);
for (i = 0; i < controls[h].d.pf.maxrow; i++)
printf ("+"); /* JDJDJDJD juste pour tester */
}
printf ("\033[m");
}
else
{
k = controls[h].d.es.nbligne;
for (j = 0; j < controls[h].d.es.nbligne; j++, k--)
{
printf ("\033[%d;%dH%s", controlsy (h) + j, controlsx (h), strfocus[0]);
p = controls[h].p;
for (i = 0; i < controls[h].d.pf.maxrow; i++)
printf ("%s",
(((*p) >> 1) % 30) == j ?
"\033[33mO" :
scorelook[k] ?
"\033[m-" : "\033[m "
);
}
printf ("\033[m");
}
}
break;
case CONTRBUTTON: /* button - refreshcontrols */
{
int *p = controls[h].p;
if ((p == NULL) || (*p < 0) || (*p > NBBUTSTR))
printf ("\033[%d;%dH%s", controlsy (h), controlsx (h), controls[h].d.bs.s[BUT_DIS + ((focus == h) ? BUT_ISFOC : 0)]);
else
printf ("\033[%d;%dH%s", controlsy (h), controlsx (h),
controls[h].d.bs.s[*p + ((focus == h) ? BUT_ISFOC : 0)]);
}
break;
case CONTRRADIO: /* radio button - refreshcontrols */
{
Radio *p = controls[h].p;
if ((p == NULL) || (p->value > p->nb))
printf ("\033[%d;%dH%s", controlsy (h), controlsx (h), controls[h].d.bs.
s[BUT_DIS + ((focus == h) ? BUT_ISFOC : 0)]);
else
printf ("\033[%d;%dH%s", controlsy (h), controlsx (h),
controls[h].d.bs.s[((p->value == controls[h].d.bs.radio) ? BUT_ON : BUT_OFF) + ((focus == h) ? BUT_ISFOC : 0)]);
}
break;
case CONTRGROUP: /* groupe de controls - refreshcontrols */
{
int i;
for (i = 0; i < controls[h].d.gr.nb; i++)
refreshcontrols (controls[h].d.gr.h[i]);
}
break;
case CONTBGND: /* le fond d'ecran - refreshcontrols */
{
int i;
printf ("\033[2m");
for (i = 0; i < nbbackstr; i++)
printf ("%s", backstr[i]);
}
break;
case CONTLISTBOX: /* list box... - refreshcontrols */
{
int i, *p = (int *) controls[h].p, curoff = controls[h].d.lb.curoff;
char format[28] = "\033[%d;%dH%s%s%-10.10s ";
sprintf (format, "\033[%%d;%%dH%%s%%s%%-%d.%ds", controls[h].d.lb.larg, controls[h].d.lb.larg);
for (i = 0; i < controls[h].d.lb.haut; i++)
{
printf (format,
controlsy (h) + i,
controlsx (h),
(focus == h) ? "\033[1m" : "\033[0m",
((i + curoff) == *p) ? "\033[41m\033[33m" :
((i + curoff) == controls[h].d.lb.cursur) ? "\033[46m\033[37m" : "\033[44m\033[37m",
((i + curoff) < controls[h].d.lb.nbelem) ?
controls[h].d.lb.list[i + curoff] :
""
);
if (i == 0)
printf ("\033[1m\033[37m\033[40m^\033[m");
}
printf ("\033[1m\033[37m\033[40mv\033[m");
}
break;
case CONTTEXTSTR: /* text string - refreshcontrols */
printf ("\033[%d;%dH\033[4%cm\033[3%cm%s", controlsy (h), controlsx (h),
'0' + contexts[controls[h].o].color,
'0' + controls[h].d.ts.color,
controls[h].d.ts.text);
break;
case CONTTEXTEDIT: /* editable text - refreshcontrols */
{
int i, t;
char *p = (char *) controls[h].p + controls[h].d.te.offset;
printf ("\033[%d;%dH%s", controlsy (h), controlsx (h), (focus == h) ? "\033[1m" : "\033[0m");
for (i = 0, t = controls[h].d.te.offset; i < controls[h].d.te.larg; i++, t++, p++)
printf ("%s%c",
(t == controls[h].d.te.curpos) ? "\033[41m\033[33m" : "\033[44m\033[37m",
(t < controls[h].d.te.curlen) ? *p : ' ');
printf ("\033[m");
}
break;
default:
return -1;
}
return 0;
}
else
{
if (!controls[h].toberefreshed)
{
toberefreshed[nbtoberefreshed++] = h;
controls[h].toberefreshed++;
}
return 0;
}
}
void refreshscreen (void)
{
int i;
for (i = 0; i < MAXNBCONTROLS; i++)
if (controls[i].type != CONTUNDEF)
refreshcontrols (i);
}
void clearscreen (void)
{
printf ("\033[H\033[2J"); /* on efface l'ecran */
refreshscreen ();
}
int refreshpfield (int h, int nbrow) /* rafraichit l'affichage d'un pattern field */
{
controls[h].d.pf.nbrow = nbrow;
return (refreshcontrols (h));
}
int changefocus (int newfocus)
{
int oldfocus = focus;
if (newfocus != focus)
{
focus = newfocus;
if (oldfocus != 0)
refreshcontrols (oldfocus);
if (focus != 0)
refreshcontrols (focus);
return 1;
}
else
return 0;
}
void clearjmeta (int m)
{
jmeta[m].nb = 0;
}
void initjmeta (void)
{
int i;
for (i = 0; i < 8; i++)
clearjmeta (i);
keyhandler[CONTKEY_F1] = 0;
keyhandler[CONTKEY_F2] = 0;
keyhandler[CONTKEY_F3] = 0;
keyhandler[CONTKEY_F4] = 0;
keyhandler[CONTKEY_F5] = 0;
keyhandler[CONTKEY_F6] = 0;
keyhandler[CONTKEY_F7] = 0;
keyhandler[CONTKEY_F8] = 0;
keyhandler[CONTKEY_F9] = 0;
keyhandler[CONTKEY_F10] = 0;
keyhandler[CONTKEY_F11] = 0;
keyhandler[CONTKEY_F12] = 0;
}
void removejmeta (int m, int h)
{
int i;
if (m == 0)
{
refreshcontrols (h);
return;
}
for (i = 0; i < jmeta[m].nb; i++)
if (jmeta[m].member[i] == h)
{
jmeta[m].member[i] = jmeta[m].member[jmeta[m].nb];
jmeta[m].nb--;
controls[h].hjmeta = 0;
refreshcontrols (h);
break;
}
}
void addjmeta (int m, int h)
{
if (controls[h].hjmeta == m)
return;
if (m == 0)
{
controls[h].hjmeta = m;
refreshcontrols (h);
return;
}
if (jmeta[m].nb >= MAXMETAMEMBER)
removejmeta (m, jmeta[m].member[jmeta[m].nb - 1]);
jmeta[m].member[jmeta[m].nb] = h;
controls[h].hjmeta = m;
jmeta[m].nb++;
refreshcontrols (h);
}
void actionnejmeta (int m, int c)
{
int i;
for (i = 0; i < jmeta[m].nb; i++)
keycontrols (jmeta[m].member[i], c);
}
void actionnedirectjmeta (int m, int val)
{
int i;
for (i = 0; i < jmeta[m].nb; i++)
keydirectcontrols (jmeta[m].member[i], val);
}
int keydirectcontrols (int h, int val) /* returns 0 if the control cannot support direct */
{
int *p = (int *) controls[h].p;
lastpressed = h;
switch (controls[h].type)
{
case CONTRVSLIDE: /* slide vertical - keycontrols */
case CONTRHSLIDE: /* slide horizontal - keycontrols */
if (p != NULL)
{
if (val > 256)
*p = 256;
else if (val < 0)
*p = 0;
else
*p = val;
controls[h].nbmodif++;
if (controls[h].pression != NULL)
controls[h].pression (controls[h].evtype, controls[h].voice, *p);
if (controls[h].associated != CONTUNDEF)
refreshcontrols (controls[h].associated);
refreshcontrols (h);
return (1);
}
break;
default:
return 0;
}
return (0);
}
int keycontrols (int h, int c) /* returns 0 if the char is NOT handled */
{
int *p = (int *) controls[h].p;
lastpressed = h;
switch (controls[h].type)
{
case CONTRVSLIDE: /* slide vertical - keycontrols */
case CONTRHSLIDE: /* slide horizontal - keycontrols */
if (p != NULL)
{
if ((c >= '1') && (c <= '9'))
*p = (c - '1') << 5;
else
switch (c)
{
case 'M':
controls[h].nbmodif++;
*p = 256; /* JDJDJDJD */
if (controls[h].pression != NULL)
controls[h].pression (controls[h].evtype, controls[h].voice, *p);
break;
case '-': /* decrement */
if (*p != 0)
{
controls[h].nbmodif++;
(*p)--;
if (controls[h].pression != NULL)
controls[h].pression (controls[h].evtype, controls[h].voice, *p);
}
break;
case '+': /* increment */
if (*p != 256)
{
(*p)++; /* JDJDJDJD */
controls[h].nbmodif++;
if (controls[h].pression != NULL)
controls[h].pression (controls[h].evtype, controls[h].voice, *p);
}
break;
default:
return 0;
}
if (controls[h].associated != CONTUNDEF)
refreshcontrols (controls[h].associated);
refreshcontrols (h);
return (1);
}
break;
case CONTRNUMRANGE: /* numerical range - keycontrols */
if (p != NULL)
{
switch (c)
{
case '-': /* decrement */
(*p)--;
if (*p < controls[h].d.mm.minv)
*p = controls[h].d.mm.minv;
else
controls[h].nbmodif++;
if (controls[h].pression != NULL)
controls[h].pression (controls[h].evtype, controls[h].voice, *p);
break;
case '+': /* increment */
(*p)++;
if (*p > controls[h].d.mm.maxv)
*p = controls[h].d.mm.maxv;
else
controls[h].nbmodif++;
if (controls[h].pression != NULL)
controls[h].pression (controls[h].evtype, controls[h].voice, *p);
break;
default:
return (0);
}
if (controls[h].associated != CONTUNDEF)
refreshcontrols (controls[h].associated);
refreshcontrols (h);
return (1);
}
break;
case CONTRBUTTON: /* button - keycontrols */
if ((p != NULL) && ((c == controls[h].c) || (c == ' ')))
{
switch (*p)
{
case BUT_DIS:
case BUT_INV:
return (0);
case BUT_ON:
controls[h].nbmodif++;
*p = BUT_OFF;
if (controls[h].pression != NULL)
controls[h].pression (controls[h].evtype, controls[h].voice, *p);
break;
case BUT_OFF:
controls[h].nbmodif++;
*(int *) controls[h].p = BUT_ON;
if (controls[h].pression != NULL)
controls[h].pression (controls[h].evtype, controls[h].voice, *p);
break;
}
if (controls[h].associated != CONTUNDEF)
refreshcontrols (controls[h].associated);
refreshcontrols (h);
return (1);
}
else
return (0);
case CONTRRADIO: /* radio button - keycontrols */
{
Radio *p = (Radio *) controls[h].p;
int oldv;
if ((p != NULL) && ((c == controls[h].c) || (c == ' ') || (c == 0xd)))
{
oldv = p->value;
if (controls[h].d.bs.radio != oldv)
{
controls[h].nbmodif++;
p->value = controls[h].d.bs.radio;
if (controls[h].pression != NULL)
controls[h].pression (controls[h].evtype, controls[h].voice, p->value);
refreshcontrols (p->h[oldv]);
refreshcontrols (h);
}
return (1);
}
}
break;
case CONTBGND: /* fond d'ecran - keycontrols */
switch (c)
{
case 0xC: /* CTRL-L */
clearscreen ();
return (1);
case CONTKEY_F1:
return (keycontrols (focus, '-'));
case CONTKEY_F2:
return (keycontrols (focus, '+'));
case CONTKEY_F3:
actionnejmeta (1, '-');
return 1;
case CONTKEY_F4:
actionnejmeta (1, '+');
return 1;
case CONTKEY_F5:
actionnejmeta (2, '-');
return 1;
case CONTKEY_F6:
actionnejmeta (2, '+');
return 1;
case CONTKEY_F7:
actionnejmeta (3, '-');
return 1;
case CONTKEY_F8:
actionnejmeta (3, '+');
return 1;
case CONTKEY_F9:
actionnejmeta (4, '-');
return 1;
case CONTKEY_F10:
actionnejmeta (4, '+');
return 1;
case CONTKEY_F11:
// fprintf (stderr, "F11\n");
actionnejmeta (5, '-');
return 1;
case CONTKEY_F12:
// fprintf (stderr, "F12\n");
actionnejmeta (5, '+');
return 1;
}
return 0;
case CONTLISTBOX: /* list box - keycontrols */
switch (c)
{
case CONTKEY_UARR: /* one-up */
if (controls[h].d.lb.cursur > 0)
{
controls[h].nbmodif++;
controls[h].d.lb.cursur--;
if (controls[h].d.lb.cursur < controls[h].d.lb.curoff)
controls[h].d.lb.curoff = controls[h].d.lb.cursur;
else if (controls[h].d.lb.cursur > controls[h].d.lb.curoff + controls[h].d.lb.haut - 1)
controls[h].d.lb.curoff = controls[h].d.lb.cursur - controls[h].d.lb.haut + 1;
if (controls[h].pression != NULL)
controls[h].pression (controls[h].evtype, controls[h].voice, *p);
refreshcontrols (h);
}
return 1;
case CONTKEY_DARR: /* one-down */
if (controls[h].d.lb.cursur < controls[h].d.lb.nbelem - 1)
{
controls[h].nbmodif++;
controls[h].d.lb.cursur++;
if (controls[h].d.lb.cursur < controls[h].d.lb.curoff)
controls[h].d.lb.curoff = controls[h].d.lb.cursur;
else if (controls[h].d.lb.cursur > controls[h].d.lb.curoff + controls[h].d.lb.haut - 1)
controls[h].d.lb.curoff = controls[h].d.lb.cursur - controls[h].d.lb.haut + 1;
if (controls[h].pression != NULL)
controls[h].pression (controls[h].evtype, controls[h].voice, *p);
refreshcontrols (h);
}
return 1;
case ' ': /* space */
case 0xd: /* return */
controls[h].nbmodif++;
*(int *) controls[h].p = controls[h].d.lb.cursur;
if (controls[h].pression != NULL)
controls[h].pression (controls[h].evtype, controls[h].voice, *p);
refreshcontrols (h);
return 1;
}
break;
case CONTTEXTEDIT: /* editable text - keycontrols */
switch (c)
{
case CONTKEY_RETURN: /* default action */
if (controls[h].d.te.defaulth != CONTUNDEF)
{
changefocus (controls[h].d.te.defaulth);
return 1;
}
return 0;
case CONTKEY_LARR: /* going left */
if (controls[h].d.te.curpos > 0)