Subversion Repositories Kolibri OS

Rev

Rev 9810 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8796 turbocat 1
#ifndef KOLIBRI_MSGBOX_H
2
#define KOLIBRI_MSGBOX_H
9620 turbocat 3
 
8796 turbocat 4
#include 
5
#include 
6
#include 
7
#include 
8
 
9
typedef struct {
10
    uint8_t     retval;  // 0 - win closed, 1 to n - button num, also default button on start
11
    uint8_t     reserv;
12
    char        texts[2048];      // must be enough ;-)
13
    char        msgbox_stack[1024];
14
    uint32_t    top_stack;
15
}__attribute__((packed)) msgbox;
16
 
17
typedef void (*msgbox_callback)(void);
18
 
9811 Coldy 19
extern void __stdcall (*mb_create)(msgbox *, void *thread); // clears callbacks, ! if fix lib, we can return eax as of Fn51
20
extern void __stdcall (*mb_setfunctions)(msgbox_callback*); // must be called immediately after create, zero-ended array
21
extern void __stdcall (*mb_reinit)(msgbox *);  // recalc sizes when structure changes, called auto when MsgBoxCreate
8796 turbocat 22
 
23
static inline msgbox* kolibri_new_msgbox(char* title, char* text, int def_but, ...)
24
/// text can be multilined by code 13 = "\r"
25
/// def_but - highlighted and used on Enter (if zero - default is [X]), user may use Tabs or Arrows
26
/// last params are buttons text, max 8. last must set as NULL
27
{
9620 turbocat 28
    va_list vl = 0;
8796 turbocat 29
    va_start(vl, def_but);
30
    msgbox* box = calloc(sizeof(msgbox), 1);
31
    box->retval = (uint8_t)def_but;
32
    char    *pc = box->texts;
33
    strcpy(pc, title);
34
    pc += strlen(title) + 1;
35
    strcpy(pc, text);
36
    pc += strlen(text) + 1;
37
    char  *but_text = va_arg(vl, char*);
38
    while (but_text)
39
    {
40
        strcpy(pc, but_text);
41
        pc += strlen(but_text) + 1;
42
        but_text = va_arg(vl, char*);
43
    }
44
 
45
    va_end(vl);
46
    return box;
47
}
48
 
49
static inline void kolibri_start_msgbox(msgbox* box, msgbox_callback cb[])
50
{
9620 turbocat 51
    mb_create(box, &box->top_stack);
52
    if (cb) mb_setfunctions(cb);
8796 turbocat 53
}
54
 
55
#endif