2 * $Id: msgbox.c,v 1.64 2010/01/15 10:50:17 tom Exp $
4 * msgbox.c -- implements the message box and info box
6 * Copyright 2000-2009,2010 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[] = {
41 DLG_KEYS_DATA( DLGK_ENTER, ' ' ),
43 DLG_KEYS_DATA( DLGK_FIELD_NEXT, KEY_DOWN ),
44 DLG_KEYS_DATA( DLGK_FIELD_NEXT, KEY_RIGHT ),
45 DLG_KEYS_DATA( DLGK_FIELD_NEXT, TAB ),
46 DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_UP ),
47 DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_BTAB ),
48 DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_LEFT ),
53 int x, y, last = 0, page;
56 int result = DLG_EXIT_UNKNOWN;
58 char *prompt = dlg_strclone(cprompt);
59 const char **buttons = dlg_ok_label();
63 int min_width = (pauseopt == 1 ? 12 : 0);
66 int req_high = height;
71 dlg_button_layout(buttons, &min_width);
73 dlg_tab_correct_str(prompt);
74 dlg_auto_size(title, prompt, &height, &width,
75 (pauseopt == 1 ? 2 : 0),
77 dlg_print_size(height, width);
78 dlg_ctl_size(height, width);
80 x = dlg_box_x_ordinate(width);
81 y = dlg_box_y_ordinate(height);
85 dlg_move_window(dialog, height, width, y, x);
89 dialog = dlg_new_window(height, width, y, x);
90 dlg_register_window(dialog, "msgbox", binding);
91 dlg_register_buttons(dialog, "msgbox", buttons);
93 page = height - (1 + 3 * MARGIN);
95 dlg_mouse_setbase(x, y);
97 dlg_draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
98 dlg_draw_title(dialog, title);
100 wattrset(dialog, dialog_attr);
103 dlg_draw_bottom_box(dialog);
104 mouse_mkbutton(height - 2, width / 2 - 4, 6, '\n');
105 dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width);
107 while (result == DLG_EXIT_UNKNOWN) {
109 last = dlg_print_scrolled(dialog, prompt, offset,
110 page, width, pauseopt);
113 key = dlg_mouse_wgetch(dialog, &fkey);
114 if (dlg_result_key(key, fkey, &result))
117 if (!fkey && (check = dlg_char_to_button(key, buttons)) >= 0) {
118 result = check ? DLG_EXIT_HELP : DLG_EXIT_OK;
132 case DLGK_FIELD_NEXT:
133 button = dlg_next_button(buttons, button);
136 dlg_draw_buttons(dialog,
141 case DLGK_FIELD_PREV:
142 button = dlg_prev_button(buttons, button);
145 dlg_draw_buttons(dialog,
151 result = button ? DLG_EXIT_HELP : DLG_EXIT_OK;
154 result = DLG_EXIT_OK;
157 result = DLG_EXIT_HELP;
160 if (dlg_check_scrolled(key,
174 dlg_print_scrolled(dialog, prompt, offset, page, width, pauseopt);
176 result = DLG_EXIT_OK;
179 dlg_del_window(dialog);
180 dlg_mouse_free_regions();