controlrelayout.icl 11.5 KB
Newer Older
Peter Achten's avatar
Peter Achten committed
1
2
3
4
5
6
implementation module controlrelayout


//	Clean Object I/O library, version 1.2


7
import StdBool, StdList, StdMisc
Peter Achten's avatar
Peter Achten committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import relayout, windowaccess, windowclipstate, wstateaccess


/*	relayoutControls(`) wMetrics isAble oldFrame newFrame oldParentPos newParentPos parentPtr defaultId old new
	resizes, moves, and updates changed WElementHandle(`)s. 
		isAble							is True iff the parent window/compound is Able.
		oldFrame						is the clipping rect of the parent window/compound at the original location and size.
		newFrame						is the clipping rect of the parent window/compound at the new location and size.
		oldParentPos and newParentPos	are the positions of the respective parent window/compound of the elements.
		parentPtr						is the parent window/dialog.
		defaultId						is the optional Id of the default control.
		old								contains the elements at their original location and size.
		new								contains the elements at their new location and size.
	relayoutControls(`) assumes that the two lists contain elements that are identical except for size and position.
		If this is not the case, a runtime error will occur.
	relayoutControls(`) assumes that the ClipStates of all compound elements are valid.
	The return OSRgnHandle is the area of the window that requires to be updated (use updatewindowbackgrounds [windowupdate] for this purpose).
*/
26
relayoutControls :: !OSWindowMetrics !Bool !Bool !Rect !Rect !Point2 !Point2 !OSWindowPtr !(Maybe Id)
Peter Achten's avatar
Peter Achten committed
27
					![WElementHandle .ls .pst] ![WElementHandle .ls .pst] !*OSToolbox -> (!OSRgnHandle,!*OSToolbox)
28
relayoutControls wMetrics isAble isVisible oldFrame newFrame oldParentPos newParentPos wPtr defaultId oldHs newHs tb
29
30
31
	= relayoutItems wMetrics oldFrame newFrame oldParentPos newParentPos wPtr
					(WElementHandlesToRelayoutItems isAble isVisible oldHs [])
					(WElementHandlesToRelayoutItems isAble isVisible newHs [])
Peter Achten's avatar
Peter Achten committed
32
33
					tb
where
34
35
36
	WElementHandlesToRelayoutItems :: !Bool !Bool ![WElementHandle .ls .pst] ![RelayoutItem] -> [RelayoutItem]
	WElementHandlesToRelayoutItems isAble isVisible [itemH:itemHs] items
		= WElementHandleToRelayoutItems isAble isVisible itemH (WElementHandlesToRelayoutItems isAble isVisible itemHs items)
Peter Achten's avatar
Peter Achten committed
37
	where
38
39
40
		WElementHandleToRelayoutItems :: !Bool !Bool !(WElementHandle .ls .pst) ![RelayoutItem] -> [RelayoutItem]
		WElementHandleToRelayoutItems isAble isVisible (WItemHandle itemH=:{wItemKind}) items
			= WItemHandleToRelayoutItems wItemKind isAble isVisible itemH items
Peter Achten's avatar
Peter Achten committed
41
		where
42
43
44
			WItemHandleToRelayoutItems :: !ControlKind !Bool !Bool !(WItemHandle .ls .pst) ![RelayoutItem] -> [RelayoutItem]
			WItemHandleToRelayoutItems controlKind=:IsRadioControl isAble isVisible itemH=:{wItemSelect,wItemShow} items
				= RadioItemToRelayoutItems (isAble && wItemSelect) (isVisible && wItemShow) (getWItemRadioInfo itemH.wItemInfo).radioItems items
Peter Achten's avatar
Peter Achten committed
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
			where
				RadioItemToRelayoutItems :: !Bool !Bool ![RadioItemInfo *(.ls,.pst)] ![RelayoutItem] -> [RelayoutItem]
				RadioItemToRelayoutItems isAble isVisible [radio:radios] items
					#! item	= RadioItemInfoToRelayoutItem isAble isVisible radio
					=  [item:RadioItemToRelayoutItems isAble isVisible radios items]
				where
					RadioItemInfoToRelayoutItem :: !Bool !Bool !(RadioItemInfo .pst) -> RelayoutItem
					RadioItemInfoToRelayoutItem isAble isVisible {radioItemPos,radioItemSize,radioItemPtr}
						= {	rliItemKind		= controlKind
						  ,	rliItemPtr		= radioItemPtr
						  ,	rliItemPos		= radioItemPos
						  ,	rliItemSize		= radioItemSize
						  ,	rliItemSelect	= isAble
						  ,	rliItemShow		= isVisible
						  ,	rliItemInfo		= undef
						  ,	rliItemLook		= undef
						  ,	rliItems		= []
						  }
				RadioItemToRelayoutItems _ _ _ items
					= items
			
