chiark / gitweb /
JPEG support and other fixes from Nick Clark
[ssr] / StraySrc / Libraries / Sapphire / s / saveWarn
1 ;
2 ; saveWarn.s
3 ;
4 ; Warn the user about saving a document
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:errorBox
38                 GET     sapphire:msgs
39                 GET     sapphire:sapphire
40                 GET     sapphire:string
41                 GET     sapphire:warning
42
43                 GET     sapphire:xfer.saveAs
44
45 ;----- Main code ------------------------------------------------------------
46
47                 AREA    |Sapphire$$Code|,CODE,READONLY
48
49 ; --- saveWarn ---
50 ;
51 ; On entry:     R0 == estimated size of data
52 ;               R1 == file type of the data
53 ;               R2 == pointer to name of the file
54 ;               R3 == pointer to handler block
55 ;               R4 == value to pass to handlers in R10
56 ;               R5 == value to pass to handlers in R12
57 ;               R6 == flags (in bottom two bits)
58 ;
59 ; On exit:      --
60 ;
61 ; Use:          Displays a warning box allowing the user to save a modified
62 ;               document.  The flags in R6 are as follows:
63 ;
64 ;               Bit 0   File is safe; don't give a warning
65 ;               Bit 1   File's name is sensible; display it in the warning
66 ;
67 ;               The handler block is the same as that passed to saveAs (q.v.)
68 ;               with an extra entry point on the very beginning, which is
69 ;               expected to remove the document from memory.  This entry
70 ;               point is not passed any arguments except for R10 and R12.
71 ;
72 ;               In order for the system to work, you must call various
73 ;               saveWarn routines from your saveAs entry points:
74 ;
75 ;               saveWarn_saved from saEntry__success
76 ;               saveWarn_close from saEntry__closed
77
78                 EXPORT  saveWarn
79 saveWarn        ROUT
80
81                 STMFD   R13!,{R0-R5,R12,R14}    ;Save some registers
82                 WSPACE  sw__wSpace              ;Find my workspace address
83
84                 ; --- Save some data in workspace ---
85
86                 MOV     R0,#0                   ;Clear flags word now
87                 STMIA   R12,{R0,R3-R5}          ;Save values in workspace
88
89                 ; --- Work out whether we need to warn the user ---
90
91                 TST     R6,#1                   ;Is the file safe?
92                 BNE     %80saveWarn             ;Yes -- just trash it then
93
94                 ; --- Give the user a warning ---
95
96                 TST     R6,#2                   ;Is the file sensibly named?
97                 ADREQ   R0,sw__noName           ;No -- point to general msg
98                 ADRNE   R0,sw__named            ;Yes -- point to name msg
99                 BL      msgs_lookup             ;Translate the message
100                 BLNE    str_buffer              ;Get a nice string buffer
101                 BLNE    str_subst               ;And substitute the name
102
103                 ADR     R1,sw__warnBlk          ;Point to button definition
104                 BL      warning                 ;Ask the big question
105                 BCC     %50saveWarn             ;If not `Save...' skip on
106
107                 ; --- User wants to try to save the file ---
108
109                 LDMIA   R13,{R0-R5}             ;Load saveAs arguments
110                 ADD     R3,R3,#4                ;Point past our entry point
111                 MOV     R14,#swFlag__saving     ;Just about to open save box
112                 STR     R14,sw__flags           ;Save this flags word
113                 BL      saveAs                  ;Try to save the file
114                 BVC     %90saveWarn             ;If it's OK, return
115
116                 MOV     R14,#0                  ;Clear the saving flag
117                 STR     R14,sw__flags           ;Save the flags again
118                 MOV     R1,#1                   ;Display error with 1 button
119                 BL      errorBox                ;Tell user we failed
120                 B       %90saveWarn             ;And now return to caller
121
122                 ; --- User chose `Cancel' or `Discard' ---
123
124 50saveWarn      CMP     R0,#1                   ;Did we choose `Discard'?
125                 BNE     %90saveWarn             ;No -- then do nothing at all
126
127 80saveWarn      BL      sw__discard             ;Discard the document
128
129 90saveWarn      LDMFD   R13!,{R0-R5,R12,PC}^    ;And return to caller
130
131 sw__noName      DCB     "swSDC0",0
132 sw__named       DCB     "swSDC1",0
133
134 sw__warnBlk     BUTTON  "swSAVE"
135                 BUTTON  "swDISC"
136                 BCANCEL
137                 BUTEND
138
139                 LTORG
140
141 ; --- sw__discard ---
142 ;
143 ; On entry:     --
144 ;
145 ; On exit:      --
146 ;
147 ; Use:          Discards the document.
148
149 sw__discard     ROUT
150
151                 STMFD   R13!,{R0,R10,R12,R14}   ;Save some registers
152                 LDMIB   R12,{R0,R10,R12}        ;Load user call arguments
153                 MOV     R14,PC                  ;Set up return address
154                 MOV     PC,R0                   ;Call discard routine
155                 LDMFD   R13!,{R0,R10,R12,PC}^   ;And return to caller
156
157                 LTORG
158
159 ; --- saveWarn_saved ---
160 ;
161 ; On entry:     --
162 ;
163 ; On exit:      --
164 ;
165 ; Use:          Informs saveWarn that the document has been saved.  If
166 ;               saveWarn is not operating, this call is ignored.  You should
167 ;               only call this routine if the document is *safe*, rather than
168 ;               RAM transferred to another application, for example.
169
170                 EXPORT  saveWarn_saved
171 saveWarn_saved  ROUT
172
173                 STMFD   R13!,{R12,R14}          ;Save some registers
174                 WSPACE  sw__wSpace              ;Find my workspace
175                 LDR     R14,sw__flags           ;Load the flags word
176                 ORR     R14,R14,#swFlag__saved  ;Say that it's been saved
177                 STR     R14,sw__flags           ;Save the flags back
178                 LDMFD   R13!,{R12,PC}^          ;And return to caller
179
180                 LTORG
181
182 ; --- saveWarn_close ---
183 ;
184 ; On entry:     --
185 ;
186 ; On exit:      --
187 ;
188 ; Use:          Informs saveWarn that the save dialogue box has been closed.
189 ;               If the document is now saved, then it is removed from
190 ;               memory.
191
192                 EXPORT  saveWarn_close
193 saveWarn_close  ROUT
194
195                 STMFD   R13!,{R12,R14}          ;Save some registers
196                 WSPACE  sw__wSpace              ;Find my workspace
197                 LDR     R14,sw__flags           ;Load the flags word
198                 CMP     R14,#3                  ;Are both bits set?
199                 BLEQ    sw__discard             ;Yes -- discard the document
200                 MOVEQ   R14,#0                  ;Clear the flags
201                 STREQ   R14,sw__flags           ;And save them back
202                 LDMFD   R13!,{R12,PC}^          ;And return to caller
203
204                 LTORG
205
206 sw__wSpace      DCD     0
207
208 ;----- Workspace ------------------------------------------------------------
209
210                 ^       0,R12
211 sw__wStart      #       0
212
213 sw__flags       #       4                       ;Various useful flags
214 sw__table       #       4                       ;Address of client's table
215 sw__R10         #       4                       ;Value to pass in R10
216 sw__R12         #       4                       ;Value to pass in R12
217
218 sw__wSize       EQU     {VAR}-sw__wStart
219
220 swFlag__saving  EQU     (1<<0)                  ;We have a save box open
221 swFlag__saved   EQU     (1<<1)                  ;User has saved the document
222
223                 AREA    |Sapphire$$LibData|,CODE,READONLY
224
225                 DCD     sw__wSize
226                 DCD     sw__wSpace
227                 DCD     0
228                 DCD     0
229
230 ;----- That's all, folks ----------------------------------------------------
231
232                 END