chiark / gitweb /
JPEG support and other fixes from Nick Clark
[ssr] / StraySrc / Libraries / Sapphire / s / warning
1 ;
2 ; warning.s
3 ;
4 ; Displays warning boxes (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:errorBox
39                 GET     sapphire:msgs
40                 GET     sapphire:nopoll
41                 GET     sapphire:sapphire
42                 GET     sapphire:string
43                 GET     sapphire:template
44                 GET     sapphire:wimp
45
46 ;----- Main code ------------------------------------------------------------
47
48                 AREA    |Sapphire$$Code|,CODE,READONLY
49
50 ; --- warning ---
51 ;
52 ; On entry:     R0 == pointer to warning text to display
53 ;               R1 == pointer to buttons block
54 ;
55 ; On exit:      R0 == button that was clicked
56 ;               CS if this was default, CC otherwise
57 ;
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.
65 ;
66 ;               Note that a call to this routine cannot fail, since the
67 ;               dialogue is created at initialisation time.
68
69                 EXPORT  warning
70 warning         ROUT
71
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
75
76                 ; --- Set up the buttons ---
77
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
87
88                 ; --- Display the window in its glory ---
89
90                 BL      errorBox_beep           ;Make a nice noise
91                 MOV     R1,#dbOpen_persist+dbOpen_centre+dbOpen_nonSub
92                 BL      dbox_open               ;Open the dialogue
93
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
101
102                 LTORG
103
104 ; --- warn__dbHandler ---
105 ;
106 ; On entry:     R0 == dialogue box event code
107 ;               R1-R7 depend on the event
108 ;
109 ; On exit:      --
110 ;
111 ; Use:          Handles events for a warning box.
112
113 warn__dbHandler ROUT
114
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
122
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
126
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
132
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
141
142                 LTORG
143
144 ; --- warn_init ---
145 ;
146 ; On entry:     R0 == program name
147 ;
148 ; On exit:      --
149 ;
150 ; Use:          Sets up the Warning dialogue box for use.
151
152                 EXPORT  warn_init
153 warn_init       ROUT
154
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
160
161                 ; --- Ensure other bits are initialised ---
162
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
167
168                 ; --- Create a dialogue box ---
169
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
176
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
185
186                 MOV     R1,#wIcon__title        ;Set up the title icon
187                 BL      dbox_setEmbeddedTitle   ;Write title in group box
188
189                 ; --- Set up the event handler ---
190
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
196
197 warn__dbName    DCB     "warning",0
198 warn__titleSkel DCB     "warnFROM",0
199
200                 LTORG
201
202 warn__wSpace    DCD     0
203
204 ;----- Icon handles ---------------------------------------------------------
205
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
209
210 warn__buttons   EQU     5                       ;Number of buttons allowed
211
212 ;----- Warning button table layout ------------------------------------------
213
214 wFlag_cancel    EQU     (1<<0)                  ;This is the cancel button
215                                                 ;+0
216
217 wFlag_text      EQU     (1<<1)                  ;This button contains text
218                                                 ;+0 == message tag
219                                                 ;+n
220
221 wFlag_last      EQU     (1<<31)                 ;This is the last item
222                                                 ;+0
223
224 ;----- Workspace ------------------------------------------------------------
225
226                 ^       0,R12
227 warn__wStart    #       0
228
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
232
233 warn__wSize     EQU     {VAR}-warn__wStart
234
235                 AREA    |Sapphire$$LibData|,CODE,READONLY
236
237                 DCD     warn__wSize
238                 DCD     warn__wSpace
239                 DCD     0
240                 DCD     warn_init
241
242 ;----- That's all, folks ----------------------------------------------------
243
244                 END