msgbox.c revision 251843
11556Srgrimes/* 21556Srgrimes * $Id: msgbox.c,v 1.75 2012/12/01 01:48:08 tom Exp $ 31556Srgrimes * 4207944Sjilles * msgbox.c -- implements the message box and info box 5207944Sjilles * 61556Srgrimes * Copyright 2000-2011,2012 Thomas E. Dickey 71556Srgrimes * 81556Srgrimes * This program is free software; you can redistribute it and/or modify 91556Srgrimes * it under the terms of the GNU Lesser General Public License, version 2.1 101556Srgrimes * as published by the Free Software Foundation. 111556Srgrimes * 121556Srgrimes * This program is distributed in the hope that it will be useful, but 131556Srgrimes * WITHOUT ANY WARRANTY; without even the implied warranty of 141556Srgrimes * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 151556Srgrimes * Lesser General Public License for more details. 161556Srgrimes * 171556Srgrimes * You should have received a copy of the GNU Lesser General Public 181556Srgrimes * License along with this program; if not, write to 191556Srgrimes * Free Software Foundation, Inc. 201556Srgrimes * 51 Franklin St., Fifth Floor 211556Srgrimes * Boston, MA 02110, USA. 221556Srgrimes * 231556Srgrimes * An earlier version of this program lists as authors: 241556Srgrimes * Savio Lam (lam836@cs.cuhk.hk) 251556Srgrimes */ 261556Srgrimes 271556Srgrimes#include <dialog.h> 281556Srgrimes#include <dlg_keys.h> 291556Srgrimes 301556Srgrimes/* 311556Srgrimes * Display a message box. Program will pause and display an "OK" button 321556Srgrimes * if the parameter 'pauseopt' is non-zero. 331556Srgrimes */ 341556Srgrimesint 351556Srgrimesdialog_msgbox(const char *title, const char *cprompt, int height, int width, 3636150Scharnier int pauseopt) 3736150Scharnier{ 3836150Scharnier /* *INDENT-OFF* */ 391556Srgrimes static DLG_KEYS_BINDING binding[] = { 4099110Sobrien HELPKEY_BINDINGS, 4199110Sobrien ENTERKEY_BINDINGS, 421556Srgrimes TRAVERSE_BINDINGS, 4317987Speter SCROLLKEY_BINDINGS, 4417987Speter END_KEYS_BINDING 4517987Speter }; 46213775Sjhb /* *INDENT-ON* */ 4717987Speter 48213775Sjhb int x, y, last = 0, page; 49213775Sjhb int button; 5017987Speter int key = 0, fkey; 51213775Sjhb int result = DLG_EXIT_UNKNOWN; 5217987Speter WINDOW *dialog = 0; 53108286Stjr char *prompt = dlg_strclone(cprompt); 54213775Sjhb const char **buttons = dlg_ok_label(); 5517987Speter int offset = 0; 561556Srgrimes int check; 571556Srgrimes bool show = TRUE; 581556Srgrimes int min_width = (pauseopt == 1 ? 12 : 0); 591556Srgrimes int save_nocancel = dialog_vars.nocancel; 601556Srgrimes#ifdef KEY_RESIZE 611556Srgrimes int req_high; 621556Srgrimes int req_wide; 631556Srgrimes#endif 641556Srgrimes 651556Srgrimes dialog_vars.nocancel = TRUE; 661556Srgrimes button = dlg_default_button(); 671556Srgrimes 681556Srgrimes#ifdef KEY_RESIZE 691556Srgrimes req_high = height; 701556Srgrimes req_wide = width; 711556Srgrimes restart: 721556Srgrimes#endif 731556Srgrimes 741556Srgrimes dlg_button_layout(buttons, &min_width); 751556Srgrimes 7617987Speter dlg_tab_correct_str(prompt); 7717987Speter dlg_auto_size(title, prompt, &height, &width, 781556Srgrimes (pauseopt == 1 ? 2 : 0), 791556Srgrimes min_width); 801556Srgrimes dlg_print_size(height, width); 811556Srgrimes dlg_ctl_size(height, width); 821556Srgrimes 831556Srgrimes x = dlg_box_x_ordinate(width); 841556Srgrimes y = dlg_box_y_ordinate(height); 851556Srgrimes 861556Srgrimes#ifdef KEY_RESIZE 871556Srgrimes if (dialog != 0) 88194975Sjilles dlg_move_window(dialog, height, width, y, x); 891556Srgrimes else 901556Srgrimes#endif 911556Srgrimes { 92213760Sobrien dialog = dlg_new_window(height, width, y, x); 93213760Sobrien dlg_register_window(dialog, "msgbox", binding); 94213760Sobrien dlg_register_buttons(dialog, "msgbox", buttons); 95213760Sobrien } 96213760Sobrien page = height - (1 + 3 * MARGIN); 971556Srgrimes 98213811Sobrien dlg_mouse_setbase(x, y); 99213811Sobrien 100213811Sobrien dlg_draw_box2(dialog, 0, 0, height, width, dialog_attr, border_attr, border2_attr); 101214524Sjilles dlg_draw_title(dialog, title); 102213811Sobrien 103213811Sobrien (void) wattrset(dialog, dialog_attr); 104213811Sobrien 105213811Sobrien if (pauseopt) { 106213811Sobrien dlg_draw_bottom_box2(dialog, border_attr, border2_attr, dialog_attr); 107213811Sobrien mouse_mkbutton(height - 2, width / 2 - 4, 6, '\n'); 108213811Sobrien dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width); 109213811Sobrien dlg_draw_helpline(dialog, FALSE); 110213811Sobrien 111213811Sobrien while (result == DLG_EXIT_UNKNOWN) { 112213811Sobrien if (show) { 113213811Sobrien last = dlg_print_scrolled(dialog, prompt, offset, 114213811Sobrien page, width, pauseopt); 1151556Srgrimes dlg_trace_win(dialog); 116213811Sobrien show = FALSE; 117118374Sache } 11819281Sache key = dlg_mouse_wgetch(dialog, &fkey); 11919281Sache if (dlg_result_key(key, fkey, &result)) 12019281Sache break; 12119281Sache 12219281Sache if (!fkey && (check = dlg_char_to_button(key, buttons)) >= 0) { 123118374Sache result = dlg_ok_buttoncode(check); 12419281Sache break; 12519281Sache } 1261556Srgrimes 1271556Srgrimes if (fkey) { 12890111Simp switch (key) { 12990111Simp#ifdef KEY_RESIZE 1301556Srgrimes case KEY_RESIZE: 1311556Srgrimes dlg_clear(); 1321556Srgrimes height = req_high; 13390111Simp width = req_wide; 13490111Simp show = TRUE; 1351556Srgrimes goto restart; 1361556Srgrimes#endif 13739137Stegge case DLGK_FIELD_NEXT: 1381556Srgrimes button = dlg_next_button(buttons, button); 1391556Srgrimes if (button < 0) 1401556Srgrimes button = 0; 1411556Srgrimes dlg_draw_buttons(dialog, 142212243Sjilles height - 2, 0, 143212243Sjilles buttons, button, 144212243Sjilles FALSE, width); 145212243Sjilles break; 146212243Sjilles case DLGK_FIELD_PREV: 147212243Sjilles button = dlg_prev_button(buttons, button); 148212243Sjilles if (button < 0) 149212243Sjilles button = 0; 150212243Sjilles dlg_draw_buttons(dialog, 151212243Sjilles height - 2, 0, 152212243Sjilles buttons, button, 1531556Srgrimes FALSE, width); 1541556Srgrimes break; 15590111Simp case DLGK_ENTER: 15617987Speter result = dlg_ok_buttoncode(button); 1571556Srgrimes break; 1581556Srgrimes default: 1591556Srgrimes if (is_DLGK_MOUSE(key)) { 1601556Srgrimes result = dlg_ok_buttoncode(key - M_EVENT); 1611556Srgrimes if (result < 0) 1621556Srgrimes result = DLG_EXIT_OK; 1631556Srgrimes } else if (dlg_check_scrolled(key, 1641556Srgrimes last, 1651556Srgrimes page, 1661556Srgrimes &show, 1671556Srgrimes &offset) == 0) { 1681556Srgrimes } else { 1691556Srgrimes beep(); 1701556Srgrimes } 1711556Srgrimes break; 1721556Srgrimes } 1731556Srgrimes } else { 1741556Srgrimes beep(); 1751556Srgrimes } 1761556Srgrimes } 1771556Srgrimes } else { 1781556Srgrimes dlg_print_scrolled(dialog, prompt, offset, page, width, pauseopt); 1791556Srgrimes dlg_draw_helpline(dialog, FALSE); 1801556Srgrimes wrefresh(dialog); 1811556Srgrimes dlg_trace_win(dialog); 1821556Srgrimes result = DLG_EXIT_OK; 1831556Srgrimes } 1841556Srgrimes 1851556Srgrimes dlg_del_window(dialog); 1861556Srgrimes dlg_mouse_free_regions(); 1871556Srgrimes free(prompt); 1881556Srgrimes 1891556Srgrimes dialog_vars.nocancel = save_nocancel; 1901556Srgrimes 1911556Srgrimes return result; 1921556Srgrimes} 1931556Srgrimes