quick.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /** \file quick.h
  2. * \brief Header: quick dialog engine
  3. */
  4. #ifndef MC__QUICK_H
  5. #define MC__QUICK_H
  6. #include "lib/tty/mouse.h"
  7. /*** typedefs(not structures) and defined constants **********************************************/
  8. #define QUICK_CHECKBOX(x, xdiv, y, ydiv, txt, st) \
  9. { \
  10. .widget_type = quick_checkbox, \
  11. .relative_x = x, \
  12. .x_divisions = xdiv, \
  13. .relative_y = y, \
  14. .y_divisions = ydiv, \
  15. .widget = NULL, \
  16. .options = 0, \
  17. .u = { \
  18. .checkbox = { \
  19. .text = txt, \
  20. .state = st \
  21. } \
  22. } \
  23. }
  24. #define QUICK_BUTTON(x, xdiv, y, ydiv, txt, act, cb) \
  25. { \
  26. .widget_type = quick_button, \
  27. .relative_x = x, \
  28. .x_divisions = xdiv, \
  29. .relative_y = y, \
  30. .y_divisions = ydiv, \
  31. .widget = NULL, \
  32. .options = 0, \
  33. .u = { \
  34. .button = { \
  35. .text = txt, \
  36. .action = act, \
  37. .callback = cb \
  38. } \
  39. } \
  40. }
  41. #define QUICK_INPUT(x, xdiv, y, ydiv, txt, len_, flags_, hname, res) \
  42. { \
  43. .widget_type = quick_input, \
  44. .relative_x = x, \
  45. .x_divisions = xdiv, \
  46. .relative_y = y, \
  47. .y_divisions = ydiv, \
  48. .widget = NULL, \
  49. .options = 0, \
  50. .u = { \
  51. .input = { \
  52. .text = txt, \
  53. .len = len_, \
  54. .flags = flags_, \
  55. .histname = hname, \
  56. .result = res \
  57. } \
  58. } \
  59. }
  60. #define QUICK_LABEL(x, xdiv, y, ydiv, txt) \
  61. { \
  62. .widget_type = quick_label, \
  63. .relative_x = x, \
  64. .x_divisions = xdiv, \
  65. .relative_y = y, \
  66. .y_divisions = ydiv, \
  67. .widget = NULL, \
  68. .options = 0, \
  69. .u = { \
  70. .label = { \
  71. .text = txt \
  72. } \
  73. } \
  74. }
  75. #define QUICK_RADIO(x, xdiv, y, ydiv, cnt, items_, val) \
  76. { \
  77. .widget_type = quick_radio, \
  78. .relative_x = x, \
  79. .x_divisions = xdiv, \
  80. .relative_y = y, \
  81. .y_divisions = ydiv, \
  82. .widget = NULL, \
  83. .options = 0, \
  84. .u = { \
  85. .radio = { \
  86. .count = cnt, \
  87. .items = items_, \
  88. .value = val \
  89. } \
  90. } \
  91. }
  92. #define QUICK_GROUPBOX(x, xdiv, y, ydiv, w, h, t) \
  93. { \
  94. .widget_type = quick_groupbox, \
  95. .relative_x = x, \
  96. .x_divisions = xdiv, \
  97. .relative_y = y, \
  98. .y_divisions = ydiv, \
  99. .widget = NULL, \
  100. .options = 0, \
  101. .u = { \
  102. .groupbox = { \
  103. .width = w, \
  104. .height = h, \
  105. .title = t \
  106. } \
  107. } \
  108. }
  109. #define QUICK_END \
  110. { \
  111. .widget_type = quick_end, \
  112. .relative_x = 0, \
  113. .x_divisions = 0, \
  114. .relative_y = 0, \
  115. .y_divisions = 0, \
  116. .widget = NULL, \
  117. .options = 0, \
  118. .u = { \
  119. .input = { \
  120. .text = NULL, \
  121. .len = 0, \
  122. .flags = 0, \
  123. .histname = NULL, \
  124. .result = NULL \
  125. } \
  126. } \
  127. }
  128. /*** enums ***************************************************************************************/
  129. /* Quick Widgets */
  130. typedef enum
  131. {
  132. quick_end = 0,
  133. quick_checkbox = 1,
  134. quick_button = 2,
  135. quick_input = 3,
  136. quick_label = 4,
  137. quick_radio = 5,
  138. quick_groupbox = 6
  139. } quick_t;
  140. /*** structures declarations (and typedefs of structures)*****************************************/
  141. /* The widget is placed on relative_?/divisions_? of the parent widget */
  142. typedef struct
  143. {
  144. quick_t widget_type;
  145. int relative_x;
  146. int x_divisions;
  147. int relative_y;
  148. int y_divisions;
  149. Widget *widget;
  150. widget_options_t options;
  151. /* widget parameters */
  152. union
  153. {
  154. struct
  155. {
  156. const char *text;
  157. int *state; /* in/out */
  158. } checkbox;
  159. struct
  160. {
  161. const char *text;
  162. int action;
  163. bcback_fn callback;
  164. } button;
  165. struct
  166. {
  167. const char *text;
  168. int len;
  169. int flags; /* 1 -- is_password, 2 -- INPUT_COMPLETE_CD */
  170. const char *histname;
  171. char **result;
  172. gboolean strip_password;
  173. } input;
  174. struct
  175. {
  176. const char *text;
  177. } label;
  178. struct
  179. {
  180. int count;
  181. const char **items;
  182. int *value; /* in/out */
  183. } radio;
  184. struct
  185. {
  186. int width;
  187. int height;
  188. const char *title;
  189. } groupbox;
  190. } u;
  191. } QuickWidget;
  192. typedef struct
  193. {
  194. int xlen, ylen;
  195. int xpos, ypos; /* if -1, then center the dialog */
  196. const char *title;
  197. const char *help;
  198. QuickWidget *widgets;
  199. dlg_cb_fn callback;
  200. mouse_h mouse;
  201. gboolean i18n; /* If true, internationalization has happened */
  202. } QuickDialog;
  203. /*** global variables defined in .c file *********************************************************/
  204. /*** declarations of public functions ************************************************************/
  205. int quick_dialog_skip (QuickDialog * qd, int nskip);
  206. /*** inline functions ****************************************************************************/
  207. static inline int
  208. quick_dialog (QuickDialog * qd)
  209. {
  210. return quick_dialog_skip (qd, 0);
  211. }
  212. #endif /* MC__QUICK_H */