scrn-hlp.mkvi /size: 4719 b    last modification: 2020-07-01 14:35
1%D \module
2%D   [       file=scrn-hlp,
3%D        version=1998.10.10,
4%D          title=\CONTEXT\ Screen Macros,
5%D       subtitle=Help (Experimental),
6%D         author={Hans Hagen \& Ton Otten},
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\writestatus{loading}{ConTeXt Screen Macros / Help popups}
15
16%D As this functionality was in the core and as I don't know
17%D how often it is used, we'll keep it around. However, it is
18%D upgraded and usage has changed a bit. We also use some
19%D \LUA\ magic in order to avoid multiple passes.
20
21\registerctxluafile{scrn-hlp}{}
22
23%D Using help boils down to plugging the placement macro
24%D someplace visible, like:
25%D
26%D \starttyping
27%D \setuptexttexts[\centerbox{\placehelp}]
28%D \stoptyping
29%D
30%D When this is done, the following should work out okay:
31%D
32%D \starttyping
33%D test \helptext{word}{tip top 1 is somewhat longer} test
34%D test \helptext{word}{tip top 2} test
35%D
36%D \starthelptext[oeps]
37%D \input tufte
38%D \stophelptext
39%D
40%D test test \showhelp{some help}[oeps] test
41%D test test \button[location=depth]{\helpsignal{oeps}OEPS}[oeps] test
42%D
43%D test test \button[location=depth]{next}[page(2)] test
44%D
45%D \page
46%D
47%D test \helptext{word}{tip top one} test
48%D test \helptext{word}{tip top two} test
49%D \stoptyping
50%D
51%D Currently you need to use the signal in custom macros but
52%D that might change at some point.
53
54\unprotect
55
56% also status
57
58\newbox  \b_scrn_help_box
59\newcount\c_scrn_help_n
60
61\definesystemattribute[help][public]
62
63\installcorenamespace{popuphelp}
64
65\installframedcommandhandler \??popuphelp {help} \??popuphelp
66
67\setuphelp
68  [\c!frame=\v!off,
69   \c!align=\v!normal,
70   \c!background=\v!color,
71   \c!backgroundcolor=gray]
72
73\appendtoks
74    \setuevalue         \currenthelp {\scrn_help_argument{\currenthelp}}%
75    \setuevalue{\e!start\currenthelp}{\scrn_help_start   {\currenthelp}}%
76    \setuevalue{\e!stop \currenthelp}{\scrn_help_stop                  }%
77\to \everydefinehelp
78
79\unexpanded\def\scrn_help_argument#category%
80  {\def\currenthelp{#category}%
81   \global\advance\c_scrn_help_n\plusone
82   \edef\currenthelpname{help:\number\c_scrn_help_n}%
83   \doifelselocation
84     {\dosingleempty\scrn_help_argument_indeed}
85     {\dosingleempty\scrn_help_argument_ignore}}
86
87\def\scrn_help_argument_indeed[#reference]#text#target%
88  {\edef\currenthelpreference{#reference}%
89   \dontleavehmode \hbox \bgroup
90     \dontcomplain
91     \setbox\b_scrn_help_box\hbox{\strut#text}%
92     \scrn_help_register{#target}%
93   \egroup % can be usernode instead
94   \goto
95     {\helpsignal{\number\c_scrn_help_n}#target}%
96     [\helpaction{\number\c_scrn_help_n}]}
97
98\def\scrn_help_argument_ignore[#reference]#text#target%
99  {#target}
100
101\unexpanded\def\scrn_help_start#category%
102  {\def\currenthelp{#category}%
103   \global\advance\c_scrn_help_n\plusone
104   \edef\currenthelpname{help:\number\c_scrn_help_n}%
105   \dosingleempty\scrn_help_start_indeed}
106
107\def\scrn_help_start_indeed[#reference]%
108  {\edef\currenthelpreference{#reference}%
109   \grabbufferdatadirect\currenthelp{\e!start\currenthelp}{\e!stop\currenthelp}}
110
111\unexpanded\def\scrn_help_stop
112  {\iflocation
113     \scrn_help_register{\getbuffer[\currenthelp]}%
114   \fi}
115
116\def\scrn_help_register#text%
117  {\setbox\b_scrn_help_box\hbox{\inheritedhelpframed{#text}}% \hpack ?
118   \definesymbol
119     [\currenthelpname]
120     [\copy\b_scrn_help_box]%
121   \definefieldbody
122     [\currenthelpname]
123     [\c!type=push,
124      \c!width=\wd\b_scrn_help_box,
125      \c!height=\ht\b_scrn_help_box,
126      \c!depth=\dp\b_scrn_help_box,
127      \c!option=\v!hidden,
128      \c!clickin=action(hide{\currenthelpname}),
129      \c!closepage=action(hide{\currenthelpname}),
130      \c!values=\currenthelpname]%
131   \setbox\b_scrn_help_box\hbox
132     {\fieldbody[\currenthelpname]}%
133   \clf_registerhelp
134     number \c_scrn_help_n
135     name   {\currenthelpreference}%
136     box    \b_scrn_help_box
137   \relax}
138
139\unexpanded\def\doifelsehelp
140  {\ifcase\c_scrn_help_n
141     \expandafter\firstoftwoarguments
142   \else
143     \expandafter\secondoftwoarguments
144   \fi}
145
146\let\doifhelpelse\doifelsehelp
147
148\unexpanded\def\placehelp % was \helpdata
149  {\ifinpagebody\ifcase\c_scrn_help_n\else
150     \clf_collecthelp\normalpagebox
151   \fi\fi}
152
153\def\helpreference#category%
154  {\clf_helpreference{#category}}
155
156\def\helpaction#category%
157  {\clf_helpaction{#category}}
158
159\unexpanded\def\helpsignal#category%
160  {\hbox attr \helpattribute \helpreference{#category}{}}
161
162\unexpanded\def\showhelp#target[#category]%
163  {\goto{\helpsignal{#category}#target}[#category]}
164
165\definehelp[\v!helptext]
166
167\protect \endinput
168