StdControlClass.icl 23.8 KB
Newer Older
Peter Achten's avatar
Peter Achten committed
1
2
3
4
5
6
7
8
9
10
implementation module StdControlClass


//	Clean Object I/O library, version 1.2

//	Definition of the Controls class for controls.


import	StdBool, StdFunc, StdInt, StdList, StdMisc, StdTuple
import	commondef, controldefaccess, controlvalidate, id, iostate, StdControlDef, StdPSt, windowhandle, windowvalidate
11
import	ospicture, ossystem, ostypes, oswindow
Peter Achten's avatar
Peter Achten committed
12
13
14


class Controls cdef where
15
16
	controlToHandles:: !(cdef .ls (PSt .l)) !(PSt .l)	-> (![ControlState .ls (PSt .l)],!PSt .l)
	getControlType	::  (cdef .ls .pst)					-> ControlType
Peter Achten's avatar
Peter Achten committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31


/*	Translating control elements with local state into the internal representation.
	Note that no additional information is generated yet.
	Attributes that can be placed in the relevant record fields 
		wItemId		- ControlId
		wItemShow	- ControlHide
		wItemSelect	- ControlSelectState
		wItemLook	- ControlLook
		wItemInfo	- ControlDomain
	are removed from the attribute list. 
	The remaining attribute list is copied to wItemAtts.
*/

instance Controls (AddLS c) | Controls c where
32
	controlToHandles :: !(AddLS c .ls (PSt .l)) !(PSt .l) -> (![ControlState .ls (PSt .l)],!PSt .l)	| Controls c
Peter Achten's avatar
Peter Achten committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
	controlToHandles {addLS,addDef} pState
		# (cs,pState)	= controlToHandles addDef pState
		= (	[WElementHandleToControlState
				(WExtendLSHandle {	wExtendLS		= addLS
								 ,	wExtendItems	= map ControlStateToWElementHandle cs
								 }
				)
			]
		  ,	pState
		  )
	getControlType _
		= ""

instance Controls (NewLS c) | Controls c where
47
	controlToHandles :: !(NewLS c .ls (PSt .l)) !(PSt .l) -> (![ControlState .ls (PSt .l)],!PSt .l)	| Controls c
Peter Achten's avatar
Peter Achten committed
48
49
50
51
52
53
54
55
56
57
58
59
60
61
	controlToHandles {newLS,newDef} pState
		# (cs,pState)	= controlToHandles newDef pState
		= (	[WElementHandleToControlState
				(WChangeLSHandle {	wChangeLS		= newLS
								 ,	wChangeItems	= map ControlStateToWElementHandle cs
								 }
				)
			]
		  ,	pState
		  )
	getControlType _
		= ""

instance Controls (ListLS c) | Controls c where
62
	controlToHandles :: !(ListLS c .ls (PSt .l)) !(PSt .l) -> (![ControlState .ls (PSt .l)],!PSt .l)	| Controls c
Peter Achten's avatar
Peter Achten committed
63
64
65
66
67
68
69
	controlToHandles (ListLS cDefs) pState
		# (css,pState)	= StateMap controlToHandles cDefs pState
		= ([WElementHandleToControlState (WListLSHandle (map ControlStateToWElementHandle (flatten css)))],pState)
	getControlType _
		= ""

instance Controls NilLS where
70
	controlToHandles :: !(NilLS .ls (PSt .l)) !(PSt .l) -> (![ControlState .ls (PSt .l)],!PSt .l)
Peter Achten's avatar
Peter Achten committed
71
72
73
74
75
76
	controlToHandles NilLS pState
		= ([WElementHandleToControlState (WListLSHandle [])],pState)
	getControlType _
		= ""

instance Controls ((:+:) c1 c2)	| Controls c1 & Controls c2 where
77
	controlToHandles :: !((:+:) c1 c2 .ls (PSt .l)) !(PSt .l) -> (![ControlState .ls (PSt .l)],!PSt .l)	| Controls c1 & Controls c2
Peter Achten's avatar
Peter Achten committed
78
79
80
81
82
83
84
85
	controlToHandles (c1:+:c2) pState
		# (cs1,pState)	= controlToHandles c1 pState
		# (cs2,pState)	= controlToHandles c2 pState
		= (cs1++cs2,pState)
	getControlType _
		= ""

