# dialog.h

    00001
    00002 /*
    00003  *  dialog.h -- common declarations for all dialog modules
    00004  *
    00005  *  AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
    00006  *
    00007  *  This program is free software; you can redistribute it and/or
    00008  *  modify it under the terms of the GNU General Public License
    00009  *  as published by the Free Software Foundation; either version 2
    00010  *  of the License, or (at your option) any later version.
    00011  *
    00012  *  This program is distributed in the hope that it will be useful,
    00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00015  *  GNU General Public License for more details.
    00016  *
    00017  *  You should have received a copy of the GNU General Public License
    00018  *  along with this program; if not, write to the Free Software
    00019  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    00020  */
    00021
    00022 #include <sys/types.h>
    00023 #include <fcntl.h>
    00024 #include <unistd.h>
    00025 #include <ctype.h>
    00026 #include <stdlib.h>
    00027 #include <string.h>
    00028
    00029 #include CURSES_LOC
    00030
    00031 /*
    00032  * Colors in ncurses 1.9.9e do not work properly since foreground and
    00033  * background colors are OR'd rather than separately masked.  This version
    00034  * of dialog was hacked to work with ncurses 1.9.9e, making it incompatible
    00035  * with standard curses.  The simplest fix (to make this work with standard
    00036  * curses) uses the wbkgdset() function, not used in the original hack.
    00037  * Turn it off if we're building with 1.9.9e, since it just confuses things.
    00038  */
    00039 #if defined(NCURSES_VERSION) && defined(_NEED_WRAP) && !defined(GCC_PRINTFLIKE)
    00040 #define OLD_NCURSES 1
    00041 #undef  wbkgdset
    00042 #define wbkgdset(w,p) /*nothing*/
    00043 #else
    00044 #define OLD_NCURSES 0
    00045 #endif
    00046
    00047 #define TR(params) _tracef params
    00048
    00049 #define ESC 27
    00050 #define TAB 9
    00051 #define MAX_LEN 2048
    00052 #define BUF_SIZE (10*1024)
    00053 #define MIN(x,y) (x < y ? x : y)
    00054 #define MAX(x,y) (x > y ? x : y)
    00055
    00056
    00057 #ifndef ACS_ULCORNER
    00058 #define ACS_ULCORNER '+'
    00059 #endif
    00060 #ifndef ACS_LLCORNER
    00061 #define ACS_LLCORNER '+'
    00062 #endif
    00063 #ifndef ACS_URCORNER
    00064 #define ACS_URCORNER '+'
    00065 #endif
    00066 #ifndef ACS_LRCORNER
    00067 #define ACS_LRCORNER '+'
    00068 #endif
    00069 #ifndef ACS_HLINE
    00070 #define ACS_HLINE '-'
    00071 #endif
    00072 #ifndef ACS_VLINE
    00073 #define ACS_VLINE '|'
    00074 #endif
    00075 #ifndef ACS_LTEE
    00076 #define ACS_LTEE '+'
    00077 #endif
    00078 #ifndef ACS_RTEE
    00079 #define ACS_RTEE '+'
    00080 #endif
    00081 #ifndef ACS_UARROW
    00082 #define ACS_UARROW '^'
    00083 #endif
    00084 #ifndef ACS_DARROW
    00085 #define ACS_DARROW 'v'
    00086 #endif
    00087
    00088 /*
    00089  * Attribute names
    00090  */
    00091 #define screen_attr                   attributes[0]
    00092 #define shadow_attr                   attributes[1]
    00093 #define dialog_attr                   attributes[2]
    00094 #define title_attr                    attributes[3]
    00095 #define border_attr                   attributes[4]
    00096 #define button_active_attr            attributes[5]
    00097 #define button_inactive_attr          attributes[6]
    00098 #define button_key_active_attr        attributes[7]
    00099 #define button_key_inactive_attr      attributes[8]
    00100 #define button_label_active_attr      attributes[9]
    00101 #define button_label_inactive_attr    attributes[10]
    00102 #define inputbox_attr                 attributes[11]
    00103 #define inputbox_border_attr          attributes[12]
    00104 #define searchbox_attr                attributes[13]
    00105 #define searchbox_title_attr          attributes[14]
    00106 #define searchbox_border_attr         attributes[15]
    00107 #define position_indicator_attr       attributes[16]
    00108 #define menubox_attr                  attributes[17]
    00109 #define menubox_border_attr           attributes[18]
    00110 #define item_attr                     attributes[19]
    00111 #define item_selected_attr            attributes[20]
    00112 #define tag_attr                      attributes[21]
    00113 #define tag_selected_attr             attributes[22]
    00114 #define tag_key_attr                  attributes[23]
    00115 #define tag_key_selected_attr         attributes[24]
    00116 #define check_attr                    attributes[25]
    00117 #define check_selected_attr           attributes[26]
    00118 #define uarrow_attr                   attributes[27]
    00119 #define darrow_attr                   attributes[28]
    00120
    00121 /* number of attributes */
    00122 #define ATTRIBUTE_COUNT               29
    00123
    00124 /*
    00125  * Global variables
    00126  */
    00127 extern bool use_colors;
    00128 extern bool use_shadow;
    00129
    00130 extern chtype attributes[];
    00131
    00132 extern const char *backtitle;
    00133
    00134 /*
    00135  * Function prototypes
    00136  */
    00137 extern void create_rc (const char *filename);
    00138 extern int parse_rc (void);
    00139
    00140
    00141 void init_dialog (void);
    00142 void end_dialog (void);
    00143 void attr_clear (WINDOW * win, int height, int width, chtype attr);
    00144 void dialog_clear (void);
    00145 void color_setup (void);
    00146 void print_autowrap (WINDOW * win, const char *prompt, int width, int y, int x);
    00147 void print_button (WINDOW * win, const char *label, int y, int x, int selected);
    00148 void draw_box (WINDOW * win, int y, int x, int height, int width, chtype box,
    00149                 chtype border);
    00150 void draw_shadow (WINDOW * win, int y, int x, int height, int width);
    00151
    00152 int first_alpha (const char *string, const char *exempt);
    00153 int dialog_yesno (const char *title, const char *prompt, int height, int width);
    00154 int dialog_msgbox (const char *title, const char *prompt, int height,
    00155                 int width, int pause);
    00156 int dialog_textbox (const char *title, const char *file, int height, int width);
    00157 int dialog_menu (const char *title, const char *prompt, int height, int width,
    00158                 int menu_height, const char *choice, int item_no,
    00159                 const char * const * items);
    00160 int dialog_checklist (const char *title, const char *prompt, int height,
    00161                 int width, int list_height, int item_no,
    00162                 const char * const * items, int flag);
    00163 extern unsigned char dialog_input_result[];
    00164 int dialog_inputbox (const char *title, const char *prompt, int height,
    00165                 int width, const char *init);
    00166
    00167 /*
    00168  * This is the base for fictitious keys, which activate
    00169  * the buttons.
    00170  *
    00171  * Mouse-generated keys are the following:
    00172  *   -- the first 32 are used as numbers, in addition to '0'-'9'
    00173  *   -- the lowercase are used to signal mouse-enter events (M_EVENT + 'o')
    00174  *   -- uppercase chars are used to invoke the button (M_EVENT + 'O')
    00175  */
    00176 #define M_EVENT (KEY_MAX+1)
    00177
    00178
    00179 /*
    00180  * The `flag' parameter in checklist is used to select between
    00181  * radiolist and checklist
    00182  */
    00183 #define FLAG_CHECK 1
    00184 #define FLAG_RADIO 0