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_REVERSE
= (1 << 5), /* Tab order is opposite to the add order */
53 DLG_WANT_TAB
= (1 << 4), /* Should the tab key be sent to the dialog? */
54 DLG_WANT_IDLE
= (1 << 3), /* Dialog wants idle events */
55 DLG_COMPACT
= (1 << 2), /* Suppress spaces around the frame */
56 DLG_TRYUP
= (1 << 1), /* Try to move two lines up the dialog */
57 DLG_CENTER
= (1 << 0), /* Center the dialog */
58 DLG_NONE
= 0 /* No options */
64 DLG_CONSTRUCT
= 0, /* Dialog has been constructed but not run yet */
65 DLG_ACTIVE
= 1, /* Dialog is visible and active */
66 DLG_SUSPENDED
= 2, /* Dialog is suspended */
67 DLG_CLOSED
= 3 /* Dialog is closed */
70 /* Dialog color constants */
81 /*** typedefs(not structures) ********************************************************************/
83 /* get string representation of shortcut assigned with command */
84 /* as menu is a widget of dialog, ask dialog about shortcut string */
85 typedef char *(*dlg_shortcut_str
) (unsigned long command
);
87 /* get dialog name to show in dialog list */
88 typedef char *(*dlg_title_str
) (const Dlg_head
* h
, size_t len
);
90 typedef int dlg_colors_t
[DLG_COLOR_COUNT
];
93 typedef cb_ret_t (*dlg_cb_fn
) (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
);
95 /* menu command execution */
96 typedef cb_ret_t (*menu_exec_fn
) (int command
);
98 /*** structures declarations (and typedefs of structures)*****************************************/
104 /* Set by the user */
105 gboolean modal
; /* type of dialog: modal or not */
106 dlg_flags_t flags
; /* User flags */
107 const char *help_ctx
; /* Name of the help entry */
108 dlg_colors_t color
; /* Color set. Unused in viewer and editor */
109 char *title
; /* Title of the dialog */
111 /* Set and received by the user */
112 int ret_value
; /* Result of run_dlg() */
116 gboolean fullscreen
; /* Parents dialogs don't need refresh */
117 gboolean winch_pending
; /* SIGWINCH signal has been got. Resize dialog after rise */
118 int mouse_status
; /* For the autorepeat status of the mouse */
120 /* Internal variables */
121 GList
*widgets
; /* widgets list */
122 GList
*current
; /* Curently active widget */
123 unsigned long widget_id
; /* maximum id of all widgets */
124 void *data
; /* Data can be passed to dialog */
125 char *event_group
; /* Name of event group for this dialog */
128 dlg_shortcut_str get_shortcut
; /* Shortcut string */
129 dlg_title_str get_title
; /* useless for modal dialogs */
132 /*** global variables defined in .c file *********************************************************/
134 /* Color styles for normal and error dialogs */
135 extern dlg_colors_t dialog_colors
;
136 extern dlg_colors_t alarm_colors
;
138 extern GList
*top_dlg
;
140 /* A hook list for idle events */
141 extern hook_t
*idle_hook
;
143 extern int fast_refresh
;
144 extern int mouse_close_dialog
;
146 extern const global_keymap_t
*dialog_map
;
148 /*** declarations of public functions ************************************************************/
150 /* draw box in window */
151 void draw_box (const Dlg_head
* h
, int y
, int x
, int ys
, int xs
, gboolean single
);
153 /* Creates a dialog head */
154 Dlg_head
*create_dlg (gboolean modal
, int y1
, int x1
, int lines
, int cols
,
155 const int *colors
, dlg_cb_fn callback
, mouse_h mouse_handler
,
156 const char *help_ctx
, const char *title
, dlg_flags_t flags
);
158 void dlg_set_default_colors (void);
160 unsigned long add_widget_autopos (Dlg_head
* dest
, void *w
, widget_pos_flags_t pos_flags
,
162 unsigned long add_widget (Dlg_head
* dest
, void *w
);
163 unsigned long add_widget_before (Dlg_head
* h
, void *w
, void *before
);
164 void del_widget (void *w
);
166 /* sets size of dialog, leaving positioning to automatic mehtods
167 according to dialog flags */
168 void dlg_set_size (Dlg_head
* h
, int lines
, int cols
);
169 /* this function allows to set dialog position */
170 void dlg_set_position (Dlg_head
* h
, int y1
, int x1
, int y2
, int x2
);
172 void init_dlg (Dlg_head
* h
);
173 int run_dlg (Dlg_head
* d
);
174 void destroy_dlg (Dlg_head
* h
);
176 void dlg_run_done (Dlg_head
* h
);
177 void dlg_save_history (Dlg_head
* h
);
178 void dlg_process_event (Dlg_head
* h
, int key
, Gpm_Event
* event
);
180 char *dlg_get_title (const Dlg_head
* h
, size_t len
);
182 /* To activate/deactivate the idle message generation */
183 void set_idle_proc (Dlg_head
* d
, int enable
);
185 void dlg_redraw (Dlg_head
* h
);
187 void dlg_broadcast_msg (Dlg_head
* h
, widget_msg_t message
, gboolean reverse
);
189 /* Default callback for dialogs */
190 cb_ret_t
default_dlg_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
);
192 /* Default paint routine for dialogs */
193 void common_dialog_repaint (Dlg_head
* h
);
195 void dlg_replace_widget (Widget
* old
, Widget
* new);
196 int dlg_overlap (Widget
* a
, Widget
* b
);
197 void dlg_erase (Dlg_head
* h
);
198 void dlg_stop (Dlg_head
* h
);
200 /* Widget selection */
201 void dlg_select_widget (void *w
);
202 void dlg_set_top_widget (void *w
);
203 void dlg_one_up (Dlg_head
* h
);
204 void dlg_one_down (Dlg_head
* h
);
205 gboolean
dlg_focus (Dlg_head
* h
);
206 Widget
*find_widget_type (const Dlg_head
* h
, callback_fn callback
);
207 Widget
*dlg_find_by_id (const Dlg_head
* h
, unsigned long id
);
208 void dlg_select_by_id (const Dlg_head
* h
, unsigned long id
);
210 /* Redraw all dialogs */
211 void do_refresh (void);
213 /* Used in load_prompt() */
214 void update_cursor (Dlg_head
* h
);
216 /*** inline functions ****************************************************************************/
218 /* Return TRUE if the widget is active, FALSE otherwise */
219 static inline gboolean
220 dlg_widget_active (void *w
)
222 return (w
== WIDGET (w
)->owner
->current
->data
);
225 /* --------------------------------------------------------------------------------------------- */
227 static inline unsigned long
228 dlg_get_current_widget_id (const struct Dlg_head
*h
)
230 return WIDGET (h
->current
->data
)->id
;
233 #endif /* MC__DIALOG_H */