instance Controls RadioControl where
86
	controlToHandles :: !(RadioControl .ls (PSt .l)) !(PSt .l) -> (![ControlState .ls (PSt .l)],!PSt .l)
Peter Achten's avatar
Peter Achten committed
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
	controlToHandles (RadioControl items layout index atts) pState
		# (wMetrics, ioState)		= IOStGetOSWindowMetrics pState.io
		  (nrItems,items)			= Ulength items
		# (infoItems,ioState)		= StateMap (radioItemToInfo wMetrics) items ioState
		= (	[WElementHandleToControlState
				(WItemHandle 
				{	wItemId			= getIdAttribute atts
				,	wItemNr			= 0
				,	wItemKind		= IsRadioControl
				,	wItemShow		= not (Contains isControlHide atts)
				,	wItemSelect		= getSelectStateAttribute atts
				,	wItemInfo		= RadioInfo 
										{	radioItems = infoItems
										,	radioLayout= validateLayout nrItems layout
										,	radioIndex = SetBetween index 1 nrItems
										}
				,	wItemAtts		= filter (not o redundantAttribute) atts
				,	wItems			= []
				,	wItemVirtual	= False
				,	wItemPos		= zero
				,	wItemSize		= zero
				,	wItemPtr		= OSNoWindowPtr
				,	wItemLayoutInfo	= undef
				})
			]
		  ,	{pState & io=ioState}
		  )
	where
115
116
		radioItemToInfo :: !OSWindowMetrics !(RadioControlItem *(.ls,PSt .l)) !(IOSt .l)
											-> (!RadioItemInfo *(.ls,PSt .l), ! IOSt .l)
Peter Achten's avatar
Peter Achten committed
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
		radioItemToInfo wMetrics (text,Just (PixelWidth reqW),f) ioState
			# wOK				= max (OSgetRadioControlItemMinWidth wMetrics) reqW
			# hOK				= OSgetRadioControlItemHeight wMetrics
			= ({radioItem=(text,wOK,f),radioItemSize={w=wOK,h=hOK},radioItemPos=zero,radioItemPtr=OSNoWindowPtr},ioState)
		radioItemToInfo wMetrics (text,Just (TextWidth wtext),f) ioState
			# (w,ioState)		= getDialogFontTextWidth wtext ioState
			  wOK				= max (OSgetRadioControlItemMinWidth wMetrics) w
			# hOK				= OSgetRadioControlItemHeight wMetrics
			= ({radioItem=(text,wOK,f),radioItemSize={w=wOK,h=hOK},radioItemPos=zero,radioItemPtr=OSNoWindowPtr},ioState)
		radioItemToInfo wMetrics (text,Just (ContentWidth wtext),f) ioState
			# ((w,hOK),ioState)	= accIOToolbox (OSgetRadioControlItemSize wMetrics wtext) ioState
			  wOK				= max (OSgetRadioControlItemMinWidth wMetrics) w
			= ({radioItem=(text,wOK,f),radioItemSize={w=wOK,h=hOK},radioItemPos=zero,radioItemPtr=OSNoWindowPtr},ioState)
		radioItemToInfo wMetrics (text,Nothing,f) ioState
			# ((w,hOK),ioState)	= accIOToolbox (OSgetRadioControlItemSize wMetrics text) ioState
			  wOK				= max (OSgetRadioControlItemMinWidth wMetrics) w
			= ({radioItem=(text,wOK,f),radioItemSize={w=wOK,h=hOK},radioItemPos=zero,radioItemPtr=OSNoWindowPtr},ioState)
	getControlType _
		= "RadioControl"

instance Controls CheckControl where
138
	controlToHandles :: !(CheckControl .ls (PSt .l)) !(PSt .l) -> (![ControlState .ls (PSt .l)],!PSt .l)
