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.
25 #define DLG_NORMALC(h) ((h)->color[0])
26 #define DLG_FOCUSC(h) ((h)->color[1])
27 #define DLG_HOT_NORMALC(h) ((h)->color[2])
28 #define DLG_HOT_FOCUSC(h) ((h)->color[3])
30 /* Common return values */
39 WIDGET_INIT
, /* Initialize widget */
40 WIDGET_FOCUS
, /* Draw widget in focused state */
41 WIDGET_UNFOCUS
, /* Draw widget in unfocused state */
42 WIDGET_DRAW
, /* Sent to widget to draw themselves */
43 WIDGET_KEY
, /* Sent to widgets on key press */
44 WIDGET_HOTKEY
, /* Sent to widget to catch preprocess key */
45 WIDGET_DESTROY
, /* Sent to widget at destruction time */
46 WIDGET_CURSOR
, /* Sent to widget to position the cursor */
47 WIDGET_IDLE
, /* Sent to widgets with options & W_WANT_IDLE*/
48 WIDGET_RESIZED
/* Sent after a widget has been resized */
56 /* Widgets are expected to answer to the following messages:
58 WIDGET_FOCUS: 1 if the accept the focus, 0 if they do not.
59 WIDGET_UNFOCUS: 1 if they accept to release the focus, 0 if they don't.
60 WIDGET_KEY: 1 if they actually used the key, 0 if not.
61 WIDGET_HOTKEY: 1 if they actually used the key, 0 if not.
66 DLG_KEY
, /* Key before sending to widget */
67 DLG_INIT
, /* Initialize dialog */
68 DLG_END
, /* Shut down dialog */
69 DLG_ACTION
, /* State of check- and radioboxes has changed */
70 DLG_DRAW
, /* Draw dialog on screen */
71 DLG_FOCUS
, /* A widget has got focus */
72 DLG_UNFOCUS
, /* A widget has been unfocused */
73 DLG_RESIZE
, /* Window size has changed */
74 DLG_POST_KEY
, /* The key has been handled */
75 DLG_IDLE
, /* The idle state is active */
76 DLG_UNHANDLED_KEY
, /* Key that no widget handled */
77 DLG_HOTKEY_HANDLED
, /* A widget has got the hotkey */
78 DLG_VALIDATE
/* Dialog is to be closed */
84 typedef cb_ret_t (*dlg_cb_fn
)(struct Dlg_head
*h
, dlg_msg_t msg
, int parm
);
86 typedef struct Dlg_head
{
89 int flags
; /* User flags */
90 const char *help_ctx
; /* Name of the help entry */
91 const int *color
; /* Color set */
92 /*notconst*/ char *title
; /* Title of the dialog */
94 /* Set and received by the user */
95 int ret_value
; /* Result of run_dlg() */
98 int x
, y
; /* Position relative to screen origin */
99 int cols
, lines
; /* Width and height of the window */
102 unsigned int running
:1; /* The dialog is currently active */
103 unsigned int fullscreen
:1; /* Parents dialogs don't need refresh */
104 int mouse_status
; /* For the autorepeat status of the mouse */
106 /* Internal variables */
107 int count
; /* Number of widgets */
108 struct Widget
*current
; /* Curently active widget */
110 struct Dlg_head
*parent
; /* Parent dialog */
115 typedef struct Widget Widget
;
117 /* Widget callback */
118 typedef cb_ret_t (*callback_fn
) (Widget
*widget
, widget_msg_t msg
, int parm
);
120 /* Every Widget must have this as its first element */
125 #define W_WANT_HOTKEY (1 << 1)
126 #define W_WANT_CURSOR (1 << 2)
127 #define W_WANT_IDLE (1 << 3)
128 #define W_IS_INPUT (1 << 4)
130 int dlg_id
; /* Number of the widget, starting with 0 */
133 callback_fn callback
;
135 struct Dlg_head
*parent
;
138 /* draw box in window */
139 void draw_box (Dlg_head
*h
, int y
, int x
, int ys
, int xs
);
141 /* doubled line if possible */
142 void draw_double_box (Dlg_head
*h
, int y
, int x
, int ys
, int xs
);
144 /* Flags for create_dlg: */
145 #define DLG_REVERSE (1 << 5) /* Tab order is opposite to the add order */
146 #define DLG_WANT_TAB (1 << 4) /* Should the tab key be sent to the dialog? */
147 #define DLG_WANT_IDLE (1 << 3) /* Dialog wants idle events */
148 #define DLG_COMPACT (1 << 2) /* Suppress spaces around the frame */
149 #define DLG_TRYUP (1 << 1) /* Try to move two lines up the dialog */
150 #define DLG_CENTER (1 << 0) /* Center the dialog */
151 #define DLG_NONE (000000) /* No options */
153 /* Creates a dialog head */
154 Dlg_head
*create_dlg (int y1
, int x1
, int lines
, int cols
,
155 const int *color_set
, dlg_cb_fn callback
,
156 const char *help_ctx
, const char *title
, int flags
);
157 int add_widget (Dlg_head
*dest
, void *Widget
);
160 int run_dlg (Dlg_head
*d
);
162 void dlg_run_done (Dlg_head
*h
);
163 void dlg_process_event (Dlg_head
*h
, int key
, Gpm_Event
*event
);
164 void init_dlg (Dlg_head
*h
);
166 /* To activate/deactivate the idle message generation */
167 void set_idle_proc (Dlg_head
*d
, int enable
);
169 void dlg_redraw (Dlg_head
*h
);
170 void destroy_dlg (Dlg_head
*h
);
172 void widget_set_size (Widget
*widget
, int x1
, int y1
, int x2
, int y2
);
174 void dlg_broadcast_msg (Dlg_head
*h
, widget_msg_t message
, int reverse
);
176 void init_widget (Widget
*w
, int y
, int x
, int lines
, int cols
,
177 callback_fn callback
, mouse_h mouse_handler
);
179 /* Default callback for dialogs */
180 cb_ret_t
default_dlg_callback (Dlg_head
*h
, dlg_msg_t msg
, int parm
);
182 /* Default callback for widgets */
183 cb_ret_t
default_proc (widget_msg_t msg
, int parm
);
185 /* Default paint routine for dialogs */
186 void common_dialog_repaint (struct Dlg_head
*h
);
188 #define widget_move(w, _y, _x) move(((Widget *)(w))->y + _y, \
189 ((Widget *)(w))->x + _x)
190 #define dlg_move(h, _y, _x) move(((Dlg_head *)(h))->y + _y, \
191 ((Dlg_head *)(h))->x + _x)
193 extern Dlg_head
*current_dlg
;
195 /* A hook list for idle events */
196 extern Hook
*idle_hook
;
198 static inline cb_ret_t
199 send_message (Widget
*w
, widget_msg_t msg
, int parm
)
201 return (*(w
->callback
)) (w
, msg
, parm
);
204 /* Return 1 if the widget is active, 0 otherwise */
206 dlg_widget_active (void *w
)
208 Widget
*w1
= (Widget
*) w
;
209 return (w1
->parent
->current
== w1
);
212 void dlg_replace_widget (Widget
*old
, Widget
*new);
213 int dlg_overlap (Widget
*a
, Widget
*b
);
214 void widget_erase (Widget
*);
215 void dlg_erase (Dlg_head
*h
);
216 void dlg_stop (Dlg_head
*h
);
218 /* Widget selection */
219 void dlg_select_widget (void *widget
);
220 void dlg_one_up (Dlg_head
*h
);
221 void dlg_one_down (Dlg_head
*h
);
222 int dlg_focus (Dlg_head
*h
);
223 Widget
*find_widget_type (Dlg_head
*h
, callback_fn callback
);
224 void dlg_select_by_id (Dlg_head
*h
, int id
);
226 /* Redraw all dialogs */
227 void do_refresh (void);
229 /* Sets/clear the specified flag in the options field */
230 #define widget_option(w,f,i) \
231 w.options = ((i) ? (w.options | (f)) : (w.options & (~(f))))
233 #define widget_want_cursor(w,i) widget_option(w, W_WANT_CURSOR, i)
234 #define widget_want_hotkey(w,i) widget_option(w, W_WANT_HOTKEY, i)
236 /* Used in load_prompt() */
237 void update_cursor (Dlg_head
*h
);