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
|
#include <cdk_int.h>
/*
* $Author: tom $
* $Date: 2016/11/20 18:39:12 $
* $Revision: 1.111 $
*/
/*
* Declare file local prototypes.
*/
static BINDFN_PROTO (adjustAlphalistCB);
static BINDFN_PROTO (completeWordCB);
static int preProcessEntryField (EObjectType, void *, void *, chtype);
static int createList (CDKALPHALIST *alphalist, CDK_CSTRING *list, int listSize);
DeclareSetXXchar (static, _setMy);
DeclareCDKObjects (ALPHALIST, Alphalist, _setMy, String);
/*
* This creates the alphalist widget.
*/
CDKALPHALIST *newCDKAlphalist (CDKSCREEN *cdkscreen,
int xplace,
int yplace,
int height,
int width,
const char *title,
const char *label,
CDK_CSTRING *list,
int listSize,
chtype fillerChar,
chtype highlight,
boolean Box,
boolean shadow)
{
/* *INDENT-EQLS* */
CDKALPHALIST *alphalist = 0;
int parentWidth = getmaxx (cdkscreen->window);
int parentHeight = getmaxy (cdkscreen->window);
int boxWidth;
int boxHeight;
int xpos = xplace;
int ypos = yplace;
int tempWidth = 0;
int tempHeight = 0;
int labelLen = 0;
int x, junk2;
/* *INDENT-OFF* */
static const struct { int from; int to; } bindings[] = {
{ CDK_BACKCHAR, KEY_PPAGE },
{ CDK_FORCHAR, KEY_NPAGE },
};
/* *INDENT-ON* */
if ((alphalist = newCDKObject (CDKALPHALIST, &my_funcs)) == 0
|| !createList (alphalist, list, listSize))
{
destroyCDKObject (alphalist);
return (0);
}
setCDKAlphalistBox (alphalist, Box);
/*
* If the height is a negative value, the height will
* be ROWS-height, otherwise, the height will be the
* given height.
*/
boxHeight = setWidgetDimension (parentHeight, height, 0);
/*
* If the width is a negative value, the width will
* be COLS-width, otherwise, the width will be the
* given width.
*/
boxWidth = setWidgetDimension (parentWidth, width, 0);
/* Translate the label char *pointer to a chtype pointer. */
if (label != 0)
{
chtype *chtypeLabel = char2Chtype (label, &labelLen, &junk2);
freeChtype (chtypeLabel);
}
/* Rejustify the x and y positions if we need to. */
alignxy (cdkscreen->window, &xpos, &ypos, boxWidth, boxHeight);
/* Make the file selector window. */
alphalist->win = newwin (boxHeight, boxWidth, ypos, xpos);
if (alphalist->win == 0)
{
destroyCDKObject (alphalist);
return (0);
}
keypad (alphalist->win, TRUE);
/* *INDENT-EQLS* Set some variables. */
ScreenOf (alphalist) = cdkscreen;
alphalist->parent = cdkscreen->window;
alphalist->highlight = highlight;
alphalist->fillerChar = fillerChar;
alphalist->boxHeight = boxHeight;
alphalist->boxWidth = boxWidth;
initExitType (alphalist);
alphalist->shadow = shadow;
alphalist->shadowWin = 0;
/* Do we want a shadow? */
if (shadow)
{
alphalist->shadowWin = newwin (boxHeight, boxWidth, ypos + 1, xpos + 1);
}
/* Create the entry field. */
tempWidth = (isFullWidth (width)
? FULL
: boxWidth - 2 - labelLen);
alphalist->entryField = newCDKEntry (cdkscreen,
getbegx (alphalist->win),
getbegy (alphalist->win),
title, label,
A_NORMAL, fillerChar,
vMIXED, tempWidth, 0, 512,
Box, FALSE);
if (alphalist->entryField == 0)
{
destroyCDKObject (alphalist);
return (0);
}
setCDKEntryLLChar (alphalist->entryField, ACS_LTEE);
setCDKEntryLRChar (alphalist->entryField, ACS_RTEE);
/* Set the key bindings for the entry field. */
bindCDKObject (vENTRY,
alphalist->entryField,
KEY_UP,
adjustAlphalistCB,
alphalist);
bindCDKObject (vENTRY,
alphalist->entryField,
KEY_DOWN,
adjustAlphalistCB,
alphalist);
bindCDKObject (vENTRY,
alphalist->entryField,
KEY_NPAGE,
adjustAlphalistCB,
alphalist);
bindCDKObject (vENTRY,
alphalist->entryField,
KEY_PPAGE,
adjustAlphalistCB,
alphalist);
bindCDKObject (vENTRY,
alphalist->entryField,
KEY_TAB,
completeWordCB,
alphalist);
/* Set up the post-process function for the entry field. */
setCDKEntryPreProcess (alphalist->entryField, preProcessEntryField, alphalist);
/*
* Create the scrolling list. It overlaps the entry field by one line if
* we are using box-borders.
*/
tempHeight = getmaxy (alphalist->entryField->win) - BorderOf (alphalist);
tempWidth = (isFullWidth (width)
? FULL
: boxWidth - 1);
alphalist->scrollField = newCDKScroll (cdkscreen,
getbegx (alphalist->win),
getbegy (alphalist->entryField->win)
+ tempHeight,
RIGHT,
boxHeight - tempHeight,
tempWidth,
0, (CDK_CSTRING2)list, listSize,
NONUMBERS, A_REVERSE,
Box, FALSE);
setCDKScrollULChar (alphalist->scrollField, ACS_LTEE);
setCDKScrollURChar (alphalist->scrollField, ACS_RTEE);
/* Setup the key bindings. */
for (x = 0; x < (int)SIZEOF (bindings); ++x)
bindCDKObject (vALPHALIST,
alphalist,
(chtype)bindings[x].from,
getcCDKBind,
(void *)(long)bindings[x].to);
registerCDKObject (cdkscreen, vALPHALIST, alphalist);
return (alphalist);
}
/*
* This erases the file selector from the screen.
*/
static void _eraseCDKAlphalist (CDKOBJS *object)
{
if (validCDKObject (object))
{
CDKALPHALIST *alphalist = (CDKALPHALIST *)object;
eraseCDKScroll (alphalist->scrollField);
eraseCDKEntry (alphalist->entryField);
eraseCursesWindow (alphalist->shadowWin);
eraseCursesWindow (alphalist->win);
}
}
/*
* This moves the alphalist field to the given location.
*/
static void _moveCDKAlphalist (CDKOBJS *object,
int xplace,
int yplace,
boolean relative,
boolean refresh_flag)
{
CDKALPHALIST *alphalist = (CDKALPHALIST *)object;
/* *INDENT-EQLS* */
int currentX = getbegx (alphalist->win);
int currentY = getbegy (alphalist->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 (alphalist->win) + xplace;
ypos = getbegy (alphalist->win) + yplace;
}
/* Adjust the window if we need to. */
alignxy (WindowOf (alphalist), &xpos, &ypos, alphalist->boxWidth, alphalist->boxHeight);
/* Get the difference. */
xdiff = currentX - xpos;
ydiff = currentY - ypos;
/* Move the window to the new location. */
moveCursesWindow (alphalist->win, -xdiff, -ydiff);
moveCursesWindow (alphalist->shadowWin, -xdiff, -ydiff);
/* Move the sub-widgets. */
moveCDKEntry (alphalist->entryField, xplace, yplace, relative, FALSE);
moveCDKScroll (alphalist->scrollField, xplace, yplace, relative, FALSE);
/* Touch the windows so they 'move'. */
refreshCDKWindow (WindowOf (alphalist));
/* Redraw the window, if they asked for it. */
if (refresh_flag)
{
drawCDKAlphalist (alphalist, ObjOf (alphalist)->box);
}
}
/*
* The alphalist's focus resides in the entry widget. But the scroll widget
* will not draw items highlighted unless it has focus. Temporarily adjust the
* focus of the scroll widget when drawing on it to get the right highlighting.
*/
#define SaveFocus(widget) \
boolean save = HasFocusObj (ObjOf (widget->scrollField)); \
HasFocusObj (ObjOf (widget->scrollField)) = \
HasFocusObj (ObjOf (widget->entryField))
#define RestoreFocus(widget) \
HasFocusObj (ObjOf (widget->scrollField)) = save
static void drawMyScroller (CDKALPHALIST *widget)
{
SaveFocus (widget);
drawCDKScroll (widget->scrollField, ObjOf (widget->scrollField)->box);
RestoreFocus (widget);
}
static void injectMyScroller (CDKALPHALIST *widget, chtype key)
{
SaveFocus (widget);
(void)injectCDKScroll (widget->scrollField, key);
RestoreFocus (widget);
}
/*
* This draws the file selector widget.
*/
static void _drawCDKAlphalist (CDKOBJS *obj, boolean Box GCC_UNUSED)
{
CDKALPHALIST *alphalist = (CDKALPHALIST *)obj;
/* Does this widget have a shadow? */
if (alphalist->shadowWin != 0)
{
drawShadow (alphalist->shadowWin);
}
/* Draw in the entry field. */
drawCDKEntry (alphalist->entryField, ObjOf (alphalist->entryField)->box);
/* Draw in the scroll field. */
drawMyScroller (alphalist);
}
/*
* This activates the file selector.
*/
char *activateCDKAlphalist (CDKALPHALIST *alphalist, chtype *actions)
{
char *ret = 0;
/* Draw the widget. */
drawCDKAlphalist (alphalist, ObjOf (alphalist)->box);
/* Activate the widget. */
ret = activateCDKEntry (alphalist->entryField, actions);
/* Copy the exit type from the entry field. */
copyExitType (alphalist, alphalist->entryField);
/* Determine the exit status. */
if (alphalist->exitType != vEARLY_EXIT)
{
return ret;
}
return 0;
}
/*
* This injects a single character into the alphalist.
*/
static int _injectCDKAlphalist (CDKOBJS *object, chtype input)
{
CDKALPHALIST *alphalist = (CDKALPHALIST *)object;
char *ret;
/* Draw the widget. */
drawCDKAlphalist (alphalist, ObjOf (alphalist)->box);
/* Inject a character into the widget. */
ret = injectCDKEntry (alphalist->entryField, input);
/* Copy the exit type from the entry field. */
copyExitType (alphalist, alphalist->entryField);
/* Determine the exit status. */
if (alphalist->exitType == vEARLY_EXIT)
ret = unknownString;
ResultOf (alphalist).valueString = ret;
return (ret != unknownString);
}
/*
* This sets multiple attributes of the widget.
*/
void setCDKAlphalist (CDKALPHALIST *alphalist,
CDK_CSTRING *list,
int listSize,
chtype fillerChar,
chtype highlight,
boolean Box)
{
setCDKAlphalistContents (alphalist, list, listSize);
setCDKAlphalistFillerChar (alphalist, fillerChar);
setCDKAlphalistHighlight (alphalist, highlight);
setCDKAlphalistBox (alphalist, Box);
}
/*
* This function sets the information inside the file selector.
*/
void setCDKAlphalistContents (CDKALPHALIST *widget, CDK_CSTRING *list, int listSize)
{
CDKSCROLL *scrollp = widget->scrollField;
CDKENTRY *entry = widget->entryField;
if (!createList (widget, list, listSize))
return;
/* Set the information in the scrolling list. */
setCDKScroll (scrollp,
(CDK_CSTRING2)widget->list,
widget->listSize,
NONUMBERS,
scrollp->highlight,
ObjOf (scrollp)->box);
/* Clean out the entry field. */
setCDKAlphalistCurrentItem (widget, 0);
cleanCDKEntry (entry);
/* Redraw the widget. */
eraseCDKAlphalist (widget);
drawCDKAlphalist (widget, ObjOf (widget)->box);
}
/*
* This returns the contents of the widget.
*/
char **getCDKAlphalistContents (CDKALPHALIST *widget, int *size)
{
(*size) = widget->listSize;
return widget->list;
}
/*
* Get/set the current position in the scroll-widget.
*/
int getCDKAlphalistCurrentItem (CDKALPHALIST *widget)
{
return getCDKScrollCurrent (widget->scrollField);
}
void setCDKAlphalistCurrentItem (CDKALPHALIST *widget, int item)
{
if (widget->listSize != 0)
{
setCDKScrollCurrent (widget->scrollField, item);
setCDKEntryValue (widget->entryField,
widget->list[getCDKScrollCurrentItem (widget->scrollField)]);
}
}
/*
* This sets the filler character of the entry field of the alphalist.
*/
void setCDKAlphalistFillerChar (CDKALPHALIST *alphalist, chtype fillerCharacter)
{
CDKENTRY *entry = (CDKENTRY *)alphalist->entryField;
alphalist->fillerChar = fillerCharacter;
setCDKEntryFillerChar (entry, fillerCharacter);
}
chtype getCDKAlphalistFillerChar (CDKALPHALIST *alphalist)
{
return alphalist->fillerChar;
}
/*
* This sets the highlight bar attributes.
*/
void setCDKAlphalistHighlight (CDKALPHALIST *alphalist, chtype highlight)
{
alphalist->highlight = highlight;
}
chtype getCDKAlphalistHighlight (CDKALPHALIST *alphalist)
{
return alphalist->highlight;
}
/*
* This sets whether or not the widget will be drawn with a box.
*/
void setCDKAlphalistBox (CDKALPHALIST *alphalist, boolean Box)
{
ObjOf (alphalist)->box = Box;
ObjOf (alphalist)->borderSize = Box ? 1 : 0;
}
boolean getCDKAlphalistBox (CDKALPHALIST *alphalist)
{
return ObjOf (alphalist)->box;
}
/*
* These functions set the drawing characters of the widget.
*/
static void _setMyULchar (CDKOBJS *object, chtype character)
{
CDKALPHALIST *alphalist = (CDKALPHALIST *)object;
setCDKEntryULChar (alphalist->entryField, character);
}
static void _setMyURchar (CDKOBJS *object, chtype character)
{
CDKALPHALIST *alphalist = (CDKALPHALIST *)object;
setCDKEntryURChar (alphalist->entryField, character);
}
static void _setMyLLchar (CDKOBJS *object, chtype character)
{
CDKALPHALIST *alphalist = (CDKALPHALIST *)object;
setCDKScrollLLChar (alphalist->scrollField, character);
}
static void _setMyLRchar (CDKOBJS *object, chtype character)
{
CDKALPHALIST *alphalist = (CDKALPHALIST *)object;
setCDKScrollLRChar (alphalist->scrollField, character);
}
static void _setMyVTchar (CDKOBJS *object, chtype character)
{
CDKALPHALIST *alphalist = (CDKALPHALIST *)object;
setCDKEntryVerticalChar (alphalist->entryField, character);
setCDKScrollVerticalChar (alphalist->scrollField, character);
}
static void _setMyHZchar (CDKOBJS *object, chtype character)
{
CDKALPHALIST *alphalist = (CDKALPHALIST *)object;
setCDKEntryHorizontalChar (alphalist->entryField, character);
setCDKScrollHorizontalChar (alphalist->scrollField, character);
}
static void _setMyBXattr (CDKOBJS *object, chtype character)
{
CDKALPHALIST *alphalist = (CDKALPHALIST *)object;
setCDKEntryBoxAttribute (alphalist->entryField, character);
setCDKScrollBoxAttribute (alphalist->scrollField, character);
}
/*
* This sets the background attribute of the widget.
*/
static void _setBKattrAlphalist (CDKOBJS *obj, chtype attrib)
{
CDKALPHALIST *alphalist = (CDKALPHALIST *)obj;
setCDKEntryBackgroundAttrib (alphalist->entryField, attrib);
setCDKScrollBackgroundAttrib (alphalist->scrollField, attrib);
}
static void destroyInfo (CDKALPHALIST *widget)
{
CDKfreeStrings (widget->list);
widget->list = 0;
widget->listSize = 0;
}
/*
* This destroys the file selector.
*/
static void _destroyCDKAlphalist (CDKOBJS *object)
{
if (object != 0)
{
CDKALPHALIST *alphalist = (CDKALPHALIST *)object;
destroyInfo (alphalist);
/* Clean the key bindings. */
cleanCDKObjectBindings (vALPHALIST, alphalist);
destroyCDKEntry (alphalist->entryField);
destroyCDKScroll (alphalist->scrollField);
/* Free up the window pointers. */
deleteCursesWindow (alphalist->shadowWin);
deleteCursesWindow (alphalist->win);
/* Unregister the object. */
unregisterCDKObject (vALPHALIST, alphalist);
}
}
/*
* This function sets the pre-process function.
*/
void setCDKAlphalistPreProcess (CDKALPHALIST *alphalist,
PROCESSFN callback,
void *data)
{
setCDKEntryPreProcess (alphalist->entryField, callback, data);
}
/*
* This function sets the post-process function.
*/
void setCDKAlphalistPostProcess (CDKALPHALIST *alphalist,
PROCESSFN callback,
void *data)
{
setCDKEntryPostProcess (alphalist->entryField, callback, data);
}
/*
* Start of callback functions.
*/
static int adjustAlphalistCB (EObjectType objectType GCC_UNUSED, void
*object GCC_UNUSED,
void *clientData,
chtype key)
{
/* *INDENT-EQLS* */
CDKALPHALIST *alphalist = (CDKALPHALIST *)clientData;
CDKSCROLL *scrollp = alphalist->scrollField;
CDKENTRY *entry = alphalist->entryField;
if (scrollp->listSize > 0)
{
char *current;
/* Adjust the scrolling list. */
injectMyScroller (alphalist, key);
/* Set the value in the entry field. */
current = chtype2Char (scrollp->item[scrollp->currentItem]);
setCDKEntryValue (entry, current);
drawCDKEntry (entry, ObjOf (entry)->box);
freeChar (current);
return (TRUE);
}
Beep ();
return (FALSE);
}
/*
* This is the heart-beat of the widget.
*/
static int preProcessEntryField (EObjectType cdktype GCC_UNUSED, void
*object GCC_UNUSED,
void *clientData,
chtype input)
{
/* *INDENT-EQLS* */
CDKALPHALIST *alphalist = (CDKALPHALIST *)clientData;
CDKSCROLL *scrollp = alphalist->scrollField;
CDKENTRY *entry = alphalist->entryField;
int infoLen = ((entry->info != 0)
? (int)strlen (entry->info)
: 0);
int result = 1;
bool empty = FALSE;
/* Make sure the entry field isn't empty. */
if (entry->info == 0)
{
empty = TRUE;
}
else if (isCDKObjectBind (ObjTypeOf (alphalist), ObjOf (alphalist), input))
{
result = 1; /* don't try to use this key in editing */
}
else if ((isChar (input) &&
(isalnum (CharOf (input)) ||
ispunct (input))) ||
input == KEY_BACKSPACE ||
input == KEY_DC)
{
int Index, difference, absoluteDifference, x;
int currPos = (entry->screenCol + entry->leftChar);
char *pattern = (char *)malloc ((size_t) infoLen + 2);
if (pattern != 0)
{
strcpy (pattern, entry->info);
if (input == KEY_BACKSPACE || input == KEY_DC)
{
if (input == KEY_BACKSPACE)
--currPos;
if (currPos >= 0)
strcpy (pattern + currPos, entry->info + currPos + 1);
}
else
{
pattern[currPos] = (char)input;
strcpy (pattern + currPos + 1, entry->info + currPos);
}
}
if (pattern == 0)
{
Beep ();
}
else if (strlen (pattern) == 0)
{
empty = TRUE;
}
else if ((Index = searchList ((CDK_CSTRING2)alphalist->list,
alphalist->listSize,
pattern)) >= 0)
{
/* *INDENT-EQLS* */
difference = Index - scrollp->currentItem;
absoluteDifference = abs (difference);
/*
* If the difference is less than zero, then move up.
* Otherwise move down.
*
* If the difference is greater than 10 jump to the new
* index position. Otherwise provide the nice scroll.
*/
if (absoluteDifference <= 10)
{
for (x = 0; x < absoluteDifference; x++)
{
injectMyScroller (alphalist,
(chtype)((difference <= 0)
? KEY_UP
: KEY_DOWN));
}
}
else
{
setCDKScrollPosition (scrollp, Index);
}
drawMyScroller (alphalist);
}
else
{
Beep ();
result = 0;
}
if (pattern != 0)
free (pattern);
}
if (empty)
{
setCDKScrollPosition (scrollp, 0);
drawMyScroller (alphalist);
}
return result;
}
/*
* This tries to complete the word in the entry field.
*/
static int completeWordCB (EObjectType objectType GCC_UNUSED, void *object GCC_UNUSED,
void *clientData,
chtype key GCC_UNUSED)
{
/* *INDENT-EQLS* */
CDKALPHALIST *alphalist = (CDKALPHALIST *)clientData;
CDKENTRY *entry = (CDKENTRY *)alphalist->entryField;
CDKSCROLL *scrollp = 0;
int wordLength = 0;
int Index = 0;
int ret = 0;
char **altWords = 0;
if (entry->info == 0)
{
Beep ();
return (TRUE);
}
wordLength = (int)strlen (entry->info);
/* If the word length is equal to zero, just leave. */
if (wordLength == 0)
{
Beep ();
return (TRUE);
}
/* Look for a unique word match. */
Index = searchList ((CDK_CSTRING2)alphalist->list, alphalist->listSize, entry->info);
/* If the index is less than zero, return we didn't find a match. */
if (Index < 0)
{
Beep ();
return (TRUE);
}
/* Did we find the last word in the list? */
if (Index == alphalist->listSize - 1)
{
setCDKEntryValue (entry, alphalist->list[Index]);
drawCDKEntry (entry, ObjOf (entry)->box);
return (TRUE);
}
/* Ok, we found a match, is the next item similar? */
ret = strncmp (alphalist->list[Index + 1], entry->info, (size_t) wordLength);
if (ret == 0)
{
int currentIndex = Index;
int altCount = 0;
unsigned used = 0;
int selected;
int height;
int match;
int x;
/* Start looking for alternate words. */
/* FIXME: bsearch would be more suitable */
while ((currentIndex < alphalist->listSize)
&& (strncmp (alphalist->list[currentIndex],
entry->info,
(size_t) wordLength) == 0))
{
used = CDKallocStrings (&altWords,
alphalist->list[currentIndex++],
(unsigned)altCount++,
used);
}
/* Determine the height of the scrolling list. */
height = (altCount < 8 ? altCount + 3 : 11);
/* Create a scrolling list of close matches. */
scrollp = newCDKScroll (entry->obj.screen,
CENTER, CENTER, RIGHT, height, -30,
"<C></B/5>Possible Matches.",
(CDK_CSTRING2)altWords, altCount,
NUMBERS, A_REVERSE, TRUE, FALSE);
/* Allow them to select a close match. */
match = activateCDKScroll (scrollp, 0);
selected = scrollp->currentItem;
/* Check how they exited the list. */
if (scrollp->exitType == vESCAPE_HIT)
{
/* Destroy the scrolling list. */
destroyCDKScroll (scrollp);
/* Clean up. */
CDKfreeStrings (altWords);
/* Beep at the user. */
Beep ();
/* Redraw the alphalist and return. */
drawCDKAlphalist (alphalist, ObjOf (alphalist)->box);
return (TRUE);
}
/* Destroy the scrolling list. */
destroyCDKScroll (scrollp);
/* Set the entry field to the selected value. */
setCDKEntry (entry,
altWords[match],
entry->min,
entry->max,
ObjOf (entry)->box);
/* Move the highlight bar down to the selected value. */
for (x = 0; x < selected; x++)
{
injectMyScroller (alphalist, KEY_DOWN);
}
/* Clean up. */
CDKfreeStrings (altWords);
/* Redraw the alphalist. */
drawCDKAlphalist (alphalist, ObjOf (alphalist)->box);
}
else
{
/* Set the entry field with the found item. */
setCDKEntry (entry,
alphalist->list[Index],
entry->min,
entry->max,
ObjOf (entry)->box);
drawCDKEntry (entry, ObjOf (entry)->box);
}
return (TRUE);
}
static int createList (CDKALPHALIST *alphalist, CDK_CSTRING *list, int listSize)
{
int status = 0;
if (listSize >= 0)
{
char **newlist = typeCallocN (char *, listSize + 1);
if (newlist != 0)
{
int x;
/*
* We'll sort the list before we use it. It would have been better to
* declare list[] const and only modify the copy, but there may be
* clients that rely on the old behavior.
*/
sortList (list, listSize);
/* Copy in the new information. */
status = 1;
for (x = 0; x < listSize; x++)
{
if ((newlist[x] = copyChar (list[x])) == 0)
{
status = 0;
break;
}
}
if (status)
{
destroyInfo (alphalist);
alphalist->listSize = listSize;
alphalist->list = newlist;
}
else
{
CDKfreeStrings (newlist);
}
}
}
else
{
destroyInfo (alphalist);
status = TRUE;
}
return status;
}
static void _focusCDKAlphalist (CDKOBJS *object)
{
CDKALPHALIST *widget = (CDKALPHALIST *)object;
FocusObj (ObjOf (widget->entryField));
}
static void _unfocusCDKAlphalist (CDKOBJS *object)
{
CDKALPHALIST *widget = (CDKALPHALIST *)object;
UnfocusObj (ObjOf (widget->entryField));
}
dummyRefreshData (Alphalist)
dummySaveData (Alphalist)
|