66
67
			WItemHandleToRelayoutItems controlKind=:IsCheckControl isAble isVisible itemH=:{wItemSelect,wItemShow} items
				= CheckItemToRelayoutItems (isAble && wItemSelect) (isVisible && wItemShow) (getWItemCheckInfo itemH.wItemInfo).checkItems items
Peter Achten's avatar
Peter Achten committed
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
			where
				CheckItemToRelayoutItems :: !Bool !Bool ![CheckItemInfo *(.ls,.pst)] ![RelayoutItem] -> [RelayoutItem]
				CheckItemToRelayoutItems isAble isVisible [check:checks] items
					#! item	= CheckItemInfoToRelayoutItem isAble isVisible check
					=  [item:CheckItemToRelayoutItems isAble isVisible checks items]
				where
					CheckItemInfoToRelayoutItem :: !Bool !Bool !(CheckItemInfo .pst) -> RelayoutItem
					CheckItemInfoToRelayoutItem isAble isVisible {checkItemPos,checkItemSize,checkItemPtr}
						= {	rliItemKind		= controlKind
						  ,	rliItemPtr		= checkItemPtr
						  ,	rliItemPos		= checkItemPos
						  ,	rliItemSize		= checkItemSize
						  ,	rliItemSelect	= isAble
						  ,	rliItemShow		= isVisible
						  ,	rliItemInfo		= undef
						  ,	rliItemLook		= undef
						  ,	rliItems		= []
						  }
				CheckItemToRelayoutItems _ _ _ items
					= items
			
89
			WItemHandleToRelayoutItems controlKind isAble isVisible itemH=:{wItemPtr,wItemPos,wItemSize,wItemSelect,wItemShow} items
Peter Achten's avatar
Peter Achten committed
90
91
92
93
				#! item		=	{	rliItemKind		= controlKind
								,	rliItemPtr		= wItemPtr
								,	rliItemPos		= wItemPos
								,	rliItemSize		= wItemSize
94
								,	rliItemSelect	= isAble`
95
								,	rliItemShow		= isVisible`
Peter Achten's avatar
Peter Achten committed
96
97
98
99
100
101
								,	rliItemInfo		= info
								,	rliItemLook		= look
								,	rliItems		= items`
								}
				= [item:items]
			where
102
				isAble`				= isAble    && wItemSelect
103
				isVisible`			= isVisible && wItemShow
104
				(info,look,items`)	= getinfo controlKind isAble` isVisible` itemH
Peter Achten's avatar
Peter Achten committed
105
				
106
107
108
				getinfo :: !ControlKind !Bool !Bool !(WItemHandle .ls .pst) -> (CompoundInfo,LookInfo,![RelayoutItem])
				getinfo IsCompoundControl isAble isVisible {wItemInfo,wItems}
					= (info,info.compoundLookInfo.compoundLook,WElementHandlesToRelayoutItems isAble isVisible wItems [])
Peter Achten's avatar
Peter Achten committed
109
110
				where
					info	= getWItemCompoundInfo wItemInfo
111
				getinfo IsCustomButtonControl _ _ {wItemInfo}
Peter Achten's avatar
Peter Achten committed
112
					= (undef,(getWItemCustomButtonInfo wItemInfo).cButtonInfoLook,[])
113
				getinfo IsCustomControl _ _ {wItemInfo}
Peter Achten's avatar
Peter Achten committed
114
					= (undef,(getWItemCustomInfo wItemInfo).customInfoLook,[])
115
116
117
				getinfo IsLayoutControl isAble isVisible {wItems}
					= (undef,undef,WElementHandlesToRelayoutItems isAble isVisible wItems [])
				getinfo _ _ _ _
Peter Achten's avatar
Peter Achten committed
118
119
					= (undef,undef,[])
		
