]> git.sur5r.net Git - cc65/blob - libsrc/geos-common/dlgbox/messagebox.c
Merge https://github.com/cc65/cc65 into c1p
[cc65] / libsrc / geos-common / dlgbox / messagebox.c
1 /*
2 ** char MessageBox (char mode, const char *format, ...)
3 **
4 ** Maciej 'YTM/Elysium' Witkowiak, 17.08.2003
5 **
6 */
7
8 #include <geos.h>
9 #include <stdio.h>
10
11 void _mbprintout(void);
12
13 static dlgBoxStr _mbdlg_EMPTY = {
14         DB_DEFPOS(1),
15         DB_OPVEC(&RstrFrmDialogue),
16         DB_USRROUT(&_mbprintout),
17         DB_END,
18 };
19
20 static dlgBoxStr _mbdlg_OK = {
21         DB_DEFPOS(1),
22         DB_USRROUT(&_mbprintout),
23         DB_ICON(OK, DBI_X_1, DBI_Y_2),
24         DB_END,
25 };
26
27 static dlgBoxStr _mbdlg_OKCANCEL = {
28         DB_DEFPOS(1),
29         DB_USRROUT(&_mbprintout),
30         DB_ICON(OK, DBI_X_0, DBI_Y_2),
31         DB_ICON(CANCEL, DBI_X_2, DBI_Y_2),
32         DB_END,
33 };
34
35 static dlgBoxStr _mbdlg_YESNO = {
36         DB_DEFPOS(1),
37         DB_USRROUT(&_mbprintout),
38         DB_ICON(YES, DBI_X_0, DBI_Y_2),
39         DB_ICON(NO, DBI_X_2, DBI_Y_2),
40         DB_END,
41 };
42
43 static dlgBoxStr *_mbboxes[] = {
44         &_mbdlg_EMPTY,
45         &_mbdlg_OK,
46         &_mbdlg_OKCANCEL,
47         &_mbdlg_YESNO
48 };
49
50 static char _mbbuffer[256];
51
52 char MessageBox(char mode, const char *format, ...)
53 {
54     register char *buf;
55     va_list ap;
56
57     /* first format out things */
58     va_start(ap, format);
59     vsprintf(_mbbuffer, format, ap);
60     va_end(ap);
61
62     /* replace LFs by CRs */
63     buf = &_mbbuffer[0];
64     while (*buf) {
65         if (*buf==LF) *buf=CR;
66         ++buf;
67     }
68
69     /* validate mode */
70     if (mode>=MB_LAST)
71         mode = MB_EMPTY;
72
73     return DoDlgBox(_mbboxes[mode]);
74 }
75
76 void _mbprintout(void)
77 {
78     UseSystemFont();
79     curWindow.top = DEF_DB_TOP;
80     curWindow.left = DEF_DB_LEFT+10;
81     curWindow.right = DEF_DB_RIGHT-10;
82     curWindow.bot = DEF_DB_BOT;
83     PutString(_mbbuffer, DEF_DB_TOP+10+curFontDesc.height, DEF_DB_LEFT+10 );
84 }