quick.h 19 KB

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