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
|
/*************************************<+>*************************************
*****************************************************************************
**
** File: Traversal.c
**
** Project: X Widgets
**
** Description: Code to support a generalized traversal handler for
** subclasses of XwManager.
**
*****************************************************************************
**
** Copyright (c) 1988 by Hewlett-Packard Company
** Copyright (c) 1988 by the Massachusetts Institute of Technology
**
** Permission to use, copy, modify, and distribute this software
** and its documentation for any purpose and without fee is hereby
** granted, provided that the above copyright notice appear in all
** copies and that both that copyright notice and this permission
** notice appear in supporting documentation, and that the names of
** Hewlett-Packard or M.I.T. not be used in advertising or publicity
** pertaining to distribution of the software without specific, written
** prior permission.
**
*****************************************************************************
*************************************<+>*************************************/
#include <X11/IntrinsicP.h>
#include <X11/Intrinsic.h>
#include <X11/Xutil.h>
#include <X11/StringDefs.h>
#include <Xw/Xw.h>
#include <Xw/XwP.h>
static int Overlap();
static void MoveNext();
static void MovePrev();
static void MoveTraversal();
static void Start();
static void Home();
static void TraverseToChild ();
static void ClearKbdFocus();
static Widget RightCheck();
static Widget LeftCheck();
static Widget UpCheck();
static Widget DownCheck();
static Widget ValidChoice();
static Boolean _XwManagerIsTraversable();
/* Structures used to maintain the traversal checklist */
typedef enum {
XwVERIFY_ONLY,
XwADD_TO_CHOSEN_LIST,
XwADD_TO_ACTIVE_LIST,
XwCLEAR_ACTIVE_LIST
} XwValidChoiceActions;
typedef enum {
XwNONE,
XwCHOSEN,
XwACTIVE
} XwEntryType;
typedef struct {
Widget widget;
XwEntryType type;
} _XwCheckListEntry;
/*
* Globals used to maintain a list of those widgets already checked
* during a traversal request.
*/
_XwCheckListEntry * _XwCheckList = NULL;
int _XwCheckListSize = 0;
int _XwCheckListIndex = 0;
/*
A manager's traversal handler will be invoked with:
Upper Left Point: (x1, y1)
Lower Right Point: (x2, y2)
Direction: XwTRAVERSE_CURRENT
XwTRAVERSE_LEFT
XwTRAVERSE_RIGHT
XwTRAVERSE_UP
XwTRAVERSE_DOWN
XwTRAVERSE_NEXT
XwTRAVERSE_PREV
XwTRAVERSE_HOME
XwTRAVERSE_NEXT_TOP
A manager has an active child which may be NULL. Widgets under
consideration to receive the keyboard focus are called candidate widgets.
In order to be a candidate, a widget must be traversable. This means
that it must be:
1) a subclass of primitive, and
sensitive (it and its ancestor)
visible
managed
have its "mapped_when_managed" flag set to TRUE, and
traversal_type=XwHIGHLIGHT_TRAVERSAL
2) a composite with a traversable primitive
Step 1: See if the manager contains any children which are traversable.
If not, set the "active_child" to NULL and
if the parent of this manager is a subclass of manager AND
that parent has traversal on, then invoke its traversal
handling procedure directly, otherwise return focus to
the root.
<<<<NOTE TEST WHETHER THIS IS THE CORRECT THING TO DO, WE
MAY NEED 2 DIFFERENT ACTIONS DEPENDING ON THE FOCUS MODEL
IN EFFECT.>>>>
If we do have someone who can accept the focus, then continue.
Step 2: The caller of this procedure supplies POINT1, POINT2 and the
DIRECTION. Pass control to the specified direction handler.
*/
/**********************************/
/* Globals for Traversal Routines */
/**********************************/
static int widget_type;
static XwManagerWidget parent;
static Boolean parent_is_manager;
void mgr_traversal (mgr, ul, lr, direction)
XwManagerWidget mgr;
XPoint ul, lr;
int direction;
{
XPoint newUl, newLr;
parent = (XwManagerWidget)mgr->core.parent;
parent_is_manager = XtIsSubclass((Widget)parent,XwmanagerWidgetClass);
if (direction == XwTRAVERSE_NEXT_TOP)
{
if (parent_is_manager)
{
newUl.x = newUl.y = newLr.x = newLr.y = 0;
(*(((XwManagerWidgetClass)(parent->core.widget_class)) ->
manager_class.traversal_handler))
((Widget)parent, newUl, newLr, direction);
}
else
{
XtCallCallbacks((Widget)mgr, XtNnextTop, NULL);
}
return;
}
if ((_XwFindTraversablePrim (mgr) == FALSE) ||
(!_XwManagerIsTraversable(mgr)))
{
if (mgr->manager.active_child != NULL)
mgr->manager.active_child = (Widget)NULL;
if (parent_is_manager && parent->manager.traversal_on)
{
newUl.x = ul.x + mgr->core.x;
newUl.y = ul.y + mgr->core.y;
newLr.x = lr.x + mgr->core.x;
newLr.y = lr.y + mgr->core.y;
(*(((XwManagerWidgetClass)(parent->core.widget_class)) ->
manager_class.traversal_handler))
((Widget)parent, newUl, newLr, direction);
}
else
ClearKbdFocus(mgr);
return;
}
/************************************
*
* THERE IS A CHILD TO TRAVERSE TO,
* DETERMINE DIRECTION & DO TRAVERSAL
*
************************************/
switch(direction)
{
case XwTRAVERSE_NEXT:
MoveNext((XwManagerWidget)mgr,ul, lr, direction); return;
case XwTRAVERSE_PREV:
MovePrev((XwManagerWidget)mgr,ul, lr, direction); return;
case XwTRAVERSE_DOWN:
case XwTRAVERSE_UP:
case XwTRAVERSE_RIGHT:
case XwTRAVERSE_LEFT:
MoveTraversal((XwManagerWidget)mgr,ul, lr, direction); return;
case XwTRAVERSE_CURRENT:
Start((XwManagerWidget)mgr, ul, lr ,direction); return;
case XwTRAVERSE_HOME:
Home((XwManagerWidget)mgr, ul, lr ,direction); return;
}
}
/*
DIRECTION = RIGHT (All other directions are just variations of this)
=================
Step 1) Find the widget to the right of the active child.
If widget A is the current active child and its upper left and lower right
points are defined by (x1,y1) and (x2,y2) respectively; and widget B is
a candidate widget whose upper left and lower right points are defined by
(x1',y1') and (x2',y2'). Then widget B is to the right of widget A
IFF ((x1 < x1') OR (if (x1 = x1') then (x2' > x2))
AND (y1 <= y2') AND (y2 >= y1')
If there is more than 1 candidate then choose the candidate with the
smallest value for:
(x1' - x1)
If 2 or more candidates have the same value for (x1'-x1) then choose the
candidate with the smallest value for:
|(x2' - x2)|
If 2 or more candidates have the same value for |(x2'-x2)| then choose
the candidate with the largest overlap of widget A along its y dimension:
if (y2' >= y2)
then
if (y1' <= y1)
then
overlap = height of active child
else
overlap = y2 - y1'
else
if (y1' <= y1)
then
overlap = y2' - y1
else
overlap = height of candidate
If 2 or more candidates have the same overlap then choose the widget with
the smallest value for y1'.
If 2 or more candidates have the same value for y1' then choose the widget with
the smallest value for y2'.
It should not be possible for 2 candidates to get this far since it would
mean that one exactly overlaps the other, which should mean that the
visibility flag of the obscured widget should be FALSE (thus making it
un-traversable), however, if we do get this far, arbitrarily choose the
first candidate.
Step 2) If no widget is to the right of the active child then:
if widget A's grandparent is a subclass of XwManager
then
-set manager's active child field to NULL
-invoke grandparent's traversal handler with:
Upper Left Point: x1=x1+parent's x coordinate
y1=y1+parent's y coordinate
Lower Right Point: x2=x2+parent's x coordinate
y2=y2+parent's y coordinate
Direction = XwTRAVERSE_RIGHT
if widget A's grandparent is NOT a subclass of XwManager
then
-set manager's active child field to NULL
-invoke parent's traversal handler with:
Upper Left Point: x1=0, y1=y1;
Lower Right Point: x2=0, y2=y2;
Direction = XwTRAVERSE_RIGHT
Step 3) If a candidate has been chosen, then set it as the active child of
its parent and:
if it is a subclass of XwPrimitive
then
-give it keyboard focus using XSetInputFocus function.
else (its a manager subclass)
-invoke its traversal handler with:
Upper Left Point: x1=x1 - x1'; y1=y1 - y1'
Lower Right Point: x2=x2 - x2'; y2=y2 - y2'
Direction = XwTRAVERSE_RIGHT
*/
static void MoveTraversal (mw, ul, lr, direction)
XwManagerWidget mw;
XPoint ul, lr;
int direction;
{
Widget candidate, chosen;
int chosen_widget_type;
int i=(-1);
XPoint cand_ul, cand_lr;
chosen = NULL;
while (++i < mw->composite.num_children)
{
candidate = mw->composite.children[i];
if ((candidate != mw->manager.active_child) &&
XwTestTraversability(candidate, &widget_type))
{
cand_ul.x = candidate->core.x;
cand_ul.y = candidate->core.y;
cand_lr.x = candidate->core.x + candidate->core.width +
(candidate->core.border_width << 1) - 1;
cand_lr.y = candidate->core.y + candidate->core.height +
(candidate->core.border_width << 1) - 1;
switch (direction)
{
case XwTRAVERSE_RIGHT:
chosen=RightCheck (chosen, ul, lr, candidate, cand_ul, cand_lr);
break;
case XwTRAVERSE_LEFT:
chosen = LeftCheck (chosen, ul, lr, candidate, cand_ul, cand_lr);
break;
case XwTRAVERSE_UP:
chosen = UpCheck (chosen, ul, lr, candidate, cand_ul, cand_lr);
break;
case XwTRAVERSE_DOWN:
chosen = DownCheck (chosen, ul, lr, candidate, cand_ul, cand_lr);
break;
}
}
if (chosen == candidate) chosen_widget_type = widget_type;
}
if (chosen == NULL) /* no widget in specified direction! */
{
/*
* Since our parent is a manager, see if there is another sibling
* of ours which can be traversed to.
*/
mw->manager.active_child = NULL;
if (parent_is_manager) /* really grandparent of active child */
{
/* Add ourselves to the active list */
ValidChoice (mw, mw, XwADD_TO_ACTIVE_LIST);
ul.x += mw->core.x;
ul.y += mw->core.y;
lr.x += mw->core.x;
lr.y += mw->core.y;
(*(((XwManagerWidgetClass)(parent->core.widget_class)) ->
manager_class.traversal_handler))
((Widget)parent, ul, lr, direction);
}
else
{
/* Wrap to opposite edge */
/* Clear the active traversal list */
ValidChoice (NULL, NULL, XwCLEAR_ACTIVE_LIST);
switch (direction)
{
case XwTRAVERSE_RIGHT:
{
ul.x = -10000;
lr.x = -10000;
break;
}
case XwTRAVERSE_LEFT:
{
ul.x = mw->core.width + (mw->core.border_width << 1);
lr.x = mw->core.width + (mw->core.border_width << 1);
break;
}
case XwTRAVERSE_UP:
{
ul.y = mw->core.height + (mw->core.border_width << 1);
lr.y = mw->core.height + (mw->core.border_width << 1);
break;
}
case XwTRAVERSE_DOWN:
{
ul.y = -10000;
lr.y = -10000;
break;
}
}
(*(((XwManagerWidgetClass)(mw->core.widget_class)) ->
manager_class.traversal_handler))
((Widget)mw, ul, lr, direction);
}
}
else
{
ValidChoice(chosen, chosen, XwADD_TO_CHOSEN_LIST);
TraverseToChild(mw, chosen, ul, lr, direction);
}
}
static void Start (mw, ul, lr, direction)
XwManagerWidget mw;
XPoint ul, lr;
int direction;
{
Widget candidate, chosen;
int chosen_widget_type;
int i=0;
chosen = NULL;
/* To prevent endless recursion, see if the child has already been checked */
if ((mw->manager.active_child != NULL) &&
(ValidChoice(NULL, mw->manager.active_child, XwVERIFY_ONLY)))
{
if (XwTestTraversability(mw->manager.active_child, &widget_type))
{
ValidChoice(chosen, chosen, XwADD_TO_CHOSEN_LIST);
TraverseToChild (mw, mw->manager.active_child, ul, lr, direction);
}
}
else
{
while (i < mw->composite.num_children)
{
candidate = mw->composite.children[i];
if (XwTestTraversability(candidate, &widget_type))
{
if (chosen==NULL)
chosen = ValidChoice(chosen, candidate, XwVERIFY_ONLY);
else
{
if ((candidate->core.x+candidate->core.y) <
(chosen->core.x+chosen->core.y))
chosen = ValidChoice(chosen, candidate,
XwVERIFY_ONLY);
}
}
i++;
}
ValidChoice(chosen, chosen, XwADD_TO_CHOSEN_LIST);
TraverseToChild(mw, chosen, ul, lr, direction);
}
}
/* We are guaranteed that there is a child to traverse to! */
static void MoveNext (mw, ul, lr, direction)
XwManagerWidget mw;
XPoint ul, lr;
int direction;
{
Widget candidate, chosen;
int chosen_widget_type;
int i=0;
parent = (XwManagerWidget)mw->core.parent;
parent_is_manager = XtIsSubclass((Widget)parent,XwmanagerWidgetClass);
if (mw->manager.active_child != NULL)
{
ul.x = (mw->manager.active_child)->core.x;
ul.y = (mw->manager.active_child)->core.y;
lr.x = ul.x + (mw->manager.active_child)->core.width +
((mw->manager.active_child)->core.border_width << 1) - 1;
lr.y = ul.y + (mw->manager.active_child)->core.height +
((mw->manager.active_child)->core.border_width << 1) - 1;
/* FIND INDEX OF CURRENTLY ACTIVE CHILD */
while ((mw->composite.children[i] != mw->manager.active_child) &&
(i < mw->composite.num_children))i++;
}
else
/* START LOOKING AT START OF LIST + 1 (TO ALLOW FOR 1ST DECREMENT)
* NOTE: THIS ALSO TAKES CARE OF THE DEGENERATE CASE WHEN THERE
* ARE NO CHILDREN. IN THIS CASE THE PARENT "MUST" BE A SUBCLASS
* OF XWMANAGER OR WE WOULD NEVER HAVE GOTTEN HERE.
*/
i = -1;
/*
* IF WE'VE COME TO THE END OF THE WIDGET LIST AND THE PARENT
* IS ALSO A SUBCLASS OF XWMANAGER, THEN INVOKE THE PARENT'S
* TRAVERSAL HANDLER, OTHERWISE, WRAP THE COUNTER TO START LOOKING
* AT THE LIST AGAIN.
*/
if (++i >= mw->composite.num_children)
{
if (parent_is_manager)
{
mw->manager.active_child = NULL;
(*(((XwManagerWidgetClass)(parent->core.widget_class)) ->
manager_class.traversal_handler))
((Widget)parent, ul, lr, direction);
return;
}
else
i=0;
}
/* FIND NEXT TRAVERSABLE WIDGET --THERE MUST BE ONE! */
while (! XwTestTraversability(mw->composite.children[i], &widget_type))
if (++i >= mw->composite.num_children) i=0;
TraverseToChild(mw, mw->composite.children[i], ul, lr, direction);
}
/* We are guaranteed that there is a child to traverse to! */
static void MovePrev (mw, ul, lr, direction)
XwManagerWidget mw;
XPoint ul, lr;
int direction;
{
Widget candidate, chosen;
int chosen_widget_type;
int i;
parent = (XwManagerWidget)mw->core.parent;
parent_is_manager = XtIsSubclass((Widget)parent,XwmanagerWidgetClass);
if (mw->manager.active_child != NULL)
{
ul.x = (mw->manager.active_child)->core.x;
ul.y = (mw->manager.active_child)->core.y;
lr.x = ul.x + (mw->manager.active_child)->core.width +
((mw->manager.active_child)->core.border_width << 1) - 1;
lr.y = ul.y + (mw->manager.active_child)->core.height +
((mw->manager.active_child)->core.border_width << 1) - 1;
/* FIND INDEX OF CURRENTLY ACTIVE CHILD */
i=mw->composite.num_children -1;
while ((mw->composite.children[i] != mw->manager.active_child) &&
(i > 0))i--;
}
else
/* START LOOKING AT END OF LIST + 1 (TO ALLOW FOR 1ST DECREMENT)
* NOTE: THIS ALSO TAKES CARE OF THE DEGENERATE CASE WHEN THERE
* ARE NO CHILDREN. IN THIS CASE THE PARENT "MUST" BE A SUBCLASS
* OF XWMANAGER OR WE WOULD NEVER HAVE GOTTEN HERE.
*/
i = mw->composite.num_children;
/*
* IF WE'VE COME TO THE END OF THE WIDGET LIST AND THE PARENT
* IS ALSO A SUBCLASS OF XWMANAGER, THEN INVOKE THE PARENT'S
* TRAVERSAL HANDLER, OTHERWISE, WRAP THE COUNTER TO START LOOKING
* AT THE LIST AGAIN.
*/
if (--i < 0)
{
if (parent_is_manager)
{
mw->manager.active_child = NULL;
(*(((XwManagerWidgetClass)(parent->core.widget_class)) ->
manager_class.traversal_handler))
((Widget)parent, ul, lr, direction);
return;
}
else
i = (mw->composite.num_children)-1;
}
/* FIND NEXT TRAVERSABLE WIDGET --THERE MUST BE ONE! */
while (! XwTestTraversability(mw->composite.children[i], &widget_type))
if (--i < 0) i = (mw->composite.num_children)-1;
TraverseToChild (mw, mw->composite.children[i], ul, lr, direction);
}
static int Overlap (pt1, pt2, w)
XPoint pt1, pt2;
Widget w;
{
XPoint pt1_prime, pt2_prime;
pt1_prime.x = w->core.x;
pt1_prime.y = w->core.y;
pt2_prime.x = w->core.x + w->core.width + (w->core.border_width << 1) - 1;
pt2_prime.y = w->core.y + w->core.height + (w->core.border_width << 1) - 1;
if (pt2_prime.y >= pt2.y)
{
if (pt1_prime.y <= pt1.y)
return(pt2.y - pt1.y);
else
return(pt2.y - pt1_prime.y);
}
else
{
if (pt1_prime.y <= pt1.y)
return(pt2_prime.y - pt1.y);
else
return(w->core.height);
}
}
/* CALCULATE OVERLAP IN X DIRECTION */
static int xOverlap (pt1, pt2, w)
XPoint pt1, pt2;
Widget w;
{
XPoint pt1_prime, pt2_prime;
pt1_prime.x = w->core.x;
pt1_prime.y = w->core.y;
pt2_prime.x = w->core.x + w->core.width + (w->core.border_width << 1) - 1;
pt2_prime.y = w->core.y + w->core.height + (w->core.border_width << 1) - 1;
if (pt2_prime.x >= pt2.x)
{
if (pt1_prime.x <= pt1.x)
return(pt2.x - pt1.x);
else
return(pt2.x - pt1_prime.x);
}
else
{
if (pt1_prime.x <= pt1.x)
return(pt2_prime.x - pt1.x);
else
return(w->core.width);
}
}
/*
* HOME: If I get called there is NO guarantee that there is something
* which is traversable. This is due to the way that X generates
* its visiblity events; the manager is notified before its children.
* Thus, the manager may still think it has traversable children,
* when in fact it doesn't. That is why we must have a special
* check to see that a child really was chosen.
*/
static void Home (mw, ul, lr, direction)
XwManagerWidget mw;
XPoint ul, lr;
int direction;
{
Widget candidate, chosen;
int chosen_widget_type;
int i=(-1);
chosen = NULL;
/*
search thru list of children to find child which is closest to
origin and which is traversable.
*/
while (++i < mw->composite.num_children)
{
candidate = mw->composite.children[i];
if (XwTestTraversability(candidate, &widget_type))
{
if (chosen==NULL)
chosen = ValidChoice(chosen, candidate, XwVERIFY_ONLY);
else
{
if ((candidate->core.x+candidate->core.y) <
(chosen->core.x+chosen->core.y))
chosen = ValidChoice(chosen, candidate, XwVERIFY_ONLY);
}
}
if (chosen == candidate) chosen_widget_type = widget_type;
}
/*
* If the closest to home widget is NOT the current active child then
* make it the active child. Otherwise, try and go up a level.
*/
if (mw->manager.active_child != chosen)
{
mw->manager.active_child=chosen;
ValidChoice(chosen, chosen, XwADD_TO_CHOSEN_LIST);
if (chosen_widget_type == XwPRIMITIVE)
TraverseToChild(mw, chosen, ul, lr, direction);
else
(*(((XwManagerWidgetClass)(chosen->core.widget_class)) ->
manager_class.traversal_handler))
(chosen, ul, lr, direction);
}
else /* WE ARE ALREADY HOMED IN THIS MANAGER, GO UP */
{
if (parent_is_manager) /* really grandparent of active child */
{
mw->manager.active_child = NULL;
(*(((XwManagerWidgetClass)(parent->core.widget_class)) ->
manager_class.traversal_handler))
((Widget)parent, ul, lr, direction);
}
/* If our parent is not a manager, then we are already
as HOME as we are going to get, so do nothing. */
}
}
static void TraverseToChild (mw, chosen, ul, lr, direction)
XwManagerWidget mw;
Widget chosen;
XPoint ul, lr;
int direction;
{
Widget topmost_manager= (Widget) mw;
mw->manager.active_child = chosen;
if (XtIsSubclass(chosen, XwprimitiveWidgetClass))
{
while ((topmost_manager->core.parent != NULL) &&
XtIsSubclass((Widget)(topmost_manager->core.parent),
XwmanagerWidgetClass))
topmost_manager = topmost_manager->core.parent;
XtSetKeyboardFocus(topmost_manager, chosen);
}
else
{
ul.x -= chosen->core.x;
ul.y -= chosen->core.y;
lr.x -= chosen->core.x;
lr.y -= chosen->core.y;
(*(((XwManagerWidgetClass)(chosen->core.widget_class)) ->
manager_class.traversal_handler))
(chosen, ul, lr, direction);
}
}
/*************************************<->*************************************
*
* XwMoveFocus(w)
*
* Description:
* -----------
* Useful when an application has created multiple top level
* hierarchies of widgets, is using keyboard traversal and
* wishes to move between them.
*
*
* Inputs: w = widget which is the new top level widget.
* ------
*
*************************************<->***********************************/
void XwMoveFocus(w)
Widget w;
{
/* MOVE MOUSE INTO NEW WINDOW HIERARCHY */
XWarpPointer(XtDisplay(w), None, XtWindow(w),0,0,0,0,1,1);
/* SET FOCUS HERE, SHOULD WORK FOR ALL FOCUS MODES */
XSetInputFocus (XtDisplay(w), XtWindow(w), RevertToParent,
CurrentTime);
}
static Widget RightCheck (chosen, ul, lr, candidate, cand_ul, cand_lr)
Widget chosen, candidate;
XPoint ul, lr, cand_ul, cand_lr;
{
if (((ul.x < cand_ul.x) || ((ul.x == cand_ul.x) && (lr.x < cand_lr.x))) &&
(ul.y <= cand_lr.y) && (lr.y >= cand_ul.y))
{
if (chosen == NULL)
chosen = ValidChoice(chosen, candidate, XwVERIFY_ONLY);
else
{
if (chosen->core.x > cand_ul.x)
chosen = ValidChoice(chosen, candidate, XwVERIFY_ONLY);
else
if (cand_ul.x == chosen->core.x)
{
if (abs(cand_lr.x - lr.x) <
abs((chosen->core.x+chosen->core.width +
(chosen->core.border_width << 1))-lr.x))
chosen = ValidChoice(chosen, candidate, XwVERIFY_ONLY);
else
if (abs(cand_lr.x - lr.x) ==
abs((chosen->core.x+chosen->core.width+
(chosen->core.border_width << 1))-lr.x))
if (Overlap(ul, lr, candidate) > Overlap(ul, lr, chosen))
chosen = ValidChoice(chosen, candidate, XwVERIFY_ONLY);
else
{
if (Overlap(ul,lr,candidate) == Overlap(ul,lr,chosen))
if (cand_ul.y < chosen->core.y)
chosen = ValidChoice(chosen, candidate,
XwVERIFY_ONLY);
else
{
if (cand_ul.y == chosen->core.y)
if (cand_lr.y < chosen->core.y +
chosen->core.height +
(chosen->core.border_width << 1))
chosen = ValidChoice(chosen,
candidate,
XwVERIFY_ONLY);
}
}
}
}
}
return (chosen);
}
static Widget LeftCheck (chosen, ul, lr, candidate, cand_ul, cand_lr)
Widget chosen, candidate;
XPoint ul, lr, cand_ul, cand_lr;
{
if (((cand_ul.x < ul.x) || ((cand_ul.x == ul.x) && (cand_lr.x < lr.x))) &&
(ul.y <= cand_lr.y) && (lr.y >= cand_ul.y))
{
if (chosen == NULL)
chosen = ValidChoice(chosen, candidate, XwVERIFY_ONLY);
else
{
if (cand_ul.x > chosen->core.x)
chosen = ValidChoice(chosen, candidate, XwVERIFY_ONLY);
else
if (cand_ul.x == chosen->core.x)
{
if (abs(cand_lr.x - lr.x) < abs(chosen->core.x+
chosen->core.width+(chosen->core.border_width<<1)-lr.x))
chosen = ValidChoice(chosen, candidate, XwVERIFY_ONLY);
else
if (abs(cand_lr.x - lr.x) == abs(chosen->core.x+
chosen->core.width+(chosen->core.border_width<<1)-lr.x))
if (Overlap(ul, lr, candidate) > Overlap(ul, lr, chosen))
chosen = ValidChoice(chosen, candidate, XwVERIFY_ONLY);
else
{
if (Overlap(ul,lr,candidate) == Overlap(ul,lr,chosen))
if (cand_ul.y > chosen->core.y)
chosen = ValidChoice(chosen, candidate,
XwVERIFY_ONLY);
else
{
if (cand_ul.y == chosen->core.y)
if (cand_lr.y >
chosen->core.y + chosen->core.height +
(chosen->core.border_width << 1))
chosen = ValidChoice(chosen, candidate,
XwVERIFY_ONLY);
}
}
}
}
}
return (chosen);
}
static Widget UpCheck (chosen, ul, lr, candidate, cand_ul, cand_lr)
Widget chosen, candidate;
XPoint ul, lr, cand_ul, cand_lr;
{
if (((cand_ul.y < ul.y) || ((cand_ul.y == ul.y) && (cand_lr.y < lr.y))) &&
(ul.x <= cand_lr.x) && (lr.x >= cand_ul.x))
{
if (chosen == NULL)
chosen = ValidChoice(chosen, candidate, XwVERIFY_ONLY);
else
{
if (cand_ul.y > chosen->core.y)
chosen = ValidChoice(chosen, candidate, XwVERIFY_ONLY);
else
if (cand_ul.y == chosen->core.y)
{
if (abs(cand_lr.y - lr.y) < abs(chosen->core.y+
chosen->core.height+(chosen->core.border_width<<1)-lr.y))
chosen = ValidChoice(chosen, candidate, XwVERIFY_ONLY);
else
if (abs(cand_lr.y - lr.y) == abs(chosen->core.y+
chosen->core.height+(chosen->core.border_width<<1)-lr.y))
if (xOverlap(ul, lr, candidate) > xOverlap(ul, lr, chosen))
chosen = ValidChoice(chosen, candidate, XwVERIFY_ONLY);
else
{
if (xOverlap(ul, lr, candidate) ==
xOverlap(ul, lr, chosen))
if (cand_ul.x > chosen->core.x)
chosen = ValidChoice(chosen, candidate,
XwVERIFY_ONLY);
else
{
if (cand_ul.x == chosen->core.x)
if (cand_lr.x >
chosen->core.x + chosen->core.width +
(chosen->core.border_width << 1))
chosen = ValidChoice(chosen,candidate,
XwVERIFY_ONLY);
}
}
}
}
}
return (chosen);
}
static Widget DownCheck (chosen, ul, lr, candidate, cand_ul, cand_lr)
Widget chosen, candidate;
XPoint ul, lr, cand_ul, cand_lr;
{
if (((ul.y < cand_ul.y) || ((ul.y == cand_ul.y) && (lr.y < cand_lr.y))) &&
(ul.x <= cand_lr.x) && (lr.x >= cand_ul.x))
{
if (chosen == NULL)
chosen = ValidChoice(chosen, candidate, XwVERIFY_ONLY);
else
{
if (chosen->core.y > cand_ul.y)
chosen = ValidChoice(chosen, candidate, XwVERIFY_ONLY);
else
if (cand_ul.y == chosen->core.y)
{
if (abs(cand_lr.y - lr.y) <
abs((chosen->core.y+chosen->core.height+
(chosen->core.border_width << 1))-lr.y))
chosen = ValidChoice(chosen, candidate, XwVERIFY_ONLY);
else
if (abs(cand_lr.y - lr.y) ==
abs((chosen->core.y+chosen->core.height+
(chosen->core.border_width << 1))-lr.y))
if (xOverlap(ul, lr, candidate) > xOverlap(ul, lr, chosen))
chosen = ValidChoice(chosen, candidate, XwVERIFY_ONLY);
else
{
if (xOverlap(ul, lr, candidate) ==
xOverlap(ul, lr, chosen))
if (cand_ul.x < chosen->core.x)
chosen = ValidChoice(chosen, candidate,
XwVERIFY_ONLY);
else
{
if (cand_ul.x == chosen->core.x)
if (cand_lr.x <
chosen->core.x + chosen->core.width +
(chosen->core.border_width << 1))
chosen = ValidChoice(chosen, candidate,
XwVERIFY_ONLY);
}
}
}
}
}
return (chosen);
}
/*
* To prevent the traversal mechanism from getting into an infinite
* recursion, we need to keep a list of those widgets already checked
* during a given traversal request. If a candidate has already been
* checked once, we don't want to give it a second chance. This is
* normally a problem only when a traversal request causes the search
* to wrap to the opposite edge.
*
* There are two types of entries maintained on the list: active entries
* and chosen entries. An entry is a chosen entry if its parent has
* determined that the entry can possible accept the traversal request,
* and has thus chosen it to in turn check its children to see if they
* can accept the traversal. An entry is an active entry if it is part
* of the current traversal path, but it does not have any children which
* can currently accept the traversal request; a widget is added to this
* list only if it is not already on the chosen list, AND it is passing
* the traversal request up to its parent.
*
* The active list prevents any of the widgets in the current traversal
* path from being rechecked by their parent, once they have already
* decided they can't accept the traversal request, until the upper most
* manager decides to wrap at an edge and start looking again; at this
* point, all active entries are cleared from the list, so that they can
* have a chance to regain the traversal if no other widget can.
*
* If an entry is marked as being on the
* active list, and then a request comes to place it on the chosen list,
* then the move will occur. If, however, a widget is on the chosen list,
* and it asks to move to the active list, this will be denied, since we
* don't want this widget to have the chance of being chosen again. An
* entry on the active list has not yet been chosen, it mearly was part of
* the original active child list.
*/
static Widget ValidChoice (chosen, candidate, action)
Widget chosen, candidate;
XwValidChoiceActions action;
{
int i;
/* If candidate is already on the list, then don't reprocess it */
if (action == XwVERIFY_ONLY)
{
/* Don't consider it unless it has some traversable primitives */
if (XtIsSubclass(candidate, XwmanagerWidgetClass) &&
_XwFindTraversablePrim(candidate) == False)
return (chosen);
for (i = 0; i < _XwCheckListIndex; i++)
{
if ((_XwCheckList[i].widget == candidate) &&
(_XwCheckList[i].type != XwNONE))
return (chosen);
}
}
if ((action == XwADD_TO_CHOSEN_LIST) || (action == XwADD_TO_ACTIVE_LIST))
{
/* See if already on the list; then just update type field */
for (i = 0; i < _XwCheckListIndex; i++)
{
if (_XwCheckList[i].widget == candidate)
{
if (_XwCheckList[i].type != XwCHOSEN)
{
_XwCheckList[_XwCheckListIndex].type =
(action == XwADD_TO_CHOSEN_LIST) ? XwCHOSEN : XwACTIVE;
}
return (candidate);
}
}
/* See if the list needs to grow */
if (_XwCheckListIndex >= _XwCheckListSize)
{
_XwCheckListSize += 20;
_XwCheckList = (_XwCheckListEntry *)XtRealloc((char *)_XwCheckList,
(sizeof(_XwCheckListEntry) * _XwCheckListSize));
}
/* Add to the checklist */
_XwCheckList[_XwCheckListIndex].widget = candidate;
_XwCheckList[_XwCheckListIndex].type = (action == XwADD_TO_CHOSEN_LIST) ?
XwCHOSEN : XwACTIVE;
_XwCheckListIndex++;
}
/* Clear all entries which were not on the chosen list */
if (action == XwCLEAR_ACTIVE_LIST)
{
for (i = 0; i < _XwCheckListIndex; i++)
{
if (_XwCheckList[i].type == XwACTIVE)
_XwCheckList[i].type = XwNONE;
}
}
return (candidate);
}
void _XwInitCheckList()
{
/* Initialize the traversal checklist */
if (_XwCheckList == NULL)
{
_XwCheckList=(_XwCheckListEntry *)XtMalloc(sizeof(_XwCheckListEntry)*20);
_XwCheckListSize = 20;
}
/* Always reset the checklist to the beginning */
_XwCheckListIndex = 0;
}
/*
* This function verifies that all of the ancestors of a manager
* have traversal enabled.
*/
static Boolean _XwManagerIsTraversable (w)
XwManagerWidget w;
{
while (w && XtIsSubclass((Widget)w, XwmanagerWidgetClass))
{
if ((w->manager.traversal_on == FALSE) || (w->core.visible == False))
return (False);
w = (XwManagerWidget)w->core.parent;
}
return (True);
}
static void ClearKbdFocus (topmost_manager)
Widget topmost_manager;
{
while ((topmost_manager->core.parent != NULL) &&
XtIsSubclass((Widget)(topmost_manager->core.parent),
XwmanagerWidgetClass))
topmost_manager = topmost_manager->core.parent;
XtSetKeyboardFocus(topmost_manager, NULL);
}
|