Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
8098 superturbo 1
#ifndef KOLIBRI_MSGBOX_H
2
#define KOLIBRI_MSGBOX_H
3
#include 
4
#include 
5
#include 
6
#include 
7
 
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
 
8101 superturbo 19
extern void (*msgbox_create __attribute__((__stdcall__)))(msgbox *, void *thread); // clears callbacks, ! if fix lib, we can return eax as of Fn51
20
extern void (*msgbox_setfunctions __attribute__((__stdcall__)))(msgbox_callback*); // must be called immediately after create, zero-ended array
21
extern void (*msgbox_reinit __attribute__((__stdcall__)))(msgbox *) ;  // recalc sizes when structure changes, called auto when MsgBoxCreate
8098 superturbo 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
{
28
    va_list vl=0;
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
{
51
    (*msgbox_create)(box, &box->top_stack);
52
    if (cb) (*msgbox_setfunctions)(cb);
53
}
54
 
55
#endif