Copyright (c) Hyperion Entertainment and contributors.

Difference between revisions of "Intuition Alerts"

From AmigaOS Documentation Wiki
Jump to navigation Jump to search
 
(3 intermediate revisions by one other user not shown)
Line 31: Line 31:
 
The function DisplayAlert() creates and displays an alert message. The message will almost always be displayed regardless of the state of the machine (with the exception of catastrophic hardware failures). If the user presses one of the mouse buttons, the display is restored to its original state, if possible. If a recoverable alert cannot be displayed (because memory is low), DisplayAlert() will return FALSE, as if the user had selected cancel. DisplayAlert() is also used by the system to display the Amiga system alert messages.
 
The function DisplayAlert() creates and displays an alert message. The message will almost always be displayed regardless of the state of the machine (with the exception of catastrophic hardware failures). If the user presses one of the mouse buttons, the display is restored to its original state, if possible. If a recoverable alert cannot be displayed (because memory is low), DisplayAlert() will return FALSE, as if the user had selected cancel. DisplayAlert() is also used by the system to display the Amiga system alert messages.
   
  +
<syntaxhighlight>
<pre>
 
 
BOOL DisplayAlert( ULONG alertNumber, UBYTE *string, ULONG height );
 
BOOL DisplayAlert( ULONG alertNumber, UBYTE *string, ULONG height );
  +
</syntaxhighlight>
</pre>
 
   
 
The alertNumber argument is a LONG value, specifying whether this is a RECOVERY_ALERT or a DEADEND_ALERT (see the &lt;intuition/intuition.h&gt; include file).
 
The alertNumber argument is a LONG value, specifying whether this is a RECOVERY_ALERT or a DEADEND_ALERT (see the &lt;intuition/intuition.h&gt; include file).
Line 51: Line 51:
 
This program demonstrates an alert. An explanation of the positioning values for the alert strings is in the comment that precedes the alertMsg string.
 
This program demonstrates an alert. An explanation of the positioning values for the alert strings is in the comment that precedes the alertMsg string.
   
  +
<syntaxhighlight>
<pre>
 
  +
/*
;/* displayalert.c - Execute me to compile me with SAS C 5.10
 
LC -b1 -cfistq -v -y -j73 displayalert.c
 
Blink FROM LIB:c.o,displayalert.o TO displayalert LIBRARY LIB:LC.lib,LIB:Amiga.lib
 
quit
 
 
 
** displayalert.c - This program implements a recoverable alert
 
** displayalert.c - This program implements a recoverable alert
 
*/
 
*/
 
#define INTUI_V36_NAMES_ONLY
 
#define INTUI_V36_NAMES_ONLY
   
#include &lt;exec/types.h&gt;
+
#include <exec/types.h>
#include &lt;intuition/intuition.h&gt;
+
#include <intuition/intuition.h>
 
#include &lt;clib/exec_protos.h&gt;
 
#include &lt;clib/intuition_protos.h&gt;
 
 
#include &lt;stdio.h&gt;
 
 
#ifdef LATTICE
 
int CXBRK(void) { return(0); } /* Disable Lattice CTRL/C handling */
 
int chkabort(void) { return(0); } /* really */
 
#endif
 
   
  +
#include <proto/exec.h>
  +
#include <proto/intuition.h>
  +
#include <proto/dos.h>
   
 
/* Each string requires its own positioning information, as explained
 
/* Each string requires its own positioning information, as explained
 
** in the manual. Hex notation has been used to specify the positions of
 
** in the manual. Hex notation has been used to specify the positions of
** the text. Hex numbers start with a backslash, an &quot;x&quot; and the characters
+
** the text. Hex numbers start with a backslash, an "x" and the characters
 
** that make up the number.
 
** that make up the number.
 
**
 
**
Line 91: Line 80:
 
*/
 
*/
   
