uprava merge
[midnight-commander/osp/novacja3.git] / lib / widget / dialog.h
blobdb2cdf3531be583c656dca3ba41679f7b2a9a0a0
1 /*
2 Dialog box features module for the Midnight Commander
3 */
5 /** \file dialog.h
6 * \brief Header: dialog box features module
7 */
9 #ifndef MC__DIALOG_H
10 #define MC__DIALOG_H
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 */
21 #define B_EXIT 0
22 #define B_CANCEL 1
23 #define B_ENTER 2
24 #define B_HELP 3
25 #define B_USER 100
27 #define dlg_move(h, _y, _x) tty_gotoyx (((Dlg_head *)(h))->y + _y, ((Dlg_head *)(h))->x + _x)
29 /*** enums ***************************************************************************************/
31 /* Dialog messages */
32 typedef enum
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 */
48 } dlg_msg_t;
50 /* Flags for create_dlg */
51 typedef enum
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 */
60 } dlg_flags_t;
62 /* Dialog state */
63 typedef enum
65 DLG_CONSTRUCT = 0, /* DIalog has been constructed but bot run yet */
66 DLG_ACTIVE = 1, /* Dialog is visible and active */
67 DLG_SUSPENDED = 2, /* Dialog is suspended */
68 DLG_CLOSED = 3 /* Dialog is closed */
69 } dlg_state_t;
71 /* Dialog color constants */
72 typedef enum
74 DLG_COLOR_NORMAL,
75 DLG_COLOR_FOCUS,
76 DLG_COLOR_HOT_NORMAL,
77 DLG_COLOR_HOT_FOCUS,
78 DLG_COLOR_TITLE,
79 DLG_COLOR_COUNT
80 } dlg_colors_enum_t;
82 /*** typedefs(not structures) ********************************************************************/
84 /* get string representation of shortcut assigned with command */
85 /* as menu is a widget of dialog, ask dialog about shortcut string */
86 typedef char *(*dlg_shortcut_str) (unsigned long command);
88 /* get dialog name to show in dialog list */
89 typedef char *(*dlg_title_str) (const Dlg_head * h, size_t len);
91 typedef int dlg_colors_t[DLG_COLOR_COUNT];
93 /* Dialog callback */
94 typedef cb_ret_t (*dlg_cb_fn) (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data);
96 /* menu command execution */
97 typedef cb_ret_t (*menu_exec_fn) (int command);
99 /*** structures declarations (and typedefs of structures)*****************************************/
101 struct Dlg_head
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() */
113 /* Geometry */
114 int x, y; /* Position relative to screen origin */
115 int cols, lines; /* Width and height of the window */
117 /* Internal flags */
118 dlg_state_t state;
119 gboolean fullscreen; /* Parents dialogs don't need refresh */
120 gboolean winch_pending; /* SIGWINCH signal has been got. Resize dialog after rise */
121 int mouse_status; /* For the autorepeat status of the mouse */
123 /* Internal variables */
124 GList *widgets; /* widgets list */
125 GList *current; /* Curently active widget */
126 unsigned long widget_id; /* maximum id of all widgets */
127 void *data; /* Data can be passed to dialog */
128 char *event_group; /* Name of event group for this dialog */
130 dlg_cb_fn callback;
131 dlg_shortcut_str get_shortcut; /* Shortcut string */
132 dlg_title_str get_title; /* useless for modal dialogs */
135 /*** global variables defined in .c file *********************************************************/
137 /* Color styles for normal and error dialogs */
138 extern dlg_colors_t dialog_colors;
139 extern dlg_colors_t alarm_colors;
141 extern GList *top_dlg;
143 /* A hook list for idle events */
144 extern hook_t *idle_hook;
146 extern int fast_refresh;
147 extern int mouse_close_dialog;
149 extern const global_keymap_t *dialog_map;
151 /*** declarations of public functions ************************************************************/
153 /* draw box in window */
154 void draw_box (Dlg_head * h, int y, int x, int ys, int xs, gboolean single);
156 /* Creates a dialog head */
157 Dlg_head *create_dlg (gboolean modal, int y1, int x1, int lines, int cols,
158 const int *colors, dlg_cb_fn callback,
159 const char *help_ctx, const char *title, dlg_flags_t flags);
161 void dlg_set_default_colors (void);
163 unsigned long add_widget_autopos (Dlg_head * dest, void *w, widget_pos_flags_t pos_flags,
164 const void *before);
165 unsigned long add_widget (Dlg_head * dest, void *w);
166 unsigned long add_widget_before (Dlg_head * h, void *w, void *before);
167 void del_widget (void *w);
169 /* sets size of dialog, leaving positioning to automatic mehtods
170 according to dialog flags */
171 void dlg_set_size (Dlg_head * h, int lines, int cols);
172 /* this function allows to set dialog position */
173 void dlg_set_position (Dlg_head * h, int y1, int x1, int y2, int x2);
175 void init_dlg (Dlg_head * h);
176 int run_dlg (Dlg_head * d);
177 void destroy_dlg (Dlg_head * h);
179 void dlg_run_done (Dlg_head * h);
180 void dlg_save_history (Dlg_head * h);
181 void dlg_process_event (Dlg_head * h, int key, Gpm_Event * event);
183 char *dlg_get_title (const Dlg_head * h, size_t len);
185 /* To activate/deactivate the idle message generation */
186 void set_idle_proc (Dlg_head * d, int enable);
188 void dlg_redraw (Dlg_head * h);
190 void dlg_broadcast_msg (Dlg_head * h, widget_msg_t message, gboolean reverse);
192 /* Default callback for dialogs */
193 cb_ret_t default_dlg_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data);
195 /* Default paint routine for dialogs */
196 void common_dialog_repaint (Dlg_head * h);
198 void dlg_replace_widget (Widget * old, Widget * new);
199 int dlg_overlap (Widget * a, Widget * b);
200 void dlg_erase (Dlg_head * h);
201 void dlg_stop (Dlg_head * h);
203 /* Widget selection */
204 void dlg_select_widget (void *w);
205 void dlg_set_top_widget (void *w);
206 void dlg_one_up (Dlg_head * h);
207 void dlg_one_down (Dlg_head * h);
208 gboolean dlg_focus (Dlg_head * h);
209 Widget *find_widget_type (const Dlg_head * h, callback_fn callback);
210 Widget *dlg_find_by_id (const Dlg_head * h, unsigned long id);
211 void dlg_select_by_id (const Dlg_head * h, unsigned long id);
213 /* Redraw all dialogs */
214 void do_refresh (void);
216 /* Used in load_prompt() */
217 void update_cursor (Dlg_head * h);
219 /*** inline functions ****************************************************************************/
221 /* Return TRUE if the widget is active, FALSE otherwise */
222 static inline gboolean
223 dlg_widget_active (void *w)
225 Widget *w1 = (Widget *) w;
226 return ((Widget *) w1->owner->current->data == w1);
229 /* --------------------------------------------------------------------------------------------- */
231 static inline unsigned long
232 dlg_get_current_widget_id (const struct Dlg_head *h)
234 return ((Widget *) h->current->data)->id;
237 #endif /* MC__DIALOG_H */