2 Dialog box features module for the Midnight Commander
6 * \brief Header: dialog box features module
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 */
30 /*** enums ***************************************************************************************/
32 /* Flags for dlg_create */
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? */
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 */
51 /* Dialog color constants */
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
) (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)*****************************************/
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 const int *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 dlg_run() */
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
; /* Currently 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
;
114 extern dlg_colors_t listbox_colors
;
116 extern GList
*top_dlg
;
118 /* A hook list for idle events */
119 extern hook_t
*idle_hook
;
121 extern int fast_refresh
;
122 extern int mouse_close_dialog
;
124 extern const global_keymap_t
*dialog_map
;
126 /*** declarations of public functions ************************************************************/
128 /* Creates a dialog head */
129 WDialog
*dlg_create (gboolean modal
, int y1
, int x1
, int lines
, int cols
,
130 const int *colors
, widget_cb_fn callback
, widget_mouse_cb_fn mouse_callback
,
131 const char *help_ctx
, const char *title
, dlg_flags_t flags
);
133 void dlg_set_default_colors (void);
135 unsigned long add_widget_autopos (WDialog
* dest
, void *w
, widget_pos_flags_t pos_flags
,
137 unsigned long add_widget (WDialog
* dest
, void *w
);
138 unsigned long add_widget_before (WDialog
* h
, void *w
, void *before
);
139 void del_widget (void *w
);
141 /* sets size of dialog, leaving positioning to automatic mehtods
142 according to dialog flags */
143 void dlg_set_size (WDialog
* h
, int lines
, int cols
);
144 /* this function allows to set dialog position */
145 void dlg_set_position (WDialog
* h
, int y1
, int x1
, int y2
, int x2
);
147 void dlg_init (WDialog
* h
);
148 int dlg_run (WDialog
* d
);
149 void dlg_destroy (WDialog
* h
);
151 void dlg_run_done (WDialog
* h
);
152 void dlg_save_history (WDialog
* h
);
153 void dlg_process_event (WDialog
* h
, int key
, Gpm_Event
* event
);
155 char *dlg_get_title (const WDialog
* h
, size_t len
);
157 void dlg_redraw (WDialog
* h
);
159 void dlg_broadcast_msg (WDialog
* h
, widget_msg_t message
);
161 /* Default callback for dialogs */
162 cb_ret_t
dlg_default_callback (Widget
* w
, Widget
* sender
, widget_msg_t msg
, int parm
, void *data
);
164 /* Default paint routine for dialogs */
165 void dlg_default_repaint (WDialog
* h
);
167 void dlg_erase (WDialog
* h
);
168 void dlg_stop (WDialog
* h
);
170 /* Widget selection */
171 void dlg_select_widget (void *w
);
172 void dlg_set_top_widget (void *w
);
173 void dlg_set_bottom_widget (void *w
);
174 void dlg_one_up (WDialog
* h
);
175 void dlg_one_down (WDialog
* h
);
176 gboolean
dlg_focus (WDialog
* h
);
177 Widget
*find_widget_type (const WDialog
* h
, widget_cb_fn callback
);
178 Widget
*dlg_find_by_id (const WDialog
* h
, unsigned long id
);
179 void dlg_select_by_id (const WDialog
* h
, unsigned long id
);
181 /* Redraw all dialogs */
182 void do_refresh (void);
184 /* Used in load_prompt() */
185 void update_cursor (WDialog
* h
);
187 /* --------------------------------------------------------------------------------------------- */
188 /*** inline functions ****************************************************************************/
189 /* --------------------------------------------------------------------------------------------- */
191 static inline unsigned long
192 dlg_get_current_widget_id (const WDialog
* h
)
194 return WIDGET (h
->current
->data
)->id
;
197 /* --------------------------------------------------------------------------------------------- */
199 #endif /* MC__DIALOG_H */