Subversion Repositories Kolibri OS

Rev

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

  1. #ifndef KOLIBRI_MSGBOX_H
  2. #define KOLIBRI_MSGBOX_H
  3.  
  4. #include <stdarg.h>
  5. #include <stddef.h>
  6. #include <stdint.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9.  
  10. typedef struct {
  11.     uint8_t     retval;  // 0 - win closed, 1 to n - button num, also default button on start
  12.     uint8_t     reserv;
  13.     char        texts[2048];      // must be enough ;-)
  14.     char        msgbox_stack[1024];
  15.     uint32_t    top_stack;
  16. }__attribute__((packed)) msgbox;
  17.  
  18. typedef void (*msgbox_callback)(void);
  19.  
  20. DLLAPI 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
  22. DLLAPI void __stdcall mb_reinit(msgbox *);  // recalc sizes when structure changes, called auto when MsgBoxCreate
  23.  
  24. static inline msgbox* kolibri_new_msgbox(char* title, char* text, int def_but, ...)
  25. /// 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
  27. /// last params are buttons text, max 8. last must set as NULL
  28. {
  29.     va_list vl = 0;
  30.     va_start(vl, def_but);
  31.     msgbox* box = calloc(sizeof(msgbox), 1);
  32.     box->retval = (uint8_t)def_but;
  33.     char    *pc = box->texts;
  34.     strcpy(pc, title);
  35.     pc += strlen(title) + 1;
  36.     strcpy(pc, text);
  37.     pc += strlen(text) + 1;
  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.         but_text = va_arg(vl, char*);
  44.     }
  45.  
  46.     va_end(vl);
  47.     return box;
  48. }
  49.  
  50. static inline void kolibri_start_msgbox(msgbox* box, msgbox_callback cb[])
  51. {
  52.     mb_create(box, &box->top_stack);
  53.     if (cb) mb_setfunctions(cb);
  54. }
  55.  
  56. #endif
  57.