Initial revision
[ssr] / StraySrc / Libraries / Sapphire / s / note
1 ;
2 ; note.s
3 ;
4 ; Handling of a Note box (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 ;----- External dependencies ------------------------------------------------
33
34 GET sapphire:dbox
35 GET sapphire:errorBox
36 GET sapphire:msgs
37 GET sapphire:nopoll
38 GET sapphire:sapphire
39 GET sapphire:string
40
41 ;----- Main code ------------------------------------------------------------
42
43 AREA |Sapphire$$Code|,CODE,READONLY
44
45 ; --- note ---
46 ;
47 ; On entry: R0 == pointer to a piece of text to display
48 ;
49 ; On exit: --
50 ;
51 ; Use: Displays some text in a small window.
52
53 EXPORT note
54 note ROUT
55
56 STMFD R13!,{R0-R4,R14} ;Save some registers
57 ADR R0,note__dbName ;Point to the dialogue name
58 BL dbox_create ;Create the dialogue box
59 BVS %90note ;If it failed, skip ahead
60 MOV R4,R0 ;Look after the handle
61
62 ; --- Set up the window title bar ---
63
64 BL sapphire_appName ;Get the application's name
65 MOV R2,R0 ;Put it in another register
66 BL str_buffer ;Point to a buffer
67 ADR R0,note__from ;Point to title skeleton
68 BL msgs_lookup ;Translate the message
69 BL str_subst ;Fill in the string nicely
70 MOV R2,R0 ;Point to the title string
71 MOV R1,#-1 ;Set the window title
72 MOV R0,R4 ;Get the dialogue handle
73 BL dbox_setField ;Fill in the window title
74
75 ; --- Set up the other bits of the dialogue ---
76
77 LDR R2,[R13,#0] ;Get the caller's string
78 MOV R1,#nIcon__text ;Get the icon handle
79 BL dbox_setField ;Fill in the icon nicely
80 MOV R1,#nIcon__title ;Get the pseudotitle icon
81 BL dbox_setEmbeddedTitle ;Write the title string here
82 ADR R1,note__handler ;Point to my handler routine
83 MOV R2,R0 ;Pass dialogue handle in R10
84 MOV R3,R12 ;Pass workspace in R12
85 BL dbox_eventHandler ;Register my event handler
86
87 ; --- Display the dialogue box ---
88
89 MOV R1,#dbOpen_pointer+dbOpen_persist+dbOpen_nonSub
90 BL dbox_open ;Open the dialogue box
91 BL dbox_window ;Get the dialogue's window
92 BL nopoll_open ;Let nopoll take over now
93 BL nopoll_process ;Wait until it's over
94 LDMFD R13!,{R0-R4,PC}^ ;Return to caller
95
96 ; --- Not enough memory or something ---
97 ;
98 ; We display the message in an error box and put up with it.
99
100 90note LDR R0,[R13,#0] ;Get the caller's string
101 SUB R0,R0,#4 ;Make a fake error number
102 MOV R1,#1 ;Just an OK button please
103 BL errorBox ;Display the error message
104 LDMFD R13!,{R0-R4,PC}^ ;Return to caller
105
106 note__dbName DCB "note",0
107 note__from DCB "noteFROM",0
108
109 LTORG
110
111 ; --- note__handler ---
112 ;
113 ; On entry: R0 == dialogue event code
114 ; R1-R9 == something weird
115 ;
116 ; On exit: --
117 ;
118 ; Use: Handles events for note dialogue boxes
119
120 note__handler ROUT
121
122 CMP R0,#dbEvent_OK ;Is it a return keypress?
123 CMPNE R0,#dbEvent_cancel ;Or an escape keypress?
124 CMPNE R0,#nIcon__ok ;Or a click on OK?
125 MOVNES PC,R14 ;None of these -- return
126
127 STMFD R13!,{R0,R1,R14} ;Save some registers
128 MOV R0,R10 ;Get the dialogue handle
129 MOV R1,#nIcon__ok ;Get the OK icon number
130 BL dbox_slab ;Slab the button in
131 BL dbox_close ;Close the window
132 BL dbox_unslab ;Unslab the button quietlike
133 BL nopoll_close ;Stop nopoll being silly
134 BL dbox_destroy ;Zap the dialogue box
135 LDMFD R13!,{R0,R1,PC}^ ;Return to caller happy
136
137 LTORG
138
139 ;----- Icon numbers ---------------------------------------------------------
140
141 nIcon__text EQU 0
142 nIcon__ok EQU 1
143 nIcon__title EQU 2
144
145 ;----- That's all, folks ----------------------------------------------------
146
147 END