2 * $Id: msgbox.c,v 1.66 2011/06/27 08:36:28 tom Exp $
4 * msgbox.c -- implements the message box and info box
6 * Copyright 2000-2010,2011 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 message box. Program will pause and display an "OK" button
32 * if the parameter 'pauseopt' is non-zero.
35 dialog_msgbox(const char *title, const char *cprompt, int height, int width,
39 static DLG_KEYS_BINDING binding[] = {
42 DLG_KEYS_DATA( DLGK_ENTER, ' ' ),
44 DLG_KEYS_DATA( DLGK_FIELD_NEXT, KEY_DOWN ),
45 DLG_KEYS_DATA( DLGK_FIELD_NEXT, KEY_RIGHT ),
46 DLG_KEYS_DATA( DLGK_FIELD_NEXT, TAB ),
47 DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_UP ),
48 DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_BTAB ),
49 DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_LEFT ),
54 int x, y, last = 0, page;
57 int result = DLG_EXIT_UNKNOWN;
59 char *prompt = dlg_strclone(cprompt);
60 const char **buttons = dlg_ok_label();
64 int min_width = (pauseopt == 1 ? 12 : 0);
67 int req_high = height;
72 dlg_button_layout(buttons, &min_width);
74 dlg_tab_correct_str(prompt);
75 dlg_auto_size(title, prompt, &height, &width,
76 (pauseopt == 1 ? 2 : 0),
78 dlg_print_size(height, width);
79 dlg_ctl_size(height, width);
81 x = dlg_box_x_ordinate(width);
82 y = dlg_box_y_ordinate(height);
86 dlg_move_window(dialog, height, width, y, x);
90 dialog = dlg_new_window(height, width, y, x);
91 dlg_register_window(dialog, "msgbox", binding);
92 dlg_register_buttons(dialog, "msgbox", buttons);
94 page = height - (1 + 3 * MARGIN);
96 dlg_mouse_setbase(x, y);
98 dlg_draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
99 dlg_draw_title(dialog, title);
101 wattrset(dialog, dialog_attr);
104 dlg_draw_bottom_box(dialog);
105 mouse_mkbutton(height - 2, width / 2 - 4, 6, '\n');
106 dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width);
107 dlg_draw_helpline(dialog, FALSE);
109 while (result == DLG_EXIT_UNKNOWN) {
111 last = dlg_print_scrolled(dialog, prompt, offset,
112 page, width, pauseopt);
115 key = dlg_mouse_wgetch(dialog, &fkey);
116 if (dlg_result_key(key, fkey, &result))
119 if (!fkey && (check = dlg_char_to_button(key, buttons)) >= 0) {
120 result = check ? DLG_EXIT_HELP : DLG_EXIT_OK;
134 case DLGK_FIELD_NEXT:
135 button = dlg_next_button(buttons, button);
138 dlg_draw_buttons(dialog,
143 case DLGK_FIELD_PREV:
144 button = dlg_prev_button(buttons, button);
147 dlg_draw_buttons(dialog,
153 result = button ? DLG_EXIT_HELP : DLG_EXIT_OK;
156 result = DLG_EXIT_OK;
159 result = DLG_EXIT_HELP;
162 if (dlg_check_scrolled(key,
176 dlg_print_scrolled(dialog, prompt, offset, page, width, pauseopt);
177 dlg_draw_helpline(dialog, FALSE);
179 result = DLG_EXIT_OK;
182 dlg_del_window(dialog);
183 dlg_mouse_free_regions();