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