Peter Achten's avatar
Peter Achten committed
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
	controlToHandles (CheckControl items layout atts) pState
		# (wMetrics,ioState)		= IOStGetOSWindowMetrics pState.io
		  (nrItems,items)			= Ulength items
		# (infoItems,ioState)		= StateMap (checkItemToInfo wMetrics) items ioState
		= (	[WElementHandleToControlState
				(WItemHandle 
				{	wItemId			= getIdAttribute atts
				,	wItemNr			= 0
				,	wItemKind		= IsCheckControl
				,	wItemShow		= not (Contains isControlHide atts)
				,	wItemSelect		= getSelectStateAttribute atts
				,	wItemInfo		= CheckInfo
										{	checkItems = infoItems
										,	checkLayout= validateLayout nrItems layout
										}
				,	wItemAtts		= filter (not o redundantAttribute) atts
				,	wItems			= []
				,	wItemVirtual	= False
				,	wItemPos		= zero
				,	wItemSize		= zero
				,	wItemPtr		= OSNoWindowPtr
				,	wItemLayoutInfo	= undef
				})
			]
		  ,	{pState & io=ioState}
		  )
	where
166
167
		checkItemToInfo :: !OSWindowMetrics !(CheckControlItem *(.ls,PSt .l)) !(IOSt .l)
											-> (!CheckItemInfo *(.ls,PSt .l), ! IOSt .l)
Peter Achten's avatar
Peter Achten committed
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
		checkItemToInfo wMetrics (text,Just (PixelWidth reqW),mark,f) ioState
			# wOK				= max (OSgetCheckControlItemMinWidth wMetrics) reqW
			# hOK				= OSgetCheckControlItemHeight wMetrics
			= ({checkItem=(text,wOK,mark,f),checkItemSize={w=wOK,h=hOK},checkItemPos=zero,checkItemPtr=OSNoWindowPtr},ioState)
		checkItemToInfo wMetrics (text,Just (TextWidth wtext),mark,f) ioState
			# (w,ioState)		= getDialogFontTextWidth wtext ioState
			  wOK				= max (OSgetCheckControlItemMinWidth wMetrics) w
			# hOK				= OSgetCheckControlItemHeight wMetrics
			= ({checkItem=(text,wOK,mark,f),checkItemSize={w=wOK,h=hOK},checkItemPos=zero,checkItemPtr=OSNoWindowPtr},ioState)
		checkItemToInfo wMetrics (text,Just (ContentWidth wtext),mark,f) ioState
			# ((w,hOK),ioState)	= accIOToolbox (OSgetCheckControlItemSize wMetrics wtext) ioState
			  wOK				= max (OSgetCheckControlItemMinWidth wMetrics) w
			= ({checkItem=(text,wOK,mark,f),checkItemSize={w=wOK,h=hOK},checkItemPos=zero,checkItemPtr=OSNoWindowPtr},ioState)
		checkItemToInfo wMetrics (text,Nothing,mark,f) ioState
			# ((w,hOK),ioState)	= accIOToolbox (OSgetCheckControlItemSize wMetrics text) ioState
			  wOK				= max (OSgetCheckControlItemMinWidth wMetrics) w
			= ({checkItem=(text,wOK,mark,f),checkItemSize={w=wOK,h=hOK},checkItemPos=zero,checkItemPtr=OSNoWindowPtr},ioState)
	getControlType _
		= "CheckControl"

instance Controls PopUpControl where
189
	controlToHandles :: !(PopUpControl .ls (PSt .l)) !(PSt .l) -> (![ControlState .ls (PSt .l)],!PSt .l)
Peter Achten's avatar
Peter Achten committed
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
	controlToHandles (PopUpControl popUpItems index atts) pState
		# (wMetrics,ioState)		= IOStGetOSWindowMetrics pState.io
		# (size,ioState)			= getPopUpSize wMetrics (map fst popUpItems) cWidth ioState
		# nrItems					= length popUpItems
		= (	[WElementHandleToControlState
				(WItemHandle 
				{	wItemId			= getIdAttribute atts
				,	wItemNr			= 0
				,	wItemKind		= IsPopUpControl
				,	wItemShow		= not (Contains isControlHide atts)
				,	wItemSelect		= getSelectStateAttribute atts
				,	wItemInfo		= PopUpInfo 
										{	popUpInfoItems = popUpItems
										,	popUpInfoIndex = validatePopUpIndex nrItems index
										,	popUpInfoEdit  = Nothing
										}
				,	wItemAtts		= filter (not o redundantAttribute) atts
				,	wItems			= []
				,	wItemVirtual	= False
				,	wItemPos		= zero
				,	wItemSize		= size
				,	wItemPtr		= OSNoWindowPtr
				,	wItemLayoutInfo	= undef
				})
			]
		  ,	{pState & io=ioState}
		  )
	where
		cWidth						= getControlWidthAttribute atts
		
