Updated Russian translation.
[midnight-commander.git] / lib / widget / dialog.h
blob22f00ff5c92c4aec3267fa5988badb7c8a2ecfb2
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 */
35 /*** defined constants ***************************************************************************/
37 /* Common return values */
38 #define B_EXIT 0
39 #define B_CANCEL 1
40 #define B_ENTER 2
41 #define B_HELP 3
42 #define B_USER 100
44 #define dlg_move(h, _y, _x) tty_gotoyx (((Dlg_head *)(h))->y + _y, ((Dlg_head *)(h))->x + _x)
46 /*** enums ***************************************************************************************/
48 /* Dialog messages */
49 typedef enum
51 DLG_INIT = 0, /* Initialize dialog */
52 DLG_IDLE = 1, /* The idle state is active */
53 DLG_DRAW = 2, /* Draw dialog on screen */
54 DLG_FOCUS = 3, /* A widget has got focus */
55 DLG_UNFOCUS = 4, /* A widget has been unfocused */
56 DLG_RESIZE = 5, /* Window size has changed */
57 DLG_KEY = 6, /* Key before sending to widget */
58 DLG_HOTKEY_HANDLED = 7, /* A widget has got the hotkey */
59 DLG_POST_KEY = 8, /* The key has been handled */
60 DLG_UNHANDLED_KEY = 9, /* Key that no widget handled */
61 DLG_ACTION = 10, /* State of check- and radioboxes has changed
62 * and listbox current entry has changed */
63 DLG_VALIDATE = 11, /* Dialog is to be closed */
64 DLG_END = 12 /* Shut down dialog */
65 } dlg_msg_t;
67 /* Flags for create_dlg */
68 typedef enum
70 DLG_REVERSE = (1 << 5), /* Tab order is opposite to the add order */
71 DLG_WANT_TAB = (1 << 4), /* Should the tab key be sent to the dialog? */
72 DLG_WANT_IDLE = (1 << 3), /* Dialog wants idle events */
73 DLG_COMPACT = (1 << 2), /* Suppress spaces around the frame */
74 DLG_TRYUP = (1 << 1), /* Try to move two lines up the dialog */
75 DLG_CENTER = (1 << 0), /* Center the dialog */
76 DLG_NONE = 0 /* No options */
77 } dlg_flags_t;
79 /* Dialog state */
80 typedef enum
82 DLG_ACTIVE = 0, /* Dialog is visible and active */
83 DLG_SUSPENDED = 1, /* Dialog is suspended */
84 DLG_CLOSED = 2 /* Dialog is closed */
85 } dlg_state_t;
87 /* Dialog color constants */
88 typedef enum
90 DLG_COLOR_NORMAL,
91 DLG_COLOR_FOCUS,
92 DLG_COLOR_HOT_NORMAL,
93 DLG_COLOR_HOT_FOCUS,
94 DLG_COLOR_TITLE,
95 DLG_COLOR_COUNT
96 } dlg_colors_enum_t;
98 /*** typedefs(not structures) ********************************************************************/
100 /* get string representation of shortcut assigned with command */
101 /* as menu is a widget of dialog, ask dialog about shortcut string */
102 typedef char *(*dlg_shortcut_str) (unsigned long command);
104 /* get dialog name to show in dialog list */
105 typedef char *(*dlg_title_str) (const Dlg_head * h, size_t len);
107 typedef int dlg_colors_t[DLG_COLOR_COUNT];
109 /* Dialog callback */
110 typedef cb_ret_t (*dlg_cb_fn) (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data);
112 /* menu command execution */
113 typedef cb_ret_t (*menu_exec_fn) (int command);
115 /*** structures declarations (and typedefs of structures)*****************************************/
117 struct Dlg_head
119 /* Set by the user */
120 gboolean modal; /* type of dialog: modal or not */
121 dlg_flags_t flags; /* User flags */
122 const char *help_ctx; /* Name of the help entry */
123 dlg_colors_t color; /* Color set. Unused in viewer and editor */
124 char *title; /* Title of the dialog */
126 /* Set and received by the user */
127 int ret_value; /* Result of run_dlg() */
129 /* Geometry */
130 int x, y; /* Position relative to screen origin */
131 int cols, lines; /* Width and height of the window */
133 /* Internal flags */
134 dlg_state_t state;
135 gboolean fullscreen; /* Parents dialogs don't need refresh */
136 gboolean winch_pending; /* SIGWINCH signal has been got. Resize dialog after rise */
137 int mouse_status; /* For the autorepeat status of the mouse */
139 /* Internal variables */
140 GList *widgets; /* widgets list */
141 GList *current; /* Curently active widget */
142 void *data; /* Data can be passed to dialog */
144 dlg_cb_fn callback;
145 dlg_shortcut_str get_shortcut; /* Shortcut string */
146 dlg_title_str get_title; /* useless for modal dialogs */
149 /*** global variables defined in .c file *********************************************************/
151 /* Color styles for normal and error dialogs */
152 extern dlg_colors_t dialog_colors;
153 extern dlg_colors_t alarm_colors;
155 extern GList *top_dlg;
157 /* A hook list for idle events */
158 extern hook_t *idle_hook;
160 extern int fast_refresh;
161 extern int mouse_close_dialog;
163 /*** declarations of public functions ************************************************************/
165 /* draw box in window */
166 void draw_box (Dlg_head * h, int y, int x, int ys, int xs, gboolean single);
168 /* Creates a dialog head */
169 Dlg_head *create_dlg (gboolean modal, int y1, int x1, int lines, int cols,
170 const int *colors, dlg_cb_fn callback,
171 const char *help_ctx, const char *title, dlg_flags_t flags);
173 void dlg_set_default_colors (void);
175 int add_widget_autopos (Dlg_head * dest, void *w, widget_pos_flags_t pos_flags);
176 int add_widget (Dlg_head * dest, void *w);
178 /* sets size of dialog, leaving positioning to automatic mehtods
179 according to dialog flags */
180 void dlg_set_size (Dlg_head * h, int lines, int cols);
181 /* this function allows to set dialog position */
182 void dlg_set_position (Dlg_head * h, int y1, int x1, int y2, int x2);
184 void init_dlg (Dlg_head * h);
185 int run_dlg (Dlg_head * d);
186 void destroy_dlg (Dlg_head * h);
188 void dlg_run_done (Dlg_head * h);
189 void dlg_process_event (Dlg_head * h, int key, Gpm_Event * event);
191 char *dlg_get_title (const Dlg_head * h, size_t len);
193 /* To activate/deactivate the idle message generation */
194 void set_idle_proc (Dlg_head * d, int enable);
196 void dlg_redraw (Dlg_head * h);
198 void dlg_broadcast_msg (Dlg_head * h, widget_msg_t message, gboolean reverse);
200 /* Default callback for dialogs */
201 cb_ret_t default_dlg_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data);
203 /* Default paint routine for dialogs */
204 void common_dialog_repaint (Dlg_head * h);
206 void dlg_replace_widget (Widget * old, Widget * new);
207 int dlg_overlap (Widget * a, Widget * b);
208 void dlg_erase (Dlg_head * h);
209 void dlg_stop (Dlg_head * h);
211 /* Widget selection */
212 void dlg_select_widget (void *widget);
213 void dlg_one_up (Dlg_head * h);
214 void dlg_one_down (Dlg_head * h);
215 int dlg_focus (Dlg_head * h);
216 Widget *find_widget_type (const Dlg_head * h, callback_fn callback);
217 Widget *dlg_find_by_id (const Dlg_head * h, unsigned int id);
218 void dlg_select_by_id (const Dlg_head * h, unsigned int id);
220 /* Redraw all dialogs */
221 void do_refresh (void);
223 /* Used in load_prompt() */
224 void update_cursor (Dlg_head * h);
226 /*** inline functions ****************************************************************************/
228 /* Return TRUE if the widget is active, FALSE otherwise */
229 static inline gboolean
230 dlg_widget_active (void *w)
232 Widget *w1 = (Widget *) w;
233 return ((Widget *) w1->owner->current->data == w1);
237 static inline unsigned int
238 dlg_get_current_widget_id (const struct Dlg_head *h)
240 return ((Widget *) h->current->data)->id;
243 #endif /* MC__DIALOG_H */