blob: b70252d9d7605eb315aacc5a1abf10993a054eac [file] [log] [blame]
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +00001
2#ifndef Py_CURSES_H
3#define Py_CURSES_H
4
Jack Jansen26897bf2002-11-22 16:12:57 +00005#ifdef __APPLE__
6/*
7** On Mac OS X 10.2 [n]curses.h and stdlib.h use different guards
8** against multiple definition of wchar_t.
9*/
Serhiy Storchakabaac01e2017-10-31 13:56:44 +020010#ifdef _BSD_WCHAR_T_DEFINED_
Jack Jansen26897bf2002-11-22 16:12:57 +000011#define _WCHAR_T
12#endif
Mark Dickinson5ea7d642009-09-06 21:24:55 +000013#endif /* __APPLE__ */
Jack Jansend00c13a2003-02-28 12:51:18 +000014
Victor Stinner13ff2452018-01-22 18:32:50 +010015/* On FreeBSD, [n]curses.h and stdlib.h/wchar.h use different guards
16 against multiple definition of wchar_t and wint_t. */
17#if defined(__FreeBSD__) && defined(_XOPEN_SOURCE_EXTENDED)
18# ifndef __wchar_t
19# define __wchar_t
20# endif
21# ifndef __wint_t
22# define __wint_t
23# endif
Andrew MacIntyree3454af2003-06-29 15:46:21 +000024#endif
Andrew MacIntyre1a901172003-06-11 12:26:08 +000025
Masayuki Yamamoto8bc7d632017-11-01 21:05:26 +090026#if !defined(HAVE_CURSES_IS_PAD) && defined(WINDOW_HAS_FLAGS)
27/* The following definition is necessary for ncurses 5.7; without it,
28 some of [n]curses.h set NCURSES_OPAQUE to 1, and then Python
29 can't get at the WINDOW flags field. */
30#define NCURSES_OPAQUE 0
31#endif
32
Jack Jansend00c13a2003-02-28 12:51:18 +000033#ifdef HAVE_NCURSES_H
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000034#include <ncurses.h>
35#else
36#include <curses.h>
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000037#endif
38
Martin v. Löwiseb9b1032001-10-24 17:10:49 +000039#ifdef HAVE_NCURSES_H
40/* configure was checking <curses.h>, but we will
Masayuki Yamamoto8bc7d632017-11-01 21:05:26 +090041 use <ncurses.h>, which has some or all these features. */
42#if !defined(WINDOW_HAS_FLAGS) && !(NCURSES_OPAQUE+0)
Martin v. Löwiseb9b1032001-10-24 17:10:49 +000043#define WINDOW_HAS_FLAGS 1
44#endif
Masayuki Yamamoto8bc7d632017-11-01 21:05:26 +090045#if !defined(HAVE_CURSES_IS_PAD) && NCURSES_VERSION_PATCH+0 >= 20090906
46#define HAVE_CURSES_IS_PAD 1
47#endif
Martin v. Löwiseb9b1032001-10-24 17:10:49 +000048#ifndef MVWDELCH_IS_EXPRESSION
49#define MVWDELCH_IS_EXPRESSION 1
50#endif
51#endif
52
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000053#ifdef __cplusplus
54extern "C" {
55#endif
56
57#define PyCurses_API_pointers 4
58
59/* Type declarations */
60
61typedef struct {
Serhiy Storchakabaac01e2017-10-31 13:56:44 +020062 PyObject_HEAD
63 WINDOW *win;
64 char *encoding;
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000065} PyCursesWindowObject;
66
Andy Lesterdffe4c02020-03-04 07:15:20 -060067#define PyCursesWindow_Check(v) Py_IS_TYPE(v, &PyCursesWindow_Type)
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000068
Benjamin Petersonb173f782009-05-05 22:31:58 +000069#define PyCurses_CAPSULE_NAME "_curses._C_API"
70
71
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000072#ifdef CURSES_MODULE
73/* This section is used when compiling _cursesmodule.c */
74
75#else
76/* This section is used in modules that use the _cursesmodule API */
77
78static void **PyCurses_API;
79
80#define PyCursesWindow_Type (*(PyTypeObject *) PyCurses_API[0])
81#define PyCursesSetupTermCalled {if (! ((int (*)(void))PyCurses_API[1]) () ) return NULL;}
82#define PyCursesInitialised {if (! ((int (*)(void))PyCurses_API[2]) () ) return NULL;}
83#define PyCursesInitialisedColor {if (! ((int (*)(void))PyCurses_API[3]) () ) return NULL;}
84
85#define import_curses() \
Benjamin Petersonb173f782009-05-05 22:31:58 +000086 PyCurses_API = (void **)PyCapsule_Import(PyCurses_CAPSULE_NAME, 1);
87
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000088#endif
89
90/* general error messages */
Serhiy Storchaka2d06e842015-12-25 19:53:18 +020091static const char catchall_ERR[] = "curses function returned ERR";
92static const char catchall_NULL[] = "curses function returned NULL";
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000093
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000094#ifdef __cplusplus
95}
96#endif
97
98#endif /* !defined(Py_CURSES_H) */
99