UBYTE *alertMsg =
+
uint8 *alertMsg =
&quot;\x00\xF0\x14&quot; &quot;OH NO, NOT AGAIN!&quot; &quot;\x00\x01&quot;
+
"\x00\xF0\x14" "OH NO, NOT AGAIN!" "\x00\x01"
&quot;\x00\x80\x24&quot; &quot;PRESS MOUSEBUTTON: LEFT=TRUE RIGHT=FALSE&quot; &quot;\x00&quot;;
+
"\x00\x80\x24" "PRESS MOUSEBUTTON: LEFT=TRUE RIGHT=FALSE" "\x00";
   
struct Library *IntuitionBase;
+
struct IntuitionIFace *IIntuition = NULL;
   
VOID main(int argc, char **argv)
+
int main()
 
{
 
{
if (IntuitionBase = OpenLibrary(&quot;intuition.library&quot;,33))
+
struct Library *IntuitionBase = IExec->OpenLibrary("intuition.library", 50);
  +
IIntuition = (struct IntuitionIFace *)IExec->GetInterface(IntuitionBase, "main", 1, NULL);
{
 
if (DisplayAlert(RECOVERY_ALERT, alertMsg, 52))
 
printf(&quot;Alert returned TRUE\n&quot;);
 
else
 
printf(&quot;Alert returned FALSE\n&quot;);
 
   
  +
if (IIntuition != NULL)
CloseLibrary(IntuitionBase);
 
  +
{
  +
if (IIntuition->DisplayAlert(RECOVERY_ALERT, alertMsg, 52))
  +
IDOS->Printf("Alert returned TRUE\n");
  +
else
  +
IDOS->Printf("Alert returned FALSE\n");
 
}
 
}
  +
  +
IExec->DropInterface((struct Interface *)IIntuition);
  +
IExec->CloseLibrary(IntuitionBase);
  +
  +
return 0;
 
}
 
}
  +
</syntaxhighlight>
</pre>
 
   
 
= Function Reference =
 
= Function Reference =
   
