Ticket #1981: configure.ac: add AM_PROG_CC_C_O as we use compiler, that accepts ...
[midnight-commander.git] / src / dialog.h
bloba31323a06bb8db8854b2e393ee46f102de145e35
1 /* Dialog box features module for the Midnight Commander
2 Copyright (C) 1994, 1995 Radek Doulik, Miguel de Icaza
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 /** \file dialog.h
20 * \brief Header: dialog box features module
23 #ifndef MC_DIALOG_H
24 #define MC_DIALOG_H
26 #include "lib/tty/mouse.h"
28 /* Common return values */
29 #define B_EXIT 0
30 #define B_CANCEL 1
31 #define B_ENTER 2
32 #define B_HELP 3
33 #define B_USER 100
35 typedef struct Widget Widget;
37 /* Widget messages */
38 typedef enum {
39 WIDGET_INIT, /* Initialize widget */
40 WIDGET_FOCUS, /* Draw widget in focused state */
41 WIDGET_UNFOCUS, /* Draw widget in unfocused state */
42 WIDGET_DRAW, /* Sent to widget to draw themselves */
43 WIDGET_KEY, /* Sent to widgets on key press */
44 WIDGET_HOTKEY, /* Sent to widget to catch preprocess key */
45 WIDGET_COMMAND, /* Send to widget to handle command */
46 WIDGET_DESTROY, /* Sent to widget at destruction time */
47 WIDGET_CURSOR, /* Sent to widget to position the cursor */
48 WIDGET_IDLE, /* Sent to widgets with options & W_WANT_IDLE*/
49 WIDGET_RESIZED /* Sent after a widget has been resized */
50 } widget_msg_t;
52 typedef enum {
53 MSG_NOT_HANDLED = 0,
54 MSG_HANDLED = 1
55 } cb_ret_t;
57 /* Widgets are expected to answer to the following messages:
59 WIDGET_FOCUS: 1 if the accept the focus, 0 if they do not.
60 WIDGET_UNFOCUS: 1 if they accept to release the focus, 0 if they don't.
61 WIDGET_KEY: 1 if they actually used the key, 0 if not.
62 WIDGET_HOTKEY: 1 if they actually used the key, 0 if not.
65 /* Dialog messages */
66 typedef enum {
67 DLG_INIT = 0, /* Initialize dialog */
68 DLG_IDLE = 1, /* The idle state is active */
69 DLG_DRAW = 2, /* Draw dialog on screen */
70 DLG_FOCUS = 3, /* A widget has got focus */
71 DLG_UNFOCUS = 4, /* A widget has been unfocused */
72 DLG_RESIZE = 5, /* Window size has changed */
73 DLG_KEY = 6, /* Key before sending to widget */
74 DLG_HOTKEY_HANDLED = 7, /* A widget has got the hotkey */
75 DLG_POST_KEY = 8, /* The key has been handled */
76 DLG_UNHANDLED_KEY = 9, /* Key that no widget handled */
77 DLG_ACTION = 10, /* State of check- and radioboxes has changed
78 * and listbox current entry has changed */
79 DLG_VALIDATE = 11, /* Dialog is to be closed */
80 DLG_END = 12 /* Shut down dialog */
81 } dlg_msg_t;
84 /* Dialog callback */
85 typedef struct Dlg_head Dlg_head;
86 typedef cb_ret_t (*dlg_cb_fn)(struct Dlg_head *h, Widget *sender,
87 dlg_msg_t msg, int parm, void *data);
89 /* get string representation of shortcut assigned with command */
90 /* as menu is a widget of dialog, ask dialog about shortcut string */
91 typedef char * (*dlg_shortcut_str) (unsigned long command);
93 /* Dialog color constants */
94 #define DLG_COLOR_NUM 4
95 #define DLG_NORMALC(h) ((h)->color[0])
96 #define DLG_FOCUSC(h) ((h)->color[1])
97 #define DLG_HOT_NORMALC(h) ((h)->color[2])
98 #define DLG_HOT_FOCUSC(h) ((h)->color[3])
100 struct Dlg_head {
101 /* Set by the user */
102 int flags; /* User flags */
103 const char *help_ctx; /* Name of the help entry */
104 int *color; /* Color set. Unused in viewer and editor */
105 /*notconst*/ char *title; /* Title of the dialog */
107 /* Set and received by the user */
108 int ret_value; /* Result of run_dlg() */
110 /* Geometry */
111 int x, y; /* Position relative to screen origin */
112 int cols, lines; /* Width and height of the window */
114 /* Internal flags */
115 unsigned int running:1; /* The dialog is currently active */
116 unsigned int fullscreen:1; /* Parents dialogs don't need refresh */
117 int mouse_status; /* For the autorepeat status of the mouse */
119 /* Internal variables */
120 int count; /* Number of widgets */
121 struct Widget *current; /* Curently active widget */
122 void *data; /* Data can be passed to dialog */
123 dlg_cb_fn callback;
124 dlg_shortcut_str get_shortcut; /* Shortcut string */
125 struct Dlg_head *parent; /* Parent dialog */
128 /* Color styles for normal and error dialogs */
129 extern int dialog_colors[4];
130 extern int alarm_colors[4];
133 /* Widget callback */
134 typedef cb_ret_t (*callback_fn) (Widget *widget, widget_msg_t msg, int parm);
136 /* widget options */
137 typedef enum {
138 W_WANT_HOTKEY = (1 << 1),
139 W_WANT_CURSOR = (1 << 2),
140 W_WANT_IDLE = (1 << 3),
141 W_IS_INPUT = (1 << 4)
142 } widget_options_t;
144 /* Flags for widget repositioning on dialog resize */
145 typedef enum {
146 WPOS_KEEP_LEFT = (1 << 0), /* keep widget distance to left border of dialog */
147 WPOS_KEEP_RIGHT = (1 << 1), /* keep widget distance to right border of dialog */
148 WPOS_KEEP_TOP = (1 << 2), /* keep widget distance to top border of dialog */
149 WPOS_KEEP_BOTTOM = (1 << 3), /* keep widget distance to bottom border of dialog */
150 WPOS_KEEP_HORZ = WPOS_KEEP_LEFT | WPOS_KEEP_RIGHT,
151 WPOS_KEEP_VERT = WPOS_KEEP_TOP | WPOS_KEEP_BOTTOM,
152 WPOS_KEEP_ALL = WPOS_KEEP_HORZ | WPOS_KEEP_VERT
153 } widget_pos_flags_t;
155 /* Every Widget must have this as its first element */
156 struct Widget {
157 int x, y;
158 int cols, lines;
159 widget_options_t options;
160 widget_pos_flags_t pos_flags; /* repositioning flags */
161 int dlg_id; /* Number of the widget, starting with 0 */
162 struct Widget *next;
163 struct Widget *prev;
164 callback_fn callback;
165 mouse_h mouse;
166 struct Dlg_head *parent;
169 /* draw box in window */
170 void draw_box (Dlg_head *h, int y, int x, int ys, int xs);
172 /* Flags for create_dlg: */
173 #define DLG_REVERSE (1 << 5) /* Tab order is opposite to the add order */
174 #define DLG_WANT_TAB (1 << 4) /* Should the tab key be sent to the dialog? */
175 #define DLG_WANT_IDLE (1 << 3) /* Dialog wants idle events */
176 #define DLG_COMPACT (1 << 2) /* Suppress spaces around the frame */
177 #define DLG_TRYUP (1 << 1) /* Try to move two lines up the dialog */
178 #define DLG_CENTER (1 << 0) /* Center the dialog */
179 #define DLG_NONE (000000) /* No options */
181 /* Creates a dialog head */
182 Dlg_head *create_dlg (int y1, int x1, int lines, int cols,
183 const int *color_set, dlg_cb_fn callback,
184 const char *help_ctx, const char *title, int flags);
186 void dlg_set_default_colors (void);
188 int add_widget_autopos (Dlg_head *dest, void *w, widget_pos_flags_t pos_flags);
189 int add_widget (Dlg_head *dest, void *w);
191 /* sets size of dialog, leaving positioning to automatic mehtods
192 according to dialog flags */
193 void dlg_set_size (Dlg_head *h, int lines, int cols);
194 /* this function allows to set dialog position */
195 void dlg_set_position (Dlg_head *h, int y1, int x1, int y2, int x2);
197 /* Runs dialog d */
198 int run_dlg (Dlg_head *d);
200 void dlg_run_done (Dlg_head *h);
201 void dlg_process_event (Dlg_head *h, int key, Gpm_Event *event);
202 void init_dlg (Dlg_head *h);
204 /* To activate/deactivate the idle message generation */
205 void set_idle_proc (Dlg_head *d, int enable);
207 void dlg_redraw (Dlg_head *h);
208 void destroy_dlg (Dlg_head *h);
210 void widget_set_size (Widget *widget, int y, int x, int lines, int cols);
212 void dlg_broadcast_msg (Dlg_head *h, widget_msg_t message, int reverse);
214 void init_widget (Widget *w, int y, int x, int lines, int cols,
215 callback_fn callback, mouse_h mouse_handler);
217 /* Default callback for dialogs */
218 cb_ret_t default_dlg_callback (Dlg_head *h, Widget *sender,
219 dlg_msg_t msg, int parm, void *data);
221 /* Default paint routine for dialogs */
222 void common_dialog_repaint (struct Dlg_head *h);
224 #define widget_move(w, _y, _x) tty_gotoyx (((Widget *)(w))->y + _y, ((Widget *)(w))->x + _x)
225 #define dlg_move(h, _y, _x) tty_gotoyx (((Dlg_head *)(h))->y + _y, ((Dlg_head *)(h))->x + _x)
227 extern Dlg_head *current_dlg;
229 /* A hook list for idle events */
230 extern Hook *idle_hook;
232 static inline cb_ret_t
233 send_message (Widget *w, widget_msg_t msg, int parm)
235 return (*(w->callback)) (w, msg, parm);
238 /* Return 1 if the widget is active, 0 otherwise */
239 static inline int
240 dlg_widget_active (void *w)
242 Widget *w1 = (Widget *) w;
243 return (w1->parent->current == w1);
246 void dlg_replace_widget (Widget *old, Widget *new);
247 int dlg_overlap (Widget *a, Widget *b);
248 void widget_erase (Widget *);
249 void dlg_erase (Dlg_head *h);
250 void dlg_stop (Dlg_head *h);
252 /* Widget selection */
253 void dlg_select_widget (void *widget);
254 void dlg_one_up (Dlg_head *h);
255 void dlg_one_down (Dlg_head *h);
256 int dlg_focus (Dlg_head *h);
257 Widget *find_widget_type (const Dlg_head *h, callback_fn callback);
258 void dlg_select_by_id (const Dlg_head *h, int id);
260 /* Redraw all dialogs */
261 void do_refresh (void);
263 /* Sets/clear the specified flag in the options field */
264 #define widget_option(w,f,i) \
265 w.options = ((i) ? (w.options | (f)) : (w.options & (~(f))))
267 #define widget_want_cursor(w,i) widget_option(w, W_WANT_CURSOR, i)
268 #define widget_want_hotkey(w,i) widget_option(w, W_WANT_HOTKEY, i)
270 /* Used in load_prompt() */
271 void update_cursor (Dlg_head *h);
273 #endif /* MC_DIALOG_H */