3
0

dialog.h 5.7 KB

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