120
121
		WElementHandleToRelayoutItems isAble isVisible (WListLSHandle itemHs) items
			= WElementHandlesToRelayoutItems isAble isVisible itemHs items
Peter Achten's avatar
Peter Achten committed
122
		
123
124
		WElementHandleToRelayoutItems isAble isVisible (WExtendLSHandle {wExtendItems=itemHs}) items
			= WElementHandlesToRelayoutItems isAble isVisible itemHs items
Peter Achten's avatar
Peter Achten committed
125
		
126
127
		WElementHandleToRelayoutItems isAble isVisible (WChangeLSHandle {wChangeItems=itemHs}) items
			= WElementHandlesToRelayoutItems isAble isVisible itemHs items
Peter Achten's avatar
Peter Achten committed
128
	
129
	WElementHandlesToRelayoutItems _ _ _ items
Peter Achten's avatar
Peter Achten committed
130
131
132
		= items


133
relayoutControls` :: !OSWindowMetrics !Bool !Bool !Rect !Rect !Point2 !Point2 !OSWindowPtr !(Maybe Id)
Peter Achten's avatar
Peter Achten committed
134
					 ![WElementHandle`] ![WElementHandle`] !*OSToolbox -> (!OSRgnHandle,!*OSToolbox)
135
relayoutControls` wMetrics isAble isVisible oldFrame newFrame oldParentPos newParentPos wPtr defaultId oldHs newHs tb
136
137
138
	= relayoutItems wMetrics oldFrame newFrame oldParentPos newParentPos wPtr
					(WElementHandles`ToRelayoutItems isAble isVisible oldHs [])
					(WElementHandles`ToRelayoutItems isAble isVisible newHs [])
Peter Achten's avatar
Peter Achten committed
139
140
					tb
where
141
142
143
	WElementHandles`ToRelayoutItems :: !Bool !Bool ![WElementHandle`] ![RelayoutItem] -> [RelayoutItem]
	WElementHandles`ToRelayoutItems isAble isVisible [itemH:itemHs] items
		= WElementHandle`ToRelayoutItems isAble isVisible itemH (WElementHandles`ToRelayoutItems isAble isVisible itemHs items)
Peter Achten's avatar
Peter Achten committed
144
	where
145
146
147
		WElementHandle`ToRelayoutItems :: !Bool !Bool !WElementHandle` ![RelayoutItem] -> [RelayoutItem]
		WElementHandle`ToRelayoutItems isAble isVisible (WItemHandle` itemH=:{wItemKind`}) items
			= WItemHandle`ToRelayoutItems wItemKind` isAble isVisible itemH items
Peter Achten's avatar
Peter Achten committed
148
		where
