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_COUNT
44 } dlg_colors_enum_t;
45
46 /*** typedefs(not structures) ********************************************************************/
47
48 typedef struct WDialog WDialog;
49
50 /* get string representation of shortcut assigned with command */
51 /* as menu is a widget of dialog, ask dialog about shortcut string */
52 typedef char *(*dlg_shortcut_str) (long command);
53
54 /* get dialog name to show in dialog list */
55 typedef char *(*dlg_title_str) (const WDialog *h, const ssize_t width);
56
57 typedef int dlg_colors_t[DLG_COLOR_COUNT];
58
59 /*** structures declarations (and typedefs of structures)*****************************************/
60
61 struct WDialog
62 {
63 WGroup group; // base class
64
65 // Set by the user
66 gboolean compact; // Suppress spaces around the frame
67 const char *help_ctx; // Name of the help entry
68 const int *colors; // Color set. Unused in viewer and editor
69
70 // Set and received by the user
71 int ret_value; // Result of dlg_run()
72
73 // Internal variables
74 char *event_group; // Name of event group for this dialog
75 Widget *bg; // WFrame or WBackground
76
77 // Data can be passed to dialog
78 union
79 {
80 void *p;
81 int i;
82 } data;
83
84 dlg_shortcut_str get_shortcut; // Shortcut string
85 dlg_title_str get_title; // useless for modal dialogs
86 };
87
88 /*** global variables defined in .c file *********************************************************/
89
90 /* Color styles for normal and error dialogs */
91 extern dlg_colors_t dialog_colors;
92 extern dlg_colors_t alarm_colors;
93 extern dlg_colors_t listbox_colors;
94
95 /* A hook list for idle events */
96 extern hook_t *idle_hook;
97
98 extern gboolean mouse_close_dialog;
99
100 extern const global_keymap_t *dialog_map;
101
102 /*** declarations of public functions ************************************************************/
103
104 /* Creates a dialog head */
105 WDialog *dlg_create (gboolean modal, int y1, int x1, int lines, int cols,
106 widget_pos_flags_t pos_flags, gboolean compact, const int *colors,
107 widget_cb_fn callback, widget_mouse_cb_fn mouse_callback, const char *help_ctx,
108 const char *title);
109
110 void dlg_set_default_colors (void);
111
112 void dlg_init (WDialog *h);
113 int dlg_run (WDialog *d);
114
115 void dlg_run_done (WDialog *h);
116 void dlg_save_history (WDialog *h);
117 void dlg_process_event (WDialog *h, int key, Gpm_Event *event);
118
119 char *dlg_get_title (const WDialog *h, const ssize_t width);
120
121 /* Default callbacks for dialogs */
122 cb_ret_t dlg_default_callback (Widget *w, Widget *sender, widget_msg_t msg, int parm, void *data);
123 void dlg_default_mouse_callback (Widget *w, mouse_msg_t msg, mouse_event_t *event);
124
125 void dlg_close (WDialog *h);
126
127 /* --------------------------------------------------------------------------------------------- */
128 /*** inline functions ****************************************************************************/
129 /* --------------------------------------------------------------------------------------------- */
130
131 #endif