grub2: bring back build of aros-side grub2 tools
[AROS.git] / rom / intuition / displayalert.c
blobe0da6986b77953fac5e439ed3402c0c8dbf5eefd
1 /*
2 Copyright © 1995-2013, 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 historical 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 text data. Text data have the following layout:
75 each string is preceded by 3 bytes. The first two of them are
76 the X coordinates of the string in the alert display. This is
77 given as a big-endian value. The third byte is the Y
78 coordinate of the text's baseline. Then a NUL-terminated
79 string follows by itself. After the NUL terminator there's
80 one more byte. If it's not zero, another string starts from
81 the next byte. Zero marks the end of the sequence. The text
82 is always rendered using the topaz/8 font.
83 height - The height of alert display in pixels.
85 RESULT
86 Always FALSE if AT_DeadEnd bit is set in alertnumber. Otherwise the
87 function returns TRUE or FALSE depending on what user chooses. In
88 AROS, alerts are presented in a requester with two gadgets: Ok and
89 Cancel. Ok returns TRUE; Cancel returns FALSE.
91 If the alert could not be posted for whatever reason, FALSE is
92 returned.
94 NOTES
95 This function is obsolete and exists only for backwards compatibility
96 with AmigaOS(tm). On various modern systems this function has
97 different effects. On classic Amiga(tm) this function may not work
98 with RTG displays, so it is generally deprecated. Please don't use it
99 in new software! Use legitimate intuition requesters if you want to
100 present some message to the user.
102 EXAMPLE
104 BUGS
106 SEE ALSO
108 INTERNALS
110 *****************************************************************************/
112 AROS_LIBFUNC_INIT
114 struct TextAttr font = {
115 "topaz.font",
117 FS_NORMAL,
120 struct IntuiText postext = {
121 1, 0, JAM2,
122 0, 0,
123 NULL,
124 "Ok"
126 struct IntuiText negtext = {
127 1, 0, JAM2,
128 0, 0,
129 NULL,
130 "Cancel"
132 struct IntuiText *body = displayalert_makebody(string, &font);
133 struct Window *req;
134 LONG ret = FALSE;
136 if (body)
138 char *buf;
139 unsigned int l1, l2;
140 struct Task *t = FindTask(NULL);
142 l1 = strlen(title);
143 l2 = strlen(t->tc_Node.ln_Name) + 1;
144 buf = AllocMem(l1 + l2, MEMF_ANY);
145 if (buf)
147 CopyMem(title, buf, l1);
148 CopyMem(t->tc_Node.ln_Name, &buf[l1], l2);
151 * This is actually the same as AutoRequest(), without IDCMP processing.
152 * We use internal function instead of BuildSysRequest() because the latter
153 * does not allow to specify own title for the requester. In order to stay
154 * compatible with various patches which modify system requesters look and
155 * feel we call all three functions by their internal entry points.
157 if (alertnumber & AT_DeadEnd)
158 req = buildsysreq_intern(NULL, buf, body, NULL, &postext, 0, 640, height, IntuitionBase);
159 else
160 req = buildsysreq_intern(NULL, buf, body, &postext, &negtext, 0, 640, height, IntuitionBase);
162 if (req)
164 while ((ret = sysreqhandler_intern(req, NULL, TRUE, IntuitionBase)) == -2);
165 freesysreq_intern(req, IntuitionBase);
168 FreeMem(buf, l1 + l2);
170 FreeVec(body);
173 return ret;
175 AROS_LIBFUNC_EXIT
176 } /* DisplayAlert */