wined3d: Pass a wined3d_device_context to wined3d_cs_emit_set_index_buffer().
[wine.git] / dlls / kernel32 / console.c
blob8c61d28e8c6a13b13589b4758b99e1e425a6082e
1 /*
2 * Win32 console functions
4 * Copyright 1995 Martin von Loewis and Cameron Heide
5 * Copyright 1997 Karl Garrison
6 * Copyright 1998 John Richardson
7 * Copyright 1998 Marcus Meissner
8 * Copyright 2001,2002,2004,2005,2010 Eric Pouech
9 * Copyright 2001 Alexandre Julliard
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include <stdarg.h>
27 #include <stdio.h>
28 #include <string.h>
29 #include <limits.h>
31 #define NONAMELESSUNION
32 #include "ntstatus.h"
33 #define WIN32_NO_STATUS
34 #include "windef.h"
35 #include "winbase.h"
36 #include "winternl.h"
37 #include "winnls.h"
38 #include "winerror.h"
39 #include "wincon.h"
40 #include "wine/condrv.h"
41 #include "wine/exception.h"
42 #include "wine/debug.h"
43 #include "excpt.h"
44 #include "kernel_private.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(console);
48 /******************************************************************************
49 * GetConsoleWindow [KERNEL32.@] Get hwnd of the console window.
51 * RETURNS
52 * Success: hwnd of the console window.
53 * Failure: NULL
55 HWND WINAPI GetConsoleWindow(void)
57 struct condrv_input_info info;
58 BOOL ret;
60 ret = DeviceIoControl( RtlGetCurrentPeb()->ProcessParameters->ConsoleHandle,
61 IOCTL_CONDRV_GET_INPUT_INFO, NULL, 0, &info, sizeof(info), NULL, NULL );
62 return ret ? LongToHandle( info.win ) : NULL;
66 /******************************************************************
67 * OpenConsoleW (KERNEL32.@)
69 * Undocumented
70 * Open a handle to the current process console.
71 * Returns INVALID_HANDLE_VALUE on failure.
73 HANDLE WINAPI OpenConsoleW(LPCWSTR name, DWORD access, BOOL inherit, DWORD creation)
75 SECURITY_ATTRIBUTES sa;
77 TRACE("(%s, 0x%08x, %d, %u)\n", debugstr_w(name), access, inherit, creation);
79 if (!name || (wcsicmp( L"CONIN$", name ) && wcsicmp( L"CONOUT$", name )) || creation != OPEN_EXISTING)
81 SetLastError( ERROR_INVALID_PARAMETER );
82 return INVALID_HANDLE_VALUE;
85 sa.nLength = sizeof(sa);
86 sa.lpSecurityDescriptor = NULL;
87 sa.bInheritHandle = inherit;
89 return CreateFileW( name, access, FILE_SHARE_READ | FILE_SHARE_WRITE, &sa, creation, 0, NULL );
92 /******************************************************************
93 * VerifyConsoleIoHandle (KERNEL32.@)
95 * Undocumented
97 BOOL WINAPI VerifyConsoleIoHandle(HANDLE handle)
99 IO_STATUS_BLOCK io;
100 DWORD mode;
101 return !NtDeviceIoControlFile( handle, NULL, NULL, NULL, &io, IOCTL_CONDRV_GET_MODE,
102 NULL, 0, &mode, sizeof(mode) );
105 /******************************************************************
106 * DuplicateConsoleHandle (KERNEL32.@)
108 * Undocumented
110 HANDLE WINAPI DuplicateConsoleHandle(HANDLE handle, DWORD access, BOOL inherit,
111 DWORD options)
113 HANDLE ret;
114 return DuplicateHandle(GetCurrentProcess(), handle, GetCurrentProcess(), &ret,
115 access, inherit, options) ? ret : INVALID_HANDLE_VALUE;
118 /******************************************************************
119 * CloseConsoleHandle (KERNEL32.@)
121 * Undocumented
123 BOOL WINAPI CloseConsoleHandle(HANDLE handle)
125 return CloseHandle(handle);
128 /******************************************************************
129 * GetConsoleInputWaitHandle (KERNEL32.@)
131 * Undocumented
133 HANDLE WINAPI GetConsoleInputWaitHandle(void)
135 return GetStdHandle( STD_INPUT_HANDLE );
139 /***********************************************************************
140 * SetConsoleTitleA (KERNEL32.@)
142 BOOL WINAPI SetConsoleTitleA( LPCSTR title )
144 LPWSTR titleW;
145 BOOL ret;
147 DWORD len = MultiByteToWideChar( GetConsoleOutputCP(), 0, title, -1, NULL, 0 );
148 if (!(titleW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)))) return FALSE;
149 MultiByteToWideChar( GetConsoleOutputCP(), 0, title, -1, titleW, len );
150 ret = SetConsoleTitleW(titleW);
151 HeapFree(GetProcessHeap(), 0, titleW);
152 return ret;
156 /***********************************************************************
157 * GetConsoleKeyboardLayoutNameA (KERNEL32.@)
159 BOOL WINAPI GetConsoleKeyboardLayoutNameA(LPSTR layoutName)
161 FIXME( "stub %p\n", layoutName);
162 return TRUE;
165 /***********************************************************************
166 * GetConsoleKeyboardLayoutNameW (KERNEL32.@)
168 BOOL WINAPI GetConsoleKeyboardLayoutNameW(LPWSTR layoutName)
170 static int once;
171 if (!once++)
172 FIXME( "stub %p\n", layoutName);
173 return TRUE;
176 /***********************************************************************
177 * GetConsoleTitleA (KERNEL32.@)
179 * See GetConsoleTitleW.
181 DWORD WINAPI GetConsoleTitleA(LPSTR title, DWORD size)
183 WCHAR *ptr = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * size);
184 DWORD ret;
186 if (!ptr) return 0;
187 ret = GetConsoleTitleW( ptr, size );
188 if (ret)
190 WideCharToMultiByte( GetConsoleOutputCP(), 0, ptr, ret + 1, title, size, NULL, NULL);
191 ret = strlen(title);
193 HeapFree(GetProcessHeap(), 0, ptr);
194 return ret;
198 /***********************************************************************
199 * GetNumberOfConsoleMouseButtons (KERNEL32.@)
201 BOOL WINAPI GetNumberOfConsoleMouseButtons(LPDWORD nrofbuttons)
203 FIXME("(%p): stub\n", nrofbuttons);
204 *nrofbuttons = 2;
205 return TRUE;
209 /******************************************************************
210 * GetConsoleDisplayMode (KERNEL32.@)
212 BOOL WINAPI GetConsoleDisplayMode(LPDWORD lpModeFlags)
214 TRACE("semi-stub: %p\n", lpModeFlags);
215 /* It is safe to successfully report windowed mode */
216 *lpModeFlags = 0;
217 return TRUE;
220 /******************************************************************
221 * SetConsoleDisplayMode (KERNEL32.@)
223 BOOL WINAPI SetConsoleDisplayMode(HANDLE hConsoleOutput, DWORD dwFlags,
224 COORD *lpNewScreenBufferDimensions)
226 TRACE("(%p, %x, (%d, %d))\n", hConsoleOutput, dwFlags,
227 lpNewScreenBufferDimensions->X, lpNewScreenBufferDimensions->Y);
228 if (dwFlags == 1)
230 /* We cannot switch to fullscreen */
231 return FALSE;
233 return TRUE;
236 /******************************************************************
237 * GetConsoleAliasW
240 * RETURNS
241 * 0 if an error occurred, non-zero for success
244 DWORD WINAPI GetConsoleAliasW(LPWSTR lpSource, LPWSTR lpTargetBuffer,
245 DWORD TargetBufferLength, LPWSTR lpExename)
247 FIXME("(%s,%p,%d,%s): stub\n", debugstr_w(lpSource), lpTargetBuffer, TargetBufferLength, debugstr_w(lpExename));
248 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
249 return 0;
252 /******************************************************************
253 * GetConsoleProcessList (KERNEL32.@)
255 DWORD WINAPI GetConsoleProcessList(LPDWORD processlist, DWORD processcount)
257 FIXME("(%p,%d): stub\n", processlist, processcount);
259 if (!processlist || processcount < 1)
261 SetLastError(ERROR_INVALID_PARAMETER);
262 return 0;
265 return 0;
268 /* Undocumented, called by native doskey.exe */
269 DWORD WINAPI GetConsoleCommandHistoryA(DWORD unknown1, DWORD unknown2, DWORD unknown3)
271 FIXME(": (0x%x, 0x%x, 0x%x) stub!\n", unknown1, unknown2, unknown3);
272 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
273 return 0;
276 /* Undocumented, called by native doskey.exe */
277 DWORD WINAPI GetConsoleCommandHistoryW(DWORD unknown1, DWORD unknown2, DWORD unknown3)
279 FIXME(": (0x%x, 0x%x, 0x%x) stub!\n", unknown1, unknown2, unknown3);
280 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
281 return 0;
284 /* Undocumented, called by native doskey.exe */
285 DWORD WINAPI GetConsoleCommandHistoryLengthA(LPCSTR unknown)
287 FIXME(": (%s) stub!\n", debugstr_a(unknown));
288 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
289 return 0;
292 /* Undocumented, called by native doskey.exe */
293 DWORD WINAPI GetConsoleCommandHistoryLengthW(LPCWSTR unknown)
295 FIXME(": (%s) stub!\n", debugstr_w(unknown));
296 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
297 return 0;
300 DWORD WINAPI GetConsoleAliasesLengthA(LPSTR unknown)
302 FIXME(": (%s) stub!\n", debugstr_a(unknown));
303 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
304 return 0;
307 DWORD WINAPI GetConsoleAliasesLengthW(LPWSTR unknown)
309 FIXME(": (%s) stub!\n", debugstr_w(unknown));
310 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
311 return 0;
314 DWORD WINAPI GetConsoleAliasExesLengthA(void)
316 FIXME(": stub!\n");
317 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
318 return 0;
321 DWORD WINAPI GetConsoleAliasExesLengthW(void)
323 FIXME(": stub!\n");
324 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
325 return 0;
328 VOID WINAPI ExpungeConsoleCommandHistoryA(LPCSTR unknown)
330 FIXME(": (%s) stub!\n", debugstr_a(unknown));
331 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
334 VOID WINAPI ExpungeConsoleCommandHistoryW(LPCWSTR unknown)
336 FIXME(": (%s) stub!\n", debugstr_w(unknown));
337 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
340 BOOL WINAPI AddConsoleAliasA(LPSTR source, LPSTR target, LPSTR exename)
342 FIXME(": (%s, %s, %s) stub!\n", debugstr_a(source), debugstr_a(target), debugstr_a(exename));
343 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
344 return FALSE;
347 BOOL WINAPI AddConsoleAliasW(LPWSTR source, LPWSTR target, LPWSTR exename)
349 FIXME(": (%s, %s, %s) stub!\n", debugstr_w(source), debugstr_w(target), debugstr_w(exename));
350 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
351 return FALSE;
355 BOOL WINAPI SetConsoleIcon(HICON icon)
357 FIXME(": (%p) stub!\n", icon);
358 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
359 return FALSE;
362 DWORD WINAPI GetNumberOfConsoleFonts(void)
364 return 1;
367 BOOL WINAPI SetConsoleFont(HANDLE hConsole, DWORD index)
369 FIXME("(%p, %u): stub!\n", hConsole, index);
370 SetLastError(LOWORD(E_NOTIMPL) /* win10 1709+ */);
371 return FALSE;
374 BOOL WINAPI SetConsoleKeyShortcuts(BOOL set, BYTE keys, VOID *a, DWORD b)
376 FIXME(": (%u %u %p %u) stub!\n", set, keys, a, b);
377 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
378 return FALSE;
382 BOOL WINAPI GetCurrentConsoleFontEx(HANDLE hConsole, BOOL maxwindow, CONSOLE_FONT_INFOEX *fontinfo)
384 DWORD size;
385 struct
387 struct condrv_output_info info;
388 WCHAR face_name[LF_FACESIZE - 1];
389 } data;
391 if (fontinfo->cbSize != sizeof(CONSOLE_FONT_INFOEX))
393 SetLastError(ERROR_INVALID_PARAMETER);
394 return FALSE;
397 if (!DeviceIoControl( hConsole, IOCTL_CONDRV_GET_OUTPUT_INFO, NULL, 0,
398 &data, sizeof(data), &size, NULL ))
400 SetLastError( ERROR_INVALID_HANDLE );
401 return FALSE;
404 fontinfo->nFont = 0;
405 if (maxwindow)
407 fontinfo->dwFontSize.X = min( data.info.width, data.info.max_width );
408 fontinfo->dwFontSize.Y = min( data.info.height, data.info.max_height );
410 else
412 fontinfo->dwFontSize.X = data.info.win_right - data.info.win_left + 1;
413 fontinfo->dwFontSize.Y = data.info.win_bottom - data.info.win_top + 1;
415 size -= sizeof(data.info);
416 if (size) memcpy( fontinfo->FaceName, data.face_name, size );
417 fontinfo->FaceName[size / sizeof(WCHAR)] = 0;
418 fontinfo->FontFamily = data.info.font_pitch_family;
419 fontinfo->FontWeight = data.info.font_weight;
420 return TRUE;
423 BOOL WINAPI GetCurrentConsoleFont(HANDLE hConsole, BOOL maxwindow, CONSOLE_FONT_INFO *fontinfo)
425 BOOL ret;
426 CONSOLE_FONT_INFOEX res;
428 res.cbSize = sizeof(CONSOLE_FONT_INFOEX);
430 ret = GetCurrentConsoleFontEx(hConsole, maxwindow, &res);
431 if(ret)
433 fontinfo->nFont = res.nFont;
434 fontinfo->dwFontSize.X = res.dwFontSize.X;
435 fontinfo->dwFontSize.Y = res.dwFontSize.Y;
437 return ret;
440 static COORD get_console_font_size(HANDLE hConsole, DWORD index)
442 struct condrv_output_info info;
443 COORD c = {0,0};
445 if (index >= GetNumberOfConsoleFonts())
447 SetLastError(ERROR_INVALID_PARAMETER);
448 return c;
451 if (DeviceIoControl( hConsole, IOCTL_CONDRV_GET_OUTPUT_INFO, NULL, 0, &info, sizeof(info), NULL, NULL ))
453 c.X = info.font_width;
454 c.Y = info.font_height;
456 else SetLastError( ERROR_INVALID_HANDLE );
457 return c;
460 #if defined(__i386__) && !defined(__MINGW32__) && !defined(_MSC_VER)
461 #undef GetConsoleFontSize
462 DWORD WINAPI GetConsoleFontSize(HANDLE hConsole, DWORD index)
464 union {
465 COORD c;
466 DWORD w;
467 } x;
469 x.c = get_console_font_size(hConsole, index);
470 return x.w;
472 #else
473 COORD WINAPI GetConsoleFontSize(HANDLE hConsole, DWORD index)
475 return get_console_font_size(hConsole, index);
477 #endif /* !defined(__i386__) */
479 BOOL WINAPI GetConsoleFontInfo(HANDLE hConsole, BOOL maximize, DWORD numfonts, CONSOLE_FONT_INFO *info)
481 FIXME("(%p %d %u %p): stub!\n", hConsole, maximize, numfonts, info);
482 SetLastError(LOWORD(E_NOTIMPL) /* win10 1709+ */);
483 return FALSE;
486 BOOL WINAPI SetCurrentConsoleFontEx(HANDLE hConsole, BOOL maxwindow, CONSOLE_FONT_INFOEX *cfix)
488 FIXME("(%p %d %p): stub!\n", hConsole, maxwindow, cfix);
489 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
490 return FALSE;