dialog.h 5.8 KB

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