Just a little correction at the it.po file.
[midnight-commander.git] / src / dlg.h
blob55cca5a1305a658929f0bb0ab646965bc0da4ebc
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, /* Key before sending to widget */
49 DLG_INIT, /* Initialize dialog */
50 DLG_END, /* Shut down dialog */
51 DLG_ACTION, /* State of check- and radioboxes has changed */
52 DLG_DRAW, /* Draw dialog on screen */
53 DLG_FOCUS, /* A widget has got focus */
54 DLG_UNFOCUS, /* A widget has been unfocused */
55 DLG_RESIZE, /* Window size has changed */
56 DLG_POST_KEY, /* The key has been handled */
57 DLG_IDLE, /* The idle state is active */
58 DLG_UNHANDLED_KEY, /* Key that no widget handled */
59 DLG_HOTKEY_HANDLED, /* A widget has got the hotkey */
60 DLG_PRE_EVENT, /* About to get new event */
61 DLG_VALIDATE /* Dialog is to be closed */
62 } /* Dialog_Messages */ ;
65 /* Dialog callback */
66 struct Dlg_head;
67 typedef int (*dlg_cb_fn)(struct Dlg_head *h, int Par, int Msg);
69 typedef struct Dlg_head {
71 /* Set by the user */
72 int flags; /* User flags */
73 char *help_ctx; /* Name of the help entry */
74 const int *color; /* Color set */
75 char *title; /* Title of the dialog */
77 /* Set and received by the user */
78 int ret_value; /* Result of run_dlg() */
80 /* Geometry */
81 int x, y; /* Position relative to screen origin */
82 int cols, lines; /* Width and height of the window */
84 /* Internal flags */
85 int running;
86 int send_idle_msg;
87 int mouse_status; /* For the autorepeat status of the mouse */
88 int refresh_pushed; /* Did the dialog actually run? */
90 /* Internal variables */
91 int count; /* number of widgets */
92 struct Widget_Item *current, *first, *last;
93 dlg_cb_fn callback;
94 struct Widget_Item *initfocus;
95 void *previous_dialog; /* Pointer to the previously running Dlg_head */
97 } Dlg_head;
100 /* Call when the widget is destroyed */
101 typedef void (*destroy_fn)(void *widget);
103 /* Widget callback */
104 typedef int (*callback_fn)(void *widget, int Msg, int Par);
106 /* Every Widget must have this as it's first element */
107 typedef struct Widget {
108 int x, y;
109 int cols, lines;
110 int options;
111 callback_fn callback; /* The callback function */
112 destroy_fn destroy;
113 mouse_h mouse;
114 struct Dlg_head *parent;
115 char *tkname; /* name used for history saving */
116 } Widget;
118 /* The options for the widgets */
119 #define W_WANT_HOTKEY 2
120 #define W_WANT_CURSOR 4
121 #define W_WANT_IDLE 8
122 #define W_IS_INPUT 16
124 /* Items in the circular buffer. Each item refers to a widget. */
125 typedef struct Widget_Item {
126 int dlg_id;
127 struct Widget_Item *next;
128 struct Widget_Item *prev;
129 Widget *widget;
130 } Widget_Item;
132 /* draw box in window */
133 void draw_box (Dlg_head *h, int y, int x, int ys, int xs);
135 /* doubled line if possible */
136 void draw_double_box (Dlg_head *h, int y, int x, int ys, int xs);
138 /* Creates a dialog head */
139 Dlg_head *create_dlg (int y1, int x1, int lines, int cols,
140 const int *color_set, dlg_cb_fn callback,
141 char *help_ctx, const char *title, int flags);
144 /* The flags: */
145 #define DLG_BACKWARD 32 /* Tab order is reverse to the index order */
146 #define DLG_WANT_TAB 16 /* Should the tab key be sent to the dialog? */
147 #define DLG_HAS_MENUBAR 8 /* GrossHack: Send events on row 1 to a menubar? */
148 #define DLG_COMPACT 4 /* Suppress spaces around the frame */
149 #define DLG_TRYUP 2 /* Try to move two lines up the dialog */
150 #define DLG_CENTER 1 /* Center the dialog */
151 #define DLG_NONE 0 /* No options */
153 int add_widget (Dlg_head *dest, void *Widget);
155 /* Runs dialog d */
156 int run_dlg (Dlg_head *d);
158 void dlg_run_done (Dlg_head *h);
159 void dlg_process_event (Dlg_head *h, int key, Gpm_Event *event);
160 void init_dlg (Dlg_head *h);
162 /* To activate/deactivate the idle message generation */
163 void set_idle_proc (Dlg_head *d, int state);
165 void dlg_redraw (Dlg_head *h);
166 void destroy_dlg (Dlg_head *h);
168 void widget_set_size (Widget *widget, int x1, int y1, int x2, int y2);
170 void dlg_broadcast_msg (Dlg_head *h, int message, int reverse);
172 void init_widget (Widget *w, int y, int x, int lines, int cols,
173 callback_fn callback, destroy_fn destroy,
174 mouse_h mouse_handler, char *tkname);
176 /* Default callback for dialogs */
177 int default_dlg_callback (Dlg_head *h, int id, int msg);
179 /* Default callback for widgets */
180 int default_proc (int Msg, int Par);
182 /* Default paint routine for dialogs */
183 void common_dialog_repaint (struct Dlg_head *h);
185 #define real_widget_move(w, _y, _x) move((w)->y + _y, (w)->x + _x)
186 #define dlg_move(h, _y, _x) move(((Dlg_head *) h)->y + _y, \
187 ((Dlg_head *) h)->x + _x)
189 #define widget_move(w,y,x) real_widget_move((Widget*)w,y,x)
191 extern Dlg_head *current_dlg;
193 static inline int
194 send_message (Widget *w, int Msg, int Par)
196 return (*(w->callback))(w, Msg, Par);
199 void dlg_replace_widget (Dlg_head *h, Widget *old, Widget *new);
200 int dlg_overlap (Widget *a, Widget *b);
201 void widget_erase (Widget *);
202 void dlg_erase (Dlg_head *h);
203 void dlg_stop (Dlg_head *h);
205 /* Widget selection */
206 int dlg_select_widget (Dlg_head *h, void *widget);
207 void dlg_one_up (Dlg_head *h);
208 void dlg_one_down (Dlg_head *h);
209 int dlg_focus (Dlg_head *h);
210 int dlg_select_nth_widget (Dlg_head *h, int n);
211 int dlg_item_number (Dlg_head *h);
212 Widget *find_widget_type (Dlg_head *h, callback_fn signature);
214 /* Sets/clear the specified flag in the options field */
215 #define widget_option(w,f,i) \
216 w.options = ((i) ? (w.options | (f)) : (w.options & (~(f))))
218 #define widget_want_cursor(w,i) widget_option(w, W_WANT_CURSOR, i)
219 #define widget_want_hotkey(w,i) widget_option(w, W_WANT_HOTKEY, i)
220 #define widget_want_postkey(w,i) widget_option(w, W_WANT_POSTKEY, i)
222 /* Used in load_prompt() */
223 void update_cursor (Dlg_head *h);
225 #endif /* MC_DLG_H */