xref: /freebsd/contrib/ncurses/include/nc_win32.h (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1 /****************************************************************************
2  * Copyright 2018-2019,2020 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.9 2020/09/13 00:17:30 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 #undef HAVE_GETTIMEOFDAY
83 #define HAVE_GETTIMEOFDAY 1
84 extern NCURSES_EXPORT(int) _nc_gettimeofday(struct timeval *, void *);
85 
86 #undef wcwidth
87 #define wcwidth(ucs)  _nc_wcwidth((wchar_t)(ucs))
88 extern NCURSES_EXPORT(int)    _nc_wcwidth(wchar_t);
89 
90 #ifdef EVENTLIST_2nd /* test.priv.h just needs the preceding */
91 
92 extern NCURSES_EXPORT(void)   _nc_console_size(int* Lines, int* Cols);
93 extern NCURSES_EXPORT(HANDLE) _nc_console_handle(int fd);
94 extern NCURSES_EXPORT(int)    _nc_console_isatty(int fd);
95 extern NCURSES_EXPORT(int)    _nc_console_test(int fd);
96 extern NCURSES_EXPORT(int)    _nc_console_read(SCREEN *sp,HANDLE hdl,int *buf);
97 extern NCURSES_EXPORT(int)    _nc_console_twait(SCREEN *, HANDLE,int,int,int * EVENTLIST_2nd(_nc_eventlist * evl));
98 extern NCURSES_EXPORT(WORD)   _nc_console_MapColor(bool fore, int color);
99 extern NCURSES_EXPORT(void)   _nc_console_selectActiveHandle(void);
100 extern NCURSES_EXPORT(bool)   _nc_console_get_SBI(void);
101 extern NCURSES_EXPORT(void)   _nc_console_set_scrollback(bool normal, CONSOLE_SCREEN_BUFFER_INFO * info);
102 extern NCURSES_EXPORT(int)    _nc_console_testmouse(SCREEN *,HANDLE,int EVENTLIST_2nd(_nc_eventlist*));
103 extern NCURSES_EXPORT(int)    _nc_console_keyok(int keycode,int flag);
104 extern NCURSES_EXPORT(bool)   _nc_console_keyExist(int keycode);
105 extern NCURSES_EXPORT(bool)   _nc_console_checkinit(bool initFlag, bool assumeTermInfo);
106 extern NCURSES_EXPORT(int)    _nc_console_vt_supported(void);
107 
108 #ifdef _NC_CHECK_MINTTY
109 extern NCURSES_EXPORT(int)    _nc_console_checkmintty(int fd, LPHANDLE pMinTTY);
110 #endif
111 
112 #undef VALID_TERM_ENV
113 #define MS_TERMINAL "ms-terminal"
114 #define VALID_TERM_ENV(term_env, no_terminal) \
115 	(term_env = (NonEmpty(term_env) \
116 		      ? term_env \
117 		      : (_nc_console_vt_supported() \
118 		         ? MS_TERMINAL \
119 		         : no_terminal)), \
120 	 NonEmpty(term_env))
121 
122   /*
123    * Various Console mode definitions
124    */
125 
126   /* Flags to enable virtual Terminal processing */
127 #define VT_FLAG_OUT ENABLE_VIRTUAL_TERMINAL_PROCESSING
128 #define VT_FLAG_IN  ENABLE_VIRTUAL_TERMINAL_INPUT
129 
130   /* Default flags for input/output modes */
131 #define CONMODE_IN_DEFAULT (ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT)
132 #define CONMODE_OUT_DEFAULT (ENABLE_PROCESSED_OUTPUT | DISABLE_NEWLINE_AUTO_RETURN | ENABLE_LVB_GRID_WORLDWIDE)
133 
134   /* Flags to reset from RAW/CBREAK */
135 #define CONMODE_NORAW    (ENABLE_PROCESSED_INPUT|ENABLE_LINE_INPUT)
136 #define CONMODE_NOCBREAK (ENABLE_LINE_INPUT)
137 
138 
139 #if defined(USE_TERM_DRIVER) && defined(USE_WIN32CON_DRIVER)
140 extern NCURSES_EXPORT_VAR(TERM_DRIVER) _nc_WIN_DRIVER;
141 #endif
142 
143 #define CON_NUMPAIRS 64
144 typedef struct {
145     BOOL initialized;
146     BOOL buffered;
147     BOOL window_only;
148     BOOL progMode;
149     BOOL isMinTTY;
150     BOOL isTermInfoConsole;
151     HANDLE out;
152     HANDLE inp;
153     HANDLE hdl;
154     HANDLE lastOut;
155     int numButtons;
156     LPDWORD ansi_map;
157     LPDWORD map;
158     LPDWORD rmap;
159     WORD pairs[CON_NUMPAIRS];
160     COORD origin;
161     CHAR_INFO *save_screen;
162     COORD save_size;
163     SMALL_RECT save_region;
164     CONSOLE_SCREEN_BUFFER_INFO SBI;
165     CONSOLE_SCREEN_BUFFER_INFO save_SBI;
166     CONSOLE_CURSOR_INFO save_CI;
167     TTY originalMode;
168 } ConsoleInfo;
169 
170 extern NCURSES_EXPORT_VAR(ConsoleInfo) _nc_CONSOLE;
171 #define WINCONSOLE _nc_CONSOLE
172 
173 #define TypeAlloca(type,count)(type*) _alloca(sizeof(type)*(size_t)(count))
174 
175 #endif /* EVENTLIST_2nd */
176 
177 #ifdef __cplusplus
178 }
179 #endif
180 
181 #endif /* _WIN32 || _WIN64 */
182 
183 #endif /* NC_WIN32_H */
184