Join widget_state_t and dlg_state_t.
[midnight-commander.git] / lib / widget / dialog.h
bloba84beebb97853728c8d588126e9add600b68a199
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 */
18 /*** typedefs(not structures) and defined constants **********************************************/
20 #define DIALOG(x) ((WDialog *)(x))
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
30 /*** enums ***************************************************************************************/
32 /* Flags for dlg_create */
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 color constants */
43 typedef enum
45 DLG_COLOR_NORMAL,
46 DLG_COLOR_FOCUS,
47 DLG_COLOR_HOT_NORMAL,
48 DLG_COLOR_HOT_FOCUS,
49 DLG_COLOR_TITLE,
50 DLG_COLOR_COUNT
51 } dlg_colors_enum_t;
53 /*** typedefs(not structures) ********************************************************************/
55 /* get string representation of shortcut assigned with command */
56 /* as menu is a widget of dialog, ask dialog about shortcut string */
57 typedef char *(*dlg_shortcut_str) (long command);
59 /* get dialog name to show in dialog list */
60 typedef char *(*dlg_title_str) (const WDialog * h, size_t len);
62 typedef int dlg_colors_t[DLG_COLOR_COUNT];
64 /* menu command execution */
65 typedef cb_ret_t (*menu_exec_fn) (int command);
67 /*** structures declarations (and typedefs of structures)*****************************************/
69 struct WDialog
71 Widget widget;
73 /* Set by the user */
74 gboolean modal; /* type of dialog: modal or not */
75 dlg_flags_t flags; /* User flags */
76 const char *help_ctx; /* Name of the help entry */
77 const int *color; /* Color set. Unused in viewer and editor */
78 char *title; /* Title of the dialog */
80 /* Set and received by the user */
81 int ret_value; /* Result of dlg_run() */
83 /* Internal flags */
84 gboolean fullscreen; /* Parents dialogs don't need refresh */
85 gboolean winch_pending; /* SIGWINCH signal has been got. Resize dialog after rise */
86 int mouse_status; /* For the autorepeat status of the mouse */
88 /* Internal variables */
89 GList *widgets; /* widgets list */
90 GList *current; /* Currently active widget */
91 unsigned long widget_id; /* maximum id of all widgets */
92 void *data; /* Data can be passed to dialog */
93 char *event_group; /* Name of event group for this dialog */
95 dlg_shortcut_str get_shortcut; /* Shortcut string */
96 dlg_title_str get_title; /* useless for modal dialogs */
99 /*** global variables defined in .c file *********************************************************/
101 /* Color styles for normal and error dialogs */
102 extern dlg_colors_t dialog_colors;
103 extern dlg_colors_t alarm_colors;
104 extern dlg_colors_t listbox_colors;
106 extern GList *top_dlg;
108 /* A hook list for idle events */
109 extern hook_t *idle_hook;
111 extern int fast_refresh;
112 extern int mouse_close_dialog;
114 extern const global_keymap_t *dialog_map;
116 /*** declarations of public functions ************************************************************/
118 /* Creates a dialog head */
119 WDialog *dlg_create (gboolean modal, int y1, int x1, int lines, int cols,
120 const int *colors, widget_cb_fn callback, widget_mouse_cb_fn mouse_callback,
121 const char *help_ctx, const char *title, dlg_flags_t flags);
123 void dlg_set_default_colors (void);
125 unsigned long add_widget_autopos (WDialog * dest, void *w, widget_pos_flags_t pos_flags,
126 const void *before);
127 unsigned long add_widget (WDialog * dest, void *w);
128 unsigned long add_widget_before (WDialog * h, void *w, void *before);
129 void del_widget (void *w);
131 /* sets size of dialog, leaving positioning to automatic mehtods
132 according to dialog flags */
133 void dlg_set_size (WDialog * h, int lines, int cols);
134 /* this function allows to set dialog position */
135 void dlg_set_position (WDialog * h, int y1, int x1, int y2, int x2);
137 void dlg_init (WDialog * h);
138 int dlg_run (WDialog * d);
139 void dlg_destroy (WDialog * h);
141 void dlg_run_done (WDialog * h);
142 void dlg_save_history (WDialog * h);
143 void dlg_process_event (WDialog * h, int key, Gpm_Event * event);
145 char *dlg_get_title (const WDialog * h, size_t len);
147 void dlg_redraw (WDialog * h);
149 void dlg_broadcast_msg (WDialog * h, widget_msg_t message);
151 /* Default callback for dialogs */
152 cb_ret_t dlg_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data);
154 /* Default paint routine for dialogs */
155 void dlg_default_repaint (WDialog * h);
157 void dlg_erase (WDialog * h);
158 void dlg_stop (WDialog * h);
160 /* Widget selection */
161 void dlg_select_widget (void *w);
162 void dlg_set_top_widget (void *w);
163 void dlg_set_bottom_widget (void *w);
164 void dlg_one_up (WDialog * h);
165 void dlg_one_down (WDialog * h);
166 gboolean dlg_focus (WDialog * h);
167 Widget *find_widget_type (const WDialog * h, widget_cb_fn callback);
168 Widget *dlg_find_by_id (const WDialog * h, unsigned long id);
169 void dlg_select_by_id (const WDialog * h, unsigned long id);
171 /* Redraw all dialogs */
172 void do_refresh (void);
174 /* Used in load_prompt() */
175 void update_cursor (WDialog * h);
177 /* --------------------------------------------------------------------------------------------- */
178 /*** inline functions ****************************************************************************/
179 /* --------------------------------------------------------------------------------------------- */
181 static inline unsigned long
182 dlg_get_current_widget_id (const WDialog * h)
184 return WIDGET (h->current->data)->id;
187 /* --------------------------------------------------------------------------------------------- */
189 #endif /* MC__DIALOG_H */