Subversion Repositories Kolibri OS

Rev

Rev 6601 | Blame | Compare with Previous | Last modification | View Log | RSS feed

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