summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mkiv/scrn-ini.mkvi
blob: 93dde6962db839284e602857ecd1152617ae07e3 (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
%D \module
%D   [       file=scrn-ini,
%D        version=2011.02.27,
%D          title=\CONTEXT\ Interaction Macros,
%D       subtitle=Initialization,
%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.

\writestatus{loading}{ConTeXt Interaction Macros / Initialization}

\unprotect

\registerctxluafile{scrn-ini}{1.001}

%D There is no interaction at all unless enabled by saying:
%D
%D \starttyping
%D \setupinteraction[state=start]
%D \stoptyping
%D
%D The other settings are:
%D
%D \showsetup{setupinteraction}

\installcorenamespace{interaction}

\installswitchcommandhandler \??interaction {interaction} \??interaction

\appendtoks
    \ifx\previousinteraction\empty
      \checkinteractionstate
    \else\ifx\currentinteraction\previousinteraction
      \checkinteractionstate
    \fi\fi
\to \everysetupinteraction

\unexpanded\def\checkinteractionstate
  {\doifelse{\interactionparameter\c!state}\v!start
     {\locationtrue  \setsystemmode  \v!interaction}%
     {\locationfalse \resetsystemmode\v!interaction}}

\def\doifelselocation % expandable
  {\iflocation
     \expandafter\firstoftwoarguments
   \else
     \expandafter\secondoftwoarguments
   \fi}

\let\doiflocationelse\doifelselocation

\setupinteraction
  [\c!state=\v!stop]

\appendtoks
    \setupinteraction % todo: remember info at the lua end (already possible)
\to \everyjob

% it makes no sense to create an environment as we will seldom have structured
% interactionso a general start-stop will do
%
% \appendtoks
%     \setuevalue         \currentinteraction {\scrn_interaction_direct{\currentinteraction}}%
%     \setuevalue{\e!start\currentinteraction}{\scrn_interaction_start {\currentinteraction}}%
%     \setuevalue{\e!stop \currentinteraction}{\scrn_interaction_stop                       }%
% \to \everydefineinteraction
%
% \unexpanded\def\scrn_interaction_direct#1%
%   {\edef\currentinteraction{#1}}
%
% \unexpanded\def\scrn_interaction_start#1%
%   {\pushmacro\currentinteraction
%    \edef\currentinteraction{#1}}
%
% \unexpanded\def\scrn_interaction_stop
%   {\popmacro\currentinteraction}
%
% \unexpanded\def\setinteraction[#1]%
%   {\def\currentinteraction{#1}}
%
% \defineinteraction[\v!interaction]

\unexpanded\def\startinteraction[#1]%
  {\pushmacro\currentinteraction
   \edef\currentinteraction{#1}}

\unexpanded\def\stopinteraction
  {\popmacro\currentinteraction}

\unexpanded\def\setinteraction[#1]%
  {\def\currentinteraction{#1}}

\defineinteraction % keep it simple
  [\v!hidden]

\setupinteraction
  [\v!hidden]
  [\c!state=\v!start,
   \c!color=,
   \c!contrastcolor=,
   \c!style=,
   \c!click=\v!off]

%D As long as there a natural feeling of what can be considered
%D hyper active or not, we have to tell users where they can
%D possibly click. We've already seen a few macros that deal
%D with this visualization, something we definitely do not let
%D up to the viewer. One way of telling is using a distinctive
%D typeface, another way is using color.
%D
%D There are two colors involved: one for normal hyperlinks,
%D and one for those that point to the currentpage, the
%D contrast color.

\definecolor [interactioncolor]         [r=0,  g=.6, b=0]
\definecolor [interactioncontrastcolor] [r=.8, g=0,  b=0]

%D The next few macros are responsible for highlighting hyper
%D links. The first one, \type{\showlocation}, is used in those
%D situations where the typeface is handled by the calling
%D macro.

%D When we're dealing with pure page references, contrast
%D colors are used when we are already at the page mentioned.

\unexpanded\def\setlocationcolorspecified#1% not grouped !
  {\ifnum#1=\plusone
     \edef\askedcontrastcolor{\interactionparameter\c!contrastcolor}%
     \ifx\askedcontrastcolor\empty
       \useinteractioncolorparameter\c!color
     \else
       \useinteractioncolorparameter\c!contrastcolor
     \fi
   \else % we could just set and if > 0 set again
     \useinteractioncolorparameter\c!color
   \fi}

\unexpanded\def\setlocationattributesspecified#1% not grouped !
  {\ifnum#1=\plusone
     \edef\askedcontrastcolor{\interactionparameter\c!contrastcolor}%
     \ifx\askedcontrastcolor\empty
       \useinteractionstyleandcolor\c!style\c!color
     \else
       \useinteractionstyleandcolor\c!style\c!contrastcolor
     \fi
   \else % we could just set and if > 0 set again
     \useinteractionstyleandcolor\c!style\c!color
   \fi}

\unexpanded\def\setlocationcolorspecspecified#1#2% \resolver
  {\ifnum#1=\plusone
     \edef\askedcontrastcolor{#2\c!contrastcolor}%
     \ifx\askedcontrastcolor\empty
       \colo_helpers_activate{#2\c!color}%
     \else
       \colo_helpers_activate\askedcontrastcolor
     \fi
   \else
     \colo_helpers_activate{#2\c!color}%
   \fi}

\unexpanded\def\setlocationcolor     {\setlocationcolorspecified     \referencepagestate}
\unexpanded\def\setlocationattributes{\setlocationattributesspecified\referencepagestate}
\unexpanded\def\setlocationcolorspec {\setlocationcolorspecspecified \referencepagestate}

\unexpanded\def\setlocationfont % not grouped !
  {\useinteractionstyleparameter\c!style}

\setupinteraction
  [\c!style=\v!bold,
   \c!color=interactioncolor,
   \c!contrastcolor=interactioncontrastcolor]

%D Identity

% \def\scrn_identity_synchronize
%   {\clf_setupidentity
%        title    {\interactionparameter\c!title}%
%        subtitle {\interactionparameter\c!subtitle}%
%        author   {\interactionparameter\c!author}%
%      % creator  {ConTeXt - \contextversion}%
%        date     {\interactionparameter\c!date}%
%        keywords {\interactionparameter\c!keyword}%
%    \relax}

\newconditional\c_scrn_identity_preroll

\installtexdirective
  {interaction.identity.preroll}
  {\settrue \c_scrn_identity_preroll}
  {\setfalse\c_scrn_identity_preroll}

\def\scrn_identity_prerolled#1%
  {\begingroup
   \edef\tempstring{\interactionparameter#1}%
   \ifx\tempstring\empty
     \endgroup
   \else
     \the\everypreroll
     \nodestostring\tempstring{\tempstring}%
     \normalexpanded{\endgroup\setexpandedinteractionparameter{#1}{\tempstring}}%
   \fi}

\def\scrn_identity_synchronize
  {\begingroup
   \ifconditional\c_scrn_identity_preroll
     \scrn_identity_prerolled\c!title
     \scrn_identity_prerolled\c!subtitle
     \scrn_identity_prerolled\c!author
     \scrn_identity_prerolled\c!date
     \scrn_identity_prerolled\c!keyword
   \fi
   \clf_setupidentity
       title    {\interactionparameter\c!title}%
       subtitle {\interactionparameter\c!subtitle}%
       author   {\interactionparameter\c!author}%
     % creator  {ConTeXt - \contextversion}%
       date     {\interactionparameter\c!date}%
       keywords {\interactionparameter\c!keyword}%
   \relax
   \endgroup}

\appendtoks
    \scrn_identity_synchronize
\to \everysetupinteraction

% this comes before starttext

\def\scrn_identity_document#1#2%
  {\doifvariable{document}{metadata:#1}{\setupinteraction[#2=\documentvariable{metadata:#1}]}}

\appendtoks % not interfaced i.e. english
    \scrn_identity_document   {title}\c!title
    \scrn_identity_document {subject}\c!subtitle
    \scrn_identity_document{subtitle}\c!subtitle
    \scrn_identity_document  {author}\c!author
    \scrn_identity_document {authors}\c!author
    \scrn_identity_document {keyword}\c!keyword
    \scrn_identity_document{keywords}\c!keyword
    \scrn_identity_document    {date}\c!date
\to \everysetupdocument

\setupinteraction
  [\c!title=,
   \c!subtitle=,
   \c!author=,
   \c!keyword=,
   \c!date=]

\protect \endinput