configure.c: fix AX_GCC_FUNC_ATTRIBUTE detection on custom CFLAGS
[midnight-commander.git] / lib / widget / dialog.h
blobf4bc154fa0ab7f1e99b959c94fd369ca1c9da891
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 /* Dialog color constants */
33 typedef enum
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;
43 /*** typedefs(not structures) ********************************************************************/
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);
49 /* get dialog name to show in dialog list */
50 typedef char *(*dlg_title_str) (const WDialog * h, size_t len);
52 typedef int dlg_colors_t[DLG_COLOR_COUNT];
54 /* menu command execution */
55 typedef cb_ret_t (*menu_exec_fn) (int command);
57 /*** structures declarations (and typedefs of structures)*****************************************/
59 struct WDialog
61 Widget widget;
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 */
69 /* Set and received by the user */
70 int ret_value; /* Result of dlg_run() */
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 */
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 */
83 dlg_shortcut_str get_shortcut; /* Shortcut string */
84 dlg_title_str get_title; /* useless for modal dialogs */
87 /*** global variables defined in .c file *********************************************************/
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;
94 extern GList *top_dlg;
96 /* A hook list for idle events */
97 extern hook_t *idle_hook;
99 extern gboolean fast_refresh;
100 extern gboolean mouse_close_dialog;
102 extern const global_keymap_t *dialog_map;
104 /*** declarations of public functions ************************************************************/
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);
112 void dlg_set_default_colors (void);
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);
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);
126 void dlg_init (WDialog * h);
127 int dlg_run (WDialog * d);
128 void dlg_destroy (WDialog * h);
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);
134 void dlg_set_title (WDialog * h, const char *title);
135 char *dlg_get_title (const WDialog * h, size_t len);
137 void dlg_redraw (WDialog * h);
139 void dlg_broadcast_msg (WDialog * h, widget_msg_t message);
141 /* Default callback for dialogs */
142 cb_ret_t dlg_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data);
144 /* Default paint routine for dialogs */
145 void dlg_default_repaint (WDialog * h);
147 void dlg_erase (WDialog * h);
148 void dlg_stop (WDialog * h);
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);
158 /* Redraw all dialogs */
159 void do_refresh (void);
161 /* Used in load_prompt() */
162 void update_cursor (WDialog * h);
164 void dlg_set_current_widget_next (WDialog * h);
165 void dlg_set_current_widget_prev (WDialog * h);
167 GList *dlg_get_widget_next_of (GList * w);
168 GList *dlg_get_widget_prev_of (GList * w);
170 /* --------------------------------------------------------------------------------------------- */
171 /*** inline functions ****************************************************************************/
172 /* --------------------------------------------------------------------------------------------- */
174 static inline unsigned long
175 dlg_get_current_widget_id (const WDialog * h)
177 return WIDGET (h->current->data)->id;
180 /* --------------------------------------------------------------------------------------------- */
183 * Select current widget in the Dialog.
185 * @param h WDialog object
188 static inline void
189 dlg_select_current_widget (WDialog * h)
191 if (h->current != NULL)
192 widget_select (WIDGET (h->current->data));
195 /* --------------------------------------------------------------------------------------------- */
197 #endif /* MC__DIALOG_H */