summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/attr-lay.mkiv
blob: 6055c2a73d2ab6a5114417fa0c03391d7f8f7ccb (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
%D \module
%D   [       file=attr-lay,
%D        version=2007.06.06,
%D          title=\CONTEXT\ Attribute Macros,
%D       subtitle=Viewerlayers,
%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 Attribute Macros / Viewerlayers}

%D Currently there is a limitation in mixed inline usage. This has to do with the fact
%D that we have a stacked model but cannot determine where to revert to (as we can
%D have AABBCCAA ranges). Maybe I'll solve that one day. It only affects nested inline
%D layers and these make not much sense anyway. We'd have to store the complete nesting
%D stack in the attribute in order to be able to cross pages and that demands a new
%D mechanism.

\unprotect

\registerctxluafile{attr-lay}{1.001}

% needs to work over stopitemize grouping etc

\installcorenamespace{viewerlayer}

\installcommandhandler \??viewerlayer {viewerlayer} \??viewerlayer

\setupviewerlayer
  [\c!state=\v!start,
   \c!title=,
   \c!printable=\v!yes,
   \c!scope=\v!local, % maybe global but needs checking with layout
   \c!method=\v!none]

\appendtoks
  \ctxcommand{defineviewerlayer{
       tag       = "\currentviewerlayer",
       title     = "\viewerlayerparameter\c!title",
       visible   = "\viewerlayerparameter\c!state",
       editable  = "\v!yes",
       printable = "\viewerlayerparameter\c!printable",
       scope     = "\viewerlayerparameter\c!scope"
  }}%
  \doif{\viewerlayerparameter\c!method}\v!command
    {\setuxvalue{\e!start#1}{\startviewerlayer[\currentviewerlayer]}%
     \setuxvalue{\e!stop #1}{\stopviewerlayer}}%
\to \everydefineviewerlayer

\unexpanded\def\startviewerlayer[#1]{\ctxcommand{startviewerlayer("#1")}}                      % not grouped
\unexpanded\def\stopviewerlayer     {\ctxcommand{stopviewerlayer()}}                           % not grouped
\unexpanded\def\viewerlayer     [#1]{\groupedcommand{\startviewerlayer[#1]}{\stopviewerlayer}} % grouped

% some day we will keep this at the lua end as the info is only needed there

\newtoks\currentviewerlayertoks % soon we can set macros at the lua end

\def\currentviewerlayer{\the\currentviewerlayertoks}

\appendtoks
    \let\currentviewerlayer\empty
\to \everybeforepagebody

% layout components are implemented rather directly (speed)

\installcorenamespace{layoutcomponentattribute}

\def\attr_layoutcomponent_initialize#1%
  {\edef\layoutcomponentboxattribute{\ctxcommand{definedviewerlayer{%
     tag       = "#1",
     title     = utilities.strings.nice("#1"), % only here as in steps we have step:<number>
     visible   = "\v!start",
     editable  = "\v!yes",
     printable = "\v!yes"
   }}}%
   \edef\layoutcomponentboxattribute{attr \viewerlayerattribute \layoutcomponentboxattribute\relax}%
   \expandafter\glet\csname\??layoutcomponentattribute#1\endcsname\layoutcomponentboxattribute}

\def\attr_layoutcomponent_set#1% make this faster
  {\expandafter\let\expandafter\layoutcomponentboxattribute\csname\??layoutcomponentattribute#1\endcsname
   \ifx\layoutcomponentboxattribute\relax
     \attr_layoutcomponent_initialize{#1}% get rid of { }
   \fi}

\def\attr_layoutcomponent_reset
  {\let\layoutcomponentboxattribute\empty}

\let\setlayoutcomponentattribute  \gobbleoneargument
\let\resetlayoutcomponentattribute\relax
\let\layoutcomponentboxattribute  \empty

\unexpanded\def\showlayoutcomponents
  {\let\setlayoutcomponentattribute  \attr_layoutcomponent_set
   \let\resetlayoutcomponentattribute\attr_layoutcomponent_reset}

\unexpanded\def\attr_layoutcomponent_cleanup
  {\ctxcommand{cleanuplayers()}}

\appendtoks
    \attr_layoutcomponent_cleanup
\to \everyshipout

\protect \endinput