2011-01-13 02:21:23 +00:00
|
|
|
/*
|
2021-02-26 09:05:35 +00:00
|
|
|
* $Id: msgbox.c,v 1.89 2020/11/23 00:32:02 tom Exp $
|
2011-01-13 02:21:23 +00:00
|
|
|
*
|
|
|
|
* msgbox.c -- implements the message box and info box
|
|
|
|
*
|
2021-02-26 09:05:35 +00:00
|
|
|
* Copyright 2000-2019,2020 Thomas E. Dickey
|
2011-01-13 02:21:23 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License, version 2.1
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this program; if not, write to
|
|
|
|
* Free Software Foundation, Inc.
|
|
|
|
* 51 Franklin St., Fifth Floor
|
|
|
|
* Boston, MA 02110, USA.
|
|
|
|
*
|
|
|
|
* An earlier version of this program lists as authors:
|
|
|
|
* Savio Lam (lam836@cs.cuhk.hk)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <dialog.h>
|
|
|
|
#include <dlg_keys.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Display a message box. Program will pause and display an "OK" button
|
|
|
|
* if the parameter 'pauseopt' is non-zero.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
dialog_msgbox(const char *title, const char *cprompt, int height, int width,
|
|
|
|
int pauseopt)
|
|
|
|
{
|
|
|
|
/* *INDENT-OFF* */
|
|
|
|
static DLG_KEYS_BINDING binding[] = {
|
2011-07-14 13:57:13 +00:00
|
|
|
HELPKEY_BINDINGS,
|
2011-01-13 02:21:23 +00:00
|
|
|
ENTERKEY_BINDINGS,
|
|
|
|
SCROLLKEY_BINDINGS,
|
2018-10-20 20:32:57 +00:00
|
|
|
TRAVERSE_BINDINGS,
|
2011-01-13 02:21:23 +00:00
|
|
|
END_KEYS_BINDING
|
|
|
|
};
|
|
|
|
/* *INDENT-ON* */
|
|
|
|
|
2021-02-26 09:05:35 +00:00
|
|
|
int x, y, page;
|
2012-10-21 18:18:09 +00:00
|
|
|
int button;
|
2021-02-26 09:05:35 +00:00
|
|
|
int key, fkey;
|
2011-01-13 02:21:23 +00:00
|
|
|
int result = DLG_EXIT_UNKNOWN;
|
|
|
|
WINDOW *dialog = 0;
|
2018-10-20 20:32:57 +00:00
|
|
|
char *prompt;
|
2011-01-13 02:21:23 +00:00
|
|
|
const char **buttons = dlg_ok_label();
|
|
|
|
int offset = 0;
|
|
|
|
bool show = TRUE;
|
|
|
|
int min_width = (pauseopt == 1 ? 12 : 0);
|
2018-10-20 20:32:57 +00:00
|
|
|
bool save_nocancel = dialog_vars.nocancel;
|
2012-10-21 18:18:09 +00:00
|
|
|
#ifdef KEY_RESIZE
|
|
|
|
int req_high;
|
|
|
|
int req_wide;
|
|
|
|
#endif
|
|
|
|
|
2018-10-20 20:32:57 +00:00
|
|
|
DLG_TRACE(("# msgbox args:\n"));
|
|
|
|
DLG_TRACE2S("title", title);
|
|
|
|
DLG_TRACE2S("message", cprompt);
|
|
|
|
DLG_TRACE2N("height", height);
|
|
|
|
DLG_TRACE2N("width", width);
|
|
|
|
DLG_TRACE2N("pauseopt", pauseopt);
|
|
|
|
|
2012-10-21 18:18:09 +00:00
|
|
|
dialog_vars.nocancel = TRUE;
|
|
|
|
button = dlg_default_button();
|
2011-01-13 02:21:23 +00:00
|
|
|
|
|
|
|
#ifdef KEY_RESIZE
|
2012-10-21 18:18:09 +00:00
|
|
|
req_high = height;
|
|
|
|
req_wide = width;
|
2011-01-13 02:21:23 +00:00
|
|
|
restart:
|
|
|
|
#endif
|
|
|
|
|
|
|
|
dlg_button_layout(buttons, &min_width);
|
|
|
|
|
2018-10-20 20:32:57 +00:00
|
|
|
prompt = dlg_strclone(cprompt);
|
2011-01-13 02:21:23 +00:00
|
|
|
dlg_tab_correct_str(prompt);
|
|
|
|
dlg_auto_size(title, prompt, &height, &width,
|
|
|
|
(pauseopt == 1 ? 2 : 0),
|
|
|
|
min_width);
|
|
|
|
dlg_print_size(height, width);
|
|
|
|
dlg_ctl_size(height, width);
|
|
|
|
|
|
|
|
x = dlg_box_x_ordinate(width);
|
|
|
|
y = dlg_box_y_ordinate(height);
|
|
|
|
|
2021-02-26 09:05:35 +00:00
|
|
|
dialog = dlg_new_window(height, width, y, x);
|
|
|
|
dlg_register_window(dialog, "msgbox", binding);
|
|
|
|
dlg_register_buttons(dialog, "msgbox", buttons);
|
|
|
|
|
2011-01-13 02:21:23 +00:00
|
|
|
page = height - (1 + 3 * MARGIN);
|
|
|
|
|
|
|
|
dlg_mouse_setbase(x, y);
|
|
|
|
|
2012-10-21 18:18:09 +00:00
|
|
|
dlg_draw_box2(dialog, 0, 0, height, width, dialog_attr, border_attr, border2_attr);
|
2011-01-13 02:21:23 +00:00
|
|
|
dlg_draw_title(dialog, title);
|
|
|
|
|
2018-10-20 20:32:57 +00:00
|
|
|
dlg_attrset(dialog, dialog_attr);
|
2011-01-13 02:21:23 +00:00
|
|
|
|
|
|
|
if (pauseopt) {
|
2021-02-26 09:05:35 +00:00
|
|
|
int last = 0;
|
|
|
|
|
2012-10-21 18:18:09 +00:00
|
|
|
dlg_draw_bottom_box2(dialog, border_attr, border2_attr, dialog_attr);
|
2011-01-13 02:21:23 +00:00
|
|
|
mouse_mkbutton(height - 2, width / 2 - 4, 6, '\n');
|
|
|
|
dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width);
|
2011-07-14 13:57:13 +00:00
|
|
|
dlg_draw_helpline(dialog, FALSE);
|
2011-01-13 02:21:23 +00:00
|
|
|
|
|
|
|
while (result == DLG_EXIT_UNKNOWN) {
|
2021-02-26 09:05:35 +00:00
|
|
|
int check;
|
|
|
|
|
2011-01-13 02:21:23 +00:00
|
|
|
if (show) {
|
|
|
|
last = dlg_print_scrolled(dialog, prompt, offset,
|
|
|
|
page, width, pauseopt);
|
2012-10-21 18:18:09 +00:00
|
|
|
dlg_trace_win(dialog);
|
2011-01-13 02:21:23 +00:00
|
|
|
show = FALSE;
|
|
|
|
}
|
|
|
|
key = dlg_mouse_wgetch(dialog, &fkey);
|
2021-02-26 09:05:35 +00:00
|
|
|
if (dlg_result_key(key, fkey, &result)) {
|
|
|
|
if (!dlg_button_key(result, &button, &key, &fkey))
|
|
|
|
break;
|
|
|
|
}
|
2011-01-13 02:21:23 +00:00
|
|
|
if (!fkey && (check = dlg_char_to_button(key, buttons)) >= 0) {
|
2012-10-21 18:18:09 +00:00
|
|
|
result = dlg_ok_buttoncode(check);
|
2011-01-13 02:21:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fkey) {
|
|
|
|
switch (key) {
|
|
|
|
#ifdef KEY_RESIZE
|
|
|
|
case KEY_RESIZE:
|
2018-10-20 20:32:57 +00:00
|
|
|
dlg_will_resize(dialog);
|
|
|
|
free(prompt);
|
2011-01-13 02:21:23 +00:00
|
|
|
height = req_high;
|
|
|
|
width = req_wide;
|
|
|
|
show = TRUE;
|
2021-02-26 09:05:35 +00:00
|
|
|
_dlg_resize_cleanup(dialog);
|
2011-01-13 02:21:23 +00:00
|
|
|
goto restart;
|
|
|
|
#endif
|
|
|
|
case DLGK_FIELD_NEXT:
|
|
|
|
button = dlg_next_button(buttons, button);
|
|
|
|
if (button < 0)
|
|
|
|
button = 0;
|
|
|
|
dlg_draw_buttons(dialog,
|
|
|
|
height - 2, 0,
|
|
|
|
buttons, button,
|
|
|
|
FALSE, width);
|
|
|
|
break;
|
|
|
|
case DLGK_FIELD_PREV:
|
|
|
|
button = dlg_prev_button(buttons, button);
|
|
|
|
if (button < 0)
|
|
|
|
button = 0;
|
|
|
|
dlg_draw_buttons(dialog,
|
|
|
|
height - 2, 0,
|
|
|
|
buttons, button,
|
|
|
|
FALSE, width);
|
|
|
|
break;
|
|
|
|
case DLGK_ENTER:
|
2021-02-26 09:05:35 +00:00
|
|
|
result = dlg_enter_buttoncode(button);
|
|
|
|
break;
|
|
|
|
case DLGK_LEAVE:
|
2012-10-21 18:18:09 +00:00
|
|
|
result = dlg_ok_buttoncode(button);
|
2011-01-13 02:21:23 +00:00
|
|
|
break;
|
|
|
|
default:
|
2012-10-21 18:18:09 +00:00
|
|
|
if (is_DLGK_MOUSE(key)) {
|
|
|
|
result = dlg_ok_buttoncode(key - M_EVENT);
|
|
|
|
if (result < 0)
|
|
|
|
result = DLG_EXIT_OK;
|
|
|
|
} else if (dlg_check_scrolled(key,
|
|
|
|
last,
|
|
|
|
page,
|
|
|
|
&show,
|
|
|
|
&offset) == 0) {
|
|
|
|
} else {
|
|
|
|
beep();
|
|
|
|
}
|
2011-01-13 02:21:23 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-02-26 09:05:35 +00:00
|
|
|
} else if (key > 0) {
|
2011-01-13 02:21:23 +00:00
|
|
|
beep();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dlg_print_scrolled(dialog, prompt, offset, page, width, pauseopt);
|
2011-07-14 13:57:13 +00:00
|
|
|
dlg_draw_helpline(dialog, FALSE);
|
2011-01-13 02:21:23 +00:00
|
|
|
wrefresh(dialog);
|
2012-10-21 18:18:09 +00:00
|
|
|
dlg_trace_win(dialog);
|
2011-01-13 02:21:23 +00:00
|
|
|
result = DLG_EXIT_OK;
|
|
|
|
}
|
2021-02-26 09:05:35 +00:00
|
|
|
dlg_add_last_key(-1);
|
2011-01-13 02:21:23 +00:00
|
|
|
|
|
|
|
dlg_del_window(dialog);
|
|
|
|
dlg_mouse_free_regions();
|
|
|
|
free(prompt);
|
2012-10-21 18:18:09 +00:00
|
|
|
|
|
|
|
dialog_vars.nocancel = save_nocancel;
|
|
|
|
|
2011-01-13 02:21:23 +00:00
|
|
|
return result;
|
|
|
|
}
|