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 /*** defined constants ***************************************************************************/
20 /* Common return values */
27 #define dlg_move(h, _y, _x) tty_gotoyx (((Dlg_head *)(h))->y + (_y), ((Dlg_head *)(h))->x + (_x))
29 /*** enums ***************************************************************************************/
34 DLG_INIT
= 0, /* Initialize dialog */
35 DLG_IDLE
= 1, /* The idle state is active */
36 DLG_DRAW
= 2, /* Draw dialog on screen */
37 DLG_FOCUS
= 3, /* A widget has got focus */
38 DLG_UNFOCUS
= 4, /* A widget has been unfocused */
39 DLG_RESIZE
= 5, /* Window size has changed */
40 DLG_KEY
= 6, /* Key before sending to widget */
41 DLG_HOTKEY_HANDLED
= 7, /* A widget has got the hotkey */
42 DLG_POST_KEY
= 8, /* The key has been handled */
43 DLG_UNHANDLED_KEY
= 9, /* Key that no widget handled */
44 DLG_ACTION
= 10, /* State of check- and radioboxes has changed
45 * and listbox current entry has changed */
46 DLG_VALIDATE
= 11, /* Dialog is to be closed */
47 DLG_END
= 12 /* Shut down dialog */
50 /* Flags for create_dlg */
53 DLG_REVERSE
= (1 << 5), /* Tab order is opposite to the add order */
54 DLG_WANT_TAB
= (1 << 4), /* Should the tab key be sent to the dialog? */
55 DLG_WANT_IDLE
= (1 << 3), /* Dialog wants idle events */
56 DLG_COMPACT
= (1 << 2), /* Suppress spaces around the frame */
57 DLG_TRYUP
= (1 << 1), /* Try to move two lines up the dialog */
58 DLG_CENTER
= (1 << 0), /* Center the dialog */
59 DLG_NONE
= 0 /* No options */
65 DLG_ACTIVE
= 0, /* Dialog is visible and active */
66 DLG_SUSPENDED
= 1, /* Dialog is suspended */
67 DLG_CLOSED
= 2 /* 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)*****************************************/
102 /* Set by the user */
103 gboolean modal
; /* type of dialog: modal or not */
104 dlg_flags_t flags
; /* User flags */
105 const char *help_ctx
; /* Name of the help entry */
106 dlg_colors_t color
; /* Color set. Unused in viewer and editor */
107 char *title
; /* Title of the dialog */
109 /* Set and received by the user */
110 int ret_value
; /* Result of run_dlg() */
113 int x
, y
; /* Position relative to screen origin */
114 int cols
, lines
; /* Width and height of the window */
118 gboolean fullscreen
; /* Parents dialogs don't need refresh */
119 gboolean winch_pending
; /* SIGWINCH signal has been got. Resize dialog after rise */
120 int mouse_status
; /* For the autorepeat status of the mouse */
122 /* Internal variables */
123 GList
*widgets
; /* widgets list */
124 GList
*current
; /* Curently active widget */
125 void *data
; /* Data can be passed to dialog */
126 char *event_group
; /* Name of event group for this dialog */
129 dlg_shortcut_str get_shortcut
; /* Shortcut string */
130 dlg_title_str get_title
; /* useless for modal dialogs */
133 /*** global variables defined in .c file *********************************************************/
135 /* Color styles for normal and error dialogs */
136 extern dlg_colors_t dialog_colors
;
137 extern dlg_colors_t alarm_colors
;
139 extern GList
*top_dlg
;
141 /* A hook list for idle events */
142 extern hook_t
*idle_hook
;
144 extern int fast_refresh
;
145 extern int mouse_close_dialog
;
147 extern const global_keymap_t
*dialog_map
;
149 /*** declarations of public functions ************************************************************/
151 /* draw box in window */
152 void draw_box (Dlg_head
* h
, int y
, int x
, int ys
, int xs
, gboolean single
);
154 /* Creates a dialog head */
155 Dlg_head
*create_dlg (gboolean modal
, int y1
, int x1
, int lines
, int cols
,
156 const int *colors
, dlg_cb_fn callback
,
157 const char *help_ctx
, const char *title
, dlg_flags_t flags
);
159 void dlg_set_default_colors (void);
161 int add_widget_autopos (Dlg_head
* dest
, void *w
, widget_pos_flags_t pos_flags
);
162 int add_widget (Dlg_head
* dest
, void *w
);
164 /* sets size of dialog, leaving positioning to automatic mehtods
165 according to dialog flags */
166 void dlg_set_size (Dlg_head
* h
, int lines
, int cols
);
167 /* this function allows to set dialog position */
168 void dlg_set_position (Dlg_head
* h
, int y1
, int x1
, int y2
, int x2
);
170 void init_dlg (Dlg_head
* h
);
171 int run_dlg (Dlg_head
* d
);
172 void destroy_dlg (Dlg_head
* h
);
174 void dlg_run_done (Dlg_head
* h
);
175 void dlg_save_history (Dlg_head
* h
);
176 void dlg_process_event (Dlg_head
* h
, int key
, Gpm_Event
* event
);
178 char *dlg_get_title (const Dlg_head
* h
, size_t len
);
180 /* To activate/deactivate the idle message generation */
181 void set_idle_proc (Dlg_head
* d
, int enable
);
183 void dlg_redraw (Dlg_head
* h
);
185 void dlg_broadcast_msg (Dlg_head
* h
, widget_msg_t message
, gboolean reverse
);
187 /* Default callback for dialogs */
188 cb_ret_t
default_dlg_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
);
190 /* Default paint routine for dialogs */
191 void common_dialog_repaint (Dlg_head
* h
);
193 void dlg_replace_widget (Widget
* old
, Widget
* new);
194 int dlg_overlap (Widget
* a
, Widget
* b
);
195 void dlg_erase (Dlg_head
* h
);
196 void dlg_stop (Dlg_head
* h
);
198 /* Widget selection */
199 void dlg_select_widget (void *widget
);
200 void dlg_one_up (Dlg_head
* h
);
201 void dlg_one_down (Dlg_head
* h
);
202 int dlg_focus (Dlg_head
* h
);
203 Widget
*find_widget_type (const Dlg_head
* h
, callback_fn callback
);
204 Widget
*dlg_find_by_id (const Dlg_head
* h
, unsigned int id
);
205 void dlg_select_by_id (const Dlg_head
* h
, unsigned int id
);
207 /* Redraw all dialogs */
208 void do_refresh (void);
210 /* Used in load_prompt() */
211 void update_cursor (Dlg_head
* h
);
213 /*** inline functions ****************************************************************************/
215 /* Return TRUE if the widget is active, FALSE otherwise */
216 static inline gboolean
217 dlg_widget_active (void *w
)
219 Widget
*w1
= (Widget
*) w
;
220 return ((Widget
*) w1
->owner
->current
->data
== w1
);
224 static inline unsigned int
225 dlg_get_current_widget_id (const struct Dlg_head
*h
)
227 return ((Widget
*) h
->current
->data
)->id
;
230 #endif /* MC__DIALOG_H */