comparison src/console-msw.c @ 771:943eaba38521

[xemacs-hg @ 2002-03-13 08:51:24 by ben] The big ben-mule-21-5 check-in! Various files were added and deleted. See CHANGES-ben-mule. There are still some test suite failures. No crashes, though. Many of the failures have to do with problems in the test suite itself rather than in the actual code. I'll be addressing these in the next day or so -- none of the test suite failures are at all critical. Meanwhile I'll be trying to address the biggest issues -- i.e. build or run failures, which will almost certainly happen on various platforms. All comments should be sent to ben@xemacs.org -- use a Cc: if necessary when sending to mailing lists. There will be pre- and post- tags, something like pre-ben-mule-21-5-merge-in, and post-ben-mule-21-5-merge-in.
author ben
date Wed, 13 Mar 2002 08:54:06 +0000
parents fdefd0186b75
children e38acbeb1cae
comparison
equal deleted inserted replaced
770:336a418893b5 771:943eaba38521
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */ 19 Boston, MA 02111-1307, USA. */
20 20
21 /* Synched up with: Not in FSF. */ 21 /* Synched up with: Not in FSF. */
22 22
23 /* This file essentially Mule-ized (except perhaps some Unicode splitting).
24 5-2000. */
25
23 /* Authorship: 26 /* Authorship:
24 27
25 Ben Wing: January 1996, for 19.14. 28 Ben Wing: January 1996, for 19.14.
26 Rewritten for mswindows by Jonathan Harris, November 1997 for 21.0 29 Rewritten for mswindows by Jonathan Harris, November 1997 for 21.0
27 */ 30 */
28 31
29 #include <config.h> 32 #include <config.h>
30 #include "lisp.h" 33 #include "lisp.h"
31 34
32 #include "buffer.h"
33 #include "console-msw.h" 35 #include "console-msw.h"
34 #include "events.h" 36 #include "events.h"
35 #include "opaque.h" 37 #include "opaque.h"
36 38
37 DEFINE_CONSOLE_TYPE (mswindows); 39 DEFINE_CONSOLE_TYPE (mswindows);
95 char pszNewWindowTitle[KLUDGE_BUFSIZE]; /* contains fabricated WindowTitle */ 97 char pszNewWindowTitle[KLUDGE_BUFSIZE]; /* contains fabricated WindowTitle */
96 char pszOldWindowTitle[KLUDGE_BUFSIZE]; /* contains original WindowTitle */ 98 char pszOldWindowTitle[KLUDGE_BUFSIZE]; /* contains original WindowTitle */
97 99
98 /* fetch current window title */ 100 /* fetch current window title */
99 101
100 GetConsoleTitle(pszOldWindowTitle, KLUDGE_BUFSIZE); 102 GetConsoleTitle (pszOldWindowTitle, KLUDGE_BUFSIZE);
101 103
102 /* format a "unique" NewWindowTitle */ 104 /* format a "unique" NewWindowTitle */
103 105
104 wsprintf(pszNewWindowTitle,"%d/%d", 106 sprintf (pszNewWindowTitle, "%ld/%ld",
105 GetTickCount(), 107 GetTickCount (),
106 GetCurrentProcessId()); 108 GetCurrentProcessId ());
107 109
108 /* change current window title */ 110 /* change current window title */
109 111
110 SetConsoleTitle(pszNewWindowTitle); 112 SetConsoleTitle (pszNewWindowTitle);
111 113
112 /* ensure window title has been updated */ 114 /* ensure window title has been updated */
113 115
114 Sleep(40); 116 Sleep (40);
115 117
116 /* look for NewWindowTitle */ 118 /* look for NewWindowTitle */
117 119
118 hwndFound=FindWindow(NULL, pszNewWindowTitle); 120 hwndFound=FindWindow (NULL, pszNewWindowTitle);
119 121
120 /* restore original window title */ 122 /* restore original window title */
121 123
122 SetConsoleTitle(pszOldWindowTitle); 124 SetConsoleTitle (pszOldWindowTitle);
123 125
124 return(hwndFound); 126 return (hwndFound);
125 } 127 }
126 128
127 HWND 129 static HWND
128 mswindows_get_console_hwnd (void) 130 mswindows_get_console_hwnd (void)
129 { 131 {
130 if (!mswindows_console_hwnd) 132 if (!mswindows_console_hwnd)
131 mswindows_console_hwnd = GetConsoleHwnd (); 133 mswindows_console_hwnd = GetConsoleHwnd ();
132 return mswindows_console_hwnd; 134 return mswindows_console_hwnd;
177 mswindows_hide_console (void) 179 mswindows_hide_console (void)
178 { 180 {
179 ShowWindow (mswindows_get_console_hwnd (), SW_HIDE); 181 ShowWindow (mswindows_get_console_hwnd (), SW_HIDE);
180 } 182 }
181 183
182 void 184 static void
183 mswindows_show_console (void) 185 mswindows_show_console (void)
184 { 186 {
185 /* What I really want is for the console window to appear on top of other 187 /* What I really want is for the console window to appear on top of other
186 windows, but NOT get the focus. This seems hard-to-impossible under 188 windows, but NOT get the focus. This seems hard-to-impossible under
187 Windows. The following sequence seems to do the best possible, along 189 Windows. The following sequence seems to do the best possible, along
188 with keeping the console window on top when xemacs --help is used. */ 190 with keeping the console window on top when xemacs --help is used. */
189 HWND hwnd = mswindows_get_console_hwnd (); 191 HWND hwnd = mswindows_get_console_hwnd ();
190 HWND hwndf = GetFocus (); 192 HWND hwndf = GetFocus ();
191 ShowWindow (hwnd, SW_SHOW); 193 if (!IsWindowVisible (hwnd))
192 BringWindowToTop (hwnd); 194 ShowWindow (hwnd, SW_SHOWNA);
193 SetFocus (hwndf); 195 if (noninteractive)
196 BringWindowToTop (hwnd);
197 else
198 SetWindowPos (hwnd, hwndf, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
199 | SWP_NOACTIVATE);
194 } 200 }
195 201
196 static int mswindows_console_buffered = 0; 202 static int mswindows_console_buffered = 0;
197 HANDLE mswindows_console_buffer; 203 HANDLE mswindows_console_buffer;
198 204
216 } 222 }
217 223
218 int mswindows_message_outputted; 224 int mswindows_message_outputted;
219 225
220 int 226 int
221 mswindows_output_console_string (CONST Extbyte *str, Bytecount len) 227 mswindows_output_console_string (const Intbyte *ptr, Bytecount len)
222 { 228 {
223 DWORD num_written; 229 DWORD num_written;
224 230
225 mswindows_message_outputted = 1; 231 mswindows_message_outputted = 1;
226 mswindows_ensure_console_buffered (); 232 mswindows_ensure_console_buffered ();
227 mswindows_show_console (); 233 mswindows_show_console ();
228 return WriteConsole (mswindows_console_buffer, str, len, &num_written, NULL); 234
229 } 235 if (initialized && !inhibit_non_essential_printing_operations)
230 236 {
231 /* Determine if running on Windows 9x and not NT */ 237 const Extbyte *extptr;
232 int 238 Bytecount extlen;
233 mswindows_windows9x_p (void) 239 TO_EXTERNAL_FORMAT (DATA, (ptr, len),
234 { 240 ALLOCA, (extptr, extlen),
235 return GetVersion () & 0x80000000; 241 Qmswindows_tstr);
242 return qxeWriteConsole (mswindows_console_buffer, extptr,
243 extlen / XETCHAR_SIZE, &num_written, NULL);
244 }
245 else
246 return WriteConsoleA (mswindows_console_buffer, (char *) ptr, len,
247 &num_written, NULL);
236 } 248 }
237 249
238 DEFUN ("mswindows-debugging-output", Fmswindows_debugging_output, 1, 1, 0, /* 250 DEFUN ("mswindows-debugging-output", Fmswindows_debugging_output, 1, 1, 0, /*
239 Write CHAR-OR-STRING to the Windows debugger, using OutputDebugString(). 251 Write CHAR-OR-STRING to the Windows debugger, using OutputDebugString().
240 This function can be used as the STREAM argument of Fprint() or the like. 252 This function can be used as the STREAM argument of Fprint() or the like.
241 */ 253 */
242 (char_or_string)) 254 (char_or_string))
243 { 255 {
244 Extbyte *extstr;
245
246 if (STRINGP (char_or_string)) 256 if (STRINGP (char_or_string))
247 { 257 /* It's safe to pass in string data because TO_EXTERNAL_FORMAT
248 TO_EXTERNAL_FORMAT (LISP_STRING, char_or_string, 258 inhibits GC. */
249 C_STRING_ALLOCA, extstr, 259 write_string_to_mswindows_debugging_output
250 Qmswindows_tstr); 260 (XSTRING_DATA (char_or_string), XSTRING_LENGTH (char_or_string));
251 OutputDebugString (extstr);
252 }
253 else 261 else
254 { 262 {
255 Intbyte str[MAX_EMCHAR_LEN + 1]; 263 Intbyte str[MAX_EMCHAR_LEN];
256 Bytecount len; 264 Bytecount len;
257 265
258 CHECK_CHAR_COERCE_INT (char_or_string); 266 CHECK_CHAR_COERCE_INT (char_or_string);
259 len = set_charptr_emchar (str, XCHAR (char_or_string)); 267 len = set_charptr_emchar (str, XCHAR (char_or_string));
260 str[len] = '\0'; 268 write_string_to_mswindows_debugging_output (str, len);
261 TO_EXTERNAL_FORMAT (C_STRING, str, 269 }
262 C_STRING_ALLOCA, extstr, 270
271 return char_or_string;
272 }
273
274 void
275 write_string_to_mswindows_debugging_output (Intbyte *str, Bytecount len)
276 {
277 const Extbyte *extptr;
278 if (initialized && !inhibit_non_essential_printing_operations)
279 {
280 TO_EXTERNAL_FORMAT (DATA, (str, len),
281 C_STRING_ALLOCA, extptr,
263 Qmswindows_tstr); 282 Qmswindows_tstr);
264 OutputDebugString (extstr); 283 qxeOutputDebugString (extptr);
265 } 284 }
266 285 else
267 return char_or_string; 286 OutputDebugStringA ((char *) str);
268 } 287 }
269 288
270 #ifdef DEBUG_XEMACS 289 #ifdef DEBUG_XEMACS
271 290
272 /* 291 /*
480 CHECK_SYMBOL (flags); 499 CHECK_SYMBOL (flags);
481 flags = list1 (flags); 500 flags = list1 (flags);
482 } 501 }
483 502
484 CHECK_STRING (message_); 503 CHECK_STRING (message_);
485 TO_EXTERNAL_FORMAT (LISP_STRING, message_, 504 LISP_STRING_TO_TSTR (message_, msgout);
486 C_STRING_ALLOCA, msgout,
487 Qmswindows_tstr);
488 505
489 if (!NILP (title)) 506 if (!NILP (title))
490 { 507 {
491 CHECK_STRING (title); 508 CHECK_STRING (title);
492 TO_EXTERNAL_FORMAT (LISP_STRING, title, 509 LISP_STRING_TO_TSTR (title, titleout);
493 C_STRING_ALLOCA, titleout,
494 Qmswindows_tstr);
495 } 510 }
496 511
497 EXTERNAL_LIST_LOOP (tail, flags) 512 EXTERNAL_LIST_LOOP (tail, flags)
498 { 513 {
499 Lisp_Object st = XCAR (tail); 514 Lisp_Object st = XCAR (tail);
532 else 547 else
533 invalid_constant ("Unrecognized flag", st); 548 invalid_constant ("Unrecognized flag", st);
534 } 549 }
535 550
536 { 551 {
537 int retval = MessageBox (NULL, msgout, titleout, sty); 552 int retval = qxeMessageBox (NULL, msgout, titleout, sty);
538 553
539 if (retval == 0) 554 if (retval == 0)
540 out_of_memory ("When calling `mswindows-message-box'", Qunbound); 555 out_of_memory ("When calling `mswindows-message-box'", Qunbound);
541 556
542 #define FROB(sym, val) if (retval == val) return sym 557 #define FROB(sym, val) if (retval == val) return sym
552 invalid_argument ("Unknown return value from MessageBox()", 567 invalid_argument ("Unknown return value from MessageBox()",
553 make_int (retval)); 568 make_int (retval));
554 } 569 }
555 570
556 return Qnil; 571 return Qnil;
557 }
558
559 Lisp_Object
560 mswindows_lisp_error (int errnum)
561 {
562 LPTSTR lpMsgBuf;
563 Lisp_Object result;
564 Intbyte *inres;
565 Bytecount len;
566
567 FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER
568 | FORMAT_MESSAGE_FROM_SYSTEM,
569 NULL, errnum,
570 /* !!#### not Mule-correct */
571 MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
572 /* yeah, i'm casting a char ** to a char *. ya gotta
573 problem widdat? */
574 (LPTSTR) &lpMsgBuf,
575 0,
576 NULL);
577
578 TO_INTERNAL_FORMAT (C_STRING, lpMsgBuf, ALLOCA, (inres, len),
579 Qmswindows_tstr);
580 /* Messages tend to end with a period and newline */
581 if (len >= 3 && !intbyte_strcmp (inres + len - 3, ".\r\n"))
582 len -= 3;
583 result = make_string (inres, len);
584
585 LocalFree (lpMsgBuf);
586 return result;
587 }
588
589 void
590 mswindows_output_last_error (char *frob)
591 {
592 int errval = GetLastError ();
593 Lisp_Object errmess = mswindows_lisp_error (errval);
594
595 stderr_out ("last error during %s is %d: %s\n",
596 frob, errval, XSTRING_DATA (errmess));
597 } 572 }
598 573
599 static Lisp_Object 574 static Lisp_Object
600 msprinter_canonicalize_console_connection (Lisp_Object connection, 575 msprinter_canonicalize_console_connection (Lisp_Object connection,
601 Error_Behavior errb) 576 Error_Behavior errb)