1 /****************************************************************************
2 * Copyright 2018-2020,2023 Thomas E. Dickey *
3 * Copyright 2008-2010,2017 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************/
30 /****************************************************************************
31 * Author: Thomas Dickey, 2008-on *
32 ****************************************************************************/
34 /* $Id: nc_win32.h,v 1.10 2023/02/25 20:09:23 tom Exp $ */
39 #if defined(_WIN32) || defined(_WIN64)
46 #error TERMIOS must not be defined on Windows
49 /* We no longer support WindowsXP.
50 Minimum requirement is Windows Vista or Server2008,
55 # error WINVER must at least be 0x0600
58 # define WINVER 0x0600
61 #undef _NC_CHECK_MINTTY
63 #define _NC_CHECK_MINTTY
69 #include <sys/time.h> /* for struct timeval */
73 #include <winsock2.h> /* for struct timeval */
80 #include <ncurses_dll.h>
82 #if !HAVE_CLOCK_GETTIME && !HAVE_GETTIMEOFDAY
83 #undef HAVE_GETTIMEOFDAY
84 #define HAVE_GETTIMEOFDAY 2
85 extern NCURSES_EXPORT(int) _nc_gettimeofday(struct timeval *, void *);
89 #define wcwidth(ucs) _nc_wcwidth((wchar_t)(ucs))
90 extern NCURSES_EXPORT(int) _nc_wcwidth(wchar_t);
92 #ifdef EVENTLIST_2nd /* test.priv.h just needs the preceding */
94 extern NCURSES_EXPORT(void) _nc_console_size(int* Lines, int* Cols);
95 extern NCURSES_EXPORT(HANDLE) _nc_console_handle(int fd);
96 extern NCURSES_EXPORT(int) _nc_console_isatty(int fd);
97 extern NCURSES_EXPORT(int) _nc_console_test(int fd);
98 extern NCURSES_EXPORT(int) _nc_console_read(SCREEN *sp,HANDLE hdl,int *buf);
99 extern NCURSES_EXPORT(int) _nc_console_twait(SCREEN *, HANDLE,int,int,int * EVENTLIST_2nd(_nc_eventlist * evl));
100 extern NCURSES_EXPORT(WORD) _nc_console_MapColor(bool fore, int color);
101 extern NCURSES_EXPORT(void) _nc_console_selectActiveHandle(void);
102 extern NCURSES_EXPORT(bool) _nc_console_get_SBI(void);
103 extern NCURSES_EXPORT(void) _nc_console_set_scrollback(bool normal, CONSOLE_SCREEN_BUFFER_INFO * info);
104 extern NCURSES_EXPORT(int) _nc_console_testmouse(SCREEN *,HANDLE,int EVENTLIST_2nd(_nc_eventlist*));
105 extern NCURSES_EXPORT(int) _nc_console_keyok(int keycode,int flag);
106 extern NCURSES_EXPORT(bool) _nc_console_keyExist(int keycode);
107 extern NCURSES_EXPORT(bool) _nc_console_checkinit(bool initFlag, bool assumeTermInfo);
108 extern NCURSES_EXPORT(int) _nc_console_vt_supported(void);
110 #ifdef _NC_CHECK_MINTTY
111 extern NCURSES_EXPORT(int) _nc_console_checkmintty(int fd, LPHANDLE pMinTTY);
114 #undef VALID_TERM_ENV
115 #define MS_TERMINAL "ms-terminal"
116 #define VALID_TERM_ENV(term_env, no_terminal) \
117 (term_env = (NonEmpty(term_env) \
119 : (_nc_console_vt_supported() \
125 * Various Console mode definitions
128 /* Flags to enable virtual Terminal processing */
129 #define VT_FLAG_OUT ENABLE_VIRTUAL_TERMINAL_PROCESSING
130 #define VT_FLAG_IN ENABLE_VIRTUAL_TERMINAL_INPUT
132 /* Default flags for input/output modes */
133 #define CONMODE_IN_DEFAULT (ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT)
134 #define CONMODE_OUT_DEFAULT (ENABLE_PROCESSED_OUTPUT | DISABLE_NEWLINE_AUTO_RETURN | ENABLE_LVB_GRID_WORLDWIDE)
136 /* Flags to reset from RAW/CBREAK */
137 #define CONMODE_NORAW (ENABLE_PROCESSED_INPUT|ENABLE_LINE_INPUT)
138 #define CONMODE_NOCBREAK (ENABLE_LINE_INPUT)
141 #if defined(USE_TERM_DRIVER) && defined(USE_WIN32CON_DRIVER)
142 extern NCURSES_EXPORT_VAR(TERM_DRIVER) _nc_WIN_DRIVER;
145 #define CON_NUMPAIRS 64
152 BOOL isTermInfoConsole;
161 WORD pairs[CON_NUMPAIRS];
163 CHAR_INFO *save_screen;
165 SMALL_RECT save_region;
166 CONSOLE_SCREEN_BUFFER_INFO SBI;
167 CONSOLE_SCREEN_BUFFER_INFO save_SBI;
168 CONSOLE_CURSOR_INFO save_CI;
172 extern NCURSES_EXPORT_VAR(ConsoleInfo) _nc_CONSOLE;
173 #define WINCONSOLE _nc_CONSOLE
175 #define TypeAlloca(type,count)(type*) _alloca(sizeof(type)*(size_t)(count))
177 #endif /* EVENTLIST_2nd */
183 #endif /* _WIN32 || _WIN64 */
185 #endif /* NC_WIN32_H */