1 /* Console functions for mswindows.
2 Copyright (C) 1996, 2000 Ben Wing.
4 This file is part of XEmacs.
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
8 Free Software Foundation; either version 2, or (at your option) any
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with XEmacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* Synched up with: Not in FSF. */
25 Ben Wing: January 1996, for 19.14.
26 Rewritten for mswindows by Jonathan Harris, November 1997 for 21.0
34 #include "console-msw.h"
36 DEFINE_CONSOLE_TYPE (mswindows);
37 DEFINE_CONSOLE_TYPE (msprinter);
39 /************************************************************************/
40 /* mswindows console methods */
41 /************************************************************************/
44 mswindows_initially_selected_for_input (struct console *con)
49 static HWND msw_console_hwnd = 0;
51 #define KLUDGE_BUFSIZE 1024 /* buffer size for console window titles */
53 /* Direct from the horse's mouth: Microsoft KB article Q124103 */
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 */
61 /* fetch current window title */
63 GetConsoleTitle(pszOldWindowTitle, KLUDGE_BUFSIZE);
65 /* format a "unique" NewWindowTitle */
67 wsprintf(pszNewWindowTitle,"%d/%d",
69 GetCurrentProcessId());
71 /* change current window title */
73 SetConsoleTitle(pszNewWindowTitle);
75 /* ensure window title has been updated */
79 /* look for NewWindowTitle */
81 hwndFound=FindWindow(NULL, pszNewWindowTitle);
83 /* restore original window title */
85 SetConsoleTitle(pszOldWindowTitle);
91 msw_get_console_hwnd (void)
93 if (!msw_console_hwnd)
94 msw_console_hwnd = GetConsoleHwnd ();
95 return msw_console_hwnd;
99 msw_ensure_console_allocated (void)
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! */
106 SetForegroundWindow (fgwin);
113 mswindows_canonicalize_console_connection (Lisp_Object connection,
116 /* Do not allow more than one mswindows device, by explicitly
117 requiring that CONNECTION is nil, the only allowed connection in
119 if (!NILP (connection))
121 if (ERRB_EQ (errb, ERROR_ME))
123 ("Invalid (non-nil) connection for mswindows device/console",
133 mswindows_canonicalize_device_connection (Lisp_Object connection,
136 return mswindows_canonicalize_console_connection (connection, errb);
140 msw_hide_console (void)
142 ShowWindow (msw_get_console_hwnd (), SW_HIDE);
146 msw_show_console (void)
148 HWND hwnd = msw_get_console_hwnd ();
149 ShowWindow (hwnd, SW_SHOWNA);
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 |
161 static int msw_console_buffered = 0;
162 HANDLE msw_console_buffer;
165 msw_ensure_console_buffered (void)
167 if (!msw_console_buffered)
173 msw_ensure_console_allocated ();
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;
184 msw_output_console_string (CONST Extbyte *str, Extcount len)
188 msw_ensure_console_buffered ();
190 return WriteConsole (msw_console_buffer, str, len, &num_written, NULL);
193 /* Determine if running on Windows 9x and not NT */
195 msw_windows9x_p (void)
197 return GetVersion () & 0x80000000;
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.
208 struct lrecord_header *
209 DHEADER (Lisp_Object obj)
211 return LRECORDP (obj) ? XRECORD_LHEADER (obj) : NULL;
215 DOPAQUE_DATA (Lisp_Object obj)
217 return OPAQUEP (obj) ? OPAQUE_DATA (XOPAQUE (obj)) : NULL;
221 DEVENT (Lisp_Object obj)
223 return EVENTP (obj) ? XEVENT (obj) : NULL;
227 DCONS (Lisp_Object obj)
229 return CONSP (obj) ? XCONS (obj) : NULL;
233 DCONSCDR (Lisp_Object obj)
235 return (CONSP (obj) && CONSP (XCDR (obj))) ? XCONS (XCDR (obj)) : 0;
239 DSTRING (Lisp_Object obj)
241 return STRINGP (obj) ? XSTRING_DATA (obj) : NULL;
245 DVECTOR (Lisp_Object obj)
247 return VECTORP (obj) ? XVECTOR (obj) : NULL;
251 DSYMBOL (Lisp_Object obj)
253 return SYMBOLP (obj) ? XSYMBOL (obj) : NULL;
257 DSYMNAME (Lisp_Object obj)
259 return SYMBOLP (obj) ? string_data (XSYMBOL (obj)->name) : NULL;
262 #endif /* DEBUG_XEMACS */
266 /************************************************************************/
268 /************************************************************************/
271 syms_of_console_mswindows (void)
276 console_type_create_mswindows (void)
278 INITIALIZE_CONSOLE_TYPE (mswindows, "mswindows", "console-mswindows-p");
280 /* console methods */
281 /* CONSOLE_HAS_METHOD (mswindows, init_console); */
282 /* CONSOLE_HAS_METHOD (mswindows, mark_console); */
283 CONSOLE_HAS_METHOD (mswindows, initially_selected_for_input);
284 /* CONSOLE_HAS_METHOD (mswindows, delete_console); */
285 CONSOLE_HAS_METHOD (mswindows, canonicalize_console_connection);
286 CONSOLE_HAS_METHOD (mswindows, canonicalize_device_connection);
287 /* CONSOLE_HAS_METHOD (mswindows, semi_canonicalize_console_connection); */
288 /* CONSOLE_HAS_METHOD (mswindows, semi_canonicalize_device_connection); */
290 INITIALIZE_CONSOLE_TYPE (msprinter, "msprinter", "console-msprinter-p");
294 reinit_console_type_create_mswindows (void)
296 REINITIALIZE_CONSOLE_TYPE (mswindows);
297 REINITIALIZE_CONSOLE_TYPE (msprinter);
301 vars_of_console_mswindows (void)
303 Fprovide (Qmswindows);