xref: /freebsd/contrib/ncurses/include/nc_win32.h.in (revision 68ad2b0d7af2a3571c4abac9afa712f9b09b721c)
1/****************************************************************************
2 * Copyright 2018-2024,2025 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.in,v 1.19 2025/12/26 23:32:43 tom Exp $ */
35
36#ifndef NC_WIN32_H
37#define NC_WIN32_H 1
38
39#include <ncurses_cfg.h>
40
41#if defined(_WIN32) || defined(_WIN64) || defined(USE_WIN32CON_DRIVER)
42
43#if @USE_NAMED_PIPES@	/* USE_NAMED_PIPES */
44
45#ifndef _NC_WINDOWS_NATIVE
46#define _NC_WINDOWS_NATIVE
47#endif
48
49#ifdef TERMIOS
50#error TERMIOS must not be defined on Windows
51#endif
52
53/*
54   Minimum requirement for named pipes is Windows Vista or Server2008,
55   aka Windows NT 6.0
56*/
57#ifdef WINVER
58#  if WINVER < 0x0600
59#    error WINVER must at least be 0x0600
60#  endif
61#else
62#  define WINVER 0x0600
63#endif
64
65#undef _NC_CHECK_MINTTY
66#if WINVER >= 0x0600
67#define _NC_CHECK_MINTTY
68#endif
69
70#include <windows.h>
71
72#else /* !USE_NAMED_PIPES */
73
74#ifdef WINVER
75#  if WINVER < 0x0501
76#    error WINVER must at least be 0x0501
77#  endif
78#else
79#  define WINVER 0x0501
80#endif
81
82#include <windows.h>
83
84#undef sleep
85#define sleep(n) Sleep((n) * 1000)
86
87#endif /* USE_NAMED_PIPES */
88
89#if HAVE_SYS_TIME_H
90#include <sys/time.h>		/* for struct timeval */
91#endif
92
93#ifdef _MSC_VER
94#include <winsock2.h>		/* for struct timeval */
95#endif
96
97#include <stdint.h>		/* for uint32_t */
98
99/*
100 * Allow for build-override, e.g., MinGW used "cygwin".
101 */
102#ifndef DEFAULT_TERM_ENV
103#define DEFAULT_TERM_ENV "ms-terminal"
104#endif
105
106#undef VALID_TERM_ENV
107#define VALID_TERM_ENV(term_env, no_terminal) \
108	(term_env = (NonEmpty(term_env) \
109		      ? term_env \
110		      : (_nc_console_vt_supported() \
111		         ? DEFAULT_TERM_ENV \
112		         : no_terminal)), \
113	 NonEmpty(term_env))
114
115  /*
116   * Various Console mode definitions
117   */
118
119  /* Flags to enable virtual Terminal processing */
120#define VT_FLAG_OUT ENABLE_VIRTUAL_TERMINAL_PROCESSING
121#define VT_FLAG_IN  ENABLE_VIRTUAL_TERMINAL_INPUT
122
123  /* Default flags for input/output modes */
124#define CONMODE_IN_DEFAULT (ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT)
125#define CONMODE_OUT_DEFAULT (ENABLE_PROCESSED_OUTPUT | DISABLE_NEWLINE_AUTO_RETURN | ENABLE_LVB_GRID_WORLDWIDE)
126
127  /* Flags to reset from RAW/CBREAK */
128#define CONMODE_NORAW    (ENABLE_PROCESSED_INPUT|ENABLE_LINE_INPUT)
129#define CONMODE_NOCBREAK (ENABLE_LINE_INPUT)
130
131#include <ncurses_dll.h>
132
133#ifdef __cplusplus
134extern "C" {
135#endif
136
137#if defined(CURSES_PRIV_H) || defined(TEST_PRIV_H)
138
139#if !HAVE_CLOCK_GETTIME && !HAVE_GETTIMEOFDAY
140extern NCURSES_EXPORT(int) _nc_gettimeofday(struct timeval *, void *);
141#undef HAVE_GETTIMEOFDAY
142#define HAVE_GETTIMEOFDAY 2
143#define gettimeofday(tv,tz) _nc_gettimeofday(tv,tz)
144#endif
145
146#endif /* defined(CURSES_PRIV_H) || defined(TEST_PRIV_H) */
147
148#if !HAVE_WCWIDTH
149#undef wcwidth
150#define wcwidth(ucs) _nc_wcwidth((wchar_t)(ucs))
151extern NCURSES_EXPORT(int) _nc_wcwidth(uint32_t);
152#endif
153
154typedef struct
155{
156    DWORD dwFlagIn;
157    DWORD dwFlagOut;
158} ConsoleMode;
159
160#define CON_NUMPAIRS 64
161typedef struct {
162    BOOL initialized;
163    BOOL buffered;
164    BOOL window_only;
165    BOOL progMode;
166    BOOL isMinTTY;
167    BOOL isTermInfoConsole;
168    HANDLE out;
169    HANDLE inp;
170    HANDLE hdl;
171    HANDLE lastOut;
172    int numButtons;
173    LPDWORD ansi_map;
174    LPDWORD map;
175    LPDWORD rmap;
176    WORD pairs[CON_NUMPAIRS];
177    COORD origin;
178    CHAR_INFO *save_screen;
179    COORD save_size;
180    SMALL_RECT save_region;
181    CONSOLE_SCREEN_BUFFER_INFO SBI;
182    CONSOLE_SCREEN_BUFFER_INFO save_SBI;
183    CONSOLE_CURSOR_INFO save_CI;
184    ConsoleMode originalMode;
185} ConsoleInfo;
186
187extern NCURSES_EXPORT_VAR(ConsoleInfo) _nc_CONSOLE;
188#define WINCONSOLE _nc_CONSOLE
189
190#ifdef __cplusplus
191}
192#endif
193
194#ifdef CURSES_PRIV_H	/* test.priv.h just needs the preceding */
195#include <term.h>
196#endif
197
198#if USE_DOS_PATHS
199NCURSES_EXPORT(const char *) _nc_to_dospath(const char *, char *);
200#define FixupPathname(path) \
201	char fixed_pathname[PATH_MAX]; \
202	path = _nc_to_dospath(path, fixed_pathname)
203#define FixupPathname2(path,buffer) \
204	path = _nc_to_dospath(path, buffer)
205#endif
206
207#undef  ttyname
208#define ttyname(fd) NULL
209
210#endif /* _WIN32 || _WIN64 */
211
212#endif /* NC_WIN32_H */
213