dialog.h 6.0 KB

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