220
		getPopUpSize :: !OSWindowMetrics [String] !(Maybe ControlWidth) !(IOSt .l) -> (!Size,!IOSt .l)
Peter Achten's avatar
Peter Achten committed
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
		getPopUpSize wMetrics _ (Just (PixelWidth reqW)) ioState
			# wOK					= max (OSgetPopUpControlMinWidth wMetrics) reqW
			  hOK					= OSgetPopUpControlHeight wMetrics
			= ({w=wOK,h=hOK},ioState)
		getPopUpSize wMetrics _ (Just (TextWidth wtext)) ioState
			# (w,ioState)			= getDialogFontTextWidth wtext ioState
			  wOK					= max (OSgetPopUpControlMinWidth wMetrics) w
			  hOK					= OSgetPopUpControlHeight wMetrics
			= ({w=wOK,h=hOK},ioState)
		getPopUpSize wMetrics _ (Just (ContentWidth wtext)) ioState
			# ((w,hOK),ioState)		= accIOToolbox (OSgetPopUpControlSize wMetrics [wtext]) ioState
			  wOK					= max (OSgetPopUpControlMinWidth wMetrics) w
			= ({w=wOK,h=hOK},ioState)
		getPopUpSize wMetrics itemtexts Nothing ioState
			# ((w,hOK),ioState)		= accIOToolbox (OSgetPopUpControlSize wMetrics (if (isEmpty itemtexts) ["MMMMMMMMMM"] itemtexts)) ioState
			  wOK					= max (OSgetPopUpControlMinWidth wMetrics) w
			= ({w=wOK,h=hOK},ioState)
	getControlType _
		= "PopUpControl"

instance Controls SliderControl where
242
	controlToHandles :: !(SliderControl .ls (PSt .l)) !(PSt .l) -> (![ControlState .ls (PSt .l)],!PSt .l)
Peter Achten's avatar
Peter Achten committed
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
	controlToHandles (SliderControl direction cWidth sliderState action atts) pState
		# (wMetrics,ioState)		= IOStGetOSWindowMetrics pState.io
		# (size,ioState)			= getSliderSize wMetrics isHorizontal cWidth ioState
		= (	[WElementHandleToControlState
				(WItemHandle 
				{	wItemId			= getIdAttribute atts
				,	wItemNr			= 0
				,	wItemKind		= IsSliderControl
				,	wItemShow		= not (Contains isControlHide atts)
				,	wItemSelect		= getSelectStateAttribute atts
				,	wItemInfo		= SliderInfo 
				 						{	sliderInfoDir	= direction
				 						,	sliderInfoLength= if isHorizontal size.w size.h		// PA: maybe this field is now redundant
			 							,	sliderInfoState	= validateSliderState sliderState
			 							,	sliderInfoAction= action
			 							}
				,	wItemAtts		= filter (not o redundantAttribute) atts
				,	wItems			= []
				,	wItemVirtual	= False
				,	wItemPos		= zero
				,	wItemSize		= size
				,	wItemPtr		= OSNoWindowPtr
				,	wItemLayoutInfo	= undef
				})
			]
		  ,	{pState & io=ioState}
		  )
	where
		isHorizontal				= direction == Horizontal
		
273
		getSliderSize :: !OSWindowMetrics !Bool !ControlWidth !(IOSt .l) -> (!Size,!IOSt .l)
Peter Achten's avatar
Peter Achten committed
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
		getSliderSize wMetrics isHorizontal (PixelWidth reqW) ioState
			# (wOK,hOK)				= OSgetSliderControlSize wMetrics isHorizontal reqW
			= ({w=wOK,h=hOK},ioState)
		getSliderSize wMetrics isHorizontal (TextWidth wtext) ioState
			# (w,ioState)			= getDialogFontTextWidth wtext ioState
			  (wOK,hOK)				= OSgetSliderControlSize wMetrics isHorizontal w
			= ({w=wOK,h=hOK},ioState)
		getSliderSize wMetrics isHorizontal (ContentWidth wtext) ioState
			# (w,ioState)			= getDialogFontTextWidth wtext ioState
			  (wOK,hOK)				= OSgetSliderControlSize wMetrics isHorizontal w
			= ({w=wOK,h=hOK},ioState)
	getControlType _
		= "SliderControl"

