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
|
#include <cdk_int.h>
/*
* $Author: tom $
* $Date: 2016/11/20 20:13:16 $
* $Revision: 1.142 $
*/
/*
* Declare file local prototypes.
*/
static void CDKTemplateCallBack (CDKTEMPLATE *widget, chtype input);
static void drawCDKTemplateField (CDKTEMPLATE *widget);
static void adjustCDKTemplateCursor (CDKTEMPLATE *widget, int direction);
#define isPlateChar(c) ((c) != 0 && strchr ("#ACcMXz", c) != 0)
DeclareCDKObjects (TEMPLATE, Template, setCdk, String);
/*
* This creates a cdktemplate widget.
*/
CDKTEMPLATE *newCDKTemplate (CDKSCREEN *cdkscreen,
int xplace,
int yplace,
const char *title,
const char *label,
const char *plate,
const char *Overlay,
boolean Box,
boolean shadow)
{
/* *INDENT-EQLS* */
CDKTEMPLATE *cdktemplate = 0;
int parentWidth = getmaxx (cdkscreen->window);
int parentHeight = getmaxy (cdkscreen->window);
int boxWidth = 0;
int boxHeight = Box ? 3 : 1;
int xpos = xplace;
int ypos = yplace;
int horizontalAdjust, oldWidth;
int fieldWidth = 0;
int plateLen = 0;
int junk = 0;
if (plate == 0
|| (cdktemplate = newCDKObject (CDKTEMPLATE, &my_funcs)) == 0)
return (0);
setCDKTemplateBox (cdktemplate, Box);
fieldWidth = (int)strlen (plate) + 2 * BorderOf (cdktemplate);
/* *INDENT-EQLS* Set some basic values of the cdktemplate field. */
cdktemplate->label = 0;
cdktemplate->labelLen = 0;
cdktemplate->labelWin = 0;
/* Translate the char * label to a chtype * */
if (label != 0)
{
cdktemplate->label = char2Chtype (label, &cdktemplate->labelLen, &junk);
}
/* Translate the char * Overlay to a chtype * */
if (Overlay != 0)
{
cdktemplate->overlay = char2Chtype (Overlay, &cdktemplate->overlayLen, &junk);
cdktemplate->fieldAttr = cdktemplate->overlay[0] & A_ATTRIBUTES;
}
else
{
/* *INDENT-EQLS* */
cdktemplate->overlay = 0;
cdktemplate->overlayLen = 0;
cdktemplate->fieldAttr = A_NORMAL;
}
/* Set the box width. */
boxWidth = fieldWidth + cdktemplate->labelLen + 2 * BorderOf (cdktemplate);
oldWidth = boxWidth;
boxWidth = setCdkTitle (ObjOf (cdktemplate), title, boxWidth);
horizontalAdjust = (boxWidth - oldWidth) / 2;
boxHeight += TitleLinesOf (cdktemplate);
/*
* Make sure we didn't extend beyond the dimensions of the window.
*/
/* *INDENT-EQLS* */
boxWidth = MINIMUM (boxWidth, parentWidth);
boxHeight = MINIMUM (boxHeight, parentHeight);
fieldWidth = MINIMUM (fieldWidth,
boxWidth - cdktemplate->labelLen - 2 * BorderOf (cdktemplate));
/* Rejustify the x and y positions if we need to. */
alignxy (cdkscreen->window, &xpos, &ypos, boxWidth, boxHeight);
/* Make the cdktemplate window */
cdktemplate->win = newwin (boxHeight, boxWidth, ypos, xpos);
/* Is the cdktemplate window null?? */
if (cdktemplate->win == 0)
{
destroyCDKObject (cdktemplate);
return (0);
}
keypad (cdktemplate->win, TRUE);
/* Make the label window. */
if (cdktemplate->label != 0)
{
cdktemplate->labelWin = subwin (cdktemplate->win,
1, cdktemplate->labelLen,
(ypos +
TitleLinesOf (cdktemplate) +
BorderOf (cdktemplate)),
(xpos +
horizontalAdjust +
BorderOf (cdktemplate)));
}
/* Make the field window. */
cdktemplate->fieldWin = subwin (cdktemplate->win,
1, fieldWidth,
(ypos +
TitleLinesOf (cdktemplate) +
BorderOf (cdktemplate)),
(xpos +
cdktemplate->labelLen +
horizontalAdjust +
BorderOf (cdktemplate)));
keypad (cdktemplate->fieldWin, TRUE);
/* Set up the info field. */
cdktemplate->plateLen = (int)strlen (plate);
cdktemplate->info = typeCallocN (char, cdktemplate->plateLen + 2);
if (cdktemplate->info == 0)
{
destroyCDKObject (cdktemplate);
return (0);
}
/* Copy the plate to the cdktemplate. */
plateLen = (int)strlen (plate);
cdktemplate->plate = typeMallocN (char, plateLen + 3);
if (cdktemplate->plate == 0)
{
destroyCDKObject (cdktemplate);
return (0);
}
strcpy (cdktemplate->plate, plate);
/* *INDENT-EQLS* Set up the rest of the structure */
ScreenOf (cdktemplate) = cdkscreen;
cdktemplate->parent = cdkscreen->window;
cdktemplate->shadowWin = 0;
cdktemplate->fieldWidth = fieldWidth;
cdktemplate->boxHeight = boxHeight;
cdktemplate->boxWidth = boxWidth;
cdktemplate->platePos = 0;
cdktemplate->screenPos = 0;
cdktemplate->infoPos = 0;
initExitType (cdktemplate);
cdktemplate->min = 0;
ObjOf (cdktemplate)->inputWindow = cdktemplate->win;
ObjOf (cdktemplate)->acceptsFocus = TRUE;
cdktemplate->shadow = shadow;
cdktemplate->callbackfn = CDKTemplateCallBack;
/* Do we need to create a shadow??? */
if (shadow)
{
cdktemplate->shadowWin = newwin (boxHeight, boxWidth, ypos + 1, xpos + 1);
}
registerCDKObject (cdkscreen, vTEMPLATE, cdktemplate);
return cdktemplate;
}
/*
* This actually manages the cdktemplate widget...
*/
char *activateCDKTemplate (CDKTEMPLATE *cdktemplate, chtype *actions)
{
chtype input = 0;
boolean functionKey;
char *ret = 0;
/* Draw the object. */
drawCDKTemplate (cdktemplate, ObjOf (cdktemplate)->box);
if (actions == 0)
{
for (;;)
{
input = (chtype)getchCDKObject (ObjOf (cdktemplate), &functionKey);
/* Inject the character into the widget. */
ret = injectCDKTemplate (cdktemplate, input);
if (cdktemplate->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 = injectCDKTemplate (cdktemplate, actions[x]);
if (cdktemplate->exitType != vEARLY_EXIT)
{
return ret;
}
}
}
/* Set the exit type and return. */
setExitType (cdktemplate, 0);
return ret;
}
/*
* This injects a character into the widget.
*/
static int _injectCDKTemplate (CDKOBJS *object, chtype input)
{
CDKTEMPLATE *widget = (CDKTEMPLATE *)object;
int ppReturn = 1;
char *ret = unknownString;
bool complete = FALSE;
/* Set the exit type and return. */
setExitType (widget, 0);
/* Move the cursor. */
drawCDKTemplateField (widget);
/* Check if there is a pre-process function to be called. */
if (PreProcessFuncOf (widget) != 0)
{
ppReturn = PreProcessFuncOf (widget) (vTEMPLATE,
widget,
PreProcessDataOf (widget),
input);
}
/* Should we continue? */
if (ppReturn != 0)
{
/* Check a predefined binding... */
if (checkCDKObjectBind (vTEMPLATE, widget, input) != 0)
{
checkEarlyExit (widget);
complete = TRUE;
}
else
{
switch (input)
{
case CDK_ERASE:
if (strlen (widget->info) != 0)
{
cleanCDKTemplate (widget);
drawCDKTemplateField (widget);
}
break;
case CDK_CUT:
if ((int)strlen (widget->info) != 0)
{
freeChar (GPasteBuffer);
GPasteBuffer = copyChar (widget->info);
cleanCDKTemplate (widget);
drawCDKTemplateField (widget);
}
else
{
Beep ();
}
break;
case CDK_COPY:
if ((int)strlen (widget->info) != 0)
{
freeChar (GPasteBuffer);
GPasteBuffer = copyChar (widget->info);
}
else
{
Beep ();
}
break;
case CDK_PASTE:
if (GPasteBuffer != 0)
{
int length, x;
cleanCDKTemplate (widget);
/* Start inserting each character one at a time. */
length = (int)strlen (GPasteBuffer);
for (x = 0; x < length; x++)
{
(widget->callbackfn) (widget, (chtype)GPasteBuffer[x]);
}
drawCDKTemplateField (widget);
}
else
{
Beep ();
}
break;
case KEY_TAB:
case KEY_ENTER:
if ((int)strlen (widget->info) < (int)widget->min)
{
Beep ();
}
else
{
setExitType (widget, input);
ret = widget->info;
complete = TRUE;
}
break;
case KEY_ESC:
setExitType (widget, input);
complete = TRUE;
break;
case KEY_ERROR:
setExitType (widget, input);
complete = TRUE;
break;
case CDK_REFRESH:
eraseCDKScreen (ScreenOf (widget));
refreshCDKScreen (ScreenOf (widget));
break;
default:
(widget->callbackfn) (widget, input);
break;
}
}
/* Should we call a post-process? */
if (!complete && (PostProcessFuncOf (widget) != 0))
{
PostProcessFuncOf (widget) (vTEMPLATE,
widget,
PostProcessDataOf (widget),
input);
}
}
if (!complete)
{
setExitType (widget, 0);
}
ResultOf (widget).valueString = ret;
return (ret != unknownString);
}
/*
* Return true if the given string matches the template (may be incomplete).
*/
static boolean validTemplate (CDKTEMPLATE *cdktemplate, char *input)
{
int pp, ip;
const char *plate = cdktemplate->plate;
for (pp = 0, ip = 0; input[ip] != '\0' && plate[pp] != '\0'; ++ip, ++pp)
{
int newchar = input[ip];
while (plate[pp] != '\0' && !isPlateChar (plate[pp]))
{
++pp;
}
if (plate[pp] == 0)
{
return FALSE;
}
/* check if the input matches the plate */
if (isdigit (CharOf (newchar)) &&
(plate[pp] == 'A' ||
plate[pp] == 'C' ||
plate[pp] == 'c'))
{
return FALSE;
}
if (!isdigit (CharOf (newchar)) &&
plate[pp] == '#')
{
return FALSE;
}
/* Do we need to convert the case??? */
if (plate[pp] == 'C' ||
plate[pp] == 'X')
{
newchar = toupper (newchar);
}
else if (plate[pp] == 'c' ||
plate[pp] == 'x')
{
newchar = tolower (newchar);
}
input[ip] = (char)newchar;
}
return TRUE;
}
/*
* This is the standard callback proc for the cdktemplate.
*/
static void CDKTemplateCallBack (CDKTEMPLATE *cdktemplate, chtype input)
{
boolean failed = FALSE;
boolean change = FALSE;
boolean moveby = FALSE;
int amount = 0;
size_t mark = (size_t) cdktemplate->infoPos;
size_t have = strlen (cdktemplate->info);
if (input == KEY_LEFT)
{
if (mark != 0)
{
moveby = TRUE;
amount = -1;
}
else
{
failed = TRUE;
}
}
else if (input == KEY_RIGHT)
{
if (cdktemplate->info[mark] != '\0')
{
moveby = TRUE;
amount = 1;
}
else
{
failed = TRUE;
}
}
else
{
char *test = (char *)malloc (have + 2);
if (test != 0)
{
strcpy (test, cdktemplate->info);
if (input == KEY_BACKSPACE)
{
if (mark != 0)
{
strcpy (test + mark - 1, cdktemplate->info + mark);
change = TRUE;
amount = -1;
}
else
{
failed = TRUE;
}
}
else if (input == KEY_DC)
{
if (test[mark] != '\0')
{
strcpy (test + mark, cdktemplate->info + mark + 1);
change = TRUE;
amount = 0;
}
else
{
failed = TRUE;
}
}
else if (isChar (input) &&
cdktemplate->platePos < cdktemplate->fieldWidth)
{
test[mark] = (char)(input);
strcpy (test + mark + 1, cdktemplate->info + mark + 1);
change = TRUE;
amount = 1;
}
else
{
failed = TRUE;
}
if (change)
{
if (validTemplate (cdktemplate, test))
{
strcpy (cdktemplate->info, test);
drawCDKTemplateField (cdktemplate);
}
else
{
failed = TRUE;
}
}
free (test);
}
}
if (failed)
{
Beep ();
}
else if (change || moveby)
{
cdktemplate->infoPos += amount;
cdktemplate->platePos += amount;
cdktemplate->screenPos += amount;
adjustCDKTemplateCursor (cdktemplate, amount);
}
}
/*
* Return a mixture of the plate-overlay and field-info.
*/
char *mixCDKTemplate (CDKTEMPLATE *cdktemplate)
{
char *mixedString = 0;
if (cdktemplate->info != 0 && cdktemplate->info[0] != '\0')
{
mixedString = typeCallocN (char, cdktemplate->plateLen + 3);
if (mixedString != 0)
{
int infoPos = 0;
int platePos = 0;
while (platePos < cdktemplate->plateLen)
{
mixedString[platePos] = (char)(isPlateChar (cdktemplate->plate[platePos])
? cdktemplate->info[infoPos++]
: cdktemplate->plate[platePos]);
platePos++;
}
}
}
return mixedString;
}
/*
* Return the field-info from the mixed string.
*/
char *unmixCDKTemplate (CDKTEMPLATE *cdktemplate, const char *info)
{
/* *INDENT-EQLS* */
int infolen = (int)strlen (info);
char *unmixedString = typeCallocN (char, infolen + 2);
if (unmixedString != 0)
{
int pos = 0;
int x = 0;
while (pos < infolen)
{
if (isPlateChar (cdktemplate->plate[pos]))
{
unmixedString[x++] = info[pos++];
}
else
{
pos++;
}
}
}
return unmixedString;
}
/*
* Move the cdktemplate field to the given location.
*/
static void _moveCDKTemplate (CDKOBJS *object,
int xplace,
int yplace,
boolean relative,
boolean refresh_flag)
{
CDKTEMPLATE *cdktemplate = (CDKTEMPLATE *)object;
/* *INDENT-EQLS* */
int currentX = getbegx (cdktemplate->win);
int currentY = getbegy (cdktemplate->win);
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 = getbegx (cdktemplate->win) + xplace;
ypos = getbegy (cdktemplate->win) + yplace;
}
/* Adjust the window if we need to. */
alignxy (WindowOf (cdktemplate), &xpos, &ypos, cdktemplate->boxWidth, cdktemplate->boxHeight);
/* Get the difference. */
xdiff = currentX - xpos;
ydiff = currentY - ypos;
/* Move the window to the new location. */
moveCursesWindow (cdktemplate->win, -xdiff, -ydiff);
moveCursesWindow (cdktemplate->labelWin, -xdiff, -ydiff);
moveCursesWindow (cdktemplate->fieldWin, -xdiff, -ydiff);
moveCursesWindow (cdktemplate->shadowWin, -xdiff, -ydiff);
/* Touch the windows so they 'move'. */
refreshCDKWindow (WindowOf (cdktemplate));
/* Redraw the window, if they asked for it. */
if (refresh_flag)
{
drawCDKTemplate (cdktemplate, ObjOf (cdktemplate)->box);
}
}
/*
* Draw the template widget.
*/
static void _drawCDKTemplate (CDKOBJS *object, boolean Box)
{
CDKTEMPLATE *cdktemplate = (CDKTEMPLATE *)object;
/* Do we need to draw the shadow. */
if (cdktemplate->shadowWin != 0)
{
drawShadow (cdktemplate->shadowWin);
}
/* Box it if needed */
if (Box)
{
drawObjBox (cdktemplate->win, ObjOf (cdktemplate));
}
drawCdkTitle (cdktemplate->win, object);
wrefresh (cdktemplate->win);
drawCDKTemplateField (cdktemplate);
}
/*
* Draw the cdktemplate field.
*/
static void drawCDKTemplateField (CDKTEMPLATE *cdktemplate)
{
/* *INDENT-EQLS* */
chtype fieldColor = 0;
int infolen = (int)strlen (cdktemplate->info);
/* Draw in the label and the cdktemplate object. */
if (cdktemplate->labelWin != 0)
{
writeChtype (cdktemplate->labelWin, 0, 0,
cdktemplate->label,
HORIZONTAL, 0,
cdktemplate->labelLen);
wrefresh (cdktemplate->labelWin);
}
/* Draw in the cdktemplate... */
if (cdktemplate->overlay != 0)
{
writeChtype (cdktemplate->fieldWin, 0, 0,
cdktemplate->overlay,
HORIZONTAL, 0,
cdktemplate->overlayLen);
/* Adjust the cursor. */
if (infolen != 0)
{
int pos = 0;
int x = 0;
for (x = 0; x < cdktemplate->fieldWidth; x++)
{
if (isPlateChar (cdktemplate->plate[x]) && pos < infolen)
{
fieldColor = cdktemplate->overlay[x] & A_ATTRIBUTES;
(void)mvwaddch (cdktemplate->fieldWin,
0, x,
CharOf (cdktemplate->info[pos++]) | fieldColor);
}
}
wmove (cdktemplate->fieldWin, 0, cdktemplate->screenPos);
}
else
{
adjustCDKTemplateCursor (cdktemplate, +1);
}
wrefresh (cdktemplate->fieldWin);
}
}
/*
* Adjust the cursor for the cdktemplate.
*/
static void adjustCDKTemplateCursor (CDKTEMPLATE *cdktemplate, int direction)
{
while (!isPlateChar (cdktemplate->plate[cdktemplate->platePos])
&& cdktemplate->platePos < cdktemplate->fieldWidth)
{
cdktemplate->platePos += direction;
cdktemplate->screenPos += direction;
}
wmove (cdktemplate->fieldWin, 0, cdktemplate->screenPos);
wrefresh (cdktemplate->fieldWin);
}
/*
* Set the background attribute of the widget.
*/
static void _setBKattrTemplate (CDKOBJS *object, chtype attrib)
{
if (object != 0)
{
CDKTEMPLATE *widget = (CDKTEMPLATE *)object;
wbkgd (widget->win, attrib);
wbkgd (widget->fieldWin, attrib);
if (widget->labelWin != 0)
{
wbkgd (widget->labelWin, attrib);
}
}
}
/*
* Destroy this widget.
*/
static void _destroyCDKTemplate (CDKOBJS *object)
{
if (object != 0)
{
CDKTEMPLATE *cdktemplate = (CDKTEMPLATE *)object;
cleanCdkTitle (object);
freeChtype (cdktemplate->label);
freeChtype (cdktemplate->overlay);
freeChar (cdktemplate->plate);
freeChar (cdktemplate->info);
/* Delete the windows. */
deleteCursesWindow (cdktemplate->fieldWin);
deleteCursesWindow (cdktemplate->labelWin);
deleteCursesWindow (cdktemplate->shadowWin);
deleteCursesWindow (cdktemplate->win);
/* Clean the key bindings. */
cleanCDKObjectBindings (vTEMPLATE, cdktemplate);
unregisterCDKObject (vTEMPLATE, cdktemplate);
}
}
/*
* Erase the widget.
*/
static void _eraseCDKTemplate (CDKOBJS *object)
{
if (validCDKObject (object))
{
CDKTEMPLATE *cdktemplate = (CDKTEMPLATE *)object;
eraseCursesWindow (cdktemplate->fieldWin);
eraseCursesWindow (cdktemplate->labelWin);
eraseCursesWindow (cdktemplate->win);
eraseCursesWindow (cdktemplate->shadowWin);
}
}
/*
* Set the value given to the cdktemplate.
*/
void setCDKTemplate (CDKTEMPLATE *cdktemplate, const char *newValue, boolean Box)
{
setCDKTemplateValue (cdktemplate, newValue);
setCDKTemplateBox (cdktemplate, Box);
}
/*
* Set the value given to the cdktemplate.
*/
void setCDKTemplateValue (CDKTEMPLATE *cdktemplate, const char *newValue)
{
/* *INDENT-EQLS* */
int len = 0;
int copychars = 0;
int x;
cleanCDKTemplate (cdktemplate);
/* Just to be sure, if let's make sure the new value isn't null. */
if (newValue == 0)
{
return;
}
/* Determine how many characters we need to copy. */
len = (int)strlen (newValue);
copychars = MINIMUM (len, cdktemplate->fieldWidth);
/* OK, erase the old value, and copy in the new value. */
cdktemplate->info[0] = '\0';
strncpy (cdktemplate->info, newValue, (size_t) copychars);
/* Use the function which handles the input of the characters. */
for (x = 0; x < len; x++)
{
(cdktemplate->callbackfn) (cdktemplate, (chtype)newValue[x]);
}
}
char *getCDKTemplateValue (CDKTEMPLATE *cdktemplate)
{
return cdktemplate->info;
}
/*
* Set the minimum number of characters to enter into the widget.
*/
void setCDKTemplateMin (CDKTEMPLATE *cdktemplate, int min)
{
if (min >= 0)
{
cdktemplate->min = min;
}
}
int getCDKTemplateMin (CDKTEMPLATE *cdktemplate)
{
return cdktemplate->min;
}
/*
* Set the box attribute of the cdktemplate widget.
*/
void setCDKTemplateBox (CDKTEMPLATE *cdktemplate, boolean Box)
{
ObjOf (cdktemplate)->box = Box;
ObjOf (cdktemplate)->borderSize = Box ? 1 : 0;
}
boolean getCDKTemplateBox (CDKTEMPLATE *cdktemplate)
{
return ObjOf (cdktemplate)->box;
}
/*
* Erase the information in the cdktemplate widget.
*/
void cleanCDKTemplate (CDKTEMPLATE *cdktemplate)
{
if (cdktemplate->fieldWidth > 0)
memset (cdktemplate->info, 0, (size_t) cdktemplate->fieldWidth);
/* *INDENT-EQLS* */
cdktemplate->screenPos = 0;
cdktemplate->infoPos = 0;
cdktemplate->platePos = 0;
}
/*
* Set the callback function for the widget.
*/
void setCDKTemplateCB (CDKTEMPLATE *cdktemplate, TEMPLATECB callback)
{
cdktemplate->callbackfn = callback;
}
static void _focusCDKTemplate (CDKOBJS *object)
{
CDKTEMPLATE *widget = (CDKTEMPLATE *)object;
drawCDKTemplate (widget, ObjOf (widget)->box);
}
static void _unfocusCDKTemplate (CDKOBJS *object)
{
CDKTEMPLATE *widget = (CDKTEMPLATE *)object;
drawCDKTemplate (widget, ObjOf (widget)->box);
}
dummyRefreshData (Template)
dummySaveData (Template)
|