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 */
17 #include "lib/tty/mouse.h" /* mouse_h */
19 /*** defined constants ***************************************************************************/
21 /* Common return values */
28 /*** enums ***************************************************************************************/
33 DLG_INIT
= 0, /* Initialize dialog */
34 DLG_IDLE
= 1, /* The idle state is active */
35 DLG_DRAW
= 2, /* Draw dialog on screen */
36 DLG_FOCUS
= 3, /* A widget has got focus */
37 DLG_UNFOCUS
= 4, /* A widget has been unfocused */
38 DLG_RESIZE
= 5, /* Window size has changed */
39 DLG_KEY
= 6, /* Key before sending to widget */
40 DLG_HOTKEY_HANDLED
= 7, /* A widget has got the hotkey */
41 DLG_POST_KEY
= 8, /* The key has been handled */
42 DLG_UNHANDLED_KEY
= 9, /* Key that no widget handled */
43 DLG_ACTION
= 10, /* State of check- and radioboxes has changed
44 * and listbox current entry has changed */
45 DLG_VALIDATE
= 11, /* Dialog is to be closed */
46 DLG_END
= 12 /* Shut down dialog */
49 /* Flags for create_dlg */
52 DLG_WANT_TAB
= (1 << 4), /* Should the tab key be sent to the dialog? */
53 DLG_WANT_IDLE
= (1 << 3), /* Dialog wants idle events */
54 DLG_COMPACT
= (1 << 2), /* Suppress spaces around the frame */
55 DLG_TRYUP
= (1 << 1), /* Try to move two lines up the dialog */
56 DLG_CENTER
= (1 << 0), /* Center the dialog */
57 DLG_NONE
= 0 /* No options */
63 DLG_CONSTRUCT
= 0, /* Dialog has been constructed but not run yet */
64 DLG_ACTIVE
= 1, /* Dialog is visible and active */
65 DLG_SUSPENDED
= 2, /* Dialog is suspended */
66 DLG_CLOSED
= 3 /* Dialog is closed */
69 /* Dialog color constants */
80 /*** typedefs(not structures) ********************************************************************/
82 /* get string representation of shortcut assigned with command */
83 /* as menu is a widget of dialog, ask dialog about shortcut string */
84 typedef char *(*dlg_shortcut_str
) (unsigned long command
);
86 /* get dialog name to show in dialog list */
87 typedef char *(*dlg_title_str
) (const Dlg_head
* h
, size_t len
);
89 typedef int dlg_colors_t
[DLG_COLOR_COUNT
];
92 typedef cb_ret_t (*dlg_cb_fn
) (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
);
94 /* menu command execution */
95 typedef cb_ret_t (*menu_exec_fn
) (int command
);
97 /*** structures declarations (and typedefs of structures)*****************************************/
103 /* Set by the user */
104 gboolean modal
; /* type of dialog: modal or not */
105 dlg_flags_t flags
; /* User flags */
106 const char *help_ctx
; /* Name of the help entry */
107 dlg_colors_t color
; /* Color set. Unused in viewer and editor */
108 char *title
; /* Title of the dialog */
110 /* Set and received by the user */
111 int ret_value
; /* Result of run_dlg() */
115 gboolean fullscreen
; /* Parents dialogs don't need refresh */
116 gboolean winch_pending
; /* SIGWINCH signal has been got. Resize dialog after rise */
117 int mouse_status
; /* For the autorepeat status of the mouse */
119 /* Internal variables */
120 GList
*widgets
; /* widgets list */
121 GList
*current
; /* Curently active widget */
122 unsigned long widget_id
; /* maximum id of all widgets */
123 void *data
; /* Data can be passed to dialog */
124 char *event_group
; /* Name of event group for this dialog */
127 dlg_shortcut_str get_shortcut
; /* Shortcut string */
128 dlg_title_str get_title
; /* useless for modal dialogs */
131 /*** global variables defined in .c file *********************************************************/
133 /* Color styles for normal and error dialogs */
134 extern dlg_colors_t dialog_colors
;
135 extern dlg_colors_t alarm_colors
;
137 extern GList
*top_dlg
;
139 /* A hook list for idle events */
140 extern hook_t
*idle_hook
;
142 extern int fast_refresh
;
143 extern int mouse_close_dialog
;
145 extern const global_keymap_t
*dialog_map
;
147 /*** declarations of public functions ************************************************************/
149 /* draw box in window */
150 void draw_box (const Dlg_head
* h
, int y
, int x
, int ys
, int xs
, gboolean single
);
152 /* Creates a dialog head */
153 Dlg_head
*create_dlg (gboolean modal
, int y1
, int x1
, int lines
, int cols
,
154 const int *colors
, dlg_cb_fn callback
, mouse_h mouse_handler
,
155 const char *help_ctx
, const char *title
, dlg_flags_t flags
);
157 void dlg_set_default_colors (void);
159 unsigned long add_widget_autopos (Dlg_head
* dest
, void *w
, widget_pos_flags_t pos_flags
,
161 unsigned long add_widget (Dlg_head
* dest
, void *w
);
162 unsigned long add_widget_before (Dlg_head
* h
, void *w
, void *before
);
163 void del_widget (void *w
);
165 /* sets size of dialog, leaving positioning to automatic mehtods
166 according to dialog flags */
167 void dlg_set_size (Dlg_head
* h
, int lines
, int cols
);
168 /* this function allows to set dialog position */
169 void dlg_set_position (Dlg_head
* h
, int y1
, int x1
, int y2
, int x2
);
171 void init_dlg (Dlg_head
* h
);
172 int run_dlg (Dlg_head
* d
);
173 void destroy_dlg (Dlg_head
* h
);
175 void dlg_run_done (Dlg_head
* h
);
176 void dlg_save_history (Dlg_head
* h
);
177 void dlg_process_event (Dlg_head
* h
, int key
, Gpm_Event
* event
);
179 char *dlg_get_title (const Dlg_head
* h
, size_t len
);
181 /* To activate/deactivate the idle message generation */
182 void set_idle_proc (Dlg_head
* d
, int enable
);
184 void dlg_redraw (Dlg_head
* h
);
186 void dlg_broadcast_msg (Dlg_head
* h
, widget_msg_t message
);
188 /* Default callback for dialogs */
189 cb_ret_t
default_dlg_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
);
191 /* Default paint routine for dialogs */
192 void common_dialog_repaint (Dlg_head
* h
);
194 void dlg_replace_widget (Widget
* old
, Widget
* new);
195 int dlg_overlap (Widget
* a
, Widget
* b
);
196 void dlg_erase (Dlg_head
* h
);
197 void dlg_stop (Dlg_head
* h
);
199 /* Widget selection */
200 void dlg_select_widget (void *w
);
201 void dlg_set_top_widget (void *w
);
202 void dlg_one_up (Dlg_head
* h
);
203 void dlg_one_down (Dlg_head
* h
);
204 gboolean
dlg_focus (Dlg_head
* h
);
205 Widget
*find_widget_type (const Dlg_head
* h
, widget_cb_fn callback
);
206 Widget
*dlg_find_by_id (const Dlg_head
* h
, unsigned long id
);
207 void dlg_select_by_id (const Dlg_head
* h
, unsigned long id
);
209 /* Redraw all dialogs */
210 void do_refresh (void);
212 /* Used in load_prompt() */
213 void update_cursor (Dlg_head
* h
);
215 /*** inline functions ****************************************************************************/
217 /* Return TRUE if the widget is active, FALSE otherwise */
218 static inline gboolean
219 dlg_widget_active (void *w
)
221 return (w
== WIDGET (w
)->owner
->current
->data
);
224 /* --------------------------------------------------------------------------------------------- */
226 static inline unsigned long
227 dlg_get_current_widget_id (const struct Dlg_head
*h
)
229 return WIDGET (h
->current
->data
)->id
;
232 #endif /* MC__DIALOG_H */