2 * $Id: yesno.c,v 1.57 2012/12/01 01:48:21 tom Exp $
4 * yesno.c -- implements the yes/no box
6 * Copyright 1999-2011,2012 Thomas E. Dickey
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License, version 2.1
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program; if not, write to
19 * Free Software Foundation, Inc.
20 * 51 Franklin St., Fifth Floor
21 * Boston, MA 02110, USA.
23 * An earlier version of this program lists as authors
24 * Savio Lam (lam836@cs.cuhk.hk)
31 * Display a dialog box with two buttons - Yes and No.
34 dialog_yesno(const char *title
, const char *cprompt
, int height
, int width
)
37 static DLG_KEYS_BINDING binding
[] = {
49 int button
= dlg_default_button();
51 int result
= DLG_EXIT_UNKNOWN
;
52 char *prompt
= dlg_strclone(cprompt
);
53 const char **buttons
= dlg_yes_labels();
56 int page
, last
= 0, offset
= 0;
59 int req_high
= height
;
64 dlg_tab_correct_str(prompt
);
65 dlg_button_layout(buttons
, &min_width
);
66 dlg_auto_size(title
, prompt
, &height
, &width
, 2, min_width
);
67 dlg_print_size(height
, width
);
68 dlg_ctl_size(height
, width
);
70 x
= dlg_box_x_ordinate(width
);
71 y
= dlg_box_y_ordinate(height
);
75 dlg_move_window(dialog
, height
, width
, y
, x
);
79 dialog
= dlg_new_window(height
, width
, y
, x
);
80 dlg_register_window(dialog
, "yesno", binding
);
81 dlg_register_buttons(dialog
, "yesno", buttons
);
84 dlg_draw_box2(dialog
, 0, 0, height
, width
, dialog_attr
, border_attr
, border2_attr
);
85 dlg_draw_bottom_box2(dialog
, border_attr
, border2_attr
, dialog_attr
);
86 dlg_draw_title(dialog
, title
);
87 dlg_draw_helpline(dialog
, FALSE
);
89 (void) wattrset(dialog
, dialog_attr
);
91 page
= height
- (1 + 3 * MARGIN
);
92 dlg_draw_buttons(dialog
,
93 height
- 2 * MARGIN
, 0,
94 buttons
, button
, FALSE
, width
);
96 while (result
== DLG_EXIT_UNKNOWN
) {
98 last
= dlg_print_scrolled(dialog
, prompt
, offset
,
100 dlg_trace_win(dialog
);
103 key
= dlg_mouse_wgetch(dialog
, &fkey
);
104 if (dlg_result_key(key
, fkey
, &result
))
106 if ((code
= dlg_char_to_button(key
, buttons
)) >= 0) {
107 result
= dlg_ok_buttoncode(code
);
110 /* handle function keys */
113 case DLGK_FIELD_NEXT
:
114 button
= dlg_next_button(buttons
, button
);
117 dlg_draw_buttons(dialog
,
122 case DLGK_FIELD_PREV
:
123 button
= dlg_prev_button(buttons
, button
);
126 dlg_draw_buttons(dialog
,
132 result
= dlg_yes_buttoncode(button
);
142 if (is_DLGK_MOUSE(key
)) {
143 result
= dlg_yes_buttoncode(key
- M_EVENT
);
145 result
= DLG_EXIT_OK
;
146 } else if (dlg_check_scrolled(key
, last
, page
,
147 &show
, &offset
) != 0) {
157 dlg_del_window(dialog
);
158 dlg_mouse_free_regions();