17a656419SBaptiste Daroussin /**************************************************************************** 2*21817992SBaptiste Daroussin * Copyright 2018-2020,2023 Thomas E. Dickey * 37a656419SBaptiste Daroussin * Copyright 2008-2010,2017 Free Software Foundation, Inc. * 47a656419SBaptiste Daroussin * * 57a656419SBaptiste Daroussin * Permission is hereby granted, free of charge, to any person obtaining a * 67a656419SBaptiste Daroussin * copy of this software and associated documentation files (the * 77a656419SBaptiste Daroussin * "Software"), to deal in the Software without restriction, including * 87a656419SBaptiste Daroussin * without limitation the rights to use, copy, modify, merge, publish, * 97a656419SBaptiste Daroussin * distribute, distribute with modifications, sublicense, and/or sell * 107a656419SBaptiste Daroussin * copies of the Software, and to permit persons to whom the Software is * 117a656419SBaptiste Daroussin * furnished to do so, subject to the following conditions: * 127a656419SBaptiste Daroussin * * 137a656419SBaptiste Daroussin * The above copyright notice and this permission notice shall be included * 147a656419SBaptiste Daroussin * in all copies or substantial portions of the Software. * 157a656419SBaptiste Daroussin * * 167a656419SBaptiste Daroussin * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 177a656419SBaptiste Daroussin * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 187a656419SBaptiste Daroussin * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 197a656419SBaptiste Daroussin * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 207a656419SBaptiste Daroussin * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 217a656419SBaptiste Daroussin * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 227a656419SBaptiste Daroussin * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 237a656419SBaptiste Daroussin * * 247a656419SBaptiste Daroussin * Except as contained in this notice, the name(s) of the above copyright * 257a656419SBaptiste Daroussin * holders shall not be used in advertising or otherwise to promote the * 267a656419SBaptiste Daroussin * sale, use or other dealings in this Software without prior written * 277a656419SBaptiste Daroussin * authorization. * 287a656419SBaptiste Daroussin ****************************************************************************/ 297a656419SBaptiste Daroussin 307a656419SBaptiste Daroussin /**************************************************************************** 317a656419SBaptiste Daroussin * Author: Thomas Dickey, 2008-on * 327a656419SBaptiste Daroussin ****************************************************************************/ 337a656419SBaptiste Daroussin 34*21817992SBaptiste Daroussin /* $Id: nc_win32.h,v 1.10 2023/02/25 20:09:23 tom Exp $ */ 357a656419SBaptiste Daroussin 367a656419SBaptiste Daroussin #ifndef NC_WIN32_H 377a656419SBaptiste Daroussin #define NC_WIN32_H 1 387a656419SBaptiste Daroussin 397a656419SBaptiste Daroussin #if defined(_WIN32) || defined(_WIN64) 407a656419SBaptiste Daroussin 417a656419SBaptiste Daroussin #ifndef _NC_WINDOWS 427a656419SBaptiste Daroussin #define _NC_WINDOWS 437a656419SBaptiste Daroussin #endif 447a656419SBaptiste Daroussin 457a656419SBaptiste Daroussin #ifdef TERMIOS 467a656419SBaptiste Daroussin #error TERMIOS must not be defined on Windows 477a656419SBaptiste Daroussin #endif 487a656419SBaptiste Daroussin 497a656419SBaptiste Daroussin /* We no longer support WindowsXP. 507a656419SBaptiste Daroussin Minimum requirement is Windows Vista or Server2008, 517a656419SBaptiste Daroussin aka Windows NT 6.0 527a656419SBaptiste Daroussin */ 537a656419SBaptiste Daroussin #ifdef WINVER 547a656419SBaptiste Daroussin # if WINVER < 0x0600 557a656419SBaptiste Daroussin # error WINVER must at least be 0x0600 567a656419SBaptiste Daroussin # endif 577a656419SBaptiste Daroussin #else 587a656419SBaptiste Daroussin # define WINVER 0x0600 597a656419SBaptiste Daroussin #endif 607a656419SBaptiste Daroussin 617a656419SBaptiste Daroussin #undef _NC_CHECK_MINTTY 627a656419SBaptiste Daroussin #if WINVER >= 0x0600 637a656419SBaptiste Daroussin #define _NC_CHECK_MINTTY 647a656419SBaptiste Daroussin #endif 657a656419SBaptiste Daroussin 667a656419SBaptiste Daroussin #include <windows.h> 677a656419SBaptiste Daroussin 687a656419SBaptiste Daroussin #if HAVE_SYS_TIME_H 697a656419SBaptiste Daroussin #include <sys/time.h> /* for struct timeval */ 707a656419SBaptiste Daroussin #endif 717a656419SBaptiste Daroussin 727a656419SBaptiste Daroussin #ifdef _NC_MSC 737a656419SBaptiste Daroussin #include <winsock2.h> /* for struct timeval */ 747a656419SBaptiste Daroussin #endif 757a656419SBaptiste Daroussin 767a656419SBaptiste Daroussin #ifdef __cplusplus 777a656419SBaptiste Daroussin extern "C" { 787a656419SBaptiste Daroussin #endif 797a656419SBaptiste Daroussin 807a656419SBaptiste Daroussin #include <ncurses_dll.h> 817a656419SBaptiste Daroussin 82*21817992SBaptiste Daroussin #if !HAVE_CLOCK_GETTIME && !HAVE_GETTIMEOFDAY 837a656419SBaptiste Daroussin #undef HAVE_GETTIMEOFDAY 84*21817992SBaptiste Daroussin #define HAVE_GETTIMEOFDAY 2 857a656419SBaptiste Daroussin extern NCURSES_EXPORT(int) _nc_gettimeofday(struct timeval *, void *); 86*21817992SBaptiste Daroussin #endif 877a656419SBaptiste Daroussin 887a656419SBaptiste Daroussin #undef wcwidth 897a656419SBaptiste Daroussin #define wcwidth(ucs) _nc_wcwidth((wchar_t)(ucs)) 907a656419SBaptiste Daroussin extern NCURSES_EXPORT(int) _nc_wcwidth(wchar_t); 917a656419SBaptiste Daroussin 927a656419SBaptiste Daroussin #ifdef EVENTLIST_2nd /* test.priv.h just needs the preceding */ 937a656419SBaptiste Daroussin 947a656419SBaptiste Daroussin extern NCURSES_EXPORT(void) _nc_console_size(int* Lines, int* Cols); 957a656419SBaptiste Daroussin extern NCURSES_EXPORT(HANDLE) _nc_console_handle(int fd); 967a656419SBaptiste Daroussin extern NCURSES_EXPORT(int) _nc_console_isatty(int fd); 977a656419SBaptiste Daroussin extern NCURSES_EXPORT(int) _nc_console_test(int fd); 987a656419SBaptiste Daroussin extern NCURSES_EXPORT(int) _nc_console_read(SCREEN *sp,HANDLE hdl,int *buf); 997a656419SBaptiste Daroussin extern NCURSES_EXPORT(int) _nc_console_twait(SCREEN *, HANDLE,int,int,int * EVENTLIST_2nd(_nc_eventlist * evl)); 1007a656419SBaptiste Daroussin extern NCURSES_EXPORT(WORD) _nc_console_MapColor(bool fore, int color); 1017a656419SBaptiste Daroussin extern NCURSES_EXPORT(void) _nc_console_selectActiveHandle(void); 1027a656419SBaptiste Daroussin extern NCURSES_EXPORT(bool) _nc_console_get_SBI(void); 1037a656419SBaptiste Daroussin extern NCURSES_EXPORT(void) _nc_console_set_scrollback(bool normal, CONSOLE_SCREEN_BUFFER_INFO * info); 1047a656419SBaptiste Daroussin extern NCURSES_EXPORT(int) _nc_console_testmouse(SCREEN *,HANDLE,int EVENTLIST_2nd(_nc_eventlist*)); 1057a656419SBaptiste Daroussin extern NCURSES_EXPORT(int) _nc_console_keyok(int keycode,int flag); 1067a656419SBaptiste Daroussin extern NCURSES_EXPORT(bool) _nc_console_keyExist(int keycode); 1077a656419SBaptiste Daroussin extern NCURSES_EXPORT(bool) _nc_console_checkinit(bool initFlag, bool assumeTermInfo); 1087a656419SBaptiste Daroussin extern NCURSES_EXPORT(int) _nc_console_vt_supported(void); 1097a656419SBaptiste Daroussin 1107a656419SBaptiste Daroussin #ifdef _NC_CHECK_MINTTY 1117a656419SBaptiste Daroussin extern NCURSES_EXPORT(int) _nc_console_checkmintty(int fd, LPHANDLE pMinTTY); 1127a656419SBaptiste Daroussin #endif 1137a656419SBaptiste Daroussin 1147a656419SBaptiste Daroussin #undef VALID_TERM_ENV 1157a656419SBaptiste Daroussin #define MS_TERMINAL "ms-terminal" 1167a656419SBaptiste Daroussin #define VALID_TERM_ENV(term_env, no_terminal) \ 1177a656419SBaptiste Daroussin (term_env = (NonEmpty(term_env) \ 1187a656419SBaptiste Daroussin ? term_env \ 1197a656419SBaptiste Daroussin : (_nc_console_vt_supported() \ 1207a656419SBaptiste Daroussin ? MS_TERMINAL \ 1217a656419SBaptiste Daroussin : no_terminal)), \ 1227a656419SBaptiste Daroussin NonEmpty(term_env)) 1237a656419SBaptiste Daroussin 1247a656419SBaptiste Daroussin /* 1257a656419SBaptiste Daroussin * Various Console mode definitions 1267a656419SBaptiste Daroussin */ 1277a656419SBaptiste Daroussin 1287a656419SBaptiste Daroussin /* Flags to enable virtual Terminal processing */ 1297a656419SBaptiste Daroussin #define VT_FLAG_OUT ENABLE_VIRTUAL_TERMINAL_PROCESSING 1307a656419SBaptiste Daroussin #define VT_FLAG_IN ENABLE_VIRTUAL_TERMINAL_INPUT 1317a656419SBaptiste Daroussin 1327a656419SBaptiste Daroussin /* Default flags for input/output modes */ 1337a656419SBaptiste Daroussin #define CONMODE_IN_DEFAULT (ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT) 1347a656419SBaptiste Daroussin #define CONMODE_OUT_DEFAULT (ENABLE_PROCESSED_OUTPUT | DISABLE_NEWLINE_AUTO_RETURN | ENABLE_LVB_GRID_WORLDWIDE) 1357a656419SBaptiste Daroussin 1367a656419SBaptiste Daroussin /* Flags to reset from RAW/CBREAK */ 1377a656419SBaptiste Daroussin #define CONMODE_NORAW (ENABLE_PROCESSED_INPUT|ENABLE_LINE_INPUT) 1387a656419SBaptiste Daroussin #define CONMODE_NOCBREAK (ENABLE_LINE_INPUT) 1397a656419SBaptiste Daroussin 1407a656419SBaptiste Daroussin 1417a656419SBaptiste Daroussin #if defined(USE_TERM_DRIVER) && defined(USE_WIN32CON_DRIVER) 1427a656419SBaptiste Daroussin extern NCURSES_EXPORT_VAR(TERM_DRIVER) _nc_WIN_DRIVER; 1437a656419SBaptiste Daroussin #endif 1447a656419SBaptiste Daroussin 1457a656419SBaptiste Daroussin #define CON_NUMPAIRS 64 1467a656419SBaptiste Daroussin typedef struct { 1477a656419SBaptiste Daroussin BOOL initialized; 1487a656419SBaptiste Daroussin BOOL buffered; 1497a656419SBaptiste Daroussin BOOL window_only; 1507a656419SBaptiste Daroussin BOOL progMode; 1517a656419SBaptiste Daroussin BOOL isMinTTY; 1527a656419SBaptiste Daroussin BOOL isTermInfoConsole; 1537a656419SBaptiste Daroussin HANDLE out; 1547a656419SBaptiste Daroussin HANDLE inp; 1557a656419SBaptiste Daroussin HANDLE hdl; 1567a656419SBaptiste Daroussin HANDLE lastOut; 1577a656419SBaptiste Daroussin int numButtons; 1587a656419SBaptiste Daroussin LPDWORD ansi_map; 1597a656419SBaptiste Daroussin LPDWORD map; 1607a656419SBaptiste Daroussin LPDWORD rmap; 1617a656419SBaptiste Daroussin WORD pairs[CON_NUMPAIRS]; 1627a656419SBaptiste Daroussin COORD origin; 1637a656419SBaptiste Daroussin CHAR_INFO *save_screen; 1647a656419SBaptiste Daroussin COORD save_size; 1657a656419SBaptiste Daroussin SMALL_RECT save_region; 1667a656419SBaptiste Daroussin CONSOLE_SCREEN_BUFFER_INFO SBI; 1677a656419SBaptiste Daroussin CONSOLE_SCREEN_BUFFER_INFO save_SBI; 1687a656419SBaptiste Daroussin CONSOLE_CURSOR_INFO save_CI; 1697a656419SBaptiste Daroussin TTY originalMode; 1707a656419SBaptiste Daroussin } ConsoleInfo; 1717a656419SBaptiste Daroussin 1727a656419SBaptiste Daroussin extern NCURSES_EXPORT_VAR(ConsoleInfo) _nc_CONSOLE; 1737a656419SBaptiste Daroussin #define WINCONSOLE _nc_CONSOLE 1747a656419SBaptiste Daroussin 1757a656419SBaptiste Daroussin #define TypeAlloca(type,count)(type*) _alloca(sizeof(type)*(size_t)(count)) 1767a656419SBaptiste Daroussin 1777a656419SBaptiste Daroussin #endif /* EVENTLIST_2nd */ 1787a656419SBaptiste Daroussin 1797a656419SBaptiste Daroussin #ifdef __cplusplus 1807a656419SBaptiste Daroussin } 1817a656419SBaptiste Daroussin #endif 1827a656419SBaptiste Daroussin 1837a656419SBaptiste Daroussin #endif /* _WIN32 || _WIN64 */ 1847a656419SBaptiste Daroussin 1857a656419SBaptiste Daroussin #endif /* NC_WIN32_H */ 186