1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211
|
#include "cdk.h"
#include <limits.h>
/*
* $Author: glovem $
* $Date: 1998/03/02 16:31:18 $
* $Revision: 1.135 $
*/
/*
* Declare file local prototypes.
*/
void CDKEntryCallBack (CDKENTRY *entry, chtype character);
void drawCDKEntryField (CDKENTRY *entry);
/*
* Declare file local variables.
*/
extern char *GPasteBuffer;
/*
* This creates a pointer to an entry widget.
*/
CDKENTRY *newCDKEntry (CDKSCREEN *cdkscreen, int xplace, int yplace, char *title, char *label, chtype fieldAttr, chtype filler, EDisplayType dispType, int fWidth, int min, int max, boolean box, boolean shadow)
{
/* Set up some variables. */
CDKENTRY *entry = (CDKENTRY *)malloc (sizeof (CDKENTRY));
chtype *holder = (chtype *)NULL;
int parentWidth = WIN_WIDTH (cdkscreen->window);
int parentHeight = WIN_HEIGHT (cdkscreen->window);
int fieldWidth = fWidth;
int boxWidth = 0;
int boxHeight = 3;
int maxWidth = INT_MIN;
int xpos = xplace;
int ypos = yplace;
int junk = 0;
int horizontalAdjust = 0;
char *temp[256];
int x, len, junk2;
/*
* If the fieldWidth is a negative value, the fieldWidth will
* be COLS-fieldWidth, otherwise, the fieldWidth will be the
* given width.
*/
fieldWidth = setWidgetDimension (parentWidth, fieldWidth, 0);
boxWidth = fieldWidth + 2;
/* Set some basic values of the entry field. */
entry->label = (chtype *)NULL;
entry->labelLen = 0;
entry->labelWin = (WINDOW *)NULL;
entry->titleLines = 0;
/* Translate the label char *pointer to a chtype pointer. */
if (label != (char *)NULL)
{
entry->label = char2Chtype (label, &entry->labelLen, &junk);
boxWidth += entry->labelLen;
}
/* Translate the char * items to chtype * */
if (title != (char *)NULL)
{
/* We need to split the title on \n. */
entry->titleLines = splitString (title, temp, '\n');
/* We need to determine the widest title line. */
for (x=0; x < entry->titleLines; x++)
{
holder = char2Chtype (temp[x], &len, &junk2);
maxWidth = MAXIMUM (maxWidth, len);
freeChtype (holder);
}
/*
* If one of the title lines is wider than the field and the label,
* the box width will expand to accomodate.
*/
if (maxWidth > boxWidth)
{
horizontalAdjust = (int)((maxWidth - boxWidth) / 2) + 1;
boxWidth = maxWidth + 2;
}
/* For each line in the title, convert from char * to chtype * */
for (x=0; x < entry->titleLines; x++)
{
entry->title[x] = char2Chtype (temp[x], &entry->titleLen[x], &entry->titlePos[x]);
entry->titlePos[x] = justifyString (boxWidth, entry->titleLen[x], entry->titlePos[x]);
freeChar (temp[x]);
}
}
else
{
/* No title? Set the required variables. */
entry->titleLines = 0;
}
boxHeight += entry->titleLines;
/*
* Make sure we didn't extend beyond the dimensions of the window.
*/
boxWidth = (boxWidth > parentWidth ? parentWidth : boxWidth);
boxHeight = (boxHeight > parentHeight ? parentHeight : boxHeight);
fieldWidth = (fieldWidth > (boxWidth - entry->labelLen - 2) ? (boxWidth - entry->labelLen - 2) : fieldWidth);
/* Rejustify the x and y positions if we need to. */
alignxy (cdkscreen->window, &xpos, &ypos, boxWidth, boxHeight);
/* Make the label window. */
entry->win = newwin (boxHeight, boxWidth, ypos, xpos);
/* Is the window NULL? */
if (entry->win == (WINDOW *)NULL)
{
/* Clean up the pointers. */
freeChtype (entry->label);
free (entry);
/* Exit with NULL. */
return ((CDKENTRY *)NULL);
}
keypad (entry->win, TRUE);
/* Make the field window. */
entry->fieldWin = subwin (entry->win, 1, fieldWidth,
ypos+entry->titleLines+1,
xpos+entry->labelLen+horizontalAdjust+1);
keypad (entry->fieldWin, TRUE);
/* Make the label win, if we need to. */
if (label != (char *)NULL)
{
entry->labelWin = subwin (entry->win, 1, entry->labelLen+2,
ypos+entry->titleLines+1,
xpos+horizontalAdjust+1);
}
/* Make room for the info char * pointer. */
entry->info = (char *)malloc (sizeof(char) * (max+3));
cleanChar (entry->info, max+3, '\0');
entry->infoWidth = max+3;
/* Set up the rest of the structure. */
entry->parent = cdkscreen->window;
entry->shadowWin = (WINDOW *)NULL;
entry->fieldAttr = fieldAttr;
entry->fieldWidth = fieldWidth;
entry->filler = filler;
entry->hidden = filler;
entry->box = box;
entry->shadow = shadow;
entry->screenCol = 0;
entry->leftChar = 0;
entry->min = min;
entry->max = max;
entry->boxWidth = boxWidth;
entry->boxHeight = boxHeight;
entry->ULChar = ACS_ULCORNER;
entry->URChar = ACS_URCORNER;
entry->LLChar = ACS_LLCORNER;
entry->LRChar = ACS_LRCORNER;
entry->HChar = ACS_HLINE;
entry->VChar = ACS_VLINE;
entry->BoxAttrib = A_NORMAL;
entry->exitType = vNEVER_ACTIVATED;
entry->dispType = dispType;
entry->callbackfn = (void *)&CDKEntryCallBack;
entry->preProcessFunction = (PROCESSFN)NULL;
entry->preProcessData = (void *)NULL;
entry->postProcessFunction = (PROCESSFN)NULL;
entry->postProcessData = (void *)NULL;
/* Do we want a shadow? */
if (shadow)
{
entry->shadowWin = newwin (boxHeight, boxWidth, ypos+1, xpos+1);
}
/* Clean the key bindings. */
cleanCDKObjectBindings (vENTRY, entry);
/* Register this baby. */
registerCDKObject (cdkscreen, vENTRY, entry);
/* Return the pointer to the structure. */
return (entry);
}
/*
* This means you want to use the given entry field. It takes input
* from the keyboard, and when its done, it fills the entry info
* element of the structure with what was typed.
*/
char *activateCDKEntry (CDKENTRY *entry, chtype *actions)
{
/* Declare local variables. */
chtype input = (chtype)NULL;
char *ret = (char *)NULL;
/* Draw the widget. */
drawCDKEntry (entry, entry->box);
/* Check if 'actions' is NULL. */
if (actions == (chtype *)NULL)
{
for (;;)
{
/* Get the input. */
input = wgetch (entry->fieldWin);
/* Inject the character into the widget. */
ret = injectCDKEntry (entry, input);
if (entry->exitType != vEARLY_EXIT)
{
return ret;
}
}
}
else
{
int length = chlen (actions);
int x =0;
/* Inject each character one at a time. */
for (x=0; x < length; x++)
{
ret = injectCDKEntry (entry, actions[x]);
if (entry->exitType != vEARLY_EXIT)
{
return ret;
}
}
}
/* Make sure we return the correct info. */
if (entry->exitType == vNORMAL)
{
return entry->info;
}
else
{
return (char *)NULL;
}
}
/*
* This injects a single character into the widget.
*/
char *injectCDKEntry (CDKENTRY *entry, chtype input)
{
/* Declare local variables. */
int ppReturn = 1;
int temp, x, charCount, stringLen;
char holder;
/* Set the exit type. */
entry->exitType = vEARLY_EXIT;
/* Refresh the entry field. */
drawCDKEntryField (entry);
/* Check if there is a pre-process function to be called. */
if (entry->preProcessFunction != (PROCESSFN)NULL)
{
/* Call the pre-process function. */
ppReturn = ((PROCESSFN)(entry->preProcessFunction)) (vENTRY, entry, entry->preProcessData, input);
}
/* Should we continue? */
if (ppReturn != 0)
{
/* Check a predefined binding... */
if (checkCDKObjectBind (vENTRY, entry, input) != 0)
{
entry->exitType = vEARLY_EXIT;
return (char *)NULL;
}
else
{
switch (input)
{
case KEY_UP : case KEY_DOWN :
Beep();
break;
case CDK_BEGOFLINE :
entry->leftChar = 0;
entry->screenCol = 0;
drawCDKEntryField (entry);
break;
case CDK_TRANSPOSE :
stringLen = (int)strlen (entry->info);
temp = entry->leftChar + entry->screenCol;
if (temp >= stringLen-1)
{
Beep();
}
else
{
holder = entry->info[temp];
entry->info[temp] = entry->info[temp+1];
entry->info[temp+1] = holder;
drawCDKEntryField (entry);
}
break;
case CDK_ENDOFLINE :
stringLen = (int)strlen (entry->info);
if (stringLen >= entry->fieldWidth)
{
charCount = (int)(entry->fieldWidth * .8);
entry->leftChar = stringLen - charCount;
entry->screenCol = charCount;
}
else
{
entry->leftChar = 0;
entry->screenCol = stringLen;
}
drawCDKEntryField (entry);
break;
case KEY_LEFT : case CDK_BACKCHAR :
if (entry->screenCol == 0)
{
if (entry->leftChar == 0)
{
Beep();
}
else
{
/* Scroll left. */
entry->leftChar--;
drawCDKEntryField (entry);
}
}
else
{
wmove (entry->fieldWin, 0, --entry->screenCol);
wrefresh (entry->fieldWin);
}
break;
case KEY_RIGHT : case CDK_FORCHAR :
if (entry->screenCol == entry->fieldWidth-1)
{
temp = (int)strlen (entry->info);
if ((entry->leftChar + entry->screenCol+1) == temp)
{
Beep();
}
else
{
/* Scroll to the right. */
entry->leftChar++;
drawCDKEntryField (entry);
}
}
else
{
/* Move right. */
temp = (int)strlen (entry->info);
if ((entry->leftChar + entry->screenCol) == temp)
{
Beep();
}
else
{
wmove (entry->fieldWin, 0, ++entry->screenCol);
}
wrefresh (entry->fieldWin);
}
break;
case DELETE : case '' : case KEY_BACKSPACE : case KEY_DC :
if (entry->dispType == vVIEWONLY)
{
Beep();
}
else
{
/* Get the length of the widget information. */
int infoLength = (int)strlen (entry->info);
if ((entry->leftChar + entry->screenCol) < infoLength)
{
/* We are deleteing from inside the string. */
int currPos = entry->screenCol+entry->leftChar;
for (x=currPos; x < infoLength; x++)
{
entry->info[x] = entry->info[x+1];
}
entry->info[infoLength] = '\0';
/* Update the widget. */
drawCDKEntryField (entry);
}
else
{
/* We are deleting from the end of the string. */
if (infoLength > 0)
{
/* Update the character pointer. */
entry->info[infoLength-1] = '\0';
infoLength--;
/* Adjust the cursor. */
if (entry->screenCol > 0)
{
entry->screenCol--;
}
/*
* If we deleted the last character on the
* screen and the information has scrolled,
* adjust the entry field to show the info.
*/
if (entry->leftChar > 0 && entry->screenCol == 1)
{
if (infoLength < entry->fieldWidth-1)
{
entry->leftChar = 0;
entry->screenCol = infoLength;
}
else
{
entry->leftChar -= (entry->fieldWidth-3);
entry->screenCol = entry->fieldWidth-2;
}
}
/* Update the widget. */
drawCDKEntryField (entry);
}
else
{
Beep();
}
}
}
break;
case KEY_ESC :
entry->exitType = vESCAPE_HIT;
return (char *)NULL;
break;
case CDK_ERASE :
if ((int)strlen(entry->info) != 0)
{
cleanCDKEntry (entry);
drawCDKEntryField (entry);
}
break;
case CDK_CUT:
if ((int)strlen(entry->info) != 0)
{
freeChar (GPasteBuffer);
GPasteBuffer = copyChar (entry->info);
cleanCDKEntry (entry);
drawCDKEntryField (entry);
}
else
{
Beep();
}
break;
case CDK_COPY:
if ((int)strlen(entry->info) != 0)
{
freeChar (GPasteBuffer);
GPasteBuffer = copyChar (entry->info);
}
else
{
Beep();
}
break;
case CDK_PASTE:
if (GPasteBuffer != (char *)NULL)
{
setCDKEntryValue (entry, GPasteBuffer);
drawCDKEntryField (entry);
}
else
{
Beep();
}
break;
case KEY_RETURN : case KEY_TAB : case KEY_ENTER :
if ((int)strlen (entry->info) >= entry->min)
{
entry->exitType = vNORMAL;
return (entry->info);
}
else
{
Beep();
}
break;
case CDK_REFRESH :
eraseCDKScreen (entry->screen);
refreshCDKScreen (entry->screen);
break;
default :
((ENTRYCB)entry->callbackfn)(entry, input);
break;
}
}
/* Should we do a post-process? */
if (entry->postProcessFunction != (PROCESSFN)NULL)
{
((PROCESSFN)(entry->postProcessFunction)) (vENTRY, entry, entry->postProcessData, input);
}
}
/* Return and indicate that we exited early. */
entry->exitType = vEARLY_EXIT;
return (char *)NULL;
}
/*
* This moves the entry field to the given location.
*/
void moveCDKEntry (CDKENTRY *entry, int xplace, int yplace, boolean relative, boolean refresh)
{
/* Declare local variables. */
int currentX = entry->win->_begx;
int currentY = entry->win->_begy;
int xpos = xplace;
int ypos = yplace;
int xdiff = 0;
int ydiff = 0;
/*
* If this is a relative move, then we will adjust where we want
* to move to.
*/
if (relative)
{
xpos = entry->win->_begx + xplace;
ypos = entry->win->_begy + yplace;
}
/* Adjust the window if we need to. */
alignxy (entry->screen->window, &xpos, &ypos, entry->boxWidth, entry->boxHeight);
/* Get the difference. */
xdiff = currentX - xpos;
ydiff = currentY - ypos;
/* Move the window to the new location. */
entry->win->_begx = xpos;
entry->win->_begy = ypos;
entry->fieldWin->_begx -= xdiff;
entry->fieldWin->_begy -= ydiff;
if (entry->labelWin != (WINDOW *)NULL)
{
entry->labelWin->_begx -= xdiff;
entry->labelWin->_begy -= ydiff;
}
/* If there is a shadow box we have to move it too. */
if (entry->shadowWin != (WINDOW *)NULL)
{
entry->shadowWin->_begx -= xdiff;
entry->shadowWin->_begy -= ydiff;
}
/* Touch the windows so they 'move'. */
touchwin (entry->screen->window);
wrefresh (entry->screen->window);
/* Redraw the window, if they asked for it. */
if (refresh)
{
touchwin (entry->win);
touchwin (entry->labelWin);
touchwin (entry->fieldWin);
drawCDKEntry (entry, entry->box);
}
}
/*
* This allows the user to use the cursor keys to adjust the
* position of the widget.
*/
void positionCDKEntry (CDKENTRY *entry)
{
/* Declare some variables. */
int origX = entry->win->_begx;
int origY = entry->win->_begy;
chtype key = (chtype)NULL;
/* Let them move the widget around until they hit return. */
while ((key != KEY_RETURN) && (key != KEY_ENTER))
{
key = wgetch (entry->win);
if (key == KEY_UP || key == '8')
{
if (entry->win->_begy > 0)
{
moveCDKEntry (entry, 0, -1, TRUE, TRUE);
}
else
{
Beep();
}
}
else if (key == KEY_DOWN || key == '2')
{
if (entry->win->_begy+entry->win->_maxy < entry->screen->window->_maxy-1)
{
moveCDKEntry (entry, 0, 1, TRUE, TRUE);
}
else
{
Beep();
}
}
else if (key == KEY_LEFT || key == '4')
{
if (entry->win->_begx > 0)
{
moveCDKEntry (entry, -1, 0, TRUE, TRUE);
}
else
{
Beep();
}
}
else if (key == KEY_RIGHT || key == '6')
{
if (entry->win->_begx+entry->win->_maxx < entry->screen->window->_maxx-1)
{
moveCDKEntry (entry, 1, 0, TRUE, TRUE);
}
else
{
Beep();
}
}
else if (key == '7')
{
if (entry->win->_begy > 0 && entry->win->_begx > 0)
{
moveCDKEntry (entry, -1, -1, TRUE, TRUE);
}
else
{
Beep();
}
}
else if (key == '9')
{
if (entry->win->_begx+entry->win->_maxx < entry->screen->window->_maxx-1 &&
entry->win->_begy > 0)
{
moveCDKEntry (entry, 1, -1, TRUE, TRUE);
}
else
{
Beep();
}
}
else if (key == '1')
{
if (entry->win->_begx > 0 && entry->win->_begx+entry->win->_maxx < entry->screen->window->_maxx-1)
{
moveCDKEntry (entry, -1, 1, TRUE, TRUE);
}
else
{
Beep();
}
}
else if (key == '3')
{
if (entry->win->_begx+entry->win->_maxx < entry->screen->window->_maxx-1 &&
entry->win->_begy+entry->win->_maxy < entry->screen->window->_maxy-1)
{
moveCDKEntry (entry, 1, 1, TRUE, TRUE);
}
else
{
Beep();
}
}
else if (key == '5')
{
moveCDKEntry (entry, CENTER, CENTER, FALSE, TRUE);
}
else if (key == 't')
{
moveCDKEntry (entry, entry->win->_begx, TOP, FALSE, TRUE);
}
else if (key == 'b')
{
moveCDKEntry (entry, entry->win->_begx, BOTTOM, FALSE, TRUE);
}
else if (key == 'l')
{
moveCDKEntry (entry, LEFT, entry->win->_begy, FALSE, TRUE);
}
else if (key == 'r')
{
moveCDKEntry (entry, RIGHT, entry->win->_begy, FALSE, TRUE);
}
else if (key == 'c')
{
moveCDKEntry (entry, CENTER, entry->win->_begy, FALSE, TRUE);
}
else if (key == 'C')
{
moveCDKEntry (entry, entry->win->_begx, CENTER, FALSE, TRUE);
}
else if (key == CDK_REFRESH)
{
eraseCDKScreen (entry->screen);
refreshCDKScreen (entry->screen);
}
else if (key == KEY_ESC)
{
moveCDKEntry (entry, origX, origY, FALSE, TRUE);
}
else if ((key != KEY_RETURN) && (key != KEY_ENTER))
{
Beep();
}
}
}
/*
* This is a generic character parser for the entry field. It is used as a
* callback function, so any personal modifications can be made by creating
* a new function and calling the activation with its name.
*/
void CDKEntryCallBack (CDKENTRY *entry, chtype character)
{
/* Declare local variables. */
char plainchar = (character & A_CHARTEXT);
int temp, x;
/* Start checking the input. */
if ((entry->dispType == vINT || \
entry->dispType ==vHINT) && \
!isdigit((int)plainchar))
{
Beep();
}
else if ((entry->dispType == vCHAR || \
entry->dispType == vUCHAR || \
entry->dispType == vLCHAR || \
entry->dispType == vUHCHAR || \
entry->dispType == vLHCHAR) && \
isdigit((int)plainchar))
{
Beep();
}
else if (entry->dispType == vVIEWONLY)
{
Beep();
}
else
{
if ((int)strlen (entry->info) == entry->max)
{
Beep();
}
else
{
/* We will make any adjustments to the case of the character. */
if ((entry->dispType == vUCHAR || \
entry->dispType == vUHCHAR || \
entry->dispType == vUMIXED || \
entry->dispType == vUHMIXED) \
&& !isdigit((int)plainchar))
{
plainchar = toupper (plainchar);
}
else if ((entry->dispType == vLCHAR || \
entry->dispType == vLHCHAR || \
entry->dispType == vLMIXED || \
entry->dispType == vLHMIXED) && \
!isdigit((int)plainchar))
{
plainchar = tolower (plainchar);
}
/* Update the screen and pointer. */
if (entry->screenCol != entry->fieldWidth-1)
{
/* Update the character pointer. */
temp = (int)strlen (entry->info);
for (x=temp; x > entry->screenCol+entry->leftChar; x--)
{
entry->info[x] = entry->info[x-1];
}
entry->info[entry->screenCol+entry->leftChar] = plainchar;
entry->screenCol++;
}
else
{
/* Update the character pointer. */
temp = (int)strlen (entry->info);
entry->info[temp] = plainchar;
entry->info[temp+1] = '\0';
entry->leftChar++;
}
/* Update the entry field. */
drawCDKEntryField (entry);
}
}
}
/*
* This erases the information in the entry field
* and redraws a clean and empty entry field.
*/
void cleanCDKEntry (CDKENTRY *entry)
{
/* Declare local variables. */
int width = entry->fieldWidth;
int x;
/* Erase the information in the character pointer. */
cleanChar (entry->info, entry->infoWidth, '\0');
/* Clean the entry screen field. */
for (x=0; x < width; x++)
{
mvwaddch (entry->fieldWin, 0, x, entry->filler);
}
/* Reset some variables. */
entry->screenCol = 0;
entry->leftChar = 0;
/* Refresh the entry field. */
wrefresh (entry->fieldWin);
}
/*
* This draws the entry field.
*/
void drawCDKEntry (CDKENTRY *entry, boolean Box)
{
int x;
/* Did we ask for a shadow? */
if (entry->shadowWin != (WINDOW *)NULL)
{
drawShadow (entry->shadowWin);
}
/* Box the widget if asked. */
if (Box)
{
attrbox (entry->win,
entry->ULChar, entry->URChar,
entry->LLChar, entry->LRChar,
entry->HChar, entry->VChar,
entry->BoxAttrib);
}
/* Draw in the title if there is one. */
if (entry->titleLines != 0)
{
for (x=0; x < entry->titleLines; x++)
{
writeChtype (entry->win,
entry->titlePos[x],
x+1,
entry->title[x],
HORIZONTAL, 0,
entry->titleLen[x]);
}
}
/* Refresh the window. */
touchwin (entry->win);
wrefresh (entry->win);
/* Draw in the label to the widget. */
if (entry->labelWin != (WINDOW *)NULL)
{
writeChtype (entry->labelWin, 0, 0, entry->label, HORIZONTAL, 0, entry->labelLen);
touchwin (entry->labelWin);
wrefresh (entry->labelWin);
}
/* Redraw the entry field. */
drawCDKEntryField (entry);
}
/*
* This redraws the entry field.
*/
void drawCDKEntryField (CDKENTRY *entry)
{
/* Declare variables. */
int infoLength = 0;
int x = 0;
/* Draw in the filler characters.*/
for (x=0; x < entry->fieldWidth; x++)
{
mvwaddch (entry->fieldWin, 0, x, entry->filler);
}
wmove (entry->fieldWin, 0, 0);
/* If there is information in the field. Then draw it in. */
if (entry->info != (char *) NULL)
{
infoLength = (int)strlen (entry->info);
/* Redraw the field. */
if (entry->dispType == vHINT || \
entry->dispType == vHCHAR || \
entry->dispType == vHMIXED || \
entry->dispType == vUHCHAR || \
entry->dispType == vLHCHAR || \
entry->dispType == vUHMIXED || \
entry->dispType == vLHMIXED)
{
for (x=entry->leftChar; x < infoLength; x++)
{
mvwaddch (entry->fieldWin, 0, x-entry->leftChar, entry->hidden);
}
}
else
{
for (x=entry->leftChar; x < infoLength; x++)
{
mvwaddch (entry->fieldWin, 0, x-entry->leftChar, entry->info[x] | entry->fieldAttr);
}
}
wmove (entry->fieldWin, 0, entry->screenCol);
}
/* Refresh the field. */
touchwin (entry->fieldWin);
wrefresh (entry->fieldWin);
}
/*
* This erases an entry widget from the screen.
*/
void eraseCDKEntry (CDKENTRY *entry)
{
eraseCursesWindow (entry->fieldWin);
eraseCursesWindow (entry->labelWin);
eraseCursesWindow (entry->win);
eraseCursesWindow (entry->shadowWin);
}
/*
* This destroys an entry widget.
*/
void destroyCDKEntry (CDKENTRY *entry)
{
int x;
/* Erase the object. */
eraseCDKEntry (entry);
/* Clear out the character pointers. */
for (x=0; x < entry->titleLines; x++)
{
freeChtype (entry->title[x]);
}
freeChtype (entry->label);
freeChar (entry->info);
/* Delete the windows. */
deleteCursesWindow (entry->fieldWin);
deleteCursesWindow (entry->labelWin);
deleteCursesWindow (entry->shadowWin);
deleteCursesWindow (entry->win);
/* Unregister this object. */
unregisterCDKObject (vENTRY, entry);
/* Finish cleaning up. */
free (entry);
}
/*
* This sets specific attributes of the entry field.
*/
void setCDKEntry (CDKENTRY *entry, char *value, int min, int max, boolean Box)
{
setCDKEntryValue (entry, value);
setCDKEntryMin (entry, min);
setCDKEntryMax (entry, max);
setCDKEntryBox (entry, Box);
}
/*
* This removes the old information in the entry field and keeps the
* new information given.
*/
void setCDKEntryValue (CDKENTRY *entry, char *newValue)
{
/* Declare local variables. */
int copychars = 0;
int stringLen = 0;
int charCount = 0;
/* If the pointer sent in is the same pointer as before, do nothing. */
if (entry->info == newValue)
{
return;
}
/* Just to be sure, if lets make sure the new value isn't NULL. */
if (newValue == (char *)NULL)
{
/* Then we want to just erase the old value. */
cleanChar (entry->info, entry->infoWidth, '\0');
/* Set the pointers back to zero. */
entry->leftChar = 0;
entry->screenCol = 0;
return;
}
/* Determine how many characters we need to copy. */
copychars = MINIMUM ((int)strlen(newValue), entry->max);
/* OK, erase the old value, and copy in the new value. */
cleanChar (entry->info, entry->max, '\0');
strncpy (entry->info, newValue, copychars);
stringLen = (int)strlen (entry->info);
/* Now determine the values of leftChar and screenCol. */
if (stringLen >= entry->fieldWidth)
{
charCount = (int)(entry->fieldWidth * .8);
entry->leftChar = stringLen - charCount;
entry->screenCol = charCount;
}
else
{
entry->leftChar = 0;
entry->screenCol = stringLen;
}
}
char *getCDKEntryValue (CDKENTRY *entry)
{
return entry->info;
}
/*
* This sets the maximum length of the string that will be accepted.
*/
void setCDKEntryMax (CDKENTRY *entry, int max)
{
entry->max = max;
}
int getCDKEntryMax (CDKENTRY *entry)
{
return entry->max;
}
/*
* This sets the minimum length of the string that will
* be accepted.
*/
void setCDKEntryMin (CDKENTRY *entry, int min)
{
entry->min = min;
}
int getCDKEntryMin (CDKENTRY *entry)
{
return entry->min;
}
/*
* This sets the filler character to be used in the entry field.
*/
void setCDKEntryFillerChar (CDKENTRY *entry, chtype fillerCharacter)
{
entry->filler = fillerCharacter;
}
chtype getCDKEntryFillerChar (CDKENTRY *entry)
{
return entry->filler;
}
/*
* This sets the character to use when a hidden type is used.
*/
void setCDKEntryHiddenChar (CDKENTRY *entry, chtype hiddenCharacter)
{
entry->hidden = hiddenCharacter;
}
chtype getCDKEntryHiddenChar (CDKENTRY *entry)
{
return entry->hidden;
}
/*
* This sets whether or not the entry field will be boxed.
*/
void setCDKEntryBox (CDKENTRY *entry, boolean Box)
{
entry->box = Box;
}
boolean getCDKEntryBox (CDKENTRY *entry)
{
return entry->box;
}
/*
* These functions set the drawing characters of the widget.
*/
void setCDKEntryULChar (CDKENTRY *entry, chtype character)
{
entry->ULChar = character;
}
void setCDKEntryURChar (CDKENTRY *entry, chtype character)
{
entry->URChar = character;
}
void setCDKEntryLLChar (CDKENTRY *entry, chtype character)
{
entry->LLChar = character;
}
void setCDKEntryLRChar (CDKENTRY *entry, chtype character)
{
entry->LRChar = character;
}
void setCDKEntryVerticalChar (CDKENTRY *entry, chtype character)
{
entry->VChar = character;
}
void setCDKEntryHorizontalChar (CDKENTRY *entry, chtype character)
{
entry->HChar = character;
}
void setCDKEntryBoxAttribute (CDKENTRY *entry, chtype character)
{
entry->BoxAttrib = character;
}
/*
* This sets the background color of the widget.
*/
void setCDKEntryBackgroundColor (CDKENTRY *entry, char *color)
{
chtype *holder = (chtype *)NULL;
int junk1, junk2;
/* Make sure the color isn't NULL. */
if (color == (char *)NULL)
{
return;
}
/* Convert the value of the environment variable to a chtype. */
holder = char2Chtype (color, &junk1, &junk2);
/* Set the widgets background color. */
wbkgd (entry->win, holder[0]);
wbkgd (entry->fieldWin, holder[0]);
if (entry->labelWin != (WINDOW *)NULL)
{
wbkgd (entry->labelWin, holder[0]);
}
/* Clean up. */
freeChtype (holder);
}
/*
* This sets the entry field callback function.
*/
void setCDKEntryCB (CDKENTRY *entry, ENTRYCB callback)
{
entry->callbackfn = (void *)callback;
}
/*
* This function sets the pre-process function.
*/
void setCDKEntryPreProcess (CDKENTRY *entry, PROCESSFN callback, void *data)
{
entry->preProcessFunction = callback;
entry->preProcessData = data;
}
/*
* This function sets the post-process function.
*/
void setCDKEntryPostProcess (CDKENTRY *entry, PROCESSFN callback, void *data)
{
entry->postProcessFunction = callback;
entry->postProcessData = data;
}
|