instance Controls TextControl where
289
	controlToHandles :: !(TextControl .ls (PSt .l)) !(PSt .l) -> (![ControlState .ls (PSt .l)],!PSt .l)
Peter Achten's avatar
Peter Achten committed
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
	controlToHandles (TextControl textLine atts) pState
		# (wMetrics,ioState)		= IOStGetOSWindowMetrics pState.io
		# (size,ioState)			= getTextSize wMetrics textLine cWidth ioState
		= (	[WElementHandleToControlState
				(WItemHandle 
				{	wItemId			= getIdAttribute atts
				,	wItemNr			= 0
				,	wItemKind		= IsTextControl
				,	wItemShow		= not (Contains isControlHide atts)
				,	wItemSelect		= getSelectStateAttribute atts
				,	wItemInfo		= TextInfo {textInfoText=textLine}
				,	wItemAtts		= filter (not o redundantAttribute) atts
				,	wItems			= []
				,	wItemVirtual	= False
				,	wItemPos		= zero
				,	wItemSize		= size
				,	wItemPtr		= OSNoWindowPtr
				,	wItemLayoutInfo	= undef
				})
			]
		  ,	{pState & io=ioState}
		  )
	where
		cWidth						= getControlWidthAttribute atts
		
315
		getTextSize :: !OSWindowMetrics !String !(Maybe ControlWidth) !(IOSt .l) -> (!Size,!IOSt .l)
Peter Achten's avatar
Peter Achten committed
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
		getTextSize wMetrics _ (Just (PixelWidth reqW)) ioState
			# wOK					= max (OSgetTextControlMinWidth wMetrics) reqW
			  hOK					= OSgetTextControlHeight wMetrics
			= ({w=wOK,h=hOK},ioState)
		getTextSize wMetrics _ (Just (TextWidth wtext)) ioState
			# (w,ioState)			= getDialogFontTextWidth wtext ioState
			  wOK					= max (OSgetTextControlMinWidth wMetrics) w
			  hOK					= OSgetTextControlHeight wMetrics
			= ({w=wOK,h=hOK},ioState)
		getTextSize wMetrics _ (Just (ContentWidth wtext)) ioState
			# ((w,hOK),ioState)	= accIOToolbox (OSgetTextControlSize wMetrics wtext) ioState
			  wOK				= max (OSgetTextControlMinWidth wMetrics) w
			= ({w=wOK,h=hOK},ioState)
		getTextSize wMetrics text Nothing ioState
			# ((w,hOK),ioState)	= accIOToolbox (OSgetTextControlSize wMetrics text) ioState
			  wOK				= max (OSgetTextControlMinWidth wMetrics) w
			= ({w=wOK,h=hOK},ioState)
	getControlType _
		= "TextControl"

instance Controls EditControl where
337
	controlToHandles :: !(EditControl .ls (PSt .l)) !(PSt .l) -> (![ControlState .ls (PSt .l)],!PSt .l)
Peter Achten's avatar
Peter Achten committed
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
	controlToHandles (EditControl textLine cWidth nrLines atts) pState
		# (wMetrics,ioState)		= IOStGetOSWindowMetrics pState.io
		# (size,ioState)			= getEditSize wMetrics nrLines cWidth ioState
		= (	[WElementHandleToControlState
				(WItemHandle 
				{	wItemId			= getIdAttribute atts
				,	wItemNr			= 0
				,	wItemKind		= IsEditControl
				,	wItemShow		= not (Contains isControlHide atts)
				,	wItemSelect		= getSelectStateAttribute atts
				,	wItemInfo		= EditInfo
										{	editInfoText	= textLine
										,	editInfoWidth	= size.w			// PA: this field might have become redundant
										,	editInfoNrLines	= nrLines
										}
				,	wItemAtts		= filter (not o redundantAttribute) atts
				,	wItems			= []
				,	wItemVirtual	= False
				,	wItemPos		= zero
				,	wItemSize		= size
				,	wItemPtr		= OSNoWindowPtr
				,	wItemLayoutInfo	= undef
				})
			]
		  ,	{pState & io=ioState}
		  )
	where
