;
; note.s
;
; Handling of a Note box (MDW)
;
;  1994-1998 Straylight
;

;----- Licensing note -------------------------------------------------------
;
; This file is part of Straylight's Sapphire library.
;
; Sapphire is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2, or (at your option)
; any later version.
;
; Sapphire is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with Sapphire.  If not, write to the Free Software Foundation,
; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

;----- Standard header ------------------------------------------------------

		GET	libs:header
		GET	libs:swis

;----- External dependencies ------------------------------------------------

		GET	sapphire:dbox
		GET	sapphire:errorBox
		GET	sapphire:msgs
		GET	sapphire:nopoll
		GET	sapphire:sapphire
		GET	sapphire:string

;----- Main code ------------------------------------------------------------

		AREA	|Sapphire$$Code|,CODE,READONLY

; --- note ---
;
; On entry:	R0 == pointer to a piece of text to display
;
; On exit:	--
;
; Use:		Displays some text in a small window.

		EXPORT	note
note		ROUT

		STMFD	R13!,{R0-R4,R14}	;Save some registers
		ADR	R0,note__dbName		;Point to the dialogue name
		BL	dbox_create		;Create the dialogue box
		BVS	%90note			;If it failed, skip ahead
		MOV	R4,R0			;Look after the handle

		; --- Set up the window title bar ---

		BL	sapphire_appName	;Get the application's name
		MOV	R2,R0			;Put it in another register
		BL	str_buffer		;Point to a buffer
		ADR	R0,note__from		;Point to title skeleton
		BL	msgs_lookup		;Translate the message
		BL	str_subst		;Fill in the string nicely
		MOV	R2,R0			;Point to the title string
		MOV	R1,#-1			;Set the window title
		MOV	R0,R4			;Get the dialogue handle
		BL	dbox_setField		;Fill in the window title

		; --- Set up the other bits of the dialogue ---

		LDR	R2,[R13,#0]		;Get the caller's string
		MOV	R1,#nIcon__text		;Get the icon handle
		BL	dbox_setField		;Fill in the icon nicely
		MOV	R1,#nIcon__title	;Get the pseudotitle icon
		BL	dbox_setEmbeddedTitle	;Write the title string here
		ADR	R1,note__handler	;Point to my handler routine
		MOV	R2,R0			;Pass dialogue handle in R10
		MOV	R3,R12			;Pass workspace in R12
		BL	dbox_eventHandler	;Register my event handler

		; --- Display the dialogue box ---

		MOV	R1,#dbOpen_pointer+dbOpen_persist+dbOpen_nonSub
		BL	dbox_open		;Open the dialogue box
		BL	dbox_window		;Get the dialogue's window
		BL	nopoll_open		;Let nopoll take over now
		BL	nopoll_process		;Wait until it's over
		LDMFD	R13!,{R0-R4,PC}^	;Return to caller

		; --- Not enough memory or something ---
		;
		; We display the message in an error box and put up with it.

90note		LDR	R0,[R13,#0]		;Get the caller's string
		SUB	R0,R0,#4		;Make a fake error number
		MOV	R1,#1			;Just an OK button please
		BL	errorBox		;Display the error message
		LDMFD	R13!,{R0-R4,PC}^	;Return to caller

note__dbName	DCB	"note",0
note__from	DCB	"noteFROM",0

		LTORG

; --- note__handler ---
;
; On entry:	R0 == dialogue event code
;		R1-R9 == something weird
;
; On exit:	--
;
; Use:		Handles events for note dialogue boxes

note__handler	ROUT

		CMP	R0,#dbEvent_OK		;Is it a return keypress?
		CMPNE	R0,#dbEvent_cancel	;Or an escape keypress?
		CMPNE	R0,#nIcon__ok		;Or a click on OK?
		MOVNES	PC,R14			;None of these -- return

		STMFD	R13!,{R0,R1,R14}	;Save some registers
		MOV	R0,R10			;Get the dialogue handle
		MOV	R1,#nIcon__ok		;Get the OK icon number
		BL	dbox_slab		;Slab the button in
		BL	dbox_close		;Close the window
		BL	dbox_unslab		;Unslab the button quietlike
		BL	nopoll_close		;Stop nopoll being silly
		BL	dbox_destroy		;Zap the dialogue box
		LDMFD	R13!,{R0,R1,PC}^	;Return to caller happy

		LTORG

;----- Icon numbers ---------------------------------------------------------

nIcon__text	EQU	0
nIcon__ok	EQU	1
nIcon__title	EQU	2

;----- That's all, folks ----------------------------------------------------

		END
