Subversion Repositories Kolibri OS

Rev

Rev 9810 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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