comparison src/console-msw.c @ 404:2f8bb876ab1d r21-2-32

Import from CVS: tag r21-2-32
author cvs
date Mon, 13 Aug 2007 11:16:07 +0200
parents 74fd4e045ea6
children 501cfd01ee6d
comparison
equal deleted inserted replaced
403:9f011ab08d48 404:2f8bb876ab1d
1 /* Console functions for mswindows. 1 /* Console functions for mswindows.
2 Copyright (C) 1996 Ben Wing. 2 Copyright (C) 1996, 2000 Ben Wing.
3 3
4 This file is part of XEmacs. 4 This file is part of XEmacs.
5 5
6 XEmacs is free software; you can redistribute it and/or modify it 6 XEmacs is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the 7 under the terms of the GNU General Public License as published by the
26 Rewritten for mswindows by Jonathan Harris, November 1997 for 21.0 26 Rewritten for mswindows by Jonathan Harris, November 1997 for 21.0
27 */ 27 */
28 28
29 #include <config.h> 29 #include <config.h>
30 #include "lisp.h" 30 #include "lisp.h"
31 #include "events.h"
32 #include "opaque.h"
31 33
32 #include "console-msw.h" 34 #include "console-msw.h"
33 35
34 DEFINE_CONSOLE_TYPE (mswindows); 36 DEFINE_CONSOLE_TYPE (mswindows);
35 DEFINE_CONSOLE_TYPE (msprinter); 37 DEFINE_CONSOLE_TYPE (msprinter);
40 42
41 static int 43 static int
42 mswindows_initially_selected_for_input (struct console *con) 44 mswindows_initially_selected_for_input (struct console *con)
43 { 45 {
44 return 1; 46 return 1;
47 }
48
49 static HWND msw_console_hwnd = 0;
50
51 #define KLUDGE_BUFSIZE 1024 /* buffer size for console window titles */
52
53 /* Direct from the horse's mouth: Microsoft KB article Q124103 */
54 static HWND
55 GetConsoleHwnd (void)
56 {
57 HWND hwndFound; /* this is what is returned to the caller */
58 char pszNewWindowTitle[KLUDGE_BUFSIZE]; /* contains fabricated WindowTitle */
59 char pszOldWindowTitle[KLUDGE_BUFSIZE]; /* contains original WindowTitle */
60
61 /* fetch current window title */
62
63 GetConsoleTitle(pszOldWindowTitle, KLUDGE_BUFSIZE);
64
65 /* format a "unique" NewWindowTitle */
66
67 wsprintf(pszNewWindowTitle,"%d/%d",
68 GetTickCount(),
69 GetCurrentProcessId());
70
71 /* change current window title */
72
73 SetConsoleTitle(pszNewWindowTitle);
74
75 /* ensure window title has been updated */
76
77 Sleep(40);
78
79 /* look for NewWindowTitle */
80
81 hwndFound=FindWindow(NULL, pszNewWindowTitle);
82
83 /* restore original window title */
84
85 SetConsoleTitle(pszOldWindowTitle);
86
87 return(hwndFound);
88 }
89
90 HWND
91 msw_get_console_hwnd (void)
92 {
93 if (!msw_console_hwnd)
94 msw_console_hwnd = GetConsoleHwnd ();
95 return msw_console_hwnd;
96 }
97
98 int
99 msw_ensure_console_allocated (void)
100 {
101 HWND fgwin = GetForegroundWindow ();
102 /* stupid mswin api won't let you create the console window
103 hidden! creating it changes the focus! fuck me! */
104 if (AllocConsole ())
105 {
106 SetForegroundWindow (fgwin);
107 return 1;
108 }
109 return 0;
45 } 110 }
46 111
47 static Lisp_Object 112 static Lisp_Object
48 mswindows_canonicalize_console_connection (Lisp_Object connection, 113 mswindows_canonicalize_console_connection (Lisp_Object connection,
49 Error_behavior errb) 114 Error_behavior errb)
69 Error_behavior errb) 134 Error_behavior errb)
70 { 135 {
71 return mswindows_canonicalize_console_connection (connection, errb); 136 return mswindows_canonicalize_console_connection (connection, errb);
72 } 137 }
73 138
139 void
140 msw_hide_console (void)
141 {
142 ShowWindow (msw_get_console_hwnd (), SW_HIDE);
143 }
144
145 void
146 msw_show_console (void)
147 {
148 HWND hwnd = msw_get_console_hwnd ();
149 ShowWindow (hwnd, SW_SHOWNA);
150
151 /* I tried to raise the window to the top without activating
152 it, but this fails. Apparently Windows just doesn't like
153 having the active window not be on top. So instead, we
154 at least put it just below our own window, where part of it
155 will likely be seen. */
156 SetWindowPos (hwnd, GetForegroundWindow (), 0, 0, 0, 0,
157 SWP_NOSIZE | SWP_NOMOVE | SWP_NOSENDCHANGING |
158 SWP_NOACTIVATE);
159 }
160
161 static int msw_console_buffered = 0;
162 HANDLE msw_console_buffer;
163
164 static void
165 msw_ensure_console_buffered (void)
166 {
167 if (!msw_console_buffered)
168 {
169 COORD new_size;
170
171 new_size.X = 80;
172 new_size.Y = 1000;
173 msw_ensure_console_allocated ();
174 msw_console_buffer =
175 CreateConsoleScreenBuffer (GENERIC_WRITE, 0, NULL,
176 CONSOLE_TEXTMODE_BUFFER, NULL);
177 SetConsoleScreenBufferSize (msw_console_buffer, new_size);
178 SetConsoleActiveScreenBuffer (msw_console_buffer);
179 msw_console_buffered = 1;
180 }
181 }
182
183 int
184 msw_output_console_string (CONST Extbyte *str, Extcount len)
185 {
186 DWORD num_written;
187
188 msw_ensure_console_buffered ();
189 msw_show_console ();
190 return WriteConsole (msw_console_buffer, str, len, &num_written, NULL);
191 }
192
193 /* Determine if running on Windows 9x and not NT */
194 int
195 msw_windows9x_p (void)
196 {
197 return GetVersion () & 0x80000000;
198 }
199
200
201 #ifdef DEBUG_XEMACS
202
203 /*
204 * Random helper functions for debugging.
205 * Intended for use in the MSVC "Watch" window which doesn't like
206 * the aborts that the error_check_foo() functions can make.
207 */
208 struct lrecord_header *
209 DHEADER (Lisp_Object obj)
210 {
211 return LRECORDP (obj) ? XRECORD_LHEADER (obj) : NULL;
212 }
213
214 void *
215 DOPAQUE_DATA (Lisp_Object obj)
216 {
217 return OPAQUEP (obj) ? OPAQUE_DATA (XOPAQUE (obj)) : NULL;
218 }
219
220 Lisp_Event *
221 DEVENT (Lisp_Object obj)
222 {
223 return EVENTP (obj) ? XEVENT (obj) : NULL;
224 }
225
226 Lisp_Cons *
227 DCONS (Lisp_Object obj)
228 {
229 return CONSP (obj) ? XCONS (obj) : NULL;
230 }
231
232 Lisp_Cons *
233 DCONSCDR (Lisp_Object obj)
234 {
235 return (CONSP (obj) && CONSP (XCDR (obj))) ? XCONS (XCDR (obj)) : 0;
236 }
237
238 Bufbyte *
239 DSTRING (Lisp_Object obj)
240 {
241 return STRINGP (obj) ? XSTRING_DATA (obj) : NULL;
242 }
243
244 Lisp_Vector *
245 DVECTOR (Lisp_Object obj)
246 {
247 return VECTORP (obj) ? XVECTOR (obj) : NULL;
248 }
249
250 Lisp_Symbol *
251 DSYMBOL (Lisp_Object obj)
252 {
253 return SYMBOLP (obj) ? XSYMBOL (obj) : NULL;
254 }
255
256 Bufbyte *
257 DSYMNAME (Lisp_Object obj)
258 {
259 return SYMBOLP (obj) ? string_data (XSYMBOL (obj)->name) : NULL;
260 }
261
262 #endif /* DEBUG_XEMACS */
263
264
74 265
75 /************************************************************************/ 266 /************************************************************************/
76 /* initialization */ 267 /* initialization */
77 /************************************************************************/ 268 /************************************************************************/
78 269
109 void 300 void
110 vars_of_console_mswindows (void) 301 vars_of_console_mswindows (void)
111 { 302 {
112 Fprovide (Qmswindows); 303 Fprovide (Qmswindows);
113 } 304 }
114
115
116 #ifdef DEBUG_XEMACS
117 #include "events.h"
118 #include "opaque.h"
119 /*
120 * Random helper functions for debugging.
121 * Intended for use in the MSVC "Watch" window which doesn't like
122 * the aborts that the error_check_foo() functions can make.
123 */
124 struct lrecord_header *
125 DHEADER (Lisp_Object obj)
126 {
127 return LRECORDP (obj) ? XRECORD_LHEADER (obj) : NULL;
128 }
129
130 void *
131 DOPAQUE_DATA (Lisp_Object obj)
132 {
133 return OPAQUEP (obj) ? OPAQUE_DATA (XOPAQUE (obj)) : NULL;
134 }
135
136 Lisp_Event *
137 DEVENT (Lisp_Object obj)
138 {
139 return EVENTP (obj) ? XEVENT (obj) : NULL;
140 }
141
142 Lisp_Cons *
143 DCONS (Lisp_Object obj)
144 {
145 return CONSP (obj) ? XCONS (obj) : NULL;
146 }
147
148 Lisp_Cons *
149 DCONSCDR (Lisp_Object obj)
150 {
151 return (CONSP (obj) && CONSP (XCDR (obj))) ? XCONS (XCDR (obj)) : 0;
152 }
153
154 Bufbyte *
155 DSTRING (Lisp_Object obj)
156 {
157 return STRINGP (obj) ? XSTRING_DATA (obj) : NULL;
158 }
159
160 Lisp_Vector *
161 DVECTOR (Lisp_Object obj)
162 {
163 return VECTORP (obj) ? XVECTOR (obj) : NULL;
164 }
165
166 Lisp_Symbol *
167 DSYMBOL (Lisp_Object obj)
168 {
169 return SYMBOLP (obj) ? XSYMBOL (obj) : NULL;
170 }
171
172 Bufbyte *
173 DSYMNAME (Lisp_Object obj)
174 {
175 return SYMBOLP (obj) ? string_data (XSYMBOL (obj)->name) : NULL;
176 }
177
178 #endif /* DEBUG_XEMACS */