- converted 1st stage setup stub from message box style to property sheet style
[reactos.git] / rosapps / applications / mc / pc / slint_pc.c
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
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (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 <config.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include "../src/tty.h"
25 #include "../src/mad.h"
26 #include "../src/color.h"
27 #include "../src/util.h"
28 #include "../src/mouse.h" /* Gpm_Event is required in key.h */
29 #include "../src/key.h" /* define_sequence */
30 #include "../src/main.h" /* extern: force_colors */
31 #include "../src/win.h" /* do_exit_ca_mode */
32
33 #ifdef HAVE_SLANG
34
35
36 static void slang_sigterm ()
37 {
38 SLsmg_reset_smg ();
39 }
40
41 static int slinterrupt;
42
43 void enable_interrupt_key(void)
44 {
45 SLang_set_abort_signal(NULL);
46 slinterrupt = 1;
47 }
48 void disable_interrupt_key(void)
49 {
50 slinterrupt = 0;
51 }
52 int got_interrupt ()
53 {
54 int t;
55 int SLKeyboard_Quit=0; /* FIXME!! */
56 t = slinterrupt ? SLKeyboard_Quit : 0;
57 /* SLKeyboard_Quit = 0; */
58 return t;
59 }
60
61 /* Only done the first time */
62 void slang_init (void)
63 {
64 SLtt_get_terminfo ();
65 SLang_init_tty (XCTRL('c'), 1, 0);
66 slang_prog_mode ();
67 load_terminfo_keys ();
68 }
69
70 /* Done each time we come back from done mode */
71 void slang_prog_mode (void)
72 {
73 SLsmg_init_smg ();
74 SLsmg_touch_lines (0, LINES);
75 }
76
77 /* Called each time we want to shutdown slang screen manager */
78 void slang_shell_mode (void)
79 {
80
81 }
82
83 void slang_shutdown ()
84 {
85 slang_shell_mode ();
86 do_exit_ca_mode ();
87 SLang_reset_tty ();
88
89 /* reset the colors to those that were
90 * active when the program was started up
91 (not written)
92 */
93 }
94
95 /* keypad routines */
96 void slang_keypad (int set)
97 {
98 /* enable keypad strings */
99 }
100
101 static int no_slang_delay;
102
103 void set_slang_delay (int v)
104 {
105 no_slang_delay = v;
106 }
107
108 void hline (int ch, int len)
109 {
110 int last_x, last_y;
111
112 last_x = SLsmg_get_column ();
113 last_y = SLsmg_get_row ();
114
115 if (ch == 0)
116 ch = ACS_HLINE;
117
118 if (ch == ACS_HLINE){
119 SLsmg_draw_hline (len);
120 } else {
121 while (len--)
122 addch (ch);
123 }
124 move (last_y, last_x);
125 }
126
127 void vline (int character, int len)
128 {
129 if (!slow_terminal){
130 SLsmg_draw_vline (len);
131 } else {
132 int last_x, last_y, pos = 0;
133
134 last_x = SLsmg_get_column ();
135 last_y = SLsmg_get_row ();
136
137 while (len--){
138 move (last_y + pos++, last_x);
139 addch (' ');
140 }
141 move (last_x, last_y);
142 }
143 }
144
145 int has_colors ()
146 {
147 /* No terminals on NT, make default color */
148 if (!disable_colors)
149 SLtt_Use_Ansi_Colors = 1;
150
151 /* Setup emulated colors */
152 if (SLtt_Use_Ansi_Colors){
153 /* DO NOT TRANSLATE WITH gettext SYNTAX coloring will be broken */
154 init_pair (A_REVERSE, "black", "white");
155 } else {
156 /* SLtt_set_mono (A_BOLD, NULL, SLTT_BOLD_MASK);
157 SLtt_set_mono (A_REVERSE, NULL, SLTT_REV_MASK);
158 SLtt_set_mono (A_BOLD|A_REVERSE, NULL, SLTT_BOLD_MASK | SLTT_REV_MASK);
159 */ }
160 return SLtt_Use_Ansi_Colors;
161 }
162
163 void attrset (int color)
164 {
165 if (!SLtt_Use_Ansi_Colors){
166 SLsmg_set_color (color);
167 return;
168 }
169
170 if (color & A_BOLD){
171 if (color == A_BOLD)
172 SLsmg_set_color (A_BOLD);
173 else
174 SLsmg_set_color ((color & (~A_BOLD)) + 8);
175 return;
176 }
177
178 if (color == A_REVERSE)
179 SLsmg_set_color (A_REVERSE);
180 else
181 SLsmg_set_color (color);
182 }
183
184 void load_terminfo_keys ()
185 {
186 }
187
188 int getch ()
189 {
190 if (no_slang_delay)
191 if (SLang_input_pending (0) == 0)
192 return -1;
193
194 return SLang_getkey ();
195 }
196
197 extern int slow_terminal;
198
199 #else
200
201 /* Non slang builds do not understand got_interrupt */
202 int got_interrupt ()
203 {
204 return 0;
205 }
206 #endif /* HAVE_SLANG */
207
208 void mc_refresh (void)
209 {
210 /* if (!we_are_background) (no background mode yet) */
211 refresh ();
212 }
213
214 void slang_set_raw_mode (void)
215 {
216 return;
217 }
218
219 int max_index = 0;
220
221 void
222 init_pair (int index, char *foreground, char *background)
223 {
224
225 SLtt_set_color (index, "", foreground, background);
226 if (index > max_index)
227 max_index = index;
228 }
229
230 int
231 alloc_color_pair (char *foreground, char *background)
232 {
233 init_pair (++max_index, foreground, background);
234 return max_index;
235 }
236
237 int
238 try_alloc_color_pair (char *fg, char *bg)
239 {
240 static struct colors_avail {
241 struct colors_avail *next;
242 char *fg, *bg;
243 int index;
244 } *p, c =
245 {
246 0, 0, 0, 0
247 };
248
249 c.index = NORMAL_COLOR;
250 p = &c;
251 for (;;) {
252 if (((fg && p->fg) ? !strcmp (fg, p->fg) : fg == p->fg) != 0
253 && ((bg && p->bg) ? !strcmp (bg, p->bg) : bg == p->bg) != 0)
254 return p->index;
255 if (!p->next)
256 break;
257 p = p->next;
258 }
259 p->next = malloc (sizeof (c));
260 p = p->next;
261 p->next = 0;
262 p->fg = fg ? strdup (fg) : 0;
263 p->bg = bg ? strdup (bg) : 0;
264 /* DO NOT TRANSLATE WITH gettext SYNTAX coloring will be broken */
265 if (!fg)
266 fg = "white";
267 if (!bg)
268 bg = "blue";
269 p->index = alloc_color_pair (fg, bg);
270 return p->index;
271 }