quick.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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(txt, st, id_) \
  8. { \
  9. .widget_type = quick_checkbox, .options = WOP_DEFAULT, .pos_flags = WPOS_KEEP_DEFAULT, \
  10. .id = id_, .u = { \
  11. .checkbox = { .text = txt, .state = st } \
  12. } \
  13. }
  14. #define QUICK_BUTTON(txt, act, cb, id_) \
  15. { \
  16. .widget_type = quick_button, .options = WOP_DEFAULT, .pos_flags = WPOS_KEEP_DEFAULT, \
  17. .id = id_, .u = { \
  18. .button = { .text = txt, .action = act, .callback = cb } \
  19. } \
  20. }
  21. #define QUICK_INPUT(txt, hname, res, id_, is_passwd_, strip_passwd_, completion_flags_) \
  22. { \
  23. .widget_type = quick_input, .options = WOP_DEFAULT, .pos_flags = WPOS_KEEP_DEFAULT, \
  24. .id = id_, .u = { \
  25. .input = { .label_text = NULL, \
  26. .label_location = input_label_none, \
  27. .label = NULL, \
  28. .text = txt, \
  29. .completion_flags = completion_flags_, \
  30. .is_passwd = is_passwd_, \
  31. .strip_passwd = strip_passwd_, \
  32. .histname = hname, \
  33. .result = res } \
  34. } \
  35. }
  36. #define QUICK_LABELED_INPUT(label_, label_loc, txt, hname, res, id_, is_passwd_, strip_passwd_, \
  37. completion_flags_) \
  38. { \
  39. .widget_type = quick_input, .options = WOP_DEFAULT, .pos_flags = WPOS_KEEP_DEFAULT, \
  40. .id = id_, .u = { \
  41. .input = { .label_text = label_, \
  42. .label_location = label_loc, \
  43. .label = NULL, \
  44. .text = txt, \
  45. .completion_flags = completion_flags_, \
  46. .is_passwd = is_passwd_, \
  47. .strip_passwd = strip_passwd_, \
  48. .histname = hname, \
  49. .result = res } \
  50. } \
  51. }
  52. #define QUICK_LABEL(txt, id_) \
  53. { \
  54. .widget_type = quick_label, .options = WOP_DEFAULT, .pos_flags = WPOS_KEEP_DEFAULT, \
  55. .id = id_, .u = { \
  56. .label = { .text = txt, .input = NULL } \
  57. } \
  58. }
  59. #define QUICK_RADIO(cnt, items_, val, id_) \
  60. { \
  61. .widget_type = quick_radio, .options = WOP_DEFAULT, .pos_flags = WPOS_KEEP_DEFAULT, \
  62. .id = id_, .u = { \
  63. .radio = { .count = cnt, .items = items_, .value = val } \
  64. } \
  65. }
  66. #define QUICK_START_GROUPBOX(t) \
  67. { \
  68. .widget_type = quick_start_groupbox, .options = WOP_DEFAULT, \
  69. .pos_flags = WPOS_KEEP_DEFAULT, .id = NULL, .u = { \
  70. .groupbox = { .title = t } \
  71. } \
  72. }
  73. #define QUICK_STOP_GROUPBOX \
  74. { \
  75. .widget_type = quick_stop_groupbox, .options = WOP_DEFAULT, \
  76. .pos_flags = WPOS_KEEP_DEFAULT, .id = NULL, .u = { \
  77. .input = { .text = NULL, .histname = NULL, .result = NULL } \
  78. } \
  79. }
  80. #define QUICK_SEPARATOR(line_) \
  81. { \
  82. .widget_type = quick_separator, .options = WOP_DEFAULT, .pos_flags = WPOS_KEEP_DEFAULT, \
  83. .id = NULL, .u = { \
  84. .separator = { .space = TRUE, .line = line_ } \
  85. } \
  86. }
  87. #define QUICK_START_COLUMNS \
  88. { \
  89. .widget_type = quick_start_columns, .options = WOP_DEFAULT, \
  90. .pos_flags = WPOS_KEEP_DEFAULT, .id = NULL, .u = { \
  91. .input = { .text = NULL, .histname = NULL, .result = NULL } \
  92. } \
  93. }
  94. #define QUICK_NEXT_COLUMN \
  95. { \
  96. .widget_type = quick_next_column, .options = WOP_DEFAULT, .pos_flags = WPOS_KEEP_DEFAULT, \
  97. .id = NULL, .u = { \
  98. .input = { .text = NULL, .histname = NULL, .result = NULL } \
  99. } \
  100. }
  101. #define QUICK_STOP_COLUMNS \
  102. { \
  103. .widget_type = quick_stop_columns, .options = WOP_DEFAULT, .pos_flags = WPOS_KEEP_DEFAULT, \
  104. .id = NULL, .u = { \
  105. .input = { .text = NULL, .histname = NULL, .result = NULL } \
  106. } \
  107. }
  108. #define QUICK_START_BUTTONS(space_, line_) \
  109. { \
  110. .widget_type = quick_buttons, .options = WOP_DEFAULT, .pos_flags = WPOS_KEEP_DEFAULT, \
  111. .id = NULL, .u = { \
  112. .separator = { .space = space_, .line = line_ } \
  113. } \
  114. }
  115. #define QUICK_BUTTONS_OK_CANCEL \
  116. QUICK_START_BUTTONS (TRUE, TRUE), QUICK_BUTTON (N_ ("&OK"), B_ENTER, NULL, NULL), \
  117. QUICK_BUTTON (N_ ("&Cancel"), B_CANCEL, NULL, NULL)
  118. #define QUICK_END \
  119. { \
  120. .widget_type = quick_end, .options = WOP_DEFAULT, .pos_flags = WPOS_KEEP_DEFAULT, \
  121. .id = NULL, .u = { \
  122. .input = { .text = NULL, .histname = NULL, .result = NULL } \
  123. } \
  124. }
  125. /*** enums ***************************************************************************************/
  126. /* Quick Widgets */
  127. typedef enum
  128. {
  129. quick_end = 0,
  130. quick_checkbox = 1,
  131. quick_button = 2,
  132. quick_input = 3,
  133. quick_label = 4,
  134. quick_radio = 5,
  135. quick_start_groupbox = 6,
  136. quick_stop_groupbox = 7,
  137. quick_separator = 8,
  138. quick_start_columns = 9,
  139. quick_next_column = 10,
  140. quick_stop_columns = 11,
  141. quick_buttons = 12
  142. } quick_t;
  143. typedef enum
  144. {
  145. input_label_none = 0,
  146. input_label_above = 1,
  147. input_label_left = 2,
  148. input_label_right = 3,
  149. input_label_below = 4
  150. } quick_input_label_location_t;
  151. /*** structures declarations (and typedefs of structures)*****************************************/
  152. /* The widget is placed on relative_?/divisions_? of the parent widget */
  153. typedef struct quick_widget_t quick_widget_t;
  154. struct quick_widget_t
  155. {
  156. quick_t widget_type;
  157. widget_options_t options;
  158. widget_state_t state;
  159. widget_pos_flags_t pos_flags;
  160. unsigned long *id;
  161. /* widget parameters */
  162. union
  163. {
  164. struct
  165. {
  166. const char *text;
  167. gboolean *state; /* in/out */
  168. } checkbox;
  169. struct
  170. {
  171. const char *text;
  172. int action;
  173. bcback_fn callback;
  174. } button;
  175. struct
  176. {
  177. const char *label_text;
  178. quick_input_label_location_t label_location;
  179. quick_widget_t *label;
  180. const char *text;
  181. input_complete_t completion_flags;
  182. gboolean is_passwd; /* TRUE -- is password */
  183. gboolean strip_passwd;
  184. const char *histname;
  185. char **result;
  186. } input;
  187. struct
  188. {
  189. const char *text;
  190. quick_widget_t *input;
  191. } label;
  192. struct
  193. {
  194. int count;
  195. const char **items;
  196. int *value; /* in/out */
  197. } radio;
  198. struct
  199. {
  200. const char *title;
  201. } groupbox;
  202. struct
  203. {
  204. gboolean space;
  205. gboolean line;
  206. } separator;
  207. } u;
  208. };
  209. typedef struct
  210. {
  211. WRect rect; /* if rect.x == -1 or rect.y == -1, then dialog is ceneterd;
  212. * rect.lines is unused and ignored */
  213. const char *title;
  214. const char *help;
  215. quick_widget_t *widgets;
  216. widget_cb_fn callback;
  217. widget_mouse_cb_fn mouse_callback;
  218. } quick_dialog_t;
  219. /*** global variables defined in .c file *********************************************************/
  220. /*** declarations of public functions ************************************************************/
  221. int quick_dialog_skip (quick_dialog_t *quick_dlg, int nskip);
  222. /*** inline functions ****************************************************************************/
  223. static inline int
  224. quick_dialog (quick_dialog_t *quick_dlg)
  225. {
  226. return quick_dialog_skip (quick_dlg, 1);
  227. }
  228. #endif /* MC__QUICK_H */