scrn-ini.mklx /size: 10 Kb    last modification: 2025-02-21 11:03
1%D \module
2%D   [       file=scrn-ini,
3%D        version=2011.02.27,
4%D          title=\CONTEXT\ Interaction Macros,
5%D       subtitle=Initialization,
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\writestatus{loading}{ConTeXt Interaction Macros / Initialization}
15
16\unprotect
17
18\registerctxluafile{scrn-ini}{autosuffix}
19
20%D There is no interaction at all unless enabled by saying:
21%D
22%D \starttyping
23%D \setupinteraction[state=start]
24%D \stoptyping
25%D
26%D The other settings are:
27%D
28%D \showsetup{setupinteraction}
29
30\installcorenamespace{interaction}
31
32\installswitchcommandhandler \??interaction {interaction} \??interaction
33
34\appendtoks
35    \ifempty\previousinteraction
36      \checkinteractionstate
37    \orelse\ifx\currentinteraction\previousinteraction
38      \checkinteractionstate
39    \fi
40\to \everysetupinteraction
41
42\permanent\protected\def\checkinteractionstate
43  {\ifcstok{\interactionparameter\c!state}\v!start
44     \locationtrue
45     \setsystemmode\v!interaction
46   \else
47     \locationfalse
48     \resetsystemmode\v!interaction
49   \fi}
50
51\permanent\def\doifelselocation % expandable
52  {\iflocation
53     \expandafter\firstoftwoarguments
54   \else
55     \expandafter\secondoftwoarguments
56   \fi}
57
58\aliased\let\doiflocationelse\doifelselocation
59
60\setupinteraction
61  [\c!state=\v!stop]
62
63\setupinteraction
64  [\c!title=,
65   \c!subtitle=,
66   \c!author=,
67   \c!keyword=,
68   \c!date=]
69
70\appendtoks
71    \setupinteraction % todo: remember info at the lua end (already possible)
72\to \everyjob
73
74% it makes no sense to create an environment as we will seldom have structured
75% interactions so a general start-stop will do
76%
77% \appendtoks
78%     \frozen\instance\protected\edefcsname        \currentinteraction\endcsname{\scrn_interaction_direct{\currentinteraction}}%
79%     \frozen\instance\protected\edefcsname\e!start\currentinteraction\endcsname{\scrn_interaction_start {\currentinteraction}}%
80%     \frozen\instance\protected\edefcsname\e!stop \currentinteraction\endcsname{\scrn_interaction_stop                       }%
81% \to \everydefineinteraction
82%
83% \protected\def\scrn_interaction_direct#1%
84%   {\cdef\currentinteraction{#1}}
85%
86% \protected\def\scrn_interaction_start#1%
87%   {\pushmacro\currentinteraction
88%    \cdef\currentinteraction{#1}}
89%
90% \protected\def\scrn_interaction_stop
91%   {\popmacro\currentinteraction}
92%
93% \protected\def\setinteraction[#1]%
94%   {\cdef\currentinteraction{#1}}
95%
96% \defineinteraction[\v!interaction]
97
98\permanent\protected\def\startinteraction[#1]%
99  {\pushmacro\currentinteraction
100   \cdef\currentinteraction{#1}}
101
102\permanent\protected\def\stopinteraction
103  {\popmacro\currentinteraction}
104
105\permanent\protected\def\setinteraction[#1]%
106  {\cdef\currentinteraction{#1}}
107
108\defineinteraction % keep it simple
109  [\v!hidden]
110
111\setupinteraction
112  [\v!hidden]
113  [\c!state=\v!start,
114   \c!color=,
115   \c!contrastcolor=,
116   \c!style=,
117   \c!click=\v!off]
118
119%D As long as there a natural feeling of what can be considered
120%D hyper active or not, we have to tell users where they can
121%D possibly click. We've already seen a few macros that deal
122%D with this visualization, something we definitely do not let
123%D up to the viewer. One way of telling is using a distinctive
124%D typeface, another way is using color.
125%D
126%D There are two colors involved: one for normal hyperlinks,
127%D and one for those that point to the currentpage, the
128%D contrast color.
129
130\definecolor [interactioncolor]         [r=0,  g=.6, b=0]
131\definecolor [interactioncontrastcolor] [r=.8, g=0,  b=0]
132
133%D The next few macros are responsible for highlighting hyper
134%D links. The first one, \type{\showlocation}, is used in those
135%D situations where the typeface is handled by the calling
136%D macro.
137
138%D When we're dealing with pure page references, contrast
139%D colors are used when we are already at the page mentioned.
140
141% \permanent\protected\def\setlocationcolorspecified#1% not grouped !
142%   {\ifnum#1=\plusone
143%      \edef\p_contrastcolor{\interactionparameter\c!contrastcolor}%
144%      \ifempty\p_contrastcolor
145%        \useinteractioncolorparameter\c!color
146%      \else
147%        \useinteractioncolorparameter\c!contrastcolor
148%      \fi
149%    \else % we could just set and if > 0 set again
150%      \useinteractioncolorparameter\c!color
151%    \fi}
152
153% \permanent\protected\def\setlocationattributesspecified#1% not grouped !
154%   {\ifnum#1=\plusone
155%      \edef\p_contrastcolor{\interactionparameter\c!contrastcolor}%
156%      \ifempty\p_contrastcolor
157%        \useinteractionstyleandcolor\c!style\c!color
158%      \else
159%        \useinteractionstyleandcolor\c!style\c!contrastcolor
160%      \fi
161%    \else % we could just set and if > 0 set again
162%      \useinteractionstyleandcolor\c!style\c!color
163%    \fi}
164
165% \permanent\protected\def\setlocationcolorspecspecified#1#2% \resolver
166%   {\ifnum#1=\plusone
167%      \edef\p_contrastcolor{#2\c!contrastcolor}%
168%      \ifempty\p_contrastcolor
169%        \colo_helpers_activate{#2\c!color}%
170%      \else
171%        \colo_helpers_activate\p_contrastcolor
172%      \fi
173%    \else
174%      \colo_helpers_activate{#2\c!color}%
175%    \fi}
176
177\newconditional\c_scrn_interaction_no_style
178\newconditional\c_scrn_interaction_no_color
179\newconditional\c_scrn_interaction_no_contrastcolor
180
181\permanent\protected\def\resetinteractionstyleandcolor
182  {\c_scrn_interaction_no_style\conditionaltrue
183   \c_scrn_interaction_no_color\conditionaltrue
184   \c_scrn_interaction_no_contrastcolor\conditionaltrue}
185
186\permanent\protected\def\resetinteractionstyle
187  {\c_scrn_interaction_no_style\conditionaltrue}
188
189\permanent\protected\def\resetinteractioncolor
190  {\c_scrn_interaction_no_color\conditionaltrue
191   \c_scrn_interaction_no_contrastcolor\conditionaltrue}
192
193\permanent\protected\def\resetinteractioncontrastcolor
194  {\c_scrn_interaction_no_contrastcolor\conditionaltrue}
195
196\permanent\protected\def\restoreinteractionstyleandcolor
197  {\c_scrn_interaction_no_style\conditionalfalse
198   \c_scrn_interaction_no_color\conditionalfalse
199   \c_scrn_interaction_no_contrastcolor\conditionalfalse}
200
201\appendtoks
202    \iflocation
203      \restoreinteractionstyleandcolor
204    \fi
205\to \everybeforepagebody
206
207\permanent\protected\def\setlocationcolorspecified#1% not grouped !
208  {\ifconditional\c_scrn_interaction_no_color
209    % none of them
210   \orunless\ifconditional\c_scrn_interaction_no_contrastcolor
211     \useinteractioncolorparameter\c!color
212   \orelse\ifnum#1=\plusone
213     \edef\p_contrastcolor{\interactionparameter\c!contrastcolor}%
214     \ifempty\p_contrastcolor
215       \useinteractioncolorparameter\c!color
216     \else
217       \useinteractioncolorparameter\c!contrastcolor
218     \fi
219   \else % we could just set and if > 0 set again
220     \useinteractioncolorparameter\c!color
221   \fi}
222
223\permanent\protected\def\setlocationattributesspecified#1% not grouped !
224  {\ifconditional\c_scrn_interaction_no_color
225      \ifconditional\c_scrn_interaction_no_style
226      \else
227        \useinteractionstyleparameter\c!style
228      \fi
229   \orelse\ifnum#1=\plusone
230     \edef\p_contrastcolor{\interactionparameter\c!contrastcolor}%
231     \ifempty\p_contrastcolor
232       \useinteractionstyleandcolor\c!style\c!color
233     \else
234       \useinteractionstyleandcolor\c!style\c!contrastcolor
235     \fi
236   \else
237       \ifconditional\c_scrn_interaction_no_color
238         \useinteractionstyleparameter\c!style
239       \orelse\ifconditional\c_scrn_interaction_no_style
240         \useinteractioncolorparameter\c!color
241       \else
242         \useinteractionstyleandcolor\c!style\c!color
243       \fi
244   \fi}
245
246\permanent\protected\def\setlocationcolorspecspecified#1#2% \resolver
247  {\ifconditional\c_scrn_interaction_no_color
248    % none of them
249   \orunless\ifconditional\c_scrn_interaction_no_contrastcolor
250     \colo_helpers_activate{#2\c!color}%
251   \orelse\ifnum#1=\plusone
252     \edef\p_contrastcolor{#2\c!contrastcolor}%
253     \ifempty\p_contrastcolor
254       \colo_helpers_activate{#2\c!color}%
255     \else
256       \colo_helpers_activate\p_contrastcolor
257     \fi
258   \else
259     \colo_helpers_activate{#2\c!color}%
260   \fi}
261
262\permanent\protected\def\setlocationcolor     {\setlocationcolorspecified     \referencepagestate}
263\permanent\protected\def\setlocationattributes{\setlocationattributesspecified\referencepagestate}
264\permanent\protected\def\setlocationcolorspec {\setlocationcolorspecspecified \referencepagestate}
265
266\permanent\protected\def\setlocationfont % not grouped !
267  {\useinteractionstyleparameter\c!style}
268
269\setupinteraction
270  [\c!style=\v!bold,
271   \c!color=interactioncolor,
272   \c!contrastcolor=interactioncontrastcolor]
273
274%D Identity
275
276%D We want to delay the preroll as it needs fonts so we now actively fetch from
277%D the \LUA\ end. So this one gets called by the time we need the value.
278
279\def\scrn_identity_get#1%
280  {\setidentityvariable{#1}{\prerolltostring{\interactionparameter{#1}}}}
281
282% this comes before starttext
283
284\def\scrn_identity_document#1#2%
285  {\doifdocumentvariable{metadata:#1}{\setupinteraction[#2=\documentvariable{metadata:#1}]}}
286
287\appendtoks % not interfaced i.e. english
288    \scrn_identity_document   {title}\c!title
289    \scrn_identity_document {subject}\c!subtitle
290    \scrn_identity_document{subtitle}\c!subtitle
291    \scrn_identity_document  {author}\c!author
292    \scrn_identity_document {authors}\c!author
293    \scrn_identity_document {keyword}\c!keyword
294    \scrn_identity_document{keywords}\c!keyword
295    \scrn_identity_document    {date}\c!date
296\to \everystartdocument % or stop
297
298\appendtoks
299    \clf_setautoprefix{\interactionparameter\c!prefix}%
300\to \everysetupinteraction
301
302
303%D This setter is global, contrary to the interaction setting which is local. The values of
304%D these keys are only looked at when we finalize the document.
305
306\def\syst_set_metatdata_from_dummy#1%
307  {\ifempty{\dummyparameter#1}\else
308     \global\expandafter\letinteractionparameter\expandafter#1\lastnamedcs
309   \fi}
310
311\permanent\protected\def\setupmetadata[#1]%
312  {\begingroup
313   \resetdummyparameter\c!title
314   \resetdummyparameter\c!subtitle
315   \resetdummyparameter\c!author
316   \resetdummyparameter\c!keyword
317   \resetdummyparameter\c!date
318   \getdummyparameters[#1]%
319   \syst_set_metatdata_from_dummy\c!title
320   \syst_set_metatdata_from_dummy\c!subtitle
321   \syst_set_metatdata_from_dummy\c!author
322   \syst_set_metatdata_from_dummy\c!keyword
323   \syst_set_metatdata_from_dummy\c!date
324   \endgroup}
325
326\protect \endinput
327