Back to index

tetex-bin  3.0
dialog.h
Go to the documentation of this file.
00001 /*
00002  *  dialog.h -- common declarations for all dialog modules
00003  *
00004  *  AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
00005  *
00006  *  This program is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU General Public License
00008  *  as published by the Free Software Foundation; either version 2
00009  *  of the License, or (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00021 
00022 #include <dialogconfig.h>
00023 #include <sys/types.h>
00024 #include <fcntl.h>
00025 #include <unistd.h>
00026 #include <ctype.h>
00027 #include <stdlib.h>
00028 #include <string.h>
00029 
00030 #ifdef HAVE_NCURSES
00031 #ifdef HAVE_NCURSES_H
00032 #include <ncurses.h>
00033 #else
00034 #include <ncurses/curses.h>
00035 #endif
00036 #else
00037 
00038 #ifdef ultrix
00039 #include <cursesX.h>
00040 #else
00041 #include <curses.h>
00042 #endif
00043 
00044 #endif
00045 
00046 #if defined(LOCALE)
00047 #include <locale.h>
00048 #endif
00049 
00050 /*
00051  * Change these if you want
00052  */
00053 #ifndef USE_SHADOW
00054 #define USE_SHADOW FALSE
00055 #endif
00056 #ifndef USE_COLORS
00057 #define USE_COLORS TRUE
00058 #endif
00059 
00060 
00061 
00062 #define VERSION "0.4"
00063 #define ESC 27
00064 #define TAB 9
00065 #define MAX_LEN 2048
00066 #define BUF_SIZE (10*1024)
00067 #define MIN(x,y) (x < y ? x : y)
00068 #define MAX(x,y) (x > y ? x : y)
00069 
00070 #ifndef HAVE_NCURSES
00071 #ifndef ACS_ULCORNER
00072 #define ACS_ULCORNER '+'
00073 #endif
00074 #ifndef ACS_LLCORNER
00075 #define ACS_LLCORNER '+'
00076 #endif
00077 #ifndef ACS_URCORNER
00078 #define ACS_URCORNER '+'
00079 #endif
00080 #ifndef ACS_LRCORNER
00081 #define ACS_LRCORNER '+'
00082 #endif
00083 #ifndef ACS_HLINE
00084 #define ACS_HLINE '-'
00085 #endif
00086 #ifndef ACS_VLINE
00087 #define ACS_VLINE '|'
00088 #endif
00089 #ifndef ACS_LTEE
00090 #define ACS_LTEE '+'
00091 #endif
00092 #ifndef ACS_RTEE
00093 #define ACS_RTEE '+'
00094 #endif
00095 #ifndef ACS_UARROW
00096 #define ACS_UARROW '^'
00097 #endif
00098 #ifndef ACS_DARROW
00099 #define ACS_DARROW 'v'
00100 #endif
00101 #endif    /* HAVE_NCURSES */
00102 
00103 
00104 /* 
00105  * Attribute names
00106  */
00107 #define screen_attr                   attributes[0]
00108 #define shadow_attr                   attributes[1]
00109 #define dialog_attr                   attributes[2]
00110 #define title_attr                    attributes[3]
00111 #define border_attr                   attributes[4]
00112 #define button_active_attr            attributes[5]
00113 #define button_inactive_attr          attributes[6]
00114 #define button_key_active_attr        attributes[7]
00115 #define button_key_inactive_attr      attributes[8]
00116 #define button_label_active_attr      attributes[9]
00117 #define button_label_inactive_attr    attributes[10]
00118 #define inputbox_attr                 attributes[11]
00119 #define inputbox_border_attr          attributes[12]
00120 #define searchbox_attr                attributes[13]
00121 #define searchbox_title_attr          attributes[14]
00122 #define searchbox_border_attr         attributes[15]
00123 #define position_indicator_attr       attributes[16]
00124 #define menubox_attr                  attributes[17]
00125 #define menubox_border_attr           attributes[18]
00126 #define item_attr                     attributes[19]
00127 #define item_selected_attr            attributes[20]
00128 #define tag_attr                      attributes[21]
00129 #define tag_selected_attr             attributes[22]
00130 #define tag_key_attr                  attributes[23]
00131 #define tag_key_selected_attr         attributes[24]
00132 #define check_attr                    attributes[25]
00133 #define check_selected_attr           attributes[26]
00134 #define uarrow_attr                   attributes[27]
00135 #define darrow_attr                   attributes[28]
00136 
00137 /* number of attributes */
00138 #define ATTRIBUTE_COUNT               29
00139 
00140 
00141 /*
00142  * Global variables
00143  */
00144 #ifdef __DIALOG_MAIN__
00145 
00146 #ifdef HAVE_NCURSES
00147 
00148 /* use colors by default? */
00149 bool use_colors = USE_COLORS;
00150 
00151 /* shadow dialog boxes by default?
00152    Note that 'use_shadow' implies 'use_colors' */
00153 bool use_shadow = USE_SHADOW;
00154 
00155 #endif
00156 
00157 /* 
00158  * Attribute values, default is for mono display
00159  */
00160 chtype attributes[] = {
00161   A_NORMAL,       /* screen_attr */
00162   A_NORMAL,       /* shadow_attr */
00163   A_REVERSE,      /* dialog_attr */
00164   A_REVERSE,      /* title_attr */
00165   A_REVERSE,      /* border_attr */
00166   A_BOLD,         /* button_active_attr */
00167   A_DIM,          /* button_inactive_attr */
00168   A_UNDERLINE,    /* button_key_active_attr */
00169   A_UNDERLINE,    /* button_key_inactive_attr */
00170   A_NORMAL,       /* button_label_active_attr */
00171   A_NORMAL,       /* button_label_inactive_attr */
00172   A_REVERSE,      /* inputbox_attr */
00173   A_REVERSE,      /* inputbox_border_attr */
00174   A_REVERSE,      /* searchbox_attr */
00175   A_REVERSE,      /* searchbox_title_attr */
00176   A_REVERSE,      /* searchbox_border_attr */
00177   A_REVERSE,      /* position_indicator_attr */
00178   A_REVERSE,      /* menubox_attr */
00179   A_REVERSE,      /* menubox_border_attr */
00180   A_REVERSE,      /* item_attr */
00181   A_NORMAL,       /* item_selected_attr */
00182   A_REVERSE,      /* tag_attr */
00183   A_REVERSE,      /* tag_selected_attr */
00184   A_NORMAL,       /* tag_key_attr */
00185   A_BOLD,         /* tag_key_selected_attr */
00186   A_REVERSE,      /* check_attr */
00187   A_REVERSE,      /* check_selected_attr */
00188   A_REVERSE,      /* uarrow_attr */
00189   A_REVERSE       /* darrow_attr */
00190 };
00191 
00192 #else
00193 
00194 #ifdef HAVE_NCURSES
00195 extern bool use_colors;
00196 extern bool use_shadow;
00197 #endif
00198 
00199 extern chtype attributes[];
00200 
00201 #endif    /* __DIALOG_MAIN__ */
00202 
00203 /* Governs printing of checklist and radiobox output */
00204 extern int separate_output;
00205 
00206 
00207 #ifdef HAVE_NCURSES
00208 
00209 /*
00210  * Function prototypes
00211  */
00212 #ifdef __DIALOG_MAIN__
00213 
00214 extern void create_rc(char *filename);
00215 extern int parse_rc(void);
00216 
00217 #endif    /* __DIALOG_MAIN__ */
00218 
00219 #endif
00220 
00221 
00222 void Usage(char *name);
00223 void init_dialog(void);
00224 #ifdef HAVE_NCURSES
00225 void color_setup(void);
00226 #endif
00227 void attr_clear(WINDOW *win, int height, int width, chtype attr);
00228 void print_autowrap(WINDOW *win, char *prompt, int width, int y, int x);
00229 void print_button(WINDOW *win, char *label, int y, int x, int selected);
00230 void draw_box(WINDOW *win, int y, int x, int height, int width, chtype box, chtype border);
00231 #ifdef HAVE_NCURSES
00232 void draw_shadow(WINDOW *win, int y, int x, int height, int width);
00233 #endif
00234 
00235 #ifndef HAVE_STRCASECMP
00236 extern int strcasecmp();
00237 #endif
00238 
00239 int dialog_yesno(char *title, char *prompt, int height, int width);
00240 int dialog_msgbox(char *title, char *prompt, int height, int width, int pause);
00241 int dialog_textbox(char *title, char *file, int height, int width);
00242 int dialog_menu(char *title, char *prompt, int height, int width, int menu_height, int item_no, char **items);
00243 int dialog_checklist(char *title, char *prompt, int height, int width, int list_height, int item_no, char **items);
00244 int dialog_radiolist(char *title, char *prompt, int height, int width, int list_height, int item_no, char **items);
00245 int dialog_inputbox(char *title, char *prompt, int height, int width, char *init);
00246 int dialog_guage(char *title, char *prompt, int height, int width, int percent);
00247