quick.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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 = 0, \
  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 = 0, \
  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 = 0, \
  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 = 0, \
  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 = 0, \
  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 = 0, \
  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 = 0, \
  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 = 0, \
  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 = 0, \
  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 = 0, \
  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 = 0, \
  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 = 0, \
  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 = 0, \
  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 = 0, \
  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_pos_flags_t pos_flags;
  248. unsigned long *id;
  249. /* widget parameters */
  250. union
  251. {
  252. struct
  253. {
  254. const char *text;
  255. int *state; /* in/out */
  256. } checkbox;
  257. struct
  258. {
  259. const char *text;
  260. int action;
  261. bcback_fn callback;
  262. } button;
  263. struct
  264. {
  265. const char *label_text;
  266. quick_input_label_location_t label_location;
  267. quick_widget_t *label;
  268. const char *text;
  269. input_complete_t completion_flags;
  270. gboolean is_passwd; /* TRUE -- is password */
  271. gboolean strip_passwd;
  272. const char *histname;
  273. char **result;
  274. } input;
  275. struct
  276. {
  277. const char *text;
  278. quick_widget_t *input;
  279. } label;
  280. struct
  281. {
  282. int count;
  283. const char **items;
  284. int *value; /* in/out */
  285. } radio;
  286. struct
  287. {
  288. const char *title;
  289. } groupbox;
  290. struct
  291. {
  292. gboolean space;
  293. gboolean line;
  294. } separator;
  295. } u;
  296. };
  297. typedef struct
  298. {
  299. int y, x; /* if -1, then center the dialog */
  300. int cols; /* heigth is calculated automatically */
  301. const char *title;
  302. const char *help;
  303. quick_widget_t *widgets;
  304. widget_cb_fn callback;
  305. mouse_h mouse;
  306. } quick_dialog_t;
  307. /*** global variables defined in .c file *********************************************************/
  308. /*** declarations of public functions ************************************************************/
  309. int quick_dialog_skip (quick_dialog_t * quick_dlg, int nskip);
  310. /*** inline functions ****************************************************************************/
  311. static inline int
  312. quick_dialog (quick_dialog_t * quick_dlg)
  313. {
  314. return quick_dialog_skip (quick_dlg, 1);
  315. }
  316. #endif /* MC__QUICK_H */