comparison src/console-msw.c @ 410:de805c49cfc1 r21-2-35

Import from CVS: tag r21-2-35
author cvs
date Mon, 13 Aug 2007 11:19:21 +0200
parents 501cfd01ee6d
children 697ef44129c6
comparison
equal deleted inserted replaced
409:301b9ebbdf3b 410:de805c49cfc1
81 mswindows_initially_selected_for_input (struct console *con) 81 mswindows_initially_selected_for_input (struct console *con)
82 { 82 {
83 return 1; 83 return 1;
84 } 84 }
85 85
86 static HWND msw_console_hwnd = 0; 86 static HWND mswindows_console_hwnd = 0;
87 87
88 #define KLUDGE_BUFSIZE 1024 /* buffer size for console window titles */ 88 #define KLUDGE_BUFSIZE 1024 /* buffer size for console window titles */
89 89
90 /* Direct from the horse's mouth: Microsoft KB article Q124103 */ 90 /* Direct from the horse's mouth: Microsoft KB article Q124103 */
91 static HWND 91 static HWND
123 123
124 return(hwndFound); 124 return(hwndFound);
125 } 125 }
126 126
127 HWND 127 HWND
128 msw_get_console_hwnd (void) 128 mswindows_get_console_hwnd (void)
129 { 129 {
130 if (!msw_console_hwnd) 130 if (!mswindows_console_hwnd)
131 msw_console_hwnd = GetConsoleHwnd (); 131 mswindows_console_hwnd = GetConsoleHwnd ();
132 return msw_console_hwnd; 132 return mswindows_console_hwnd;
133 } 133 }
134 134
135 int 135 static int
136 msw_ensure_console_allocated (void) 136 mswindows_ensure_console_allocated (void)
137 { 137 {
138 HWND fgwin = GetForegroundWindow (); 138 HWND fgwin = GetForegroundWindow ();
139 /* stupid mswin api won't let you create the console window 139 /* stupid mswin api won't let you create the console window
140 hidden! creating it changes the focus! fuck me! */ 140 hidden! creating it changes the focus! fuck me! */
141 if (AllocConsole ()) 141 if (AllocConsole ())
172 { 172 {
173 return mswindows_canonicalize_console_connection (connection, errb); 173 return mswindows_canonicalize_console_connection (connection, errb);
174 } 174 }
175 175
176 void 176 void
177 msw_hide_console (void) 177 mswindows_hide_console (void)
178 { 178 {
179 ShowWindow (msw_get_console_hwnd (), SW_HIDE); 179 ShowWindow (mswindows_get_console_hwnd (), SW_HIDE);
180 } 180 }
181 181
182 void 182 void
183 msw_show_console (void) 183 mswindows_show_console (void)
184 { 184 {
185 HWND hwnd = msw_get_console_hwnd (); 185 HWND hwnd = mswindows_get_console_hwnd ();
186 ShowWindow (hwnd, SW_SHOWNA); 186 ShowWindow (hwnd, SW_SHOWNA);
187 187
188 /* I tried to raise the window to the top without activating 188 /* I tried to raise the window to the top without activating
189 it, but this fails. Apparently Windows just doesn't like 189 it, but this fails. Apparently Windows just doesn't like
190 having the active window not be on top. So instead, we 190 having the active window not be on top. So instead, we
193 SetWindowPos (hwnd, GetForegroundWindow (), 0, 0, 0, 0, 193 SetWindowPos (hwnd, GetForegroundWindow (), 0, 0, 0, 0,
194 SWP_NOSIZE | SWP_NOMOVE | SWP_NOSENDCHANGING | 194 SWP_NOSIZE | SWP_NOMOVE | SWP_NOSENDCHANGING |
195 SWP_NOACTIVATE); 195 SWP_NOACTIVATE);
196 } 196 }
197 197
198 static int msw_console_buffered = 0; 198 static int mswindows_console_buffered = 0;
199 HANDLE msw_console_buffer; 199 HANDLE mswindows_console_buffer;
200 200
201 static void 201 static void
202 msw_ensure_console_buffered (void) 202 mswindows_ensure_console_buffered (void)
203 { 203 {
204 if (!msw_console_buffered) 204 if (!mswindows_console_buffered)
205 { 205 {
206 COORD new_size; 206 COORD new_size;
207 207
208 new_size.X = 80; 208 new_size.X = 80;
209 new_size.Y = 1000; 209 new_size.Y = 1000;
210 msw_ensure_console_allocated (); 210 mswindows_ensure_console_allocated ();
211 msw_console_buffer = 211 mswindows_console_buffer =
212 CreateConsoleScreenBuffer (GENERIC_WRITE, 0, NULL, 212 CreateConsoleScreenBuffer (GENERIC_WRITE, 0, NULL,
213 CONSOLE_TEXTMODE_BUFFER, NULL); 213 CONSOLE_TEXTMODE_BUFFER, NULL);
214 SetConsoleScreenBufferSize (msw_console_buffer, new_size); 214 SetConsoleScreenBufferSize (mswindows_console_buffer, new_size);
215 SetConsoleActiveScreenBuffer (msw_console_buffer); 215 SetConsoleActiveScreenBuffer (mswindows_console_buffer);
216 msw_console_buffered = 1; 216 mswindows_console_buffered = 1;
217 } 217 }
218 } 218 }
219 219
220 int mswindows_message_outputted;
221
220 int 222 int
221 msw_output_console_string (CONST Extbyte *str, Extcount len) 223 mswindows_output_console_string (CONST Extbyte *str, Extcount len)
222 { 224 {
223 DWORD num_written; 225 DWORD num_written;
224 226
225 msw_ensure_console_buffered (); 227 mswindows_message_outputted = 1;
226 msw_show_console (); 228 mswindows_ensure_console_buffered ();
227 return WriteConsole (msw_console_buffer, str, len, &num_written, NULL); 229 mswindows_show_console ();
230 return WriteConsole (mswindows_console_buffer, str, len, &num_written, NULL);
228 } 231 }
229 232
230 /* Determine if running on Windows 9x and not NT */ 233 /* Determine if running on Windows 9x and not NT */
231 int 234 int
232 msw_windows9x_p (void) 235 mswindows_windows9x_p (void)
233 { 236 {
234 return GetVersion () & 0x80000000; 237 return GetVersion () & 0x80000000;
235 } 238 }
236 239
237 240
240 /* 243 /*
241 * Random helper functions for debugging. 244 * Random helper functions for debugging.
242 * Intended for use in the MSVC "Watch" window which doesn't like 245 * Intended for use in the MSVC "Watch" window which doesn't like
243 * the aborts that the error_check_foo() functions can make. 246 * the aborts that the error_check_foo() functions can make.
244 */ 247 */
248 struct lrecord_header *DHEADER (Lisp_Object obj);
245 struct lrecord_header * 249 struct lrecord_header *
246 DHEADER (Lisp_Object obj) 250 DHEADER (Lisp_Object obj)
247 { 251 {
248 return LRECORDP (obj) ? XRECORD_LHEADER (obj) : NULL; 252 return LRECORDP (obj) ? XRECORD_LHEADER (obj) : NULL;
249 } 253 }
250 254
255 void *DOPAQUE_DATA (Lisp_Object obj);
251 void * 256 void *
252 DOPAQUE_DATA (Lisp_Object obj) 257 DOPAQUE_DATA (Lisp_Object obj)
253 { 258 {
254 return OPAQUEP (obj) ? OPAQUE_DATA (XOPAQUE (obj)) : NULL; 259 return OPAQUEP (obj) ? OPAQUE_DATA (XOPAQUE (obj)) : NULL;
255 } 260 }
256 261
262 Lisp_Event *DEVENT (Lisp_Object obj);
257 Lisp_Event * 263 Lisp_Event *
258 DEVENT (Lisp_Object obj) 264 DEVENT (Lisp_Object obj)
259 { 265 {
260 return EVENTP (obj) ? XEVENT (obj) : NULL; 266 return EVENTP (obj) ? XEVENT (obj) : NULL;
261 } 267 }
262 268
269 Lisp_Cons *DCONS (Lisp_Object obj);
263 Lisp_Cons * 270 Lisp_Cons *
264 DCONS (Lisp_Object obj) 271 DCONS (Lisp_Object obj)
265 { 272 {
266 return CONSP (obj) ? XCONS (obj) : NULL; 273 return CONSP (obj) ? XCONS (obj) : NULL;
267 } 274 }
268 275
276 Lisp_Cons *DCONSCDR (Lisp_Object obj);
269 Lisp_Cons * 277 Lisp_Cons *
270 DCONSCDR (Lisp_Object obj) 278 DCONSCDR (Lisp_Object obj)
271 { 279 {
272 return (CONSP (obj) && CONSP (XCDR (obj))) ? XCONS (XCDR (obj)) : 0; 280 return (CONSP (obj) && CONSP (XCDR (obj))) ? XCONS (XCDR (obj)) : 0;
273 } 281 }
274 282
283 Bufbyte *DSTRING (Lisp_Object obj);
275 Bufbyte * 284 Bufbyte *
276 DSTRING (Lisp_Object obj) 285 DSTRING (Lisp_Object obj)
277 { 286 {
278 return STRINGP (obj) ? XSTRING_DATA (obj) : NULL; 287 return STRINGP (obj) ? XSTRING_DATA (obj) : NULL;
279 } 288 }
280 289
290 Lisp_Vector *DVECTOR (Lisp_Object obj);
281 Lisp_Vector * 291 Lisp_Vector *
282 DVECTOR (Lisp_Object obj) 292 DVECTOR (Lisp_Object obj)
283 { 293 {
284 return VECTORP (obj) ? XVECTOR (obj) : NULL; 294 return VECTORP (obj) ? XVECTOR (obj) : NULL;
285 } 295 }
286 296
297 Lisp_Symbol *DSYMBOL (Lisp_Object obj);
287 Lisp_Symbol * 298 Lisp_Symbol *
288 DSYMBOL (Lisp_Object obj) 299 DSYMBOL (Lisp_Object obj)
289 { 300 {
290 return SYMBOLP (obj) ? XSYMBOL (obj) : NULL; 301 return SYMBOLP (obj) ? XSYMBOL (obj) : NULL;
291 } 302 }
292 303
304 Bufbyte *DSYMNAME (Lisp_Object obj);
293 Bufbyte * 305 Bufbyte *
294 DSYMNAME (Lisp_Object obj) 306 DSYMNAME (Lisp_Object obj)
295 { 307 {
296 return SYMBOLP (obj) ? string_data (XSYMBOL (obj)->name) : NULL; 308 return SYMBOLP (obj) ? string_data (XSYMBOL (obj)->name) : NULL;
297 } 309 }