]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/new_pair.h
ncurses 6.0 - patch 20170311
[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.2 2017/03/10 09:20:43 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 #ifdef NEW_PAIR_INTERNAL
46
47 typedef enum {
48     cpKEEP = -1,                /* color pair 0 */
49     cpFREE = 0,                 /* free for use */
50     cpINIT = 1,                 /* init_pair() */
51     cpAUTO = 1                  /* alloc_pair() */
52 } CPMODE;
53
54 typedef struct _color_pairs
55 {
56     int fg;
57     int bg;
58 #if USE_NEW_PAIR
59     int mode;                   /* FIXME - needed? */
60     int prev;                   /* index of previous item */
61     int next;                   /* index of next item */
62 #endif
63 }
64 colorpair_t;
65
66 #define MakeColorPair(target,f,b) target.fg = f, target.bg = b
67 #define isSamePair(a,b)         ((a).fg == (b).fg && (a).bg == (b).bg)
68 #define FORE_OF(c)              (c).fg
69 #define BACK_OF(c)              (c).bg
70
71 /*
72  * Ensure that we use color pairs only when colors have been started, and also
73  * that the index is within the limits of the table which we allocated.
74  */
75 #define ValidPair(sp,pair) \
76     ((sp != 0) && (pair >= 0) && (pair < sp->_pair_limit) && sp->_coloron)
77
78 #if USE_NEW_PAIR
79 extern NCURSES_EXPORT(void)     _nc_set_color_pair(SCREEN*, int, int);
80 extern NCURSES_EXPORT(void)     _nc_reset_color_pair(SCREEN*, int, colorpair_t*);
81 #else
82 #define _nc_set_color_pair(sp, pair, mode) /* nothing */
83 #define _nc_reset_color_pair(sp, pair, data) /* nothing */
84 #endif
85
86 #else
87
88 typedef struct _color_pairs colorpair_t;
89
90 #endif /* NEW_PAIR_INTERNAL */
91
92 #if NO_LEAKS
93 extern NCURSES_EXPORT(void)     _nc_new_pair_leaks(SCREEN*);
94 #endif
95
96 /* *INDENT-ON* */
97
98 #endif /* NEW_PAIR_H */