quick.h 11 KB

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