summaryrefslogtreecommitdiff
path: root/tex/context/base/scrn-nav.mkiv
blob: bc27cd973e6abe77750ff0840168d40f26fc75c4 (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
255
%D \module
%D   [       file=scrn-nav,
%D        version=1998.01.15,
%D          title=\CONTEXT\ Screen Macros,
%D       subtitle=Navigation,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%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 Screen Macros / Navigation}

\unprotect

%D Support for interactive document is very present in
%D \CONTEXT\ and interwoven in many modules. This means that in
%D this module, where we deal with some common navigational
%D features, there will be quite some forward references.
%D
%D The current support in \MKIV\ is mostly the same as in
%D \MKII\ and the old files have some more detailed
%D (sometimes historic) information.

%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}

% use with care, no checking done

\def\setinteractionparameter#1#2%
  {\expandafter\def\csname\??ia#1\endcsname{#2}}

\def\resetinteractionparameter#1%
  {\expandafter\let\csname\??ia#1\endcsname\empty}

\newtoks\everysetupinteraction

\unexpanded\def\setupinteraction
  {\dosingleargument\dodosetupinteraction}

\def\dodosetupinteraction[#1]% % \dosetupinteraction == special
  {\getparameters[\??ia][#1]%
   \the\everysetupinteraction}

% todo, move partial append to where the action happens

\appendtoks
  \doifelse\@@iastate\v!start
    {\iflocation\else
       \showmessage\m!interactions2{\ifusepagedestinations\space(PAGE)\fi}%
       \global\locationtrue
     \fi}%
    {\iflocation
       \showmessage\m!interactions3{\ifusepagedestinations\space(PAGE)\fi}%
       \global\locationfalse
     \fi}%
  \iflocation
    \setsystemmode  \v!interaction
  \else
    \resetsystemmode\v!interaction
  \fi
  \doifsomething\@@iacalculate
    {\doregistercalculationset\@@iacalculate}%
  \doifelse\@@iastrut  \v!yes \settrue \setfalse \uselocationstrut
  \doifelse\@@iaclick  \v!yes \settrue \setfalse \highlighthyperlinks
  \doifelse\@@iadisplay\v!new \settrue \setfalse \gotonewwindow
  \doifelse\@@iapage   \v!yes \settrue \setfalse \usepagedestinations
\to \everysetupinteraction

\def\synchronizebackendidentity
  {\ctxlua{backends.codeinjections.setupidentity{
     title    = \!!bs\@@iatitle\!!es,
     subject  = \!!bs\@@iasubtitle\!!es,
     author   = \!!bs\@@iaauthor\!!es,
     creator  = \!!bs ConTeXt - \contextversion\!!es,
     date     = \!!bs\@@iadate\!!es,
     keywords = \!!bs\@@iakeyword\!!es,
  }}}

\appendtoks
  \synchronizebackendidentity
\to \everyfirstshipout

%D We have to make sure of some settings:

\def\dolocationstartup
  {\iflocation
     \donefalse
     \ifx\@@iaopenaction\empty \else \donetrue
        \ctxlua{structures.references.checkopendocumentactions("\@@iaopenaction")}%
        \ctxlua{structures.references.expandcurrent()}%
     \fi
     \ifx\@@iacloseaction\empty \else \donetrue
        \ctxlua{structures.references.checkclosedocumentactions("\@@iacloseaction")}%
        \ctxlua{structures.references.expandcurrent()}%
     \fi
     \ifdone
        \ctxlua{structures.references.flushdocumentactions()}%
     \fi
     \global\let\dolocationstartup\relax
   \fi}

\def\dolocationpagecheck
  {\iflocation
     \donefalse
     \ifx\@@iaopenpageaction\empty \else \donetrue
        \ctxlua{structures.references.checkopenpageactions("\@@iaopenpageaction")}%
        \ctxlua{structures.references.expandcurrent()}%
     \fi
     \ifx\@@iaclosepageaction\empty \else \donetrue
        \ctxlua{structures.references.checkclosepageactions("\@@iaclosepageaction")}%
        \ctxlua{structures.references.expandcurrent()}%
     \fi
     \ifdone
        \ctxlua{structures.references.flushpageactions()}%
     \fi
   \fi}

\appendtoks \dolocationstartup   \to \everyshipout
\appendtoks \dolocationpagecheck \to \everyshipout

%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]

\definecolor [interactiekleur]          [interactioncolor]
\definecolor [interactiecontrastkleur]  [interactioncontrastcolor]

%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.

\def\setlocationcolor#1% not grouped !
  {\ifnum\referencepagestate=\plusone
     \edef\askedcontrastcolor{\csname#1\c!contrastcolor\endcsname}%
     \ifx\askedcontrastcolor\empty
       \dosetcolorattribute{#1}\c!color
     \else
       \dosetcolorattribute{#1}\c!contrastcolor
     \fi
   \else % we could just set and if > 0 set again
     \dosetcolorattribute{#1}\c!color
   \fi}

\def\setlocationfont#1%
  {\dosetfontattribute{#1}\c!style}

\def\setlocationattributes#1%
  {\ifnum\referencepagestate=\plusone
     \edef\askedcontrastcolor{\csname#1\c!contrastcolor\endcsname}%
     \ifx\askedcontrastcolor\empty
       \dosetcolorattribute{#1}\c!color
     \else
       \dosetcolorattribute{#1}\c!contrastcolor
     \fi
   \else % we could just set and if > 0 set again
     \dosetcolorattribute{#1}\c!color
   \fi
   \dosetfontattribute{#1}\c!style}

\def\setlocationcolorspec#1% \resolver
  {\ifnum\referencepagestate=\plusone
     \edef\askedcontrastcolor{#1\c!contrastcolor}%
     \ifx\askedcontrastcolor\empty
       \doactivatecolor{#1\c!color}%
     \else
       \doactivatecolor\askedcontrastcolor
     \fi
   \else
     \doactivatecolor{#1\c!color}%
   \fi}

%D delayed ...

\def\enableinteractivereferences
  {\ifproductionrun
     \ctxlua{structures.references.enableinteraction()}%
     \globallet\enableinteractivereferences\relax
   \fi}

\appendtoks
    \enableinteractivereferences
\to \everysetupinteraction

%D More tokens are spend when we want both typeface and color
%D highlighting.

\def\@@iatimestamp
  {\the\normalyear
   \ifnum\normalmonth<10 0\fi\the\normalmonth
   \ifnum\normalday  <10 0\fi\the\normalday}

\setupinteraction % start fit page and reset form
  [\c!state=\v!stop,
   \c!page=\v!no,
   \c!click=\v!yes,
   \c!openaction=,
   \c!closeaction=,
   \c!openpageaction=,
   \c!closepageaction=,
   \c!display=\v!normal,
   \c!focus=\v!fit,
   \c!menu=\v!off,
   \c!style=\v!bold,
   \c!calculate=,
   \c!strut=\v!yes,
   \c!split=\v!yes,
   \c!color=interactioncolor,
   \c!contrastcolor=interactioncontrastcolor,
   \c!symbolset=,
   \c!width=1em,
   \c!height=\!!zeropoint,
   \c!depth=\!!zeropoint,
   \c!title=\jobname, % needed for fdf/x
   \c!subtitle=,
   \c!author=,
   \c!keyword=,
   \c!date=\@@iatimestamp]

%D XMP support:

\setupinteraction
  [xmpfile=]

\appendtoks
    % this will move as it is a backend issue
    \doifsomething\@@iaxmpfile
      {\ctxlua{if lpdf then lpdf.setxmpfile("\@@iaxmpfile") end}%
       \globallet\@@iaxmpfile\empty}%
\to \everysetupinteraction

\protect \endinput