365
		getEditSize :: !OSWindowMetrics Int !ControlWidth !(IOSt .l) -> (!Size,!IOSt .l)
Peter Achten's avatar
Peter Achten committed
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
		getEditSize wMetrics nrLines (PixelWidth reqW) ioState
			# ((w,hOK),ioState)		= accIOToolbox (OSgetEditControlSize wMetrics reqW nrLines) ioState
			# wOK					= max (OSgetEditControlMinWidth wMetrics) w
			= ({w=wOK,h=hOK},ioState)
		getEditSize wMetrics nrLines (TextWidth wtext) ioState
			# (w,ioState)			= getDialogFontTextWidth wtext ioState
			# ((w,hOK),ioState)		= accIOToolbox (OSgetEditControlSize wMetrics w nrLines) ioState
			  wOK					= max (OSgetEditControlMinWidth wMetrics) w
			= ({w=wOK,h=hOK},ioState)
		getEditSize wMetrics nrLines _ ioState
			= ({w=100,h=OSgetEditControlHeight wMetrics nrLines},ioState)
	getControlType _
		= "EditControl"

instance Controls ButtonControl where
381
	controlToHandles :: !(ButtonControl .ls (PSt .l)) !(PSt .l) -> (![ControlState .ls (PSt .l)],!PSt .l)
Peter Achten's avatar
Peter Achten committed
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
	controlToHandles (ButtonControl textLine atts) pState
		# (wMetrics,ioState)		= IOStGetOSWindowMetrics pState.io
		# (size,ioState)			= getButtonSize wMetrics textLine cWidth ioState
		= (	[WElementHandleToControlState
				(WItemHandle 
				{	wItemId			= getIdAttribute atts
				,	wItemNr			= 0
				,	wItemKind		= IsButtonControl
				,	wItemShow		= not (Contains isControlHide atts)
				,	wItemSelect		= getSelectStateAttribute atts
				,	wItemInfo		= ButtonInfo {buttonInfoText=textLine}
				,	wItemAtts		= filter (not o redundantAttribute) atts
				,	wItems			= []
				,	wItemVirtual	= False
				,	wItemPos		= zero
				,	wItemSize		= size
				,	wItemPtr		= OSNoWindowPtr
				,	wItemLayoutInfo	= undef
				})
			]
		  ,	{pState & io=ioState}
		  )
	where
		cWidth						= getControlWidthAttribute atts
		
407
		getButtonSize :: !OSWindowMetrics String !(Maybe ControlWidth) !(IOSt .l) -> (!Size,!IOSt .l)
Peter Achten's avatar
Peter Achten committed
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
		getButtonSize wMetrics _ (Just (PixelWidth reqW)) ioState
			# wOK					= max (OSgetButtonControlMinWidth wMetrics) reqW
			# hOK					= OSgetButtonControlHeight wMetrics
			= ({w=wOK,h=hOK},ioState)
		getButtonSize wMetrics _ (Just (TextWidth wtext)) ioState
			# (w,ioState)			= getDialogFontTextWidth wtext ioState
			  wOK					= max (OSgetButtonControlMinWidth wMetrics) w
			  hOK					= OSgetButtonControlHeight wMetrics
			= ({w=wOK,h=hOK},ioState)
		getButtonSize wMetrics _ (Just (ContentWidth wtext)) ioState
			# ((w,hOK),ioState)		= accIOToolbox (OSgetButtonControlSize wMetrics wtext) ioState
			  wOK					= max (OSgetButtonControlMinWidth wMetrics) w
			= ({w=wOK,h=hOK},ioState)
		getButtonSize wMetrics text Nothing ioState
			# ((w,hOK),ioState)		= accIOToolbox (OSgetButtonControlSize wMetrics text) ioState
			  wOK					= max (OSgetButtonControlMinWidth wMetrics) w
			= ({w=wOK,h=hOK},ioState)
	getControlType _
		= "ButtonControl"

