REM >WimpError
REM
REM Copyright 2001-2014, Stephen Fryatt (info@stevefryatt.org.uk)
REM
REM This file is part of WimpLib:
REM
REM   http://www.stevefryatt.org.uk/software/
REM
REM Licensed under the EUPL, Version 1.2 only (the "Licence");
REM You may not use this work except in compliance with the
REM Licence.
REM
REM You may obtain a copy of the Licence at:
REM
REM   http://joinup.ec.europa.eu/software/page/eupl
REM
REM Unless required by applicable law or agreed to in
REM writing, software distributed under the Licence is
REM distributed on an "AS IS" basis, WITHOUT WARRANTIES
REM OR CONDITIONS OF ANY KIND, either express or implied.
REM
REM See the Licence for the specific language governing
REM permissions and limitations under the Licence.
:
REM Wimp error handling library
REM
REM The variable a% is reqired to point to 256 bytes of memory.


REM Initialise the error handler, saving the name of the client task and the
REM sprite that it uses.
REM
REM \param taskname$		The name of the client task.
REM \param sprite$		The name of the sprite used by the task, or ""
REM 				to use the default sprite.
:
DEF PROCwimperror_initialise(taskname$, sprite$)
WimpErrorTaskName$ = taskname$
WimpErrorTaskSprite$ = sprite$
ENDPROC


REM Report a message in an Wimp error box, with no feedback from the user. Either
REM the default OK and/or Cancel can be used, or a custom string of buttons --
REM in the latter case, the default buttons are disabled.
REM
REM \param message$		The text of the message to be displayed.
REM \param type%		The type of message box (0 - 4).
REM \param buttons%		Flags for OK and Cancel buttons.
REM \param buttons$		Comma-separated list of custom buttons, or "".
:
DEF PROCwimperror_report(message$, type%, buttons%, buttons$)
LOCAL dummy%

dummy% = FNwimperror_report(message$,type%,buttons%,buttons$)
ENDPROC


REM Report a message in an Wimp error box, returning the selection made by the
REM user from the error box. Either the default OK and/or Cancel can be used,
REM or a custom string of buttons -- in the latter case, the default buttons
REM are disabled.
REM
REM \param message$		The text of the message to be displayed.
REM \param type%		The type of message box (0 - 4).
REM \param buttons%		Flags for OK and Cancel buttons.
REM \param buttons$		Comma-separated list of custom buttons, or "".
REM \return			The user's selection, rebased to zero if custom
REM				buttons are used.
:
DEF FNwimperror_report(message$, type%, buttons%, buttons$)
LOCAL result%, flags%

flags% = ((type% AND %111) << 9) + (buttons% AND %11)
IF WimpErrorTaskSprite$ <> "" THEN flags% += &100

!a% = 255
$(a% + 4) = message$ + CHR$(0)
IF buttons$ = "" THEN
	SYS "Wimp_ReportError", a%, flags%, WimpErrorTaskName$, WimpErrorTaskSprite$, 1, 0 TO ,result%
ELSE
	flags% = flags% AND (NOT %11)
	SYS "Wimp_ReportError", a%, flags%, WimpErrorTaskName$, WimpErrorTaskSprite$, 1, buttons$ TO ,result%
	result% -= 2
ENDIF

=result%


REM Report the last error using a Wimp error box; if RISC OS 3.5+ is used, the
REM message will be classified as a "Program Report".
REM
REM \return			TRUE if the caller should exit; else FALSE.

DEF FNwimperror_program
LOCAL result%

SYS "Hourglass_Smash"

!a% = ERR
$(a% + 4) = WimpErrorTaskName$ + " has suffered an internal error (" + REPORT$ + "; error code " + STR$(ERL) + ")" + CHR$(0)
SYS "Wimp_ReportError", a%, &0703, WimpErrorTaskName$, WimpErrorTaskSprite$, 1, 0 TO ,result%

=(result% = 2)

