Initial revision
[ssr] / StraySrc / Libraries / Sapphire / xfer / s / saveAs
1 ;
2 ; xfer.saveAs.s
3 ;
4 ; Implementation of a save as dialogue box (MDW)
5 ;
6 ; © 1994 Straylight
7 ;
8
9 ;----- Standard header ------------------------------------------------------
10
11 GET libs:header
12 GET libs:swis
13
14 ;----- External dependencies ------------------------------------------------
15
16 GET sapphire:dbox
17 GET sapphire:help
18 GET sapphire:msgs
19 GET sapphire:note
20 GET sapphire:sapphire
21
22 GET sapphire:dbx.dbx
23 GET sapphire:dbx.fileIcon
24
25 GET sapphire:xfer.save
26
27 ;----- Main code ------------------------------------------------------------
28
29 AREA |Sapphire$$Code|,CODE,READONLY
30
31 ; --- saveAs ---
32 ;
33 ; On entry: R0 == estimated size of data
34 ; R1 == file type of the data
35 ; R2 == pointer to name of the file
36 ; R3 == pointer to handler block
37 ; R4 == value to pass to handlers in R10
38 ; R5 == value to pass to handlers in R12
39 ;
40 ; On exit: May return an error
41 ;
42 ; Use: Displays a save as dialogue box for you to save some data.
43
44 EXPORT saveAs
45 saveAs ROUT
46
47 STMFD R13!,{R0-R6,R12,R14} ;Save some registers
48 WSPACE sa__wSpace ;Find my workspace address
49
50 ; --- Find the end of the string ---
51
52 MOV R6,R3 ;Take a copy of the title tag
53 00saveAs LDRB R14,[R3],#1 ;Load a byte from the table
54 CMP R14,#32 ;Is it the end yet?
55 BGE %00saveAs ;No -- go round again then
56 ADD R3,R3,#3 ;Add on a little bit
57 BIC R3,R3,#3 ;And word align the result
58
59 ; --- Save the fixed information away ---
60
61 STMIA R12,{R0-R5} ;Save the stuff in workspace
62
63 ; --- Now create a dialogue box ---
64
65 ADR R0,sa__dbName ;Point to my dialogue name
66 BL dbox_create ;Try to create the dialogue
67 BVS %99saveAs ;If it failed, tidy up
68 STR R0,sa__dbox ;Save the dialogue handle
69
70 ADR R1,sa__dbHandler ;Point to my handler routine
71 MOV R2,R0 ;Pass dialogue handle in R10
72 MOV R3,R12 ;And workspace in R12 please
73 BL dbox_eventHandler ;Set up the event handler
74
75 ADR R1,sa__dbxDef ;Point to my dialogue def
76 BL dbx_declare ;Let dbx handle the dialogue
77
78 ; --- Set up the dialogue ---
79
80 MOV R1,#saIcon__write ;Get the writable icon handle
81 LDR R2,[R13,#8] ;Get the default filename
82 BL dbox_setField ;Write it into the icon
83
84 MOV R3,R0 ;Save the dialogue handle
85 MOV R0,R6 ;Get the title string tag
86 BL msgs_lookup ;Translate it nicely
87 MOV R2,R0 ;Copy it into R2 now
88 MOV R0,R3 ;Restore the dialogue handle
89 MOV R1,#-1 ;Fill in the title bar
90 BL dbox_setField ;And fill in the title
91
92 ; --- Now display it and return ---
93
94 MOV R1,#dbOpen_trans :OR: dbOpen_pointer
95 BL dbox_open ;Open the dialogue box
96 LDMFD R13!,{R0-R6,R12,R14} ;Restore all the registers
97 BICS PC,R14,#V_flag ;And don't return any errors
98
99 ; --- Couldn't create the dialogue box ---
100
101 99saveAs ADD R13,R13,#4 ;Don't restore R0 on exit
102 LDMFD R13!,{R1-R6,R12,R14} ;Restore the other registers
103 ORRS PC,R14,#V_flag ;And return the error
104
105 sa__dbName DCB "save",0
106
107 sa__dbxDef FILEICN saIcon__file,R12,:INDEX: sa__fileType
108 DBXEND
109
110 LTORG
111
112 ; --- sa__dbHandler ---
113 ;
114 ; On entry: R0 == dialogue box event code
115 ; R1-R9 == event-dependent information
116 ;
117 ; On exit: --
118 ;
119 ; Use: Handles events for the save dialogue box.
120
121 sa__dbHandler ROUT
122
123 CMP R0,#saIcon__ok ;Is it the OK button clicked?
124 CMPNE R0,#dbEvent_OK ;Or maybe a return key?
125 BEQ %10sa__dbHandler ;Either -- handle it
126
127 CMP R0,#dbEvent_close ;Has the window been closed?
128 BEQ %20sa__dbHandler ;Yes -- deal with this then
129
130 CMP R0,#fIcon_event ;Or is it the fileicon drag?
131 BEQ %30sa__dbHandler ;Yes -- deal with that
132
133 CMP R0,#dbEvent_help ;Is it a help request?
134 BEQ %40sa__dbHandler ;Yes -- send some help along
135
136 MOVS PC,R14 ;Return -- unknown event
137
138 ; --- Deal with a click on the OK button ---
139
140 10sa__dbHandler STMFD R13!,{R0-R3,R10,R12,R14} ;Save some registers
141 MOV R3,R1 ;Keep the button status safe
142
143 ; --- Slab the OK button ---
144
145 MOV R0,R10 ;Get my dialogue handle
146 MOV R1,#saIcon__ok ;And the OK button handle
147 BL dbox_slab ;Slab the icon in nicely
148
149 ; --- Try to find a `.' character ---
150
151 MOV R1,#saIcon__write ;Find the writable icon
152 BL dbox_getField ;Read the string value
153 MOV R0,R2 ;Keep pointer to string
154 13sa__dbHandler LDRB R14,[R2],#1 ;Load a byte from it
155 CMP R14,#32 ;Is it a control character?
156 BLO %17sa__dbHandler ;Yes -- tell user he's silly
157 CMP R14,#'.' ;Is it a dot character?
158 BNE %13sa__dbHandler ;No -- loop round again
159
160 ; --- Tell the client to save the file ---
161
162 MOV R1,#1 ;Say that the file's safe
163 ADR R2,sa__entries ;Find the entry point block
164 LDMIA R2,{R2,R10,R12} ;Load all the client stuff
165 MOV R14,PC ;Set up the return address
166 ADD PC,R2,#saEntry__save ;Try to send the file
167 BVC %19sa__dbHandler ;If it worked, skip to end
168
169 ; --- Handle an error from the client ---
170
171 MOV R1,#1 ;Set icon count for errorBox
172 MOV R14,PC ;Set up the return address
173 ADD PC,R2,#saEntry__failed ;Tell client it failed
174 MOV R3,#1 ;Don't close the dialogue
175 B %19sa__dbHandler ;And skip to the end
176
177 ; --- Display a note about dragging the icon ---
178
179 17sa__dbHandler MOV R3,#1 ;Don't close the dialogue
180 ADR R0,sa__noteMsg ;Point to the note message
181 BL msgs_lookup ;Translate the note string
182 BL note ;And display it in a window
183
184 ; --- Wrap everything up nice and tight ---
185
186 19sa__dbHandler CMP R3,#1 ;Was it an Adjust click?
187 LDR R0,[R13,#16] ;Load my dialogue handle
188 BLNE dbox_close ;No -- close the dialogue
189 BL dbox_unslab ;Unslab the OK button
190 BLNE sa__close ;And close the dialogue box
191 LDMFD R13!,{R0-R3,R10,R12,PC}^ ;Return to caller
192
193 sa__noteMsg DCB "saDRAGICN",0
194
195 ; --- Handle a close event for the window ---
196
197 20sa__dbHandler B sa__close ;Just close the window
198
199 ; --- Handle an icon drag for the window ---
200
201 30sa__dbHandler STMFD R13!,{R0-R8,R14} ;Save a load of registers
202
203 ; --- Find the filename string ---
204
205 MOV R0,R10 ;Get the dialogue box handle
206 MOV R1,#saIcon__write ;Get the writable icon handle
207 BL dbox_getField ;Read the text string
208 MOV R8,R2 ;Keep a pointer to it
209
210 ; --- Set up the other arguments ---
211
212 ADD R14,R13,#8 ;Point to saved window/icon
213 LDMIA R14,{R0,R1} ;Load them into registers
214 LDMIA R12,{R2-R7} ;Load the other arguments
215 ORR R3,R3,#&80000000 ;Set the extended args flag
216 MOV R4,R8 ;Point to new file name
217 ADD R5,R5,#saEntry__save ;Point at save handlers
218 ADR R8,sa__extraHnd ;Point to my extra handlers
219 BL save ;Start the save operation
220 LDMFD R13!,{R0-R8,PC}^ ;Return to caller
221
222 sa__extraHnd B sa__success ;The save attempt succeeded
223 B sa__failed ;The save attempt failed
224
225 40sa__dbHandler STMFD R13!,{R0,R14} ;Save some registers
226 ADR R0,sa__dbHelp ;Point to the message string
227 BL msgs_lookup ;Translate the message
228 BL help_add ;Add it to the help text
229 BL dbox_help ;Read help from the icon
230 LDMFD R13!,{R0,PC}^ ;Return to caller
231
232 sa__dbHelp DCB "sahDB",0
233
234 LTORG
235
236 ; --- sa__close ---
237 ;
238 ; On entry: --
239 ;
240 ; On exit: --
241 ;
242 ; Use: Closes the save as dialogue box
243
244 sa__close ROUT
245
246 STMFD R13!,{R0,R10,R12,R14} ;Save some registers away
247
248 ; --- Close the dialogue box ---
249
250 WSPACE sa__wSpace ;Locate my workspace
251 LDR R0,sa__dbox ;Load the dialogue box handle
252 BL dbox_destroy ;Destroy the dialogue
253 BL fileIcon_closed ;Tell fileIcon it's closed
254
255 ; --- Tell the client we've done this thing ---
256
257 ADR R14,sa__entries ;Point to the entry table
258 LDMIA R14,{R0,R10,R12} ;Load the client data
259 LDR R14,[R0,#saEntry__closed] ;Find the closed entry word
260 CMP R14,#0 ;Is there an entry defined?
261 MOV R14,PC ;Set up the return address
262 ADDNE PC,R0,#saEntry__closed ;If defined, call the entry
263 LDMFD R13!,{R0,R10,R12,PC}^ ;Return to caller
264
265 LTORG
266
267 ; --- sa__success ---
268 ;
269 ; On entry: --
270 ;
271 ; On exit: --
272 ;
273 ; Use: Handles a successful icon drag-save operation.
274
275 sa__success ROUT
276
277 STMFD R13!,{R0-R3,R12,R14} ;Save a few registers
278
279 ; --- Send a close event to the dialogue ---
280
281 WSPACE sa__wSpace ;Find my workspace pointer
282 LDR R0,sa__dbox ;Get the dialogue box handle
283 BL dbox_window ;Get its window handle
284 STR R0,[R13,#-4]! ;Store it on the stack
285 MOV R2,R0 ;Get the window handle in R2
286 MOV R1,R13 ;Point to the close block
287 MOV R0,#3 ;And send a close event
288 SWI Wimp_SendMessage ;Add it to my event queue
289 ADD R13,R13,#4 ;Reclaim that microblock
290 LDMFD R13!,{R0-R3,R12,PC}^ ;Return to caller
291
292 LTORG
293
294 ; --- sa__failed ---
295 ;
296 ; On entry: R0 == pointer to an error, or 0
297 ; R1 == 1
298 ;
299 ; On exit: --
300 ;
301 ; Use: Deals with an abortive to save data.
302
303 sa__failed ROUT
304
305 B fileIcon_reAppear ;Make the file icon reappear
306
307 LTORG
308
309 sa__wSpace DCD 0
310
311 ;----- The SaveAs handler block ---------------------------------------------
312 ;
313 ; The block begins with the message tag for the dialogue title, followed by
314 ; an align to word boundary and then branch instructions or 0 for:
315
316 ^ 0
317 saEntry__closed # 4 ;Save dialogue has closed
318 ;Entry:
319 ; --
320 ;Exit:
321 ; --
322
323 saEntry__save # 4 ;Write to a file
324 ;Entry:
325 ; R0 == pointer to file name
326 ; R1 == 0 if file unsafe,
327 ; non-0 if safe
328 ;Exit:
329 ; --
330
331 saEntry__send # 4 ;Send a block of data
332 ;Entry:
333 ; --
334 ;Exit:
335 ; R0 == pointer to block
336 ; R1 == size of block
337 ; CS if this is the last one
338
339 saEntry__success # 4 ;Data transfer has finished
340 ;Entry:
341 ; --
342 ;Exit:
343 ; --
344
345 saEntry__failed # 4 ;Data transfer failed
346 ;Entry:
347 ; R0 == 0 or ptr to error
348 ; R1 == 1
349 ;Exit:
350 ; --
351
352 ;----- Icon numbers ---------------------------------------------------------
353
354 saIcon__write EQU 1
355 saIcon__file EQU 2
356 saIcon__ok EQU 3
357
358 ;----- Workspace ------------------------------------------------------------
359
360 ^ 0,R12
361 sa__wStart # 0
362
363 sa__estSize # 4 ;Estimated size of data
364 sa__fileType # 4 ;Filetype of data to save
365 sa__fileName # 4 ;Pointer to default name
366 sa__entries # 4 ;Pointer to branch table
367 sa__R10 # 4 ;Caller's value of R10
368 sa__R12 # 4 ;Caller's value of R12
369
370 sa__dbox # 4 ;My dialogue box handle
371
372 sa__wSize EQU {VAR}-sa__wStart
373
374 AREA |Sapphire$$LibData|,CODE,READONLY
375
376 DCD sa__wSize
377 DCD sa__wSpace
378 DCD 0
379 DCD 0
380
381 ;----- That's all, folks ----------------------------------------------------
382
383 END