fix panel_scroll_pages start page
[midnight-commander.git] / src / dlg.h
blobf7ff95a0e5c17d1c62d68adeb61d60d1527ccadd
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_RESIZE, /* Sent when the window size changes */
56 DLG_ONE_UP, /* Sent on selecting next */
57 DLG_ONE_DOWN, /* Sent on selecting prev */
58 DLG_POST_KEY, /* Sent after key has been sent */
59 DLG_IDLE, /* Sent if idle is active */
60 DLG_UNHANDLED_KEY, /* Send if no widget wanted the key */
61 DLG_HOTKEY_HANDLED, /* Send if a child got the hotkey */
62 DLG_PRE_EVENT /* Send before calling get_event */
63 } /* Dialog_Messages */;
66 typedef struct Dlg_head {
68 /* Set by the user */
69 int flags; /* User flags */
70 char *help_ctx; /* Name of the help entry */
71 const int *color; /* Color set */
72 char *title; /* Title of the dialog */
74 /* Set and received by the user */
75 int ret_value; /* Result of run_dlg() */
77 /* Geometry */
78 int x, y; /* Position relative to screen origin */
79 int cols, lines; /* Width and height of the window */
81 /* Internal flags */
82 int running;
83 int send_idle_msg;
84 int mouse_status; /* For the autorepeat status of the mouse */
85 int refresh_pushed; /* Did the dialog actually run? */
87 /* Internal variables */
88 int count; /* number of widgets */
89 struct Widget_Item *current, *first, *last;
90 int (*callback) (struct Dlg_head *, int, int);
91 struct Widget_Item *initfocus;
92 void *previous_dialog; /* Pointer to the previously running Dlg_head */
94 } Dlg_head;
97 /* Every Widget must have this as it's first element */
98 typedef struct Widget {
99 int x, y;
100 int cols, lines;
101 int options;
102 int (*callback)(Dlg_head *, void *, int, int); /* The callback function */
103 void (*destroy)(void *);
104 mouse_h mouse;
105 struct Dlg_head *parent;
106 char *tkname; /* name used for history saving */
107 } Widget;
109 /* The options for the widgets */
110 #define W_WANT_POST_KEY 1
111 #define W_WANT_HOTKEY 2
112 #define W_WANT_CURSOR 4
113 #define W_WANT_IDLE 8
114 #define W_IS_INPUT 16
115 #define W_PANEL_HIDDEN 32
117 typedef struct Widget_Item {
118 int dlg_id;
119 struct Widget_Item *next; /* next in circle buffer */
120 struct Widget_Item *prev; /* previous in circle buffer */
121 Widget *widget; /* point to the component */
122 } Widget_Item;
124 /* draw box in window */
125 void draw_box (Dlg_head *h, int y, int x, int ys, int xs);
127 /* doubled line if possible */
128 void draw_double_box (Dlg_head *h, int y, int x, int ys, int xs);
130 /* Creates a dialog head */
131 Dlg_head *create_dlg (int y1, int x1, int lines, int cols,
132 const int *color_set,
133 int (*callback) (struct Dlg_head *, int, int),
134 char *help_ctx, const char *title, int flags);
137 /* The flags: */
138 #define DLG_BACKWARD 32 /* Tab order is reverse to the index order */
139 #define DLG_WANT_TAB 16 /* Should the tab key be sent to the dialog? */
140 #define DLG_HAS_MENUBAR 8 /* GrossHack: Send events on row 1 to a menubar? */
141 #define DLG_COMPACT 4 /* Suppress spaces around the frame */
142 #define DLG_TRYUP 2 /* Try to move two lines up the dialog */
143 #define DLG_CENTER 1 /* Center the dialog */
144 #define DLG_NONE 0 /* No options */
146 int add_widget (Dlg_head *dest, void *Widget);
148 /* Runs dialog d */
149 int run_dlg (Dlg_head *d);
151 void dlg_run_done (Dlg_head *h);
152 void dlg_process_event (Dlg_head *h, int key, Gpm_Event *event);
153 void init_dlg (Dlg_head *h);
155 /* To activate/deactivate the idle message generation */
156 void set_idle_proc (Dlg_head *d, int state);
158 void dlg_redraw (Dlg_head *h);
159 void destroy_dlg (Dlg_head *h);
161 void widget_set_size (Widget *widget, int x1, int y1, int x2, int y2);
163 void dlg_broadcast_msg (Dlg_head *h, int message, int reverse);
165 typedef void (*destroy_fn)(void *);
166 typedef int (*callback_fn)(Dlg_head *, void *, int, int);
168 void init_widget (Widget *w, int y, int x, int lines, int cols,
169 callback_fn callback, destroy_fn destroy,
170 mouse_h mouse_handler, char *tkname);
172 /* Default callback for dialogs */
173 int default_dlg_callback (Dlg_head *h, int id, int msg);
175 /* Default callback for widgets */
176 int default_proc (Dlg_head *h, int Msg, int Par);
178 /* Default paint routine for dialogs */
179 void common_dialog_repaint (struct Dlg_head *h);
181 #define real_widget_move(w, _y, _x) move((w)->y + _y, (w)->x + _x)
182 #define dlg_move(h, _y, _x) move(((Dlg_head *) h)->y + _y, \
183 ((Dlg_head *) h)->x + _x)
185 #define widget_move(w,y,x) real_widget_move((Widget*)w,y,x)
187 extern Dlg_head *current_dlg;
189 int send_message (Dlg_head *h, Widget *w, int msg, int par);
190 int send_message_to (Dlg_head *h, Widget *w, int msg, int par);
191 void dlg_replace_widget (Dlg_head *h, Widget *old, Widget *new);
192 void widget_redraw (Dlg_head *h, Widget_Item *w);
193 int dlg_overlap (Widget *a, Widget *b);
194 void widget_erase (Widget *);
195 void dlg_erase (Dlg_head *h);
196 void dlg_stop (Dlg_head *h);
198 /* Widget selection */
199 int dlg_select_widget (Dlg_head *h, void *widget);
200 void dlg_one_up (Dlg_head *h);
201 void dlg_one_down (Dlg_head *h);
202 int dlg_focus (Dlg_head *h);
203 int dlg_select_nth_widget (Dlg_head *h, int n);
204 int dlg_item_number (Dlg_head *h);
205 Widget *find_widget_type (Dlg_head *h, callback_fn signature);
207 /* Sets/clear the specified flag in the options field */
208 #define widget_option(w,f,i) \
209 w.options = ((i) ? (w.options | (f)) : (w.options & (~(f))))
211 #define widget_want_cursor(w,i) widget_option(w, W_WANT_CURSOR, i)
212 #define widget_want_hotkey(w,i) widget_option(w, W_WANT_HOTKEY, i)
213 #define widget_want_postkey(w,i) widget_option(w, W_WANT_POSTKEY, i)
215 typedef void (*movefn)(void *, int);
217 /* Used in load_prompt() */
218 void update_cursor (Dlg_head *h);
220 #endif /* MC_DLG_H */