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
|
/* This file copied from Tk 8.4.19 and modified to continue support the now
deprecated TK_CONFIG_OPTION_SPECIFIED flag. */
/*
* tkOldConfig.c --
*
* This file contains the Tk_ConfigureWidget procedure. THIS FILE
* IS HERE FOR BACKWARD COMPATIBILITY; THE NEW CONFIGURATION
* PACKAGE SHOULD BE USED FOR NEW PROJECTS.
*
* Copyright (c) 1990-1994 The Regents of the University of California.
* Copyright (c) 1994-1997 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* RCS: @(#) $Id: bltOldConfig.c,v 1.3 2009/10/25 04:30:52 pcmacdon Exp $
*/
#include "tk.h"
#include "bltOldConfig.h"
/*
* Values for "flags" field of Tk_ConfigSpec structures. Be sure
* to coordinate these values with those defined in tk.h
* (TK_CONFIG_COLOR_ONLY, etc.). There must not be overlap!
*
* INIT - Non-zero means (char *) things have been
* converted to Tk_Uid's.
*/
#define INIT 0x20
/*
* Forward declarations for procedures defined later in this file:
*/
static int DoConfig _ANSI_ARGS_((Tcl_Interp *interp,
Tk_Window tkwin, Tk_ConfigSpec *specPtr,
Tk_Uid value, int valueIsUid, char *widgRec));
static Tk_ConfigSpec * FindConfigSpec _ANSI_ARGS_((Tcl_Interp *interp,
Tk_ConfigSpec *specs, CONST char *argvName,
int needFlags, int hateFlags));
static char * FormatConfigInfo _ANSI_ARGS_((Tcl_Interp *interp,
Tk_Window tkwin, Tk_ConfigSpec *specPtr,
char *widgRec));
static CONST char * FormatConfigValue _ANSI_ARGS_((Tcl_Interp *interp,
Tk_Window tkwin, Tk_ConfigSpec *specPtr,
char *widgRec, char *buffer,
Tcl_FreeProc **freeProcPtr));
static Tk_ConfigSpec * GetCachedSpecs _ANSI_ARGS_((Tcl_Interp *interp,
const Tk_ConfigSpec *staticSpecs));
static void DeleteSpecCacheTable _ANSI_ARGS_((
ClientData clientData, Tcl_Interp *interp));
/*
*--------------------------------------------------------------
*
* Blt_ConfigureWidget --
*
* Process command-line options and database options to
* fill in fields of a widget record with resources and
* other parameters.
*
* Results:
* A standard Tcl return value. In case of an error,
* the interp's result will hold an error message.
*
* Side effects:
* The fields of widgRec get filled in with information from
* argc/argv and the option database. Old information in
* widgRec's fields gets recycled. A copy of the spec-table is
* taken with (some of) the char* *fields converted into Tk_Uid
* fields; this copy will be released when *the interpreter
* terminates.
*
*--------------------------------------------------------------
*/
int
Blt_ConfigureWidget(interp, tkwin, origSpecs, argc, argv, widgRec, flags)
Tcl_Interp *interp; /* Interpreter for error reporting. */
Tk_Window tkwin; /* Window containing widget (needed to
* set up X resources). */
Tk_ConfigSpec *origSpecs; /* Describes legal options. */
int argc; /* Number of elements in argv. */
CONST char **argv; /* Command-line options. */
char *widgRec; /* Record whose fields are to be
* modified. Values must be properly
* initialized. */
int flags; /* Used to specify additional flags
* that must be present in config specs
* for them to be considered. Also,
* may have TK_CONFIG_ARGV_ONLY set. */
{
register Tk_ConfigSpec *specs, *specPtr, *origSpecPtr;
Tk_Uid value; /* Value of option from database. */
int needFlags; /* Specs must contain this set of flags
* or else they are not considered. */
int hateFlags; /* If a spec contains any bits here, it's
* not considered. */
if (tkwin == NULL) {
/*
* Either we're not really in Tk, or the main window was destroyed and
* we're on our way out of the application
*/
Tcl_AppendResult(interp, "NULL main window", (char *)NULL);
return TCL_ERROR;
}
needFlags = flags & ~(TK_CONFIG_USER_BIT - 1);
if (Tk_Depth(tkwin) <= 1) {
hateFlags = TK_CONFIG_COLOR_ONLY;
} else {
hateFlags = TK_CONFIG_MONO_ONLY;
}
/*
* Get the build of the config for this interpreter and reset any
* indication of changed options.
*/
specs = GetCachedSpecs(interp, origSpecs);
for (specPtr = specs; specPtr->type != TK_CONFIG_END; specPtr++) {
specPtr->specFlags &= ~TK_CONFIG_OPTION_SPECIFIED;
}
/*
* Pass one: scan through all of the arguments, processing those
* that match entries in the specs.
*/
for ( ; argc > 0; argc -= 2, argv += 2) {
CONST char *arg;
if (flags & TK_CONFIG_OBJS) {
arg = Tcl_GetStringFromObj((Tcl_Obj *) *argv, NULL);
} else {
arg = *argv;
}
specPtr = FindConfigSpec(interp, specs, arg, needFlags, hateFlags);
if (specPtr == NULL) {
return TCL_ERROR;
}
/*
* Process the entry.
*/
if (argc < 2) {
Tcl_AppendResult(interp, "value for \"", arg,
"\" missing", (char *) NULL);
return TCL_ERROR;
}
if (flags & TK_CONFIG_OBJS) {
arg = Tcl_GetString((Tcl_Obj *) argv[1]);
} else {
arg = argv[1];
}
if (DoConfig(interp, tkwin, specPtr, arg, 0, widgRec) != TCL_OK) {
char msg[100];
sprintf(msg, "\n (processing \"%.40s\" option)",
specPtr->argvName);
Tcl_AddErrorInfo(interp, msg);
return TCL_ERROR;
}
specPtr->specFlags |= TK_CONFIG_OPTION_SPECIFIED;
}
/*
* Thread Unsafe! For compatibility through 8.4.x, we set the original
* specPtr flags to indicate changed options. This has been removed
* from 8.5. Switch to Tcl_Obj-based options instead. [Bug 749908]
*/
for (origSpecPtr = origSpecs, specPtr = specs;
specPtr->type != TK_CONFIG_END; origSpecPtr++, specPtr++) {
origSpecPtr->specFlags = specPtr->specFlags;
}
/*
* Pass two: scan through all of the specs again; if no
* command-line argument matched a spec, then check for info
* in the option database. If there was nothing in the
* database, then use the default.
*/
if (!(flags & TK_CONFIG_ARGV_ONLY)) {
for (specPtr=specs; specPtr->type!=TK_CONFIG_END; specPtr++) {
if ((specPtr->specFlags & TK_CONFIG_OPTION_SPECIFIED)
|| (specPtr->argvName == NULL)
|| (specPtr->type == TK_CONFIG_SYNONYM)) {
continue;
}
if (((specPtr->specFlags & needFlags) != needFlags)
|| (specPtr->specFlags & hateFlags)) {
continue;
}
value = NULL;
if (specPtr->dbName != NULL) {
value = Tk_GetOption(tkwin, specPtr->dbName, specPtr->dbClass);
}
if (value != NULL) {
if (DoConfig(interp, tkwin, specPtr, value, 1, widgRec) !=
TCL_OK) {
char msg[200];
sprintf(msg, "\n (%s \"%.50s\" in widget \"%.50s\")",
"database entry for",
specPtr->dbName, Tk_PathName(tkwin));
if (getenv("TCL_BADOPTS") == NULL) {
fprintf(stderr, "%s%s\n", Tcl_GetStringResult(interp), msg);
value = NULL;
goto dodefault;
}
Tcl_AddErrorInfo(interp, msg);
return TCL_ERROR;
}
} else {
dodefault:
if (specPtr->defValue != NULL) {
value = Tk_GetUid(specPtr->defValue);
} else {
value = NULL;
}
if ((value != NULL) && !(specPtr->specFlags
& TK_CONFIG_DONT_SET_DEFAULT)) {
if (DoConfig(interp, tkwin, specPtr, value, 1, widgRec) !=
TCL_OK) {
char msg[200];
sprintf(msg,
"\n (%s \"%.50s\" in widget \"%.50s\")",
"default value for",
specPtr->dbName, Tk_PathName(tkwin));
Tcl_AddErrorInfo(interp, msg);
return TCL_ERROR;
}
}
}
}
}
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* FindConfigSpec --
*
* Search through a table of configuration specs, looking for
* one that matches a given argvName.
*
* Results:
* The return value is a pointer to the matching entry, or NULL
* if nothing matched. In that case an error message is left
* in the interp's result.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
static Tk_ConfigSpec *
FindConfigSpec(interp, specs, argvName, needFlags, hateFlags)
Tcl_Interp *interp; /* Used for reporting errors. */
Tk_ConfigSpec *specs; /* Pointer to table of configuration
* specifications for a widget. */
CONST char *argvName; /* Name (suitable for use in a "config"
* command) identifying particular option. */
int needFlags; /* Flags that must be present in matching
* entry. */
int hateFlags; /* Flags that must NOT be present in
* matching entry. */
{
register Tk_ConfigSpec *specPtr;
register char c; /* First character of current argument. */
Tk_ConfigSpec *matchPtr; /* Matching spec, or NULL. */
size_t length;
c = argvName[1];
length = strlen(argvName);
matchPtr = NULL;
for (specPtr = specs; specPtr->type != TK_CONFIG_END; specPtr++) {
if (specPtr->argvName == NULL) {
continue;
}
if ((specPtr->argvName[1] != c)
|| (strncmp(specPtr->argvName, argvName, length) != 0)) {
continue;
}
if (((specPtr->specFlags & needFlags) != needFlags)
|| (specPtr->specFlags & hateFlags)) {
continue;
}
if (specPtr->argvName[length] == 0) {
matchPtr = specPtr;
goto gotMatch;
}
if (matchPtr != NULL) {
Tcl_AppendResult(interp, "ambiguous option \"", argvName,
"\"", (char *) NULL);
return (Tk_ConfigSpec *) NULL;
}
matchPtr = specPtr;
}
if (matchPtr == NULL) {
Tcl_AppendResult(interp, "unknown option \"", argvName,
"\"", (char *) NULL);
return (Tk_ConfigSpec *) NULL;
}
/*
* Found a matching entry. If it's a synonym, then find the
* entry that it's a synonym for.
*/
gotMatch:
specPtr = matchPtr;
if (specPtr->type == TK_CONFIG_SYNONYM) {
for (specPtr = specs; ; specPtr++) {
if (specPtr->type == TK_CONFIG_END) {
Tcl_AppendResult(interp,
"couldn't find synonym for option \"",
argvName, "\"", (char *) NULL);
return (Tk_ConfigSpec *) NULL;
}
if ((specPtr->dbName == matchPtr->dbName)
&& (specPtr->type != TK_CONFIG_SYNONYM)
&& ((specPtr->specFlags & needFlags) == needFlags)
&& !(specPtr->specFlags & hateFlags)) {
break;
}
}
}
return specPtr;
}
/*
*--------------------------------------------------------------
*
* DoConfig --
*
* This procedure applies a single configuration option
* to a widget record.
*
* Results:
* A standard Tcl return value.
*
* Side effects:
* WidgRec is modified as indicated by specPtr and value.
* The old value is recycled, if that is appropriate for
* the value type.
*
*--------------------------------------------------------------
*/
static int
DoConfig(interp, tkwin, specPtr, value, valueIsUid, widgRec)
Tcl_Interp *interp; /* Interpreter for error reporting. */
Tk_Window tkwin; /* Window containing widget (needed to
* set up X resources). */
Tk_ConfigSpec *specPtr; /* Specifier to apply. */
Tk_Uid value; /* Value to use to fill in widgRec. */
int valueIsUid; /* Non-zero means value is a Tk_Uid;
* zero means it's an ordinary string. */
char *widgRec; /* Record whose fields are to be
* modified. Values must be properly
* initialized. */
{
char *ptr;
Tk_Uid uid;
int nullValue;
nullValue = 0;
if ((*value == 0) && (specPtr->specFlags & TK_CONFIG_NULL_OK)) {
nullValue = 1;
}
do {
ptr = widgRec + specPtr->offset;
switch (specPtr->type) {
case TK_CONFIG_BOOLEAN:
if (Tcl_GetBoolean(interp, value, (int *) ptr) != TCL_OK) {
return TCL_ERROR;
}
break;
case TK_CONFIG_INT:
if (Tcl_GetInt(interp, value, (int *) ptr) != TCL_OK) {
return TCL_ERROR;
}
break;
case TK_CONFIG_DOUBLE:
if (Tcl_GetDouble(interp, value, (double *) ptr) != TCL_OK) {
return TCL_ERROR;
}
break;
case TK_CONFIG_STRING: {
char *old, *new;
if (nullValue) {
new = NULL;
} else {
new = (char *) ckalloc((unsigned) (strlen(value) + 1));
strcpy(new, value);
}
old = *((char **) ptr);
if (old != NULL) {
ckfree(old);
}
*((char **) ptr) = new;
break;
}
case TK_CONFIG_UID:
if (nullValue) {
*((Tk_Uid *) ptr) = NULL;
} else {
uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
*((Tk_Uid *) ptr) = uid;
}
break;
case TK_CONFIG_COLOR: {
XColor *newPtr, *oldPtr;
if (nullValue) {
newPtr = NULL;
} else {
uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
newPtr = Tk_GetColor(interp, tkwin, uid);
if (newPtr == NULL) {
return TCL_ERROR;
}
}
oldPtr = *((XColor **) ptr);
if (oldPtr != NULL) {
Tk_FreeColor(oldPtr);
}
*((XColor **) ptr) = newPtr;
break;
}
case TK_CONFIG_FONT: {
Tk_Font new;
if (nullValue) {
new = NULL;
} else {
new = Tk_GetFont(interp, tkwin, value);
if (new == NULL) {
return TCL_ERROR;
}
}
Tk_FreeFont(*((Tk_Font *) ptr));
*((Tk_Font *) ptr) = new;
break;
}
case TK_CONFIG_BITMAP: {
Pixmap new, old;
if (nullValue) {
new = None;
} else {
uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
new = Tk_GetBitmap(interp, tkwin, uid);
if (new == None) {
return TCL_ERROR;
}
}
old = *((Pixmap *) ptr);
if (old != None) {
Tk_FreeBitmap(Tk_Display(tkwin), old);
}
*((Pixmap *) ptr) = new;
break;
}
case TK_CONFIG_BORDER: {
Tk_3DBorder new, old;
if (nullValue) {
new = NULL;
} else {
uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
new = Tk_Get3DBorder(interp, tkwin, uid);
if (new == NULL) {
return TCL_ERROR;
}
}
old = *((Tk_3DBorder *) ptr);
if (old != NULL) {
Tk_Free3DBorder(old);
}
*((Tk_3DBorder *) ptr) = new;
break;
}
case TK_CONFIG_RELIEF:
uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
if (Tk_GetRelief(interp, uid, (int *) ptr) != TCL_OK) {
return TCL_ERROR;
}
break;
case TK_CONFIG_CURSOR:
case TK_CONFIG_ACTIVE_CURSOR: {
Tk_Cursor new, old;
if (nullValue) {
new = None;
} else {
uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
new = Tk_GetCursor(interp, tkwin, uid);
if (new == None) {
return TCL_ERROR;
}
}
old = *((Tk_Cursor *) ptr);
if (old != None) {
Tk_FreeCursor(Tk_Display(tkwin), old);
}
*((Tk_Cursor *) ptr) = new;
if (specPtr->type == TK_CONFIG_ACTIVE_CURSOR) {
Tk_DefineCursor(tkwin, new);
}
break;
}
case TK_CONFIG_JUSTIFY:
uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
if (Tk_GetJustify(interp, uid, (Tk_Justify *) ptr) != TCL_OK) {
return TCL_ERROR;
}
break;
case TK_CONFIG_ANCHOR:
uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
if (Tk_GetAnchor(interp, uid, (Tk_Anchor *) ptr) != TCL_OK) {
return TCL_ERROR;
}
break;
case TK_CONFIG_CAP_STYLE:
uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
if (Tk_GetCapStyle(interp, uid, (int *) ptr) != TCL_OK) {
return TCL_ERROR;
}
break;
case TK_CONFIG_JOIN_STYLE:
uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
if (Tk_GetJoinStyle(interp, uid, (int *) ptr) != TCL_OK) {
return TCL_ERROR;
}
break;
case TK_CONFIG_PIXELS:
if (Tk_GetPixels(interp, tkwin, value, (int *) ptr)
!= TCL_OK) {
return TCL_ERROR;
}
break;
case TK_CONFIG_MM:
if (Tk_GetScreenMM(interp, tkwin, value, (double *) ptr)
!= TCL_OK) {
return TCL_ERROR;
}
break;
case TK_CONFIG_WINDOW: {
Tk_Window tkwin2;
if (nullValue) {
tkwin2 = NULL;
} else {
tkwin2 = Tk_NameToWindow(interp, value, tkwin);
if (tkwin2 == NULL) {
return TCL_ERROR;
}
}
*((Tk_Window *) ptr) = tkwin2;
break;
}
case TK_CONFIG_CUSTOM:
if ((*specPtr->customPtr->parseProc)(
specPtr->customPtr->clientData, interp, tkwin,
(char *)value, widgRec, specPtr->offset) != TCL_OK) {
return TCL_ERROR;
}
break;
default: {
char buf[64 + TCL_INTEGER_SPACE];
sprintf(buf, "bad config table: unknown type %d",
specPtr->type);
Tcl_SetResult(interp, buf, TCL_VOLATILE);
return TCL_ERROR;
}
}
specPtr++;
} while ((specPtr->argvName == NULL) && (specPtr->type != TK_CONFIG_END));
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* Blt_ConfigureInfo --
*
* Return information about the configuration options
* for a window, and their current values.
*
* Results:
* Always returns TCL_OK. The interp's result will be modified
* hold a description of either a single configuration option
* available for "widgRec" via "specs", or all the configuration
* options available. In the "all" case, the result will
* available for "widgRec" via "specs". The result will
* be a list, each of whose entries describes one option.
* Each entry will itself be a list containing the option's
* name for use on command lines, database name, database
* class, default value, and current value (empty string
* if none). For options that are synonyms, the list will
* contain only two values: name and synonym name. If the
* "name" argument is non-NULL, then the only information
* returned is that for the named argument (i.e. the corresponding
* entry in the overall list is returned).
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
int
Blt_ConfigureInfo(interp, tkwin, specs, widgRec, argvName, flags)
Tcl_Interp *interp; /* Interpreter for error reporting. */
Tk_Window tkwin; /* Window corresponding to widgRec. */
Tk_ConfigSpec *specs; /* Describes legal options. */
char *widgRec; /* Record whose fields contain current
* values for options. */
CONST char *argvName; /* If non-NULL, indicates a single option
* whose info is to be returned. Otherwise
* info is returned for all options. */
int flags; /* Used to specify additional flags
* that must be present in config specs
* for them to be considered. */
{
register Tk_ConfigSpec *specPtr;
int needFlags, hateFlags;
char *list;
char *leader = "{";
needFlags = flags & ~(TK_CONFIG_USER_BIT - 1);
if (Tk_Depth(tkwin) <= 1) {
hateFlags = TK_CONFIG_COLOR_ONLY;
} else {
hateFlags = TK_CONFIG_MONO_ONLY;
}
/*
* Get the build of the config for this interpreter.
*/
specs = GetCachedSpecs(interp, specs);
/*
* If information is only wanted for a single configuration
* spec, then handle that one spec specially.
*/
Tcl_SetResult(interp, (char *) NULL, TCL_STATIC);
if (argvName != NULL) {
specPtr = FindConfigSpec(interp, specs, argvName, needFlags,hateFlags);
if (specPtr == NULL) {
return TCL_ERROR;
}
Tcl_SetResult(interp,
FormatConfigInfo(interp, tkwin, specPtr, widgRec),
TCL_DYNAMIC);
return TCL_OK;
}
/*
* Loop through all the specs, creating a big list with all
* their information.
*/
for (specPtr = specs; specPtr->type != TK_CONFIG_END; specPtr++) {
if ((argvName != NULL) && (specPtr->argvName != argvName)) {
continue;
}
if (((specPtr->specFlags & needFlags) != needFlags)
|| (specPtr->specFlags & hateFlags)) {
continue;
}
if (specPtr->argvName == NULL) {
continue;
}
list = FormatConfigInfo(interp, tkwin, specPtr, widgRec);
Tcl_AppendResult(interp, leader, list, "}", (char *) NULL);
ckfree(list);
leader = " {";
}
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* FormatConfigInfo --
*
* Create a valid Tcl list holding the configuration information
* for a single configuration option.
*
* Results:
* A Tcl list, dynamically allocated. The caller is expected to
* arrange for this list to be freed eventually.
*
* Side effects:
* Memory is allocated.
*
*--------------------------------------------------------------
*/
static char *
FormatConfigInfo(interp, tkwin, specPtr, widgRec)
Tcl_Interp *interp; /* Interpreter to use for things
* like floating-point precision. */
Tk_Window tkwin; /* Window corresponding to widget. */
register Tk_ConfigSpec *specPtr; /* Pointer to information describing
* option. */
char *widgRec; /* Pointer to record holding current
* values of info for widget. */
{
CONST char *argv[7];
char *result;
char buffer[200];
Tcl_FreeProc *freeProc = (Tcl_FreeProc *) NULL;
argv[0] = specPtr->argvName;
argv[1] = specPtr->dbName;
argv[2] = specPtr->dbClass;
argv[3] = specPtr->defValue;
if (specPtr->type == TK_CONFIG_SYNONYM) {
return Tcl_Merge(2, (char * CONST *)argv);
}
argv[4] = FormatConfigValue(interp, tkwin, specPtr, widgRec, buffer,
&freeProc);
if (argv[1] == NULL) {
argv[1] = "";
}
if (argv[2] == NULL) {
argv[2] = "";
}
if (argv[3] == NULL) {
argv[3] = "";
}
if (argv[4] == NULL) {
argv[4] = "";
}
if (strstr(Tk_PathName(tkwin), ".__##") &&
specPtr->type < TK_CONFIG_CUSTOM && specPtr->type >=0) {
static char *conftypes[TK_CONFIG_END+10] = {
"bool", "int", "double", "string", "uid", "color", "font",
"bitmap", "border", "relief", "cursor", "activecursor", "justify",
"anchor", "syn", "cap", "join", "pixels", "mm", "window", "custom",
"END"
};
if (conftypes[TK_CONFIG_END] == 0 ||
strcmp(conftypes[TK_CONFIG_END],"END")) {
fprintf(stderr, "Tk_ConfigTypes in blt changed\n");
}
argv[5] = conftypes[specPtr->type];
result = Tcl_Merge(6, (char * CONST *)argv);
} else {
result = Tcl_Merge(5, (char * CONST *)argv);
}
if (freeProc != NULL) {
if ((freeProc == TCL_DYNAMIC) || (freeProc == (Tcl_FreeProc *) free)) {
ckfree((char *)argv[4]);
} else {
(*freeProc)((char *)argv[4]);
}
}
return result;
}
/*
*----------------------------------------------------------------------
*
* FormatConfigValue --
*
* This procedure formats the current value of a configuration
* option.
*
* Results:
* The return value is the formatted value of the option given
* by specPtr and widgRec. If the value is static, so that it
* need not be freed, *freeProcPtr will be set to NULL; otherwise
* *freeProcPtr will be set to the address of a procedure to
* free the result, and the caller must invoke this procedure
* when it is finished with the result.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static CONST char *
FormatConfigValue(interp, tkwin, specPtr, widgRec, buffer, freeProcPtr)
Tcl_Interp *interp; /* Interpreter for use in real conversions. */
Tk_Window tkwin; /* Window corresponding to widget. */
Tk_ConfigSpec *specPtr; /* Pointer to information describing option.
* Must not point to a synonym option. */
char *widgRec; /* Pointer to record holding current
* values of info for widget. */
char *buffer; /* Static buffer to use for small values.
* Must have at least 200 bytes of storage. */
Tcl_FreeProc **freeProcPtr; /* Pointer to word to fill in with address
* of procedure to free the result, or NULL
* if result is static. */
{
CONST char *ptr, *result;
*freeProcPtr = NULL;
ptr = widgRec + specPtr->offset;
result = "";
switch (specPtr->type) {
case TK_CONFIG_BOOLEAN:
if (*((int *) ptr) == 0) {
result = "0";
} else {
result = "1";
}
break;
case TK_CONFIG_INT:
sprintf(buffer, "%d", *((int *) ptr));
result = buffer;
break;
case TK_CONFIG_DOUBLE:
Tcl_PrintDouble(interp, *((double *) ptr), buffer);
result = buffer;
break;
case TK_CONFIG_STRING:
result = (*(char **) ptr);
if (result == NULL) {
result = "";
}
break;
case TK_CONFIG_UID: {
Tk_Uid uid = *((Tk_Uid *) ptr);
if (uid != NULL) {
result = uid;
}
break;
}
case TK_CONFIG_COLOR: {
XColor *colorPtr = *((XColor **) ptr);
if (colorPtr != NULL) {
result = Tk_NameOfColor(colorPtr);
}
break;
}
case TK_CONFIG_FONT: {
Tk_Font tkfont = *((Tk_Font *) ptr);
if (tkfont != NULL) {
result = Tk_NameOfFont(tkfont);
}
break;
}
case TK_CONFIG_BITMAP: {
Pixmap pixmap = *((Pixmap *) ptr);
if (pixmap != None) {
result = Tk_NameOfBitmap(Tk_Display(tkwin), pixmap);
}
break;
}
case TK_CONFIG_BORDER: {
Tk_3DBorder border = *((Tk_3DBorder *) ptr);
if (border != NULL) {
result = Tk_NameOf3DBorder(border);
}
break;
}
case TK_CONFIG_RELIEF:
result = Tk_NameOfRelief(*((int *) ptr));
break;
case TK_CONFIG_CURSOR:
case TK_CONFIG_ACTIVE_CURSOR: {
Tk_Cursor cursor = *((Tk_Cursor *) ptr);
if (cursor != None) {
result = Tk_NameOfCursor(Tk_Display(tkwin), cursor);
}
break;
}
case TK_CONFIG_JUSTIFY:
result = Tk_NameOfJustify(*((Tk_Justify *) ptr));
break;
case TK_CONFIG_ANCHOR:
result = Tk_NameOfAnchor(*((Tk_Anchor *) ptr));
break;
case TK_CONFIG_CAP_STYLE:
result = Tk_NameOfCapStyle(*((int *) ptr));
break;
case TK_CONFIG_JOIN_STYLE:
result = Tk_NameOfJoinStyle(*((int *) ptr));
break;
case TK_CONFIG_PIXELS:
sprintf(buffer, "%d", *((int *) ptr));
result = buffer;
break;
case TK_CONFIG_MM:
Tcl_PrintDouble(interp, *((double *) ptr), buffer);
result = buffer;
break;
case TK_CONFIG_WINDOW: {
Tk_Window ntkwin;
ntkwin = *((Tk_Window *) ptr);
if (ntkwin != NULL) {
result = Tk_PathName(ntkwin);
}
break;
}
case TK_CONFIG_CUSTOM:
result = (*specPtr->customPtr->printProc)(
specPtr->customPtr->clientData, tkwin, widgRec,
specPtr->offset, freeProcPtr);
break;
default:
result = "?? unknown type ??";
}
return result;
}
/*
*----------------------------------------------------------------------
*
* _ConfigureValue --
*
* This procedure returns the current value of a configuration
* option for a widget.
*
* Results:
* The return value is a standard Tcl completion code (TCL_OK or
* TCL_ERROR). The interp's result will be set to hold either the value
* of the option given by argvName (if TCL_OK is returned) or
* an error message (if TCL_ERROR is returned).
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
int
Blt_ConfigureValue(interp, tkwin, specs, widgRec, argvName, flags)
Tcl_Interp *interp; /* Interpreter for error reporting. */
Tk_Window tkwin; /* Window corresponding to widgRec. */
Tk_ConfigSpec *specs; /* Describes legal options. */
char *widgRec; /* Record whose fields contain current
* values for options. */
CONST char *argvName; /* Gives the command-line name for the
* option whose value is to be returned. */
int flags; /* Used to specify additional flags
* that must be present in config specs
* for them to be considered. */
{
Tk_ConfigSpec *specPtr;
int needFlags, hateFlags;
Tcl_FreeProc *freeProc;
CONST char *result;
char buffer[200];
needFlags = flags & ~(TK_CONFIG_USER_BIT - 1);
if (Tk_Depth(tkwin) <= 1) {
hateFlags = TK_CONFIG_COLOR_ONLY;
} else {
hateFlags = TK_CONFIG_MONO_ONLY;
}
/*
* Get the build of the config for this interpreter.
*/
specs = GetCachedSpecs(interp, specs);
specPtr = FindConfigSpec(interp, specs, argvName, needFlags, hateFlags);
if (specPtr == NULL) {
return TCL_ERROR;
}
result = FormatConfigValue(interp, tkwin, specPtr, widgRec, buffer, &freeProc);
Tcl_SetResult(interp, (char *) result, TCL_VOLATILE);
if (freeProc != NULL) {
if ((freeProc == TCL_DYNAMIC) || (freeProc == (Tcl_FreeProc *) free)) {
ckfree((char *)result);
} else {
(*freeProc)((char *)result);
}
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* Blt_FreeOptions --
*
* Free up all resources associated with configuration options.
*
* Results:
* None.
*
* Side effects:
* Any resource in widgRec that is controlled by a configuration
* option (e.g. a Tk_3DBorder or XColor) is freed in the appropriate
* fashion.
*
*----------------------------------------------------------------------
*/
/* ARGSUSED */
void
Blt_FreeOptions(specs, widgRec, display, needFlags)
Tk_ConfigSpec *specs; /* Describes legal options. */
char *widgRec; /* Record whose fields contain current
* values for options. */
Display *display; /* X display; needed for freeing some
* resources. */
int needFlags; /* Used to specify additional flags
* that must be present in config specs
* for them to be considered. */
{
register Tk_ConfigSpec *specPtr;
char *ptr;
for (specPtr = specs; specPtr->type != TK_CONFIG_END; specPtr++) {
if ((specPtr->specFlags & needFlags) != needFlags) {
continue;
}
ptr = widgRec + specPtr->offset;
switch (specPtr->type) {
case TK_CONFIG_STRING:
if (*((char **) ptr) != NULL) {
ckfree(*((char **) ptr));
*((char **) ptr) = NULL;
}
break;
case TK_CONFIG_COLOR:
if (*((XColor **) ptr) != NULL) {
Tk_FreeColor(*((XColor **) ptr));
*((XColor **) ptr) = NULL;
}
break;
case TK_CONFIG_FONT:
Tk_FreeFont(*((Tk_Font *) ptr));
*((Tk_Font *) ptr) = NULL;
break;
case TK_CONFIG_BITMAP:
if (*((Pixmap *) ptr) != None) {
Tk_FreeBitmap(display, *((Pixmap *) ptr));
*((Pixmap *) ptr) = None;
}
break;
case TK_CONFIG_BORDER:
if (*((Tk_3DBorder *) ptr) != NULL) {
Tk_Free3DBorder(*((Tk_3DBorder *) ptr));
*((Tk_3DBorder *) ptr) = NULL;
}
break;
case TK_CONFIG_CURSOR:
case TK_CONFIG_ACTIVE_CURSOR:
if (*((Tk_Cursor *) ptr) != None) {
Tk_FreeCursor(display, *((Tk_Cursor *) ptr));
*((Tk_Cursor *) ptr) = None;
}
}
}
}
Tk_ConfigSpec *
Blt_GetCachedSpecs(interp, staticSpecs)
Tcl_Interp *interp;
const Tk_ConfigSpec *staticSpecs;
{
return GetCachedSpecs(interp, staticSpecs);
}
/*
*--------------------------------------------------------------
*
* GetCachedSpecs --
*
*Returns a writable per-interpreter (and hence thread-local) copy of
*the given spec-table with (some of) the char* fields converted into
*Tk_Uid fields; this copy will be released when the interpreter
*terminates (during AssocData cleanup).
*
* Results:
*A pointer to the copied table.
*
* Notes:
*The conversion to Tk_Uid is only done the first time, when the table
*copy is taken. After that, the table is assumed to have Tk_Uids where
*they are needed. The time of deletion of the caches isn't very
*important unless you've got a lot of code that uses Tk_ConfigureWidget
*(or *Info or *Value} when the interpreter is being deleted.
*
*--------------------------------------------------------------
*/
static Tk_ConfigSpec *
GetCachedSpecs(interp, staticSpecs)
Tcl_Interp *interp; /* Interpreter in which to store the cache. */
const Tk_ConfigSpec *staticSpecs;
/* Value to cache a copy of; it is also used
* as a key into the cache. */
{
Tk_ConfigSpec *cachedSpecs;
Tcl_HashTable *specCacheTablePtr;
Tcl_HashEntry *entryPtr;
int isNew;
/*
* Get (or allocate if it doesn't exist) the hash table that the writable
* copies of the widget specs are stored in. In effect, this is
* self-initializing code.
*/
specCacheTablePtr = (Tcl_HashTable *)
Tcl_GetAssocData(interp, "tkConfigSpec.threadTable", NULL);
if (specCacheTablePtr == NULL) {
specCacheTablePtr = (Tcl_HashTable *) ckalloc(sizeof(Tcl_HashTable));
Tcl_InitHashTable(specCacheTablePtr, TCL_ONE_WORD_KEYS);
Tcl_SetAssocData(interp, "tkConfigSpec.threadTable",
DeleteSpecCacheTable, (ClientData) specCacheTablePtr);
}
/*
* Look up or create the hash entry that the constant specs are mapped to,
* which will have the writable specs as its associated value.
*/
entryPtr = Tcl_CreateHashEntry(specCacheTablePtr, (char *) staticSpecs,
&isNew);
if (isNew) {
unsigned int entrySpace = sizeof(Tk_ConfigSpec);
const Tk_ConfigSpec *staticSpecPtr;
Tk_ConfigSpec *specPtr;
/*
* OK, no working copy in this interpreter so copy. Need to work out
* how much space to allocate first.
*/
for (staticSpecPtr=staticSpecs; staticSpecPtr->type!=TK_CONFIG_END;
staticSpecPtr++) {
entrySpace += sizeof(Tk_ConfigSpec);
}
/*
* Now allocate our working copy's space and copy over the contents
* from the master copy.
*/
cachedSpecs = (Tk_ConfigSpec *) ckalloc(entrySpace);
memcpy((void *) cachedSpecs, (void *) staticSpecs, entrySpace);
Tcl_SetHashValue(entryPtr, (ClientData) cachedSpecs);
/*
* Finally, go through and replace database names, database classes
* and default values with Tk_Uids. This is the bit that has to be
* per-thread.
*/
for (specPtr=cachedSpecs; specPtr->type!=TK_CONFIG_END; specPtr++) {
if (specPtr->argvName != NULL) {
if (specPtr->dbName != NULL) {
specPtr->dbName = Tk_GetUid(specPtr->dbName);
}
if (specPtr->dbClass != NULL) {
specPtr->dbClass = Tk_GetUid(specPtr->dbClass);
}
if (specPtr->defValue != NULL) {
specPtr->defValue = Tk_GetUid(specPtr->defValue);
}
}
}
} else {
cachedSpecs = (Tk_ConfigSpec *) Tcl_GetHashValue(entryPtr);
}
return cachedSpecs;
}
/*
*--------------------------------------------------------------
*
* DeleteSpecCacheTable --
*
* Delete the per-interpreter copy of all the Tk_ConfigSpec tables which
* were stored in the interpreter's assoc-data store.
*
* Results:
* None
*
* Side effects:
* None
*
*--------------------------------------------------------------
*/
static void
DeleteSpecCacheTable(clientData, interp)
ClientData clientData;
Tcl_Interp *interp;
{
Tcl_HashTable *tablePtr = (Tcl_HashTable *) clientData;
Tcl_HashEntry *entryPtr;
Tcl_HashSearch search;
for (entryPtr = Tcl_FirstHashEntry(tablePtr,&search); entryPtr != NULL;
entryPtr = Tcl_NextHashEntry(&search)) {
/*
* Someone else deallocates the Tk_Uids themselves.
*/
ckfree((char *) Tcl_GetHashValue(entryPtr));
}
Tcl_DeleteHashTable(tablePtr);
ckfree((char *) tablePtr);
}
|