iDataButtons.icl 20.9 KB
Newer Older
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
1
2
implementation module iDataButtons

Pieter Koopman's avatar
Pieter Koopman committed
3
import StdFunc, StdList, StdString, StdArray
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
4
import iDataFormlib, iDataHandler, iDataStylelib, iDataTrivial, StdBimap
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
5

6

Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
7
derive gUpd  	(,), (,,), (,,,), (<->), <|>, HtmlDate, HtmlTime, DisplayMode/*, Button, CheckBox*/, RadioButton /*, PullDownMenu, TextInput , TextArea, PasswordBox*/
8
9
10
11
12
derive gPrint 	(,), (,,), (,,,), (<->), <|>, HtmlDate, HtmlTime, DisplayMode, Button, CheckBox, RadioButton, RadioGroup, PullDownMenu, TextInput, TextArea, PasswordBox, RefreshTimer
derive gParse 	(,), (,,), (,,,), (<->), <|>, HtmlDate, HtmlTime, DisplayMode, Button, CheckBox, RadioButton, RadioGroup, PullDownMenu, TextInput, TextArea, PasswordBox, RefreshTimer
derive gerda 	(,), (,,), (,,,), (<->), <|>, HtmlDate, HtmlTime, DisplayMode, Button, CheckBox, RadioButton, RadioGroup, PullDownMenu, TextInput, TextArea, PasswordBox, RefreshTimer
derive read 					  (<->), <|>, HtmlDate, HtmlTime, DisplayMode, Button, CheckBox, RadioButton, RadioGroup, PullDownMenu, TextInput, TextArea, PasswordBox, RefreshTimer
derive write 	  				  (<->), <|>, HtmlDate, HtmlTime, DisplayMode, Button, CheckBox, RadioButton, RadioGroup, PullDownMenu, TextInput, TextArea, PasswordBox, RefreshTimer
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
13

14
/*
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
15
16
17
18
19
20
21
22
:: TextInput	= TI Int Int						// Input box of size Size for Integers
				| TR Int Real						// Input box of size Size for Reals
				| TS Int String						// Input box of size Size for Strings


// Types that have an effect on lay-out

:: HTML = HTML [BodyTag]
23
*/
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

gForm {|HTML|} (init,formid ) hst	= specialize myeditor (Set,formid) hst
where
	myeditor (init,formid ) hst
	# (HTML bodytag)				= formid.ival
	= ({changed = False, form = bodytag, value = formid.ival},hst)

gUpd  {|HTML|} mode v				= (mode,v)

gPrint{|HTML|} (HTML x) st			= st <<- "XYX" 

gParse{|HTML|} st					= case gParse {|*|} st of
										Just "XYX" -> Just (HTML [EmptyBody])
										_          -> Just (HTML [EmptyBody])

Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
39
gerda{|HTML|}  = abort "illegal gerda call for type HTML"
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
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

// Tuples are placed next to each other, pairs below each other ...
layoutTableAtts	:== [Tbl_CellPadding (Pixels 0), Tbl_CellSpacing (Pixels 0)]	// default table attributes for arranging layout

gForm{|(,)|} gHa gHb (init,formid) hst
# (na,hst)				= gHa (init,reuseFormId formid a) (incrHSt 1 hst)   	// one more for the now invisible (,) constructor 
# (nb,hst)				= gHb (init,reuseFormId formid b) hst
= (	{ changed			= na.changed || nb.changed
	, value				= (na.value,nb.value)
	, form				= [STable layoutTableAtts [[BodyTag na.form, BodyTag nb.form]]]
	},hst)
where
	(a,b)				= formid.ival

gForm{|(,,)|} gHa gHb gHc (init,formid) hst
# (na,hst)				= gHa (init,reuseFormId formid a) (incrHSt 1 hst)   	// one more for the now invisible (,,) constructor 
# (nb,hst)				= gHb (init,reuseFormId formid b) hst
# (nc,hst)				= gHc (init,reuseFormId formid c) hst
= (	{ changed			= na.changed || nb.changed || nc.changed
	, value				= (na.value,nb.value,nc.value)
	, form				= [STable layoutTableAtts [[BodyTag na.form,BodyTag nb.form,BodyTag nc.form]]]
	},hst)
