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 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359
|
/*
* tkTableTag.c --
*
* This module implements tags for table widgets.
*
* Copyright (c) 1998-2002 Jeffrey Hobbs
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* RCS: @(#) $Id: tkTableTag.c,v 1.18 2004/02/08 03:09:46 cerney Exp $
*/
#include "tkVMacro.h"
#include "tkTable.h"
static TableTag *TableTagGetEntry _ANSI_ARGS_((Table *tablePtr, char *name,
int objc, Tcl_Obj *CONST *objv));
static unsigned int TableTagGetPriority _ANSI_ARGS_((Table *tablePtr,
TableTag *tagPtr));
static void TableImageProc _ANSI_ARGS_((ClientData clientData, int x,
int y, int width, int height, int imageWidth, int imageHeight));
static int TableOptionReliefSet _ANSI_ARGS_((ClientData clientData,
Tcl_Interp *interp, Tk_Window tkwin,
Arg value, char *widgRec, int offset));
static Arg TableOptionReliefGet _ANSI_ARGS_((ClientData clientData,
Tk_Window tkwin, char *widgRec, int offset,
Tcl_FreeProc **freeProcPtr));
static CONST char *tagCmdNames[] = {
"celltag", "cget", "coltag", "configure", "delete", "exists",
"includes", "lower", "names", "raise", "rowtag", NULL
};
enum tagCmd {
TAG_CELLTAG, TAG_CGET, TAG_COLTAG, TAG_CONFIGURE, TAG_DELETE, TAG_EXISTS,
TAG_INCLUDES, TAG_LOWER, TAG_NAMES, TAG_RAISE, TAG_ROWTAG
};
static Cmd_Struct tagState_vals[]= {
{"unknown", STATE_UNKNOWN},
{"normal", STATE_NORMAL},
{"disabled", STATE_DISABLED},
{"", 0 }
};
static Tk_CustomOption tagStateOpt =
{ Cmd_OptionSet, Cmd_OptionGet, (ClientData) (&tagState_vals) };
static Tk_CustomOption tagBdOpt =
{ TableOptionBdSet, TableOptionBdGet, (ClientData) BD_TABLE_TAG };
static Tk_CustomOption tagReliefOpt =
{ TableOptionReliefSet, TableOptionReliefGet, (ClientData) NULL };
/*
* The default specification for configuring tags
* Done like this to make the command line parsing easy
*/
static Tk_ConfigSpec tagConfig[] = {
{TK_CONFIG_ANCHOR, "-anchor", "anchor", "Anchor", "center",
Tk_Offset(TableTag, anchor), TK_CONFIG_DONT_SET_DEFAULT|TK_CONFIG_NULL_OK },
{TK_CONFIG_BORDER, "-background", "background", "Background", NULL,
Tk_Offset(TableTag, bg), TK_CONFIG_DONT_SET_DEFAULT|TK_CONFIG_NULL_OK },
{TK_CONFIG_SYNONYM, "-bd", "borderWidth", NULL, NULL, 0, 0},
{TK_CONFIG_SYNONYM, "-bg", "background", NULL, NULL, 0, 0},
{TK_CONFIG_CUSTOM, "-borderwidth", "borderWidth", "BorderWidth", "",
0 /* no offset */,
TK_CONFIG_DONT_SET_DEFAULT|TK_CONFIG_NULL_OK, &tagBdOpt },
{TK_CONFIG_BORDER, "-foreground", "foreground", "Foreground", NULL,
Tk_Offset(TableTag, fg), TK_CONFIG_DONT_SET_DEFAULT|TK_CONFIG_NULL_OK },
{TK_CONFIG_SYNONYM, "-fg", "foreground", NULL, NULL, 0, 0},
{TK_CONFIG_FONT, "-font", "font", "Font", NULL,
Tk_Offset(TableTag, tkfont), TK_CONFIG_DONT_SET_DEFAULT|TK_CONFIG_NULL_OK },
{TK_CONFIG_STRING, "-image", "image", "Image", NULL,
Tk_Offset(TableTag, imageStr),
TK_CONFIG_DONT_SET_DEFAULT|TK_CONFIG_NULL_OK },
{TK_CONFIG_JUSTIFY, "-justify", "justify", "Justify", "left",
Tk_Offset(TableTag, justify), TK_CONFIG_DONT_SET_DEFAULT|TK_CONFIG_NULL_OK },
{TK_CONFIG_INT, "-multiline", "multiline", "Multiline", "-1",
Tk_Offset(TableTag, multiline), TK_CONFIG_DONT_SET_DEFAULT },
{TK_CONFIG_CUSTOM, "-relief", "relief", "Relief", "flat",
Tk_Offset(TableTag, relief), TK_CONFIG_DONT_SET_DEFAULT|TK_CONFIG_NULL_OK,
&tagReliefOpt },
{TK_CONFIG_INT, "-showtext", "showText", "ShowText", "-1",
Tk_Offset(TableTag, showtext), TK_CONFIG_DONT_SET_DEFAULT },
{TK_CONFIG_CUSTOM, "-state", "state", "State", "unknown",
Tk_Offset(TableTag, state), TK_CONFIG_DONT_SET_DEFAULT, &tagStateOpt },
{TK_CONFIG_INT, "-wrap", "wrap", "Wrap", "-1",
Tk_Offset(TableTag, wrap), TK_CONFIG_DONT_SET_DEFAULT },
{TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0}
};
/*
* The join tag structure is used to create a combined tag, so it
* keeps priority info.
*/
typedef struct {
TableTag tag; /* must be first */
unsigned int magic;
unsigned int pbg, pfg, pborders, prelief, ptkfont, panchor, pimage;
unsigned int pstate, pjustify, pmultiline, pwrap, pshowtext;
} TableJoinTag;
/*
*----------------------------------------------------------------------
*
* TableImageProc --
* Called when an image associated with a tag is changed.
*
* Results:
* None.
*
* Side effects:
* Invalidates the whole table.
* This should only invalidate affected cells, but that info
* is not managed...
*
*----------------------------------------------------------------------
*/
static void
TableImageProc(ClientData clientData, int x, int y, int width, int height,
int imageWidth, int imageHeight)
{
TableInvalidateAll((Table *)clientData, 0);
}
/*
*----------------------------------------------------------------------
*
* TableNewTag --
* ckallocs space for a new tag structure and inits the structure.
*
* Results:
* Returns a pointer to the new structure. Must be freed later.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
TableTag *
TableNewTag(Table *tablePtr)
{
TableTag *tagPtr;
/*
* If tablePtr is NULL, make a regular tag, otherwise make a join tag.
*/
if (tablePtr == NULL) {
tagPtr = (TableTag *) ckalloc(sizeof(TableTag));
memset((VOID *) tagPtr, 0, sizeof(TableTag));
/*
* Set the values that aren't 0/NULL by default
*/
tagPtr->anchor = (Tk_Anchor)-1;
tagPtr->justify = (Tk_Justify)-1;
tagPtr->multiline = -1;
tagPtr->relief = -1;
tagPtr->showtext = -1;
tagPtr->state = STATE_UNKNOWN;
tagPtr->wrap = -1;
} else {
TableJoinTag *jtagPtr = (TableJoinTag *) ckalloc(sizeof(TableJoinTag));
memset((VOID *) jtagPtr, 0, sizeof(TableJoinTag));
tagPtr = (TableTag *) jtagPtr;
tagPtr->anchor = (Tk_Anchor)-1;
tagPtr->justify = (Tk_Justify)-1;
tagPtr->multiline = -1;
tagPtr->relief = -1;
tagPtr->showtext = -1;
tagPtr->state = STATE_UNKNOWN;
tagPtr->wrap = -1;
jtagPtr->magic = 0x99ABCDEF;
jtagPtr->pbg = -1;
jtagPtr->pfg = -1;
jtagPtr->pborders = -1;
jtagPtr->prelief = -1;
jtagPtr->ptkfont = -1;
jtagPtr->panchor = -1;
jtagPtr->pimage = -1;
jtagPtr->pstate = -1;
jtagPtr->pjustify = -1;
jtagPtr->pmultiline = -1;
jtagPtr->pwrap = -1;
jtagPtr->pshowtext = -1;
}
return (TableTag *) tagPtr;
}
/*
*----------------------------------------------------------------------
*
* TableResetTag --
* This routine resets a given tag to the table defaults.
*
* Results:
* Tag will have values changed.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
void
TableResetTag(Table *tablePtr, TableTag *tagPtr)
{
TableJoinTag *jtagPtr = (TableJoinTag *) tagPtr;
if (jtagPtr->magic != 0x99ABCDEF) {
Tcl_Panic("bad mojo in TableResetTag");
}
memset((VOID *) jtagPtr, 0, sizeof(TableJoinTag));
tagPtr->anchor = (Tk_Anchor)-1;
tagPtr->justify = (Tk_Justify)-1;
tagPtr->multiline = -1;
tagPtr->relief = -1;
tagPtr->showtext = -1;
tagPtr->state = STATE_UNKNOWN;
tagPtr->wrap = -1;
jtagPtr->magic = 0x99ABCDEF;
jtagPtr->pbg = -1;
jtagPtr->pfg = -1;
jtagPtr->pborders = -1;
jtagPtr->prelief = -1;
jtagPtr->ptkfont = -1;
jtagPtr->panchor = -1;
jtagPtr->pimage = -1;
jtagPtr->pstate = -1;
jtagPtr->pjustify = -1;
jtagPtr->pmultiline = -1;
jtagPtr->pwrap = -1;
jtagPtr->pshowtext = -1;
/*
* Merge in the default tag.
*/
memcpy((VOID *) jtagPtr, (VOID *) &(tablePtr->defaultTag),
sizeof(TableTag));
}
/*
*----------------------------------------------------------------------
*
* TableMergeTag --
* This routine merges two tags by adding any fields from the addTag
* that are set to the baseTag.
*
* Results:
* baseTag will inherit all set characteristics of addTag
* (addTag thus has the priority).
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
void
TableMergeTag(Table *tablePtr, TableTag *baseTag, TableTag *addTag)
{
TableJoinTag *jtagPtr = (TableJoinTag *) baseTag;
unsigned int prio;
if (jtagPtr->magic != 0x99ABCDEF) {
Tcl_Panic("bad mojo in TableMergeTag");
}
#ifndef NO_TAG_PRIORITIES
/*
* Find priority for the tag to merge
*/
prio = TableTagGetPriority(tablePtr, addTag);
if ((addTag->anchor != -1) && (prio < jtagPtr->panchor)) {
baseTag->anchor = addTag->anchor;
jtagPtr->panchor = prio;
}
if ((addTag->bg != NULL) && (prio < jtagPtr->pbg)) {
baseTag->bg = addTag->bg;
jtagPtr->pbg = prio;
}
if ((addTag->fg != NULL) && (prio < jtagPtr->pfg)) {
baseTag->fg = addTag->fg;
jtagPtr->pfg = prio;
}
if ((addTag->tkfont != NULL) && (prio < jtagPtr->ptkfont)) {
baseTag->tkfont = addTag->tkfont;
jtagPtr->ptkfont = prio;
}
if ((addTag->imageStr != NULL) && (prio < jtagPtr->pimage)) {
baseTag->imageStr = addTag->imageStr;
baseTag->image = addTag->image;
jtagPtr->pimage = prio;
}
if ((addTag->multiline >= 0) && (prio < jtagPtr->pmultiline)) {
baseTag->multiline = addTag->multiline;
jtagPtr->pmultiline = prio;
}
if ((addTag->relief != -1) && (prio < jtagPtr->prelief)) {
baseTag->relief = addTag->relief;
jtagPtr->prelief = prio;
}
if ((addTag->showtext >= 0) && (prio < jtagPtr->pshowtext)) {
baseTag->showtext = addTag->showtext;
jtagPtr->pshowtext = prio;
}
if ((addTag->state != STATE_UNKNOWN) && (prio < jtagPtr->pstate)) {
baseTag->state = addTag->state;
jtagPtr->pstate = prio;
}
if ((addTag->justify != -1) && (prio < jtagPtr->pjustify)) {
baseTag->justify = addTag->justify;
jtagPtr->pjustify = prio;
}
if ((addTag->wrap >= 0) && (prio < jtagPtr->pwrap)) {
baseTag->wrap = addTag->wrap;
jtagPtr->pwrap = prio;
}
if ((addTag->borders) && (prio < jtagPtr->pborders)) {
baseTag->borderStr = addTag->borderStr;
baseTag->borders = addTag->borders;
baseTag->bd[0] = addTag->bd[0];
baseTag->bd[1] = addTag->bd[1];
baseTag->bd[2] = addTag->bd[2];
baseTag->bd[3] = addTag->bd[3];
jtagPtr->pborders = prio;
}
#else
if (addTag->anchor != -1) baseTag->anchor = addTag->anchor;
if (addTag->bg != NULL) baseTag->bg = addTag->bg;
if (addTag->fg != NULL) baseTag->fg = addTag->fg;
if (addTag->tkfont != NULL) baseTag->tkfont = addTag->tkfont;
if (addTag->imageStr != NULL) {
baseTag->imageStr = addTag->imageStr;
baseTag->image = addTag->image;
}
if (addTag->multiline >= 0) baseTag->multiline = addTag->multiline;
if (addTag->relief != -1) baseTag->relief = addTag->relief;
if (addTag->showtext >= 0) baseTag->showtext = addTag->showtext;
if (addTag->state != STATE_UNKNOWN) baseTag->state = addTag->state;
if (addTag->justify != -1) baseTag->justify = addTag->justify;
if (addTag->wrap >= 0) baseTag->wrap = addTag->wrap;
if (addTag->borders) {
baseTag->borderStr = addTag->borderStr;
baseTag->borders = addTag->borders;
baseTag->bd[0] = addTag->bd[0];
baseTag->bd[1] = addTag->bd[1];
baseTag->bd[2] = addTag->bd[2];
baseTag->bd[3] = addTag->bd[3];
}
#endif
}
/*
*----------------------------------------------------------------------
*
* TableInvertTag --
* This routine swaps background and foreground for the selected tag.
*
* Results:
* Inverts fg and bg of tag.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
void
TableInvertTag(TableTag *baseTag)
{
Tk_3DBorder tmpBg;
tmpBg = baseTag->fg;
baseTag->fg = baseTag->bg;
baseTag->bg = tmpBg;
}
/*
*----------------------------------------------------------------------
*
* TableGetTagBorders --
* This routine gets the border values based on a tag.
*
* Results:
* It returns the values in the int*'s (if not NULL), and the
* total number of defined borders as a result.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
int
TableGetTagBorders(TableTag *tagPtr,
int *left, int *right, int *top, int *bottom)
{
switch (tagPtr->borders) {
case 0:
if (left) { *left = 0; }
if (right) { *right = 0; }
if (top) { *top = 0; }
if (bottom) { *bottom = 0; }
break;
case 1:
if (left) { *left = tagPtr->bd[0]; }
if (right) { *right = tagPtr->bd[0]; }
if (top) { *top = tagPtr->bd[0]; }
if (bottom) { *bottom = tagPtr->bd[0]; }
break;
case 2:
if (left) { *left = tagPtr->bd[0]; }
if (right) { *right = tagPtr->bd[1]; }
if (top) { *top = 0; }
if (bottom) { *bottom = 0; }
break;
case 4:
if (left) { *left = tagPtr->bd[0]; }
if (right) { *right = tagPtr->bd[1]; }
if (top) { *top = tagPtr->bd[2]; }
if (bottom) { *bottom = tagPtr->bd[3]; }
break;
default:
Tcl_Panic("invalid border value '%d'\n", tagPtr->borders);
break;
}
return tagPtr->borders;
}
/*
*----------------------------------------------------------------------
*
* TableTagGetEntry --
* Takes a name and optional args and creates a tag entry in the
* table's tag table.
*
* Results:
* A new tag entry will be created and returned.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static TableTag *
TableTagGetEntry(Table *tablePtr, char *name, int objc, Tcl_Obj *CONST *objv)
{
Tcl_HashEntry *entryPtr;
TableTag *tagPtr = NULL;
int new;
entryPtr = Tcl_CreateHashEntry(tablePtr->tagTable, name, &new);
if (new) {
tagPtr = TableNewTag(NULL);
Tcl_SetHashValue(entryPtr, (ClientData) tagPtr);
if (tablePtr->tagPrioSize >= tablePtr->tagPrioMax) {
int i;
/*
* Increase the priority list size in blocks of 10
*/
tablePtr->tagPrioMax += 10;
tablePtr->tagPrioNames = (char **) ckrealloc(
(char *) tablePtr->tagPrioNames,
sizeof(TableTag *) * tablePtr->tagPrioMax);
tablePtr->tagPrios = (TableTag **) ckrealloc(
(char *) tablePtr->tagPrios,
sizeof(TableTag *) * tablePtr->tagPrioMax);
for (i = tablePtr->tagPrioSize; i < tablePtr->tagPrioMax; i++) {
tablePtr->tagPrioNames[i] = NULL;
tablePtr->tagPrios[i] = (TableTag *) NULL;
}
}
tablePtr->tagPrioNames[tablePtr->tagPrioSize] =
(char *) Tcl_GetHashKey(tablePtr->tagTable, entryPtr);
tablePtr->tagPrios[tablePtr->tagPrioSize] = tagPtr;
tablePtr->tagPrioSize++;
} else {
tagPtr = (TableTag *) Tcl_GetHashValue(entryPtr);
}
if (objc) {
Tk_ConfigureWidget(tablePtr->interp, tablePtr->tkwin, tagConfig,
objc, objv, (char *)tagPtr,
TK_CONFIG_ARGV_ONLY);
}
return tagPtr;
}
/*
*----------------------------------------------------------------------
*
* TableTagGetPriority --
* Get the priority value for a tag.
*
* Results:
* returns the priority.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static unsigned int
TableTagGetPriority(Table *tablePtr, TableTag *tagPtr)
{
unsigned int prio = 0;
while (tagPtr != tablePtr->tagPrios[prio]) { prio++; }
return prio;
}
/*
*----------------------------------------------------------------------
*
* TableInitTags --
* Creates the static table tags.
*
* Results:
* active, sel, title and flash are created as tags.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
void
TableInitTags(Table *tablePtr)
{
Arg activeArgs[4];
Arg selArgs[6];
Arg titleArgs[8];
Arg flashArgs[2];
activeArgs[0]= LangStringArg("-bg"); activeArgs[1]= LangStringArg(ACTIVE_BG); activeArgs[2]=LangStringArg("-relief"); activeArgs[3]=LangStringArg("flat");
selArgs[0]= LangStringArg("-bg"); selArgs[1]=LangStringArg(SELECT_BG); selArgs[2]=LangStringArg("-fg"); selArgs[3]=LangStringArg(SELECT_FG);
selArgs[4]=LangStringArg("-relief"); selArgs[5]=LangStringArg("sunken");
titleArgs[0]=LangStringArg("-bg"), titleArgs[1]=LangStringArg(DISABLED), titleArgs[2]=LangStringArg("-fg"), titleArgs[3]=LangStringArg("white"),
titleArgs[4]=LangStringArg("-relief"), titleArgs[5]=LangStringArg("flat"), titleArgs[6]=LangStringArg("-state"), titleArgs[7]=LangStringArg("disabled");
flashArgs[0]= LangStringArg("-bg"); flashArgs[1]=LangStringArg("red");
/*
* The order of creation is important to priority.
*/
TableTagGetEntry(tablePtr, "flash", ARSIZE(flashArgs), flashArgs);
TableTagGetEntry(tablePtr, "active", ARSIZE(activeArgs), activeArgs);
TableTagGetEntry(tablePtr, "sel", ARSIZE(selArgs), selArgs);
TableTagGetEntry(tablePtr, "title", ARSIZE(titleArgs), titleArgs);
}
/*
*----------------------------------------------------------------------
*
* FindRowColTag --
* Finds a row/col tag based on the row/col styles and tagCommand.
*
* Results:
* Returns tag associated with row/col cell, if any.
*
* Side effects:
* Possible side effects from eval of tagCommand.
* IMPORTANT: This plays with the interp result object,
* so use of resultPtr in prior command may be invalid after
* calling this function.
*
*----------------------------------------------------------------------
*/
TableTag *
FindRowColTag(Table *tablePtr, int cell, int mode)
{
Tcl_HashEntry *entryPtr;
TableTag *tagPtr = NULL;
/* kill(0,2); */
entryPtr = Tcl_FindHashEntry((mode == ROW) ? tablePtr->rowStyles
: tablePtr->colStyles, (char *) cell);
if (entryPtr == NULL) {
LangCallback *cmd = (mode == ROW) ? tablePtr->rowTagCmd : tablePtr->colTagCmd;
if (cmd) {
register Tcl_Interp *interp = tablePtr->interp;
char buf[INDEX_BUFSIZE];
/*
* Since no specific row/col tag exists, eval the given command
* with row/col appended
*/
sprintf(buf, " %d", cell);
Tcl_Preserve((ClientData) interp);
if ( LangDoCallback(interp, cmd, 1, 1, " %d", cell) == TCL_OK) {
CONST char *name = Tcl_GetStringFromObj(Tcl_GetObjResult(interp),NULL);
if (name && *name) {
/*
* If a result was returned, check to see if it is
* a valid tag.
*/
entryPtr = Tcl_FindHashEntry(tablePtr->tagTable, name);
}
}
Tcl_Release((ClientData) interp);
Tcl_ResetResult(interp);
}
}
if (entryPtr != NULL) {
/*
* This can be either the one in row|colStyles,
* or that returned by eval'ing the row|colTagCmd
*/
tagPtr = (TableTag *) Tcl_GetHashValue(entryPtr);
}
return tagPtr;
}
/*
*----------------------------------------------------------------------
*
* TableCleanupTag --
* Releases the resources used by a tag before it is freed up.
*
* Results:
* None.
*
* Side effects:
* The tag is no longer valid.
*
*----------------------------------------------------------------------
*/
void
TableCleanupTag(Table *tablePtr, TableTag *tagPtr)
{
/*
* Free resources that the optionSpec doesn't specifically know about
*/
if (tagPtr->image) {
Tk_FreeImage(tagPtr->image);
}
Tk_FreeOptions(tagConfig, (char *) tagPtr, tablePtr->display, 0);
}
/*
*--------------------------------------------------------------
*
* Table_TagCmd --
* This procedure is invoked to process the tag method
* that corresponds to a widget managed by this module.
* See the user documentation for details on what it does.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
*--------------------------------------------------------------
*/
int
Table_TagCmd(ClientData clientData, register Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
register Table *tablePtr = (Table *)clientData;
int result = TCL_OK, cmdIndex, i, newEntry, value, len;
int row, col, tagPrio, refresh = 0;
TableTag *tagPtr, *tag2Ptr;
Tcl_HashEntry *entryPtr, *scanPtr;
Tcl_HashTable *hashTblPtr;
Tcl_HashSearch search;
Tk_Image image;
Tcl_Obj *objPtr, *resultPtr;
char buf[INDEX_BUFSIZE], *keybuf, *tagname;
if (objc < 3) {
Tcl_WrongNumArgs(interp, 2, objv, "option ?arg arg ...?");
return TCL_ERROR;
}
result = Tcl_GetIndexFromObj(interp, objv[2], tagCmdNames,
"tag option", 0, &cmdIndex);
if (result != TCL_OK) {
return result;
}
/*
* Before using this object, make sure there aren't any calls that
* could have changed the interp result, thus freeing the object.
*/
resultPtr = Tcl_GetObjResult(interp);
switch ((enum tagCmd) cmdIndex) {
case TAG_CELLTAG: /* add named tag to a (group of) cell(s) */
if (objc < 4) {
Tcl_WrongNumArgs(interp, 3, objv, "tag ?arg arg ...?");
return TCL_ERROR;
}
tagname = Tcl_GetStringFromObj(objv[3], &len);
if (len == 0) {
/*
* An empty string was specified, so just delete the tag.
*/
tagPtr = NULL;
} else {
/*
* Get the pointer to the tag structure. If it doesn't
* exist, it will be created.
*/
tagPtr = TableTagGetEntry(tablePtr, tagname, 0, NULL);
}
if (objc == 4) {
/*
* The user just wants the cells with this tag returned.
* Handle specially tags named: active, flash, sel, title
*/
if ((tablePtr->flags & HAS_ACTIVE) &&
STREQ(tagname, "active")) {
TableMakeArrayIndex(
tablePtr->activeRow+tablePtr->rowOffset,
tablePtr->activeCol+tablePtr->colOffset, buf);
Tcl_SetStringObj(resultPtr, buf, -1);
} else if ((tablePtr->flashMode && STREQ(tagname, "flash"))
|| STREQ(tagname, "sel")) {
hashTblPtr = (*tagname == 's') ?
tablePtr->selCells : tablePtr->flashCells;
for (scanPtr = Tcl_FirstHashEntry(hashTblPtr, &search);
scanPtr != NULL;
scanPtr = Tcl_NextHashEntry(&search)) {
keybuf = (char *) Tcl_GetHashKey(hashTblPtr, scanPtr);
Tcl_ListObjAppendElement(NULL, resultPtr,
Tcl_NewStringObj(keybuf, -1));
}
} else if (STREQ(tagname, "title") &&
(tablePtr->titleRows || tablePtr->titleCols)) {
for (row = tablePtr->rowOffset;
row < tablePtr->rowOffset+tablePtr->rows; row++) {
for (col = tablePtr->colOffset;
col < tablePtr->colOffset+tablePtr->titleCols;
col++) {
TableMakeArrayIndex(row, col, buf);
Tcl_ListObjAppendElement(NULL, resultPtr,
Tcl_NewStringObj(buf, -1));
}
}
for (row = tablePtr->rowOffset;
row < tablePtr->rowOffset+tablePtr->titleRows;
row++) {
for (col = tablePtr->colOffset+tablePtr->titleCols;
col < tablePtr->colOffset+tablePtr->cols; col++) {
TableMakeArrayIndex(row, col, buf);
Tcl_ListObjAppendElement(NULL, resultPtr,
Tcl_NewStringObj(buf, -1));
}
}
} else {
/*
* Check this tag pointer amongst all tagged cells
*/
for (scanPtr = Tcl_FirstHashEntry(tablePtr->cellStyles,
&search);
scanPtr != NULL;
scanPtr = Tcl_NextHashEntry(&search)) {
if ((TableTag *) Tcl_GetHashValue(scanPtr) == tagPtr) {
keybuf = (char *) Tcl_GetHashKey(
tablePtr->cellStyles, scanPtr);
Tcl_ListObjAppendElement(NULL, resultPtr,
Tcl_NewStringObj(keybuf, -1));
}
}
}
return TCL_OK;
}
/*
* Loop through the arguments and fill in the hash table
*/
for (i = 4; i < objc; i++) {
/*
* Try and parse the index
*/
if (TableGetIndexObj(tablePtr, objv[i], &row, &col)
!= TCL_OK) {
return TCL_ERROR;
}
/*
* Get the hash key ready
*/
TableMakeArrayIndex(row, col, buf);
if (tagPtr == NULL) {
/*
* This is a deletion
*/
entryPtr = Tcl_FindHashEntry(tablePtr->cellStyles, buf);
if (entryPtr != NULL) {
Tcl_DeleteHashEntry(entryPtr);
refresh = 1;
}
} else {
/*
* Add a key to the hash table and set it to point to the
* Tag structure if it wasn't the same as an existing one
*/
entryPtr = Tcl_CreateHashEntry(tablePtr->cellStyles,
buf, &newEntry);
if (newEntry || (tagPtr !=
(TableTag *) Tcl_GetHashValue(entryPtr))) {
Tcl_SetHashValue(entryPtr, (ClientData) tagPtr);
refresh = 1;
}
}
/*
* Now invalidate this cell for redraw
*/
if (refresh) {
TableRefresh(tablePtr, row-tablePtr->rowOffset,
col-tablePtr->colOffset, CELL);
}
}
return TCL_OK;
case TAG_COLTAG:
case TAG_ROWTAG: { /* tag a row or a column */
int forRows = (cmdIndex == TAG_ROWTAG);
if (objc < 4) {
Tcl_WrongNumArgs(interp, 3, objv, "tag ?arg arg ..?");
return TCL_ERROR;
}
tagname = Tcl_GetStringFromObj(objv[3], &len);
if (len == 0) {
/*
* Empty string, so we want to delete this element
*/
tagPtr = NULL;
} else {
/*
* Get the pointer to the tag structure. If it doesn't
* exist, it will be created.
*/
tagPtr = TableTagGetEntry(tablePtr, tagname, 0, NULL);
}
/*
* Choose the correct hash table based on args
*/
hashTblPtr = forRows ? tablePtr->rowStyles : tablePtr->colStyles;
if (objc == 4) {
/* the user just wants the tagged cells to be returned */
/* Special handling for tags: active, flash, sel, title */
if ((tablePtr->flags & HAS_ACTIVE) &&
strcmp(tagname, "active") == 0) {
Tcl_SetIntObj(resultPtr,
(forRows ?
tablePtr->activeRow+tablePtr->rowOffset :
tablePtr->activeCol+tablePtr->colOffset));
} else if ((tablePtr->flashMode && STREQ(tagname, "flash"))
|| STREQ(tagname, "sel")) {
Tcl_HashTable *cacheTblPtr;
cacheTblPtr = (Tcl_HashTable *)
ckalloc(sizeof(Tcl_HashTable));
Tcl_InitHashTable(cacheTblPtr, TCL_ONE_WORD_KEYS);
hashTblPtr = (*tagname == 's') ?
tablePtr->selCells : tablePtr->flashCells;
for (scanPtr = Tcl_FirstHashEntry(hashTblPtr, &search);
scanPtr != NULL;
scanPtr = Tcl_NextHashEntry(&search)) {
TableParseArrayIndex(&row, &col,
Tcl_GetHashKey(hashTblPtr, scanPtr));
value = forRows ? row : col;
entryPtr = Tcl_CreateHashEntry(cacheTblPtr,
(char *)value, &newEntry);
if (newEntry) {
Tcl_ListObjAppendElement(NULL, resultPtr,
Tcl_NewIntObj(value));
}
}
Tcl_DeleteHashTable(cacheTblPtr);
ckfree((char *) (cacheTblPtr));
} else if (STREQ(tagname, "title") &&
(forRows?tablePtr->titleRows:tablePtr->titleCols)) {
if (forRows) {
for (row = tablePtr->rowOffset;
row < tablePtr->rowOffset+tablePtr->titleRows;
row++) {
Tcl_ListObjAppendElement(NULL, resultPtr,
Tcl_NewIntObj(row));
}
} else {
for (col = tablePtr->colOffset;
col < tablePtr->colOffset+tablePtr->titleCols;
col++) {
Tcl_ListObjAppendElement(NULL, resultPtr,
Tcl_NewIntObj(col));
}
}
} else {
for (scanPtr = Tcl_FirstHashEntry(hashTblPtr, &search);
scanPtr != NULL;
scanPtr = Tcl_NextHashEntry(&search)) {
/* is this the tag pointer on this row */
if ((TableTag *) Tcl_GetHashValue(scanPtr) == tagPtr) {
objPtr = Tcl_NewIntObj(
(int) Tcl_GetHashKey(hashTblPtr, scanPtr));
Tcl_ListObjAppendElement(NULL, resultPtr, objPtr);
}
}
}
return TCL_OK;
}
/*
* Loop through the arguments and fill in the hash table
*/
for (i = 4; i < objc; i++) {
/*
* Try and parse the index
*/
if (Tcl_GetIntFromObj(interp, objv[i], &value) != TCL_OK) {
return TCL_ERROR;
}
if (tagPtr == NULL) {
/*
* This is a deletion
*/
entryPtr = Tcl_FindHashEntry(hashTblPtr, (char *)value);
if (entryPtr != NULL) {
Tcl_DeleteHashEntry(entryPtr);
refresh = 1;
}
} else {
/*
* Add a key to the hash table and set it to point to the
* Tag structure if it wasn't the same as an existing one
*/
entryPtr = Tcl_CreateHashEntry(hashTblPtr,
(char *) value, &newEntry);
if (newEntry || (tagPtr !=
(TableTag *) Tcl_GetHashValue(entryPtr))) {
Tcl_SetHashValue(entryPtr, (ClientData) tagPtr);
refresh = 1;
}
}
/* and invalidate the row or column affected */
if (refresh) {
if (cmdIndex == TAG_ROWTAG) {
TableRefresh(tablePtr, value-tablePtr->rowOffset, 0,
ROW);
} else {
TableRefresh(tablePtr, 0, value-tablePtr->colOffset,
COL);
}
}
}
return TCL_OK; /* COLTAG && ROWTAG */
}
case TAG_CGET:
if (objc != 5) {
Tcl_WrongNumArgs(interp, 3, objv, "tagName option");
return TCL_ERROR;
}
tagname = Tcl_GetString(objv[3]);
entryPtr = Tcl_FindHashEntry(tablePtr->tagTable, tagname);
if (entryPtr == NULL) {
goto invalidtag;
} else {
tagPtr = (TableTag *) Tcl_GetHashValue (entryPtr);
result = Tk_ConfigureValue(interp, tablePtr->tkwin, tagConfig,
(char *) tagPtr, Tcl_GetString(objv[4]), 0);
/*
* This is a work-around to fix a bug in Tk_ConfigureValue
* that would set Tcl_GetResult(interp) to NULL for -borderwidth
* which has no associated tag offset value. This was fixed
* in 8.3.5 and 8.4b1. [Bug #522882]
*/
if (Tcl_GetObjResult(interp) == NULL) {
Tcl_SetResult(interp, "",TCL_STATIC);
}
}
return result; /* CGET */
case TAG_CONFIGURE:
if (objc < 4) {
Tcl_WrongNumArgs(interp, 3, objv, "tagName ?arg arg ...?");
return TCL_ERROR;
}
/*
* Get the pointer to the tag structure. If it doesn't
* exist, it will be created.
*/
tagPtr = TableTagGetEntry(tablePtr, Tcl_GetString(objv[3]),
0, NULL);
/*
* If there were less than 6 args, we return the configuration
* (for all or just one option), even for new tags
*/
if (objc < 6) {
result = Tk_ConfigureInfo(interp, tablePtr->tkwin, tagConfig,
(char *) tagPtr, (objc == 5) ?
Tcl_GetString(objv[4]) : NULL, 0);
} else {
Arg *args;
/* Stringify */
args = (Arg *) ckalloc((objc + 1) * sizeof(Arg));
for (i = 0; i < objc; i++)
args[i] = LangStringArg(Tcl_GetString(objv[i]));
args[objc] = NULL;
result = Tk_ConfigureWidget(interp, tablePtr->tkwin,
tagConfig, objc-4, args+4, (char *) tagPtr,
TK_CONFIG_ARGV_ONLY);
ckfree((char *) args);
if (result == TCL_ERROR) {
return TCL_ERROR;
}
/*
* Handle change of image name
*/
if (tagPtr->imageStr) {
image = Tk_GetImage(interp, tablePtr->tkwin,
tagPtr->imageStr,
TableImageProc, (ClientData)tablePtr);
if (image == NULL) {
result = TCL_ERROR;
}
} else {
image = NULL;
}
if (tagPtr->image) {
Tk_FreeImage(tagPtr->image);
}
tagPtr->image = image;
/*
* We reconfigured, so invalidate the table to redraw
*/
TableInvalidateAll(tablePtr, 0);
}
return result;
case TAG_DELETE:
/* delete a tag */
if (objc < 4) {
Tcl_WrongNumArgs(interp, 3, objv, "tagName ?tagName ...?");
return TCL_ERROR;
}
/* run through the remaining arguments */
for (i = 3; i < objc; i++) {
tagname = Tcl_GetString(objv[i]);
/* cannot delete the title tag */
if (STREQ(tagname, "title") ||
STREQ(tagname, "sel") ||
STREQ(tagname, "flash") ||
STREQ(tagname, "active")) {
Tcl_AppendStringsToObj(resultPtr, "cannot delete ",
tagname, " tag", NULL);
return TCL_ERROR;
}
entryPtr = Tcl_FindHashEntry(tablePtr->tagTable, tagname);
if (entryPtr != NULL) {
/* get the tag pointer */
tagPtr = (TableTag *) Tcl_GetHashValue(entryPtr);
/* delete all references to this tag in rows */
scanPtr = Tcl_FirstHashEntry(tablePtr->rowStyles, &search);
for (; scanPtr != NULL;
scanPtr = Tcl_NextHashEntry(&search)) {
if ((TableTag *)Tcl_GetHashValue(scanPtr) == tagPtr) {
Tcl_DeleteHashEntry(scanPtr);
refresh = 1;
}
}
/* delete all references to this tag in cols */
scanPtr = Tcl_FirstHashEntry(tablePtr->colStyles, &search);
for (; scanPtr != NULL;
scanPtr = Tcl_NextHashEntry(&search)) {
if ((TableTag *)Tcl_GetHashValue(scanPtr) == tagPtr) {
Tcl_DeleteHashEntry(scanPtr);
refresh = 1;
}
}
/* delete all references to this tag in cells */
scanPtr = Tcl_FirstHashEntry(tablePtr->cellStyles,
&search);
for (; scanPtr != NULL;
scanPtr = Tcl_NextHashEntry(&search)) {
if ((TableTag *)Tcl_GetHashValue(scanPtr) == tagPtr) {
Tcl_DeleteHashEntry(scanPtr);
refresh = 1;
}
}
/*
* Remove the tag from the prio list and collapse
* the rest of the tags. We could check for shrinking
* the prio list as well.
*/
for (i = 0; i < tablePtr->tagPrioSize; i++) {
if (tablePtr->tagPrios[i] == tagPtr) break;
}
for ( ; i < tablePtr->tagPrioSize; i++) {
tablePtr->tagPrioNames[i] =
tablePtr->tagPrioNames[i+1];
tablePtr->tagPrios[i] = tablePtr->tagPrios[i+1];
}
tablePtr->tagPrioSize--;
/* Release the tag structure */
TableCleanupTag(tablePtr, tagPtr);
ckfree((char *) tagPtr);
/* And free the hash table entry */
Tcl_DeleteHashEntry(entryPtr);
}
}
/* since we deleted a tag, redraw the screen */
if (refresh) {
TableInvalidateAll(tablePtr, 0);
}
return result;
case TAG_EXISTS:
if (objc != 4) {
Tcl_WrongNumArgs(interp, 3, objv, "tagName");
return TCL_ERROR;
}
Tcl_SetBooleanObj(resultPtr,
(Tcl_FindHashEntry(tablePtr->tagTable,
Tcl_GetString(objv[3])) != NULL));
return TCL_OK;
case TAG_INCLUDES:
/* does a tag contain a index ? */
if (objc != 5) {
Tcl_WrongNumArgs(interp, 3, objv, "tag index");
return TCL_ERROR;
}
tagname = Tcl_GetString(objv[3]);
/* check to see if the tag actually exists */
entryPtr = Tcl_FindHashEntry(tablePtr->tagTable, tagname);
if (entryPtr == NULL) {
/* Unknown tag, just return 0 */
Tcl_SetBooleanObj(resultPtr, 0);
return TCL_OK;
}
/* parse index */
if (TableGetIndexObj(tablePtr, objv[4], &row, &col) != TCL_OK) {
return TCL_ERROR;
}
/* create hash key */
TableMakeArrayIndex(row, col, buf);
if (STREQ(tagname, "active")) {
result = (tablePtr->activeRow+tablePtr->rowOffset==row &&
tablePtr->activeCol+tablePtr->colOffset==col);
} else if (STREQ(tagname, "flash")) {
result = (tablePtr->flashMode &&
(Tcl_FindHashEntry(tablePtr->flashCells, buf)
!= NULL));
} else if (STREQ(tagname, "sel")) {
result = (Tcl_FindHashEntry(tablePtr->selCells, buf) != NULL);
} else if (STREQ(tagname, "title")) {
result = (row < tablePtr->titleRows+tablePtr->rowOffset ||
col < tablePtr->titleCols+tablePtr->colOffset);
} else {
/* get the pointer to the tag structure */
tagPtr = (TableTag *) Tcl_GetHashValue(entryPtr);
scanPtr = Tcl_FindHashEntry(tablePtr->cellStyles, buf);
/*
* Look to see if there is a cell, row, or col tag
* for this cell
*/
result = ((scanPtr &&
(tagPtr == (TableTag *) Tcl_GetHashValue(scanPtr))) ||
(tagPtr == FindRowColTag(tablePtr, row, ROW)) ||
(tagPtr == FindRowColTag(tablePtr, col, COL)));
}
/*
* Because we may call FindRowColTag above, we can't use
* the resultPtr, but this is almost equivalent, and is SAFE
*/
Tcl_SetObjResult(interp, Tcl_NewIntObj(result));
return TCL_OK;
case TAG_NAMES:
/*
* Print out the tag names in priority order
*/
if (objc < 3 || objc > 4) {
Tcl_WrongNumArgs(interp, 3, objv, "?pattern?");
return TCL_ERROR;
}
tagname = (objc == 4) ? Tcl_GetString(objv[3]) : NULL;
for (i = 0; i < tablePtr->tagPrioSize; i++) {
keybuf = tablePtr->tagPrioNames[i];
if (objc == 3 || Tcl_StringMatch(keybuf, tagname)) {
objPtr = Tcl_NewStringObj(keybuf, -1);
Tcl_ListObjAppendElement(NULL, resultPtr, objPtr);
}
}
return TCL_OK;
case TAG_LOWER:
case TAG_RAISE:
/*
* Change priority of the named tag
*/
if (objc != 4 && objc != 5) {
Tcl_WrongNumArgs(interp, 3, objv, (cmdIndex == TAG_LOWER) ?
"tagName ?belowThis?" : "tagName ?aboveThis?");
return TCL_ERROR;
}
tagname = Tcl_GetString(objv[3]);
/* check to see if the tag actually exists */
entryPtr = Tcl_FindHashEntry(tablePtr->tagTable, tagname);
if (entryPtr == NULL) {
goto invalidtag;
}
tagPtr = (TableTag *) Tcl_GetHashValue(entryPtr);
tagPrio = TableTagGetPriority(tablePtr, tagPtr);
keybuf = tablePtr->tagPrioNames[tagPrio];
/*
* In the RAISE case, the priority is one higher (-1) because
* we want the named tag to move above the other in priority.
*/
if (objc == 5) {
tagname = Tcl_GetString(objv[4]);
entryPtr = Tcl_FindHashEntry(tablePtr->tagTable, tagname);
if (entryPtr == NULL) {
goto invalidtag;
}
tag2Ptr = (TableTag *) Tcl_GetHashValue(entryPtr);
if (cmdIndex == TAG_LOWER) {
value = TableTagGetPriority(tablePtr, tag2Ptr);
} else {
value = TableTagGetPriority(tablePtr, tag2Ptr) - 1;
}
} else {
if (cmdIndex == TAG_LOWER) {
/*
* Lower this tag's priority to the bottom.
*/
value = tablePtr->tagPrioSize - 1;
} else {
/*
* Raise this tag's priority to the top.
*/
value = -1;
}
}
if (value < tagPrio) {
/*
* Move tag up in priority.
*/
for (i = tagPrio; i > value; i--) {
tablePtr->tagPrioNames[i] = tablePtr->tagPrioNames[i-1];
tablePtr->tagPrios[i] = tablePtr->tagPrios[i-1];
}
i++;
tablePtr->tagPrioNames[i] = keybuf;
tablePtr->tagPrios[i] = tagPtr;
refresh = 1;
} else if (value > tagPrio) {
/*
* Move tag down in priority.
*/
for (i = tagPrio; i < value; i++) {
tablePtr->tagPrioNames[i] = tablePtr->tagPrioNames[i+1];
tablePtr->tagPrios[i] = tablePtr->tagPrios[i+1];
}
tablePtr->tagPrioNames[i] = keybuf;
tablePtr->tagPrios[i] = tagPtr;
refresh = 1;
}
/* since we deleted a tag, redraw the screen */
if (refresh) {
TableInvalidateAll(tablePtr, 0);
}
return TCL_OK;
}
return TCL_OK;
invalidtag:
/*
* When jumping here, ensure the invalid 'tagname' is set already.
*/
Tcl_AppendStringsToObj(resultPtr, "invalid tag name \"",
tagname, "\"", NULL);
return TCL_ERROR;
}
/*
*----------------------------------------------------------------------
*
* TableOptionReliefSet --
*
* This routine configures the borderwidth value for a tag.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* It may adjust the tag struct values of relief[0..4] and borders.
*
*----------------------------------------------------------------------
*/
static int
TableOptionReliefSet(clientData, interp, tkwin, value, widgRec, offset)
ClientData clientData; /* Type of struct being set. */
Tcl_Interp *interp; /* Used for reporting errors. */
Tk_Window tkwin; /* Window containing table widget. */
Arg value; /* Value of option. */
char *widgRec; /* Pointer to record for item. */
int offset; /* Offset into item. */
{
TableTag *tagPtr = (TableTag *) widgRec;
if (STREQ(Tcl_GetString(value),"")) {
tagPtr->relief = -1;
} else {
return Tk_GetRelief(interp, Tcl_GetString(value), &(tagPtr->relief));
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* TableOptionReliefGet --
*
* Results:
* Value of the tag's -relief option.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static Arg
TableOptionReliefGet(clientData, tkwin, widgRec, offset, freeProcPtr)
ClientData clientData; /* Type of struct being set. */
Tk_Window tkwin; /* Window containing canvas widget. */
char *widgRec; /* Pointer to record for item. */
int offset; /* Offset into item. */
Tcl_FreeProc **freeProcPtr; /* Pointer to variable to fill in with
* information about how to reclaim
* storage for return string. */
{
return LangStringArg( Tk_NameOfRelief(((TableTag *) widgRec)->relief));
}
|