1if not modules then modules = { } end modules [ ' scrn-wid ' ] = {
2 version = 1 . 001 ,
3 comment = " companion to scrn-wid.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
11
12
13
14
15
16
17
18
19
20
21
22
23
24local next = next
25
26interactions = interactions or { }
27local interactions = interactions
28
29local context = context
30local implement = interfaces . implement
31
32local allocate = utilities . storage . allocate
33
34local attachments = allocate ( )
35local comments = allocate ( )
36local soundclips = allocate ( )
37local renderings = allocate ( )
38local linkedlists = allocate ( )
39
40interactions . attachments = attachments
41interactions . soundclips = soundclips
42interactions . renderings = renderings
43interactions . linkedlists = linkedlists
44
45local texsetbox = tex . setbox
46
47local jobpasses = job . passes
48
49local texgetcount = tex . getcount
50
51local codeinjections = backends . codeinjections
52local nodeinjections = backends . nodeinjections
53
54local variables = interfaces . variables
55local v_auto = variables . auto
56
57local trace_attachments = false trackers . register ( " widgets.attachments " , function ( v ) trace_attachments = v end )
58
59local report_attachments = logs . reporter ( " widgets " , " attachments " )
60
61
62
63implement {
64 name = " presetsymbollist " ,
65 arguments = " string " ,
66 actions = function ( list )
67 codeinjections . presetsymbollist ( list )
68 end
69}
70
71
72
73
74
75
76
77
78
79
80
81
82local nofautoattachments , lastregistered = 0 , nil
83
84local function checkregistered ( specification )
85 local registered = specification . registered
86 if not registered or registered = = " " or registered = = v_auto then
87 nofautoattachments = nofautoattachments + 1
88 lastregistered = " attachment- " . . nofautoattachments
89 specification . registered = lastregistered
90 return lastregistered
91 else
92 return registered
93 end
94end
95
96local function checkbuffer ( specification )
97 local buffer = specification . buffer
98 if buffer ~ = " " then
99 specification . data = buffers . getcontent ( buffer ) or " <no data> "
100 end
101end
102
103function attachments . register ( specification )
104 local registered = checkregistered ( specification )
105 checkbuffer ( specification )
106 attachments [ registered ] = specification
107 if trace_attachments then
108 report_attachments ( " registering %a " , registered )
109 end
110 return specification
111end
112
113function attachments . insert ( specification )
114 local registered = checkregistered ( specification )
115 local r = attachments [ registered ]
116 if r then
117 if trace_attachments then
118 report_attachments ( " including registered %a " , registered )
119 end
120 for k , v in next , r do
121 local s = specification [ k ]
122 if s = = " " then
123 specification [ k ] = v
124 end
125 end
126 elseif trace_attachments then
127 report_attachments ( " including unregistered %a " , registered )
128 end
129 checkbuffer ( specification )
130 return nodeinjections . attachfile ( specification )
131end
132
133implement {
134 name = " registerattachment " ,
135 actions = attachments . register ,
136 arguments = {
137 {
138 { " tag " } ,
139 { " registered " } ,
140 { " title " } ,
141 { " subtitle " } ,
142 { " author " } ,
143 { " file " } ,
144 { " name " } ,
145 { " buffer " } ,
146 { " mimetype " } ,
147 }
148 }
149}
150
151implement {
152 name = " insertattachment " ,
153 actions = function ( specification )
154 texsetbox ( " b_scrn_attachment_link " , ( attachments . insert ( specification ) ) )
155 end ,
156 arguments = {
157 {
158 { " tag " } ,
159 { " registered " } ,
160 { " method " } ,
161 { " width " , " dimen " } ,
162 { " height " , " dimen " } ,
163 { " depth " , " dimen " } ,
164 { " colormodel " , " integer " } ,
165 { " colorvalue " , " integer " } ,
166 { " color " } ,
167 { " transparencyvalue " , " integer " } ,
168 { " symbol " } ,
169 { " layer " } ,
170 { " title " } ,
171 { " subtitle " } ,
172 { " author " } ,
173 { " file " } ,
174 { " name " } ,
175 { " buffer " } ,
176 { " mimetype " } ,
177 }
178 }
179}
180
181
182
183function comments . insert ( specification )
184 local buffer = specification . buffer
185 if buffer ~ = " " then
186 specification . data = buffers . getcontent ( buffer ) or " "
187 end
188 return nodeinjections . comment ( specification )
189end
190
191implement {
192 name = " insertcomment " ,
193 actions = function ( specification )
194 texsetbox ( " b_scrn_comment_link " , ( comments . insert ( specification ) ) )
195 end ,
196 arguments = {
197 {
198 { " tag " } ,
199 { " title " } ,
200 { " subtitle " } ,
201 { " author " } ,
202 { " width " , " dimen " } ,
203 { " height " , " dimen " } ,
204 { " depth " , " dimen " } ,
205 { " nx " } ,
206 { " ny " } ,
207 { " colormodel " , " integer " } ,
208 { " colorvalue " , " integer " } ,
209 { " transparencyvalue " , " integer " } ,
210 { " option " } ,
211 { " symbol " } ,
212 { " buffer " } ,
213 { " layer " } ,
214 { " space " } ,
215 }
216 }
217}
218
219
220
221function soundclips . register ( specification )
222 local tag = specification . tag
223 if tag and tag ~ = " " then
224 local filename = specification . file
225 if not filename or filename = = " " then
226 filename = tag
227 specification . file = filename
228 end
229 soundclips [ tag ] = specification
230 return specification
231 end
232end
233
234function soundclips . insert ( tag )
235 local sc = soundclips [ tag ]
236 if not sc then
237
238 return soundclips . register { tag = tag }
239 else
240 return sc
241 end
242end
243
244implement {
245 name = " registersoundclip " ,
246 actions = soundclips . register ,
247 arguments = {
248 {
249 { " tag " } ,
250 { " file " }
251 }
252 }
253}
254
255implement {
256 name = " insertsoundclip " ,
257 actions = soundclips . insert ,
258 arguments = {
259 {
260 { " tag " } ,
261 { " repeat " }
262 }
263 }
264}
265
266
267
268function renderings . register ( specification )
269 if specification . label then
270 renderings [ specification . label ] = specification
271 return specification
272 end
273end
274
275function renderings . rendering ( label )
276 local rn = renderings [ label ]
277 if not rn then
278
279 return renderings . register { label = label }
280 else
281 return rn
282 end
283end
284
285function renderings . var ( label , key )
286 local rn = renderings [ label ]
287 return rn and rn [ key ] or " "
288end
289
290implement {
291 name = " renderingvar " ,
292 actions = { renderings . var , context } ,
293 arguments = " 2 strings " ,
294}
295
296implement {
297 name = " registerrendering " ,
298 actions = renderings . register ,
299 arguments = {
300 {
301 { " type " } ,
302 { " label " } ,
303 { " mime " } ,
304 { " filename " } ,
305 { " option " } ,
306 }
307 }
308}
309
310
311
312implement {
313 name = " insertrenderingwindow " ,
314 actions = function ( specification )
315 codeinjections . insertrenderingwindow ( specification )
316 end ,
317 arguments = {
318 {
319 { " label " } ,
320 { " width " , " dimen " } ,
321 { " height " , " dimen " } ,
322 { " option " } ,
323 { " page " , " integer " } ,
324 }
325 }
326}
327
328
329
330implement {
331 name = " definelinkedlist " ,
332 arguments = " string " ,
333 actions = function ( tag )
334
335 end
336}
337
338implement {
339 name = " enhancelinkedlist " ,
340 arguments = { " string " , " integer " } ,
341 actions = function ( tag , n )
342 local ll = jobpasses . gettobesaved ( tag )
343 if ll then
344 ll [ n ] = texgetcount ( " realpageno " )
345 end
346 end
347}
348
349implement {
350 name = " addlinklistelement " ,
351 arguments = " string " ,
352 actions = function ( tag )
353 local tobesaved = jobpasses . gettobesaved ( tag )
354 local collected = jobpasses . getcollected ( tag ) or { }
355 local currentlink = # tobesaved + 1
356 local noflinks = # collected
357 tobesaved [ currentlink ] = 0
358 local f = collected [ 1 ] or 0
359 local l = collected [ noflinks ] or 0
360 local p = collected [ currentlink -1 ] or f
361 local n = collected [ currentlink + 1 ] or l
362 context . setlinkedlistproperties ( currentlink , noflinks , f , p , n , l )
363
364 end
365}
366 |