/*
* Common type definitions and macros for new_pair.c, lib_color.c
*
- * $Id: new_pair.h,v 1.2 2017/03/10 09:20:43 tom Exp $
+ * $Id: new_pair.h,v 1.6 2017/04/29 20:25:29 tom Exp $
*/
#ifndef NEW_PAIR_H
#define USE_NEW_PAIR NCURSES_EXT_COLORS
+#define LIMIT_TYPED(n,t) \
+ (t)(((n) > MAX_OF_TYPE(t)) \
+ ? MAX_OF_TYPE(t) \
+ : ((n) < -MAX_OF_TYPE(t)) \
+ ? -MAX_OF_TYPE(t) \
+ : (n))
+
+#define limit_COLOR(n) LIMIT_TYPED(n,NCURSES_COLOR_T)
+#define limit_PAIRS(n) LIMIT_TYPED(n,NCURSES_PAIRS_T)
+
+#define MAX_XCURSES_PAIR MAX_OF_TYPE(NCURSES_PAIRS_T)
+
+#if USE_NEW_PAIR
+#define OPTIONAL_PAIR GCC_UNUSED
+#define USE_NEW_PAIR NCURSES_EXT_COLORS
+#define get_extended_pair(opts, color_pair) \
+ if ((opts) != NULL) { \
+ *(int*)(opts) = color_pair; \
+ }
+#define set_extended_pair(opts, color_pair) \
+ if ((opts) != NULL) { \
+ color_pair = *(const int*)(opts); \
+ }
+#else
+#define OPTIONAL_PAIR /* nothing */
+#define USE_NEW_PAIR NCURSES_EXT_COLORS
+#define get_extended_pair(opts, color_pair) /* nothing */
+#define set_extended_pair(opts, color_pair) \
+ if ((opts) != NULL) { \
+ color_pair = -1; \
+ }
+#endif
+
#ifdef NEW_PAIR_INTERNAL
typedef enum {
int fg;
int bg;
#if USE_NEW_PAIR
- int mode; /* FIXME - needed? */
+ int mode; /* tells if the entry is allocated or free */
int prev; /* index of previous item */
int next; /* index of next item */
#endif