4 ; Implementation of a save as dialogue box (MDW)
9 ;----- Standard header ------------------------------------------------------
14 ;----- External dependencies ------------------------------------------------
23 GET sapphire:dbx.fileIcon
25 GET sapphire:xfer.save
27 ;----- Main code ------------------------------------------------------------
29 AREA |Sapphire$$Code|,CODE,READONLY
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
40 ; On exit: May return an error
42 ; Use: Displays a save as dialogue box for you to save some data.
47 STMFD R13!,{R0-R6,R12,R14} ;Save some registers
48 WSPACE sa__wSpace ;Find my workspace address
50 ; --- Find the end of the string ---
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
59 ; --- Save the fixed information away ---
61 STMIA R12,{R0-R5} ;Save the stuff in workspace
63 ; --- Now create a dialogue box ---
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
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
75 ADR R1,sa__dbxDef ;Point to my dialogue def
76 BL dbx_declare ;Let dbx handle the dialogue
78 ; --- Set up the dialogue ---
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
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
92 ; --- Now display it and return ---
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
99 ; --- Couldn't create the dialogue box ---
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
105 sa__dbName DCB "save",0
107 sa__dbxDef FILEICN saIcon__file,R12,:INDEX: sa__fileType
112 ; --- sa__dbHandler ---
114 ; On entry: R0 == dialogue box event code
115 ; R1-R9 == event-dependent information
119 ; Use: Handles events for the save dialogue box.
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
127 CMP R0,#dbEvent_close ;Has the window been closed?
128 BEQ %20sa__dbHandler ;Yes -- deal with this then
130 CMP R0,#fIcon_event ;Or is it the fileicon drag?
131 BEQ %30sa__dbHandler ;Yes -- deal with that
133 CMP R0,#dbEvent_help ;Is it a help request?
134 BEQ %40sa__dbHandler ;Yes -- send some help along
136 MOVS PC,R14 ;Return -- unknown event
138 ; --- Deal with a click on the OK button ---
140 10sa__dbHandler STMFD R13!,{R0-R3,R10,R12,R14} ;Save some registers
141 MOV R3,R1 ;Keep the button status safe
143 ; --- Slab the OK button ---
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
149 ; --- Try to find a `.' character ---
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
160 ; --- Tell the client to save the file ---
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
169 ; --- Handle an error from the client ---
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
177 ; --- Display a note about dragging the icon ---
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
184 ; --- Wrap everything up nice and tight ---
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
193 sa__noteMsg DCB "saDRAGICN",0
195 ; --- Handle a close event for the window ---
197 20sa__dbHandler B sa__close ;Just close the window
199 ; --- Handle an icon drag for the window ---
201 30sa__dbHandler STMFD R13!,{R0-R8,R14} ;Save a load of registers
203 ; --- Find the filename string ---
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
210 ; --- Set up the other arguments ---
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
222 sa__extraHnd B sa__success ;The save attempt succeeded
223 B sa__failed ;The save attempt failed
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
232 sa__dbHelp DCB "sahDB",0
242 ; Use: Closes the save as dialogue box
246 STMFD R13!,{R0,R10,R12,R14} ;Save some registers away
248 ; --- Close the dialogue box ---
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
255 ; --- Tell the client we've done this thing ---
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
267 ; --- sa__success ---
273 ; Use: Handles a successful icon drag-save operation.
277 STMFD R13!,{R0-R3,R12,R14} ;Save a few registers
279 ; --- Send a close event to the dialogue ---
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
296 ; On entry: R0 == pointer to an error, or 0
301 ; Use: Deals with an abortive to save data.
305 B fileIcon_reAppear ;Make the file icon reappear
311 ;----- The SaveAs handler block ---------------------------------------------
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:
317 saEntry__closed # 4 ;Save dialogue has closed
323 saEntry__save # 4 ;Write to a file
325 ; R0 == pointer to file name
326 ; R1 == 0 if file unsafe,
331 saEntry__send # 4 ;Send a block of data
335 ; R0 == pointer to block
336 ; R1 == size of block
337 ; CS if this is the last one
339 saEntry__success # 4 ;Data transfer has finished
345 saEntry__failed # 4 ;Data transfer failed
347 ; R0 == 0 or ptr to error
352 ;----- Icon numbers ---------------------------------------------------------
358 ;----- Workspace ------------------------------------------------------------
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
370 sa__dbox # 4 ;My dialogue box handle
372 sa__wSize EQU {VAR}-sa__wStart
374 AREA |Sapphire$$LibData|,CODE,READONLY
381 ;----- That's all, folks ----------------------------------------------------