instance Controls CustomButtonControl where
429
	controlToHandles :: !(CustomButtonControl .ls (PSt .l)) !(PSt .l) -> (![ControlState .ls (PSt .l)],!PSt .l)
Peter Achten's avatar
Peter Achten committed
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
	controlToHandles (CustomButtonControl {w,h} controlLook atts) pState
		# size	= {w=max 0 w,h=max 0 h}
		= (	[WElementHandleToControlState
				(WItemHandle 
				{	wItemId			= getIdAttribute atts
				,	wItemNr			= 0
				,	wItemKind		= IsCustomButtonControl
				,	wItemShow		= not (Contains isControlHide atts)
				,	wItemSelect		= getSelectStateAttribute atts
				,	wItemInfo		= CustomButtonInfo {cButtonInfoLook={lookFun=controlLook,lookPen=pen,lookSysUpdate=True}}
				,	wItemAtts		= filter (not o redundantAttribute) atts
				,	wItems			= []
				,	wItemVirtual	= False
				,	wItemPos		= zero
				,	wItemSize		= size
				,	wItemPtr		= OSNoWindowPtr
				,	wItemLayoutInfo	= undef
				})
			]
		  ,	pState
		  )
	where
		(_,pen)						= getInitialPen atts
	getControlType _
		= "CustomButtonControl"

instance Controls CustomControl where
457
	controlToHandles :: !(CustomControl .ls (PSt .l)) !(PSt .l) -> (![ControlState .ls (PSt .l)],!PSt .l)
Peter Achten's avatar
Peter Achten committed
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
	controlToHandles (CustomControl {w,h} controlLook atts) pState
		# size	= {w=max 0 w,h=max 0 h}
		= (	[WElementHandleToControlState
				(WItemHandle 
				{	wItemId			= getIdAttribute atts
				,	wItemNr			= 0
				,	wItemKind		= IsCustomControl
				,	wItemShow		= not (Contains isControlHide atts)
				,	wItemSelect		= getSelectStateAttribute atts
				,	wItemInfo		= CustomInfo {customInfoLook={lookFun=controlLook,lookPen=pen,lookSysUpdate=True}}
				,	wItemAtts		= filter (not o redundantAttribute) atts
				,	wItems			= []
				,	wItemVirtual	= False
				,	wItemPos		= zero
				,	wItemSize		= size
				,	wItemPtr		= OSNoWindowPtr
				,	wItemLayoutInfo	= undef
				})
			]
		  ,	pState
		  )
	where
		(_,pen)						= getInitialPen atts
	getControlType _
		= "CustomControl"

instance Controls (CompoundControl c)	| Controls c where
485
	controlToHandles :: !(CompoundControl c .ls (PSt .l)) !(PSt .l) -> (![ControlState .ls (PSt .l)],!PSt .l)	| Controls c