149
150
151
			WItemHandle`ToRelayoutItems :: !ControlKind !Bool !Bool !WItemHandle` ![RelayoutItem] -> [RelayoutItem]
			WItemHandle`ToRelayoutItems controlKind=:IsRadioControl isAble isVisible itemH=:{wItemSelect`,wItemShow`} items
				= RadioItem`ToRelayoutItems (isAble && wItemSelect`) (isVisible && wItemShow`) (getWItemRadioInfo` itemH.wItemInfo`).radioItems` items
Peter Achten's avatar
Peter Achten committed
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
			where
				RadioItem`ToRelayoutItems :: !Bool !Bool ![RadioItemInfo`] ![RelayoutItem] -> [RelayoutItem]
				RadioItem`ToRelayoutItems isAble isVisible [radio:radios] items
					#! item	= RadioItemInfo`ToRelayoutItem isAble isVisible radio
					=  [item:RadioItem`ToRelayoutItems isAble isVisible radios items]
				where
					RadioItemInfo`ToRelayoutItem :: !Bool !Bool !RadioItemInfo` -> RelayoutItem
					RadioItemInfo`ToRelayoutItem isAble isVisible {radioItemPos`,radioItemSize`,radioItemPtr`}
						= {	rliItemKind		= controlKind
						  ,	rliItemPtr		= radioItemPtr`
						  ,	rliItemPos		= radioItemPos`
						  ,	rliItemSize		= radioItemSize`
						  ,	rliItemSelect	= isAble
						  ,	rliItemShow		= isVisible
						  ,	rliItemInfo		= undef
  						  ,	rliItemLook		= undef
						  ,	rliItems		= []
						  }
				RadioItem`ToRelayoutItems _ _ _ items
					= items
			
173
174
			WItemHandle`ToRelayoutItems controlKind=:IsCheckControl isAble isVisible itemH=:{wItemSelect`,wItemShow`} items
				= CheckItem`ToRelayoutItems (isAble && wItemSelect`) (isVisible && wItemShow`) (getWItemCheckInfo` itemH.wItemInfo`).checkItems` items
Peter Achten's avatar
Peter Achten committed
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
			where
				CheckItem`ToRelayoutItems :: !Bool !Bool ![CheckItemInfo`] ![RelayoutItem] -> [RelayoutItem]
				CheckItem`ToRelayoutItems isAble isVisible [check:checks] items
					#! item	= CheckItemInfo`ToRelayoutItem isAble isVisible check
					=  [item:CheckItem`ToRelayoutItems isAble isVisible checks items]
				where
					CheckItemInfo`ToRelayoutItem :: !Bool !Bool !CheckItemInfo` -> RelayoutItem
					CheckItemInfo`ToRelayoutItem isAble isVisible {checkItemPos`,checkItemSize`,checkItemPtr`}
						= {	rliItemKind		= controlKind
						  ,	rliItemPtr		= checkItemPtr`
						  ,	rliItemPos		= checkItemPos`
						  ,	rliItemSize		= checkItemSize`
						  ,	rliItemSelect	= isAble
						  ,	rliItemShow		= isVisible
						  ,	rliItemInfo		= undef
						  ,	rliItemLook		= undef
						  ,	rliItems		= []
						  }
				CheckItem`ToRelayoutItems _ _ _ items
					= items
			
196
			WItemHandle`ToRelayoutItems controlKind isAble isVisible itemH=:{wItemPtr`,wItemPos`,wItemSize`,wItemSelect`,wItemShow`} items
Peter Achten's avatar
Peter Achten committed
197
198
199
200
				#! item		=	{	rliItemKind		= controlKind
								,	rliItemPtr		= wItemPtr`
								,	rliItemPos		= wItemPos`
								,	rliItemSize		= wItemSize`
201
								,	rliItemSelect	= isAble`
202
								,	rliItemShow		= isVisible`
Peter Achten's avatar
Peter Achten committed
203
204
205
206
207
208
								,	rliItemInfo		= info
								,	rliItemLook		= look
								,	rliItems		= items`
								}
				= [item:items]
			where
209
				isAble`				= isAble    && wItemSelect`
210
				isVisible`			= isVisible && wItemShow`
211
				(info,look,items`)	= getinfo controlKind isAble` isVisible` itemH
Peter Achten's avatar
Peter Achten committed
212
				
213
214
215
				getinfo :: !ControlKind !Bool !Bool !WItemHandle` -> (CompoundInfo,LookInfo,![RelayoutItem])
				getinfo IsCompoundControl isAble isVisible {wItemInfo`,wItems`}
					= (info,info.compoundLookInfo.compoundLook,WElementHandles`ToRelayoutItems isAble isVisible wItems` [])
Peter Achten's avatar
Peter Achten committed
216
217
				where
					info	= getWItemCompoundInfo` wItemInfo`
218
				getinfo IsCustomButtonControl _ _ {wItemInfo`}
Peter Achten's avatar
Peter Achten committed
219
					= (undef,(getWItemCustomButtonInfo` wItemInfo`).cButtonInfoLook,[])
220
				getinfo IsCustomControl _ _ {wItemInfo`}
Peter Achten's avatar
Peter Achten committed
221
					= (undef,(getWItemCustomInfo` wItemInfo`).customInfoLook,[])
222
223
224
				getinfo IsLayoutControl isAble isVisible {wItems`}
					= (undef,undef,WElementHandles`ToRelayoutItems isAble isVisible wItems` [])
				getinfo _ _ _ _
Peter Achten's avatar
Peter Achten committed
225
226
					= (undef,undef,[])
		
227
228
		WElementHandle`ToRelayoutItems isAble isVisible (WRecursiveHandle` itemHs _) items
			= WElementHandles`ToRelayoutItems isAble isVisible itemHs items
Peter Achten's avatar
Peter Achten committed
229
	
230
	WElementHandles`ToRelayoutItems _ _ _ items
Peter Achten's avatar
Peter Achten committed
231
		= items