summaryrefslogtreecommitdiff
path: root/tex/context/base/mkxl/scrn-fld.mklx
blob: 6c134268c6061663bbff2884b92df12274077b15 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
%D \module
%D   [       file=scrn-fld,
%D        version=1997.05.18,
%D          title=\CONTEXT\ Screen Macros,
%D       subtitle=Fields,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

%D There is still some leftover code from mkii, where we need to be sparse with hash
%D entries and so have a somewhat complex setup mechanism. It doesn't pay off to
%D waste time on improving this because one never knows what happens with widgets
%D in \PDF; it has a history of dropping features like this. Also, the implementation
%D of fields fluctuates with versions.

% interaction checking

\writestatus{loading}{ConTeXt Screen Macros / Fields}

\unprotect

\registerctxluafile{scrn-fld}{}

%D In \MKII\ we had to cheat a bit with setups in order not to run out of memory
%D with thousands of fields, which we happen to need at that time. In \MKIV\ we can
%D store some data at the \LUA\ end and use a somewhat slower but quite okay
%D inheritance mechanism. For this reason we now have split definitions, although
%D the old method is still somewhat supported. The clone and copy commands are
%D somewhat obsolete for several reasons: we can now use inheritance and autocloning
%D has been supported for a while. In most cases cloning (especially with check
%D boxes) the acrobat browser is not stable enough with respect to appearance
%D handling.
%D
%D A fieldcategory is nothing more than a collection of settings.
%D
%D \starttyping
%D \definefieldcategory
%D   [all-email]
%D   [height=1cm,
%D    width=14cm,
%D    style=sstf]
%D \stoptyping
%D
%D A definition can refer to this category:
%D
%D \starttyping
%D \definefieldbody [email] [type=line,category=all-email,default=pragma@xs4all.nl]
%D \stoptyping
%D
%D A copy of a field is made as follows:
%D
%D \starttyping
%D \definefieldbody [xmail] [email]
%D \stoptyping
%D
%D You can also be more specific:
%D
%D \starttyping
%D \definefieldbody[buttona][type=check,values={one,two}]
%D \definefieldbody[buttonb][type=check,values={three,four}]
%D \definefieldbody[buttonc][buttona][values={three,four}]
%D \stoptyping
%D
%D Actually typesetting a field happens this way:
%D
%D \starttyping
%D \fieldbody [Email]
%D \fieldbody [Email] [width=6cm]
%D \fieldbody [eMAIL]
%D \fieldbody [eMAIL] [width=7cm]
%D
%D \fieldbody [buttona]
%D \fieldbody [buttona]
%D \fieldbody [buttonb]
%D \fieldbody [buttonb]
%D \fieldbody [buttonc]
%D \fieldbody [buttonc]
%D \stoptyping
%D
%D So, you can call up a field many times and quite some parameters can be set.
%D
%D Because there are persistent problems with acrobat rendering associated
%D appearance streams (some messy /MK interferende) we also support native (built-in
%D dingbat) symbols: check, circle, cross, diamond, square and star.
%D
%D \starttyping
%D \definefield[test1][check]
%D \definefield[test2][check]
%D
%D \fieldbody[test1][width=1em,height=\strutht,depth=\strutdp,symbol=check]
%D \fieldbody[test1][width=1em,height=\strutht,depth=\strutdp,symbol=circle]
%D \fieldbody[test2][width=1em,height=\strutht,depth=\strutdp,symbol=square]
%D \stoptyping
%D
%D When submitting a form, we need to tell the driver module that we want \FDF\ or
%D \HTML.

\installcorenamespace {forms}

\installdirectcommandhandler \??forms {forms}

\appendtoks
    \clf_setformsmethod{\formsparameter\c!method}%
\to \everysetupforms

\setupforms
  [\c!method=XML] % no need for everyjob initialization as this is the default

\mutable\let\currentfieldbackgroundcolor     \empty
\mutable\let\currentfieldbackgroundcolorvalue\empty
\mutable\let\currentfieldbodycategory        \empty
\mutable\let\currentfieldframecolor          \empty
\mutable\let\currentfieldframecolorvalue     \empty
\mutable\let\currentfieldlabel               \empty
\mutable\let\currentfieldstackname           \empty

\appendtoks
    \iflocation
      \clf_exportformdata{\formsparameter\c!export}%
    \fi
\to \everystoptext

%D We need to initialize symbols in a special way so that they can be used as
%D rendering for a widget.

\permanent\protected\def\presetfieldsymbols[#list]% slow
  {\processcommacommand[#list]\scrn_symbols_preset}

\def\scrn_symbols_preset#set%
  {\processcommalist[#set]\scrn_symbols_preset_indeed}%

\permanent\protected\def\scrn_symbols_preset_indeed#tag%
  {\doifelseobjectfound{SYM}{#tag}
     {}
     {\settightobject{SYM}{#tag}\hbox{\symbol[#tag]}%                        % todo: set this as immediate xform
      \page_otr_add_special_content{\hskip-\maxdimen\getobject{SYM}{#tag}}}} % and then force it into the file

\aliased\let\dosetfieldsymbol\scrn_symbols_preset_indeed

\permanent\def\dogetfieldsymbol#tag%
  {\getobject{SYM}{#tag}}

\permanent\protected\def\definedefaultsymbols % used ?
  {\definesymbol[defaultyes][\mathematics{\times}]%
   \definesymbol[defaultno] [\mathematics{\cdot }]}

%D Now comes the real code:

\installcorenamespace{fieldcategory}
\installcorenamespace{fieldbody}

\installcommandhandler \??fieldcategory {fieldcategory} \??fieldcategory
\installcommandhandler \??fieldbody     {fieldbody}     \??fieldbody

\newbox\b_scrn_field_body

\setupfieldcategory
  [\c!alternative=\v!normal, % normal clone copy
   \c!type=\v!line,          % line text ...
   \c!width=5em,
   \c!height=1em,
   \c!depth=\zeropoint,
   \c!align=\v!flushleft,
   \c!option=\v!printable, % maybe we need a globaloptions and marge them
   \c!n=1024]

\def\scrn_field_check_category
  {\edef\currentfieldbodycategory{\fieldbodyparameter\c!category}%
   \ifempty\currentfieldbodycategory
     \letfieldbodyparameter\s!parent\??fieldcategory
    %\setevalue{\currentfieldbodyhash\s!parent}{\namedfieldcategoryhash\empty}% to WS: not hash !
   \else
     \normalexpanded{\setfieldbodyparameter{\s!parent}{\??fieldcategory\currentfieldbodycategory}}%
    %\setevalue{\currentfieldbodyhash\s!parent}{\namedfieldcategoryhash\currentfieldbodycategory}% to WS: not hash !
   \fi}

\appendtoks % we cannot use parent .. maybe s!parent has to change
    \ifempty\currentfieldbodyparent
        \scrn_field_check_category
        \clf_definefield
            name        {\currentfieldbody}%
            alternative {normal}%
            type        {\fieldbodyparameter\c!type}%
            category    {\fieldbodyparameter\c!category}%
            values      {\fieldbodyparameter\c!values}%
            default     {\fieldbodyparameter\c!default}%
        \relax
    \else
        \clf_clonefield
            children    {\currentfieldbody}%
            alternative {clone}%
            parent      {\currentfieldbodyparent}%
            category    {\fieldbodyparameter\c!category}%
            values      {\fieldbodyparameter\c!values}%
            default     {\fieldbodyparameter\c!default}%
        \relax
    \fi
\to \everydefinefieldbody

\permanent\tolerant\protected\def\fieldbody[#tag]#spacer[#settings]%
  {\iflocation
     \hbox\bgroup
       \edef\currentfieldbody{#tag}%
       \setupcurrentfieldbody[#settings]%
       \scrn_field_body_typeset
       \box\b_scrn_field_body
       \egroup
   \fi}

\def\scrn_field_body_typeset % todo: fieldsymbol (checkfields /MK mess)
  {\edef\currentfieldframecolor{\fieldbodyparameter\c!fieldframecolor}%
   \ifempty\currentfieldframecolor\else
     \getcolorattributevalue\currentfieldframecolor\currentfieldframecolorvalue
    % == \edef\currentfieldframecolorvalue{\thecolorattribute\currentfieldframecolor}%
   \fi
   \edef\currentfieldbackgroundcolor{\fieldbodyparameter\c!fieldbackgroundcolor}%
   \ifempty\currentfieldbackgroundcolor\else
     \getcolorattributevalue\currentfieldbackgroundcolor\currentfieldbackgroundcolorvalue
    % == \edef\currentfieldbackgroundcolorvalue{\thecolorattribute\currentfieldbackgroundcolor}%
   \fi
   \usefieldbodystyleandcolor\c!style\c!color
   \clf_insertfield
     {\currentfieldbody}%
     {%
       title                {\currentfieldbody}
       width                \dimexpr\fieldbodyparameter\c!width \relax
       height               \dimexpr\fieldbodyparameter\c!height\relax
       depth                \dimexpr\fieldbodyparameter\c!depth \relax
       align                {\fieldbodyparameter\c!align}%
       length               {\fieldbodyparameter\c!n}%
       fontstyle            {\fontstyle}%
       fontalternative      {\fontalternative}%
       fontsize             {\fontbody}%
       fontsymbol           {\fieldbodyparameter\c!symbol}%
       color                {\fieldbodyparameter\c!color}%
       colorvalue           \c_attr_color
   \ifempty\currentfieldbackgroundcolor \else
       backgroundcolor      {\currentfieldbackgroundcolor}%
       backgroundcolorvalue \numexpr\currentfieldbackgroundcolorvalue\relax
   \fi
   \ifempty\currentfieldframecolor \else
       framecolor           {\currentfieldframecolor}%
       framecolorvalue      \numexpr\currentfieldframecolorvalue\relax
   \fi
       layer                {\fieldbodyparameter\c!fieldlayer}%
       option               {\fieldbodyparameter\c!option}%
       clickin              {\fieldbodyparameter\c!clickin}%
       clickout             {\fieldbodyparameter\c!clickout}%
       regionin             {\fieldbodyparameter\c!regionin}%
       regionout            {\fieldbodyparameter\c!regionout}%
       afterkey             {\fieldbodyparameter\c!afterkey}%
       format               {\fieldbodyparameter\c!format}%
       validate             {\fieldbodyparameter\c!validate}%
       calculate            {\fieldbodyparameter\c!calculate}%
       focusin              {\fieldbodyparameter\c!focusin}%
       focusout             {\fieldbodyparameter\c!focusout}%
       openpage             {\fieldbodyparameter\c!openpage}%
       closepage            {\fieldbodyparameter\c!closepage}%
      }%
    \relax}

%D The sets are used in grouped calculations.
%D
%D [name] [set]

\permanent\tolerant\protected\def\definefieldbodyset[#tag]#spacer[#list]%
  {\clf_definefieldset{#tag}{#list}}

\aliased\let\dodefinefieldset\definefieldbodyset % compatibility

%D A few testing macros (expandable for historic reasons):

\permanent\def\doifelsefieldbody    #tag{\clf_doifelsefield{#tag}}
\permanent\def\doifelsefieldcategory#tag{\clf_doifelsefieldcategory{#tag}}

\aliased\let\doiffieldbodyelse    \doifelsefieldbody
\aliased\let\doiffieldcategoryelse\doifelsefieldcategory

\aliased\let\doiffieldelse        \doifelsefieldbody % compatibility / will be dropped
\aliased\let\doifelsefield        \doifelsefieldbody % compatibility / will be dropped

%D We still support the traditional method of defining fields:
%D
%D \starttyping
%D \definefield [name] [type] [category] [values] [default]
%D
%D \definefield [WWWW] [text]  [textsetup]            [default text]
%D \definefield [XXXX] [push]  [pushsetup]  [yes,no]  [yes]
%D \definefield [XXXX] [check] [checksetup] [yes,no]  [yes]
%D \definefield [YYYY] [combo] [combosetup] [a,b,c,d] [b]
%D \definefield [ZZZZ] [radio] [radiosetup] [W,X,Y,Z] [Y]
%D
%D \definesubfield [W]   [subsetup] [p,q]
%D \definesubfield [X,Y] [subsetup] [p,r]
%D \definesubfield [Z]   [subsetup] [y,z]
%D
%D evt \definemainfield ... wanneer geplaatst voor subs gegeven
%D
%D \clonefield [XXXX] [XX,YY] [mysetup]      [on,off]
%D \clonefield [Z]    [AA,BB] [somesetup]    [true,false]
%D \clonefield [Z]    [CC,DD] [anothersetup]
%D
%D \copyfield [XXXX] [PP,QQ,RR]
%D \stoptyping
%D
%D Keep in mind that you can also use \type {\definefieldbody} to achieve the same.

\permanent\tolerant\protected\def\definefield[#tag]#spacer[#type]#spacer[#category]#spacer[#values]#spacer[#default]%
  {\definefieldbody[#tag][\c!type=#type,\c!category=#category,\c!values={#values},\c!default={#default}]}

\permanent\tolerant\protected\def\definesubfield[#tag]#spacer[#category]#spacer[#values]%
  {\definefieldbody[#tag][\c!type=sub,\c!category=#category,\c!values={#values}]}

\permanent\tolerant\protected\def\clonefield[#parent]#spacer[#tag]#spacer[#category]#spacer[#values]%
  {\definefieldbody[#tag][#parent][\c!category=#category,\c!values={#values}]}

\permanent\tolerant\protected\def\copyfield[#parent]#spacer[#tag]%
  {\definefieldbody[#tag][#parent]}

\aliased\let\definemainfield\definefield % obsolete !

%D We hook fields into the (viewer based) layering mechanism
%D (implemented as properties).

\appendtoks
    \let\currentfieldcategory\empty
    \doifelse{\interactionparameter\c!fieldlayer}\v!auto
      {\setupcurrentfieldcategory[\c!fieldlayer=\currentviewerlayer]}%
      {\setupcurrentfieldcategory[\c!fieldlayer=]}%
\to \everysetupinteraction

\setupinteraction
  [\c!fieldlayer=\v!auto] % auto by default

%D The \type {\fieldbody} is the more bare one. One step further goes \type
%D {\fitfield}, in fact it (now) uses a dedicated instance of framed: \type
%D {fitfieldframed}.
%D
%D \starttyping
%D \ruledhbox{\fieldbody[Email][height=\strutht,depth=\strutdp,style=normal]}
%D \ruledhbox{\fitfield[Email][height=\strutht,depth=\strutdp,style=normal]}
%D \ruledhbox{\fitfield[buttona]}
%D \stoptyping

\newbox\b_scrn_field_fit_symbol

\defineframed
  [fitfieldframed]
  [\c!strut=\v!no,
   \c!frame=off,
   \c!offset=\v!overlay,
   \c!align=]

\permanent\tolerant\protected\def\fitfield[#tag]#spacer[#settings]%
  {\iflocation
     \begingroup
       \setbox\b_scrn_field_fit_symbol\hbox\bgroup
         \normalexpanded{\symbol[\clf_getdefaultfieldvalue{#tag}]}%
       \egroup
       \fitfieldframed
         {\fieldbody[#tag]
            [\c!width=\wd\b_scrn_field_fit_symbol,
             \c!height=\ht\b_scrn_field_fit_symbol,
             \c!depth=\dp\b_scrn_field_fit_symbol,
             #settings]}%
     \endgroup
   \fi}

%D The traditional field command does some labeling and boxing:

\installcorenamespace{fieldlabel}
\installcorenamespace{fieldcontent}
\installcorenamespace{fieldtotal}

\installparameterhandler     \??fieldlabel   {fieldlabelframed}
\installparameterhandler     \??fieldcontent {fieldcontentframed}
\installparameterhandler     \??fieldtotal   {fieldtotalframed}

\installparametersethandler  \??fieldcontent {fieldcontentframed}

\installsetuphandler         \??fieldlabel   {fieldlabelframed}
\installsetuphandler         \??fieldcontent {fieldcontentframed}
\installsetuphandler         \??fieldtotal   {fieldtotalframed}

\installinheritedframed                      {fieldlabelframed}
\installinheritedframed                      {fieldcontentframed}
\installinheritedframed                      {fieldtotalframed}

\setupfieldcontentframed
  [\c!align=\v!flushleft,
   \c!strut=\v!no,
   \s!parent=\??regularframed] % needs checking

\setupfieldcontentframed % independent
  [\c!alternative=\v!normal,
   \c!type=\v!line,
   \c!width=5em,
   \c!height=\lineheight,
   \c!depth=\zeropoint,
   \c!align=\v!flushleft,
   \c!option=\v!printable,
   \c!n=1024]

\setupfieldlabelframed
  [\c!style=,
   \c!color=,
   \c!align=\v!flushleft,
   \s!parent=\??regularframed] % needs checking

\setupfieldtotalframed
  [%\c!alternative={\v!label,\v!frame,\v!horizontal},
   \c!strut=\v!no,
   \c!align=,
   \s!parent=\??regularframed] % needs checking

% \setupcurrent

\permanent\tolerant\protected\def\setupfield[#tag]#spacer[#variant]#spacer[#totalsettings]#spacer[#labelsettings]#spacer[#fieldsettings]%
  {\ifarguments\or\or
     \definefieldcategory[#tag][\s!parent=\??fieldcontent#tag,#variant]%
     \setupfieldtotalframed  [#tag][\s!parent=\??fieldtotal]%
     \setupfieldlabelframed  [#tag][\s!parent=\??fieldlabel]%
     \setupfieldcontentframed[#tag][\s!parent=\??fieldcontent,#variant]%
   \or
     \definefieldcategory[#tag][\s!parent=\??fieldcontent#tag,#totalsettings]%
     \setupfieldtotalframed  [#tag][\s!parent=\??fieldtotal,\c!alternative={#variant}]%
     \setupfieldlabelframed  [#tag][\s!parent=\??fieldlabel]%
     \setupfieldcontentframed[#tag][\s!parent=\??fieldcontent,#totalsettings]%
   \or
     \definefieldcategory[#tag][\s!parent=\??fieldcontent#tag,#labelsettings]%
     \setupfieldtotalframed  [#tag][\s!parent=\??fieldtotal,\c!alternative={#variant},#totalsettings]%
     \setupfieldlabelframed  [#tag][\s!parent=\??fieldlabel]%
     \setupfieldcontentframed[#tag][\s!parent=\??fieldcontent,#labelsettings]%
   \or
     \definefieldcategory[#tag][\s!parent=\??fieldcontent#tag,#fieldsettings]%
     \setupfieldtotalframed  [#tag][\s!parent=\??fieldtotal,\c!alternative={#variant},#totalsettings]%
     \setupfieldlabelframed  [#tag][\s!parent=\??fieldlabel,#labelsettings]%
     \setupfieldcontentframed[#tag][\s!parent=\??fieldcontent,#fieldsettings]%
   \fi}

\permanent\tolerant\protected\def\setupfields[#variant]#spacer[#totalsettings]#spacer[#labelsettings]#spacer[#fieldsettings]%
  {\ifarguments\or
     \setupfieldtotalframed  [#variant]%
   \or
     \setupfieldtotalframed  [#variant]%
     \setupfieldcontentframed[#totalsettings]%
   \or
     \setupfieldtotalframed  [#variant]%
     \setupfieldlabelframed  [#totalsettings]%
     \setupfieldcontentframed[#labelsettings]%
   \or
     \setupfieldtotalframed  [\c!alternative={#variant},#totalsettings]%
     \setupfieldlabelframed  [#labelsettings]%
     \setupfieldcontentframed[#fieldsettings]%
   \fi}

% just to get the chain right for no category:

\definefieldcategory    [][\s!parent=\??fieldcontent]
%setupfieldtotalframed  [][\s!parent=\??fieldtotal]
%setupfieldlabelframed  [][\s!parent=\??fieldlabel]
%setupfieldcontentframed[][\s!parent=\??fieldcontent]

% no longer supported:

% \let\resetfields\relax

\def\scrn_field_load_scripts{\useJSscripts[fld]\glet\scrn_field_load_scripts\relax}

\newconditional\fieldlabelshown
\newconditional\fieldframeshown
\newconditional\fieldisvertical
\newconditional\fieldishorizontal

\mutable\let\currentfieldtotalframed  \empty
\mutable\let\currentfieldlabelframed  \empty
\mutable\let\currentfieldcontentframed\empty

\mutable\let\fieldtotalframedparameterhash  \empty % weird that we have to flag this
\mutable\let\fieldlabelframedparameterhash  \empty % idem
\mutable\let\fieldcontentframedparameterhash\empty % idem

\permanent\tolerant\protected\def\field[#tag]#spacer[#label]% can be sped up with \setupcurrentfieldtotalframed etc
  {\iflocation
     \dontleavehmode
     \begingroup
     \scrn_field_load_scripts
     \edef\currentfieldbody    {#tag}%
     \edef\currentfieldlabel   {#label}%
     \edef\currentfieldcategory{\clf_getfieldcategory{#tag}}%
     \ifempty\currentfieldlabel
       \let\currentfieldlabel\currentfieldbody
     \fi
     \ifempty\currentfieldcategory
       \setupfieldtotalframed  [\currentfieldbody][\s!parent=\??fieldtotal]%
       \setupfieldlabelframed  [\currentfieldbody][\s!parent=\??fieldlabel]%
       \setupfieldcontentframed[\currentfieldbody][\s!parent=\??fieldcontent]%
       \definefieldcategory    [\currentfieldbody]%
       \setupfieldbody         [\currentfieldbody][\c!category=\currentfieldbody]%
       \let\currentfieldcategory\currentfieldbody
     \fi
     \let\currentfieldtotalframed  \currentfieldcategory
     \let\currentfieldlabelframed  \currentfieldcategory
     \let\currentfieldcontentframed\currentfieldcategory
     \scrn_field_analyze_setups
     \ifconditional\fieldframeshown
       \inheritedfieldtotalframedframed % lower framedoffset
       \bgroup
     \else
       \vbox
       \bgroup
     \fi
     \dontcomplain
     \ifconditional\fieldlabelshown
       \scrn_field_set_label_box
     \fi
     \scrn_field_set_content_box
     \ifconditional\fieldlabelshown
       \ifconditional\fieldisvertical
         \scrn_field_flush_vertical
       \else
         \scrn_field_flush_horizontal
       \fi
     \else
       \scrn_field_flush_content
     \fi
     \egroup
     \endgroup
   \fi}

% opties: veld, label, kader, vertikaal/horizontaal

\newbox\b_scrn_field_label
\newbox\b_scrn_field_content

% lower framedoffset

\def\scrn_field_set_label_box
  {\setbox\b_scrn_field_label\hbox
      {\reshapeframeboxtrue % else wrong dimensions % still needed?
       \inheritedfieldlabelframedframed{\currentfieldlabel}}}

% \c!fieldoffset=-\framedoffset,\c!fieldbackgroundcolor=,
% \hbox{\lower\@@fdfieldoffset\hbox{\typesetfield}}

\def\scrn_field_set_content_box
  {\setbox\b_scrn_field_content\hbox
     {\reshapeframeboxtrue % else wrong dimensions (to be checked)
      \doifnothing{\fieldcontentframedparameter\c!height}
        {\ifconditional\fieldisvertical
           \setfieldcontentframedparameter\c!height{6ex}%
         \orelse\ifconditional\fieldishorizontal
           \setfieldcontentframedparameter\c!height{\vsize}%
         \else
           \setfieldcontentframedparameter\c!height{2cm}%
         \fi}%
      \doifnothing{\fieldcontentframedparameter\c!width}
        {\ifconditional\fieldisvertical
           \setfieldcontentframedparameter\c!width{\hsize}%
         \orelse\ifconditional\fieldishorizontal
           \setfieldcontentframedparameter\c!width{20em}%
         \else
           \setfieldcontentframedparameter\c!width{2cm}%
         \fi}%
      \inheritedfieldcontentframedframed % lower framedoffset
        {\fieldbody
           [\currentfieldbody]
           [\c!width=\framedwidth,\c!height=\framedheight]}}}


\def\scrn_field_flush_vertical
  {\vbox
     {\copy\b_scrn_field_label
      \fieldtotalframedparameter\c!inbetween
      \copy\b_scrn_field_content}}

\def\scrn_field_flush_horizontal
   {\hbox
      {\vbox \ifdim\ht\b_scrn_field_content>\ht\b_scrn_field_label to \ht\b_scrn_field_content \fi
         {\fieldtotalframedparameter\c!before
          \copy\b_scrn_field_label
          \fieldtotalframedparameter\c!after}%
       \hskip\fieldtotalframedparameter\c!distance
       \vbox \ifdim\ht\b_scrn_field_label>\ht\b_scrn_field_content to \ht\b_scrn_field_label \fi
         {\fieldtotalframedparameter\c!before
          \box\b_scrn_field_content
          \fieldtotalframedparameter\c!after}}}

\def\scrn_field_flush_content
  {\box\b_scrn_field_content}

%D todo: replace \processallactionsinset

\def\scrn_field_analyze_setups
  {\setfalse\fieldlabelshown
   \setfalse\fieldframeshown
   \setfalse\fieldishorizontal
   \setfalse\fieldisvertical
   \normalexpanded{\processallactionsinset[\fieldtotalframedparameter\c!alternative]}
     [      \v!reset=>\setfalse\fieldlabelshown
                      \setfalse\fieldframeshown
                      \setfalse\fieldishorizontal
                      \setfalse\fieldisvertical,
            \v!label=>\settrue\fieldlabelshown,
            \v!frame=>\settrue\fieldframeshown,
       \v!horizontal=>\settrue\fieldishorizontal,
         \v!vertical=>\settrue\fieldisvertical]%
   \ifconditional\fieldisvertical
     \setupfieldtotalframed[\c!distance=\zeropoint,\c!inbetween=\vskip\d_framed_local_offset,\c!align=\v!right,\c!width=20em]%
   \orelse\ifconditional\fieldishorizontal
     \setupfieldtotalframed[\c!distance=\d_framed_local_offset,\c!inbetween=,\c!align=\c!left,\c!height=10ex]%
   \else
     \setupfieldtotalframed[\c!distance=\zeropoint,\c!inbetween=,\c!align=\c!left]%
   \fi
   \setupfieldtotalframed[\c!n=,\c!before=,\c!after=\vss,\c!style=,\c!color=]}

%D Common stuff (obsolete)

\newcount\c_scrn_field_system_n

\permanent\def\currentsystemfield{sys::\number\c_scrn_field_system_n}

\permanent\protected\def\nextsystemfield
  {\global\advance\c_scrn_field_system_n\plusone}

%D \CONTEXT\ had tooltips right from the moment that it supported fields. Due to the
%D at that moment somewhat limited \PDF\ specification, they were implemented using
%D \JAVASCRIPT, but nowadays more kind of actions are supported, so we can do
%D without. The \MKIV\ version also supports definition of tooltips and
%D configuration.
%D
%D \starttyping
%D before \tooltip[right]{inbetween}{a very nice tip} after\par
%D before \tooltip[align=normal]{inbetween}{a very\\nice tip} after\par
%D before \tooltip[middle]{inbetween}{a very nice tip} after\par
%D before \tooltip[left]{inbetween}{a very nice tip} after\par
%D \stoptyping

\newbox  \b_scrn_tooltip_anchor
\newbox  \b_scrn_tooltip_text
\newcount\c_scrn_tooltip_n

\installcorenamespace{tooltip}

\installframedcommandhandler \??tooltip {tooltip} \??tooltip

\setuptooltip
  [\c!location=\v!right,
   \c!frame=\v!off,
   \c!offset=.1ex,
   \c!background=\v!color,
   \c!backgroundcolor=gray]

\appendtoks
    \frozen\instance\setuevalue\currenttooltip{\scrn_tooltip_direct{\currenttooltip}}%
\to \everydefinetooltip

\protected\def\scrn_tooltip_direct#tag%
  {\def\currenttooltip{#tag}%
   \iflocation
     \expandafter\scrn_tooltip_indeed
   \else
     \expandafter\scrn_tooltip_ignore
   \fi}

\tolerant\def\scrn_tooltip_ignore[#settings]#:#anchortext#tiptext%
  {#anchortext}

\mutable\let\currenttooltipname\empty

\tolerant\def\scrn_tooltip_indeed[#settings]#:#anchortext#tiptext% a more modern aproach (push buttons)
  {\dontleavehmode \hbox \bgroup
     \dontcomplain
     \global\advance\c_scrn_tooltip_n\plusone
     \edef\currenttooltipname{tooltip:\number\c_scrn_tooltip_n}%
     \setbox\b_scrn_tooltip_anchor\hbox
       {\strut#anchortext}%
     \doifelseassignment{#settings}
       {\setupcurrenttooltip[#settings]}%
       {\setupcurrenttooltip[\c!location=#settings]}%
     \setbox\b_scrn_tooltip_text\hbox
       {\lettooltipparameter\c!location\empty
        \inheritedtooltipframed{#tiptext}}%
     \definesymbol
       [\currenttooltipname:txt]
       [\copy\b_scrn_tooltip_text]%
     \definefieldbody
       [\currenttooltipname:txt]
       [\c!type=push,
        \c!width=\wd\b_scrn_tooltip_text,
        \c!height=\ht\b_scrn_tooltip_text,
        \c!depth=\dp\b_scrn_tooltip_text,
        \c!option=\v!hidden,
        \c!values=\currenttooltipname:txt]%
     \setbox\b_scrn_tooltip_text\hbox
       {\fieldbody[\currenttooltipname:txt]}%
     \setbox\b_scrn_tooltip_text\hbox
       {\strut\lower\dimexpr.25ex+\ht\b_scrn_tooltip_text\relax\box\b_scrn_tooltip_text}%
     \edef\p_location{\tooltipparameter\c!location}%
     \ifx\p_location\v!left
       \hsmashed{\hskip\wd\b_scrn_tooltip_anchor\llap{\box\b_scrn_tooltip_text}}%
     \orelse\ifx\p_location\v!middle
       \hsmashed to \wd\b_scrn_tooltip_anchor{\hss\box\b_scrn_tooltip_text\hss}%
     \else
       \hsmashed{\box\b_scrn_tooltip_text}%
     \fi
     \definesymbol
       [\currenttooltipname:but]
       [\hphantom{\copy\b_scrn_tooltip_anchor}]%
     \definefieldbody
       [\currenttooltipname:but]
       [\c!type=push,
        \c!regionin=action(show{\currenttooltipname:txt}),
        \c!regionout=action(hide{\currenttooltipname:txt}),
        \c!width=\wd\b_scrn_tooltip_anchor,
        \c!height=\ht\b_scrn_tooltip_anchor,
        \c!depth=\dp\b_scrn_tooltip_anchor]%
     \hsmashed{\fieldbody[\currenttooltipname:but]}%
   \egroup
   #anchortext}% when hyphenated the text wil stick out ... such are fields and we cannot use a link here

\definetooltip[tooltip]

%D From messages on the mailing list we can conclude that fieldstacks are used so we
%D keep them in the core:
%D
%D \starttyping
%D \definesymbol[one]  [one]
%D \definesymbol[two]  [two]
%D \definesymbol[three][three]
%D
%D \definefieldstack[mine][one,two,three]
%D \fieldstack[mine]
%D \fieldstack[mine]
%D
%D \goto{walk field}[Walk{mine}]
%D \stoptyping

% todo: expand #symbols

\installcorenamespace {fieldstack}

\permanent\tolerant\protected\def\definefieldstack[#tag]#spacer[#symbols]#spacer[#settings]%
  {\ifcsname\??fieldstack#tag\endcsname
     % already done
   \else
     %setgvalue{\??fieldstack#tag}{\scrn_fieldstack_construct[#tag][#symbols][#settings]}%
     \setxvalue{\??fieldstack#tag}{\scrn_fieldstack_construct[#tag][#symbols][\normalunexpanded{#settings}]}%
   \fi}

\permanent\tolerant\protected\def\fieldstack[#tag]#spacer[#symbols]#spacer[#settings]%
  {\ifparameter#symbols\or
     \definefieldstack[#tag][#symbols][#settings]%
   \fi
   \csname\??fieldstack#tag\endcsname}

\newbox\b_scrn_fieldstack_box

\definesymbol[\s!empty][]

\def\scrn_fieldstack_add#tag#settings#symbol%
  {\advance\scratchcounter\plusone
   \edef\currentfieldstackname{#tag:\number\scratchcounter}%
   \ifnum\scratchcounter=\fieldcategoryparameter\c!start\relax
     \definefieldbody[\currentfieldstackname][\c!type=check,\c!values={#symbol,\s!empty},\c!default={#symbol}]%
   \else
     \definefieldbody[\currentfieldstackname][\c!type=check,\c!values={#symbol,\s!empty},\c!default=\s!empty]%
   \fi
   \setbox\b_scrn_fieldstack_box\hbox{\symbol[#symbol]}%
   \setcollector
     [fieldstack]
     {\fieldbody
        [\currentfieldstackname]
        [\c!option={\v!readonly},
         \c!width=\wd\b_scrn_fieldstack_box,
         \c!height=\ht\b_scrn_fieldstack_box,
         \c!depth=\dp\b_scrn_fieldstack_box,
         #settings]}}

\protected\def\scrn_fieldstack_construct[#tag][#symbols][#settings]% start=n, 0 == leeg
  {\iflocation
     \dontleavehmode
     \begingroup
     \setupfieldcategory[\c!start=1,#settings]% was just \??fieldcategory
     \scrn_field_load_scripts
     \definecollector
       [fieldstack]%
       [\c!corner=\v!middle,
        \c!location=\v!middle]%
     \scratchcounter\zerocount
     \processcommalist[#symbols]{\scrn_fieldstack_add{#tag}{#settings}}%
     \flushcollector[fieldstack]%
     \endgroup
   \fi}

%D Another goodie. Two actions can be hookes into an overlay.
%D
%D \starttyping
%D \defineviewerlayer[test]
%D
%D \startviewerlayer[test]Hide Me\stopviewerlayer
%D
%D \defineoverlay
%D   [WithTest]
%D   [{\overlayrollbutton[HideLayer{test}][VideLayer{test}]}]
%D
%D \framed[background=WithTest]{toggle}
%D \stoptyping

\newcount\c_scrn_rollbutton_n

\permanent\tolerant\protected\def\overlayrollbutton[#1]#*[#2]#;#=#=%
  {\iflocation
     \bgroup
     \global\advance\c_scrn_rollbutton_n_button\plusone
     \global\advance\c_scrn_rollbutton_n_symbol\plusone
     \definesymbol
       [rollsymbol:\number\c_scrn_rollbutton_n_symbol]
       [{\framed[\c!frame=\v!off,\c!width=\overlaywidth,\c!height=\overlayheight]{}}]%
   % \definefieldbody
   %   [rollbutton:\number\c_scrn_rollbutton_n_button]
   %   [\c!type=push,
   %    \c!values=rollsymbol:\number\c_scrn_rollbutton_n_symbol,
   %    \c!default=rollsymbol:\number\c_scrn_rollbutton_n_symbol]%
   % \fitfield
   %   [rollbutton:\number\c_scrn_rollbutton_n_button]%
   %   [\c!regionin={#regionin},
   %    \c!regionout={#regionout}]%
     %
     \definefield
       [rollbutton:\number\c_scrn_rollbutton_n_button][push][rollbutton]
       [rollsymbol:\number\c_scrn_rollbutton_n_symbol]%
     \fitfield
       [rollbutton:\number\c_scrn_rollbutton_n_button]%
       [\c!regionin={#1#3},\c!regionout={#2#4}]%
     %
     \egroup
   \fi}

% \protect \endinput % THE FOLLOWING CODE IS NOT CHECKED

%D I will redo these when I need them.

% \setupinteraction[state=start]
%
% \definepushbutton [reset]
%
% \startuniqueMPgraphic{whatever}{color}
%     fill fullcircle xysized (OverlayWidth,OverlayHeight) withcolor \MPvar{color} ;
% \stopuniqueMPgraphic
%
% \definepushsymbol [reset] [n] [\uniqueMPgraphic{whatever}{color=red}]
% \definepushsymbol [reset] [r] [\uniqueMPgraphic{whatever}{color=green}]
% \definepushsymbol [reset] [d] [\uniqueMPgraphic{whatever}{color=blue}]
%
% \starttext
%     \startTEXpage
%         \pushbutton [reset] [page(2)]
%     \stopTEXpage
%     \startTEXpage
%         \pushbutton [reset] [page(1)]
%     \stopTEXpage
% \stoptext

\newcount\c_scrn_pushbutton_n

\permanent\tolerant\protected\def\definepushbutton[#tag]#spacer[#settings]%
  {\scrn_pushbutton_define_variant{#tag}{n}{push}%
   \scrn_pushbutton_define_variant{#tag}{r}{\symbol[pushsymbol:#tag:n]}%
   \scrn_pushbutton_define_variant{#tag}{d}{\symbol[pushsymbol:#tag:r]}%
   \setvalue{pushbutton:#tag}{\scrn_pushbutton_handle{#tag}{#settings}}}

\def\scrn_pushbutton_define_variant#tag#variant#content%
  {\doifelsesymboldefined{pushsymbol:#tag:#variant}
     \donothing
     {\definesymbol[pushsymbol:#tag:#variant][{#content}]}}

\def\scrn_pushbutton_handle#tag#settings#reference%
  {\bgroup
   \global\advance\c_scrn_pushbutton_n\plusone
   \setupfield
     [pushbutton]%
     [\c!frame=\v!overlay,%
      \c!offset=\v!overlay,%
      \c!clickout={#reference},%
      #settings]%
   \definefield
     [pushbutton:\number\c_scrn_pushbutton_n]%
     [push]%
     [pushbutton]%
     [pushsymbol:#tag:n,pushsymbol:#tag:r,pushsymbol:#tag:d]%
   \fitfield
     [pushbutton:\number\c_scrn_pushbutton_n]%
   \egroup}

\permanent\tolerant\protected\def\definepushsymbol[#tag]#spacer[#variant]% [#reference]
  {\definesymbol[pushsymbol:#tag:#variant]}

\permanent\tolerant\def\pushbutton[#tag]#spacer[#variant]%
  {\executeifdefined{pushbutton:#tag}\gobbleoneargument{#variant}}

%D We plug into the menu system

\permanent\permanent\protected\def\scrn_menu_psh_start[#reference]#text\stoppsh
  {\starttxt\pushbutton[\currentinteractionmenu][#reference]\stoptxt}

\permanent\permanent\protected\def\scrn_menu_psh_direct[#reference]#text\\
  {\scrn_menu_psh_start[#reference]\stoprob}

\aliased\let\startpsh\relax % maybe mutable
\aliased\let\stoppsh \relax % maybe mutable
\aliased\let\psh     \relax % maybe mutable

\appendtoks
    \enforced\let\startpsh\scrn_menu_psh_start
    \enforced\let\stoppsh \relax
    \enforced\let\psh     \scrn_menu_psh_direct
\to \everysetmenucommands

%D Another goodie: (unchecked in \MKIV)

% calls:
%              {..} [JS..]
% [left]       {..} [JS..]
%        [a=b] {..} [JS..]
% [left] [a=b] {..} [JS..]
%
% \setupbuttons[offset=0pt,frame=off] % alternative=hidden
%
% \rollbutton {Manuals}       [JS(Goto_File{show-man.pdf})]
% \rollbutton {Articles}      [JS(Goto_File{show-art.pdf})]
% \rollbutton {Papers}        [JS(Goto_File{show-pap.pdf})]
% \rollbutton {Presentations} [JS(Goto_File{show-pre.pdf})]
% \rollbutton {Resources}     [JS(Goto_File{show-res.pdf})]
%
% \rob [JS(...)] bla bla \\

% \definecolor[rollover:n][red]
% \definecolor[rollover:r][green]
% \definecolor[rollover:d][blue]

\definepalet
  [rollover]
  [n=red,
   r=green,
   d=blue]

\newcount\c_scrn_rollbutton_n_button
\newcount\c_scrn_rollbutton_n_symbol

\permanent\def\lastrollbuttonindex{\the\c_scrn_rollbutton_n_button}

\setupfield
  [rollbutton]
  [\c!frame=\v!off,
   \c!offset=\v!overlay]

\let\scrn_rollbutton_symbol\relax

\def\scrn_rollbutton_symbol_m
  {\scrn_rollbutton_symbol_indeed
     \interactionmenuparameter
     \inheritedinteractionmenuframed
     \setinteractionmenuparameter
     \useinteractionmenustyleandcolor}

\def\scrn_rollbutton_symbol_b
  {\scrn_rollbutton_symbol_indeed
     \buttonparameter
     \inheritedbuttonframed
     \setbuttonparameter
     \usebuttonstyleandcolor}

\permanent\tolerant\protected\def\rollbutton[#tag]#spacer[#settings]#:#text[#reference]%
  {\dontleavehmode
   \bgroup
   \global\advance\c_scrn_rollbutton_n_button\plusone
   \global\advance\c_scrn_rollbutton_n_symbol\plusone
   \ifparameter#tag\or
     \ifparameter#settings\or
       \edef\currentinteractionmenu{#tag}%
       \setupcurrentinteractionmenu[#settings]%
       \let\scrn_rollbutton_symbol\scrn_rollbutton_symbol_m
     \orelse\ifhastok={#tag}%
       \let\currentbutton\empty
       \setupcurrentbutton[#tag]%
       \let\scrn_rollbutton_symbol\scrn_rollbutton_symbol_b
     \else
       \edef\currentinteractionmenu{#tag}%
       \let\scrn_rollbutton_symbol\scrn_rollbutton_symbol_m
     \fi
   \else
     \let\scrn_rollbutton_symbol\scrn_rollbutton_symbol_b
   \fi
   % todo: share symbols, tricky since different dimensions (maybe \unique...)
   \definesymbol[rollsymbol:\number\c_scrn_rollbutton_n_symbol:n][\scrn_rollbutton_symbol{n}{#text}]%
   \definesymbol[rollsymbol:\number\c_scrn_rollbutton_n_symbol:r][\scrn_rollbutton_symbol{r}{#text}]%
   \definesymbol[rollsymbol:\number\c_scrn_rollbutton_n_symbol:d][\scrn_rollbutton_symbol{d}{#text}]%
   \definefield
     [rollbutton:\number\c_scrn_rollbutton_n_button][push][rollbutton]
     [rollsymbol:\number\c_scrn_rollbutton_n_symbol:n,%
      rollsymbol:\number\c_scrn_rollbutton_n_symbol:r,%
      rollsymbol:\number\c_scrn_rollbutton_n_symbol:d]%
   \fitfield
     [rollbutton:\number\c_scrn_rollbutton_n_button]%
     [\c!clickout={#reference}]%
   \egroup}

\protected\def\scrn_rollbutton_symbol_indeed#getparameter#inheritedframed#setparameter#usestyleandcolor#what#text%
  {\definecolor[rollover][rollover:#what]%
   \doifelse{#what}{n}% ?
     {\doifelse{#getparameter\c!alternative}\v!hidden\phantom\hbox}\hbox
        {#setparameter\c!framecolor     {rollover}%
         #setparameter\c!backgroundcolor{rollover}%
         #setparameter\c!color          {rollover}%
         #inheritedframed{#usestyleandcolor\c!style\c!color{#text}}}}

%D We plug into the menu system

\permanent\protected\def\scrn_menu_rob_start[#reference]#text\stoprob
  {\starttxt\rollbutton[\currentinteractionmenu]{\ignorespaces#text\unskip}[#reference]\stoptxt}

\permanent\protected\def\scrn_menu_rob_direct[#reference]#text\\
  {\scrn_menu_rob_start[#reference]#text\stoprob}

\aliased\let\startrob\relax % maybe mutable
\aliased\let\stoprob \relax % maybe mutable
\aliased\let\rob     \relax % maybe mutable

\appendtoks
    \enforced\let\startrob\scrn_menu_rob_start
    \enforced\let\stoprob \relax
    \enforced\let\rob     \scrn_menu_rob_direct
\to \everysetmenucommands

\protect \endinput