slint_pc.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /* Slang interface to the Midnight Commander for Windows NT and OS/2
  2. This emulates some features of ncurses on top of slang
  3. S-lang is not fully consistent between its Unix and non-Unix versions.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  15. #include <config.h>
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include "../src/global.h"
  19. #include "../src/tty.h"
  20. #include "../src/mad.h"
  21. #include "../src/color.h"
  22. #include "../src/util.h"
  23. #include "../src/mouse.h" /* Gpm_Event is required in key.h */
  24. #include "../src/key.h" /* define_sequence */
  25. #include "../src/main.h" /* extern: force_colors */
  26. #include "../src/win.h" /* do_exit_ca_mode */
  27. #ifdef HAVE_SLANG
  28. static void slang_sigterm ()
  29. {
  30. SLsmg_reset_smg ();
  31. }
  32. static int slinterrupt;
  33. void enable_interrupt_key(void)
  34. {
  35. SLang_set_abort_signal(NULL);
  36. slinterrupt = 1;
  37. }
  38. void disable_interrupt_key(void)
  39. {
  40. slinterrupt = 0;
  41. }
  42. int got_interrupt ()
  43. {
  44. int t;
  45. int SLKeyboard_Quit=0; /* FIXME!! */
  46. t = slinterrupt ? SLKeyboard_Quit : 0;
  47. /* SLKeyboard_Quit = 0; */
  48. return t;
  49. }
  50. /* Only done the first time */
  51. void slang_init (void)
  52. {
  53. SLtt_get_terminfo ();
  54. SLang_init_tty (XCTRL('c'), 1, 0);
  55. slang_prog_mode ();
  56. load_terminfo_keys ();
  57. }
  58. /* Done each time we come back from done mode */
  59. void slang_prog_mode (void)
  60. {
  61. SLsmg_init_smg ();
  62. SLsmg_touch_lines (0, LINES);
  63. }
  64. /* Called each time we want to shutdown slang screen manager */
  65. void slang_shell_mode (void)
  66. {
  67. }
  68. void slang_shutdown ()
  69. {
  70. slang_shell_mode ();
  71. do_exit_ca_mode ();
  72. SLang_reset_tty ();
  73. /* reset the colors to those that were
  74. * active when the program was started up
  75. (not written)
  76. */
  77. }
  78. /* keypad routines */
  79. void slang_keypad (int set)
  80. {
  81. /* enable keypad strings */
  82. }
  83. static int no_slang_delay;
  84. void set_slang_delay (int v)
  85. {
  86. no_slang_delay = v;
  87. }
  88. void hline (int ch, int len)
  89. {
  90. int last_x, last_y;
  91. last_x = SLsmg_get_column ();
  92. last_y = SLsmg_get_row ();
  93. if (ch == 0)
  94. ch = ACS_HLINE;
  95. if (ch == ACS_HLINE){
  96. SLsmg_draw_hline (len);
  97. } else {
  98. while (len--)
  99. addch (ch);
  100. }
  101. move (last_y, last_x);
  102. }
  103. void vline (int character, int len)
  104. {
  105. if (!slow_terminal){
  106. SLsmg_draw_vline (len);
  107. } else {
  108. int last_x, last_y, pos = 0;
  109. last_x = SLsmg_get_column ();
  110. last_y = SLsmg_get_row ();
  111. while (len--){
  112. move (last_y + pos++, last_x);
  113. addch (' ');
  114. }
  115. move (last_x, last_y);
  116. }
  117. }
  118. int has_colors ()
  119. {
  120. /* No terminals on NT, make default color */
  121. if (!disable_colors)
  122. SLtt_Use_Ansi_Colors = 1;
  123. /* Setup emulated colors */
  124. if (SLtt_Use_Ansi_Colors){
  125. init_pair (A_REVERSE, "black", "white");
  126. } else {
  127. /* SLtt_set_mono (A_BOLD, NULL, SLTT_BOLD_MASK);
  128. SLtt_set_mono (A_REVERSE, NULL, SLTT_REV_MASK);
  129. SLtt_set_mono (A_BOLD|A_REVERSE, NULL, SLTT_BOLD_MASK | SLTT_REV_MASK);
  130. */ }
  131. return SLtt_Use_Ansi_Colors;
  132. }
  133. void attrset (int color)
  134. {
  135. if (!SLtt_Use_Ansi_Colors){
  136. SLsmg_set_color (color);
  137. return;
  138. }
  139. if (color & A_BOLD){
  140. if (color == A_BOLD)
  141. SLsmg_set_color (A_BOLD);
  142. else
  143. SLsmg_set_color ((color & (~A_BOLD)) + 8);
  144. return;
  145. }
  146. if (color == A_REVERSE)
  147. SLsmg_set_color (A_REVERSE);
  148. else
  149. SLsmg_set_color (color);
  150. }
  151. void load_terminfo_keys ()
  152. {
  153. }
  154. int getch ()
  155. {
  156. if (no_slang_delay)
  157. if (SLang_input_pending (0) == 0)
  158. return -1;
  159. return SLang_getkey ();
  160. }
  161. extern int slow_terminal;
  162. #else
  163. /* Non slang builds do not understand got_interrupt */
  164. int got_interrupt ()
  165. {
  166. return 0;
  167. }
  168. #endif /* HAVE_SLANG */
  169. void mc_refresh (void)
  170. {
  171. /* if (!we_are_background) (no background mode yet) */
  172. refresh ();
  173. }
  174. void slang_set_raw_mode (void)
  175. {
  176. return;
  177. }
  178. int max_index = 0;
  179. void
  180. init_pair (int index, char *foreground, char *background)
  181. {
  182. SLtt_set_color (index, "", foreground, background);
  183. if (index > max_index)
  184. max_index = index;
  185. }
  186. int
  187. alloc_color_pair (char *foreground, char *background)
  188. {
  189. init_pair (++max_index, foreground, background);
  190. return max_index;
  191. }
  192. int
  193. try_alloc_color_pair (char *fg, char *bg)
  194. {
  195. static struct colors_avail {
  196. struct colors_avail *next;
  197. char *fg, *bg;
  198. int index;
  199. } *p, c =
  200. {
  201. 0, 0, 0, 0
  202. };
  203. c.index = NORMAL_COLOR;
  204. p = &c;
  205. for (;;) {
  206. if (((fg && p->fg) ? !strcmp (fg, p->fg) : fg == p->fg) != 0
  207. && ((bg && p->bg) ? !strcmp (bg, p->bg) : bg == p->bg) != 0)
  208. return p->index;
  209. if (!p->next)
  210. break;
  211. p = p->next;
  212. }
  213. p->next = malloc (sizeof (c));
  214. p = p->next;
  215. p->next = 0;
  216. p->fg = fg ? strdup (fg) : 0;
  217. p->bg = bg ? strdup (bg) : 0;
  218. if (!fg)
  219. fg = "white";
  220. if (!bg)
  221. bg = "blue";
  222. p->index = alloc_color_pair (fg, bg);
  223. return p->index;
  224. }