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.
24 * \brief Header: dialog box features module
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 */
45 #define dlg_move(h, _y, _x) tty_gotoyx (((Dlg_head *)(h))->y + _y, ((Dlg_head *)(h))->x + _x)
47 /*** enums ***************************************************************************************/
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 */
68 /* Flags for create_dlg */
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 */
83 DLG_ACTIVE
= 0, /* Dialog is visible and active */
84 DLG_SUSPENDED
= 1, /* Dialog is suspended */
85 DLG_CLOSED
= 2 /* Dialog is closed */
88 /* Dialog color constants */
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)*****************************************/
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() */
131 int x
, y
; /* Position relative to screen origin */
132 int cols
, lines
; /* Width and height of the window */
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 */
146 dlg_shortcut_str get_shortcut
; /* Shortcut string */
147 dlg_title_str get_title
; /* useless for modal dialogs */
150 /*** global variables defined in .c file *********************************************************/
152 /* Color styles for normal and error dialogs */
153 extern dlg_colors_t dialog_colors
;
154 extern dlg_colors_t alarm_colors
;
156 extern GList
*top_dlg
;
158 /* A hook list for idle events */
159 extern hook_t
*idle_hook
;
161 extern int fast_refresh
;
162 extern int mouse_close_dialog
;
164 extern const global_keymap_t
*dialog_map
;
166 /*** declarations of public functions ************************************************************/
168 /* draw box in window */
169 void draw_box (Dlg_head
* h
, int y
, int x
, int ys
, int xs
, gboolean single
);
171 /* Creates a dialog head */
172 Dlg_head
*create_dlg (gboolean modal
, int y1
, int x1
, int lines
, int cols
,
173 const int *colors
, dlg_cb_fn callback
,
174 const char *help_ctx
, const char *title
, dlg_flags_t flags
);
176 void dlg_set_default_colors (void);
178 int add_widget_autopos (Dlg_head
* dest
, void *w
, widget_pos_flags_t pos_flags
);
179 int add_widget (Dlg_head
* dest
, void *w
);
181 /* sets size of dialog, leaving positioning to automatic mehtods
182 according to dialog flags */
183 void dlg_set_size (Dlg_head
* h
, int lines
, int cols
);
184 /* this function allows to set dialog position */
185 void dlg_set_position (Dlg_head
* h
, int y1
, int x1
, int y2
, int x2
);
187 void init_dlg (Dlg_head
* h
);
188 int run_dlg (Dlg_head
* d
);
189 void destroy_dlg (Dlg_head
* h
);
191 void dlg_run_done (Dlg_head
* h
);
192 void dlg_process_event (Dlg_head
* h
, int key
, Gpm_Event
* event
);
194 char *dlg_get_title (const Dlg_head
* h
, size_t len
);
196 /* To activate/deactivate the idle message generation */
197 void set_idle_proc (Dlg_head
* d
, int enable
);
199 void dlg_redraw (Dlg_head
* h
);
201 void dlg_broadcast_msg (Dlg_head
* h
, widget_msg_t message
, gboolean reverse
);
203 /* Default callback for dialogs */
204 cb_ret_t
default_dlg_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
);
206 /* Default paint routine for dialogs */
207 void common_dialog_repaint (Dlg_head
* h
);
209 void dlg_replace_widget (Widget
* old
, Widget
* new);
210 int dlg_overlap (Widget
* a
, Widget
* b
);
211 void dlg_erase (Dlg_head
* h
);
212 void dlg_stop (Dlg_head
* h
);
214 /* Widget selection */
215 void dlg_select_widget (void *widget
);
216 void dlg_one_up (Dlg_head
* h
);
217 void dlg_one_down (Dlg_head
* h
);
218 int dlg_focus (Dlg_head
* h
);
219 Widget
*find_widget_type (const Dlg_head
* h
, callback_fn callback
);
220 Widget
*dlg_find_by_id (const Dlg_head
* h
, unsigned int id
);
221 void dlg_select_by_id (const Dlg_head
* h
, unsigned int id
);
223 /* Redraw all dialogs */
224 void do_refresh (void);
226 /* Used in load_prompt() */
227 void update_cursor (Dlg_head
* h
);
229 /*** inline functions ****************************************************************************/
231 /* Return TRUE if the widget is active, FALSE otherwise */
232 static inline gboolean
233 dlg_widget_active (void *w
)
235 Widget
*w1
= (Widget
*) w
;
236 return ((Widget
*) w1
->owner
->current
->data
== w1
);
240 static inline unsigned int
241 dlg_get_current_widget_id (const struct Dlg_head
*h
)
243 return ((Widget
*) h
->current
->data
)->id
;
246 #endif /* MC__DIALOG_H */