Making dflat32 a dll. Its a little broken ATM.
[reactos.git] / rosapps / lib / dflat32 / console.c
1 /* ----------- console.c ---------- */
2
3 //#define WIN32_LEAN_AND_MEAN
4 #include <windows.h>
5
6
7 #include <dflat32/dflat.h>
8
9
10 /* ----- table of alt keys for finding shortcut keys ----- */
11 #if 0
12 static int altconvert[] = {
13 ALT_A,ALT_B,ALT_C,ALT_D,ALT_E,ALT_F,ALT_G,ALT_H,
14 ALT_I,ALT_J,ALT_K,ALT_L,ALT_M,ALT_N,ALT_O,ALT_P,
15 ALT_Q,ALT_R,ALT_S,ALT_T,ALT_U,ALT_V,ALT_W,ALT_X,
16 ALT_Y,ALT_Z,ALT_0,ALT_1,ALT_2,ALT_3,ALT_4,ALT_5,
17 ALT_6,ALT_7,ALT_8,ALT_9
18 };
19 #endif
20
21 static COORD cursorpos[MAXSAVES];
22 static CONSOLE_CURSOR_INFO cursorinfo[MAXSAVES];
23 static int cs = 0;
24
25
26 void SwapCursorStack(void)
27 {
28 if (cs > 1)
29 {
30 COORD coord;
31 CONSOLE_CURSOR_INFO csi;
32
33 coord = cursorpos[cs-2];
34 cursorpos[cs-2] = cursorpos[cs-1];
35 cursorpos[cs-1] = coord;
36
37 memcpy (&csi,
38 &cursorinfo[cs-2],
39 sizeof(CONSOLE_CURSOR_INFO));
40 memcpy (&cursorinfo[cs-2],
41 &cursorinfo[cs-1],
42 sizeof(CONSOLE_CURSOR_INFO));
43 memcpy (&cursorinfo[cs-1],
44 &csi,
45 sizeof(CONSOLE_CURSOR_INFO));
46 }
47 }
48
49
50 /* ---- Read a keystroke ---- */
51 void GetKey (PINPUT_RECORD lpBuffer)
52 {
53 HANDLE hInput;
54 DWORD dwRead;
55
56 hInput = GetStdHandle (STD_INPUT_HANDLE);
57
58 do
59 {
60 // WaitForSingleObject (hInput, INFINITE);
61 ReadConsoleInput (hInput, lpBuffer, 1, &dwRead);
62 if ((lpBuffer->EventType == KEY_EVENT) &&
63 (lpBuffer->Event.KeyEvent.bKeyDown == TRUE))
64 break;
65 }
66 while (TRUE);
67 }
68
69
70 /* ---------- read the keyboard shift status --------- */
71
72 int getshift(void)
73 {
74 // regs.h.ah = 2;
75 // int86(KEYBRD, &regs, &regs);
76 // return regs.h.al;
77 /* FIXME */
78
79 return 0;
80 }
81
82
83 /* -------- sound a buzz tone ---------- */
84 void beep(void)
85 {
86 Beep(440, 50);
87 // MessageBeep (-1);
88 }
89
90
91 /* ------ position the cursor ------ */
92 void cursor(int x, int y)
93 {
94 COORD coPos;
95
96 coPos.X = (USHORT)x;
97 coPos.Y = (USHORT)y;
98 SetConsoleCursorPosition (GetStdHandle (STD_OUTPUT_HANDLE), coPos);
99 }
100
101
102 /* ------- get the current cursor position ------- */
103 void curr_cursor(int *x, int *y)
104 //VOID GetCursorXY (PSHORT x, PSHORT y)
105 {
106 CONSOLE_SCREEN_BUFFER_INFO csbi;
107
108 GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &csbi);
109
110 *x = (int)csbi.dwCursorPosition.X;
111 *y = (int)csbi.dwCursorPosition.Y;
112 }
113
114
115 /* ------ save the current cursor configuration ------ */
116 void savecursor(void)
117 {
118 if (cs < MAXSAVES)
119 {
120 CONSOLE_SCREEN_BUFFER_INFO csbi;
121
122 GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &csbi);
123 cursorpos[cs].X = csbi.dwCursorPosition.X;
124 cursorpos[cs].Y = csbi.dwCursorPosition.Y;
125
126 GetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE),
127 &(cursorinfo[cs]));
128
129 cs++;
130 }
131 }
132
133 /* ---- restore the saved cursor configuration ---- */
134 void restorecursor(void)
135 {
136 if (cs)
137 {
138 --cs;
139 SetConsoleCursorPosition (GetStdHandle (STD_OUTPUT_HANDLE),
140 cursorpos[cs]);
141 SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE),
142 &(cursorinfo[cs]));
143 }
144 }
145
146 /* ------ make a normal cursor ------ */
147 void normalcursor(void)
148 {
149 CONSOLE_CURSOR_INFO csi;
150
151 csi.bVisible = TRUE;
152 csi.dwSize = 5;
153 SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE),
154 &csi);
155 }
156
157 /* ------ hide the cursor ------ */
158 void hidecursor(void)
159 {
160 CONSOLE_CURSOR_INFO csi;
161
162 GetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE),
163 &csi);
164 csi.bVisible = FALSE;
165 SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE),
166 &csi);
167 }
168
169 /* ------ unhide the cursor ------ */
170 void unhidecursor(void)
171 {
172 CONSOLE_CURSOR_INFO csi;
173
174 GetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE),
175 &csi);
176 csi.bVisible = TRUE;
177 SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE),
178 &csi);
179 }
180
181 /* set the cursor size (in percent) */
182 void set_cursor_size (unsigned t)
183 {
184 CONSOLE_CURSOR_INFO csi;
185
186 GetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE),
187 &csi);
188
189 if (t < 2)
190 csi.dwSize = 2;
191 else if (t > 90)
192 csi.dwSize = 90;
193 else
194 csi.dwSize = t;
195 SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE),
196 &csi);
197 }
198
199
200 /* ------ convert an Alt+ key to its letter equivalent ----- */
201 int AltConvert(int c)
202 {
203 return c;
204 #if 0
205 int i, a = 0;
206 for (i = 0; i < 36; i++)
207 if (c == altconvert[i])
208 break;
209 if (i < 26)
210 a = 'a' + i;
211 else if (i < 36)
212 a = '0' + i - 26;
213 return a;
214 #endif
215 }
216
217 /* EOF */