The following are brief descriptions of the Intuition functions that relate to the use of Intuition requesters and alerts. See the SDK for details on each function call.
+
The following are brief descriptions of the Intuition functions that relate to the use of Intuition alerts. See the SDK for details on each function call.
   
 
{| class="wikitable"
 
{| class="wikitable"

Latest revision as of 08:38, 11 April 2014

Intuition Alerts

Alerts are for emergency messages. They can be displayed even when the system is in a very fragile state, such as when the system is low on memory or when some of the system lists are corrupt.

Alerts can be displayed by either the system or an application. They are reserved for urgent messages and dire warnings in situations that require the user to take some immediate action. Alerts should only be used where no other display type is possible. For instance, when the system has crashed or is about to crash, an alert could be used to inform the user of the cause.

The sudden display of an alert is a jarring experience for the user. The system stops dead while the alert is displayed and waits for the user input. For this reason, alerts should only be used when there is no recourse. If possible, use requesters or windows to display warning messages in place of alerts.

System alerts are managed entirely by Intuition. The program does not have to take any action to invoke or process these alerts.

The alert appears at the top of the video display. They are displayed full width and as tall as needed. Alerts are always displayed on a black background. The text of the alert is displayed within a rectangular border. Both the text and the border are displayed in a single color which is determined by the type of the alert.

The user responds to an alert by pressing one of the mouse buttons. The left mouse button signifies a positive response such as "Retry" or "OK". The right mouse button signifies a negative response such as "Cancel" or "Abort".

Alerts Save Up User Input
The events produced by the user during an alert are not consumed by the alert. These events are passed through to the program when the alert returns. There could be a great deal of input queued and waiting for processing by the application.

Types of Alerts

There are two levels of severity for alerts:

RECOVERY_ALERT
Recovery alerts are used in situations where the caller believes that the system can resume operations after handling the error. The alert is used as a warning, and is displayed in amber.
A recoverable alert displays the text of the alert and flashes the border while waiting for the user to respond. It returns TRUE if the user presses the left mouse button in response to the alert, otherwise FALSE is returned.
DEADEND_ALERT
Deadend alerts are used in situations where the caller believes that no recovery from the error is possible, and further operation of the system is impossible. This alert is used to inform the user of a fatal problem and is displayed in red. Deadend alerts are the same as recoverable alerts in every way except color.

Creating Alerts

The function DisplayAlert() creates and displays an alert message. The message will almost always be displayed regardless of the state of the machine (with the exception of catastrophic hardware failures). If the user presses one of the mouse buttons, the display is restored to its original state, if possible. If a recoverable alert cannot be displayed (because memory is low), DisplayAlert() will return FALSE, as if the user had selected cancel. DisplayAlert() is also used by the system to display the Amiga system alert messages.

BOOL DisplayAlert( ULONG alertNumber, UBYTE *string, ULONG height );

The alertNumber argument is a LONG value, specifying whether this is a RECOVERY_ALERT or a DEADEND_ALERT (see the <intuition/intuition.h> include file).

The string argument points to a string that is made up of one or more substrings. Each substring contains the following:

  • The first component is a 16 bit x-coordinate and an 8 bit y-coordinate describing where to position the substring within the alert display. The units are in pixels. The y-coordinate describes the location of the text baseline.
  • The second component is the text itself. The substring must be NULL terminated (it ends with a zero byte).
  • The last component is the continuation byte. If this byte is zero, this is the last substring in the message. If this byte is non-zero, there is another substring in this alert message.

The complete string must be terminated by two NULL characters; one as the end of the last substring, and one as a NULL continuation byte, indicating that this was the last substring.

The height argument is the number of display lines required for the alert.

Display Alert Example

This program demonstrates an alert. An explanation of the positioning values for the alert strings is in the comment that precedes the alertMsg string.

/*
** displayalert.c -  This program implements a recoverable alert
*/
#define INTUI_V36_NAMES_ONLY
 
#include <exec/types.h>
#include <intuition/intuition.h>
 
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/dos.h>
 
/* Each string requires its own positioning information, as explained
** in the manual.  Hex notation has been used to specify the positions of
** the text. Hex numbers start with a backslash, an "x" and the characters
** that make up the number.
**
** Each line needs 2 bytes of X position, and 1 byte of Y position.
**   In our 1st line: x = \x00\xF0 (2 bytes) and y = \x14 (1 byte)
**   In our 2nd line: x = \x00\xA0 (2 bytes) and y = \x24 (1 byte)
** Each line is null terminated plus a continuation character (0=done).
** This example assumes that the complier will concatenate adjacent
** strings into a single string with no extra NULLs.  The compiler does
** add the terminating NULL at the end of the entire string...The entire
** alert must end in TWO NULLs, one for the end of the string, and one
** for the NULL continuation character.
*/
 
uint8 *alertMsg =
    "\x00\xF0\x14" "OH NO, NOT AGAIN!" "\x00\x01"
    "\x00\x80\x24" "PRESS MOUSEBUTTON:   LEFT=TRUE   RIGHT=FALSE" "\x00";
 
struct IntuitionIFace *IIntuition = NULL;
 
int main()
{
    struct Library *IntuitionBase = IExec->OpenLibrary("intuition.library", 50);
    IIntuition = (struct IntuitionIFace *)IExec->GetInterface(IntuitionBase, "main", 1, NULL);
 
    if (IIntuition != NULL)
    {
        if (IIntuition->DisplayAlert(RECOVERY_ALERT, alertMsg, 52))
            IDOS->Printf("Alert returned TRUE\n");
        else
            IDOS->Printf("Alert returned FALSE\n");
    }
 
    IExec->DropInterface((struct Interface *)IIntuition);
    IExec->CloseLibrary(IntuitionBase);
 
    return 0;
}

Function Reference

The following are brief descriptions of the Intuition functions that relate to the use of Intuition alerts. See the SDK for details on each function call.

Function Description
DisplayAlert() Open an alert on the screen.