where
	(a,b,c)				= formid.ival

gForm{|(,,,)|} gHa gHb gHc gHd (init,formid) hst
# (na,hst)				= gHa (init,reuseFormId formid a) (incrHSt 1 hst)   	// one more for the now invisible (,,) constructor 
# (nb,hst)				= gHb (init,reuseFormId formid b) hst
# (nc,hst)				= gHc (init,reuseFormId formid c) hst
# (nd,hst)				= gHd (init,reuseFormId formid d) hst
= (	{ changed			= na.changed || nb.changed || nc.changed || nd.changed
	, value				= (na.value,nb.value,nc.value,nd.value)
	, form				= [STable layoutTableAtts [[BodyTag na.form,BodyTag nb.form,BodyTag nc.form, BodyTag nd.form]]]
	},hst)
where
	(a,b,c,d)			= formid.ival

// <-> works exactly the same as (,) and places its arguments next to each other, for compatibility with GEC's

gForm{|(<->)|} gHa gHb (init,formid) hst
# (na,hst)				= gHa (init,reuseFormId formid a) (incrHSt 1 hst)   	// one more for the now invisible <-> constructor 
# (nb,hst)				= gHb (init,reuseFormId formid b) hst
= (	{ changed			= na.changed || nb.changed 
	, value				= na.value <-> nb.value
	, form				= [STable layoutTableAtts [[BodyTag na.form, BodyTag nb.form]]]
	},hst)
where
	(a <-> b)			= formid.ival

// <|> works exactly the same as PAIR and places its arguments below each other, for compatibility with GEC's

gForm{|(<|>)|} gHa gHb (init,formid) hst 
# (na,hst)				= gHa (init,reuseFormId formid a) (incrHSt 1 hst)		// one more for the now invisible <|> constructor
# (nb,hst)				= gHb (init,reuseFormId formid b) hst
= (	{ changed			= na.changed || nb.changed 
	, value				= na.value <|> nb.value
	, form				= [STable layoutTableAtts [na.form, nb.form]]
	},hst)
where
	(a <|> b)			= formid.ival

// to switch between modes within a type ...

gForm{|DisplayMode|} gHa (init,formid) hst 	
= case formid.ival of
	(HideMode a)
		# (na,hst)		= gHa (init,reuseFormId formid a <@ Display) (incrHSt 1 hst)
		= (	{ changed	= na.changed 
			, value		= HideMode na.value
			, form		= [EmptyBody]
			},hst)
	(DisplayMode a)
		# (na,hst)		= gHa (init,reuseFormId formid a <@ Display) (incrHSt 1 hst)
		= (	{ changed	= False
			, value		= DisplayMode na.value
			, form		= na.form
			},hst)
	(EditMode a) 
		# (na,hst)		= gHa (init,reuseFormId formid a <@ Edit) (incrHSt 1 hst)
		= (	{ changed	= na.changed
			, value		= EditMode na.value
			, form		= na.form
			},hst)
	EmptyMode
		= (	{ changed	= False
			, value		= EmptyMode
			, form		= [EmptyBody]
			},incrHSt 1 hst)

// Buttons to press
130
131
132
133
134
135
cleanString :: !String -> String
cleanString name = {clean_char c \\ c<-: name}
where
	clean_char '"' = ' '
	clean_char c   = c

Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
136
137
138
139
140
141
142
143
144

