4 ; Reports errors in an error box (MDW)
6 ; © 1994-1998 Straylight
9 ;----- Licensing note -------------------------------------------------------
11 ; This file is part of Straylight's Sapphire library.
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)
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.
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.
27 ;----- Standard header ------------------------------------------------------
34 ;----- External dependencies ------------------------------------------------
45 ;----- Icon numbers ---------------------------------------------------------
53 ;----- Main code ------------------------------------------------------------
55 AREA |Sapphire$$Code|,CODE,READONLY
57 ; --- errorBox_init ---
59 ; On entry: R0 == pointer to application name
63 ; Use: Initialises the errorBox system nicely. It creates the
64 ; dialogue box now, and just uses it for the rest of the
70 STMFD R13!,{R0-R3,R12,R14} ;Save some registers
71 WSPACE eb__wSpace ;Load my workspace pointer
73 ; --- Am I running yet? ---
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
79 ; --- Initialise other useful things ---
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
86 ; --- Create my dialogue box ---
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
93 ; --- Fill in the dialogue box title ---
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
105 ; --- Set up the rest of the dialogue box ---
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
114 LDMFD R13!,{R0-R3,R12,PC}^ ;Return to the caller
116 eb__dbName DCB "error",0
117 eb__errorFrom DCB "ebERRFRM",0
123 ; --- eb__dbHandler ---
125 ; On entry: R0 == reason code
126 ; R1-... dependant on reason code
127 ; R10 == dialogue box handle
128 ; R12 == pointer to workspace
130 ; On exit: Registers preserved
132 ; Use: Handles events for the error box
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
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
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
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
165 ; --- errorBox_beep ---
171 ; Use: Sounds the bell (VDU 7) if the CMOS settings dictate that
172 ; error boxes should cause a beep.
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
189 ; On entry: R0 == pointer to error block
190 ; R1 == button style code, or pointer to buttons block
192 ; On exit: R0 == icon number clicked (ordered from the right)
193 ; CS if R0 == 0, else CC
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.
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'.
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).
208 ; Standard button arrangements are given by codes, as follows:
214 ; 5 == OK, Cancel, Help
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
224 ; --- Deal with button codes ---
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
231 ; --- Set up the buttons ---
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
239 ; --- Set the string in the dbox ---
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
245 ; --- Display the dialogue ---
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
251 ; --- Handle the dialogue properly ---
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
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
283 ;----- Workspace ------------------------------------------------------------
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
292 eb__wSize EQU {VAR}-eb__wStart
294 AREA |Sapphire$$LibData|,CODE,READONLY
301 ;----- That's all, folks ----------------------------------------------------