xref: /freebsd/contrib/ncurses/include/nc_win32.h (revision 21817992)
1 /****************************************************************************
2  * Copyright 2018-2020,2023 Thomas E. Dickey                                *
3  * Copyright 2008-2010,2017 Free Software Foundation, Inc.                  *
4  *                                                                          *
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:                 *
12  *                                                                          *
13  * The above copyright notice and this permission notice shall be included  *
14  * in all copies or substantial portions of the Software.                   *
15  *                                                                          *
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.                               *
23  *                                                                          *
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       *
27  * authorization.                                                           *
28  ****************************************************************************/
29 
30 /****************************************************************************
31  * Author: Thomas Dickey, 2008-on                                           *
32  ****************************************************************************/
33 
34 /* $Id: nc_win32.h,v 1.10 2023/02/25 20:09:23 tom Exp $ */
35 
36 #ifndef NC_WIN32_H
37 #define NC_WIN32_H 1
38 
39 #if defined(_WIN32) || defined(_WIN64)
40 
41 #ifndef _NC_WINDOWS
42 #define _NC_WINDOWS
43 #endif
44 
45 #ifdef TERMIOS
46 #error TERMIOS must not be defined on Windows
47 #endif
48 
49 /* We no longer support WindowsXP.
50    Minimum requirement is Windows Vista or Server2008,
51    aka Windows NT 6.0
52 */
53 #ifdef WINVER
54 #  if WINVER < 0x0600
55 #    error WINVER must at least be 0x0600
56 #  endif
57 #else
58 #  define WINVER 0x0600
59 #endif
60 
61 #undef _NC_CHECK_MINTTY
62 #if WINVER >= 0x0600
63 #define _NC_CHECK_MINTTY
64 #endif
65 
66 #include <windows.h>
67 
68 #if HAVE_SYS_TIME_H
69 #include <sys/time.h>		/* for struct timeval */
70 #endif
71 
72 #ifdef _NC_MSC
73 #include <winsock2.h>		/* for struct timeval */
74 #endif
75 
76 #ifdef __cplusplus
77 extern "C" {
78 #endif
79 
80 #include <ncurses_dll.h>
81 
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 *);
86 #endif
87 
88 #undef wcwidth
89 #define wcwidth(ucs)  _nc_wcwidth((wchar_t)(ucs))
90 extern NCURSES_EXPORT(int)    _nc_wcwidth(wchar_t);
91 
92 #ifdef EVENTLIST_2nd /* test.priv.h just needs the preceding */
93 
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);
109 
110 #ifdef _NC_CHECK_MINTTY
111 extern NCURSES_EXPORT(int)    _nc_console_checkmintty(int fd, LPHANDLE pMinTTY);
112 #endif
113 
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) \
118 		      ? term_env \
119 		      : (_nc_console_vt_supported() \
120 		         ? MS_TERMINAL \
121 		         : no_terminal)), \
122 	 NonEmpty(term_env))
123 
124   /*
125    * Various Console mode definitions
126    */
127 
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
131 
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)
135 
136   /* Flags to reset from RAW/CBREAK */
137 #define CONMODE_NORAW    (ENABLE_PROCESSED_INPUT|ENABLE_LINE_INPUT)
138 #define CONMODE_NOCBREAK (ENABLE_LINE_INPUT)
139 
140 
141 #if defined(USE_TERM_DRIVER) && defined(USE_WIN32CON_DRIVER)
142 extern NCURSES_EXPORT_VAR(TERM_DRIVER) _nc_WIN_DRIVER;
143 #endif
144 
145 #define CON_NUMPAIRS 64
146 typedef struct {
147     BOOL initialized;
148     BOOL buffered;
149     BOOL window_only;
150     BOOL progMode;
151     BOOL isMinTTY;
152     BOOL isTermInfoConsole;
153     HANDLE out;
154     HANDLE inp;
155     HANDLE hdl;
156     HANDLE lastOut;
157     int numButtons;
158     LPDWORD ansi_map;
159     LPDWORD map;
160     LPDWORD rmap;
161     WORD pairs[CON_NUMPAIRS];
162     COORD origin;
163     CHAR_INFO *save_screen;
164     COORD save_size;
165     SMALL_RECT save_region;
166     CONSOLE_SCREEN_BUFFER_INFO SBI;
167     CONSOLE_SCREEN_BUFFER_INFO save_SBI;
168     CONSOLE_CURSOR_INFO save_CI;
169     TTY originalMode;
170 } ConsoleInfo;
171 
172 extern NCURSES_EXPORT_VAR(ConsoleInfo) _nc_CONSOLE;
173 #define WINCONSOLE _nc_CONSOLE
174 
175 #define TypeAlloca(type,count)(type*) _alloca(sizeof(type)*(size_t)(count))
176 
177 #endif /* EVENTLIST_2nd */
178 
179 #ifdef __cplusplus
180 }
181 #endif
182 
183 #endif /* _WIN32 || _WIN64 */
184 
185 #endif /* NC_WIN32_H */
186