gForm{|Button|} (init,formid) hst 
# (cntr,hst)			= CntrHSt hst
= case formid.ival of
	v=:(LButton size bname)
	= (	{ changed		= False
		, value			= v
		, form			= [Input (onMode formid.mode [] [] [Inp_Disabled Disabled] [] ++
							[ Inp_Type		Inp_Button
145
							, Inp_Value		(SV (cleanString bname))
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
146
							, Inp_Name		(encodeTriplet (formid.id,cntr,UpdS bname))
147
148
							, `Inp_Std		[Std_Style ("width:" <+++ size), Std_Id (encodeInputId (formid.id,cntr,UpdS bname))]
							, `Inp_Events	(callClean OnClick Edit (encodeTriplet (formid.id,cntr,UpdS bname)) formid.lifespan True)
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
149
150
151
152
153
154
155
							]) ""]
		},(incrHSt 1 hst))
	v=:(PButton (height,width) ref)
	= (	{ changed		= False
		, value			= v
		, form			= [Input (onMode formid.mode [] [] [Inp_Disabled Disabled] [] ++
							[ Inp_Type		Inp_Image
156
							, Inp_Value		(SV (cleanString ref))
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
157
							, Inp_Name		(encodeTriplet (formid.id,cntr,UpdS ref))
158
159
							, `Inp_Std		[Std_Style ("width: " <+++ width <+++ "px; height: " <+++ height <+++ "px"), Std_Id (encodeInputId (formid.id,cntr,UpdS ref))]
							, `Inp_Events	(callClean OnClick Edit (encodeTriplet (formid.id,cntr,UpdS ref)) formid.lifespan True)
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
160
161
162
163
164
165
166
167
168
169
170
171
172
173
							, Inp_Src ref
							]) ""]
		},incrHSt 1 hst)
	Pressed
	= gForm {|*|} (init,(setFormId formid (LButton defpixel "??"))) hst // end user should reset button

gForm{|CheckBox|} (init,formid) hst 
# (cntr,hst)			= CntrHSt hst
= case formid.ival of
	v=:(CBChecked name) 
	= (	{ changed		= False
		, value			= v
		, form			= [Input (onMode formid.mode [] [] [Inp_Disabled Disabled] [] ++
							[ Inp_Type		Inp_Checkbox
174
							, Inp_Value		(SV (cleanString name))
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
175
176
							, Inp_Name		(encodeTriplet (formid.id,cntr,UpdS name))
							, Inp_Checked	Checked
177
178
							, `Inp_Std		[Std_Id (encodeInputId (formid.id,cntr,UpdS name))]
							, `Inp_Events	(callClean OnClick formid.mode "" formid.lifespan False)
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
179
180
181
182
183
184
185
							]) ""]
		},incrHSt 1 hst)
	v=:(CBNotChecked name)
	= (	{ changed		= False
		, value			= v
		, form			= [Input (onMode formid.mode [] [] [Inp_Disabled Disabled] [] ++
							[ Inp_Type		Inp_Checkbox
186
							, Inp_Value		(SV (cleanString name))
187
188
189
							, Inp_Name		(encodeTriplet (formid.id,cntr,UpdS ""))
							, `Inp_Std		[Std_Id (encodeInputId (formid.id,cntr,UpdS name))]
							, `Inp_Events	(callClean OnClick formid.mode "" formid.lifespan False)
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
190
191
192
193
194
195
196
197
198
199
200
							]) ""]
		},incrHSt 1 hst)

gForm{|RadioButton|} (init,formid) hst 
# (cntr,hst)			= CntrHSt hst
= case formid.ival of
	v=:(RBChecked name)
	= (	{ changed		= False
		, value			= v
		, form			= [Input (onMode formid.mode [] [] [Inp_Disabled Disabled] [] ++
							[ Inp_Type			Inp_Radio
201
							, Inp_Value			(SV (cleanString name))
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
202
203
							, Inp_Name			(encodeTriplet (formid.id,cntr,UpdS name))
							, Inp_Checked		Checked
204
205
							, `Inp_Std			[Std_Id (encodeInputId (formid.id,cntr,UpdS name))]
							, `Inp_Events		(callClean OnClick formid.mode "" formid.lifespan False)
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
206
207
208
209
210
211
212
							]) ""]
		},incrHSt 1 hst)
	v=:(RBNotChecked name)
	= (	{ changed		= False
		, value			= v
		, form			= [Input (onMode formid.mode [] [] [Inp_Disabled Disabled] [] ++
							[ Inp_Type			Inp_Radio
213
							, Inp_Value			(SV (cleanString name))
214
215
216
							, Inp_Name			(encodeTriplet (formid.id,cntr,UpdS ""))
							, `Inp_Std			[Std_Id (encodeInputId (formid.id,cntr,UpdS name))]
							, `Inp_Events		(callClean OnClick formid.mode "" formid.lifespan False)
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
217
218
219
							]) ""]
		},incrHSt 1 hst)

