scrn-fld.mklx /size: 37 Kb    last modification: 2024-01-16 09:03
1%D \module
2%D   [       file=scrn-fld,
3%D        version=1997.05.18,
4%D          title=\CONTEXT\ Screen Macros,
5%D       subtitle=Fields,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14%D There is still some leftover code from mkii, where we need to be sparse with hash
15%D entries and so have a somewhat complex setup mechanism. It doesn't pay off to
16%D waste time on improving this because one never knows what happens with widgets
17%D in \PDF; it has a history of dropping features like this. Also, the implementation
18%D of fields fluctuates with versions.
19
20% interaction checking
21
22\writestatus{loading}{ConTeXt Screen Macros / Fields}
23
24\unprotect
25
26\registerctxluafile{scrn-fld}{}
27
28%D In \MKII\ we had to cheat a bit with setups in order not to run out of memory
29%D with thousands of fields, which we happen to need at that time. In \MKIV\ we can
30%D store some data at the \LUA\ end and use a somewhat slower but quite okay
31%D inheritance mechanism. For this reason we now have split definitions, although
32%D the old method is still somewhat supported. The clone and copy commands are
33%D somewhat obsolete for several reasons: we can now use inheritance and autocloning
34%D has been supported for a while. In most cases cloning (especially with check
35%D boxes) the acrobat browser is not stable enough with respect to appearance
36%D handling.
37%D
38%D A fieldcategory is nothing more than a collection of settings.
39%D
40%D \starttyping
41%D \definefieldcategory
42%D   [all-email]
43%D   [height=1cm,
44%D    width=14cm,
45%D    style=sstf]
46%D \stoptyping
47%D
48%D A definition can refer to this category:
49%D
50%D \starttyping
51%D \definefieldbody [email] [type=line,category=all-email,default=pragma@xs4all.nl]
52%D \stoptyping
53%D
54%D A copy of a field is made as follows:
55%D
56%D \starttyping
57%D \definefieldbody [xmail] [email]
58%D \stoptyping
59%D
60%D You can also be more specific:
61%D
62%D \starttyping
63%D \definefieldbody[buttona][type=check,values={one,two}]
64%D \definefieldbody[buttonb][type=check,values={three,four}]
65%D \definefieldbody[buttonc][buttona][values={three,four}]
66%D \stoptyping
67%D
68%D Actually typesetting a field happens this way:
69%D
70%D \starttyping
71%D \fieldbody [Email]
72%D \fieldbody [Email] [width=6cm]
73%D \fieldbody [eMAIL]
74%D \fieldbody [eMAIL] [width=7cm]
75%D
76%D \fieldbody [buttona]
77%D \fieldbody [buttona]
78%D \fieldbody [buttonb]
79%D \fieldbody [buttonb]
80%D \fieldbody [buttonc]
81%D \fieldbody [buttonc]
82%D \stoptyping
83%D
84%D So, you can call up a field many times and quite some parameters can be set.
85%D
86%D Because there are persistent problems with acrobat rendering associated
87%D appearance streams (some messy /MK interferende) we also support native (built-in
88%D dingbat) symbols: check, circle, cross, diamond, square and star.
89%D
90%D \starttyping
91%D \definefield[test1][check]
92%D \definefield[test2][check]
93%D
94%D \fieldbody[test1][width=1em,height=\strutht,depth=\strutdp,symbol=check]
95%D \fieldbody[test1][width=1em,height=\strutht,depth=\strutdp,symbol=circle]
96%D \fieldbody[test2][width=1em,height=\strutht,depth=\strutdp,symbol=square]
97%D \stoptyping
98%D
99%D When submitting a form, we need to tell the driver module that we want \FDF\ or
100%D \HTML.
101
102\installcorenamespace {forms}
103
104\installdirectcommandhandler \??forms {forms}
105
106\appendtoks
107    \clf_setformsmethod{\formsparameter\c!method}%
108\to \everysetupforms
109
110\setupforms
111  [\c!method=XML] % no need for everyjob initialization as this is the default
112
113\mutable\lettonothing\currentfieldbackgroundcolor
114\mutable\lettonothing\currentfieldbackgroundcolorvalue
115\mutable\lettonothing\currentfieldbodycategory
116\mutable\lettonothing\currentfieldframecolor
117\mutable\lettonothing\currentfieldframecolorvalue
118\mutable\lettonothing\currentfieldlabel
119\mutable\lettonothing\currentfieldstackname
120
121\appendtoks
122    \iflocation
123      \clf_exportformdata{\formsparameter\c!export}%
124    \fi
125\to \everystoptext
126
127%D We need to initialize symbols in a special way so that they can be used as
128%D rendering for a widget.
129
130\permanent\protected\def\presetfieldsymbols[#list]% slow
131  {\processcommacommand[#list]\scrn_symbols_preset}
132
133\def\scrn_symbols_preset#set%
134  {\processcommalist[#set]\scrn_symbols_preset_indeed}%
135
136\permanent\protected\def\scrn_symbols_preset_indeed#tag%
137  {\doifelseobjectfound{SYM}{#tag}
138     {}
139     {\settightobject{SYM}{#tag}\hbox{\symbol[#tag]}%                        % todo: set this as immediate xform
140      \page_otr_add_special_content{\hskip-\maxdimen\getobject{SYM}{#tag}}}} % and then force it into the file
141
142\aliased\let\dosetfieldsymbol\scrn_symbols_preset_indeed
143
144\permanent\def\dogetfieldsymbol#tag%
145  {\getobject{SYM}{#tag}}
146
147\permanent\protected\def\definedefaultsymbols % used ?
148  {\definesymbol[defaultyes][\mathematics{\times}]%
149   \definesymbol[defaultno] [\mathematics{\cdot }]}
150
151%D Now comes the real code:
152
153\installcorenamespace{fieldcategory}
154\installcorenamespace{fieldbody}
155
156\installcommandhandler \??fieldcategory {fieldcategory} \??fieldcategory
157\installcommandhandler \??fieldbody     {fieldbody}     \??fieldbody
158
159\newbox\b_scrn_field_body
160
161\setupfieldcategory
162  [\c!alternative=\v!normal, % normal clone copy
163   \c!type=\v!line,          % line text ...
164   \c!width=5em,
165   \c!height=1em,
166   \c!depth=\zeropoint,
167   \c!align=\v!flushleft,
168   \c!option=\v!printable, % maybe we need a globaloptions and marge them
169   \c!n=1024]
170
171\def\scrn_field_check_category
172  {\edef\currentfieldbodycategory{\fieldbodyparameter\c!category}%
173   \ifempty\currentfieldbodycategory
174     \letfieldbodyparameter\s!parent\??fieldcategory
175    %\setevalue{\currentfieldbodyhash\s!parent}{\namedfieldcategoryhash\empty}% to WS: not hash !
176   \else
177     \normalexpanded{\setfieldbodyparameter{\s!parent}{\??fieldcategory\currentfieldbodycategory}}%
178    %\setevalue{\currentfieldbodyhash\s!parent}{\namedfieldcategoryhash\currentfieldbodycategory}% to WS: not hash !
179   \fi}
180
181\appendtoks % we cannot use parent .. maybe s!parent has to change
182    \ifempty\currentfieldbodyparent
183        \scrn_field_check_category
184        \clf_definefield
185            name        {\currentfieldbody}%
186            alternative {normal}%
187            type        {\fieldbodyparameter\c!type}%
188            category    {\fieldbodyparameter\c!category}%
189            values      {\fieldbodyparameter\c!values}%
190            default     {\fieldbodyparameter\c!default}%
191        \relax
192    \else
193        \clf_clonefield
194            children    {\currentfieldbody}%
195            alternative {clone}%
196            parent      {\currentfieldbodyparent}%
197            category    {\fieldbodyparameter\c!category}%
198            values      {\fieldbodyparameter\c!values}%
199            default     {\fieldbodyparameter\c!default}%
200        \relax
201    \fi
202\to \everydefinefieldbody
203
204\permanent\tolerant\protected\def\fieldbody[#tag]#spacer[#S#settings]%
205  {\iflocation
206     \hbox\bgroup
207       \edef\currentfieldbody{#tag}%
208       \setupcurrentfieldbody[#settings]%
209       \scrn_field_body_typeset
210       \box\b_scrn_field_body
211       \egroup
212   \fi}
213
214\def\scrn_field_body_typeset % todo: fieldsymbol (checkfields /MK mess)
215  {\edef\currentfieldframecolor{\fieldbodyparameter\c!fieldframecolor}%
216   \ifempty\currentfieldframecolor\else
217     \getcolorattributevalue\currentfieldframecolor\currentfieldframecolorvalue
218    % == \edef\currentfieldframecolorvalue{\thecolorattribute\currentfieldframecolor}%
219   \fi
220   \edef\currentfieldbackgroundcolor{\fieldbodyparameter\c!fieldbackgroundcolor}%
221   \ifempty\currentfieldbackgroundcolor\else
222     \getcolorattributevalue\currentfieldbackgroundcolor\currentfieldbackgroundcolorvalue
223    % == \edef\currentfieldbackgroundcolorvalue{\thecolorattribute\currentfieldbackgroundcolor}%
224   \fi
225   \usefieldbodystyleandcolor\c!style\c!color
226   \clf_insertfield
227     {\currentfieldbody}%
228     {%
229       title                {\currentfieldbody}
230       width                \dimexpr\fieldbodyparameter\c!width \relax
231       height               \dimexpr\fieldbodyparameter\c!height\relax
232       depth                \dimexpr\fieldbodyparameter\c!depth \relax
233       align                {\fieldbodyparameter\c!align}%
234       length               {\fieldbodyparameter\c!n}%
235       fontstyle            {\fontstyle}%
236       fontalternative      {\fontalternative}%
237       fontsize             {\fontbody}%
238       fontsymbol           {\fieldbodyparameter\c!symbol}%
239       color                {\fieldbodyparameter\c!color}%
240       colorvalue           \c_attr_color
241   \ifempty\currentfieldbackgroundcolor \else
242       backgroundcolor      {\currentfieldbackgroundcolor}%
243       backgroundcolorvalue \numexpr\currentfieldbackgroundcolorvalue\relax
244   \fi
245   \ifempty\currentfieldframecolor \else
246       framecolor           {\currentfieldframecolor}%
247       framecolorvalue      \numexpr\currentfieldframecolorvalue\relax
248   \fi
249       layer                {\fieldbodyparameter\c!fieldlayer}%
250       option               {\fieldbodyparameter\c!option}%
251       clickin              {\fieldbodyparameter\c!clickin}%
252       clickout             {\fieldbodyparameter\c!clickout}%
253       regionin             {\fieldbodyparameter\c!regionin}%
254       regionout            {\fieldbodyparameter\c!regionout}%
255       afterkey             {\fieldbodyparameter\c!afterkey}%
256       format               {\fieldbodyparameter\c!format}%
257       validate             {\fieldbodyparameter\c!validate}%
258       calculate            {\fieldbodyparameter\c!calculate}%
259       focusin              {\fieldbodyparameter\c!focusin}%
260       focusout             {\fieldbodyparameter\c!focusout}%
261       openpage             {\fieldbodyparameter\c!openpage}%
262       closepage            {\fieldbodyparameter\c!closepage}%
263      }%
264    \relax}
265
266%D The sets are used in grouped calculations.
267%D
268%D [name] [set]
269
270\permanent\tolerant\protected\def\definefieldbodyset[#tag]#spacer[#list]%
271  {\clf_definefieldset{#tag}{#list}}
272
273\aliased\let\dodefinefieldset\definefieldbodyset % compatibility
274
275%D A few testing macros (expandable for historic reasons):
276
277\permanent\def\doifelsefieldbody    #tag{\clf_doifelsefieldset{#tag}}
278\permanent\def\doifelsefieldcategory#tag{\clf_doifelsefieldcategory{#tag}}
279
280\aliased\let\doiffieldbodyelse    \doifelsefieldbody
281\aliased\let\doiffieldcategoryelse\doifelsefieldcategory
282
283\aliased\let\doiffieldelse        \doifelsefieldbody % compatibility / will be dropped
284\aliased\let\doifelsefield        \doifelsefieldbody % compatibility / will be dropped
285
286%D We still support the traditional method of defining fields:
287%D
288%D \starttyping
289%D \definefield [name] [type] [category] [values] [default]
290%D
291%D \definefield [WWWW] [text]  [textsetup]            [default text]
292%D \definefield [XXXX] [push]  [pushsetup]  [yes,no]  [yes]
293%D \definefield [XXXX] [check] [checksetup] [yes,no]  [yes]
294%D \definefield [YYYY] [combo] [combosetup] [a,b,c,d] [b]
295%D \definefield [ZZZZ] [radio] [radiosetup] [W,X,Y,Z] [Y]
296%D
297%D \definesubfield [W]   [subsetup] [p,q]
298%D \definesubfield [X,Y] [subsetup] [p,r]
299%D \definesubfield [Z]   [subsetup] [y,z]
300%D
301%D evt \definemainfield ... wanneer geplaatst voor subs gegeven
302%D
303%D \clonefield [XXXX] [XX,YY] [mysetup]      [on,off]
304%D \clonefield [Z]    [AA,BB] [somesetup]    [true,false]
305%D \clonefield [Z]    [CC,DD] [anothersetup]
306%D
307%D \copyfield [XXXX] [PP,QQ,RR]
308%D \stoptyping
309%D
310%D Keep in mind that you can also use \type {\definefieldbody} to achieve the same.
311
312\permanent\tolerant\protected\def\definefield[#tag]#spacer[#type]#spacer[#category]#spacer[#values]#spacer[#default]%
313  {\definefieldbody[#tag][\c!type=#type,\c!category=#category,\c!values={#values},\c!default={#default}]}
314
315\permanent\tolerant\protected\def\definesubfield[#tag]#spacer[#category]#spacer[#values]%
316  {\definefieldbody[#tag][\c!type=sub,\c!category=#category,\c!values={#values}]}
317
318\permanent\tolerant\protected\def\clonefield[#parent]#spacer[#tag]#spacer[#category]#spacer[#values]%
319  {\definefieldbody[#tag][#parent][\c!category=#category,\c!values={#values}]}
320
321\permanent\tolerant\protected\def\copyfield[#parent]#spacer[#tag]%
322  {\definefieldbody[#tag][#parent]}
323
324\aliased\let\definemainfield\definefield % obsolete !
325
326%D We hook fields into the (viewer based) layering mechanism
327%D (implemented as properties).
328
329\appendtoks
330    \lettonothing\currentfieldcategory
331    \ifcstok{\interactionparameter\c!fieldlayer}\v!auto
332        \setupcurrentfieldcategory[\c!fieldlayer=\currentviewerlayer]%
333    \else
334        \setupcurrentfieldcategory[\c!fieldlayer=]%
335    \fi
336\to \everysetupinteraction
337
338\setupinteraction
339  [\c!fieldlayer=\v!auto] % auto by default
340
341%D The \type {\fieldbody} is the more bare one. One step further goes \type
342%D {\fitfield}, in fact it (now) uses a dedicated instance of framed: \type
343%D {fitfieldframed}.
344%D
345%D \starttyping
346%D \ruledhbox{\fieldbody[Email][height=\strutht,depth=\strutdp,style=normal]}
347%D \ruledhbox{\fitfield[Email][height=\strutht,depth=\strutdp,style=normal]}
348%D \ruledhbox{\fitfield[buttona]}
349%D \stoptyping
350
351\newbox\b_scrn_field_fit_symbol
352
353\defineframed
354  [fitfieldframed]
355  [\c!strut=\v!no,
356   \c!frame=off,
357   \c!offset=\v!overlay,
358   \c!align=]
359
360\permanent\tolerant\protected\def\fitfield[#tag]#spacer[#S#settings]%
361  {\iflocation
362     \begingroup
363       \setbox\b_scrn_field_fit_symbol\hbox\bgroup
364         \normalexpanded{\symbol[\clf_getdefaultfieldvalue{#tag}]}%
365       \egroup
366       \fitfieldframed
367         {\fieldbody[#tag]
368            [\c!width=\wd\b_scrn_field_fit_symbol,
369             \c!height=\ht\b_scrn_field_fit_symbol,
370             \c!depth=\dp\b_scrn_field_fit_symbol,
371             #settings]}%
372     \endgroup
373   \fi}
374
375%D The traditional field command does some labeling and boxing:
376
377\installcorenamespace{fieldlabel}
378\installcorenamespace{fieldcontent}
379\installcorenamespace{fieldtotal}
380
381\installparameterhandler     \??fieldlabel   {fieldlabelframed}
382\installparameterhandler     \??fieldcontent {fieldcontentframed}
383\installparameterhandler     \??fieldtotal   {fieldtotalframed}
384
385\installparametersethandler  \??fieldcontent {fieldcontentframed}
386
387\installsetuphandler         \??fieldlabel   {fieldlabelframed}
388\installsetuphandler         \??fieldcontent {fieldcontentframed}
389\installsetuphandler         \??fieldtotal   {fieldtotalframed}
390
391\installinheritedframed                      {fieldlabelframed}
392\installinheritedframed                      {fieldcontentframed}
393\installinheritedframed                      {fieldtotalframed}
394
395\setupfieldcontentframed
396  [\c!align=\v!flushleft,
397   \c!strut=\v!no,
398   \s!parent=\??regularframed] % needs checking
399
400\setupfieldcontentframed % independent
401  [\c!alternative=\v!normal,
402   \c!type=\v!line,
403   \c!width=5em,
404   \c!height=\lineheight,
405   \c!depth=\zeropoint,
406   \c!align=\v!flushleft,
407   \c!option=\v!printable,
408   \c!n=1024]
409
410\setupfieldlabelframed
411  [\c!style=,
412   \c!color=,
413   \c!align=\v!flushleft,
414   \s!parent=\??regularframed] % needs checking
415
416\setupfieldtotalframed
417  [%\c!alternative={\v!label,\v!frame,\v!horizontal},
418   \c!strut=\v!no,
419   \c!align=,
420   \s!parent=\??regularframed] % needs checking
421
422% \setupcurrent
423
424\permanent\tolerant\protected\def\setupfield[#tag]#spacer[#variant]#spacer[#S#totalsettings]#spacer[#S#labelsettings]#spacer[#S#fieldsettings]%
425  {\ifarguments\or\or
426     \definefieldcategory[#tag][\s!parent=\??fieldcontent#tag,#variant]%
427     \setupfieldtotalframed  [#tag][\s!parent=\??fieldtotal]%
428     \setupfieldlabelframed  [#tag][\s!parent=\??fieldlabel]%
429     \setupfieldcontentframed[#tag][\s!parent=\??fieldcontent,#variant]%
430   \or
431     \definefieldcategory[#tag][\s!parent=\??fieldcontent#tag,#totalsettings]%
432     \setupfieldtotalframed  [#tag][\s!parent=\??fieldtotal,\c!alternative={#variant}]%
433     \setupfieldlabelframed  [#tag][\s!parent=\??fieldlabel]%
434     \setupfieldcontentframed[#tag][\s!parent=\??fieldcontent,#totalsettings]%
435   \or
436     \definefieldcategory[#tag][\s!parent=\??fieldcontent#tag,#labelsettings]%
437     \setupfieldtotalframed  [#tag][\s!parent=\??fieldtotal,\c!alternative={#variant},#totalsettings]%
438     \setupfieldlabelframed  [#tag][\s!parent=\??fieldlabel]%
439     \setupfieldcontentframed[#tag][\s!parent=\??fieldcontent,#labelsettings]%
440   \or
441     \definefieldcategory[#tag][\s!parent=\??fieldcontent#tag,#fieldsettings]%
442     \setupfieldtotalframed  [#tag][\s!parent=\??fieldtotal,\c!alternative={#variant},#totalsettings]%
443     \setupfieldlabelframed  [#tag][\s!parent=\??fieldlabel,#labelsettings]%
444     \setupfieldcontentframed[#tag][\s!parent=\??fieldcontent,#fieldsettings]%
445   \fi}
446
447\permanent\tolerant\protected\def\setupfields[#variant]#spacer[#S#totalsettings]#spacer[#S#labelsettings]#spacer[#S#fieldsettings]%
448  {\ifarguments\or
449     \setupfieldtotalframed  [#variant]%
450   \or
451     \setupfieldtotalframed  [#variant]%
452     \setupfieldcontentframed[#totalsettings]%
453   \or
454     \setupfieldtotalframed  [#variant]%
455     \setupfieldlabelframed  [#totalsettings]%
456     \setupfieldcontentframed[#labelsettings]%
457   \or
458     \setupfieldtotalframed  [\c!alternative={#variant},#totalsettings]%
459     \setupfieldlabelframed  [#labelsettings]%
460     \setupfieldcontentframed[#fieldsettings]%
461   \fi}
462
463% just to get the chain right for no category:
464
465\definefieldcategory    [][\s!parent=\??fieldcontent]
466%setupfieldtotalframed  [][\s!parent=\??fieldtotal]
467%setupfieldlabelframed  [][\s!parent=\??fieldlabel]
468%setupfieldcontentframed[][\s!parent=\??fieldcontent]
469
470% no longer supported:
471
472% \let\resetfields\relax
473
474\def\scrn_field_load_scripts{\useJSscripts[fld]\glet\scrn_field_load_scripts\relax}
475
476\newconditional\fieldlabelshown
477\newconditional\fieldframeshown
478\newconditional\fieldisvertical
479\newconditional\fieldishorizontal
480
481\mutable\lettonothing\currentfieldtotalframed
482\mutable\lettonothing\currentfieldlabelframed
483\mutable\lettonothing\currentfieldcontentframed
484
485\mutable\lettonothing\fieldtotalframedparameterhash   % weird that we have to flag this
486\mutable\lettonothing\fieldlabelframedparameterhash   % idem
487\mutable\lettonothing\fieldcontentframedparameterhash % idem
488
489\permanent\tolerant\protected\def\field[#tag]#spacer[#label]% can be sped up with \setupcurrentfieldtotalframed etc
490  {\iflocation
491     \dontleavehmode
492     \begingroup
493     \scrn_field_load_scripts
494     \edef\currentfieldbody    {#tag}%
495     \edef\currentfieldlabel   {#label}%
496     \edef\currentfieldcategory{\clf_getfieldcategory{#tag}}%
497     \ifempty\currentfieldlabel
498       \let\currentfieldlabel\currentfieldbody
499     \fi
500     \ifempty\currentfieldcategory
501       \setupfieldtotalframed  [\currentfieldbody][\s!parent=\??fieldtotal]%
502       \setupfieldlabelframed  [\currentfieldbody][\s!parent=\??fieldlabel]%
503       \setupfieldcontentframed[\currentfieldbody][\s!parent=\??fieldcontent]%
504       \definefieldcategory    [\currentfieldbody]%
505       \setupfieldbody         [\currentfieldbody][\c!category=\currentfieldbody]%
506       \let\currentfieldcategory\currentfieldbody
507     \fi
508     \let\currentfieldtotalframed  \currentfieldcategory
509     \let\currentfieldlabelframed  \currentfieldcategory
510     \let\currentfieldcontentframed\currentfieldcategory
511     \scrn_field_analyze_setups
512     \ifconditional\fieldframeshown
513       \inheritedfieldtotalframedframed % lower framedoffset
514       \bgroup
515     \else
516       \vbox
517       \bgroup
518     \fi
519     \dontcomplain
520     \ifconditional\fieldlabelshown
521       \scrn_field_set_label_box
522     \fi
523     \scrn_field_set_content_box
524     \ifconditional\fieldlabelshown
525       \ifconditional\fieldisvertical
526         \scrn_field_flush_vertical
527       \else
528         \scrn_field_flush_horizontal
529       \fi
530     \else
531       \scrn_field_flush_content
532     \fi
533     \egroup
534     \endgroup
535   \fi}
536
537% opties: veld, label, kader, vertikaal/horizontaal
538
539\newbox\b_scrn_field_label
540\newbox\b_scrn_field_content
541
542% lower framedoffset
543
544\def\scrn_field_set_label_box
545  {\setbox\b_scrn_field_label\hbox
546      {\reshapeframeboxtrue % else wrong dimensions % still needed?
547       \inheritedfieldlabelframedframed{\currentfieldlabel}}}
548
549% \c!fieldoffset=-\framedoffset,\c!fieldbackgroundcolor=,
550% \hbox{\lower\@@fdfieldoffset\hbox{\typesetfield}}
551
552\def\scrn_field_set_content_box
553  {\setbox\b_scrn_field_content\hbox
554     {\reshapeframeboxtrue % else wrong dimensions (to be checked)
555      \ifempty{\fieldcontentframedparameter\c!height}%
556        \ifconditional\fieldisvertical
557          \setfieldcontentframedparameter\c!height{6ex}%
558        \orelse\ifconditional\fieldishorizontal
559          \setfieldcontentframedparameter\c!height{\vsize}%
560        \else
561          \setfieldcontentframedparameter\c!height{2cm}%
562        \fi
563      \fi
564      \ifempty{\fieldcontentframedparameter\c!width}%
565        \ifconditional\fieldisvertical
566          \setfieldcontentframedparameter\c!width{\hsize}%
567        \orelse\ifconditional\fieldishorizontal
568          \setfieldcontentframedparameter\c!width{20em}%
569        \else
570          \setfieldcontentframedparameter\c!width{2cm}%
571        \fi
572      \fi
573      \inheritedfieldcontentframedframed % lower framedoffset
574        {\fieldbody
575           [\currentfieldbody]
576           [\c!width=\framedwidth,\c!height=\framedheight]}}}
577
578
579\def\scrn_field_flush_vertical
580  {\vbox
581     {\copy\b_scrn_field_label
582      \fieldtotalframedparameter\c!inbetween
583      \copy\b_scrn_field_content}}
584
585\def\scrn_field_flush_horizontal
586   {\hbox
587      {\vbox \ifdim\ht\b_scrn_field_content>\ht\b_scrn_field_label to \ht\b_scrn_field_content \fi
588         {\fieldtotalframedparameter\c!before
589          \copy\b_scrn_field_label
590          \fieldtotalframedparameter\c!after}%
591       \hskip\fieldtotalframedparameter\c!distance
592       \vbox \ifdim\ht\b_scrn_field_label>\ht\b_scrn_field_content to \ht\b_scrn_field_label \fi
593         {\fieldtotalframedparameter\c!before
594          \box\b_scrn_field_content
595          \fieldtotalframedparameter\c!after}}}
596
597\def\scrn_field_flush_content
598  {\box\b_scrn_field_content}
599
600%D todo: replace \processallactionsinset
601
602\def\scrn_field_analyze_setups
603  {\fieldlabelshown\conditionalfalse
604   \fieldframeshown\conditionalfalse
605   \fieldishorizontal\conditionalfalse
606   \fieldisvertical\conditionalfalse
607   \normalexpanded{\processallactionsinset[\fieldtotalframedparameter\c!alternative]}
608     [      \v!reset=>\fieldlabelshown\conditionalfalse
609                      \fieldframeshown\conditionalfalse
610                      \fieldishorizontal\conditionalfalse
611                      \fieldisvertical\conditionalfalse,
612            \v!label=>\fieldlabelshown\conditionaltrue,
613            \v!frame=>\fieldframeshown\conditionaltrue,
614       \v!horizontal=>\fieldishorizontal\conditionaltrue,
615         \v!vertical=>\fieldisvertical\conditionaltrue]%
616   \ifconditional\fieldisvertical
617     \setupfieldtotalframed[\c!distance=\zeropoint,\c!inbetween=\vskip\d_framed_local_offset,\c!align=\v!right,\c!width=20em]%
618   \orelse\ifconditional\fieldishorizontal
619     \setupfieldtotalframed[\c!distance=\d_framed_local_offset,\c!inbetween=,\c!align=\c!left,\c!height=10ex]%
620   \else
621     \setupfieldtotalframed[\c!distance=\zeropoint,\c!inbetween=,\c!align=\c!left]%
622   \fi
623   \setupfieldtotalframed[\c!n=,\c!before=,\c!after=\vss,\c!style=,\c!color=]}
624
625%D Common stuff (obsolete)
626
627\newinteger\c_scrn_field_system_n
628
629\permanent\def\currentsystemfield{sys::\the\c_scrn_field_system_n}
630
631\permanent\protected\def\nextsystemfield
632  {\global\advanceby\c_scrn_field_system_n\plusone}
633
634%D \CONTEXT\ had tooltips right from the moment that it supported fields. Due to the
635%D at that moment somewhat limited \PDF\ specification, they were implemented using
636%D \JAVASCRIPT, but nowadays more kind of actions are supported, so we can do
637%D without. The \MKIV\ version also supports definition of tooltips and
638%D configuration.
639%D
640%D \starttyping
641%D before \tooltip[right]{inbetween}{a very nice tip} after\par
642%D before \tooltip[align=normal]{inbetween}{a very\\nice tip} after\par
643%D before \tooltip[middle]{inbetween}{a very nice tip} after\par
644%D before \tooltip[left]{inbetween}{a very nice tip} after\par
645%D \stoptyping
646
647\newbox    \b_scrn_tooltip_anchor
648\newbox    \b_scrn_tooltip_text
649\newinteger\c_scrn_tooltip_n
650
651\installcorenamespace{tooltip}
652
653\installframedcommandhandler \??tooltip {tooltip} \??tooltip
654
655\setuptooltip
656  [\c!location=\v!right,
657   \c!frame=\v!off,
658   \c!offset=.1ex,
659   \c!background=\v!color,
660   \c!backgroundcolor=gray]
661
662\appendtoks
663    \frozen\instance\protected\edefcsname\currenttooltip\endcsname{\scrn_tooltip_direct{\currenttooltip}}%
664\to \everydefinetooltip
665
666\protected\def\scrn_tooltip_direct#tag%
667  {\cdef\currenttooltip{#tag}%
668   \iflocation
669     \expandafter\scrn_tooltip_indeed
670   \else
671     \expandafter\scrn_tooltip_ignore
672   \fi}
673
674\tolerant\def\scrn_tooltip_ignore[#S#settings]#:#anchortext#tiptext%
675  {#anchortext}
676
677\mutable\lettonothing\currenttooltipname
678
679\tolerant\def\scrn_tooltip_indeed[#S#settings]#:#anchortext#tiptext% a more modern aproach (push buttons)
680  {\dontleavehmode \hbox \bgroup
681     \dontcomplain
682     \global\advanceby\c_scrn_tooltip_n\plusone
683     \edef\currenttooltipname{tooltip:\the\c_scrn_tooltip_n}%
684     \setbox\b_scrn_tooltip_anchor\hbox
685       {\strut#anchortext}%
686     \doifelseassignment{#settings}
687       {\setupcurrenttooltip[#settings]}%
688       {\setupcurrenttooltip[\c!location=#settings]}%
689     \setbox\b_scrn_tooltip_text\hbox
690       {\resettooltipparameter\c!location
691        \inheritedtooltipframed{#tiptext}}%
692     \definesymbol
693       [\currenttooltipname:txt]
694       [\copy\b_scrn_tooltip_text]%
695     \definefieldbody
696       [\currenttooltipname:txt]
697       [\c!type=push,
698        \c!width=\wd\b_scrn_tooltip_text,
699        \c!height=\ht\b_scrn_tooltip_text,
700        \c!depth=\dp\b_scrn_tooltip_text,
701        \c!option=\v!hidden,
702        \c!values=\currenttooltipname:txt]%
703     \setbox\b_scrn_tooltip_text\hbox
704       {\fieldbody[\currenttooltipname:txt]}%
705     \setbox\b_scrn_tooltip_text\hbox
706       {\strut\lower\dimexpr.25ex+\ht\b_scrn_tooltip_text\relax\box\b_scrn_tooltip_text}%
707     \edef\p_location{\tooltipparameter\c!location}%
708     \ifx\p_location\v!left
709       \hsmashed{\hskip\wd\b_scrn_tooltip_anchor\llap{\box\b_scrn_tooltip_text}}%
710     \orelse\ifx\p_location\v!middle
711       \hsmashed to \wd\b_scrn_tooltip_anchor{\hss\box\b_scrn_tooltip_text\hss}%
712     \else
713       \hsmashed{\box\b_scrn_tooltip_text}%
714     \fi
715     \definesymbol
716       [\currenttooltipname:but]
717       [\hphantom{\copy\b_scrn_tooltip_anchor}]%
718     \definefieldbody
719       [\currenttooltipname:but]
720       [\c!type=push,
721        \c!regionin=action(show{\currenttooltipname:txt}),
722        \c!regionout=action(hide{\currenttooltipname:txt}),
723        \c!width=\wd\b_scrn_tooltip_anchor,
724        \c!height=\ht\b_scrn_tooltip_anchor,
725        \c!depth=\dp\b_scrn_tooltip_anchor]%
726     \hsmashed{\fieldbody[\currenttooltipname:but]}%
727   \egroup
728   #anchortext}% when hyphenated the text wil stick out ... such are fields and we cannot use a link here
729
730\definetooltip[tooltip]
731
732%D From messages on the mailing list we can conclude that fieldstacks are used so we
733%D keep them in the core:
734%D
735%D \starttyping
736%D \definesymbol[one]  [one]
737%D \definesymbol[two]  [two]
738%D \definesymbol[three][three]
739%D
740%D \definefieldstack[mine][one,two,three]
741%D \fieldstack[mine]
742%D \fieldstack[mine]
743%D
744%D \goto{walk field}[Walk{mine}]
745%D \stoptyping
746
747% todo: expand #symbols
748
749\installcorenamespace {fieldstack}
750
751\permanent\tolerant\protected\def\definefieldstack[#tag]#spacer[#symbols]#spacer[#S#settings]%
752  {\ifcsname\??fieldstack#tag\endcsname
753     % already done
754   \else
755     %xdefcsname\??fieldstack#tag\endcsname{\scrn_fieldstack_construct[#tag][#symbols][#settings]}%
756     \xdefcsname\??fieldstack#tag\endcsname{\scrn_fieldstack_construct[#tag][#symbols][\normalunexpanded{#settings}]}%
757   \fi}
758
759\permanent\tolerant\protected\def\fieldstack[#tag]#spacer[#symbols]#spacer[#S#settings]%
760  {\ifparameter#symbols\or
761     \definefieldstack[#tag][#symbols][#settings]%
762   \fi
763   \csname\??fieldstack#tag\endcsname}
764
765\newbox\b_scrn_fieldstack_box
766
767\definesymbol[\s!empty][]
768
769\def\scrn_fieldstack_add#tag#settings#symbol%
770  {\advanceby\scratchcounter\plusone
771   \edef\currentfieldstackname{#tag:\the\scratchcounter}%
772   \ifnum\scratchcounter=\fieldcategoryparameter\c!start\relax
773     \definefieldbody[\currentfieldstackname][\c!type=check,\c!values={#symbol,\s!empty},\c!default={#symbol}]%
774   \else
775     \definefieldbody[\currentfieldstackname][\c!type=check,\c!values={#symbol,\s!empty},\c!default=\s!empty]%
776   \fi
777   \setbox\b_scrn_fieldstack_box\hbox{\symbol[#symbol]}%
778   \setcollector
779     [fieldstack]
780     {\fieldbody
781        [\currentfieldstackname]
782        [\c!option={\v!readonly},
783         \c!width=\wd\b_scrn_fieldstack_box,
784         \c!height=\ht\b_scrn_fieldstack_box,
785         \c!depth=\dp\b_scrn_fieldstack_box,
786         #settings]}}
787
788\protected\def\scrn_fieldstack_construct[#tag][#symbols][#S#settings]% start=n, 0 == leeg
789  {\iflocation
790     \dontleavehmode
791     \begingroup
792     \setupfieldcategory[\c!start=1,#settings]% was just \??fieldcategory
793     \scrn_field_load_scripts
794     \definecollector
795       [fieldstack]%
796       [\c!corner=\v!middle,
797        \c!location=\v!middle]%
798     \scratchcounter\zerocount
799     \processcommalist[#symbols]{\scrn_fieldstack_add{#tag}{#settings}}%
800     \flushcollector[fieldstack]%
801     \endgroup
802   \fi}
803
804%D Another goodie. Two actions can be hookes into an overlay.
805%D
806%D \starttyping
807%D \defineviewerlayer[test]
808%D
809%D \startviewerlayer[test]Hide Me\stopviewerlayer
810%D
811%D \defineoverlay
812%D   [WithTest]
813%D   [{\overlayrollbutton[HideLayer{test}][VideLayer{test}]}]
814%D
815%D \framed[background=WithTest]{toggle}
816%D \stoptyping
817
818\newinteger\c_scrn_rollbutton_n
819
820\permanent\tolerant\protected\def\overlayrollbutton[#1]#*[#2]#;#=#=%
821  {\iflocation
822     \bgroup
823     \global\advanceby\c_scrn_rollbutton_n_button\plusone
824     \global\advanceby\c_scrn_rollbutton_n_symbol\plusone
825     \definesymbol
826       [rollsymbol:\the\c_scrn_rollbutton_n_symbol]
827       [{\framed[\c!frame=\v!off,\c!width=\overlaywidth,\c!height=\overlayheight]{}}]%
828   % \definefieldbody
829   %   [rollbutton:\the\c_scrn_rollbutton_n_button]
830   %   [\c!type=push,
831   %    \c!values=rollsymbol:\the\c_scrn_rollbutton_n_symbol,
832   %    \c!default=rollsymbol:\the\c_scrn_rollbutton_n_symbol]%
833   % \fitfield
834   %   [rollbutton:\the\c_scrn_rollbutton_n_button]%
835   %   [\c!regionin={#regionin},
836   %    \c!regionout={#regionout}]%
837     %
838     \definefield
839       [rollbutton:\the\c_scrn_rollbutton_n_button][push][rollbutton]
840       [rollsymbol:\the\c_scrn_rollbutton_n_symbol]%
841     \fitfield
842       [rollbutton:\the\c_scrn_rollbutton_n_button]%
843       [\c!regionin={#1#3},\c!regionout={#2#4}]%
844     %
845     \egroup
846   \fi}
847
848% \protect \endinput % THE FOLLOWING CODE IS NOT CHECKED
849
850%D I will redo these when I need them.
851
852% \setupinteraction[state=start]
853%
854% \definepushbutton [reset]
855%
856% \startuniqueMPgraphic{whatever}{color}
857%     fill fullcircle xysized (OverlayWidth,OverlayHeight) withcolor \MPvar{color} ;
858% \stopuniqueMPgraphic
859%
860% \definepushsymbol [reset] [n] [\uniqueMPgraphic{whatever}{color=red}]
861% \definepushsymbol [reset] [r] [\uniqueMPgraphic{whatever}{color=green}]
862% \definepushsymbol [reset] [d] [\uniqueMPgraphic{whatever}{color=blue}]
863%
864% \starttext
865%     \startTEXpage
866%         \pushbutton [reset] [page(2)]
867%     \stopTEXpage
868%     \startTEXpage
869%         \pushbutton [reset] [page(1)]
870%     \stopTEXpage
871% \stoptext
872
873\newinteger\c_scrn_pushbutton_n
874
875\permanent\tolerant\protected\def\definepushbutton[#tag]#spacer[#S#settings]%
876  {\scrn_pushbutton_define_variant{#tag}{n}{push}%
877   \scrn_pushbutton_define_variant{#tag}{r}{\symbol[pushsymbol:#tag:n]}%
878   \scrn_pushbutton_define_variant{#tag}{d}{\symbol[pushsymbol:#tag:r]}%
879   \setvalue{pushbutton:#tag}{\scrn_pushbutton_handle{#tag}{#settings}}}
880
881\def\scrn_pushbutton_define_variant#tag#variant#content%
882  {\doifelsesymboldefined{pushsymbol:#tag:#variant}
883     \donothing
884     {\definesymbol[pushsymbol:#tag:#variant][{#content}]}}
885
886\def\scrn_pushbutton_handle#tag#settings#reference%
887  {\bgroup
888   \global\advanceby\c_scrn_pushbutton_n\plusone
889   \setupfield
890     [pushbutton]%
891     [\c!frame=\v!overlay,%
892      \c!offset=\v!overlay,%
893      \c!clickout={#reference},%
894      #settings]%
895   \definefield
896     [pushbutton:\the\c_scrn_pushbutton_n]%
897     [push]%
898     [pushbutton]%
899     [pushsymbol:#tag:n,pushsymbol:#tag:r,pushsymbol:#tag:d]%
900   \fitfield
901     [pushbutton:\the\c_scrn_pushbutton_n]%
902   \egroup}
903
904\permanent\tolerant\protected\def\definepushsymbol[#tag]#spacer[#variant]% [#reference]
905  {\definesymbol[pushsymbol:#tag:#variant]}
906
907\permanent\tolerant\def\pushbutton[#tag]#spacer[#variant]%
908  {\executeifdefined{pushbutton:#tag}\gobbleoneargument{#variant}}
909
910%D We plug into the menu system
911
912\permanent\permanent\protected\def\scrn_menu_psh_start[#reference]#text\stoppsh
913  {\starttxt\pushbutton[\currentinteractionmenu][#reference]\stoptxt}
914
915\permanent\permanent\protected\def\scrn_menu_psh_direct[#reference]#text\\
916  {\scrn_menu_psh_start[#reference]\stoprob}
917
918\aliased\let\startpsh\relax % maybe mutable
919\aliased\let\stoppsh \relax % maybe mutable
920\aliased\let\psh     \relax % maybe mutable
921
922\appendtoks
923    \enforced\let\startpsh\scrn_menu_psh_start
924    \enforced\let\stoppsh \relax
925    \enforced\let\psh     \scrn_menu_psh_direct
926\to \everysetmenucommands
927
928%D Another goodie: (unchecked in \MKIV)
929
930% calls:
931%              {..} [JS..]
932% [left]       {..} [JS..]
933%        [a=b] {..} [JS..]
934% [left] [a=b] {..} [JS..]
935%
936% \setupbuttons[offset=0pt,frame=off] % alternative=hidden
937%
938% \rollbutton {Manuals}       [JS(Goto_File{show-man.pdf})]
939% \rollbutton {Articles}      [JS(Goto_File{show-art.pdf})]
940% \rollbutton {Papers}        [JS(Goto_File{show-pap.pdf})]
941% \rollbutton {Presentations} [JS(Goto_File{show-pre.pdf})]
942% \rollbutton {Resources}     [JS(Goto_File{show-res.pdf})]
943%
944% \rob [JS(...)] bla bla \\
945
946% \definecolor[rollover:n][red]
947% \definecolor[rollover:r][green]
948% \definecolor[rollover:d][blue]
949
950\definepalet
951  [rollover]
952  [n=red,
953   r=green,
954   d=blue]
955
956\newinteger\c_scrn_rollbutton_n_button
957\newinteger\c_scrn_rollbutton_n_symbol
958
959\permanent\def\lastrollbuttonindex{\the\c_scrn_rollbutton_n_button}
960
961\setupfield
962  [rollbutton]
963  [\c!frame=\v!off,
964   \c!offset=\v!overlay]
965
966\let\scrn_rollbutton_symbol\relax
967
968\def\scrn_rollbutton_symbol_m
969  {\scrn_rollbutton_symbol_indeed
970     \interactionmenuparameter
971     \inheritedinteractionmenuframed
972     \setinteractionmenuparameter
973     \useinteractionmenustyleandcolor}
974
975\def\scrn_rollbutton_symbol_b
976  {\scrn_rollbutton_symbol_indeed
977     \buttonparameter
978     \inheritedbuttonframed
979     \setbuttonparameter
980     \usebuttonstyleandcolor}
981
982\permanent\tolerant\protected\def\rollbutton[#tag]#spacer[#S#settings]#:#text[#reference]%
983  {\dontleavehmode
984   \bgroup
985   \global\advanceby\c_scrn_rollbutton_n_button\plusone
986   \global\advanceby\c_scrn_rollbutton_n_symbol\plusone
987   \ifparameter#tag\or
988     \ifparameter#settings\or
989       \edef\currentinteractionmenu{#tag}%
990       \setupcurrentinteractionmenu[#settings]%
991       \let\scrn_rollbutton_symbol\scrn_rollbutton_symbol_m
992     \orelse\ifhastok={#tag}%
993       \lettonothing\currentbutton
994       \setupcurrentbutton[#tag]%
995       \let\scrn_rollbutton_symbol\scrn_rollbutton_symbol_b
996     \else
997       \edef\currentinteractionmenu{#tag}%
998       \let\scrn_rollbutton_symbol\scrn_rollbutton_symbol_m
999     \fi
1000   \else
1001     \let\scrn_rollbutton_symbol\scrn_rollbutton_symbol_b
1002   \fi
1003   % todo: share symbols, tricky since different dimensions (maybe \unique...)
1004   \definesymbol[rollsymbol:\the\c_scrn_rollbutton_n_symbol:n][\scrn_rollbutton_symbol{n}{#text}]%
1005   \definesymbol[rollsymbol:\the\c_scrn_rollbutton_n_symbol:r][\scrn_rollbutton_symbol{r}{#text}]%
1006   \definesymbol[rollsymbol:\the\c_scrn_rollbutton_n_symbol:d][\scrn_rollbutton_symbol{d}{#text}]%
1007   \definefield
1008     [rollbutton:\the\c_scrn_rollbutton_n_button][push][rollbutton]
1009     [rollsymbol:\the\c_scrn_rollbutton_n_symbol:n,%
1010      rollsymbol:\the\c_scrn_rollbutton_n_symbol:r,%
1011      rollsymbol:\the\c_scrn_rollbutton_n_symbol:d]%
1012   \fitfield
1013     [rollbutton:\the\c_scrn_rollbutton_n_button]%
1014     [\c!clickout={#reference}]%
1015   \egroup}
1016
1017\protected\def\scrn_rollbutton_symbol_indeed#getparameter#inheritedframed#setparameter#usestyleandcolor#what#text%
1018  {\definecolor[rollover][rollover:#what]%
1019   \ifcstok{#getparameter\c!alternative}\v!hidden
1020     \expandafter\phantom
1021   \else
1022     \expandafter\hbox
1023   \fi
1024   \bgroup
1025     #setparameter\c!framecolor     {rollover}%
1026     #setparameter\c!backgroundcolor{rollover}%
1027     #setparameter\c!color          {rollover}%
1028     #inheritedframed{#usestyleandcolor\c!style\c!color{#text}}%
1029   \egroup}
1030
1031%D We plug into the menu system
1032
1033\permanent\protected\def\scrn_menu_rob_start[#reference]#text\stoprob
1034  {\starttxt\rollbutton[\currentinteractionmenu]{\ignorespaces#text\unskip}[#reference]\stoptxt}
1035
1036\permanent\protected\def\scrn_menu_rob_direct[#reference]#text\\
1037  {\scrn_menu_rob_start[#reference]#text\stoprob}
1038
1039\aliased\let\startrob\relax % maybe mutable
1040\aliased\let\stoprob \relax % maybe mutable
1041\aliased\let\rob     \relax % maybe mutable
1042
1043\appendtoks
1044    \enforced\let\startrob\scrn_menu_rob_start
1045    \enforced\let\stoprob \relax
1046    \enforced\let\rob     \scrn_menu_rob_direct
1047\to \everysetmenucommands
1048
1049%D Signing:
1050%D
1051%D \starttyping
1052%D \setupinteraction[state=start]
1053%D
1054%D \definefield[signature][signed]
1055%D
1056%D \starttext
1057%D
1058%D     \defineoverlay[signature][my signature]
1059%D
1060%D     \startTEXpage[offset=1ts]
1061%D         sign: \inframed
1062%D           [background=signature]
1063%D           {\fieldbody[signature][width=3cm,option=hidden]}
1064%D     \stopTEXpage
1065%D
1066%D \stoptext
1067%D \stoptyping
1068%D
1069%D after processing:
1070%D
1071%D \starttyping
1072%D mtxrun --script pdf --sign   --certificate=somesign.pem --password=test --uselibrary somefile
1073%D mtxrun --script pdf --verify --certificate=somesign.pem --password=test --uselibrary somefile
1074%D \stoptyping
1075
1076\protect \endinput
1077