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 #define CONST_DIALOG(x) ((const WDialog *) (x))
22
23 /* Common return values */
24 /* ATTENTION: avoid overlapping with FileProgressStatus values */
25 #define B_EXIT 0
26 #define B_CANCEL 1
27 #define B_ENTER 2
28 #define B_HELP 3
29 #define B_USER 100
30
31 /*** enums ***************************************************************************************/
32
33 /* Dialog color constants */
34 typedef enum
35 {
36 DLG_COLOR_NORMAL,
37 DLG_COLOR_FOCUS,
38 DLG_COLOR_HOT_NORMAL,
39 DLG_COLOR_HOT_FOCUS,
40 DLG_COLOR_SELECTED_NORMAL,
41 DLG_COLOR_SELECTED_FOCUS,
42 DLG_COLOR_TITLE,
43 DLG_COLOR_FRAME,
44 DLG_COLOR_COUNT
45 } dlg_colors_enum_t;
46
47 /*** typedefs(not structures) ********************************************************************/
48
49 typedef struct WDialog WDialog;
50
51 /* get string representation of shortcut assigned with command */
52 /* as menu is a widget of dialog, ask dialog about shortcut string */
53 typedef char *(*dlg_shortcut_str) (long command);
54
55 /* get dialog name to show in dialog list */
56 typedef char *(*dlg_title_str) (const WDialog *h, const ssize_t width);
57
58 typedef int dlg_colors_t[DLG_COLOR_COUNT];
59
60 /*** structures declarations (and typedefs of structures)*****************************************/
61
62 struct WDialog
63 {
64 WGroup group; // base class
65
66 // Set by the user
67 gboolean compact; // Suppress spaces around the frame
68 const char *help_ctx; // Name of the help entry
69 const int *colors; // Color set. Unused in viewer and editor
70
71 // Set and received by the user
72 int ret_value; // Result of dlg_run()
73
74 // Internal variables
75 char *event_group; // Name of event group for this dialog
76 Widget *bg; // WFrame or WBackground
77
78 // Data can be passed to dialog
79 union
80 {
81 void *p;
82 int i;
83 } data;
84
85 dlg_shortcut_str get_shortcut; // Shortcut string
86 dlg_title_str get_title; // useless for modal dialogs
87 };
88
89 /*** global variables defined in .c file *********************************************************/
90
91 /* Color styles for normal and error dialogs */
92 extern dlg_colors_t dialog_colors;
93 extern dlg_colors_t alarm_colors;
94 extern dlg_colors_t listbox_colors;
95 extern dlg_colors_t help_colors;
96
97 /* A hook list for idle events */
98 extern hook_t *idle_hook;
99
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, const int *colors,
109 widget_cb_fn callback, widget_mouse_cb_fn mouse_callback, const char *help_ctx,
110 const char *title);
111
112 void dlg_set_default_colors (void);
113
114 void dlg_init (WDialog *h);
115 int dlg_run (WDialog *d);
116
117 void dlg_run_done (WDialog *h);
118 void dlg_save_history (WDialog *h);
119 void dlg_process_event (WDialog *h, int key, Gpm_Event *event);
120
121 char *dlg_get_title (const WDialog *h, const ssize_t width);
122
123 /* Default callbacks for dialogs */
124 cb_ret_t dlg_default_callback (Widget *w, Widget *sender, widget_msg_t msg, int parm, void *data);
125 void dlg_default_mouse_callback (Widget *w, mouse_msg_t msg, mouse_event_t *event);
126
127 void dlg_close (WDialog *h);
128
129 /* --------------------------------------------------------------------------------------------- */
130 /*** inline functions ****************************************************************************/
131 /* --------------------------------------------------------------------------------------------- */
132
133 #endif