220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
gForm{|RadioGroup|} (init, formid) hst
# (cntr, hst)			= CntrHSt hst
= case formid.ival of
	v=:(RadioGroup (sel, itemlist))
	= ( { changed		= False
		, value			= v
		, form			= flatten [([Input (
							[ Inp_Type			Inp_Radio
							, Inp_Value			(SV (toString i))
							, Inp_Name			(encodeTriplet (formid.id, cntr, UpdI sel))
							, `Inp_Std			[Std_Id ((encodeInputId (formid.id,cntr,UpdI sel)) <+++ "_" <+++ i)]
							, `Inp_Events		(callClean OnChange formid.mode "" formid.lifespan False)
							] ++ (if (i == sel) [Inp_Checked Checked] []) ++ (onMode formid.mode [] [] [Inp_Disabled Disabled] [])) ""
							] ++ [Label [Lbl_For ((encodeInputId (formid.id,cntr,UpdI sel)) <+++ "_" <+++ i)] body, Br] )
							\\ body <- itemlist & i <- [0..]
						  ]
		},incrHSt 1 hst)


Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
239
240
241
242
243
244
245
246
247
248
gForm{|PullDownMenu|} (init,formid) hst=:{submits}
# (cntr,hst)			= CntrHSt hst
= case formid.ival of
	v=:(PullDown (size,width) (menuindex,itemlist))
	= (	{ changed		= False
		, value			= v
		, form			= [Select (onMode formid.mode [] [] [Sel_Disabled Disabled] [] ++
							[ Sel_Name			(selectorInpName +++ encodeString 
													(if (menuindex >= 0 && menuindex < length itemlist) (itemlist!!menuindex) ""))
							, Sel_Size			size
249
250
							, `Sel_Std			[Std_Style ("width:" <+++ width <+++ "px"), Std_Id (encodeInputId (formid.id,cntr,UpdS "") )]
							, `Sel_Events		(if submits [] (callClean OnChange formid.mode "" formid.lifespan False))
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
							])
							[ Option 
								[ Opt_Value (encodeTriplet (formid.id,cntr,UpdC (itemlist!!j)))
								: if (j == menuindex) [Opt_Selected Selected] [] 
								]
								elem
								\\ elem <- itemlist & j <- [0..]
							]]
		},incrHSt 1 hst)

gForm{|TextInput|} (init,formid) hst 	
# (cntr,hst)			= CntrHSt hst
# (body,hst)			= mkInput size (init,formid) v updv hst
= ({changed=False, value=formid.ival, form=[body]},incrHSt 2 hst)
where
	(size,v,updv)		= case formid.ival of
							(TI size i) = (size,IV i,UpdI i)
							(TR size r) = (size,RV r,UpdR r)
269
							(TS size s) = (size,SV (cleanString s),UpdS s)
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
270
271
272
273
274

gForm{|TextArea|} (init,formid) hst 
# (cntr,hst)			= CntrHSt hst
= (	{ changed			= False
	, value				= formid.ival
275
276
277
278
279
280
281
	, form				= [myTable [	[ Textarea 	((onMode formid.mode [] [] [Txa_Disabled Disabled] []) ++
											[ Txa_Name (encodeTriplet (formid.id,cntr,UpdS string))
						  					, Txa_Rows (if (row == 0) 10 row)
						  					, Txa_Cols (if (col == 0) 50 col)
						  					, `Txa_Std	[Std_Id (encodeTriplet (formid.id,cntr,UpdS string))]
						  					, `Txa_Events (callClean OnChange formid.mode formid.id formid.lifespan False)
						  					]) string ]
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
282
283
284
285
286
287
288
289
290
291
292
293
						  			]
						  ]
	},incrHSt 1 hst)
where
	(TextArea row col string) = formid.ival

	myTable table
	= Table []	(mktable table)
	where
		mktable table 	= [Tr [] (mkrow rows) \\ rows <- table]	
		mkrow rows 		= [Td [Td_VAlign Alo_Top, Td_Width (Pixels defpixel)] [row] \\ row <- rows] 

