slint.nt.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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., 675 Mass Ave, Cambridge, MA 02139, USA. */
  15. #include <config.h>
  16. #include <stdio.h>
  17. #include "tty.h"
  18. #include "mad.h"
  19. #include "color.h"
  20. #include "util.h"
  21. #include "mouse.h" /* Gpm_Event is required in key.h */
  22. #include "key.h" /* define_sequence */
  23. #include "main.h" /* extern: force_colors */
  24. #include "win.h" /* do_exit_ca_mode */
  25. #ifdef HAVE_SLANG
  26. static void slang_sigterm ()
  27. {
  28. SLsmg_reset_smg ();
  29. }
  30. static int slinterrupt;
  31. void enable_interrupt_key(void)
  32. {
  33. SLang_set_abort_signal(NULL);
  34. slinterrupt = 1;
  35. }
  36. void disable_interrupt_key(void)
  37. {
  38. slinterrupt = 0;
  39. }
  40. int got_interrupt ()
  41. {
  42. int t;
  43. int SLKeyboard_Quit=0; //FIXME!!
  44. t = slinterrupt ? SLKeyboard_Quit : 0;
  45. // SLKeyboard_Quit = 0;
  46. return t;
  47. }
  48. /* Only done the first time */
  49. void slang_init (void)
  50. {
  51. SLtt_get_terminfo ();
  52. SLang_init_tty (XCTRL('c'), 1, 0);
  53. slang_prog_mode ();
  54. load_terminfo_keys ();
  55. }
  56. /* Done each time we come back from done mode */
  57. void slang_prog_mode (void)
  58. {
  59. SLsmg_init_smg ();
  60. SLsmg_touch_lines (0, LINES);
  61. }
  62. /* Called each time we want to shutdown slang screen manager */
  63. void slang_shell_mode (void)
  64. {
  65. }
  66. void slang_shutdown ()
  67. {
  68. slang_shell_mode ();
  69. do_exit_ca_mode ();
  70. SLang_reset_tty ();
  71. /* reset the colors to those that were
  72. * active when the program was started up
  73. (not written)
  74. */
  75. }
  76. /* keypad routines */
  77. void slang_keypad (int set)
  78. {
  79. // enable keypad strings
  80. // ?
  81. }
  82. static int no_slang_delay;
  83. void set_slang_delay (int v)
  84. {
  85. no_slang_delay = v;
  86. }
  87. void hline (int ch, int len)
  88. {
  89. int last_x, last_y;
  90. last_x = SLsmg_get_column ();
  91. last_y = SLsmg_get_row ();
  92. if (ch == 0)
  93. ch = ACS_HLINE;
  94. if (ch == ACS_HLINE){
  95. SLsmg_draw_hline (len);
  96. } else {
  97. while (len--)
  98. addch (ch);
  99. }
  100. move (last_y, last_x);
  101. }
  102. void vline (int character, int len)
  103. {
  104. if (!slow_terminal){
  105. SLsmg_draw_vline (len);
  106. } else {
  107. int last_x, last_y, pos = 0;
  108. last_x = SLsmg_get_column ();
  109. last_y = SLsmg_get_row ();
  110. while (len--){
  111. move (last_y + pos++, last_x);
  112. addch (' ');
  113. }
  114. move (last_x, last_y);
  115. }
  116. }
  117. void init_pair (int index, char *foreground, char *background)
  118. {
  119. SLtt_set_color (index, "", foreground, background);
  120. }
  121. int has_colors ()
  122. {
  123. /* No terminals on NT, make default color */
  124. if (!disable_colors)
  125. SLtt_Use_Ansi_Colors = 1;
  126. /* Setup emulated colors */
  127. if (SLtt_Use_Ansi_Colors){
  128. init_pair (A_REVERSE, "black", "white");
  129. } else {
  130. /* SLtt_set_mono (A_BOLD, NULL, SLTT_BOLD_MASK);
  131. SLtt_set_mono (A_REVERSE, NULL, SLTT_REV_MASK);
  132. SLtt_set_mono (A_BOLD|A_REVERSE, NULL, SLTT_BOLD_MASK | SLTT_REV_MASK);
  133. */ }
  134. return SLtt_Use_Ansi_Colors;
  135. }
  136. void attrset (int color)
  137. {
  138. if (!SLtt_Use_Ansi_Colors){
  139. SLsmg_set_color (color);
  140. return;
  141. }
  142. if (color & A_BOLD){
  143. if (color == A_BOLD)
  144. SLsmg_set_color (A_BOLD);
  145. else
  146. SLsmg_set_color ((color & (~A_BOLD)) + 8);
  147. return;
  148. }
  149. if (color == A_REVERSE)
  150. SLsmg_set_color (A_REVERSE);
  151. else
  152. SLsmg_set_color (color);
  153. }
  154. void load_terminfo_keys ()
  155. {
  156. }
  157. int getch ()
  158. {
  159. if (no_slang_delay)
  160. if (SLang_input_pending (0) == 0)
  161. return -1;
  162. return SLang_getkey ();
  163. }
  164. extern int slow_terminal;
  165. #else
  166. /* Non slang builds do not understand got_interrupt */
  167. int got_interrupt ()
  168. {
  169. return 0;
  170. }
  171. #endif /* HAVE_SLANG */
  172. void mc_refresh (void)
  173. {
  174. /* if (!we_are_background) (no background mode yet) */
  175. refresh ();
  176. }
  177. void slang_set_raw_mode (void)
  178. {
  179. return;
  180. }