1 /****************************************************************************
2 * Copyright (c) 2017 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Thomas E. Dickey *
31 ****************************************************************************/
34 * Common type definitions and macros for new_pair.c, lib_color.c
36 * $Id: new_pair.h,v 1.5 2017/04/02 14:46:34 tom Exp $
43 #define USE_NEW_PAIR NCURSES_EXT_COLORS
45 #define LIMIT_TYPED(n,t) (t)(((t)(n) < 0) ? MAX_OF_TYPE(t) : (n))
47 #define limit_COLOR(n) LIMIT_TYPED(n,NCURSES_COLOR_T)
48 #define limit_PAIRS(n) LIMIT_TYPED(n,NCURSES_PAIRS_T)
50 #define MAX_XCURSES_PAIR MAX_OF_TYPE(NCURSES_PAIRS_T)
53 #define OPTIONAL_PAIR GCC_UNUSED
54 #define USE_NEW_PAIR NCURSES_EXT_COLORS
55 #define get_extended_pair(opts, color_pair) \
56 if ((opts) != NULL) { \
57 *(int*)(opts) = color_pair; \
59 #define set_extended_pair(opts, color_pair) \
60 if ((opts) != NULL) { \
61 color_pair = *(const int*)(opts); \
64 #define OPTIONAL_PAIR /* nothing */
65 #define USE_NEW_PAIR NCURSES_EXT_COLORS
66 #define get_extended_pair(opts, color_pair) /* nothing */
67 #define set_extended_pair(opts, color_pair) \
68 if ((opts) != NULL) { \
73 #ifdef NEW_PAIR_INTERNAL
76 cpKEEP = -1, /* color pair 0 */
77 cpFREE = 0, /* free for use */
78 cpINIT = 1, /* init_pair() */
79 cpAUTO = 1 /* alloc_pair() */
82 typedef struct _color_pairs
87 int mode; /* tells if the entry is allocated or free */
88 int prev; /* index of previous item */
89 int next; /* index of next item */
94 #define MakeColorPair(target,f,b) target.fg = f, target.bg = b
95 #define isSamePair(a,b) ((a).fg == (b).fg && (a).bg == (b).bg)
96 #define FORE_OF(c) (c).fg
97 #define BACK_OF(c) (c).bg
100 * Ensure that we use color pairs only when colors have been started, and also
101 * that the index is within the limits of the table which we allocated.
103 #define ValidPair(sp,pair) \
104 ((sp != 0) && (pair >= 0) && (pair < sp->_pair_limit) && sp->_coloron)
107 extern NCURSES_EXPORT(void) _nc_set_color_pair(SCREEN*, int, int);
108 extern NCURSES_EXPORT(void) _nc_reset_color_pair(SCREEN*, int, colorpair_t*);
110 #define _nc_set_color_pair(sp, pair, mode) /* nothing */
111 #define _nc_reset_color_pair(sp, pair, data) /* nothing */
116 typedef struct _color_pairs colorpair_t;
118 #endif /* NEW_PAIR_INTERNAL */
121 extern NCURSES_EXPORT(void) _nc_new_pair_leaks(SCREEN*);
126 #endif /* NEW_PAIR_H */