* ext.c: (regex_check_type): Further split. Restore caching
[midnight-commander.git] / src / dlg.h
blobb7696ff8243fd481d0d3c1f11c9bae6adb03a53f
1 #ifndef MC_DLG_H
2 #define MC_DLG_H
3 #include "mouse.h"
5 /* Color constants */
6 #define FOCUSC h->color[1]
7 #define NORMALC h->color[0]
8 #define HOT_NORMALC h->color[2]
9 #define HOT_FOCUSC h->color[3]
11 /* Possible directions */
12 #define DIR_FORWARD 1
13 #define DIR_BACKWARD 0
15 /* Common return values */
16 #define B_EXIT 0
17 #define B_CANCEL 1
18 #define B_ENTER 2
19 #define B_HELP 3
20 #define B_USER 100
22 /* Widget messages */
23 enum {
24 WIDGET_INIT, /* Initialize widget */
25 WIDGET_FOCUS, /* Draw widget in focused state */
26 WIDGET_UNFOCUS, /* Draw widget in unfocused state */
27 WIDGET_DRAW, /* Sent to widget to draw themselves */
28 WIDGET_KEY, /* Sent to widgets on key press */
29 WIDGET_HOTKEY, /* Sent to widget to catch preprocess key */
30 WIDGET_DESTROY, /* Sent to widget at destruction time */
31 WIDGET_CURSOR, /* Sent to widget to position the cursor */
32 WIDGET_IDLE, /* Send to widgets with options & W_WANT_IDLE*/
33 WIDGET_USER = 0x100000
35 } /* Widget_Messages */;
37 enum {
38 MSG_NOT_HANDLED,
39 MSG_HANDLED
40 } /* WRET */;
42 /* Widgets are expected to answer to the following messages:
44 WIDGET_FOCUS: 1 if the accept the focus, 0 if they do not.
45 WIDGET_UNFOCUS: 1 if they accept to release the focus, 0 if they don't.
46 WIDGET_KEY: 1 if they actually used the key, 0 if not.
47 WIDGET_HOTKEY: 1 if they actually used the key, 0 if not.
50 /* Dialog messages */
51 enum {
52 DLG_KEY, /* Sent on keypress before sending to widget */
53 DLG_INIT, /* Sent on init */
54 DLG_END, /* Sent on shutdown */
55 DLG_ACTION,
56 DLG_DRAW, /* Sent for updating dialog managed area */
57 DLG_FOCUS, /* Sent on give focus to a widget */
58 DLG_UNFOCUS, /* Sent on remove focus from widget */
59 DLG_ONE_UP, /* Sent on selecting next */
60 DLG_ONE_DOWN, /* Sent on selecting prev */
61 DLG_POST_KEY, /* Sent after key has been sent */
62 DLG_IDLE, /* Sent if idle is active */
63 DLG_UNHANDLED_KEY, /* Send if no widget wanted the key */
64 DLG_HOTKEY_HANDLED, /* Send if a child got the hotkey */
65 DLG_PRE_EVENT /* Send before calling get_event */
66 } /* Dialog_Messages */;
68 typedef unsigned long widget_data;
69 typedef struct Dlg_head {
70 int *color; /* color set */
71 int count; /* number of widgets */
72 int ret_value;
74 /* mouse status */
75 int mouse_status; /* For the autorepeat status of the mouse */
77 void *previous_dialog; /* Pointer to the previously running Dlg_head */
78 int refresh_pushed; /* Did the dialog actually run? */
80 /* position */
81 int x, y; /* Position relative to screen origin */
83 /* Flags */
84 int running;
85 int direction;
86 int send_idle_msg;
88 char *name; /* Dialog name Tk code */
89 char *help_ctx;
91 /* Internal variables */
92 struct Widget_Item *current, *first, *last;
93 int (*callback) (struct Dlg_head *, int, int);
95 struct Widget_Item *initfocus;
97 /* Hacks */
98 char *title;
100 int cols;
101 int lines;
102 void *data;
104 int has_menubar; /* GrossHack: Send events on row 1 to a menubar? */
105 int raw; /* Should the tab key be sent to the dialog? */
107 widget_data wdata;
108 int grided; /* Does it use the automatic layout? */
109 } Dlg_head;
111 /* Every Widget must have this as it's first element */
112 typedef struct Widget {
113 int x, y;
114 int cols, lines;
115 int color; /* If the widget uses it, the color */
116 int options;
117 int focused; /* Tells if the widget is focused */
118 int (*callback)(Dlg_head *, void *, int, int); /* The callback function */
119 void (*destroy)(void *);
120 mouse_h mouse;
121 struct Dlg_head *parent;
122 widget_data wdata;
123 widget_data wcontainer; /* For children of midnight_dlg, identifies
124 * the frame in which they should reside
126 char *frame; /* Tk version: frame containing it */
127 char *tkname; /* Tk version: widget name */
128 enum {
129 AREA_TOP,
130 AREA_LEFT,
131 AREA_RIGHT,
132 AREA_BOTTOM
133 } area; /* Used by X platforms, should stay here always because the size
134 of this structure has to be same everywhere :) */
135 } Widget;
137 /* The options for the widgets */
138 #define W_WANT_POST_KEY 1
139 #define W_WANT_HOTKEY 2
140 #define W_WANT_CURSOR 4
141 #define W_WANT_IDLE 8
142 #define W_IS_INPUT 16
143 #define W_PANEL_HIDDEN 32
145 typedef struct Widget_Item {
146 int dlg_id;
147 struct Widget_Item *next; /* next in circle buffer */
148 struct Widget_Item *prev; /* previous in circle buffer */
149 Widget *widget; /* point to the component */
150 } Widget_Item;
152 /* draw box in window */
153 void draw_box (Dlg_head *h, int y, int x, int ys, int xs);
155 /* doubled line if possible */
156 void draw_double_box (Dlg_head *h, int y, int x, int ys, int xs);
158 /* Creates a dialog head */
159 Dlg_head *create_dlg (int y1, int x1, int lines, int cols,
160 int *col,
161 int (*callback) (struct Dlg_head *, int, int),
162 char *help_ctx, char *name, int flags);
164 /* The flags: */
165 #define DLG_TRYUP 2 /* Try to move two lines up the dialog */
166 #define DLG_CENTER 1 /* Center the dialog */
167 #define DLG_NONE 0 /* No options */
169 int add_widget (Dlg_head *dest, void *Widget);
170 int remove_widget (Dlg_head *dest, void *Widget);
171 int destroy_widget (Widget *w);
173 /* Runs dialog d */
174 void run_dlg (Dlg_head *d);
176 void dlg_run_done (Dlg_head *h);
177 void dlg_process_event (Dlg_head *h, int key, Gpm_Event *event);
178 void init_dlg (Dlg_head *h);
180 /* To activate/deactivate the idle message generation */
181 void set_idle_proc (Dlg_head *d, int state);
183 void dlg_redraw (Dlg_head *h);
184 void dlg_refresh (void *parameter);
185 void destroy_dlg (Dlg_head *h);
187 void widget_set_size (Widget *widget, int x1, int y1, int x2, int y2);
189 void dlg_broadcast_msg_to (Dlg_head *h, int message, int reverse, int flags);
190 void dlg_broadcast_msg (Dlg_head *h, int message, int reverse);
191 void dlg_mouse (Dlg_head *h, Gpm_Event *event);
193 typedef void (*destroy_fn)(void *);
194 typedef int (*callback_fn)(Dlg_head *, void *, int, int);
196 void init_widget (Widget *w, int y, int x, int lines, int cols,
197 callback_fn callback, destroy_fn destroy,
198 mouse_h mouse_handler, char *tkname);
200 /* Various default service provision */
201 int default_dlg_callback (Dlg_head *h, int id, int msg);
202 int std_callback (Dlg_head *h, int Msg, int Par);
203 int default_proc (Dlg_head *h, int Msg, int Par);
205 #define real_widget_move(w, _y, _x) move((w)->y + _y, (w)->x + _x)
206 #define dlg_move(h, _y, _x) move(((Dlg_head *) h)->y + _y, \
207 ((Dlg_head *) h)->x + _x)
209 #define widget_move(w,y,x) real_widget_move((Widget*)w,y,x)
211 extern Dlg_head *current_dlg;
213 int send_message (Dlg_head *h, Widget *w, int msg, int par);
214 int send_message_to (Dlg_head *h, Widget *w, int msg, int par);
215 void dlg_replace_widget (Dlg_head *h, Widget *old, Widget *new);
216 void widget_redraw (Dlg_head *h, Widget_Item *w);
217 int dlg_overlap (Widget *a, Widget *b);
218 void widget_erase (Widget *);
219 void dlg_erase (Dlg_head *h);
220 void dlg_stop (Dlg_head *h);
222 /* Widget selection */
223 int dlg_select_widget (Dlg_head *h, void *widget);
224 void dlg_one_up (Dlg_head *h);
225 void dlg_one_down (Dlg_head *h);
226 int dlg_focus (Dlg_head *h);
227 int dlg_unfocus (Dlg_head *h);
228 int dlg_select_nth_widget (Dlg_head *h, int n);
229 int dlg_item_number (Dlg_head *h);
230 Widget *find_widget_type (Dlg_head *h, callback_fn signature);
232 /* Sets/clear the specified flag in the options field */
233 #define widget_option(w,f,i) \
234 w.options = ((i) ? (w.options | (f)) : (w.options & (~(f))))
236 #define widget_want_cursor(w,i) widget_option(w, W_WANT_CURSOR, i)
237 #define widget_want_hotkey(w,i) widget_option(w, W_WANT_HOTKEY, i)
238 #define widget_want_postkey(w,i) widget_option(w, W_WANT_POSTKEY, i)
240 typedef void (*movefn)(void *, int);
242 /* Layout definitions */
244 void x_set_dialog_title (Dlg_head *h, const char *title);
246 /* The inner workings of run_dlg, exported for the Tk and XView toolkits */
247 int dlg_key_event (Dlg_head *h, int d_key);
248 void update_cursor (Dlg_head *h);
250 #endif /* MC_DLG_H */