summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mkiv/scrn-wid.mkvi
blob: c74125c72b6543b56c055f24eb3359e89dac1d7c (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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
%D \module
%D   [       file=scrn-int,
%D        version=2011.02.27, % moved from scrn-int
%D          title=\CONTEXT\ Core Macros,
%D       subtitle=Widgets,
%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 / Widgets}

\registerctxluafile{scrn-wid}{}

% todo: expansion in comments (default is expanded)
% todo: check renderings ... acrobat crashes too easily on missing one

\unprotect

%D Attachments (mkiv upgraded):
%D
%D As usual in \CONTEXT\ we separate the general definition (frontend)
%D and the rendering (backend).

% old but stil valid method:
%
% \useattachment[test.tex]
% \useattachment[whatever][test.tex]
% \useattachment[whatever][newname][test.tex]
% \useattachment[whatever][title][newname][test.tex]
%
% new method:
%
% \registerattachment[sometag][specification] % name file author title subtitle
%
% \attachment[sometag][extra specs]
% \attachment[test.tex]
% \attachment[file=test.tex]
% \attachment[file=test.tex,method=hidden]
% \attachment[name=newname,file=test.tex]
% \attachment[title=mytitle,name=newname,file=test.tex]
%
% indirect
%
% \defineattachment[whatever5][file=test.tex] \attachment[whatever5][method=hidden]
% \defineattachment[whatever5][file=test.tex,method=hidden] \attachment[whatever5]
%
% direct (no definitions)
%
% \attachment[test][file=oeps.tex,title=Oeps,author=Hans,subtitle=TeX File,method=hidden]
% \attachment[label=test,file=oeps.tex,title=Oeps,author=Hans,subtitle=TeX File,method=hidden]
%
% autolabel:
%
% \attachment[file=oeps.tex,title=Oeps,author=Hans,subtitle=TeX File,method=hidden]
%
% % \setupattachments[\c!symbol={symbol-normal,symbol-down}]

% startattachment -> temp file

\newbox\b_scrn_attachment_collect
\newbox\b_scrn_attachment_link
\newbox\b_scrn_attachment_symbol

\installcorenamespace{attachment}
\installcorenamespace{attachmentlocation}
\installcorenamespace{attachmentmethod}

\installcommandhandler \??attachment {attachment} \??attachment

\let\setupattachments\setupattachment % convenience and compatibility

\setupattachment
  [\c!state=\v!start,
   \c!color=\interactionparameter\c!color,
  %\c!textlayer=,
  %\c!symbol=,
  %\c!title=,
  %\c!subtitle=,
  %\c!file=, % input filename
  %\c!name=, % new filename
  %\c!author=,
  %\c!method=, % \v!hidden = not in menu
  %\c!buffer=
   \c!symbol=,
   \c!distance=\emwidth,
   \c!width=\v!fit,
   \c!height=\v!fit,
   \c!depth=\v!fit,
   \c!location=\v!high]

\unexpanded\def\registerattachment
  {\dodoubleempty\scrn_attachment_register}

\def\scrn_attachment_register[#tag][#settings]% we save (globally) at the lua end
  {\ifsecondargument
     \begingroup
     \def\currentattachment{_}%
     \setupcurrentattachment[#settings,\s!parent=\??attachment]%
     \clf_registerattachment
        tag        {#tag}%
        registered {#tag}%
        title      {\attachmentparameter\c!title}%
        subtitle   {\attachmentparameter\c!subtitle}%
        author     {\attachmentparameter\c!author}%
        file       {\attachmentparameter\c!file}%
        name       {\attachmentparameter\c!name}%
        buffer     {\attachmentparameter\c!buffer}%
     \relax
     \endgroup
   \else
     % todo
   \fi}

\appendtoks
    \setuevalue         \currentattachment {\scrn_attachment_direct{\currentattachment}}%
    \setuevalue{\e!start\currentattachment}{\scrn_attachment_start {\currentattachment}}%
    \setuevalue{\e!stop \currentattachment}{\scrn_attachment_stop                     }%
\to \everydefineattachment

\unexpanded\def\scrn_attachment_direct#tag%
  {\edef\currentattachment{#tag}%
   \doifelselocation
     {\dodoubleempty\scrn_attachment_direct_status}
     {\dodoubleempty\scrn_attachment_direct_ignore}}

\def\scrn_attachment_direct_status
  {\doifelse{\attachmentparameter\c!state}\v!start
     \scrn_attachment_direct_indeed
     \scrn_attachment_direct_ignore}

\def\scrn_attachment_direct_indeed[#registered][#settings]%
  {\bgroup
   \doifelsenothing{#registered}
      {\scrn_attachment_inject[\v!auto][]}
      {\doifelseassignment{#registered}
         {\scrn_attachment_inject[\v!auto][#registered]}
         {\scrn_attachment_inject[#registered][#settings]}}%
   \egroup}

\def\scrn_attachment_direct_ignore[#tag][#settings]%
  {}

\unexpanded\def\scrn_attachment_start#tag%
  {\edef\currentattachment{#tag}%
   \doifelselocation
     {\dodoubleempty\scrn_attachment_start_indeed}
     {\dodoubleempty\scrn_attachment_start_ignore}}

\unexpanded\def\scrn_attachment_stop
  {}

\def\scrn_attachment_start_indeed
  {\doif{\attachmentparameter\c!state}\v!start
     {\scrn_attachment_start_indeed}
     {\scrn_attachment_start_ignore}}

\def\scrn_attachment_start_indeed[#registered][#settings]%
  {\bgroup
   \doifelsenothing{#registered}
     {\def\scrn_attachment_stop{\scrn_attachment_inject[\v!auto][\c!buffer=\v!attachment]\egroup}}%
     {\doifelseassignment{#registered}
        {\def\scrn_attachment_stop{\scrn_attachment_inject[\v!auto][\c!buffer=\v!attachment,#registered]\egroup}}%
        {\def\scrn_attachment_stop{\scrn_attachment_inject[#registered][\c!buffer=\v!attachment,#settings]\egroup}}}%
   \grabbufferdatadirect\v!attachment{\e!start\currentattachment}{\e!stop\currentattachment}}

\def\scrn_attachment_start_ignore
  {\expandafter\gobbleuntil\csname\e!stop\currentattachment\endcsname}

\def\scrn_attachment_inject[#registered][#settings]%
  {\edef\currentattachmentregistered{#registered}%
   \setupattachment[\currentattachment][#settings]%
   \expandnamespaceparameter\??attachmentmethod\attachmentparameter\c!method\v!normal}

\setvalue{\??attachmentmethod\v!normal}%
  {\edef\currentattachmentsymbol{\attachmentparameter\c!symbol}%
   \edef\currentattachmentwidth {\attachmentparameter\c!width }%
   \edef\currentattachmentheight{\attachmentparameter\c!height}%
   \edef\currentattachmentdepth {\attachmentparameter\c!depth }%
   \ifx\currentattachmentsymbol\empty
     \ifx\currentattachmentwidth \v!fit\edef\currentattachmentwidth {.5\emwidth}\fi
     \ifx\currentattachmentheight\v!fit\edef\currentattachmentheight{.5\emwidth}\fi
     \ifx\currentattachmentdepth \v!fit\let \currentattachmentdepth \zeropoint\fi
   \else
     \clf_presetsymbollist{\attachmentparameter\c!symbol}%
     % we cannot yet ask for the wd/ht/dp of an xform else we could use those
     \setbox\b_scrn_attachment_symbol\hbox{\symbol[\lastpredefinedsymbol]}%
     \ifx\currentattachmentwidth \v!fit\edef\currentattachmentwidth {\wd\b_scrn_attachment_symbol}\fi
     \ifx\currentattachmentheight\v!fit\edef\currentattachmentheight{\ht\b_scrn_attachment_symbol}\fi
     \ifx\currentattachmentdepth \v!fit\edef\currentattachmentdepth {\dp\b_scrn_attachment_symbol}\fi
   \fi
   \clf_insertattachment
     tag               {\currentattachment}%
     registered        {\currentattachmentregistered}%
     width             \dimexpr\currentattachmentwidth \relax
     height            \dimexpr\currentattachmentheight\relax
     depth             \dimexpr\currentattachmentdepth \relax
     color             {\attachmentparameter\c!color}%
     colormodel        \attribute\colormodelattribute
     colorvalue        \numexpr\thecolorattribute{\attachmentparameter\c!color}\relax % or are these chardefs
     transparencyvalue \numexpr\thetransparencyattribute{\attachmentparameter\c!color}\relax % or are these chardefs
     symbol            {\currentattachmentsymbol}%
     layer             {\attachmentparameter\c!textlayer}%
     % these will be overloaded by registered when available
     title             {\attachmentparameter\c!title}%
     subtitle          {\attachmentparameter\c!subtitle}%
     author            {\attachmentparameter\c!author}%
     file              {\attachmentparameter\c!file}%
     name              {\attachmentparameter\c!name}%
     buffer            {\attachmentparameter\c!buffer}%
   \relax
   \setbox\b_scrn_attachment_link\hbox{\scrn_attachment_place}%
   \wd\b_scrn_attachment_link\currentattachmentwidth
   \ht\b_scrn_attachment_link\currentattachmentheight
   \dp\b_scrn_attachment_link\currentattachmentdepth
   \box\b_scrn_attachment_link}

\setvalue{\??attachmentmethod\v!hidden}%
  {\clf_insertattachment
     tag        {\currentattachment}%
     registered {\currentattachmentregistered}%
     method     {\v!hidden}%
     title      {\attachmentparameter\c!title}%
     subtitle   {\attachmentparameter\c!subtitle}%
     author     {\attachmentparameter\c!author}%
     file       {\attachmentparameter\c!file}%
     name       {\attachmentparameter\c!name}%
     buffer     {\attachmentparameter\c!buffer}%
   \relax}

\def\scrn_attachment_place
  {\executeifdefined
     {\??attachmentlocation\attachmentparameter\c!location}\hbox
     {\box\b_scrn_attachment_link}}

\setvalue{\??attachmentlocation\v!inmargin   }{\inmargin     }
\setvalue{\??attachmentlocation\v!leftedge   }{\inleftedge   }
\setvalue{\??attachmentlocation\v!rightedge  }{\inrightedge  }
\setvalue{\??attachmentlocation\v!leftmargin }{\inleftmargin }
\setvalue{\??attachmentlocation\v!rightmargin}{\inrightmargin}
\setvalue{\??attachmentlocation\v!high       }{\high}
\setvalue{\??attachmentlocation\v!none       }{\scrn_attachment_collect}
%setvalue{\??attachmentlocation\v!text       }{\gobblenextargument} % gobbles the box

\def\scrn_attachment_collect#content%
  {\global\setbox\b_scrn_attachment_collect\hbox\bgroup
     \ifvoid\b_scrn_attachment_collect\else
       \box\b_scrn_attachment_collect
       \hskip\attachmentparameter\c!distance\relax
     \fi
     #content%
   \egroup}

\unexpanded\def\placeattachments
  {\ifvoid\b_scrn_attachment_collect\else
     \box\b_scrn_attachment_collect
   \fi}

\defineattachment[attachment]

% \ifx\currentinterface\defaultinterface \else
%     \defineattachment[\v!attachment]
% \fi

% backward compatible:

\unexpanded\def\useattachment
  {\doquadrupleempty\scrn_attachment_use}

\def\scrn_attachment_use[#tag][#title][#name][#file]%
  {\iffourthargument
     \registerattachment[#tag][title=#title,name=#name,file=#file]%
   \else\ifthirdargument
     \registerattachment[#tag][title=#title,name=#title,file=#name]%
   \else\ifsecondargument
     \registerattachment[#tag][title=#title,name=#title,file=#title]%
   \else
     \registerattachment[#tag][title=#tag,name=#tag,file=#tag]%
   \fi\fi\fi}

%D Comments:

% test
%
% \startcomment
%   hello beautiful\\world
% \stopcomment
%
% test
%
% \startcomment[hello]
%   hello << eerste >>
%   beautiful
%   world
% \stopcomment
%
% test
%
% \startcomment[hello][color=green,width=10cm,height=3cm]
%   hello
%   beautiful
%   world
% \stopcomment
%
% test
%
% \startcomment[hello][color=red,width=4cm,height=3cm]
%   hello
%
%   beautiful
%
%   world
% \stopcomment
%
% test
%
% \startcomment[symbol=Balloon]
%   Do we want this kind of rubish?
% \stopcomment
%
% test
%
% \definesymbol [comment-normal][{\externalfigure[cow.pdf]}]
% \definesymbol [comment-down]  [{\externalfigure[cow.pdf]}]
%
% \def\CowSymbol#1#2%
%  {\scale
%     [\c!height=#1]
%     {\startMPcode
%        loadfigure "koe.mp" number 1 ;
%        refill currentpicture withcolor #2 ;
%      \stopMPcode}}
%
% \definesymbol [comment-normal]
%   [\CowSymbol{4ex}{red}]
%
% \definesymbol [comment-down]
%   [\CowSymbol{4ex}{green}]
%
% \setupcomment
%   [\c!symbol={comment-normal,comment-down},
%    \c!option=\v!buffer]
%
% \startcomment[hello]
%     oeps
% \stopcomment
%
% test
%
% \setupcomment
%   [\c!symbol=normal,
%    \c!option=max,width=10cm]
%
% \startcomment[hello]
%     oeps
% \stopcomment
%
% test

\installcorenamespace{comment}
\installcorenamespace{commentlocation}

\installcommandhandler \??comment {comment} \??comment

\newbox\b_scrn_comment_collect
\newbox\b_scrn_comment_rendering
\newbox\b_scrn_comment_link
\newbox\b_scrn_comment_symbol

\setupcomment
  [\c!state=\v!start,
   \c!distance=\emwidth,
   \c!color=\interactionparameter\c!color,
   \c!space=\v!no,
   \c!symbol=,
  %\c!title=,
  %\c!option=,
  %\c!textlayer=,
   \c!width=\v!fit,
   \c!height=\v!fit,
   \c!depth=\v!fit,
   \c!nx=40,
   \c!ny=10,
   \c!buffer=\v!comment,
   \c!location=\v!high]

\appendtoks
    \setuevalue         \currentcomment {\scrn_comment_argument{\currentcomment}}%
    \setuevalue{\e!start\currentcomment}{\scrn_comment_start   {\currentcomment}}%
    \setuevalue{\e!stop \currentcomment}{\scrn_comment_stop                     }%
\to \everydefinecomment

\unexpanded\def\scrn_comment_argument#category%
  {\def\currentcomment{#category}%
   \doifelselocation
     {\dodoubleempty\scrn_comment_argument_status}
     {\dodoubleempty\scrn_comment_argument_ignore}}

\def\scrn_comment_argument_status
  {\doifelse{\commentparameter\c!state}\v!start
     \scrn_comment_argument_indeed
     \scrn_comment_argument_ignore}

\def\scrn_comment_argument_indeed[#title][#settings]#text%
  {\doifelseassignment{#title}
     {\setupcurrentcomment[#title]}
     {\setupcurrentcomment[\c!title=#title,#settings]}%
   \clf_assignbuffer{\v!comment}{#text}\catcodetable\relax% todo: expansion control, but expanded by default (xml)
   \scrn_comment_inject
   \ignorespaces}

\def\scrn_comment_argument_ignore[#title][#settings]#text%
  {\ignorespaces}

\unexpanded\def\scrn_comment_start#category%
  {\def\currentcomment{#category}%
   \doifelselocation
     {\dodoubleempty\scrn_comment_start_status}
     {\dodoubleempty\scrn_comment_start_ignore}}

\def\scrn_comment_start_status
  {\doifelse{\commentparameter\c!state}\v!start
     {\scrn_comment_start_indeed}
     {\scrn_comment_start_ignore}}

\def\scrn_comment_start_indeed[#title][#settings]%
  {\bgroup
   \doifelseassignment{#title}
     {\setupcurrentcomment[#title]}
     {\setupcurrentcomment[\c!title=#title,#settings]}%
   \unexpanded\def\scrn_comment_stop{\scrn_comment_inject\egroup}%
   \grabbufferdatadirect\v!comment{\e!start\currentcomment}{\e!stop\currentcomment}}

\def\scrn_comment_start_ignore
  {\expandafter\gobbleuntil\csname\e!stop\currentcomment\endcsname}

\unexpanded\def\scrn_comment_stop
  {}

\installcorenamespace{commentmethods}

\unexpanded\def\scrn_comment_inject
  {\expandnamespaceparameter\??commentmethods\commentparameter\c!method\v!normal}

%D Beware: comments symbols don't scale in acrobat (cf. spec but somewhat
%D weird, esp because for instance attachment symbols do scale).

\setvalue{\??commentmethods\v!normal}%
  {\edef\currentcommentsymbol{\commentparameter\c!symbol}%
   \edef\currentcommentwidth {\commentparameter\c!width }%
   \edef\currentcommentheight{\commentparameter\c!height}%
   \edef\currentcommentdepth {\commentparameter\c!depth }%
   \ifx\currentcommentsymbol\empty
     \ifx\currentcommentwidth \v!fit\edef\currentcommentwidth {.5\emwidth}\fi
     \ifx\currentcommentheight\v!fit\edef\currentcommentheight{.5\emwidth}\fi
     \ifx\currentcommentdepth \v!fit\let \currentcommentdepth \zeropoint\fi
   \else
     \clf_presetsymbollist{\commentparameter\c!symbol}%
     % we cannot yet ask for the wd/ht/dp of an xform else we could use those
     \setbox\b_scrn_comment_symbol\hbox{\symbol[\lastpredefinedsymbol]}%
     \ifx\currentcommentwidth \v!fit\edef\currentcommentwidth {\wd\b_scrn_comment_symbol}\fi
     \ifx\currentcommentheight\v!fit\edef\currentcommentheight{\ht\b_scrn_comment_symbol}\fi
     \ifx\currentcommentdepth \v!fit\edef\currentcommentdepth {\dp\b_scrn_comment_symbol}\fi
   \fi
   \clf_insertcomment
     tag               {\currentcomment}%
     title             {\commentparameter\c!title}%
     subtitle          {\commentparameter\c!subtitle}%
     author            {\commentparameter\c!author}%
     width             \dimexpr\currentcommentwidth\relax
     height            \dimexpr\currentcommentheight\relax
     depth             \dimexpr\currentcommentdepth\relax
     nx                {\commentparameter\c!nx}%
     ny                {\commentparameter\c!ny}%
     colormodel        \attribute\colormodelattribute
     colorvalue        \numexpr\thecolorattribute{\commentparameter\c!color}\relax
     transparencyvalue \numexpr\thetransparencyattribute{\commentparameter\c!color}\relax
     option            {\commentparameter\c!option}% % todo
     symbol            {\commentparameter\c!symbol}%
     buffer            {\commentparameter\c!buffer}% {\v!comment}%
     layer             {\commentparameter\c!textlayer}%
     space             {\commentparameter\c!space}%
   \relax
   \wd\b_scrn_comment_link\currentcommentwidth
   \ht\b_scrn_comment_link\currentcommentheight
   \dp\b_scrn_comment_link\currentcommentdepth
   \expandnamespaceparameter\??commentlocation\commentparameter\c!location\s!unknown}

\setvalue{\??commentmethods\v!hidden}%
  {}

% todo: dedicated margin classes

\setvalue{\??commentlocation\v!inmargin   }{\inmargin     {\box\b_scrn_comment_link}}
\setvalue{\??commentlocation\v!leftedge   }{\inleftedge   {\box\b_scrn_comment_link}}
\setvalue{\??commentlocation\v!rightedge  }{\inrightedge  {\box\b_scrn_comment_link}}
\setvalue{\??commentlocation\v!leftmargin }{\inleftmargin {\box\b_scrn_comment_link}}
\setvalue{\??commentlocation\v!rightmargin}{\inrightmargin{\box\b_scrn_comment_link}}
\setvalue{\??commentlocation\v!high       }{\high         {\box\b_scrn_comment_link}}

\setvalue{\??commentlocation\v!none}%
  {\global\setbox\b_scrn_comment_collect\hbox\bgroup
     \ifvoid\b_scrn_comment_collect\else
       \box\b_scrn_comment_collect
       \hskip\commentparameter\c!distance\relax
     \fi
     \box\b_scrn_comment_link
   \egroup}

\setvalue{\??commentlocation\s!unknown}%
  {\ifvoid\b_scrn_comment_collect\else
     \box\b_scrn_comment_collect
   \fi}

\unexpanded\def\placecomments
  {\ifvoid\b_scrn_comment_collect\else
     \box\b_scrn_comment_collect
   \fi}

\definecomment[comment]

% \ifx\currentinterface\defaultinterface \else
%     \definecomment[\v!comment]
% \fi

%D Soundclips:
%D
%D Defining sound tracks:
%D
%D \starttyping
%D \useexternalsoundtrack[label][file]
%D \stoptyping
%D
%D associated actions: StartSound StopSound PauseSound ResumeSound
%D
%D Todo: like external figures, also search on path,
%D although, they need to be present ar viewing time, so ...

\installcorenamespace{externalsoundtracks}

\installsetuponlycommandhandler \??externalsoundtracks {externalsoundtracks}

\setupexternalsoundtracks
  [\c!option=]

\unexpanded\def\useexternalsoundtrack
  {\dodoubleargument\scrn_soundtrack_indeed}

\def\scrn_soundtrack_indeed[#tag][#filename]%
  {\clf_registersoundclip
     tag  {#tag}%
     file {#filename}%
   \relax}

\def\checksoundtrack#tag% yet untested in mkiv (also move management to lua)
  {\iflocation
     \clf_insertsoundclip
       tag    {#tag}%
       repeat {\directexternalsoundtrackparameter\c!option}%
     \relax
   \fi}

%D Renderings (not yet tested in mkvi):

% Todo: multiple instances and inheritance .. will be done when
% needed i.e. when I see usage.

\let\currentrendering\empty

\definereference[StartCurrentRendering] [\v!StartRendering {\currentrendering}]
\definereference[StopCurrentRendering]  [\v!StopRendering  {\currentrendering}]
\definereference[PauseCurrentRendering] [\v!PauseRendering {\currentrendering}]
\definereference[ResumeCurrentRendering][\v!ResumeRendering{\currentrendering}]

\unexpanded\def\useexternalrendering{\doquadrupleempty\scrn_rendering_use}
\unexpanded\def\setinternalrendering{\dodoubleempty   \scrn_rendering_set}

\def\scrn_rendering_use[#tag][#mime][#file][#option]%
  {\clf_registerrendering
     type     {external}%
     label    {#tag}%
     mime     {#mime}%
     filename {#file}%
     option   {#option}%
   \relax}

\def\scrn_rendering_set[#tag][#option]% {content} % crappy
  {\bgroup
   \dowithnextbox
     {\clf_registerrendering
         type     {internal}%
         label    {#tag}%
         mime     {IRO}% brrr
         filename {#tag}%
         option   {#option}%
      \relax
      \let\objectoffset\zeropoint
      \setobject{IRO}{#tag}\hpack{\box\nextbox}%
      \egroup}%
     \hbox}

\def\renderingtype  #tag{\clf_renderingvar{#tag}{type}}
\def\renderingoption#tag{\clf_renderingvar{#tag}{option}}

\newdimen\d_scrn_rendering_width  \d_scrn_rendering_width  8cm
\newdimen\d_scrn_rendering_height \d_scrn_rendering_height 6cm

\let\m_scrn_rendering_page\!!zerocount

\installcorenamespace{renderingwindow}

\installframedcommandhandler \??renderingwindow {renderingwindow} \??renderingwindow

\appendtoks
    \letrenderingwindowparameter\c!openpageaction \empty
    \letrenderingwindowparameter\c!closepageaction\empty
    \setrenderingwindowparameter\c!width          {\d_scrn_rendering_width }%
    \setrenderingwindowparameter\c!height         {\d_scrn_rendering_height}%
\to \everypresetrenderingwindow

\unexpanded\def\placerenderingwindow
  {\dodoubleempty\scrn_rendering_place_window}

\def\scrn_rendering_place_window[#window][#rendering]% do all in lua
  {\bgroup
   \edef\currentrendering{\ifsecondargument#rendering\else#window\fi}%
   % create fall back if needed
   \edef\currentrenderingwindow{\namedrenderingwindowparameter{#window}\c!width}% stupid test, we need a proper one here
   \ifx\currentrenderingwindow\empty
     \let\currentrenderingwindow\s!default
     \definerenderingwindow[\currentrenderingwindow]% why not global
   \else
     \edef\currentrenderingwindow{#window}%
   \fi
   \edef\currentrenderingtype{\renderingtype\currentrendering}%
   \ifx\currentrenderingtype\s!internal
     \getobjectdimensions{IRO}\currentrendering
     \d_scrn_rendering_height\dimexpr\objectheight+\objectdepth\relax
     \d_scrn_rendering_width\objectwidth\relax
     \dogetobjectreferencepage{IRO}\currentrendering\m_scrn_rendering_page
   \else\ifx\currentrenderingwindow\s!default
     \d_scrn_rendering_height\vsize
     \d_scrn_rendering_width \hsize
     \let\m_scrn_rendering_page\realpageno
   \else
     \d_scrn_rendering_height\renderingwindowparameter\c!height
     \d_scrn_rendering_width \renderingwindowparameter\c!width
     \let\m_scrn_rendering_page\realpageno
   \fi\fi
 % todo:
 % \handlereferenceactions{\renderingwindowparameter\c!openpageaction }\dosetuprenderingopenpageaction
 % \handlereferenceactions{\renderingwindowparameter\c!closepageaction}\dosetuprenderingclosepageaction
   \letrenderingwindowparameter\c!offset\v!overlay
   \inheritedrenderingwindowframed
     {\vfilll
      \dontleavehmode
      \clf_insertrenderingwindow
        label  {\currentrendering}%
        width  \d_scrn_rendering_width
        height \d_scrn_rendering_height
        option {\renderingoption\currentrendering}%
        page   \m_scrn_rendering_page
      \relax
      \hfill}%
   \egroup}

%D Linkedlists (not tested in mkvi):

% %D The next mechanism, linked lists, is quite old and
% %D is \MKIV'd for completeness. I will finish the
% %D configuration part when I need it.
% %D
% %D \starttyping
% %D \setupinteraction[state=start]
% %D \definelinkedlist[demo]
% %D \dorecurse{10}{\linkedlistelement[demo]{link \recurselevel} \page}
% %D \stoptyping
%
% \definesystemvariable {lk}   % LinK
%
% \installcommandhandler\??lk{linkedlist}\??lk
%
% \let\setupbutton\setuplinkedlists\setuplinkedlist
%
% \appendtoks
%     \clf_definelinkedlist{\currentlinkedlist}%
% \to \everydefinelinkedlist
%
% \def\setlinkedlistproperties#1#2#3#4#5#6%
%   {\def\currentlink {#1}%
%    \def\noflinks    {#2}%
%    \def\firstlink   {#3}%
%    \def\previouslink{#4}%
%    \def\nextlink    {#5}%
%    \def\lastlink    {#6}}
%
% \def\linkedlistelement[#1]#2% currently no view support
%   {\dontleavehmode\hbox\bgroup
%    #2%
%    \iflocation
%      \edef\currentlinkedlist{#1}%
%      \ifcsname\??lk\currentlinkedlist\s!parent\endcsname
%        \hskip\linkedlistparameter\c!distance\relax
%        \clf_addlinklistelement{\currentlinkedlist}%
%        \expanded{\ctxlatecommand{enhancelinkedlist("\currentlinkedlist",\currentlink)}}% can also be done at the lua end
%        \dogotosomepage  {\??lk\currentlinkedlist}\gotobegincharacter \firstlink
%        \ifnum\noflinks>\plustwo
%          \dogotosomepage{\??lk\currentlinkedlist}\gobackwardcharacter\previouslink
%          \dogotosomepage{\??lk\currentlinkedlist}\goforwardcharacter \nextlink
%        \fi
%        \dogotosomepage  {\??lk\currentlinkedlist}\gotoendcharacter   \lastlink
%      \else
%        \writestatus\m!interactions{no such linked list: \currentlinkedlist}%
%      \fi
%    \fi
%    \egroup}
%
% \setuplinkedlists
%   [\c!distance=.25em,
%    \c!width=\v!fit,
%    \c!location=\v!low,
%    \c!color=\interactionparameter\c!color,
%    \c!frame=\v!off,
%    \c!background=,
%    \c!backgroundcolor=]

\protect \endinput