dialog.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * dialog.h -- common declarations for all dialog modules
  3. *
  4. * AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. #include <sys/types.h>
  21. #include <fcntl.h>
  22. #include <unistd.h>
  23. #include <ctype.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #ifdef CURSES_LOC
  27. #ifdef __sun__
  28. #define CURS_MACROS
  29. #endif
  30. #include CURSES_LOC
  31. /*
  32. * Colors in ncurses 1.9.9e do not work properly since foreground and
  33. * background colors are OR'd rather than separately masked. This version
  34. * of dialog was hacked to work with ncurses 1.9.9e, making it incompatible
  35. * with standard curses. The simplest fix (to make this work with standard
  36. * curses) uses the wbkgdset() function, not used in the original hack.
  37. * Turn it off if we're building with 1.9.9e, since it just confuses things.
  38. */
  39. #if defined(NCURSES_VERSION) && defined(_NEED_WRAP) && !defined(GCC_PRINTFLIKE)
  40. #define OLD_NCURSES 1
  41. #undef wbkgdset
  42. #define wbkgdset(w,p) /*nothing*/
  43. #else
  44. #define OLD_NCURSES 0
  45. #endif
  46. #define TR(params) _tracef params
  47. #define ESC 27
  48. #define TAB 9
  49. #define MAX_LEN 2048
  50. #define BUF_SIZE (10*1024)
  51. #define MIN(x,y) (x < y ? x : y)
  52. #define MAX(x,y) (x > y ? x : y)
  53. #ifndef ACS_ULCORNER
  54. #define ACS_ULCORNER '+'
  55. #endif
  56. #ifndef ACS_LLCORNER
  57. #define ACS_LLCORNER '+'
  58. #endif
  59. #ifndef ACS_URCORNER
  60. #define ACS_URCORNER '+'
  61. #endif
  62. #ifndef ACS_LRCORNER
  63. #define ACS_LRCORNER '+'
  64. #endif
  65. #ifndef ACS_HLINE
  66. #define ACS_HLINE '-'
  67. #endif
  68. #ifndef ACS_VLINE
  69. #define ACS_VLINE '|'
  70. #endif
  71. #ifndef ACS_LTEE
  72. #define ACS_LTEE '+'
  73. #endif
  74. #ifndef ACS_RTEE
  75. #define ACS_RTEE '+'
  76. #endif
  77. #ifndef ACS_UARROW
  78. #define ACS_UARROW '^'
  79. #endif
  80. #ifndef ACS_DARROW
  81. #define ACS_DARROW 'v'
  82. #endif
  83. /*
  84. * Attribute names
  85. */
  86. #define screen_attr attributes[0]
  87. #define shadow_attr attributes[1]
  88. #define dialog_attr attributes[2]
  89. #define title_attr attributes[3]
  90. #define border_attr attributes[4]
  91. #define button_active_attr attributes[5]
  92. #define button_inactive_attr attributes[6]
  93. #define button_key_active_attr attributes[7]
  94. #define button_key_inactive_attr attributes[8]
  95. #define button_label_active_attr attributes[9]
  96. #define button_label_inactive_attr attributes[10]
  97. #define inputbox_attr attributes[11]
  98. #define inputbox_border_attr attributes[12]
  99. #define searchbox_attr attributes[13]
  100. #define searchbox_title_attr attributes[14]
  101. #define searchbox_border_attr attributes[15]
  102. #define position_indicator_attr attributes[16]
  103. #define menubox_attr attributes[17]
  104. #define menubox_border_attr attributes[18]
  105. #define item_attr attributes[19]
  106. #define item_selected_attr attributes[20]
  107. #define tag_attr attributes[21]
  108. #define tag_selected_attr attributes[22]
  109. #define tag_key_attr attributes[23]
  110. #define tag_key_selected_attr attributes[24]
  111. #define check_attr attributes[25]
  112. #define check_selected_attr attributes[26]
  113. #define uarrow_attr attributes[27]
  114. #define darrow_attr attributes[28]
  115. /* number of attributes */
  116. #define ATTRIBUTE_COUNT 29
  117. /*
  118. * Global variables
  119. */
  120. extern bool use_colors;
  121. extern chtype attributes[];
  122. #endif
  123. extern const char *backtitle;
  124. struct dialog_list_item {
  125. char *name;
  126. int namelen;
  127. char *tag;
  128. int selected; /* Set to 1 by dialog_*() function. */
  129. };
  130. /*
  131. * Function prototypes
  132. */
  133. void init_dialog (void);
  134. void end_dialog (void);
  135. void dialog_clear (void);
  136. #ifdef CURSES_LOC
  137. void attr_clear (WINDOW * win, int height, int width, chtype attr);
  138. void color_setup (void);
  139. void print_autowrap (WINDOW * win, const char *prompt, int width, int y, int x);
  140. void print_button (WINDOW * win, const char *label, int y, int x, int selected);
  141. void draw_box (WINDOW * win, int y, int x, int height, int width, chtype box,
  142. chtype border);
  143. void draw_shadow (WINDOW * win, int y, int x, int height, int width);
  144. #endif
  145. int first_alpha (const char *string, const char *exempt);
  146. int dialog_yesno (const char *title, const char *prompt, int height, int width);
  147. int dialog_msgbox (const char *title, const char *prompt, int height,
  148. int width, int pause);
  149. int dialog_textbox (const char *title, const char *file, int height, int width);
  150. int dialog_menu (const char *title, const char *prompt, int height, int width,
  151. int menu_height, const char *choice, int item_no,
  152. struct dialog_list_item ** items);
  153. int dialog_checklist (const char *title, const char *prompt, int height,
  154. int width, int list_height, int item_no,
  155. struct dialog_list_item ** items, int flag);
  156. extern char dialog_input_result[];
  157. int dialog_inputbox (const char *title, const char *prompt, int height,
  158. int width, const char *init);
  159. struct dialog_list_item *first_sel_item(int item_no,
  160. struct dialog_list_item ** items);
  161. /*
  162. * This is the base for fictitious keys, which activate
  163. * the buttons.
  164. *
  165. * Mouse-generated keys are the following:
  166. * -- the first 32 are used as numbers, in addition to '0'-'9'
  167. * -- the lowercase are used to signal mouse-enter events (M_EVENT + 'o')
  168. * -- uppercase chars are used to invoke the button (M_EVENT + 'O')
  169. */
  170. #ifdef CURSES_LOC
  171. #define M_EVENT (KEY_MAX+1)
  172. #endif
  173. /*
  174. * The `flag' parameter in checklist is used to select between
  175. * radiolist and checklist
  176. */
  177. #define FLAG_CHECK 1
  178. #define FLAG_RADIO 0