]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/new_pair.h
ncurses 6.0 - patch 20170610
[ncurses.git] / ncurses / new_pair.h
1 /****************************************************************************
2  * Copyright (c) 2017 Free Software Foundation, Inc.                        *
3  *                                                                          *
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:                 *
11  *                                                                          *
12  * The above copyright notice and this permission notice shall be included  *
13  * in all copies or substantial portions of the Software.                   *
14  *                                                                          *
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.                               *
22  *                                                                          *
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       *
26  * authorization.                                                           *
27  ****************************************************************************/
28
29 /****************************************************************************
30  *  Author: Thomas E. Dickey                                                *
31  ****************************************************************************/
32
33 /*
34  * Common type definitions and macros for new_pair.c, lib_color.c
35  *
36  * $Id: new_pair.h,v 1.6 2017/04/29 20:25:29 tom Exp $
37  */
38
39 #ifndef NEW_PAIR_H
40 #define NEW_PAIR_H 1
41 /* *INDENT-OFF* */
42
43 #define USE_NEW_PAIR NCURSES_EXT_COLORS
44
45 #define LIMIT_TYPED(n,t) \
46         (t)(((n) > MAX_OF_TYPE(t)) \
47             ? MAX_OF_TYPE(t) \
48             : ((n) < -MAX_OF_TYPE(t)) \
49                ? -MAX_OF_TYPE(t) \
50                : (n))
51
52 #define limit_COLOR(n) LIMIT_TYPED(n,NCURSES_COLOR_T)
53 #define limit_PAIRS(n) LIMIT_TYPED(n,NCURSES_PAIRS_T)
54
55 #define MAX_XCURSES_PAIR MAX_OF_TYPE(NCURSES_PAIRS_T)
56
57 #if USE_NEW_PAIR
58 #define OPTIONAL_PAIR   GCC_UNUSED
59 #define USE_NEW_PAIR NCURSES_EXT_COLORS
60 #define get_extended_pair(opts, color_pair) \
61         if ((opts) != NULL) { \
62             *(int*)(opts) = color_pair; \
63         }
64 #define set_extended_pair(opts, color_pair) \
65         if ((opts) != NULL) { \
66             color_pair = *(const int*)(opts); \
67         }
68 #else
69 #define OPTIONAL_PAIR   /* nothing */
70 #define USE_NEW_PAIR NCURSES_EXT_COLORS
71 #define get_extended_pair(opts, color_pair) /* nothing */
72 #define set_extended_pair(opts, color_pair) \
73         if ((opts) != NULL) { \
74             color_pair = -1; \
75         }
76 #endif
77
78 #ifdef NEW_PAIR_INTERNAL
79
80 typedef enum {
81     cpKEEP = -1,                /* color pair 0 */
82     cpFREE = 0,                 /* free for use */
83     cpINIT = 1,                 /* init_pair() */
84     cpAUTO = 1                  /* alloc_pair() */
85 } CPMODE;
86
87 typedef struct _color_pairs
88 {
89     int fg;
90     int bg;
91 #if USE_NEW_PAIR
92     int mode;                   /* tells if the entry is allocated or free */
93     int prev;                   /* index of previous item */
94     int next;                   /* index of next item */
95 #endif
96 }
97 colorpair_t;
98
99 #define MakeColorPair(target,f,b) target.fg = f, target.bg = b
100 #define isSamePair(a,b)         ((a).fg == (b).fg && (a).bg == (b).bg)
101 #define FORE_OF(c)              (c).fg
102 #define BACK_OF(c)              (c).bg
103
104 /*
105  * Ensure that we use color pairs only when colors have been started, and also
106  * that the index is within the limits of the table which we allocated.
107  */
108 #define ValidPair(sp,pair) \
109     ((sp != 0) && (pair >= 0) && (pair < sp->_pair_limit) && sp->_coloron)
110
111 #if USE_NEW_PAIR
112 extern NCURSES_EXPORT(void)     _nc_set_color_pair(SCREEN*, int, int);
113 extern NCURSES_EXPORT(void)     _nc_reset_color_pair(SCREEN*, int, colorpair_t*);
114 #else
115 #define _nc_set_color_pair(sp, pair, mode) /* nothing */
116 #define _nc_reset_color_pair(sp, pair, data) /* nothing */
117 #endif
118
119 #else
120
121 typedef struct _color_pairs colorpair_t;
122
123 #endif /* NEW_PAIR_INTERNAL */
124
125 #if NO_LEAKS
126 extern NCURSES_EXPORT(void)     _nc_new_pair_leaks(SCREEN*);
127 #endif
128
129 /* *INDENT-ON* */
130
131 #endif /* NEW_PAIR_H */