done_screen() is moved from src/layout.c to src/main.c.
[midnight-commander.git] / src / dialog.h
blobd9c2702e0d539c54fd3f5f1b7423ba180f0066c3
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 "../src/tty/mouse.h"
27 #include "util.h" /* Hook */
29 /* Color constants */
30 #define DLG_NORMALC(h) ((h)->color[0])
31 #define DLG_FOCUSC(h) ((h)->color[1])
32 #define DLG_HOT_NORMALC(h) ((h)->color[2])
33 #define DLG_HOT_FOCUSC(h) ((h)->color[3])
35 /* Common return values */
36 #define B_EXIT 0
37 #define B_CANCEL 1
38 #define B_ENTER 2
39 #define B_HELP 3
40 #define B_USER 100
42 /* Widget messages */
43 typedef enum {
44 WIDGET_INIT, /* Initialize widget */
45 WIDGET_FOCUS, /* Draw widget in focused state */
46 WIDGET_UNFOCUS, /* Draw widget in unfocused state */
47 WIDGET_DRAW, /* Sent to widget to draw themselves */
48 WIDGET_KEY, /* Sent to widgets on key press */
49 WIDGET_HOTKEY, /* Sent to widget to catch preprocess key */
50 WIDGET_DESTROY, /* Sent to widget at destruction time */
51 WIDGET_CURSOR, /* Sent to widget to position the cursor */
52 WIDGET_IDLE, /* Sent to widgets with options & W_WANT_IDLE*/
53 WIDGET_RESIZED /* Sent after a widget has been resized */
54 } widget_msg_t;
56 typedef enum {
57 MSG_NOT_HANDLED = 0,
58 MSG_HANDLED = 1
59 } cb_ret_t;
61 /* Widgets are expected to answer to the following messages:
63 WIDGET_FOCUS: 1 if the accept the focus, 0 if they do not.
64 WIDGET_UNFOCUS: 1 if they accept to release the focus, 0 if they don't.
65 WIDGET_KEY: 1 if they actually used the key, 0 if not.
66 WIDGET_HOTKEY: 1 if they actually used the key, 0 if not.
69 /* Dialog messages */
70 typedef enum {
71 DLG_KEY, /* Key before sending to widget */
72 DLG_INIT, /* Initialize dialog */
73 DLG_END, /* Shut down dialog */
74 DLG_ACTION, /* State of check- and radioboxes has changed
75 * and listbox current entry has changed */
76 DLG_DRAW, /* Draw dialog on screen */
77 DLG_FOCUS, /* A widget has got focus */
78 DLG_UNFOCUS, /* A widget has been unfocused */
79 DLG_RESIZE, /* Window size has changed */
80 DLG_POST_KEY, /* The key has been handled */
81 DLG_IDLE, /* The idle state is active */
82 DLG_UNHANDLED_KEY, /* Key that no widget handled */
83 DLG_HOTKEY_HANDLED, /* A widget has got the hotkey */
84 DLG_VALIDATE /* Dialog is to be closed */
85 } dlg_msg_t;
88 /* Dialog callback */
89 struct Dlg_head;
90 typedef cb_ret_t (*dlg_cb_fn)(struct Dlg_head *h, dlg_msg_t msg, int parm);
92 typedef struct Dlg_head {
93 /* Set by the user */
94 int flags; /* User flags */
95 const char *help_ctx; /* Name of the help entry */
96 const int *color; /* Color set */
97 /*notconst*/ char *title; /* Title of the dialog */
99 /* Set and received by the user */
100 int ret_value; /* Result of run_dlg() */
102 /* Geometry */
103 int x, y; /* Position relative to screen origin */
104 int cols, lines; /* Width and height of the window */
106 /* Internal flags */
107 unsigned int running:1; /* The dialog is currently active */
108 unsigned int fullscreen:1; /* Parents dialogs don't need refresh */
109 int mouse_status; /* For the autorepeat status of the mouse */
111 /* Internal variables */
112 int count; /* Number of widgets */
113 struct Widget *current; /* Curently active widget */
114 dlg_cb_fn callback;
115 struct Dlg_head *parent; /* Parent dialog */
116 } Dlg_head;
118 /* Color styles for normal and error dialogs */
119 extern int dialog_colors[4];
120 extern int alarm_colors[4];
122 typedef struct Widget Widget;
124 /* Widget callback */
125 typedef cb_ret_t (*callback_fn) (Widget *widget, widget_msg_t msg, int parm);
127 /* Every Widget must have this as its first element */
128 struct Widget {
129 int x, y;
130 int cols, lines;
132 #define W_WANT_HOTKEY (1 << 1)
133 #define W_WANT_CURSOR (1 << 2)
134 #define W_WANT_IDLE (1 << 3)
135 #define W_IS_INPUT (1 << 4)
136 int options;
137 int dlg_id; /* Number of the widget, starting with 0 */
138 struct Widget *next;
139 struct Widget *prev;
140 callback_fn callback;
141 mouse_h mouse;
142 struct Dlg_head *parent;
145 /* draw box in window */
146 void draw_box (Dlg_head *h, int y, int x, int ys, int xs);
148 /* doubled line if possible */
149 void draw_double_box (Dlg_head *h, int y, int x, int ys, int xs);
151 /* Flags for create_dlg: */
152 #define DLG_REVERSE (1 << 5) /* Tab order is opposite to the add order */
153 #define DLG_WANT_TAB (1 << 4) /* Should the tab key be sent to the dialog? */
154 #define DLG_WANT_IDLE (1 << 3) /* Dialog wants idle events */
155 #define DLG_COMPACT (1 << 2) /* Suppress spaces around the frame */
156 #define DLG_TRYUP (1 << 1) /* Try to move two lines up the dialog */
157 #define DLG_CENTER (1 << 0) /* Center the dialog */
158 #define DLG_NONE (000000) /* No options */
160 /* Creates a dialog head */
161 Dlg_head *create_dlg (int y1, int x1, int lines, int cols,
162 const int *color_set, dlg_cb_fn callback,
163 const char *help_ctx, const char *title, int flags);
165 void dlg_set_default_colors (void);
167 int add_widget (Dlg_head *dest, void *Widget);
169 /* Runs dialog d */
170 int run_dlg (Dlg_head *d);
172 void dlg_run_done (Dlg_head *h);
173 void dlg_process_event (Dlg_head *h, int key, Gpm_Event *event);
174 void init_dlg (Dlg_head *h);
176 /* To activate/deactivate the idle message generation */
177 void set_idle_proc (Dlg_head *d, int enable);
179 void dlg_redraw (Dlg_head *h);
180 void destroy_dlg (Dlg_head *h);
182 void widget_set_size (Widget *widget, int x1, int y1, int x2, int y2);
184 void dlg_broadcast_msg (Dlg_head *h, widget_msg_t message, int reverse);
186 void init_widget (Widget *w, int y, int x, int lines, int cols,
187 callback_fn callback, mouse_h mouse_handler);
189 /* Default callback for dialogs */
190 cb_ret_t default_dlg_callback (Dlg_head *h, dlg_msg_t msg, int parm);
192 /* Default callback for widgets */
193 cb_ret_t default_proc (widget_msg_t msg, int parm);
195 /* Default paint routine for dialogs */
196 void common_dialog_repaint (struct Dlg_head *h);
198 #define widget_move(w, _y, _x) tty_gotoyx (((Widget *)(w))->y + _y, ((Widget *)(w))->x + _x)
199 #define dlg_move(h, _y, _x) tty_gotoyx (((Dlg_head *)(h))->y + _y, ((Dlg_head *)(h))->x + _x)
201 extern Dlg_head *current_dlg;
203 /* A hook list for idle events */
204 extern Hook *idle_hook;
206 static inline cb_ret_t
207 send_message (Widget *w, widget_msg_t msg, int parm)
209 return (*(w->callback)) (w, msg, parm);
212 /* Return 1 if the widget is active, 0 otherwise */
213 static inline int
214 dlg_widget_active (void *w)
216 Widget *w1 = (Widget *) w;
217 return (w1->parent->current == w1);
220 void dlg_replace_widget (Widget *old, Widget *new);
221 int dlg_overlap (Widget *a, Widget *b);
222 void widget_erase (Widget *);
223 void dlg_erase (Dlg_head *h);
224 void dlg_stop (Dlg_head *h);
226 /* Widget selection */
227 void dlg_select_widget (void *widget);
228 void dlg_one_up (Dlg_head *h);
229 void dlg_one_down (Dlg_head *h);
230 int dlg_focus (Dlg_head *h);
231 Widget *find_widget_type (Dlg_head *h, callback_fn callback);
232 void dlg_select_by_id (Dlg_head *h, int id);
234 /* Redraw all dialogs */
235 void do_refresh (void);
237 /* Sets/clear the specified flag in the options field */
238 #define widget_option(w,f,i) \
239 w.options = ((i) ? (w.options | (f)) : (w.options & (~(f))))
241 #define widget_want_cursor(w,i) widget_option(w, W_WANT_CURSOR, i)
242 #define widget_want_hotkey(w,i) widget_option(w, W_WANT_HOTKEY, i)
244 /* Used in load_prompt() */
245 void update_cursor (Dlg_head *h);
247 #endif /* MC_DIALOG_H */