Ticket #2598: u7z: Improve handling of missing p7zip binaries.
[midnight-commander.git] / lib / widget / dialog.h
blob6c13212a2e11af46cfabcf7f60f04d5e166f6b16
1 /* Dialog box features module for the Midnight Commander
2 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3 2005, 2007, 2009, 2010 Free Software Foundation
5 Authors: 1994, 1995 Radek Doulik, Miguel de Icaza
6 2009, 2010 Andrew Borodin
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 /** \file dialog.h
24 * \brief Header: dialog box features module
27 #ifndef MC__DIALOG_H
28 #define MC__DIALOG_H
30 #include <sys/types.h> /* size_t */
32 #include "lib/global.h"
33 #include "lib/hook.h" /* hook_t */
34 #include "lib/keybind.h" /* global_keymap_t */
36 /*** defined constants ***************************************************************************/
38 /* Common return values */
39 #define B_EXIT 0
40 #define B_CANCEL 1
41 #define B_ENTER 2
42 #define B_HELP 3
43 #define B_USER 100
45 #define dlg_move(h, _y, _x) tty_gotoyx (((Dlg_head *)(h))->y + _y, ((Dlg_head *)(h))->x + _x)
47 /*** enums ***************************************************************************************/
49 /* Dialog messages */
50 typedef enum
52 DLG_INIT = 0, /* Initialize dialog */
53 DLG_IDLE = 1, /* The idle state is active */
54 DLG_DRAW = 2, /* Draw dialog on screen */
55 DLG_FOCUS = 3, /* A widget has got focus */
56 DLG_UNFOCUS = 4, /* A widget has been unfocused */
57 DLG_RESIZE = 5, /* Window size has changed */
58 DLG_KEY = 6, /* Key before sending to widget */
59 DLG_HOTKEY_HANDLED = 7, /* A widget has got the hotkey */
60 DLG_POST_KEY = 8, /* The key has been handled */
61 DLG_UNHANDLED_KEY = 9, /* Key that no widget handled */
62 DLG_ACTION = 10, /* State of check- and radioboxes has changed
63 * and listbox current entry has changed */
64 DLG_VALIDATE = 11, /* Dialog is to be closed */
65 DLG_END = 12 /* Shut down dialog */
66 } dlg_msg_t;
68 /* Flags for create_dlg */
69 typedef enum
71 DLG_REVERSE = (1 << 5), /* Tab order is opposite to the add order */
72 DLG_WANT_TAB = (1 << 4), /* Should the tab key be sent to the dialog? */
73 DLG_WANT_IDLE = (1 << 3), /* Dialog wants idle events */
74 DLG_COMPACT = (1 << 2), /* Suppress spaces around the frame */
75 DLG_TRYUP = (1 << 1), /* Try to move two lines up the dialog */
76 DLG_CENTER = (1 << 0), /* Center the dialog */
77 DLG_NONE = 0 /* No options */
78 } dlg_flags_t;
80 /* Dialog state */
81 typedef enum
83 DLG_ACTIVE = 0, /* Dialog is visible and active */
84 DLG_SUSPENDED = 1, /* Dialog is suspended */
85 DLG_CLOSED = 2 /* Dialog is closed */
86 } dlg_state_t;
88 /* Dialog color constants */
89 typedef enum
91 DLG_COLOR_NORMAL,
92 DLG_COLOR_FOCUS,
93 DLG_COLOR_HOT_NORMAL,
94 DLG_COLOR_HOT_FOCUS,
95 DLG_COLOR_TITLE,
96 DLG_COLOR_COUNT
97 } dlg_colors_enum_t;
99 /*** typedefs(not structures) ********************************************************************/
101 /* get string representation of shortcut assigned with command */
102 /* as menu is a widget of dialog, ask dialog about shortcut string */
103 typedef char *(*dlg_shortcut_str) (unsigned long command);
105 /* get dialog name to show in dialog list */
106 typedef char *(*dlg_title_str) (const Dlg_head * h, size_t len);
108 typedef int dlg_colors_t[DLG_COLOR_COUNT];
110 /* Dialog callback */
111 typedef cb_ret_t (*dlg_cb_fn) (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data);
113 /* menu command execution */
114 typedef cb_ret_t (*menu_exec_fn) (int command);
116 /*** structures declarations (and typedefs of structures)*****************************************/
118 struct Dlg_head
120 /* Set by the user */
121 gboolean modal; /* type of dialog: modal or not */
122 dlg_flags_t flags; /* User flags */
123 const char *help_ctx; /* Name of the help entry */
124 dlg_colors_t color; /* Color set. Unused in viewer and editor */
125 char *title; /* Title of the dialog */
127 /* Set and received by the user */
128 int ret_value; /* Result of run_dlg() */
130 /* Geometry */
131 int x, y; /* Position relative to screen origin */
132 int cols, lines; /* Width and height of the window */
134 /* Internal flags */
135 dlg_state_t state;
136 gboolean fullscreen; /* Parents dialogs don't need refresh */
137 gboolean winch_pending; /* SIGWINCH signal has been got. Resize dialog after rise */
138 int mouse_status; /* For the autorepeat status of the mouse */
140 /* Internal variables */
141 GList *widgets; /* widgets list */
142 GList *current; /* Curently active widget */
143 void *data; /* Data can be passed to dialog */
144 char *event_group; /* Name of event group for this dialog */
146 dlg_cb_fn callback;
147 dlg_shortcut_str get_shortcut; /* Shortcut string */
148 dlg_title_str get_title; /* useless for modal dialogs */
151 /*** global variables defined in .c file *********************************************************/
153 /* Color styles for normal and error dialogs */
154 extern dlg_colors_t dialog_colors;
155 extern dlg_colors_t alarm_colors;
157 extern GList *top_dlg;
159 /* A hook list for idle events */
160 extern hook_t *idle_hook;
162 extern int fast_refresh;
163 extern int mouse_close_dialog;
165 extern const global_keymap_t *dialog_map;
167 /*** declarations of public functions ************************************************************/
169 /* draw box in window */
170 void draw_box (Dlg_head * h, int y, int x, int ys, int xs, gboolean single);
172 /* Creates a dialog head */
173 Dlg_head *create_dlg (gboolean modal, int y1, int x1, int lines, int cols,
174 const int *colors, dlg_cb_fn callback,
175 const char *help_ctx, const char *title, dlg_flags_t flags);
177 void dlg_set_default_colors (void);
179 int add_widget_autopos (Dlg_head * dest, void *w, widget_pos_flags_t pos_flags);
180 int add_widget (Dlg_head * dest, void *w);
182 /* sets size of dialog, leaving positioning to automatic mehtods
183 according to dialog flags */
184 void dlg_set_size (Dlg_head * h, int lines, int cols);
185 /* this function allows to set dialog position */
186 void dlg_set_position (Dlg_head * h, int y1, int x1, int y2, int x2);
188 void init_dlg (Dlg_head * h);
189 int run_dlg (Dlg_head * d);
190 void destroy_dlg (Dlg_head * h);
192 void dlg_run_done (Dlg_head * h);
193 void dlg_save_history (Dlg_head * h);
194 void dlg_process_event (Dlg_head * h, int key, Gpm_Event * event);
196 char *dlg_get_title (const Dlg_head * h, size_t len);
198 /* To activate/deactivate the idle message generation */
199 void set_idle_proc (Dlg_head * d, int enable);
201 void dlg_redraw (Dlg_head * h);
203 void dlg_broadcast_msg (Dlg_head * h, widget_msg_t message, gboolean reverse);
205 /* Default callback for dialogs */
206 cb_ret_t default_dlg_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data);
208 /* Default paint routine for dialogs */
209 void common_dialog_repaint (Dlg_head * h);
211 void dlg_replace_widget (Widget * old, Widget * new);
212 int dlg_overlap (Widget * a, Widget * b);
213 void dlg_erase (Dlg_head * h);
214 void dlg_stop (Dlg_head * h);
216 /* Widget selection */
217 void dlg_select_widget (void *widget);
218 void dlg_one_up (Dlg_head * h);
219 void dlg_one_down (Dlg_head * h);
220 int dlg_focus (Dlg_head * h);
221 Widget *find_widget_type (const Dlg_head * h, callback_fn callback);
222 Widget *dlg_find_by_id (const Dlg_head * h, unsigned int id);
223 void dlg_select_by_id (const Dlg_head * h, unsigned int id);
225 /* Redraw all dialogs */
226 void do_refresh (void);
228 /* Used in load_prompt() */
229 void update_cursor (Dlg_head * h);
231 /*** inline functions ****************************************************************************/
233 /* Return TRUE if the widget is active, FALSE otherwise */
234 static inline gboolean
235 dlg_widget_active (void *w)
237 Widget *w1 = (Widget *) w;
238 return ((Widget *) w1->owner->current->data == w1);
242 static inline unsigned int
243 dlg_get_current_widget_id (const struct Dlg_head *h)
245 return ((Widget *) h->current->data)->id;
248 #endif /* MC__DIALOG_H */