root/lib/widget/quick.h

/* [previous][next][first][last][top][bottom][index][help]  */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. quick_dialog

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

/* [previous][next][first][last][top][bottom][index][help]  */