294
gUpd{|TextArea|}       (UpdSearch (UpdS name) 0) (TextArea r c s) 	= (UpdDone,                TextArea r c (urlDecode name))			// update button value
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
295
gUpd{|TextArea|}       (UpdSearch val cnt)       t					= (UpdSearch val (cnt - 1),t)										// continue search, don't change
296
gUpd{|TextArea|}       (UpdCreate l)             _					= (UpdCreate l,            TextArea defsize defsize "")				// create default value
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
gUpd{|TextArea|}       mode                      t					= (mode,                   t)										// don't change

gForm{|PasswordBox|} (init,formid) hst 	
= case formid.ival of
	(PasswordBox password) 
	# (body,hst)		= mkPswInput defsize (init,formid) password (UpdS password) hst
	= ({ changed		= False
	   , value			= PasswordBox password
	   , form			= [body]
	   },incrHSt 1 hst)
where
	mkPswInput :: !Int !(InIDataId d) String UpdValue !*HSt -> (!BodyTag,!*HSt) 
	mkPswInput size (init,formid=:{mode}) sval updval hst=:{cntr,submits}
	| mode == Edit || mode == Submit
		= ( Input 	[ Inp_Type		Inp_Password
312
					, Inp_Value		(SV (cleanString sval))
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
313
314
					, Inp_Name		(encodeTriplet (formid.id,cntr,updval))
					, Inp_Size		size
315
					, `Inp_Std		[EditBoxStyle, Std_Title "::Password", Std_Id (encodeInputId (formid.id,cntr,updval))]
316
					, `Inp_Events	if (mode == Edit && not submits) (callClean OnChange Edit "" formid.lifespan False) []
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
317
318
319
320
					] ""
			,incrHSt 1 hst)
	| mode == Display
		= ( Input 	[ Inp_Type		Inp_Password
321
					, Inp_Value		(SV (cleanString sval))
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
					, Inp_ReadOnly	ReadOnly
					, `Inp_Std		[DisplayBoxStyle]
					, Inp_Size		size
					] ""
			,incrHSt 1 hst)
	= ( EmptyBody,incrHSt 1 hst )

// time and date

import StdTime

getTimeAndDate :: !*HSt -> *(!(!HtmlTime,!HtmlDate),!*HSt)
getTimeAndDate hst
# (time,hst)				= accWorldHSt getCurrentTime hst
# (date,hst)				= accWorldHSt getCurrentDate hst
= ((Time time.hours time.minutes time.seconds,Date date.day date.month date.year),hst)

gForm {|HtmlTime|} (init,formid) hst
340
	= specialize (flip mkBimapEditor {map_to = toPullDown, map_from = fromPullDown}) (init,formid <@ nPage) hst
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
341
where
342
	nPage = if (formid.lifespan == Client) Client Page
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
343
344
345
346
347
348
349
350
351
352
353
	toPullDown (Time h m s)	= (hv,mv,sv)
	where
		hv					= PullDown (1, defpixel/2) (h,[toString i \\ i <- [0..23]])
		mv					= PullDown (1, defpixel/2) (m,[toString i \\ i <- [0..59]])
		sv					= PullDown (1, defpixel/2) (s,[toString i \\ i <- [0..59]])

	fromPullDown (hv,mv,sv)	= Time (convert hv) (convert mv) (convert sv)
	where
		convert x			= toInt (toString x)

gForm {|HtmlDate|} (init,formid) hst 
354
	= specialize (flip mkBimapEditor {map_to = toPullDown, map_from = fromPullDown}) (init,formid <@ nPage) hst
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
355
where
356
	nPage = if (formid.lifespan == Client) Client Page
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
357
358
359
360
361
362
	toPullDown (Date d m y)	= (dv,mv,yv)
	where
		dv					= PullDown (1,  defpixel/2) (md-1,   [toString i \\ i <- [1..31]])
		mv					= PullDown (1,  defpixel/2) (mm-1,   [toString i \\ i <- [1..12]])
		yv					= PullDown (1,2*defpixel/3) (my-1950,[toString i \\ i <- [1950..2015]])

Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
363
		my					= if (y >= 1950 && y <= 2015) y 2007
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
364
365
366
367
368
369
		md					= if (d >= 1    && d <= 31)   d 1
		mm					= if (m >= 1    && m <= 12)   m 1

	fromPullDown (dv,mv,yv)	= Date (convert dv) (convert mv) (convert yv)
	where
		convert x			= toInt (toString x)
370
371
372
373
374
375
376
377
378
379
380
		
		
gForm {|RefreshTimer|} (init,formid) hst = case formid.ival of
		RefreshTimer timeout
			# (cntr,hst)			= CntrHSt hst
			# triplet = encodeTriplet (formid.id,cntr,UpdS "timer")
			# inputid = encodeInputId (formid.id,cntr,UpdS "timer")
			# timedcode = "toClean(document.getElementById('" +++ inputid +++ "'),'" +++ triplet +++ "',true,false," +++ (IF_ClientTasks "true" "false") +++ ");"
			# script =  [InlineCode ("<input type=\"hidden\" id=\""+++ inputid +++"\" /><script type=\"text/javascript\">setTimeout(\"" +++ timedcode +++ "\"," +++ toString timeout +++ ");</script>")]
			= ({ changed = False, value = formid.ival, form = script}, incrHSt 1 hst)

Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
381
382
383
384
385
386
387
388
389
390
391

// Updates that have to be treated specially:

gUpd{|PullDownMenu|} (UpdSearch (UpdC cname) 0) (PullDown dim (menuindex,itemlist)) 
																= (UpdDone,                PullDown dim (itemlist??cname,itemlist))	// update integer value
gUpd{|PullDownMenu|} (UpdSearch val cnt)       v				= (UpdSearch val (cnt - 1),v)										// continue search, don't change
gUpd{|PullDownMenu|} (UpdCreate l)             _				= (UpdCreate l,            PullDown (1,defpixel) (0,["error"]))		// create default value
gUpd{|PullDownMenu|} mode                      v				= (mode,                   v)										// don't change

gUpd{|Button|}       (UpdSearch (UpdS name) 0) _				= (UpdDone,                Pressed)									// update button value
gUpd{|Button|}       (UpdSearch val cnt)       b				= (UpdSearch val (cnt - 1),b)										// continue search, don't change
392
gUpd{|Button|}       (UpdCreate l)             _				= (UpdCreate l,            LButton defpixel "Press")				// create default value
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
393
394
395
396
397
398
399
400
gUpd{|Button|}       mode                      b				= (mode,                   b)										// don't change

gUpd{|CheckBox|}     (UpdSearch (UpdS name) 0) (CBChecked    s)	= (UpdDone,                CBNotChecked s)							// update CheckBox value
gUpd{|CheckBox|}     (UpdSearch (UpdS name) 0) (CBNotChecked s)	= (UpdDone,                CBChecked    s)							// update CheckBox value
gUpd{|CheckBox|}     (UpdSearch val cnt)       b				= (UpdSearch val (cnt - 1),b)										// continue search, don't change
gUpd{|CheckBox|}     (UpdCreate l)             _				= (UpdCreate l,            CBNotChecked "defaultCheckboxName")		// create default value
gUpd{|CheckBox|}     mode                      b				= (mode,                   b)										// don't change

401
402
403
404
405
406
gUpd{|RadioGroup|} 	(UpdSearch (UpdI sel) 0) (RadioGroup (index,itemlist)) 
																= (UpdDone,                RadioGroup (sel,itemlist))				// update integer value
gUpd{|RadioGroup|} 	(UpdSearch val cnt)       v					= (UpdSearch val (cnt - 1),v)										// continue search, don't change
gUpd{|RadioGroup|} 	(UpdCreate l)             _					= (UpdCreate l,            RadioGroup (0,["error"]))				// create default value
gUpd{|RadioGroup|}	mode                      v					= (mode,                   v)										// don't change

Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
407
408
409
410
gUpd{|TextInput|}    (UpdSearch (UpdI ni) 0)   (TI size i)		= (UpdDone,                TI size ni)								// update integer value
gUpd{|TextInput|}    (UpdSearch (UpdR nr) 0)   (TR size r)		= (UpdDone,                TR size nr)								// update real    value
gUpd{|TextInput|}    (UpdSearch (UpdS ns) 0)   (TS size s)		= (UpdDone,                TS size ns)								// update string  value
gUpd{|TextInput|}    (UpdSearch val cnt)       i				= (UpdSearch val (cnt - 3),i)										// continue search, don't change
411
gUpd{|TextInput|}    (UpdCreate l)             _				= (UpdCreate l,            TS defsize "")							// create default value
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
412
413
414
415
416
417
418
gUpd{|TextInput|}    mode                      i				= (mode,                   i)										// don't change

gUpd{|PasswordBox|}  (UpdSearch (UpdS name) 0) _				= (UpdDone,                PasswordBox name)						// update password value
gUpd{|PasswordBox|}  (UpdSearch val cnt)       b				= (UpdSearch val (cnt - 2),b)										// continue search, don't change
gUpd{|PasswordBox|}  (UpdCreate l)             _				= (UpdCreate l,            PasswordBox "")							// create default value
gUpd{|PasswordBox|}  mode                      b				= (mode,                   b)										// don't change

419
420
421
422
423
424
gUpd{|RefreshTimer|} (UpdSearch (UpdS name) 0) v				= (UpdDone,                v)										// We don't update
gUpd{|RefreshTimer|} (UpdSearch val cnt)       v				= (UpdSearch val (cnt - 1),v)										// continue search, don't change
gUpd{|RefreshTimer|} (UpdCreate l)             _				= (UpdCreate l,            RefreshTimer 0)							// create default value
gUpd{|RefreshTimer|} mode                      v				= (mode,                   v)										// don't change


Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
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
// small utility stuf

instance toBool RadioButton where
	toBool (RBChecked _)					= True
	toBool _								= False

instance toBool CheckBox where
	toBool (CBChecked _)					= True
	toBool _								= False

instance toBool Button where
	toBool Pressed							= True
	toBool _								= False

instance toInt PullDownMenu where
	toInt (PullDown _ (i,_))				= i

instance toString PullDownMenu where
	toString (PullDown _ (i,s))				= if (i>=0 && i <=length s) (s!!i) ""

derive gEq PasswordBox, HtmlTime, HtmlDate
instance == PasswordBox where (==) pb1 pb2	= pb1 === pb2
instance == HtmlTime    where (==) ht1 ht2	= ht1 === ht2
instance == HtmlDate    where (==) hd1 hd2	= hd1 === hd2

instance == (DisplayMode a) | == a
where 
	(==) (DisplayMode a) (DisplayMode b)	= a == b
	(==) (EditMode a) (EditMode b)			= a == b
	(==) (HideMode a) (HideMode b)			= a == b
	(==) EmptyMode EmptyMode				= True
	(==) _ _								= False

derive gLexOrd HtmlTime, HtmlDate
instance + HtmlTime where (+) (Time h1 m1 s1) (Time h2 m2 s2)
											= Time (h1 + h2) (m1 + m2) (s1 + s2)
instance - HtmlTime where (-) (Time h1 m1 s1) (Time h2 m2 s2)
											= Time (h1 - h2) (m1 - m2) (s1 - s2)
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
463
464
465
466
467
468
469
470
471
472
473
474
475
instance < HtmlTime 
where 
	(<) (Time h1 m1 s1) (Time h2 m2 s2)
	| h1 <> h2 = h1 < h2
	| m1 <> m2 = m1 < m2
	= s1 < s2

instance < HtmlDate 
where 
	(<) (Date d1 m1 y1) (Date d2 m2 y2) 
	| y1 <> y2 = y1 < y2
	| m1 <> m2 = m1 < m2
	= d1 < d2
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
476
477
478
479
480

instance toString HtmlTime where
	toString (Time hrs min sec)				= toString hrs <+++ ":" <+++ min <+++ ":" <+++ sec
instance toString HtmlDate where
	toString (Date day month year)			= toString day <+++ "/" <+++ month <+++ "/" <+++ year