1 /**************************************************************************** 2 * Copyright (c) 1998-2004,2009 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: Juergen Pfeifer, 1995,1997 * 31 ****************************************************************************/ 32 33 /* $Id: form.h,v 0.21 2009/11/07 19:31:11 tom Exp $ */ 34 35 module deimos.ncurses.form; 36 37 38 import core.stdc.stdarg; 39 public import deimos.ncurses.ncurses; 40 public import deimos.ncurses.eti; 41 42 extern(C) @nogc 43 { 44 45 alias void* FIELD_CELL; 46 alias int Form_Options; 47 alias int Field_Options; 48 49 50 /********** 51 * _PAGE * 52 **********/ 53 54 struct _PAGE 55 { 56 short pmin; /* index of first field on page */ 57 short pmax; /* index of last field on page */ 58 short smin; /* index of top leftmost field on page */ 59 short smax; /* index of bottom rightmost field on page */ 60 } 61 62 /********** 63 * FIELD * 64 **********/ 65 66 struct FIELD 67 { 68 ushort status; /* flags */ 69 short rows; /* size in rows */ 70 short cols; /* size in cols */ 71 short frow; /* first row */ 72 short fcol; /* first col */ 73 int drows; /* dynamic rows */ 74 int dcols; /* dynamic cols */ 75 int maxgrow; /* maximum field growth */ 76 int nrow; /* off-screen rows */ 77 short nbuf; /* additional buffers */ 78 short just; /* justification */ 79 short page; /* page on form */ 80 short index; /* into form -> field */ 81 int pad; /* pad character */ 82 chtype fore; /* foreground attribute */ 83 chtype back; /* background attribute */ 84 Field_Options opts; /* options */ 85 FIELD* snext; /* sorted order pointer */ 86 FIELD* sprev; /* sorted order pointer */ 87 FIELD* link; /* linked field chain */ 88 FORM* form; /* containing form */ 89 FORM* type; /* field type */ 90 void* arg; /* argument for type */ 91 FIELD_CELL* buf; /* field buffers */ 92 void* usrptr; /* user pointer */ 93 /* 94 * The wide-character configuration requires extra information. Because 95 * there are existing applications that manipulate the members of FIELD 96 * directly, we cannot make the struct opaque. Offsets of members up to 97 * this point are the same in the narrow- and wide-character configuration. 98 * But note that the type of buf depends on the configuration, and is made 99 * opaque for that reason. 100 */ 101 } 102 103 /********* 104 * FORM * 105 *********/ 106 107 struct FORM 108 { 109 ushort status; /* flags */ 110 short rows; /* size in rows */ 111 short cols; /* size in cols */ 112 int currow; /* current row in field window */ 113 int curcol; /* current col in field window */ 114 int toprow; /* in scrollable field window */ 115 int begincol; /* in horiz. scrollable field */ 116 short maxfield; /* number of fields */ 117 short maxpage; /* number of pages */ 118 short curpage; /* index into page */ 119 Form_Options opts; /* options */ 120 WINDOW* win; /* window */ 121 WINDOW* sub; /* subwindow */ 122 WINDOW* w; /* window for current field */ 123 FIELD** field; /* field [maxfield] */ 124 FIELD* current; /* current field */ 125 _PAGE* page; /* page [maxpage] */ 126 void* usrptr; /* user pointer */ 127 //TODO check... 128 void function(FORM* form) forminit; 129 void function(FORM* form) formterm; 130 void function(FORM* form) fieldinit; 131 void function(FORM* form) fieldterm; 132 } 133 134 135 /************** 136 * FIELDTYPE * 137 **************/ 138 139 struct FIELDTYPE 140 { 141 ushort status; /* flags */ 142 long reference; /* reference count */ 143 FIELDTYPE* left; /* ptr to operand for | */ 144 FIELDTYPE* right; /* ptr to operand for | */ 145 146 void* function(va_list*) makearg; /* make fieldtype arg */ 147 void* function(const void*) copyarg; /* copy fieldtype arg */ 148 void function(void*) freearg; /* free fieldtype arg */ 149 150 bool function(FIELD*, const void*) fcheck; /* field validation */ 151 bool function(int, const void*) ccheck; /* character validation */ 152 153 bool function(FIELD*, const void*) next; /* enumerate next value */ 154 bool function(FIELD*, const void*) prev; /* enumerate prev value */ 155 } 156 157 /*************************** 158 * miscellaneous #defines * 159 ***************************/ 160 161 immutable enum 162 { 163 /* field justification */ 164 NO_JUSTIFICATION = 0, 165 JUSTIFY_LEFT = 1, 166 JUSTIFY_CENTER = 2, 167 JUSTIFY_RIGHT = 3 168 } 169 170 immutable enum :OPTIONS 171 { 172 /* field options */ 173 O_VISIBLE = 0x0001, 174 O_ACTIVE = 0x0002, 175 O_PUBLIC = 0x0004, 176 O_EDIT = 0x0008, 177 O_WRAP = 0x0010, 178 O_BLANK = 0x0020, 179 O_AUTOSKIP = 0x0040, 180 O_NULLOK = 0x0080, 181 O_PASSOK = 0x0100, 182 O_STATIC = 0x0200, 183 184 /* form options */ 185 O_NL_OVERLOAD = 0x0001, 186 O_BS_OVERLOAD = 0x0002 187 } 188 189 immutable enum 190 { 191 /* form driver commands */ 192 REQ_NEXT_PAGE = (KEY_MAX + 1), /* move to next page */ 193 REQ_PREV_PAGE = (KEY_MAX + 2), /* move to previous page */ 194 REQ_FIRST_PAGE = (KEY_MAX + 3), /* move to first page */ 195 REQ_LAST_PAGE = (KEY_MAX + 4), /* move to last page */ 196 197 REQ_NEXT_FIELD = (KEY_MAX + 5), /* move to next field */ 198 REQ_PREV_FIELD = (KEY_MAX + 6), /* move to previous field */ 199 REQ_FIRST_FIELD = (KEY_MAX + 7), /* move to first field */ 200 REQ_LAST_FIELD = (KEY_MAX + 8), /* move to last field */ 201 REQ_SNEXT_FIELD = (KEY_MAX + 9), /* move to sorted next field */ 202 REQ_SPREV_FIELD = (KEY_MAX + 10), /* move to sorted prev field */ 203 REQ_SFIRST_FIELD = (KEY_MAX + 11), /* move to sorted first field */ 204 REQ_SLAST_FIELD = (KEY_MAX + 12), /* move to sorted last field */ 205 REQ_LEFT_FIELD = (KEY_MAX + 13), /* move to left to field */ 206 REQ_RIGHT_FIELD = (KEY_MAX + 14), /* move to right to field */ 207 REQ_UP_FIELD = (KEY_MAX + 15), /* move to up to field */ 208 REQ_DOWN_FIELD = (KEY_MAX + 16), /* move to down to field */ 209 210 REQ_NEXT_CHAR = (KEY_MAX + 17), /* move to next char in field */ 211 REQ_PREV_CHAR = (KEY_MAX + 18), /* move to prev char in field */ 212 REQ_NEXT_LINE = (KEY_MAX + 19), /* move to next line in field */ 213 REQ_PREV_LINE = (KEY_MAX + 20), /* move to prev line in field */ 214 REQ_NEXT_WORD = (KEY_MAX + 21), /* move to next word in field */ 215 REQ_PREV_WORD = (KEY_MAX + 22), /* move to prev word in field */ 216 REQ_BEG_FIELD = (KEY_MAX + 23), /* move to first char in field */ 217 REQ_END_FIELD = (KEY_MAX + 24), /* move after last char in fld */ 218 REQ_BEG_LINE = (KEY_MAX + 25), /* move to beginning of line */ 219 REQ_END_LINE = (KEY_MAX + 26), /* move after last char in line */ 220 REQ_LEFT_CHAR = (KEY_MAX + 27), /* move left in field */ 221 REQ_RIGHT_CHAR = (KEY_MAX + 28), /* move right in field */ 222 REQ_UP_CHAR = (KEY_MAX + 29), /* move up in field */ 223 REQ_DOWN_CHAR = (KEY_MAX + 30), /* move down in field */ 224 225 REQ_NEW_LINE = (KEY_MAX + 31), /* insert/overlay new line */ 226 REQ_INS_CHAR = (KEY_MAX + 32), /* insert blank char at cursor */ 227 REQ_INS_LINE = (KEY_MAX + 33), /* insert blank line at cursor */ 228 REQ_DEL_CHAR = (KEY_MAX + 34), /* delete char at cursor */ 229 REQ_DEL_PREV = (KEY_MAX + 35), /* delete char before cursor */ 230 REQ_DEL_LINE = (KEY_MAX + 36), /* delete line at cursor */ 231 REQ_DEL_WORD = (KEY_MAX + 37), /* delete word at cursor */ 232 REQ_CLR_EOL = (KEY_MAX + 38), /* clear to end of line */ 233 REQ_CLR_EOF = (KEY_MAX + 39), /* clear to end of field */ 234 REQ_CLR_FIELD = (KEY_MAX + 40), /* clear entire field */ 235 REQ_OVL_MODE = (KEY_MAX + 41), /* begin overlay mode */ 236 REQ_INS_MODE = (KEY_MAX + 42), /* begin insert mode */ 237 REQ_SCR_FLINE = (KEY_MAX + 43), /* scroll field forward a line */ 238 REQ_SCR_BLINE = (KEY_MAX + 44), /* scroll field backward a line */ 239 REQ_SCR_FPAGE = (KEY_MAX + 45), /* scroll field forward a page */ 240 REQ_SCR_BPAGE = (KEY_MAX + 46), /* scroll field backward a page */ 241 REQ_SCR_FHPAGE = (KEY_MAX + 47), /* scroll field forward half page */ 242 REQ_SCR_BHPAGE = (KEY_MAX + 48), /* scroll field backward half page */ 243 REQ_SCR_FCHAR = (KEY_MAX + 49), /* horizontal scroll char */ 244 REQ_SCR_BCHAR = (KEY_MAX + 50), /* horizontal scroll char */ 245 REQ_SCR_HFLINE = (KEY_MAX + 51), /* horizontal scroll line */ 246 REQ_SCR_HBLINE = (KEY_MAX + 52), /* horizontal scroll line */ 247 REQ_SCR_HFHALF = (KEY_MAX + 53), /* horizontal scroll half line */ 248 REQ_SCR_HBHALF = (KEY_MAX + 54), /* horizontal scroll half line */ 249 250 REQ_VALIDATION = (KEY_MAX + 55), /* validate field */ 251 REQ_NEXT_CHOICE = (KEY_MAX + 56), /* display next field choice */ 252 REQ_PREV_CHOICE = (KEY_MAX + 57), /* display prev field choice */ 253 254 MIN_FORM_COMMAND = (KEY_MAX + 1), /* used by form_driver */ 255 MAX_FORM_COMMAND = (KEY_MAX + 57) /* used by form_driver */ 256 } 257 258 immutable MAX_COMMAND = (KEY_MAX + 128); 259 260 /************************* 261 * standard field types * 262 *************************/ 263 FIELDTYPE* TYPE_ALNUM; 264 FIELDTYPE* TYPE_ALPHA; 265 FIELDTYPE* TYPE_ENUM; 266 FIELDTYPE* TYPE_INTEGER; 267 FIELDTYPE* TYPE_NUMERIC; 268 FIELDTYPE* TYPE_REGEXP; 269 270 /************************************ 271 * built-in additional field types * 272 * They are not defined in SVr4 * 273 ************************************/ 274 FIELDTYPE* TYPE_IPV4; /* Internet IP Version 4 address */ 275 276 /*********************** 277 * FIELDTYPE routines * 278 ***********************/ 279 FIELDTYPE* new_fieldtype( 280 bool function(FIELD*, void*) field_check, 281 bool function(int, void*) char_check); 282 FIELDTYPE* link_fieldtype(FIELDTYPE* type1, FIELDTYPE* type2); 283 284 int free_fieldtype(FIELDTYPE* fieldtype); 285 int set_fieldtype_arg( 286 FIELDTYPE* fieldtype, 287 void* function(va_list*) make_arg, 288 void* function(void*) copy_arg, 289 void function(void*) free_arg); 290 int set_fieldtype_choice( 291 FIELDTYPE* fieldtype, 292 bool function(FIELD*, void*) next_choice, 293 bool function(FIELD*, void*) prev_choice); 294 295 /******************* 296 * FIELD routines * 297 *******************/ 298 FIELD* new_field(int height, int width, int toprow, int leftcol, int offscreen, int nbuffers); 299 FIELD* dup_field(FIELD* field, int toprow, int leftcol); 300 FIELD* link_field(FIELD* field, int toprow, int leftcol); 301 302 int free_field(FIELD* field); 303 int field_info(const FIELD* field, int* rows, int* cols, int* frow, int* fcol, int* nrow, int* nbuf); 304 int dynamic_field_info(const FIELD* field, int* rows, int* cols, int* max); 305 int set_max_field(FIELD* field, int max); 306 int move_field(FIELD* field, int frow, int fcol); 307 int set_field_type(FIELD* field, FIELDTYPE* type, ...); 308 int set_new_page(FIELD* field, bool new_page_flag); 309 int set_field_just(FIELD* field, int justification); 310 int field_just(const FIELD* field); 311 int set_field_fore(FIELD* field, chtype attr); 312 int set_field_back(FIELD* field, chtype attr); 313 int set_field_pad(FIELD* field, int pad); 314 int field_pad(const FIELD* field); 315 int set_field_buffer(FIELD* field, int buf, immutable(char*) value); 316 int set_field_status(FIELD* field, bool status); 317 int set_field_userptr(FIELD* field, void* userptr); 318 int set_field_opts(FIELD* field, Field_Options opts); 319 int field_opts_on(FIELD* field, Field_Options opts); 320 int field_opts_off(FIELD* field, Field_Options opts); 321 322 chtype field_fore(const FIELD* field); 323 chtype field_back(const FIELD* field); 324 325 bool new_page(const FIELD* field); 326 bool field_status(const FIELD* field); 327 328 void* field_arg(const FIELD* field); 329 330 void* field_userptr(const FIELD* field); 331 332 FIELDTYPE* field_type(const FIELD* field); 333 334 char* field_buffer(const FIELD* field, int buffer); 335 336 Field_Options field_opts(const FIELD* field); 337 338 /****************** 339 * FORM routines * 340 ******************/ 341 342 FORM* new_form(FIELD** fields); 343 344 FIELD** form_fields(const FORM* form); 345 FIELD* current_field(const FORM* form); 346 347 WINDOW* form_win(const FORM* form); 348 WINDOW* form_sub(const FORM* form); 349 350 FORM* form_init(const FORM* form); 351 FORM* form_term(const FORM* form); 352 FORM* field_init(const FORM* form); 353 FORM* field_term(const FORM* form); 354 355 int free_form(FORM* form); 356 int set_form_fields(FORM* form, FIELD** fields); 357 int field_count(const FORM* form); 358 int set_form_win(FORM* form, WINDOW* win); 359 int set_form_sub(FORM* form, WINDOW* sub); 360 int set_current_field(FORM* form, FIELD* field); 361 int field_index(const FIELD* field); 362 int set_form_page(FORM* form, int n); 363 int form_page(const FORM* form); 364 int scale_form(const FORM* form, int* rows, int* columns); 365 366 int set_form_init(FORM* form, FORM* func); 367 int set_form_term(FORM* form, FORM* func); 368 int set_field_init(FORM* form, FORM* func); 369 int set_field_term(FORM* form, FORM* func); 370 int post_form(FORM* form); 371 int unpost_form(FORM* form); 372 int pos_form_cursor(FORM* form); 373 int form_driver(FORM* form, int c); 374 int set_form_userptr(FORM* form, void* userptr); 375 int set_form_opts(FORM* form, Form_Options opts); 376 int form_opts_on(FORM* form, Form_Options opts); 377 int form_opts_off(FORM* form, Form_Options opts); 378 int form_request_by_name(immutable char* name); 379 380 char* form_request_name(int request); 381 382 void* form_userptr(const FORM* form); 383 384 Form_Options form_opts(const FORM* form); 385 386 bool data_ahead(const FORM* form); 387 bool data_behind(const FORM* form); 388 }//end extern (C)