1 /* 2 * $Id: cdk_int.h,v 1.27 2016/12/04 19:43:43 tom Exp $ 3 */ 4 5 #ifndef CDKINCLUDES 6 #ifndef CDK_INT_H 7 #define CDK_INT_H 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 #include <cdk.h> 14 15 /* 16 * Copyright 2003-2013,2016 Thomas E. Dickey 17 * All rights reserved. 18 * 19 * Redistribution and use in source and binary forms, with or without 20 * modification, are permitted provided that the following conditions 21 * are met: 22 * 1. Redistributions of source code must retain the above copyright 23 * notice, this list of conditions and the following disclaimer. 24 * 2. Redistributions in binary form must reproduce the above copyright 25 * notice, this list of conditions and the following disclaimer in the 26 * documentation and/or other materials provided with the distribution. 27 * 3. All advertising materials mentioning features or use of this software 28 * must display the following acknowledgment: 29 * This product includes software developed by Thomas Dickey 30 * and contributors. 31 * 4. Neither the name of Thomas Dickey, nor the names of contributors 32 * may be used to endorse or promote products derived from this software 33 * without specific prior written permission. 34 * 35 * THIS SOFTWARE IS PROVIDED BY THOMAS DICKEY AND CONTRIBUTORS ``AS IS'' AND 36 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 38 * ARE DISCLAIMED. IN NO EVENT SHALL THOMAS DICKEY OR CONTRIBUTORS BE LIABLE 39 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 40 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 41 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 42 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 43 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 44 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 45 * SUCH DAMAGE. 46 */ 47 48 #define typeCallocN(type,n) (type*)calloc((size_t)(n), sizeof(type)) 49 #define typeCalloc(type) typeCallocN(type,1) 50 51 #define typeReallocN(type,p,n) (type*)realloc(p, (size_t)(n) * sizeof(type)) 52 53 #define typeMallocN(type,n) (type*)malloc((size_t)(n) * sizeof(type)) 54 #define typeMalloc(type) typeMallocN(type,1) 55 56 #define freeChecked(p) if ((p) != 0) free (p) 57 #define freeAndNull(p) if ((p) != 0) { free (p); p = 0; } 58 59 #define isChar(c) ((int)(c) >= 0 && (int)(c) < KEY_MIN) 60 #define CharOf(c) ((unsigned char)(c)) 61 62 #define SIZEOF(v) (sizeof(v)/sizeof((v)[0])) 63 64 #define MAX_COLORS 8 65 66 /* 67 * Macros to check if caller is attempting to make the widget as high (or wide) 68 * as the screen. 69 */ 70 #define isFullWidth(n) ((n) == FULL || (COLS != 0 && ((n) >= COLS))) 71 #define isFullHeight(n) ((n) == FULL || (LINES != 0 && ((n) >= LINES))) 72 73 /* 74 * Hide details of modifying widget->exitType 75 */ 76 #define storeExitType(d) ObjOf(d)->exitType = (d)->exitType 77 #define initExitType(d) storeExitType(d) = vNEVER_ACTIVATED 78 #define setExitType(w,c) setCdkExitType(ObjOf(w), &((w)->exitType), c) 79 #define copyExitType(d,s) storeExitType(d) = ExitTypeOf(s) 80 81 /* 82 * Use this if checkCDKObjectBind() returns true, use this function to 83 * decide if the exitType should be set as a side-effect. 84 */ 85 #define checkEarlyExit(w) if (EarlyExitOf(w) != vNEVER_ACTIVATED) \ 86 storeExitType(w) = EarlyExitOf(w) 87 88 /* 89 * Position within the data area of a widget, accounting for border and title. 90 */ 91 #define SCREEN_XPOS(w,n) ((n) + BorderOf(w)) 92 #define SCREEN_YPOS(w,n) ((n) + BorderOf(w) + TitleLinesOf(w)) 93 94 /* 95 * Miscellaneous definitions. 96 */ 97 #define CDK_PATHMAX 256 98 99 extern char *GPasteBuffer; 100 101 #ifdef __cplusplus 102 } 103 #endif 104 105 #endif /* CDK_INT_H */ 106 #endif /* CDKINCLUDES */ 107