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

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