summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/scrn-fld.lua
blob: 046b7864f8bc6030789f76442a78347851b58aa5 (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
if not modules then modules = { } end modules ['scrn-fld'] = {
    version   = 1.001,
    comment   = "companion to scrn-fld.mkiv",
    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
    copyright = "PRAGMA ADE / ConTeXt Development Team",
    license   = "see context related readme files"
}

-- we should move some code from lpdf-fld to here

local context       = context
local ctx_doifelse  = commands.doifelse
local implement     = interfaces.implement

local variables     = interfaces.variables
local v_yes         = variables.yes

local report        = logs.reporter("widgets")

local texsetbox     = tex.setbox

local fields        = { }
interactions.fields = fields

local codeinjections = backends.codeinjections
local nodeinjections = backends.nodeinjections

local function define(specification)
    codeinjections.definefield(specification)
end

local function defineset(name,set)
    codeinjections.definefield(name,set)
end

local function clone(specification)
    codeinjections.clonefield(specification)
end

local function insert(name,specification)
    return nodeinjections.typesetfield(name,specification)
end

fields.define    = define
fields.defineset = defineset
fields.clone     = clone
fields.insert    = insert

-- codeinjections are not yet defined

implement {
    name      = "definefield",
    actions   = define,
    arguments = {
        {
            { "name" },
            { "alternative" },
            { "type" },
            { "category" },
            { "values" },
            { "default" },
        }
    }
}

implement {
    name      = "definefieldset",
    actions   = defineset,
    arguments = "2 strings",
}

implement {
    name      = "clonefield",
    actions   = clone,
    arguments = {
        {
            { "children" },
            { "alternative" },
            { "parent" },
            { "category" },
            { "values" },
            { "default" },
        }
    }
}

implement {
    name     = "insertfield",
    actions  = function(name,specification)
        local b = insert(name,specification)
        if b then
            texsetbox("b_scrn_field_body",b)
        else
            report("unknown field %a",name)
        end
    end,
    arguments = {
        "string",
        {
            { "title" },
            { "width", "dimen" },
            { "height", "dimen" },
            { "depth", "dimen" },
            { "align" },
            { "length" },
            { "fontstyle" },
            { "fontalternative" },
            { "fontsize" },
            { "fontsymbol" },
            { "colorvalue", "integer" },
            { "color" },
            { "backgroundcolorvalue", "integer" },
            { "backgroundcolor" },
            { "framecolorvalue", "integer" },
            { "framecolor" },
            { "layer" },
            { "option" },
            { "align" },
            { "clickin" },
            { "clickout" },
            { "regionin" },
            { "regionout" },
            { "afterkey" },
            { "format" },
            { "validate" },
            { "calculate" },
            { "focusin" },
            { "focusout" },
            { "openpage" },
            { "closepage" },
        }
    }
}

-- (for the monent) only tex interface

implement {
    name      = "getfieldcategory",
    arguments = "string",
    actions   = function(name)
        local g = codeinjections.getfieldcategory(name)
        if g then
            context(g)
        end
    end
}

implement {
    name      = "getdefaultfieldvalue",
    arguments = "string",
    actions   = function(name)
        local d = codeinjections.getdefaultfieldvalue(name)
        if d then
            context(d)
        end
    end
}

implement {
    name      = "exportformdata",
    arguments = "string",
    actions   = function(export)
        if export == v_yes then
            codeinjections.exportformdata()
        end
    end
}

implement {
    name      = "setformsmethod",
    arguments = "string",
    actions   = function(method)
        codeinjections.setformsmethod(method)
    end
}

implement {
    name      = "doifelsefieldcategory",
    arguments = "string",
    actions   = function(name)
        ctx_doifelse(codeinjections.validfieldcategory(name))
    end
}

implement {
    name      = "doiffieldsetelse",
    arguments = "string",
    actions   = function(name)
        ctx_doifelse(codeinjections.validfieldset(name))
    end
}