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.
20 * \brief Header: dialog box features module
26 #include "../src/tty/mouse.h"
27 #include "util.h" /* Hook */
30 #define DLG_NORMALC(h) ((h)->color[0])
31 #define DLG_FOCUSC(h) ((h)->color[1])
32 #define DLG_HOT_NORMALC(h) ((h)->color[2])
33 #define DLG_HOT_FOCUSC(h) ((h)->color[3])
35 /* Common return values */
44 WIDGET_INIT
, /* Initialize widget */
45 WIDGET_FOCUS
, /* Draw widget in focused state */
46 WIDGET_UNFOCUS
, /* Draw widget in unfocused state */
47 WIDGET_DRAW
, /* Sent to widget to draw themselves */
48 WIDGET_KEY
, /* Sent to widgets on key press */
49 WIDGET_HOTKEY
, /* Sent to widget to catch preprocess key */
50 WIDGET_DESTROY
, /* Sent to widget at destruction time */
51 WIDGET_CURSOR
, /* Sent to widget to position the cursor */
52 WIDGET_IDLE
, /* Sent to widgets with options & W_WANT_IDLE*/
53 WIDGET_RESIZED
/* Sent after a widget has been resized */
61 /* Widgets are expected to answer to the following messages:
63 WIDGET_FOCUS: 1 if the accept the focus, 0 if they do not.
64 WIDGET_UNFOCUS: 1 if they accept to release the focus, 0 if they don't.
65 WIDGET_KEY: 1 if they actually used the key, 0 if not.
66 WIDGET_HOTKEY: 1 if they actually used the key, 0 if not.
71 DLG_KEY
, /* Key before sending to widget */
72 DLG_INIT
, /* Initialize dialog */
73 DLG_END
, /* Shut down dialog */
74 DLG_ACTION
, /* State of check- and radioboxes has changed
75 * and listbox current entry has changed */
76 DLG_DRAW
, /* Draw dialog on screen */
77 DLG_FOCUS
, /* A widget has got focus */
78 DLG_UNFOCUS
, /* A widget has been unfocused */
79 DLG_RESIZE
, /* Window size has changed */
80 DLG_POST_KEY
, /* The key has been handled */
81 DLG_IDLE
, /* The idle state is active */
82 DLG_UNHANDLED_KEY
, /* Key that no widget handled */
83 DLG_HOTKEY_HANDLED
, /* A widget has got the hotkey */
84 DLG_VALIDATE
/* Dialog is to be closed */
90 typedef cb_ret_t (*dlg_cb_fn
)(struct Dlg_head
*h
, dlg_msg_t msg
, int parm
);
92 typedef struct Dlg_head
{
94 int flags
; /* User flags */
95 const char *help_ctx
; /* Name of the help entry */
96 const int *color
; /* Color set */
97 /*notconst*/ char *title
; /* Title of the dialog */
99 /* Set and received by the user */
100 int ret_value
; /* Result of run_dlg() */
103 int x
, y
; /* Position relative to screen origin */
104 int cols
, lines
; /* Width and height of the window */
107 unsigned int running
:1; /* The dialog is currently active */
108 unsigned int fullscreen
:1; /* Parents dialogs don't need refresh */
109 int mouse_status
; /* For the autorepeat status of the mouse */
111 /* Internal variables */
112 int count
; /* Number of widgets */
113 struct Widget
*current
; /* Curently active widget */
115 struct Dlg_head
*parent
; /* Parent dialog */
118 /* Color styles for normal and error dialogs */
119 extern int dialog_colors
[4];
120 extern int alarm_colors
[4];
122 typedef struct Widget Widget
;
124 /* Widget callback */
125 typedef cb_ret_t (*callback_fn
) (Widget
*widget
, widget_msg_t msg
, int parm
);
127 /* Every Widget must have this as its first element */
132 #define W_WANT_HOTKEY (1 << 1)
133 #define W_WANT_CURSOR (1 << 2)
134 #define W_WANT_IDLE (1 << 3)
135 #define W_IS_INPUT (1 << 4)
137 int dlg_id
; /* Number of the widget, starting with 0 */
140 callback_fn callback
;
142 struct Dlg_head
*parent
;
145 /* draw box in window */
146 void draw_box (Dlg_head
*h
, int y
, int x
, int ys
, int xs
);
148 /* Flags for create_dlg: */
149 #define DLG_REVERSE (1 << 5) /* Tab order is opposite to the add order */
150 #define DLG_WANT_TAB (1 << 4) /* Should the tab key be sent to the dialog? */
151 #define DLG_WANT_IDLE (1 << 3) /* Dialog wants idle events */
152 #define DLG_COMPACT (1 << 2) /* Suppress spaces around the frame */
153 #define DLG_TRYUP (1 << 1) /* Try to move two lines up the dialog */
154 #define DLG_CENTER (1 << 0) /* Center the dialog */
155 #define DLG_NONE (000000) /* No options */
157 /* Creates a dialog head */
158 Dlg_head
*create_dlg (int y1
, int x1
, int lines
, int cols
,
159 const int *color_set
, dlg_cb_fn callback
,
160 const char *help_ctx
, const char *title
, int flags
);
162 void dlg_set_default_colors (void);
164 int add_widget (Dlg_head
*dest
, void *Widget
);
167 int run_dlg (Dlg_head
*d
);
169 void dlg_run_done (Dlg_head
*h
);
170 void dlg_process_event (Dlg_head
*h
, int key
, Gpm_Event
*event
);
171 void init_dlg (Dlg_head
*h
);
173 /* To activate/deactivate the idle message generation */
174 void set_idle_proc (Dlg_head
*d
, int enable
);
176 void dlg_redraw (Dlg_head
*h
);
177 void destroy_dlg (Dlg_head
*h
);
179 void widget_set_size (Widget
*widget
, int x1
, int y1
, int x2
, int y2
);
181 void dlg_broadcast_msg (Dlg_head
*h
, widget_msg_t message
, int reverse
);
183 void init_widget (Widget
*w
, int y
, int x
, int lines
, int cols
,
184 callback_fn callback
, mouse_h mouse_handler
);
186 /* Default callback for dialogs */
187 cb_ret_t
default_dlg_callback (Dlg_head
*h
, dlg_msg_t msg
, int parm
);
189 /* Default callback for widgets */
190 cb_ret_t
default_proc (widget_msg_t msg
, int parm
);
192 /* Default paint routine for dialogs */
193 void common_dialog_repaint (struct Dlg_head
*h
);
195 #define widget_move(w, _y, _x) tty_gotoyx (((Widget *)(w))->y + _y, ((Widget *)(w))->x + _x)
196 #define dlg_move(h, _y, _x) tty_gotoyx (((Dlg_head *)(h))->y + _y, ((Dlg_head *)(h))->x + _x)
198 extern Dlg_head
*current_dlg
;
200 /* A hook list for idle events */
201 extern Hook
*idle_hook
;
203 static inline cb_ret_t
204 send_message (Widget
*w
, widget_msg_t msg
, int parm
)
206 return (*(w
->callback
)) (w
, msg
, parm
);
209 /* Return 1 if the widget is active, 0 otherwise */
211 dlg_widget_active (void *w
)
213 Widget
*w1
= (Widget
*) w
;
214 return (w1
->parent
->current
== w1
);
217 void dlg_replace_widget (Widget
*old
, Widget
*new);
218 int dlg_overlap (Widget
*a
, Widget
*b
);
219 void widget_erase (Widget
*);
220 void dlg_erase (Dlg_head
*h
);
221 void dlg_stop (Dlg_head
*h
);
223 /* Widget selection */
224 void dlg_select_widget (void *widget
);
225 void dlg_one_up (Dlg_head
*h
);
226 void dlg_one_down (Dlg_head
*h
);
227 int dlg_focus (Dlg_head
*h
);
228 Widget
*find_widget_type (Dlg_head
*h
, callback_fn callback
);
229 void dlg_select_by_id (Dlg_head
*h
, int id
);
231 /* Redraw all dialogs */
232 void do_refresh (void);
234 /* Sets/clear the specified flag in the options field */
235 #define widget_option(w,f,i) \
236 w.options = ((i) ? (w.options | (f)) : (w.options & (~(f))))
238 #define widget_want_cursor(w,i) widget_option(w, W_WANT_CURSOR, i)
239 #define widget_want_hotkey(w,i) widget_option(w, W_WANT_HOTKEY, i)
241 /* Used in load_prompt() */
242 void update_cursor (Dlg_head
*h
);
244 #endif /* MC_DIALOG_H */