Minor fixes to comments.
[AROS.git] / rom / intuition / displayalert.c
blob446a1e34a446dc54893d6fc0c5f2a2811df0135d
1 /*
2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
5 */
7 #include "intuition_intern.h"
9 /* I'm too lazy to open the font and query it. Anyway this is hardcoded. */
10 #define TOPAZ_8_BASELINE 6
12 /* Perhaps this should be localized */
13 static const char title[] = "Program alert: ";
15 static struct IntuiText *displayalert_makebody(STRPTR string, struct TextAttr *font)
17 struct IntuiText *res;
18 char *s = string;
19 unsigned int lines = 0;
20 unsigned int i;
22 /* First count number of lines */
25 s += 3; /* Skip coordinates */
26 while (*s++); /* Skip text bytes including NULL terminator */
27 lines++;
28 } while (*s++); /* This automatically skips continuation byte */
30 res = AllocVec(sizeof(struct IntuiText) * lines, MEMF_ANY);
31 if (!res)
32 return NULL;
34 s = string;
35 for (i = 0; i < lines; i++)
37 res[i].FrontPen = 1;
38 res[i].BackPen = 0;
39 res[i].DrawMode = JAM2;
40 res[i].LeftEdge = AROS_BE2WORD(*((UWORD *)s));
41 s += 2;
42 res[i].TopEdge = *s++ - TOPAZ_8_BASELINE;
43 res[i].ITextFont = font;
44 res[i].IText = s;
45 while(*s++);
46 res[i].NextText = *s++ ? &res[i+1] : NULL;
49 return res;
52 /*****************************************************************************
54 NAME */
55 #include <proto/intuition.h>
57 AROS_LH3(BOOL, DisplayAlert,
59 /* SYNOPSIS */
60 AROS_LHA(ULONG , alertnumber, D0),
61 AROS_LHA(UBYTE*, string, A0),
62 AROS_LHA(UWORD , height, D1),
64 /* LOCATION */
65 struct IntuitionBase *, IntuitionBase, 15, Intuition)
67 /* FUNCTION
68 Bring up an alert with the given message.
70 INPUTS
71 alertnumber - Value determining type of alert. For historic reasons
72 this is the same value as passed to Alert(). However
73 this functions takes into account only AT_DeadEnd bit.
74 string - A pointer to a text data. Text data have the following layout:
75 each string is preceded by 3 bytes. First two of them are X coordinate
76 of the string in alert display. This is given as bigendian value. Third
77 byte is Y coordinate of text's baseline. Then NULL-terminated string
78 follows by itself. After NULL terminator there's one more byte. If it's
79 not zero, another string starts from the next byte. Zero marks end of
80 the sequence.
81 The text is always rendered using topaz/8 font.
82 height - The height of alert display in pixels.
84 RESULT
85 Always FALSE if AT_DeadEnd bit is set in the alertnumber. Otherwise the function
86 returns TRUE or FALSE depending on what user chooses. In AROS alerts are presented
87 in a requester with two gadgets: Ok and Cancel. Ok returns TRUE, Cancel returns FALSE.
89 If the alert could not be posted for whatever reason, FALSE is returned.
91 NOTES
92 This function is obsolete and exists only for backwards compatibility with
93 AmigaOS(tm). On various modern systems this function has different effects.
94 On classic Amiga(tm) this function may not work with RTG displays, so it
95 is generally deprecated. Please don't use it in a new software! Use legitimate
96 intuition requesters if you want to present some message to the user.
98 EXAMPLE
100 BUGS
102 SEE ALSO
104 INTERNALS
106 HISTORY
108 *****************************************************************************/
110 AROS_LIBFUNC_INIT
112 struct TextAttr font = {
113 "topaz.font",
115 FS_NORMAL,
118 struct IntuiText postext = {
119 1, 0, JAM2,
120 0, 0,
121 NULL,
122 "Ok"
124 struct IntuiText negtext = {
125 1, 0, JAM2,
126 0, 0,
127 NULL,
128 "Cancel"
130 struct IntuiText *body = displayalert_makebody(string, &font);
131 struct Window *req;
132 LONG ret = FALSE;
134 if (body)
136 char *buf;
137 unsigned int l1, l2;
138 struct Task *t = FindTask(NULL);
140 l1 = strlen(title);
141 l2 = strlen(t->tc_Node.ln_Name) + 1;
142 buf = AllocMem(l1 + l2, MEMF_ANY);
143 if (buf)
145 CopyMem(title, buf, l1);
146 CopyMem(t->tc_Node.ln_Name, &buf[l1], l2);
149 * This is actually the same as AutoRequest(), without IDCMP processing.
150 * We use internal function instead of BuildSysRequest() because the latter
151 * does not allow to specify own title for the requester. In order to stay
152 * compatible with various patches which modify system requesters look and
153 * feel we call all three functions by their internal entry points.
155 if (alertnumber & AT_DeadEnd)
156 req = buildsysreq_intern(NULL, buf, body, NULL, &postext, 0, 640, height, IntuitionBase);
157 else
158 req = buildsysreq_intern(NULL, buf, body, &postext, &negtext, 0, 640, height, IntuitionBase);
160 if (req)
162 while ((ret = sysreqhandler_intern(req, NULL, TRUE, IntuitionBase)) == -2);
163 freesysreq_intern(req, IntuitionBase);
166 FreeMem(buf, l1 + l2);
168 FreeVec(body);
171 return ret;
173 AROS_LIBFUNC_EXIT
174 } /* DisplayAlert */