Peter Achten's avatar
Peter Achten committed
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
	controlToHandles (CompoundControl controls atts) pState
		# (cs,pState)	= controlToHandles controls pState
		= (	[WElementHandleToControlState
				(WItemHandle 
				{	wItemId			= getIdAttribute atts
				,	wItemNr			= 0
				,	wItemKind		= IsCompoundControl
				,	wItemShow		= not (Contains isControlHide atts)
				,	wItemSelect		= getSelectStateAttribute atts
				,	wItemInfo		= CompoundInfo
										{	compoundDomain	= RectangleToRect domain
										,	compoundOrigin	= origin
										,	compoundHScroll	= if hasHScroll (Just hScrollInfo) Nothing
										,	compoundVScroll	= if hasVScroll (Just vScrollInfo) Nothing
										,	compoundLookInfo= if (hasLook || hasPenAtts)
																(Just {compoundLook={	lookFun			= lookFun
																					,	lookPen			= pen
																					,	lookSysUpdate	= sysLook
																					}
																	  ,compoundClip={clipRgn=0,clipOk=False}
																	  }
																)
																Nothing
										}
				,	wItemAtts		= filter (not o redundantAttribute) atts
				,	wItems			= map ControlStateToWElementHandle cs
				,	wItemVirtual	= False
				,	wItemPos		= zero
				,	wItemSize		= zero
				,	wItemPtr		= OSNoWindowPtr
				,	wItemLayoutInfo	= undef
				})
			]
		  ,	pState
		  )
	where
		(hasHScroll,hScrollAtt)		= Select isControlHScroll undef atts
		(hasVScroll,vScrollAtt)		= Select isControlVScroll undef atts
		(hasLook,lookAtt)			= Select isControlLook (ControlLook True (\_ _ p->p)) atts
		(sysLook,lookFun)			= getControlLookAtt lookAtt
		defaultDomain				= ControlViewDomain {viewDomainRange & corner1=zero}
		(_,domainAtt)				= Select isControlViewDomain defaultDomain atts
		domain						= validateViewDomain (getControlViewDomainAtt domainAtt)
		(_,originAtt)				= Select isControlOrigin (ControlOrigin domain.corner1) atts
		origin						= validateOrigin domain (getControlOriginAtt originAtt)
		hScrollInfo					= {	scrollFunction	= getControlHScrollFun hScrollAtt
									  ,	scrollItemPos	= zero
									  ,	scrollItemSize	= zero
									  ,	scrollItemPtr	= OSNoWindowPtr
									  }
		vScrollInfo					= {	scrollFunction	= getControlVScrollFun vScrollAtt
									  ,	scrollItemPos	= zero
									  ,	scrollItemSize	= zero
									  ,	scrollItemPtr	= OSNoWindowPtr
									  }
		(hasPenAtts,pen)			= getInitialPen atts
	getControlType _
		= "CompoundControl"


//	Additional functions:

getDialogFontTextWidth :: !String !*env -> (!Int,!*env) | accScreenPicture env
getDialogFontTextWidth s env
	= accScreenPicture getTextWidth env
where
	getTextWidth :: !*Picture -> (!Int,!*Picture)
	getTextWidth picture
		# (dialogFont,picture)	= openDialogFont picture
		= getFontStringWidth dialogFont s picture

getIdAttribute :: ![ControlAttribute .st] -> Maybe Id
getIdAttribute atts
	| hasId			= Just (getControlIdAtt idAtt)
	| otherwise		= Nothing
where
	(hasId,idAtt)	= Select isControlId undef atts

getControlWidthAttribute :: ![ControlAttribute .st] -> Maybe ControlWidth
getControlWidthAttribute atts
	| hasControlWidth			= Just (getControlWidthAtt widthAtt)
	| otherwise					= Nothing
where
	(hasControlWidth,widthAtt)	= Select isControlWidth undef atts

getSelectStateAttribute :: ![ControlAttribute .st] -> Bool
getSelectStateAttribute atts
	= enabled (getControlSelectStateAtt (snd (Select isControlSelectState (ControlSelectState Able) atts)))

redundantAttribute :: !(ControlAttribute .st) -> Bool
redundantAttribute (ControlId _)			= True
redundantAttribute ControlHide				= True
redundantAttribute (ControlSelectState _)	= True
redundantAttribute (ControlLook _ _)		= True
redundantAttribute (ControlViewDomain _)	= True
redundantAttribute _						= False

getInitialPen :: ![ControlAttribute .st] -> (!Bool,!Pen)
getInitialPen atts
	= (hasPenAtts,pen)
where
	(hasPenAtts,penAttsAtt)	= Select isControlPen undef atts
	pen						= if hasPenAtts (StateMap2 setPenAttribute (reverse (getControlPenAtt penAttsAtt)) defaultPen) defaultPen

validateLayout :: !Int !RowsOrColumns -> RowsOrColumns
validateLayout nrItems (Rows    n) = Rows    (SetBetween n 1 nrItems)
validateLayout nrItems (Columns n) = Columns (SetBetween n 1 nrItems)

validatePopUpIndex :: !Int !Index -> Index
validatePopUpIndex nrItems index
	| IsBetween index 1 nrItems	= index
	| otherwise					= 1

validateOrigin :: !ViewDomain !Point2 -> Point2
validateOrigin domain origin
	= {	x=SetBetween origin.x domain.corner1.x domain.corner2.x
	  ,	y=SetBetween origin.y domain.corner1.y domain.corner2.y
	  }