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 #define dlg_move(h, _y, _x) tty_gotoyx (((Dlg_head *)(h))->y + (_y), ((Dlg_head *)(h))->x + (_x))
30 /*** enums ***************************************************************************************/
35 DLG_INIT
= 0, /* Initialize dialog */
36 DLG_IDLE
= 1, /* The idle state is active */
37 DLG_DRAW
= 2, /* Draw dialog on screen */
38 DLG_FOCUS
= 3, /* A widget has got focus */
39 DLG_UNFOCUS
= 4, /* A widget has been unfocused */
40 DLG_RESIZE
= 5, /* Window size has changed */
41 DLG_KEY
= 6, /* Key before sending to widget */
42 DLG_HOTKEY_HANDLED
= 7, /* A widget has got the hotkey */
43 DLG_POST_KEY
= 8, /* The key has been handled */
44 DLG_UNHANDLED_KEY
= 9, /* Key that no widget handled */
45 DLG_ACTION
= 10, /* State of check- and radioboxes has changed
46 * and listbox current entry has changed */
47 DLG_VALIDATE
= 11, /* Dialog is to be closed */
48 DLG_END
= 12 /* Shut down dialog */
51 /* Flags for create_dlg */
54 DLG_REVERSE
= (1 << 5), /* Tab order is opposite to the add order */
55 DLG_WANT_TAB
= (1 << 4), /* Should the tab key be sent to the dialog? */
56 DLG_WANT_IDLE
= (1 << 3), /* Dialog wants idle events */
57 DLG_COMPACT
= (1 << 2), /* Suppress spaces around the frame */
58 DLG_TRYUP
= (1 << 1), /* Try to move two lines up the dialog */
59 DLG_CENTER
= (1 << 0), /* Center the dialog */
60 DLG_NONE
= 0 /* No options */
66 DLG_CONSTRUCT
= 0, /* Dialog has been constructed but not run yet */
67 DLG_ACTIVE
= 1, /* Dialog is visible and active */
68 DLG_SUSPENDED
= 2, /* Dialog is suspended */
69 DLG_CLOSED
= 3 /* Dialog is closed */
72 /* Dialog color constants */
83 /*** typedefs(not structures) ********************************************************************/
85 /* get string representation of shortcut assigned with command */
86 /* as menu is a widget of dialog, ask dialog about shortcut string */
87 typedef char *(*dlg_shortcut_str
) (unsigned long command
);
89 /* get dialog name to show in dialog list */
90 typedef char *(*dlg_title_str
) (const Dlg_head
* h
, size_t len
);
92 typedef int dlg_colors_t
[DLG_COLOR_COUNT
];
95 typedef cb_ret_t (*dlg_cb_fn
) (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
);
97 /* menu command execution */
98 typedef cb_ret_t (*menu_exec_fn
) (int command
);
100 /*** 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() */
115 int x
, y
; /* Position relative to screen origin */
116 int cols
, lines
; /* Width and height of the window */
120 gboolean fullscreen
; /* Parents dialogs don't need refresh */
121 gboolean winch_pending
; /* SIGWINCH signal has been got. Resize dialog after rise */
122 int mouse_status
; /* For the autorepeat status of the mouse */
124 /* Internal variables */
125 GList
*widgets
; /* widgets list */
126 GList
*current
; /* Curently active widget */
127 unsigned long widget_id
; /* maximum id of all widgets */
128 void *data
; /* Data can be passed to dialog */
129 char *event_group
; /* Name of event group for this dialog */
133 dlg_shortcut_str get_shortcut
; /* Shortcut string */
134 dlg_title_str get_title
; /* useless for modal dialogs */
137 /*** global variables defined in .c file *********************************************************/
139 /* Color styles for normal and error dialogs */
140 extern dlg_colors_t dialog_colors
;
141 extern dlg_colors_t alarm_colors
;
143 extern GList
*top_dlg
;
145 /* A hook list for idle events */
146 extern hook_t
*idle_hook
;
148 extern int fast_refresh
;
149 extern int mouse_close_dialog
;
151 extern const global_keymap_t
*dialog_map
;
153 /*** declarations of public functions ************************************************************/
155 /* draw box in window */
156 void draw_box (Dlg_head
* h
, int y
, int x
, int ys
, int xs
, gboolean single
);
158 /* Creates a dialog head */
159 Dlg_head
*create_dlg (gboolean modal
, int y1
, int x1
, int lines
, int cols
,
160 const int *colors
, dlg_cb_fn callback
, mouse_h mouse_handler
,
161 const char *help_ctx
, const char *title
, dlg_flags_t flags
);
163 void dlg_set_default_colors (void);
165 unsigned long add_widget_autopos (Dlg_head
* dest
, void *w
, widget_pos_flags_t pos_flags
,
167 unsigned long add_widget (Dlg_head
* dest
, void *w
);
168 unsigned long add_widget_before (Dlg_head
* h
, void *w
, void *before
);
169 void del_widget (void *w
);
171 /* sets size of dialog, leaving positioning to automatic mehtods
172 according to dialog flags */
173 void dlg_set_size (Dlg_head
* h
, int lines
, int cols
);
174 /* this function allows to set dialog position */
175 void dlg_set_position (Dlg_head
* h
, int y1
, int x1
, int y2
, int x2
);
177 void init_dlg (Dlg_head
* h
);
178 int run_dlg (Dlg_head
* d
);
179 void destroy_dlg (Dlg_head
* h
);
181 void dlg_run_done (Dlg_head
* h
);
182 void dlg_save_history (Dlg_head
* h
);
183 void dlg_process_event (Dlg_head
* h
, int key
, Gpm_Event
* event
);
185 char *dlg_get_title (const Dlg_head
* h
, size_t len
);
187 /* To activate/deactivate the idle message generation */
188 void set_idle_proc (Dlg_head
* d
, int enable
);
190 void dlg_redraw (Dlg_head
* h
);
192 void dlg_broadcast_msg (Dlg_head
* h
, widget_msg_t message
, gboolean reverse
);
194 /* Default callback for dialogs */
195 cb_ret_t
default_dlg_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
);
197 /* Default paint routine for dialogs */
198 void common_dialog_repaint (Dlg_head
* h
);
200 void dlg_replace_widget (Widget
* old
, Widget
* new);
201 int dlg_overlap (Widget
* a
, Widget
* b
);
202 void dlg_erase (Dlg_head
* h
);
203 void dlg_stop (Dlg_head
* h
);
205 /* Widget selection */
206 void dlg_select_widget (void *w
);
207 void dlg_set_top_widget (void *w
);
208 void dlg_one_up (Dlg_head
* h
);
209 void dlg_one_down (Dlg_head
* h
);
210 gboolean
dlg_focus (Dlg_head
* h
);
211 Widget
*find_widget_type (const Dlg_head
* h
, callback_fn callback
);
212 Widget
*dlg_find_by_id (const Dlg_head
* h
, unsigned long id
);
213 void dlg_select_by_id (const Dlg_head
* h
, unsigned long id
);
215 /* Redraw all dialogs */
216 void do_refresh (void);
218 /* Used in load_prompt() */
219 void update_cursor (Dlg_head
* h
);
221 /*** inline functions ****************************************************************************/
223 /* Return TRUE if the widget is active, FALSE otherwise */
224 static inline gboolean
225 dlg_widget_active (void *w
)
227 Widget
*w1
= (Widget
*) w
;
228 return ((Widget
*) w1
->owner
->current
->data
== w1
);
231 /* --------------------------------------------------------------------------------------------- */
233 static inline unsigned long
234 dlg_get_current_widget_id (const struct Dlg_head
*h
)
236 return ((Widget
*) h
->current
->data
)->id
;
239 #endif /* MC__DIALOG_H */