4 ; Displays warning boxes (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 ------------------------------------------------
46 ;----- Main code ------------------------------------------------------------
48 AREA |Sapphire$$Code|,CODE,READONLY
52 ; On entry: R0 == pointer to warning text to display
53 ; R1 == pointer to buttons block
55 ; On exit: R0 == button that was clicked
56 ; CS if this was default, CC otherwise
58 ; Use: Displays a warning to the user. The warning box can have up
59 ; to five buttons (because it's too small for any more than
60 ; that). These are placed in a column on the right hand side
61 ; of the dialogue. The buttons are numbered from 0 up to 4
62 ; from the bottom upwards, 0 being the default. You can
63 ; choose one button to be `Cancel', in which case pressing
64 ; escape will activate it.
66 ; Note that a call to this routine cannot fail, since the
67 ; dialogue is created at initialisation time.
72 STMFD R13!,{R1-R4,R12,R14} ;Save some registers
73 WSPACE warn__wSpace ;Find my workspace address
74 MOV R4,R0 ;Look after the warning text
76 ; --- Set up the buttons ---
78 LDR R0,warn__dbox ;Load the dbox handle
79 MOV R2,#wIcon__buttons ;Find the buttons base
80 MOV R3,#warn__buttons ;Find the button count
81 BL buttons_setup ;Set all that lot up
82 STR R2,warn__butFlags ;Save the defined buttons
83 STR R3,warn__cancel ;Save the cancel button too
84 MOV R1,#wIcon__text ;Get the text icon handle
85 MOV R2,R4 ;Get the text string too
86 BL dbox_setField ;Write that into the icon
88 ; --- Display the window in its glory ---
90 BL errorBox_beep ;Make a nice noise
91 MOV R1,#dbOpen_persist+dbOpen_centre+dbOpen_nonSub
92 BL dbox_open ;Open the dialogue
94 BL dbox_window ;Get its window handle
95 BL nopoll_open ;Let nopoll take over a bit
96 BL nopoll_process ;Get a reply from the dbox
97 LDMFD R13!,{R1-R4,R12,R14} ;Reload some registers
98 SUBS R0,R0,#wIcon__buttons ;Was it the default button?
99 ORREQS PC,R14,#C_flag ;Yes -- set C flag on exit
100 BICNES PC,R14,#C_flag ;No -- clear the C flag
104 ; --- warn__dbHandler ---
106 ; On entry: R0 == dialogue box event code
107 ; R1-R7 depend on the event
111 ; Use: Handles events for a warning box.
115 STMFD R13!,{R14} ;Save a register
116 CMP R0,#dbEvent_OK ;Is it a return press?
117 MOVEQ R0,#wIcon__buttons ;Yes -- set to be default
118 CMP R0,#dbEvent_cancel ;Was it a cancel?
119 LDREQ R0,warn__cancel ;Yes -- load cancel button
120 CMPEQ R0,#-1 ;Was it defined by user?
121 MOVEQ R0,#wIcon__buttons ;No -- make it do OK then
123 SUB R14,R0,#wIcon__buttons ;Subtract the buttons base
124 CMP R14,#warn__buttons ;Is it in range?
125 LDMCSFD R13!,{PC}^ ;Yes -- then return
127 STMFD R13!,{R0,R1} ;Save another register
128 LDR R1,warn__butFlags ;Which buttons are created?
129 MOV R14,#1 ;Use a bit to test
130 TST R1,R14,LSL R0 ;Test the correct bit
131 LDMEQFD R13!,{R0,R1,PC}^ ;Not created -- return then
133 MOV R1,R0 ;Put icon into R1
134 LDR R0,warn__dbox ;Get dialogue in R0
135 BL dbox_slab ;Slab the icon nicely
136 BL dbox_close ;Close the window
137 BL dbox_unslab ;Unslab the icon again
138 MOV R0,R1 ;Put icon back in R0
139 BL nopoll_close ;Return this to main code
140 LDMFD R13!,{R0,R1,PC}^ ;And return to caller
146 ; On entry: R0 == program name
150 ; Use: Sets up the Warning dialogue box for use.
155 STMFD R13!,{R12,R14} ;Save some registers
156 WSPACE warn__wSpace ;Load my workspace address
157 LDR R14,warn__dbox ;Load the dialogue handle
158 CMP R14,#0 ;Is it defined yet?
159 LDMNEFD R13!,{R12,PC}^ ;Yes -- then return to caller
161 ; --- Ensure other bits are initialised ---
163 BL wimp_init ;We need to create windows
164 BL template_init ;Make sure we can get these
165 BL dbox_init ;We want to create dialogues
166 BL nopoll_init ;We may need this
168 ; --- Create a dialogue box ---
170 STMFD R13!,{R0-R3} ;Save some more registers
171 MOV R2,R0 ;Keep the application name
172 ADR R0,warn__dbName ;Point at my dialogue name
173 BL dbox_create ;Try to create it
174 SWIVS OS_GenerateError ;Don't take errors lying down
175 STR R0,warn__dbox ;Save my dialogue handle
177 ADR R0,warn__titleSkel ;Point to skeleton title
178 BL msgs_lookup ;Translate it nicely
179 MOV R1,R11 ;Build in scratchpad
180 BL str_subst ;Do the stuff required
181 MOV R2,R0 ;Make it ready for dbox
182 LDR R0,warn__dbox ;Get the dialogue back again
183 MOV R1,#-1 ;Put it in the title bar
184 BL dbox_setField ;Fill in the title bar
186 MOV R1,#wIcon__title ;Set up the title icon
187 BL dbox_setEmbeddedTitle ;Write title in group box
189 ; --- Set up the event handler ---
191 ADR R1,warn__dbHandler ;Point to handler routine
192 MOV R2,R10 ;Pass (bogus) R10
193 MOV R3,R12 ;Pass it my workspace
194 BL dbox_eventHandler ;Set that up nicely
195 LDMFD R13!,{R0-R3,R12,PC}^ ;Return to caller
197 warn__dbName DCB "warning",0
198 warn__titleSkel DCB "warnFROM",0
204 ;----- Icon handles ---------------------------------------------------------
206 wIcon__text EQU 2 ;The actual text icon
207 wIcon__title EQU 1 ;Embedded title icon
208 wIcon__buttons EQU 3 ;Buttons from here on up
210 warn__buttons EQU 5 ;Number of buttons allowed
212 ;----- Warning button table layout ------------------------------------------
214 wFlag_cancel EQU (1<<0) ;This is the cancel button
217 wFlag_text EQU (1<<1) ;This button contains text
221 wFlag_last EQU (1<<31) ;This is the last item
224 ;----- Workspace ------------------------------------------------------------
229 warn__dbox # 4 ;The warning dialogue handle
230 warn__cancel # 4 ;The cancel icon, or -1
231 warn__butFlags # 4 ;Which buttons are available
233 warn__wSize EQU {VAR}-warn__wStart
235 AREA |Sapphire$$LibData|,CODE,READONLY
242 ;----- That's all, folks ----------------------------------------------------