Merge branch '2944_cleanup'
[midnight-commander.git] / lib / widget / dialog.h
blobeea46725165cd5ceef1b959e50c3fda38b772bc5
1 /*
2 Dialog box features module for the Midnight Commander
3 */
5 /** \file dialog.h
6 * \brief Header: dialog box features module
7 */
9 #ifndef MC__DIALOG_H
10 #define MC__DIALOG_H
12 #include <sys/types.h> /* size_t */
14 #include "lib/global.h"
15 #include "lib/hook.h" /* hook_t */
16 #include "lib/keybind.h" /* global_keymap_t */
17 #include "lib/tty/mouse.h" /* mouse_h */
19 /*** typedefs(not structures) and defined constants **********************************************/
21 #define DIALOG(x) ((WDialog *)(x))
23 /* Common return 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
30 /*** enums ***************************************************************************************/
32 /* Flags for create_dlg */
33 typedef enum
35 DLG_NONE = 0, /* No options */
36 DLG_CENTER = (1 << 0), /* Center the dialog */
37 DLG_TRYUP = (1 << 1), /* Try to move two lines up the dialog */
38 DLG_COMPACT = (1 << 2), /* Suppress spaces around the frame */
39 DLG_WANT_TAB = (1 << 3) /* Should the tab key be sent to the dialog? */
40 } dlg_flags_t;
42 /* Dialog state */
43 typedef enum
45 DLG_CONSTRUCT = 0, /* Dialog has been constructed but not run yet */
46 DLG_ACTIVE = 1, /* Dialog is visible and active */
47 DLG_SUSPENDED = 2, /* Dialog is suspended */
48 DLG_CLOSED = 3 /* Dialog is closed */
49 } dlg_state_t;
51 /* Dialog color constants */
52 typedef enum
54 DLG_COLOR_NORMAL,
55 DLG_COLOR_FOCUS,
56 DLG_COLOR_HOT_NORMAL,
57 DLG_COLOR_HOT_FOCUS,
58 DLG_COLOR_TITLE,
59 DLG_COLOR_COUNT
60 } dlg_colors_enum_t;
62 /*** typedefs(not structures) ********************************************************************/
64 /* get string representation of shortcut assigned with command */
65 /* as menu is a widget of dialog, ask dialog about shortcut string */
66 typedef char *(*dlg_shortcut_str) (unsigned long command);
68 /* get dialog name to show in dialog list */
69 typedef char *(*dlg_title_str) (const WDialog * h, size_t len);
71 typedef int dlg_colors_t[DLG_COLOR_COUNT];
73 /* menu command execution */
74 typedef cb_ret_t (*menu_exec_fn) (int command);
76 /*** structures declarations (and typedefs of structures)*****************************************/
78 struct WDialog
80 Widget widget;
82 /* Set by the user */
83 gboolean modal; /* type of dialog: modal or not */
84 dlg_flags_t flags; /* User flags */
85 const char *help_ctx; /* Name of the help entry */
86 dlg_colors_t color; /* Color set. Unused in viewer and editor */
87 char *title; /* Title of the dialog */
89 /* Set and received by the user */
90 int ret_value; /* Result of run_dlg() */
92 /* Internal flags */
93 dlg_state_t state;
94 gboolean fullscreen; /* Parents dialogs don't need refresh */
95 gboolean winch_pending; /* SIGWINCH signal has been got. Resize dialog after rise */
96 int mouse_status; /* For the autorepeat status of the mouse */
98 /* Internal variables */
99 GList *widgets; /* widgets list */
100 GList *current; /* Curently active widget */
101 unsigned long widget_id; /* maximum id of all widgets */
102 void *data; /* Data can be passed to dialog */
103 char *event_group; /* Name of event group for this dialog */
105 dlg_shortcut_str get_shortcut; /* Shortcut string */
106 dlg_title_str get_title; /* useless for modal dialogs */
109 /*** global variables defined in .c file *********************************************************/
111 /* Color styles for normal and error dialogs */
112 extern dlg_colors_t dialog_colors;
113 extern dlg_colors_t alarm_colors;
115 extern GList *top_dlg;
117 /* A hook list for idle events */
118 extern hook_t *idle_hook;
120 extern int fast_refresh;
121 extern int mouse_close_dialog;
123 extern const global_keymap_t *dialog_map;
125 /*** declarations of public functions ************************************************************/
127 /* draw box in window */
128 void draw_box (const WDialog * h, int y, int x, int ys, int xs, gboolean single);
130 /* Creates a dialog head */
131 WDialog *create_dlg (gboolean modal, int y1, int x1, int lines, int cols,
132 const int *colors, widget_cb_fn callback, mouse_h mouse_handler,
133 const char *help_ctx, const char *title, dlg_flags_t flags);
135 void dlg_set_default_colors (void);
137 unsigned long add_widget_autopos (WDialog * dest, void *w, widget_pos_flags_t pos_flags,
138 const void *before);
139 unsigned long add_widget (WDialog * dest, void *w);
140 unsigned long add_widget_before (WDialog * h, void *w, void *before);
141 void del_widget (void *w);
143 /* sets size of dialog, leaving positioning to automatic mehtods
144 according to dialog flags */
145 void dlg_set_size (WDialog * h, int lines, int cols);
146 /* this function allows to set dialog position */
147 void dlg_set_position (WDialog * h, int y1, int x1, int y2, int x2);
149 void init_dlg (WDialog * h);
150 int run_dlg (WDialog * d);
151 void destroy_dlg (WDialog * h);
153 void dlg_run_done (WDialog * h);
154 void dlg_save_history (WDialog * h);
155 void dlg_process_event (WDialog * h, int key, Gpm_Event * event);
157 char *dlg_get_title (const WDialog * h, size_t len);
159 void dlg_redraw (WDialog * h);
161 void dlg_broadcast_msg (WDialog * h, widget_msg_t message);
163 /* Default callback for dialogs */
164 cb_ret_t dlg_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data);
166 /* Default paint routine for dialogs */
167 void dlg_default_repaint (WDialog * h);
169 void dlg_replace_widget (Widget * old, Widget * new);
170 int dlg_overlap (Widget * a, Widget * b);
171 void dlg_erase (WDialog * h);
172 void dlg_stop (WDialog * h);
174 /* Widget selection */
175 void dlg_select_widget (void *w);
176 void dlg_set_top_widget (void *w);
177 void dlg_one_up (WDialog * h);
178 void dlg_one_down (WDialog * h);
179 gboolean dlg_focus (WDialog * h);
180 Widget *find_widget_type (const WDialog * h, widget_cb_fn callback);
181 Widget *dlg_find_by_id (const WDialog * h, unsigned long id);
182 void dlg_select_by_id (const WDialog * h, unsigned long id);
184 /* Redraw all dialogs */
185 void do_refresh (void);
187 /* Used in load_prompt() */
188 void update_cursor (WDialog * h);
190 /*** inline functions ****************************************************************************/
192 /* Return TRUE if the widget is active, FALSE otherwise */
193 static inline gboolean
194 dlg_widget_active (void *w)
196 return (w == WIDGET (w)->owner->current->data);
199 /* --------------------------------------------------------------------------------------------- */
201 static inline unsigned long
202 dlg_get_current_widget_id (const struct WDialog *h)
204 return WIDGET (h->current->data)->id;
207 #endif /* MC__DIALOG_H */