root/lib/widget/dialog.h

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

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. dlg_get_current_widget_id
  2. dlg_select_current_widget

   1 /*
   2    Dialog box features module for the Midnight Commander
   3  */
   4 
   5 /** \file dialog.h
   6  *  \brief Header: dialog box features module
   7  */
   8 
   9 #ifndef MC__DIALOG_H
  10 #define MC__DIALOG_H
  11 
  12 #include <sys/types.h>          /* size_t */
  13 
  14 #include "lib/global.h"
  15 #include "lib/hook.h"           /* hook_t */
  16 #include "lib/keybind.h"        /* global_keymap_t */
  17 
  18 /*** typedefs(not structures) and defined constants **********************************************/
  19 
  20 #define DIALOG(x) ((WDialog *)(x))
  21 
  22 /* Common return values */
  23 /* ATTENTION: avoid overlapping with FileProgressStatus values */
  24 #define B_EXIT          0
  25 #define B_CANCEL        1
  26 #define B_ENTER         2
  27 #define B_HELP          3
  28 #define B_USER          100
  29 
  30 /*** enums ***************************************************************************************/
  31 
  32 /* Dialog color constants */
  33 typedef enum
  34 {
  35     DLG_COLOR_NORMAL,
  36     DLG_COLOR_FOCUS,
  37     DLG_COLOR_HOT_NORMAL,
  38     DLG_COLOR_HOT_FOCUS,
  39     DLG_COLOR_TITLE,
  40     DLG_COLOR_COUNT
  41 } dlg_colors_enum_t;
  42 
  43 /*** typedefs(not structures) ********************************************************************/
  44 
  45 /* get string representation of shortcut assigned  with command */
  46 /* as menu is a widget of dialog, ask dialog about shortcut string */
  47 typedef char *(*dlg_shortcut_str) (long command);
  48 
  49 /* get dialog name to show in dialog list */
  50 typedef char *(*dlg_title_str) (const WDialog * h, size_t len);
  51 
  52 typedef int dlg_colors_t[DLG_COLOR_COUNT];
  53 
  54 /* menu command execution */
  55 typedef cb_ret_t (*menu_exec_fn) (int command);
  56 
  57 /*** structures declarations (and typedefs of structures)*****************************************/
  58 
  59 struct WDialog
  60 {
  61     Widget widget;
  62 
  63     /* Set by the user */
  64     gboolean compact;           /* Suppress spaces around the frame */
  65     const char *help_ctx;       /* Name of the help entry */
  66     const int *color;           /* Color set. Unused in viewer and editor */
  67     char *title;                /* Title of the dialog */
  68 
  69     /* Set and received by the user */
  70     int ret_value;              /* Result of dlg_run() */
  71 
  72     /* Internal flags */
  73     gboolean winch_pending;     /* SIGWINCH signal has been got. Resize dialog after rise */
  74     int mouse_status;           /* For the autorepeat status of the mouse */
  75 
  76     /* Internal variables */
  77     GList *widgets;             /* widgets list */
  78     GList *current;             /* Currently active widget */
  79     unsigned long widget_id;    /* maximum id of all widgets */
  80     void *data;                 /* Data can be passed to dialog */
  81     char *event_group;          /* Name of event group for this dialog */
  82 
  83     dlg_shortcut_str get_shortcut;      /* Shortcut string */
  84     dlg_title_str get_title;    /* useless for modal dialogs */
  85 };
  86 
  87 /*** global variables defined in .c file *********************************************************/
  88 
  89 /* Color styles for normal and error dialogs */
  90 extern dlg_colors_t dialog_colors;
  91 extern dlg_colors_t alarm_colors;
  92 extern dlg_colors_t listbox_colors;
  93 
  94 extern GList *top_dlg;
  95 
  96 /* A hook list for idle events */
  97 extern hook_t *idle_hook;
  98 
  99 extern gboolean fast_refresh;
 100 extern gboolean mouse_close_dialog;
 101 
 102 extern const global_keymap_t *dialog_map;
 103 
 104 /*** declarations of public functions ************************************************************/
 105 
 106 /* Creates a dialog head  */
 107 WDialog *dlg_create (gboolean modal, int y1, int x1, int lines, int cols,
 108                      widget_pos_flags_t pos_flags, gboolean compact,
 109                      const int *colors, widget_cb_fn callback, widget_mouse_cb_fn mouse_callback,
 110                      const char *help_ctx, const char *title);
 111 
 112 void dlg_set_default_colors (void);
 113 
 114 unsigned long add_widget_autopos (WDialog * dest, void *w, widget_pos_flags_t pos_flags,
 115                                   const void *before);
 116 unsigned long add_widget (WDialog * dest, void *w);
 117 unsigned long add_widget_before (WDialog * h, void *w, void *before);
 118 void del_widget (void *w);
 119 
 120 /* sets size of dialog, leaving positioning to automatic mehtods
 121    according to dialog flags */
 122 void dlg_set_size (WDialog * h, int lines, int cols);
 123 /* this function allows to set dialog position */
 124 void dlg_set_position (WDialog * h, int y, int x, int lines, int cols);
 125 
 126 void dlg_init (WDialog * h);
 127 int dlg_run (WDialog * d);
 128 void dlg_destroy (WDialog * h);
 129 
 130 void dlg_run_done (WDialog * h);
 131 void dlg_save_history (WDialog * h);
 132 void dlg_process_event (WDialog * h, int key, Gpm_Event * event);
 133 
 134 void dlg_set_title (WDialog * h, const char *title);
 135 char *dlg_get_title (const WDialog * h, size_t len);
 136 
 137 void dlg_redraw (WDialog * h);
 138 
 139 void dlg_broadcast_msg (WDialog * h, widget_msg_t message);
 140 
 141 /* Default callback for dialogs */
 142 cb_ret_t dlg_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data);
 143 
 144 /* Default paint routine for dialogs */
 145 void dlg_default_repaint (WDialog * h);
 146 
 147 void dlg_erase (WDialog * h);
 148 void dlg_stop (WDialog * h);
 149 
 150 /* Widget selection */
 151 void dlg_select_prev_widget (WDialog * h);
 152 void dlg_select_next_widget (WDialog * h);
 153 Widget *find_widget_type (const WDialog * h, widget_cb_fn callback);
 154 GList *dlg_find (const WDialog * h, const Widget * w);
 155 Widget *dlg_find_by_id (const WDialog * h, unsigned long id);
 156 void dlg_select_by_id (const WDialog * h, unsigned long id);
 157 
 158 /* Redraw all dialogs */
 159 void do_refresh (void);
 160 
 161 /* Used in load_prompt() */
 162 void update_cursor (WDialog * h);
 163 
 164 void dlg_set_current_widget_next (WDialog * h);
 165 void dlg_set_current_widget_prev (WDialog * h);
 166 
 167 GList *dlg_get_widget_next_of (GList * w);
 168 GList *dlg_get_widget_prev_of (GList * w);
 169 
 170 /* --------------------------------------------------------------------------------------------- */
 171 /*** inline functions ****************************************************************************/
 172 /* --------------------------------------------------------------------------------------------- */
 173 
 174 static inline unsigned long
 175 dlg_get_current_widget_id (const WDialog * h)
     /* [previous][next][first][last][top][bottom][index][help]  */
 176 {
 177     return WIDGET (h->current->data)->id;
 178 }
 179 
 180 /* --------------------------------------------------------------------------------------------- */
 181 
 182 /**
 183  * Select current widget in the Dialog.
 184  *
 185  * @param h WDialog object
 186  */
 187 
 188 static inline void
 189 dlg_select_current_widget (WDialog * h)
     /* [previous][next][first][last][top][bottom][index][help]  */
 190 {
 191     if (h->current != NULL)
 192         widget_select (WIDGET (h->current->data));
 193 }
 194 
 195 /* --------------------------------------------------------------------------------------------- */
 196 
 197 #endif /* MC__DIALOG_H */

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