scrn-ini.mklx /size: 6700 b    last modification: 2024-01-16 09: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\permanent\protected\def\setlocationcolor     {\setlocationcolorspecified     \referencepagestate}
178\permanent\protected\def\setlocationattributes{\setlocationattributesspecified\referencepagestate}
179\permanent\protected\def\setlocationcolorspec {\setlocationcolorspecspecified \referencepagestate}
180
181\permanent\protected\def\setlocationfont % not grouped !
182  {\useinteractionstyleparameter\c!style}
183
184\setupinteraction
185  [\c!style=\v!bold,
186   \c!color=interactioncolor,
187   \c!contrastcolor=interactioncontrastcolor]
188
189%D Identity
190
191%D We want to delay the preroll as it needs fonts so we now actively fetch from
192%D the \LUA\ end. So this one gets called by the time we need the value.
193
194\def\scrn_identity_get#1%
195  {\setidentityvariable{#1}{\prerolltostring{\interactionparameter{#1}}}}
196
197% this comes before starttext
198
199\def\scrn_identity_document#1#2%
200  {\doifdocumentvariable{metadata:#1}{\setupinteraction[#2=\documentvariable{metadata:#1}]}}
201
202\appendtoks % not interfaced i.e. english
203    \scrn_identity_document   {title}\c!title
204    \scrn_identity_document {subject}\c!subtitle
205    \scrn_identity_document{subtitle}\c!subtitle
206    \scrn_identity_document  {author}\c!author
207    \scrn_identity_document {authors}\c!author
208    \scrn_identity_document {keyword}\c!keyword
209    \scrn_identity_document{keywords}\c!keyword
210    \scrn_identity_document    {date}\c!date
211\to \everystartdocument % or stop
212
213\appendtoks
214    \clf_setautoprefix{\interactionparameter\c!prefix}%
215\to \everysetupinteraction
216
217\protect \endinput
218