Initial revision
[ssr] / StraySrc / Libraries / Sapphire / s / errorBox
1 ;
2 ; errorBox.s
3 ;
4 ; Reports errors in an error box (MDW)
5 ;
6 ; © 1994-1998 Straylight
7 ;
8
9 ;----- Licensing note -------------------------------------------------------
10 ;
11 ; This file is part of Straylight's Sapphire library.
12 ;
13 ; Sapphire is free software; you can redistribute it and/or modify
14 ; it under the terms of the GNU General Public License as published by
15 ; the Free Software Foundation; either version 2, or (at your option)
16 ; any later version.
17 ;
18 ; Sapphire is distributed in the hope that it will be useful,
19 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ; GNU General Public License for more details.
22 ;
23 ; You should have received a copy of the GNU General Public License
24 ; along with Sapphire. If not, write to the Free Software Foundation,
25 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27 ;----- Standard header ------------------------------------------------------
28
29 GET libs:header
30 GET libs:swis
31
32 GET libs:stream
33
34 ;----- External dependencies ------------------------------------------------
35
36 GET sapphire:buttons
37 GET sapphire:dbox
38 GET sapphire:msgs
39 GET sapphire:nopoll
40 GET sapphire:sapphire
41 GET sapphire:string
42 GET sapphire:template
43 GET sapphire:wimp
44
45 ;----- Icon numbers ---------------------------------------------------------
46
47 ebIcon__title EQU 3
48 ebIcon__error EQU 4
49 ebIcon__buttons EQU 5
50
51 eb__buts EQU 4
52
53 ;----- Main code ------------------------------------------------------------
54
55 AREA |Sapphire$$Code|,CODE,READONLY
56
57 ; --- errorBox_init ---
58 ;
59 ; On entry: R0 == pointer to application name
60 ;
61 ; On exit: --
62 ;
63 ; Use: Initialises the errorBox system nicely. It creates the
64 ; dialogue box now, and just uses it for the rest of the
65 ; time.
66
67 EXPORT errorBox_init
68 errorBox_init ROUT
69
70 STMFD R13!,{R0-R3,R12,R14} ;Save some registers
71 WSPACE eb__wSpace ;Load my workspace pointer
72
73 ; --- Am I running yet? ---
74
75 LDR R14,eb__dbox ;Load the dialogue box handle
76 CMP R14,#0 ;Has it been defined yet?
77 LDMNEFD R13!,{R0-R3,R12,PC}^ ;Yes -- return right now
78
79 ; --- Initialise other useful things ---
80
81 BL wimp_init ;Initialise the WindowMangler
82 BL template_init ;Load lots of templates
83 BL dbox_init ;Allow me to make dboxes
84 BL nopoll_init ;I'll want to use nopoll too
85
86 ; --- Create my dialogue box ---
87
88 ADR R0,eb__dbName ;Point to the dialogue name
89 BL dbox_create ;Create the dialogue box
90 SWIVS OS_GenerateError ;If it failed, abort nastily
91 STR R0,eb__dbox ;Store the handle away
92
93 ; --- Fill in the dialogue box title ---
94
95 ADR R0,eb__errorFrom ;Point to the skeleton
96 BL msgs_lookup ;Translate the string
97 MOV R1,R11 ;Fill it in the scratchpad
98 LDR R2,[R13,#0] ;Find the application name
99 BL str_subst ;Substitute the string then
100 MOV R2,R0 ;Point to the string
101 LDR R0,eb__dbox ;Get the dialogue handle
102 MOV R1,#-1 ;Fill in the title bar
103 BL dbox_setField ;Actually write the string
104
105 ; --- Set up the rest of the dialogue box ---
106
107 MOV R1,#ebIcon__title ;Icon for the embedded title
108 BL dbox_setEmbeddedTitle ;Set up the embedded title
109 ADR R1,eb__dbHandler ;Point to my event handler
110 MOV R2,R0 ;Pass dbox handle in R10
111 MOV R3,R12 ;Pass workspace in R12
112 BL dbox_eventHandler ;Set up the event handler
113
114 LDMFD R13!,{R0-R3,R12,PC}^ ;Return to the caller
115
116 eb__dbName DCB "error",0
117 eb__errorFrom DCB "ebERRFRM",0
118
119 LTORG
120
121 eb__wSpace DCD 0
122
123 ; --- eb__dbHandler ---
124 ;
125 ; On entry: R0 == reason code
126 ; R1-... dependant on reason code
127 ; R10 == dialogue box handle
128 ; R12 == pointer to workspace
129 ;
130 ; On exit: Registers preserved
131 ;
132 ; Use: Handles events for the error box
133
134 eb__dbHandler ROUT
135
136 STMFD R13!,{R14} ;Save a register
137 CMP R0,#dbEvent_OK ;Is it a return press?
138 MOVEQ R0,#ebIcon__buttons ;Yes -- use the default
139 CMP R0,#dbEvent_cancel ;Is it a cancel?
140 LDREQ R0,eb__cancel ;Yes -- load the button
141 CMPEQ R0,#-1 ;Was that defined?
142 MOVEQ R0,#ebIcon__buttons ;No -- use default here too
143
144 SUB R14,R0,#ebIcon__buttons ;Get the button index
145 CMP R14,#eb__buts ;Is it in range?
146 LDMCSFD R13!,{PC}^ ;No -- return
147
148 STMFD R13!,{R0,R1} ;Save some more registers
149 LDR R1,eb__butFlags ;Which buttons are there?
150 MOV R14,#1 ;Use a bit to test
151 TST R1,R14,LSL R0 ;Test the correct bit
152 LDMEQFD R13!,{R0,R1,PC}^ ;Not created -- return
153
154 MOV R1,R0 ;Put icon into R1
155 LDR R0,eb__dbox ;Find the dialogue handle
156 BL dbox_slab ;Slab the icon in
157 BL dbox_close ;Close the window
158 BL dbox_unslab ;Unslab the icon cunningly
159 MOV R0,R1 ;Return the icon number
160 BL nopoll_close ;Return that to errorBox
161 LDMFD R13!,{R0,R1,PC}^ ;And return to caller
162
163 LTORG
164
165 ; --- errorBox_beep ---
166 ;
167 ; On entry: --
168 ;
169 ; On exit: --
170 ;
171 ; Use: Sounds the bell (VDU 7) if the CMOS settings dictate that
172 ; error boxes should cause a beep.
173
174 EXPORT errorBox_beep
175 errorBox_beep ROUT
176
177 STMFD R13!,{R0-R2,R14} ;Save some registers
178 MOV R0,#161 ;Read CMOS locations nicely
179 MOV R1,#197 ;Read WimpFlags location
180 SWI OS_Byte ;Do the read operation
181 TST R2,#1<<4 ;Do we make noises then?
182 SWIEQ OS_WriteI+7 ;Yes -- bleep
183 LDMFD R13!,{R0-R2,PC}^ ;Return to caller
184
185 LTORG
186
187 ; --- errorBox ---
188 ;
189 ; On entry: R0 == pointer to error block
190 ; R1 == button style code, or pointer to buttons block
191 ;
192 ; On exit: R0 == icon number clicked (ordered from the right)
193 ; CS if R0 == 0, else CC
194 ;
195 ; Use: Displays an error box on the screen. The error block
196 ; doesn't have to have a sensible error number, and doesn't
197 ; have to be word aligned, either.
198 ;
199 ; Since errorBox claims a dialogue box handle on
200 ; initialisation, it isn't possible for this call to fail.
201 ; Hence it is ideal for reporting problems like `Out of
202 ; memory' or `Too many windows'.
203 ;
204 ; The buttons in the error box may be given either by a code
205 ; or by a pointer to a buttons block (these may easily be
206 ; distinguished, since the codes are lower than &8000).
207 ;
208 ; Standard button arrangements are given by codes, as follows:
209 ;
210 ; 0 == Cancel
211 ; 1 == OK
212 ; 2 == OK, Cancel
213 ; 4 == OK, Help
214 ; 5 == OK, Cancel, Help
215
216 EXPORT errorBox
217 errorBox ROUT
218
219 STMFD R13!,{R1-R4,R12,R14} ;Save some registers away
220 WSPACE eb__wSpace ;Find my workspace address
221 MOV R4,R0 ;Look after error pointer
222 LDR R0,eb__dbox ;Load the dbox handle
223
224 ; --- Deal with button codes ---
225
226 CMP R1,#eb__endButs-eb__stdButs
227 ADRCC R14,eb__stdButs ;If it's a code, find the tbl
228 LDRCCB R1,[R14,R1] ;Load the offset of the block
229 ADDCC R1,R14,R1 ;And find the button block
230
231 ; --- Set up the buttons ---
232
233 MOV R2,#ebIcon__buttons ;Find icon base
234 MOV R3,#eb__buts ;Get the number allowed
235 BL buttons_setup ;Set up the dialogue box
236 STR R2,eb__butFlags ;Save the button flags
237 STR R3,eb__cancel ;Save the cancel button
238
239 ; --- Set the string in the dbox ---
240
241 MOV R1,#ebIcon__error ;The right icon for the job
242 ADD R2,R4,#4 ;Find the error string
243 BL dbox_setField ;Write the string in nicely
244
245 ; --- Display the dialogue ---
246
247 BL errorBox_beep ;Sound the bell if we need to
248 MOV R1,#dbOpen_centre+dbOpen_persist+dbOpen_nonSub
249 BL dbox_open ;Open centred on the screen
250
251 ; --- Handle the dialogue properly ---
252
253 BL dbox_window ;Find the window handle again
254 BL nopoll_open ;Stop polling for a while
255 BL nopoll_process ;Let nopoll take over
256 LDMFD R13!,{R1-R4,R12,R14} ;Return to caller
257 SUBS R0,R0,#ebIcon__buttons ;Was it the default?
258 ORREQS PC,R14,#C_flag ;Yes -- set C on exit
259 BICNES PC,R14,#C_flag ;No -- clear C then
260
261 eb__stdButs DCB eb__type0-eb__stdButs
262 DCB eb__type1-eb__stdButs
263 DCB eb__type2-eb__stdButs
264 DCB eb__type3-eb__stdButs
265 DCB eb__type4-eb__stdButs
266 eb__endButs
267
268 eb__type1 BOK
269 BUTEND
270 eb__type2 BOK
271 eb__type0 BCANCEL
272 BUTEND
273 eb__type3 BOK
274 BHELP
275 BUTEND
276 eb__type4 BOK
277 BCANCEL
278 BHELP
279 BUTEND
280
281 LTORG
282
283 ;----- Workspace ------------------------------------------------------------
284
285 ^ 0,R12
286 eb__wStart # 0
287
288 eb__dbox # 4 ;The dialogue box handle
289 eb__cancel # 4 ;The cancel button, or none
290 eb__butFlags # 4 ;Which buttons are available
291
292 eb__wSize EQU {VAR}-eb__wStart
293
294 AREA |Sapphire$$LibData|,CODE,READONLY
295
296 DCD eb__wSize
297 DCD eb__wSpace
298 DCD 0
299 DCD errorBox_init
300
301 ;----- That's all, folks ----------------------------------------------------
302
303 END