1if not modules then modules = { } end modules ['scrn-fld'] = {
2 version = 1.001,
3 comment = "companion to scrn-fld.mkiv",
4 author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5 copyright = "PRAGMA ADE / ConTeXt Development Team",
6 license = "see context related readme files"
7}
8
9
10
11local context = context
12local ctx_doifelse = commands.doifelse
13local implement = interfaces.implement
14
15local variables = interfaces.variables
16local v_yes = variables.yes
17
18local report = logs.reporter("widgets")
19
20local texsetbox = tex.setbox
21
22local fields = { }
23interactions.fields = fields
24
25local codeinjections = backends.codeinjections
26local nodeinjections = backends.nodeinjections
27
28local function define(specification)
29 codeinjections.definefield(specification)
30end
31
32local function defineset(name,set)
33 codeinjections.definefield(name,set)
34end
35
36local function clone(specification)
37 codeinjections.clonefield(specification)
38end
39
40local function insert(name,specification)
41 return nodeinjections.typesetfield(name,specification)
42end
43
44fields.define = define
45fields.defineset = defineset
46fields.clone = clone
47fields.insert = insert
48
49
50
51implement {
52 name = "definefield",
53 actions = define,
54 arguments = {
55 {
56 { "name" },
57 { "alternative" },
58 { "type" },
59 { "category" },
60 { "values" },
61 { "default" },
62 }
63 }
64}
65
66implement {
67 name = "definefieldset",
68 actions = defineset,
69 arguments = "2 strings",
70}
71
72implement {
73 name = "clonefield",
74 actions = clone,
75 arguments = {
76 {
77 { "children" },
78 { "alternative" },
79 { "parent" },
80 { "category" },
81 { "values" },
82 { "default" },
83 }
84 }
85}
86
87implement {
88 name = "insertfield",
89 actions = function(name,specification)
90 local b = insert(name,specification)
91 if b then
92 texsetbox("b_scrn_field_body",b)
93 else
94 report("unknown field %a",name)
95 end
96 end,
97 arguments = {
98 "string",
99 {
100 { "title" },
101 { "width", "dimen" },
102 { "height", "dimen" },
103 { "depth", "dimen" },
104 { "align" },
105 { "length" },
106 { "fontstyle" },
107 { "fontalternative" },
108 { "fontsize" },
109 { "fontsymbol" },
110 { "colorvalue", "integer" },
111 { "color" },
112 { "backgroundcolorvalue", "integer" },
113 { "backgroundcolor" },
114 { "framecolorvalue", "integer" },
115 { "framecolor" },
116 { "layer" },
117 { "option" },
118 { "align" },
119 { "clickin" },
120 { "clickout" },
121 { "regionin" },
122 { "regionout" },
123 { "afterkey" },
124 { "format" },
125 { "validate" },
126 { "calculate" },
127 { "focusin" },
128 { "focusout" },
129 { "openpage" },
130 { "closepage" },
131 }
132 }
133}
134
135
136
137implement {
138 name = "getfieldcategory",
139 arguments = "string",
140 actions = function(name)
141 local g = codeinjections.getfieldcategory(name)
142 if g then
143 context(g)
144 end
145 end
146}
147
148implement {
149 name = "getdefaultfieldvalue",
150 arguments = "string",
151 actions = function(name)
152 local d = codeinjections.getdefaultfieldvalue(name)
153 if d then
154 context(d)
155 end
156 end
157}
158
159implement {
160 name = "exportformdata",
161 arguments = "string",
162 actions = function(export)
163 if export == v_yes then
164 codeinjections.exportformdata()
165 end
166 end
167}
168
169implement {
170 name = "setformsmethod",
171 arguments = "string",
172 actions = function(method)
173 codeinjections.setformsmethod(method)
174 end
175}
176
177implement {
178 name = "doifelsefieldcategory",
179 arguments = "string",
180 actions = function(name)
181 ctx_doifelse(codeinjections.validfieldcategory(name))
182 end
183}
184
185implement {
186 name = "doifelsefieldset",
187 arguments = "string",
188 actions = function(name)
189 ctx_doifelse(codeinjections.validfieldset(name))
190 end
191}
192 |