summaryrefslogtreecommitdiff
path: root/tex/context/base/scrn-nav.mkii
blob: 3bb56bacee7ada17c814a34bd20bd4e4d12c2549 (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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
%D \module
%D   [       file=scrn-nav,
%D        version=1998.01.15,
%D          title=\CONTEXT\ Core Macros,
%D       subtitle=Navigation,
%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 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 When I started implementing hypertext support, the macros
%D were mostly dealing with things related to locations, that
%D is click in this location and goto that one. The
%D functionality of many macro depends on the output medium:
%D paper or screen. The next boolean holds the state:

\newif\iflocation  \def\ifinteractief{\iflocation} % upw comp

%D We also allocate a scratchbox:

\newbox\locationbox

%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}
%D
%D In the special driver modules we introduced a switch that
%D forces page destinations (instead of named ones). We set
%D this switch here.

\def\setinteractionparameter#1#2% use with case, no checking done
  {\setvalue{\??ia#1}{#2}}      % pass #2, can be \blabla

\def\resetinteractionparameter#1% use with case, no checking done
  {\letvalue{\??ia#1}\empty}

% \def\interactionparameter#1%
%   {\csname\??ia#1\endcsname}

\newtoks\everysetupinteraction

\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
  \dosetuppageview\@@iafocus
  \doifsomething\@@iacalculate
    {\doregistercalculationset\@@iacalculate}%
  \doifelse\@@iastrut\v!yes
    \locationstruttrue
    \locationstrutfalse
  \doifelse\@@iaclick\v!yes
    \highlighthyperlinkstrue
    \highlighthyperlinksfalse
  \doifelse\@@iasplit\v!yes
    \locationsplittrue
    \locationsplitfalse
  \doifelse\@@iadisplay\v!new
    \gotonewwindowtrue
    \gotonewwindowfalse
  \doifelse\@@iapage\v!yes
    {\global\usepagedestinationstrue}
    {\global\usepagedestinationsfalse}%
\to \everysetupinteraction

%D We have to make sure of some settings:

\def\dolocationstartup
  {\iflocation
     \dosetupinteraction
     \handlereferenceactions\@@iaopenaction \dosetupopenaction
     \handlereferenceactions\@@iacloseaction\dosetupcloseaction
     \setupinteractionscreens
     \global\let\dolocationstartup\relax
   \fi}

\appendtoks \dolocationstartup \to \everyshipout

\def\dolocationpagecheck % brr pdf dependent
  {\iflocation
     \handlereferenceactions\@@iaopenpageaction \dosetupopenpageaction
     \handlereferenceactions\@@iaclosepageaction\dosetupclosepageaction
   \fi}

\appendtoks \dolocationpagecheck \to \everyshipout

%D The next few macros are really horrible. For proper
%D navigation a in||line hypertext fragment must have
%D comfortable properties, so we must force some minimal
%D dimensions. On the other hand button, and here I mean those
%D pieces of text with fancy outlines and/or backgrounds, often
%D have fixed, preset dimensions.
%D
%D To make things even worse, if we choose to let the optimal
%D dimensions depend on the height and depth of a strut, a not
%D too uncommon practice in \TEX, we have to deal with the fact
%D that such a strut, set inside a box, is unknown too the
%D outside world.
%D
%D The solution lays in passing the strut characteristics in
%D a proper way, in our case by applying \type{\presetgoto}:
%D
%D \starttyping
%D {some piece of text \presetgoto}
%D \stoptyping
%D
%D This macro stores the current strut values.

\newif\iflocationstrut
\newif\iflocationsplit

\def\resetgoto
  {\globallet\@@ia@@hoogte\!!zeropoint
   \globallet\@@ia@@diepte\!!zeropoint}

\resetgoto

\def\presetgoto
  {\iflocationstrut
     \setstrut
    %\xdef\@@ia@@hoogte{\the\strutht}%
    %\xdef\@@ia@@diepte{\the\strutdp}%
     \globallet\@@ia@@hoogte\strutheight
     \globallet\@@ia@@diepte\strutdepth
   \else
     \globallet\@@ia@@hoogte\@@iaheight
     \globallet\@@ia@@diepte\@@iadepth
   \fi}

%D In the macros that deal with making areas into hyperlinks,
%D we use:

\newbox\driverresources

\def\collectdriverresource#1%
  {\global\setbox\driverresources\hbox{\box\driverresources#1}}

\def\flushdriverresources
  {\ifvoid\driverresources\else\box\driverresources\fi}

\def\dohandlegoto#1#2#3%
  {\ifsecondaryreference
     \bgroup\setbox0\hbox{#2#3}\egroup
   \else
     \hbox
       {\setbox0\hbox{#1}%
        \ifdim\wd0<\@@iawidth\relax
          \buttonwidth\@@iawidth\relax
        \else
          \buttonwidth\wd0
        \fi
        \ifdim\ht0<\@@ia@@hoogte\relax
          \buttonheight\@@ia@@hoogte\relax
        \else
          \buttonheight\ht0
        \fi
        \ifdim\dp0<\@@ia@@diepte\relax
          \dimen0=\@@ia@@diepte\relax % = !
        \else
          \dimen0\dp0
        \fi
        \advance\buttonheight \dimen0
        \setbox2\hbox
          {\lower\dimen0\hbox
             {\dontcomplain
              \dimen0=.5\wd0 % direct skipping is faster of course
              \advance\dimen0 -.5\buttonwidth % buts this is nicer
              \hskip\dimen0#2#3}}% when visualizing things
        \naturalhbox % needed for omega / moved from plus-omg
          {\ifreversegoto
             \dimen0\wd0\box0\kern-\dimen0\smashbox2\box2\kern\dimen0
           \else
             \smashbox2\box2\box0
           \fi
           \flushdriverresources}%
        \resetgoto}%
   \fi}

%D The secondary references are processed but not typeset. The
%D special driver must collect the data needed.

%D The width of the active area depends on the dimensions
%D preset, the actual dimens and/or the height and depth of the
%D strut.
%D
%D Normally the hyper active area is laid on top of the text.
%D This enables stacking hyperlinks on top of each other. When,
%D for some reason the opposite is prefered, one can use the
%D next boolean to signal this wish.

\newif\ifreversegoto \reversegotofalse

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

\def\interactioncolor % todo \??ia as argument
  {\iflocation
     \ifrealreferencepage
       \@@iacontrastcolor
     \else
       \@@iacolor
     \fi
   \fi}

%D CHECK WHERE USED / CONSISTENCY

\def\showlocation#1%
  {\iflocation\color[\@@iacolor]{#1\presetgoto}\else#1\fi}

%D When local color settings are to be used, we can use the
%D next macro, where \type{#1} is a tag like \type{\??tg} and
%D \type{#2} some text.

\def\showcoloredlocation#1#2%
  {\iflocation
     \color[\getvalue{#1\c!color}]{#2\presetgoto}%
   \else
     #2%
   \fi}

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

\def\showcontrastlocation#1#2#3% the \@EA is needed
  {\iflocation
     \ifnum#2=\realpageno\relax
       \doifelsevaluenothing{#1\c!color}
         {#3\presetgoto}
         {\color[\getvalue{#1\c!contrastcolor}]{#3\presetgoto}}%
     \else
       \color[\getvalue{#1\c!color}]{#3\presetgoto}%
     \fi
   \else
     #3%
   \fi}

%D The next simple macro can be used in color specifications,
%D like \type{\color[\locationcolor{green}]}.

\def\locationcolor#1%
  {\iflocation#1\fi}

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

\def\dolocationattributes#1#2#3#4%
  {\bgroup
   \let\fontattribute\empty
   \let\colorattribute\empty
   \doifdefined{#1#2}{\def\fontattribute{\getvalue{#1#2}}}%
   \iflocation
     \doifdefined{#1#3}{\def\colorattribute{\getvalue{#1#3}}}%
   \fi
   \startcolor[\colorattribute]%
   \@EA\doconvertfont\@EA{\fontattribute}{#4}% no \edef, but \@EA here
   \stopcolor
   \egroup}

\def\navigating
  {\dolocationattributes\??ia\c!style\c!color}

%D Although not decently supported in current viewers, a
%D provisory hiding mechanims is implemented. Areas marked as
%D such, are visible on screen, but invisible on paper. Don't
%D trust this mechanism yet!

\def\dostartinteraction
  {\bgroup
   \let\stopinteraction\egroup
   \dowithnextbox{\dostarthide\flushnextbox\dostophide\egroup}\hbox}

\let\startinteraction = \relax
\let\stopinteraction  = \relax

% in the future:
%
% eerst boolean invoeren bij menu, achtergrond, balk, button
% enz; verder startinteractie een argument meegeven {#1} ->
% \getvalue{#1\c!print}=={\v!ja} enz. Consequent menubutton
% gebruiken!

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

% happens in core-fld
%
% \definereference [AtOpenInitializeForm] [\v!geen]

\setupinteraction % start fit page and reset form
  [\c!state=\v!stop,
   \c!page=\v!no,
   \c!click=\v!yes,
   \c!display=,
  %\c!openaction={\v!firstpage,AtOpenInitializeForm},
  %\c!openaction={\v!firstpage,\v!ResetForm},
  %\c!openaction=\v!ResetForm, % too buggy in reader 4.05
   \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]

\protect \endinput