quick.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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(txt, st, id_) \
  9. { \
  10. .widget_type = quick_checkbox, \
  11. .options = WOP_DEFAULT, \
  12. .pos_flags = WPOS_KEEP_DEFAULT, \
  13. .id = id_, \
  14. .u = { \
  15. .checkbox = { \
  16. .text = txt, \
  17. .state = st \
  18. } \
  19. } \
  20. }
  21. #define QUICK_BUTTON(txt, act, cb, id_) \
  22. { \
  23. .widget_type = quick_button, \
  24. .options = WOP_DEFAULT, \
  25. .pos_flags = WPOS_KEEP_DEFAULT, \
  26. .id = id_, \
  27. .u = { \
  28. .button = { \
  29. .text = txt, \
  30. .action = act, \
  31. .callback = cb \
  32. } \
  33. } \
  34. }
  35. #define QUICK_INPUT(txt, hname, res, id_, is_passwd_, strip_passwd_, completion_flags_) \
  36. { \
  37. .widget_type = quick_input, \
  38. .options = WOP_DEFAULT, \
  39. .pos_flags = WPOS_KEEP_DEFAULT, \
  40. .id = id_, \
  41. .u = { \
  42. .input = { \
  43. .label_text = NULL, \
  44. .label_location = input_label_none, \
  45. .label = NULL, \
  46. .text = txt, \
  47. .completion_flags = completion_flags_, \
  48. .is_passwd = is_passwd_, \
  49. .strip_passwd = strip_passwd_, \
  50. .histname = hname, \
  51. .result = res \
  52. } \
  53. } \
  54. }
  55. #define QUICK_LABELED_INPUT(label_, label_loc, txt, hname, res, id_, is_passwd_, strip_passwd_, completion_flags_) \
  56. { \
  57. .widget_type = quick_input, \
  58. .options = WOP_DEFAULT, \
  59. .pos_flags = WPOS_KEEP_DEFAULT, \
  60. .id = id_, \
  61. .u = { \
  62. .input = { \
  63. .label_text = label_, \
  64. .label_location = label_loc, \
  65. .label = NULL, \
  66. .text = txt, \
  67. .completion_flags = completion_flags_, \
  68. .is_passwd = is_passwd_, \
  69. .strip_passwd = strip_passwd_, \
  70. .histname = hname, \
  71. .result = res \
  72. } \
  73. } \
  74. }
  75. #define QUICK_LABEL(txt, id_) \
  76. { \
  77. .widget_type = quick_label, \
  78. .options = WOP_DEFAULT, \
  79. .pos_flags = WPOS_KEEP_DEFAULT, \
  80. .id = id_, \
  81. .u = { \
  82. .label = { \
  83. .text = txt, \
  84. .input = NULL \
  85. } \
  86. } \
  87. }
  88. #define QUICK_RADIO(cnt, items_, val, id_) \
  89. { \
  90. .widget_type = quick_radio, \
  91. .options = WOP_DEFAULT, \
  92. .pos_flags = WPOS_KEEP_DEFAULT, \
  93. .id = id_, \
  94. .u = { \
  95. .radio = { \
  96. .count = cnt, \
  97. .items = items_, \
  98. .value = val \
  99. } \
  100. } \
  101. }
  102. #define QUICK_START_GROUPBOX(t) \
  103. { \
  104. .widget_type = quick_start_groupbox, \
  105. .options = WOP_DEFAULT, \
  106. .pos_flags = WPOS_KEEP_DEFAULT, \
  107. .id = NULL, \
  108. .u = { \
  109. .groupbox = { \
  110. .title = t \
  111. } \
  112. } \
  113. }
  114. #define QUICK_STOP_GROUPBOX \
  115. { \
  116. .widget_type = quick_stop_groupbox, \
  117. .options = WOP_DEFAULT, \
  118. .pos_flags = WPOS_KEEP_DEFAULT, \
  119. .id = NULL, \
  120. .u = { \
  121. .input = { \
  122. .text = NULL, \
  123. .histname = NULL, \
  124. .result = NULL \
  125. } \
  126. } \
  127. }
  128. #define QUICK_SEPARATOR(line_) \
  129. { \
  130. .widget_type = quick_separator, \
  131. .options = WOP_DEFAULT, \
  132. .pos_flags = WPOS_KEEP_DEFAULT, \
  133. .id = NULL, \
  134. .u = { \
  135. .separator = { \
  136. .space = TRUE, \
  137. .line = line_ \
  138. } \
  139. } \
  140. }
  141. #define QUICK_START_COLUMNS \
  142. { \
  143. .widget_type = quick_start_columns, \
  144. .options = WOP_DEFAULT, \
  145. .pos_flags = WPOS_KEEP_DEFAULT, \
  146. .id = NULL, \
  147. .u = { \
  148. .input = { \
  149. .text = NULL, \
  150. .histname = NULL, \
  151. .result = NULL \
  152. } \
  153. } \
  154. }
  155. #define QUICK_NEXT_COLUMN \
  156. { \
  157. .widget_type = quick_next_column, \
  158. .options = WOP_DEFAULT, \
  159. .pos_flags = WPOS_KEEP_DEFAULT, \
  160. .id = NULL, \
  161. .u = { \
  162. .input = { \
  163. .text = NULL, \
  164. .histname = NULL, \
  165. .result = NULL \
  166. } \
  167. } \
  168. }
  169. #define QUICK_STOP_COLUMNS \
  170. { \
  171. .widget_type = quick_stop_columns, \
  172. .options = WOP_DEFAULT, \
  173. .pos_flags = WPOS_KEEP_DEFAULT, \
  174. .id = NULL, \
  175. .u = { \
  176. .input = { \
  177. .text = NULL, \
  178. .histname = NULL, \
  179. .result = NULL \
  180. } \
  181. } \
  182. }
  183. #define QUICK_START_BUTTONS(space_, line_) \
  184. { \
  185. .widget_type = quick_buttons, \
  186. .options = WOP_DEFAULT, \
  187. .pos_flags = WPOS_KEEP_DEFAULT, \
  188. .id = NULL, \
  189. .u = { \
  190. .separator = { \
  191. .space = space_, \
  192. .line = line_ \
  193. } \
  194. } \
  195. }
  196. #define QUICK_BUTTONS_OK_CANCEL \
  197. QUICK_START_BUTTONS (TRUE, TRUE), \
  198. QUICK_BUTTON (N_("&OK"), B_ENTER, NULL, NULL), \
  199. QUICK_BUTTON (N_("&Cancel"), B_CANCEL, NULL, NULL)
  200. #define QUICK_END \
  201. { \
  202. .widget_type = quick_end, \
  203. .options = WOP_DEFAULT, \
  204. .pos_flags = WPOS_KEEP_DEFAULT, \
  205. .id = NULL, \
  206. .u = { \
  207. .input = { \
  208. .text = NULL, \
  209. .histname = NULL, \
  210. .result = NULL \
  211. } \
  212. } \
  213. }
  214. /*** enums ***************************************************************************************/
  215. /* Quick Widgets */
  216. typedef enum
  217. {
  218. quick_end = 0,
  219. quick_checkbox = 1,
  220. quick_button = 2,
  221. quick_input = 3,
  222. quick_label = 4,
  223. quick_radio = 5,
  224. quick_start_groupbox = 6,
  225. quick_stop_groupbox = 7,
  226. quick_separator = 8,
  227. quick_start_columns = 9,
  228. quick_next_column = 10,
  229. quick_stop_columns = 11,
  230. quick_buttons = 12
  231. } quick_t;
  232. typedef enum
  233. {
  234. input_label_none = 0,
  235. input_label_above = 1,
  236. input_label_left = 2,
  237. input_label_right = 3,
  238. input_label_below = 4
  239. } quick_input_label_location_t;
  240. /*** structures declarations (and typedefs of structures)*****************************************/
  241. /* The widget is placed on relative_?/divisions_? of the parent widget */
  242. typedef struct quick_widget_t quick_widget_t;
  243. struct quick_widget_t
  244. {
  245. quick_t widget_type;
  246. widget_options_t options;
  247. widget_state_t state;
  248. widget_pos_flags_t pos_flags;
  249. unsigned long *id;
  250. /* widget parameters */
  251. union
  252. {
  253. struct
  254. {
  255. const char *text;
  256. gboolean *state; /* in/out */
  257. } checkbox;
  258. struct
  259. {
  260. const char *text;
  261. int action;
  262. bcback_fn callback;
  263. } button;
  264. struct
  265. {
  266. const char *label_text;
  267. quick_input_label_location_t label_location;
  268. quick_widget_t *label;
  269. const char *text;
  270. input_complete_t completion_flags;
  271. gboolean is_passwd; /* TRUE -- is password */
  272. gboolean strip_passwd;
  273. const char *histname;
  274. char **result;
  275. } input;
  276. struct
  277. {
  278. const char *text;
  279. quick_widget_t *input;
  280. } label;
  281. struct
  282. {
  283. int count;
  284. const char **items;
  285. int *value; /* in/out */
  286. } radio;
  287. struct
  288. {
  289. const char *title;
  290. } groupbox;
  291. struct
  292. {
  293. gboolean space;
  294. gboolean line;
  295. } separator;
  296. } u;
  297. };
  298. typedef struct
  299. {
  300. int y, x; /* if -1, then center the dialog */
  301. int cols; /* heigth is calculated automatically */
  302. const char *title;
  303. const char *help;
  304. quick_widget_t *widgets;
  305. widget_cb_fn callback;
  306. widget_mouse_cb_fn mouse_callback;
  307. } quick_dialog_t;
  308. /*** global variables defined in .c file *********************************************************/
  309. /*** declarations of public functions ************************************************************/
  310. int quick_dialog_skip (quick_dialog_t * quick_dlg, int nskip);
  311. /*** inline functions ****************************************************************************/
  312. static inline int
  313. quick_dialog (quick_dialog_t * quick_dlg)
  314. {
  315. return quick_dialog_skip (quick_dlg, 1);
  316. }
  317. #endif /* MC__QUICK_H */