Subversion Repositories Kolibri OS

Rev

Rev 6601 | Go to most recent revision | 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];      // mus 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.             *but_text = va_arg(vl, char*);
  34.     strcpy(pc, title);
  35.     pc += strlen(title) + 1;
  36.  
  37.     while (but_text)
  38.     {
  39.         strcpy(pc, but_text);
  40.         pc += strlen(but_text) + 1;
  41.         // assert(pc - box->texts < sizeof box->texts);
  42.     }
  43.  
  44.     va_end(vl);
  45.  
  46.     return box;
  47. }
  48.  
  49. void kolibri_start_msgbox(msgbox* box, msgbox_callback cb[])
  50. {
  51.     if (!msgbox_inited)
  52.     {
  53.         kolibri_msgbox_init();
  54.         msgbox_inited++;
  55.     }
  56.     (*msgbox_create)(box, &box->top_stack);
  57.     if (cb) (*msgbox_setfunctions)(cb);
  58. }
  59.  
  60. #endif
  61.