ooops reverting mischanged option menu order...
[midnight-commander.git] / src / dlg.h
blobc0cc9a8d527753042c3ca56359819dbc18de87a1
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 /* Common return values */
12 #define B_EXIT 0
13 #define B_CANCEL 1
14 #define B_ENTER 2
15 #define B_HELP 3
16 #define B_USER 100
18 /* Widget messages */
19 enum {
20 WIDGET_INIT, /* Initialize widget */
21 WIDGET_FOCUS, /* Draw widget in focused state */
22 WIDGET_UNFOCUS, /* Draw widget in unfocused state */
23 WIDGET_DRAW, /* Sent to widget to draw themselves */
24 WIDGET_KEY, /* Sent to widgets on key press */
25 WIDGET_HOTKEY, /* Sent to widget to catch preprocess key */
26 WIDGET_DESTROY, /* Sent to widget at destruction time */
27 WIDGET_CURSOR, /* Sent to widget to position the cursor */
28 WIDGET_IDLE, /* Send to widgets with options & W_WANT_IDLE*/
29 WIDGET_USER = 0x100000
31 } /* Widget_Messages */;
33 enum {
34 MSG_NOT_HANDLED,
35 MSG_HANDLED
36 } /* WRET */;
38 /* Widgets are expected to answer to the following messages:
40 WIDGET_FOCUS: 1 if the accept the focus, 0 if they do not.
41 WIDGET_UNFOCUS: 1 if they accept to release the focus, 0 if they don't.
42 WIDGET_KEY: 1 if they actually used the key, 0 if not.
43 WIDGET_HOTKEY: 1 if they actually used the key, 0 if not.
46 /* Dialog messages */
47 enum {
48 DLG_KEY, /* Sent on keypress before sending to widget */
49 DLG_INIT, /* Sent on init */
50 DLG_END, /* Sent on shutdown */
51 DLG_ACTION,
52 DLG_DRAW, /* Sent for updating dialog managed area */
53 DLG_FOCUS, /* Sent on give focus to a widget */
54 DLG_UNFOCUS, /* Sent on remove focus from widget */
55 DLG_ONE_UP, /* Sent on selecting next */
56 DLG_ONE_DOWN, /* Sent on selecting prev */
57 DLG_POST_KEY, /* Sent after key has been sent */
58 DLG_IDLE, /* Sent if idle is active */
59 DLG_UNHANDLED_KEY, /* Send if no widget wanted the key */
60 DLG_HOTKEY_HANDLED, /* Send if a child got the hotkey */
61 DLG_PRE_EVENT /* Send before calling get_event */
62 } /* Dialog_Messages */;
65 typedef struct Dlg_head {
67 /* Set by the user */
68 int flags; /* User flags */
69 char *help_ctx; /* Name of the help entry */
70 const int *color; /* Color set */
71 char *title; /* Title of the dialog */
73 /* Set and received by the user */
74 int ret_value; /* Result of run_dlg() */
76 /* Geometry */
77 int x, y; /* Position relative to screen origin */
78 int cols, lines; /* Width and height of the window */
80 /* Internal flags */
81 int running;
82 int send_idle_msg;
83 int mouse_status; /* For the autorepeat status of the mouse */
84 int refresh_pushed; /* Did the dialog actually run? */
86 /* Internal variables */
87 int count; /* number of widgets */
88 struct Widget_Item *current, *first, *last;
89 int (*callback) (struct Dlg_head *, int, int);
90 struct Widget_Item *initfocus;
91 void *previous_dialog; /* Pointer to the previously running Dlg_head */
93 } Dlg_head;
96 /* Every Widget must have this as it's first element */
97 typedef struct Widget {
98 int x, y;
99 int cols, lines;
100 int options;
101 int (*callback)(Dlg_head *, void *, int, int); /* The callback function */
102 void (*destroy)(void *);
103 mouse_h mouse;
104 struct Dlg_head *parent;
105 char *tkname; /* name used for history saving */
106 } Widget;
108 /* The options for the widgets */
109 #define W_WANT_POST_KEY 1
110 #define W_WANT_HOTKEY 2
111 #define W_WANT_CURSOR 4
112 #define W_WANT_IDLE 8
113 #define W_IS_INPUT 16
114 #define W_PANEL_HIDDEN 32
116 typedef struct Widget_Item {
117 int dlg_id;
118 struct Widget_Item *next; /* next in circle buffer */
119 struct Widget_Item *prev; /* previous in circle buffer */
120 Widget *widget; /* point to the component */
121 } Widget_Item;
123 /* draw box in window */
124 void draw_box (Dlg_head *h, int y, int x, int ys, int xs);
126 /* doubled line if possible */
127 void draw_double_box (Dlg_head *h, int y, int x, int ys, int xs);
129 /* Creates a dialog head */
130 Dlg_head *create_dlg (int y1, int x1, int lines, int cols,
131 const int *color_set,
132 int (*callback) (struct Dlg_head *, int, int),
133 char *help_ctx, const char *title, int flags);
136 /* The flags: */
137 #define DLG_BACKWARD 32 /* Tab order is reverse to the index order */
138 #define DLG_WANT_TAB 16 /* Should the tab key be sent to the dialog? */
139 #define DLG_HAS_MENUBAR 8 /* GrossHack: Send events on row 1 to a menubar? */
140 #define DLG_COMPACT 4 /* Suppress spaces around the frame */
141 #define DLG_TRYUP 2 /* Try to move two lines up the dialog */
142 #define DLG_CENTER 1 /* Center the dialog */
143 #define DLG_NONE 0 /* No options */
145 int add_widget (Dlg_head *dest, void *Widget);
147 /* Runs dialog d */
148 int run_dlg (Dlg_head *d);
150 void dlg_run_done (Dlg_head *h);
151 void dlg_process_event (Dlg_head *h, int key, Gpm_Event *event);
152 void init_dlg (Dlg_head *h);
154 /* To activate/deactivate the idle message generation */
155 void set_idle_proc (Dlg_head *d, int state);
157 void dlg_redraw (Dlg_head *h);
158 void destroy_dlg (Dlg_head *h);
160 void widget_set_size (Widget *widget, int x1, int y1, int x2, int y2);
162 void dlg_broadcast_msg (Dlg_head *h, int message, int reverse);
164 typedef void (*destroy_fn)(void *);
165 typedef int (*callback_fn)(Dlg_head *, void *, int, int);
167 void init_widget (Widget *w, int y, int x, int lines, int cols,
168 callback_fn callback, destroy_fn destroy,
169 mouse_h mouse_handler, char *tkname);
171 /* Default callback for dialogs */
172 int default_dlg_callback (Dlg_head *h, int id, int msg);
174 /* Default callback for widgets */
175 int default_proc (Dlg_head *h, int Msg, int Par);
177 /* Default paint routine for dialogs */
178 void common_dialog_repaint (struct Dlg_head *h);
180 #define real_widget_move(w, _y, _x) move((w)->y + _y, (w)->x + _x)
181 #define dlg_move(h, _y, _x) move(((Dlg_head *) h)->y + _y, \
182 ((Dlg_head *) h)->x + _x)
184 #define widget_move(w,y,x) real_widget_move((Widget*)w,y,x)
186 extern Dlg_head *current_dlg;
188 int send_message (Dlg_head *h, Widget *w, int msg, int par);
189 int send_message_to (Dlg_head *h, Widget *w, int msg, int par);
190 void dlg_replace_widget (Dlg_head *h, Widget *old, Widget *new);
191 void widget_redraw (Dlg_head *h, Widget_Item *w);
192 int dlg_overlap (Widget *a, Widget *b);
193 void widget_erase (Widget *);
194 void dlg_erase (Dlg_head *h);
195 void dlg_stop (Dlg_head *h);
197 /* Widget selection */
198 int dlg_select_widget (Dlg_head *h, void *widget);
199 void dlg_one_up (Dlg_head *h);
200 void dlg_one_down (Dlg_head *h);
201 int dlg_focus (Dlg_head *h);
202 int dlg_select_nth_widget (Dlg_head *h, int n);
203 int dlg_item_number (Dlg_head *h);
204 Widget *find_widget_type (Dlg_head *h, callback_fn signature);
206 /* Sets/clear the specified flag in the options field */
207 #define widget_option(w,f,i) \
208 w.options = ((i) ? (w.options | (f)) : (w.options & (~(f))))
210 #define widget_want_cursor(w,i) widget_option(w, W_WANT_CURSOR, i)
211 #define widget_want_hotkey(w,i) widget_option(w, W_WANT_HOTKEY, i)
212 #define widget_want_postkey(w,i) widget_option(w, W_WANT_POSTKEY, i)
214 typedef void (*movefn)(void *, int);
216 /* Used in load_prompt() */
217 void update_cursor (Dlg_head *h);
219 #endif /* MC_DLG_H */