1 /* 2 * $Id: matrix.h,v 1.30 2012/03/21 21:15:30 tom Exp $ 3 */ 4 5 #ifndef CDKINCLUDES 6 #ifndef CDKMATRIX_H 7 #define CDKMATRIX_H 1 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 #ifndef CDK_H 14 #define CDKINCLUDES 15 #include <cdk.h> 16 #undef CDKINCLUDES 17 #include <binding.h> 18 #include <cdkscreen.h> 19 #include <cdk_objs.h> 20 #endif 21 22 /* 23 * Changes 1999-2008,2012 copyright Thomas E. Dickey 24 * 25 * Copyright 1999, Mike Glover 26 * All rights reserved. 27 * 28 * Redistribution and use in source and binary forms, with or without 29 * modification, are permitted provided that the following conditions 30 * are met: 31 * 1. Redistributions of source code must retain the above copyright 32 * notice, this list of conditions and the following disclaimer. 33 * 2. Redistributions in binary form must reproduce the above copyright 34 * notice, this list of conditions and the following disclaimer in the 35 * documentation and/or other materials provided with the distribution. 36 * 3. All advertising materials mentioning features or use of this software 37 * must display the following acknowledgment: 38 * This product includes software developed by Mike Glover 39 * and contributors. 40 * 4. Neither the name of Mike Glover, nor the names of contributors 41 * may be used to endorse or promote products derived from this software 42 * without specific prior written permission. 43 * 44 * THIS SOFTWARE IS PROVIDED BY MIKE GLOVER AND CONTRIBUTORS ``AS IS'' AND 45 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 47 * ARE DISCLAIMED. IN NO EVENT SHALL MIKE GLOVER OR CONTRIBUTORS BE LIABLE 48 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 50 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 51 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 54 * SUCH DAMAGE. 55 */ 56 57 /* 58 * Declare some matrix definitions. 59 */ 60 #define MAX_MATRIX_ROWS 1000 61 #define MAX_MATRIX_COLS 1000 62 63 /* 64 * Define the CDK matrix widget structure. 65 */ 66 typedef struct SMatrix CDKMATRIX; 67 typedef void (*MATRIXCB) (CDKMATRIX *matrix, chtype input); 68 69 #define CELL_LIMIT MAX_MATRIX_ROWS][MAX_MATRIX_COLS 70 71 #define NEW_CDKMATRIX 1 72 73 #if NEW_CDKMATRIX 74 #define CELL_INDEX(matrix, row,col) (((row) * ((matrix)->cols + 1)) + (col)) 75 #else 76 #define CELL_INDEX(matrix, row,col) (row)][(col) 77 #endif 78 79 #define MATRIX_CELL(matrix,row,col) ((matrix)->cell[CELL_INDEX(matrix, row, col)]) 80 #define MATRIX_INFO(matrix,row,col) ((matrix)->info[CELL_INDEX(matrix, row, col)]) 81 82 struct SMatrix { 83 CDKOBJS obj; 84 WINDOW * parent; 85 WINDOW * win; 86 WINDOW * shadowWin; 87 #if NEW_CDKMATRIX 88 WINDOW ** cell; 89 char ** info; 90 #else 91 WINDOW * cell[CELL_LIMIT]; 92 char * info[CELL_LIMIT]; 93 #endif 94 int titleAdj; 95 int rows; 96 int cols; 97 int vrows; 98 int vcols; 99 int * colwidths; 100 int * colvalues; 101 chtype ** coltitle; 102 int * coltitleLen; 103 int * coltitlePos; 104 int maxct; 105 chtype ** rowtitle; 106 int * rowtitleLen; 107 int * rowtitlePos; 108 int maxrt; 109 int boxHeight; 110 int boxWidth; 111 int rowSpace; 112 int colSpace; 113 int row; 114 int col; 115 int crow; /* current row */ 116 int ccol; /* current column */ 117 int trow; /* topmost row shown in screen */ 118 int lcol; /* leftmost column shown in screen */ 119 int oldcrow; 120 int oldccol; 121 int oldvrow; 122 int oldvcol; 123 EExitType exitType; 124 boolean boxCell; 125 boolean shadow; 126 chtype highlight; 127 int dominant; 128 chtype filler; 129 MATRIXCB callbackfn; 130 }; 131 132 /* 133 * This creates a new pointer to a matrix widget. 134 */ 135 CDKMATRIX *newCDKMatrix ( 136 CDKSCREEN * /* cdkscreen */, 137 int /* xpos */, 138 int /* ypos */, 139 int /* rows */, 140 int /* cols */, 141 int /* vrows */, 142 int /* vcols */, 143 const char * /* title */, 144 CDK_CSTRING2 /* rowtitles */, 145 CDK_CSTRING2 /* coltitles */, 146 int * /* colwidths */, 147 int * /* coltypes */, 148 int /* rowspace */, 149 int /* colspace */, 150 chtype /* filler */, 151 int /* dominantAttrib */, 152 boolean /* boxMatrix */, 153 boolean /* boxCell */, 154 boolean /* shadow */); 155 156 /* 157 * This activates the matrix. 158 */ 159 int activateCDKMatrix ( 160 CDKMATRIX * /* matrix */, 161 chtype * /* actions */); 162 163 /* 164 * This injects a single character into the matrix widget. 165 */ 166 #define injectCDKMatrix(obj,input) injectCDKObject(obj,input,Int) 167 168 /* 169 * This sets the contents of the matrix widget from a fixed-size 2d array. 170 * The predefined array limits are very large. 171 * Use setCDKMatrixCells() instead. 172 */ 173 #define setCDKMatrix(matrix, info, rows, subSize) \ 174 setCDKMatrixCells(matrix, &info[0][0], rows, MAX_MATRIX_COLS, subSize) 175 176 /* 177 * This sets the contents of the matrix widget from an array defined by the 178 * caller. It may be any size. For compatibility with setCDKMatrix(), the 179 * info[][] array's subscripts start at 1. 180 */ 181 void setCDKMatrixCells ( 182 CDKMATRIX * /* matrix */, 183 CDK_CSTRING2 /* info */, 184 int /* rows */, 185 int /* cols */, 186 int * /* subSize */); 187 188 /* 189 * This sets the value of a given cell. 190 */ 191 int setCDKMatrixCell ( 192 CDKMATRIX * /* matrix */, 193 int /* row */, 194 int /* col */, 195 const char * /* value */); 196 197 char *getCDKMatrixCell ( 198 CDKMATRIX * /* matrix */, 199 int /* row */, 200 int /* col */); 201 202 /* 203 * This returns the row/col of the matrix. 204 */ 205 int getCDKMatrixCol ( 206 CDKMATRIX * /* matrix */); 207 208 int getCDKMatrixRow ( 209 CDKMATRIX * /* matrix */); 210 211 /* 212 * These set the drawing characters of the widget. 213 */ 214 #define setCDKMatrixULChar(w,c) setULCharOf(w,c) 215 #define setCDKMatrixURChar(w,c) setURCharOf(w,c) 216 #define setCDKMatrixLLChar(w,c) setLLCharOf(w,c) 217 #define setCDKMatrixLRChar(w,c) setLRCharOf(w,c) 218 #define setCDKMatrixVerticalChar(w,c) setVTCharOf(w,c) 219 #define setCDKMatrixHorizontalChar(w,c) setHZCharOf(w,c) 220 #define setCDKMatrixBoxAttribute(w,c) setBXAttrOf(w,c) 221 222 /* 223 * This sets the background color of the widget. 224 */ 225 #define setCDKMatrixBackgroundColor(w,c) setCDKObjectBackgroundColor(ObjOf(w),c) 226 227 /* 228 * This sets the background attribute of the widget. 229 */ 230 #define setCDKMatrixBackgroundAttrib(w,c) setBKAttrOf(w,c) 231 232 /* 233 * This draws the matrix on the screen. 234 */ 235 #define drawCDKMatrix(obj,Box) drawCDKObject(obj,Box) 236 237 /* 238 * This removes the matrix from the screen. 239 */ 240 #define eraseCDKMatrix(obj) eraseCDKObject(obj) 241 242 /* 243 * This cleans out all the cells from the matrix. 244 */ 245 void cleanCDKMatrix ( 246 CDKMATRIX * /* matrix */); 247 248 /* 249 * This cleans one cell in the matrix. 250 */ 251 void cleanCDKMatrixCell ( 252 CDKMATRIX * /* matrix */, 253 int /* row */, 254 int /* col */); 255 256 /* 257 * This sets the main callback in the matrix. 258 */ 259 void setCDKMatrixCB ( 260 CDKMATRIX * /* matrix */, 261 MATRIXCB /* callback */); 262 263 /* 264 * This moves the matrix to the given cell. 265 */ 266 int moveToCDKMatrixCell ( 267 CDKMATRIX * /* matrix */, 268 int /* newrow */, 269 int /* newcol */); 270 271 /* 272 * This sets the box attribute of the matrix widget. 273 */ 274 void setCDKMatrixBox ( 275 CDKMATRIX * /* matrix */, 276 boolean /* Box */); 277 278 boolean getCDKMatrixBox ( 279 CDKMATRIX * /* matrix */); 280 281 /* 282 * This moves the matrix on the screen to the given location. 283 */ 284 #define moveCDKMatrix(obj,xpos,ypos,relative,refresh) moveCDKObject(obj,xpos,ypos,relative,refresh) 285 286 /* 287 * This allows the user to interactively position the matrix. 288 */ 289 #define positionCDKMatrix(widget) positionCDKObject(ObjOf(widget),widget->win) 290 291 /* 292 * This destroys the matrix widget and associated memory. 293 */ 294 #define destroyCDKMatrix(obj) destroyCDKObject(obj) 295 296 /* 297 * This jumps to the given matrix cell. You can pass in 298 * -1 for both the row/col if you want to interactively 299 * pick the cell. 300 */ 301 int jumpToCell ( 302 CDKMATRIX * /* matrix */, 303 int /* row */, 304 int /* col */); 305 306 /* 307 * These set the pre/post process callback functions. 308 */ 309 #define setCDKMatrixPreProcess(w,f,d) setCDKObjectPreProcess(ObjOf(w),f,d) 310 #define setCDKMatrixPostProcess(w,f,d) setCDKObjectPostProcess(ObjOf(w),f,d) 311 312 #ifdef __cplusplus 313 } 314 #endif 315 316 #endif /* CDKMATRIX_H */ 317 #endif /* CDKINCLUDES */ 318