| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#include "tkColor.h" |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
typedef struct { |
| 25 |
int red, green, blue; |
| 26 |
Colormap colormap; |
| 27 |
|
| 28 |
Display *display; |
| 29 |
} ValueKey; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
typedef struct ThreadSpecificData { |
| 37 |
char rgbString[20]; |
| 38 |
} ThreadSpecificData; |
| 39 |
static Tcl_ThreadDataKey dataKey; |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
static void ColorInit _ANSI_ARGS_((TkDisplay *dispPtr)); |
| 46 |
static void DupColorObjProc _ANSI_ARGS_((Tcl_Obj *srcObjPtr, |
| 47 |
Tcl_Obj *dupObjPtr)); |
| 48 |
static void FreeColorObjProc _ANSI_ARGS_((Tcl_Obj *objPtr)); |
| 49 |
static void InitColorObj _ANSI_ARGS_((Tcl_Obj *objPtr)); |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
Tcl_ObjType tkColorObjType = { |
| 58 |
"color", |
| 59 |
FreeColorObjProc, |
| 60 |
DupColorObjProc, |
| 61 |
NULL, |
| 62 |
NULL |
| 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 |
XColor * |
| 91 |
Tk_AllocColorFromObj(interp, tkwin, objPtr) |
| 92 |
Tcl_Interp *interp; |
| 93 |
|
| 94 |
Tk_Window tkwin; |
| 95 |
Tcl_Obj *objPtr; |
| 96 |
|
| 97 |
|
| 98 |
{ |
| 99 |
TkColor *tkColPtr; |
| 100 |
|
| 101 |
if (objPtr->typePtr != &tkColorObjType) { |
| 102 |
InitColorObj(objPtr); |
| 103 |
} |
| 104 |
tkColPtr = (TkColor *) objPtr->internalRep.twoPtrValue.ptr1; |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
if (tkColPtr != NULL) { |
| 112 |
if (tkColPtr->resourceRefCount == 0) { |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
FreeColorObjProc(objPtr); |
| 119 |
tkColPtr = NULL; |
| 120 |
} else if ((Tk_Screen(tkwin) == tkColPtr->screen) |
| 121 |
&& (Tk_Colormap(tkwin) == tkColPtr->colormap)) { |
| 122 |
tkColPtr->resourceRefCount++; |
| 123 |
return (XColor *) tkColPtr; |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
if (tkColPtr != NULL) { |
| 134 |
TkColor *firstColorPtr = |
| 135 |
(TkColor *) Tcl_GetHashValue(tkColPtr->hashPtr); |
| 136 |
FreeColorObjProc(objPtr); |
| 137 |
for (tkColPtr = firstColorPtr; tkColPtr != NULL; |
| 138 |
tkColPtr = tkColPtr->nextPtr) { |
| 139 |
if ((Tk_Screen(tkwin) == tkColPtr->screen) |
| 140 |
&& (Tk_Colormap(tkwin) == tkColPtr->colormap)) { |
| 141 |
tkColPtr->resourceRefCount++; |
| 142 |
tkColPtr->objRefCount++; |
| 143 |
objPtr->internalRep.twoPtrValue.ptr1 = (VOID *) tkColPtr; |
| 144 |
return (XColor *) tkColPtr; |
| 145 |
} |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
tkColPtr = (TkColor *) Tk_GetColor(interp, tkwin, Tcl_GetString(objPtr)); |
| 154 |
objPtr->internalRep.twoPtrValue.ptr1 = (VOID *) tkColPtr; |
| 155 |
if (tkColPtr != NULL) { |
| 156 |
tkColPtr->objRefCount++; |
| 157 |
} |
| 158 |
return (XColor *) tkColPtr; |
| 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 |
XColor * |
| 186 |
Tk_GetColor(interp, tkwin, name) |
| 187 |
Tcl_Interp *interp; |
| 188 |
|
| 189 |
Tk_Window tkwin; |
| 190 |
Tk_Uid name; |
| 191 |
|
| 192 |
{ |
| 193 |
Tcl_HashEntry *nameHashPtr; |
| 194 |
int new; |
| 195 |
TkColor *tkColPtr; |
| 196 |
TkColor *existingColPtr; |
| 197 |
TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr; |
| 198 |
|
| 199 |
if (!dispPtr->colorInit) { |
| 200 |
ColorInit(dispPtr); |
| 201 |
} |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
nameHashPtr = Tcl_CreateHashEntry(&dispPtr->colorNameTable, name, &new); |
| 209 |
if (!new) { |
| 210 |
existingColPtr = (TkColor *) Tcl_GetHashValue(nameHashPtr); |
| 211 |
for (tkColPtr = existingColPtr; tkColPtr != NULL; |
| 212 |
tkColPtr = tkColPtr->nextPtr) { |
| 213 |
if ((tkColPtr->screen == Tk_Screen(tkwin)) |
| 214 |
&& (Tk_Colormap(tkwin) == tkColPtr->colormap)) { |
| 215 |
tkColPtr->resourceRefCount++; |
| 216 |
return &tkColPtr->color; |
| 217 |
} |
| 218 |
} |
| 219 |
} else { |
| 220 |
existingColPtr = NULL; |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
tkColPtr = TkpGetColor(tkwin, name); |
| 229 |
if (tkColPtr == NULL) { |
| 230 |
if (interp != NULL) { |
| 231 |
if (*name == '#') { |
| 232 |
Tcl_AppendResult(interp, "invalid color name \"", name, |
| 233 |
"\"", (char *) NULL); |
| 234 |
} else { |
| 235 |
Tcl_AppendResult(interp, "unknown color name \"", name, |
| 236 |
"\"", (char *) NULL); |
| 237 |
} |
| 238 |
} |
| 239 |
if (new) { |
| 240 |
Tcl_DeleteHashEntry(nameHashPtr); |
| 241 |
} |
| 242 |
return (XColor *) NULL; |
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
tkColPtr->magic = COLOR_MAGIC; |
| 251 |
tkColPtr->gc = None; |
| 252 |
tkColPtr->screen = Tk_Screen(tkwin); |
| 253 |
tkColPtr->colormap = Tk_Colormap(tkwin); |
| 254 |
tkColPtr->visual = Tk_Visual(tkwin); |
| 255 |
tkColPtr->resourceRefCount = 1; |
| 256 |
tkColPtr->objRefCount = 0; |
| 257 |
tkColPtr->type = TK_COLOR_BY_NAME; |
| 258 |
tkColPtr->hashPtr = nameHashPtr; |
| 259 |
tkColPtr->nextPtr = existingColPtr; |
| 260 |
Tcl_SetHashValue(nameHashPtr, tkColPtr); |
| 261 |
|
| 262 |
return &tkColPtr->color; |
| 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 |
XColor * |
| 290 |
Tk_GetColorByValue(tkwin, colorPtr) |
| 291 |
Tk_Window tkwin; |
| 292 |
XColor *colorPtr; |
| 293 |
|
| 294 |
{ |
| 295 |
ValueKey valueKey; |
| 296 |
Tcl_HashEntry *valueHashPtr; |
| 297 |
int new; |
| 298 |
TkColor *tkColPtr; |
| 299 |
Display *display = Tk_Display(tkwin); |
| 300 |
TkDisplay *dispPtr = TkGetDisplay(display); |
| 301 |
|
| 302 |
if (!dispPtr->colorInit) { |
| 303 |
ColorInit(dispPtr); |
| 304 |
} |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
valueKey.red = colorPtr->red; |
| 312 |
valueKey.green = colorPtr->green; |
| 313 |
valueKey.blue = colorPtr->blue; |
| 314 |
valueKey.colormap = Tk_Colormap(tkwin); |
| 315 |
valueKey.display = display; |
| 316 |
valueHashPtr = Tcl_CreateHashEntry(&dispPtr->colorValueTable, |
| 317 |
(char *) &valueKey, &new); |
| 318 |
if (!new) { |
| 319 |
tkColPtr = (TkColor *) Tcl_GetHashValue(valueHashPtr); |
| 320 |
tkColPtr->resourceRefCount++; |
| 321 |
return &tkColPtr->color; |
| 322 |
} |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
tkColPtr = TkpGetColorByValue(tkwin, colorPtr); |
| 330 |
tkColPtr->magic = COLOR_MAGIC; |
| 331 |
tkColPtr->gc = None; |
| 332 |
tkColPtr->screen = Tk_Screen(tkwin); |
| 333 |
tkColPtr->colormap = valueKey.colormap; |
| 334 |
tkColPtr->visual = Tk_Visual(tkwin); |
| 335 |
tkColPtr->resourceRefCount = 1; |
| 336 |
tkColPtr->objRefCount = 0; |
| 337 |
tkColPtr->type = TK_COLOR_BY_VALUE; |
| 338 |
tkColPtr->hashPtr = valueHashPtr; |
| 339 |
tkColPtr->nextPtr = NULL; |
| 340 |
Tcl_SetHashValue(valueHashPtr, tkColPtr); |
| 341 |
return &tkColPtr->color; |
| 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 |
CONST char * |
| 367 |
Tk_NameOfColor(colorPtr) |
| 368 |
XColor *colorPtr; |
| 369 |
{ |
| 370 |
register TkColor *tkColPtr = (TkColor *) colorPtr; |
| 371 |
|
| 372 |
if ((tkColPtr->magic == COLOR_MAGIC) && |
| 373 |
(tkColPtr->type == TK_COLOR_BY_NAME)) { |
| 374 |
return tkColPtr->hashPtr->key.string; |
| 375 |
} else { |
| 376 |
ThreadSpecificData *tsdPtr = (ThreadSpecificData *) |
| 377 |
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); |
| 378 |
sprintf(tsdPtr->rgbString, "#%04x%04x%04x", colorPtr->red, |
| 379 |
colorPtr->green, colorPtr->blue); |
| 380 |
return tsdPtr->rgbString; |
| 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 |
GC |
| 406 |
Tk_GCForColor(colorPtr, drawable) |
| 407 |
XColor *colorPtr; |
| 408 |
|
| 409 |
Drawable drawable; |
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
{ |
| 414 |
TkColor *tkColPtr = (TkColor *) colorPtr; |
| 415 |
XGCValues gcValues; |
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
if (tkColPtr->magic != COLOR_MAGIC) { |
| 423 |
panic("Tk_GCForColor called with bogus color"); |
| 424 |
} |
| 425 |
|
| 426 |
if (tkColPtr->gc == None) { |
| 427 |
gcValues.foreground = tkColPtr->color.pixel; |
| 428 |
tkColPtr->gc = XCreateGC(DisplayOfScreen(tkColPtr->screen), |
| 429 |
drawable, GCForeground, &gcValues); |
| 430 |
} |
| 431 |
return tkColPtr->gc; |
| 432 |
} |
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
void |
| 454 |
Tk_FreeColor(colorPtr) |
| 455 |
XColor *colorPtr; |
| 456 |
|
| 457 |
|
| 458 |
{ |
| 459 |
TkColor *tkColPtr = (TkColor *) colorPtr; |
| 460 |
Screen *screen = tkColPtr->screen; |
| 461 |
TkColor *prevPtr; |
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
if (tkColPtr->magic != COLOR_MAGIC) { |
| 469 |
panic("Tk_FreeColor called with bogus color"); |
| 470 |
} |
| 471 |
|
| 472 |
tkColPtr->resourceRefCount--; |
| 473 |
if (tkColPtr->resourceRefCount > 0) { |
| 474 |
return; |
| 475 |
} |
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
if (tkColPtr->gc != None) { |
| 484 |
XFreeGC(DisplayOfScreen(screen), tkColPtr->gc); |
| 485 |
tkColPtr->gc = None; |
| 486 |
} |
| 487 |
TkpFreeColor(tkColPtr); |
| 488 |
|
| 489 |
prevPtr = (TkColor *) Tcl_GetHashValue(tkColPtr->hashPtr); |
| 490 |
if (prevPtr == tkColPtr) { |
| 491 |
if (tkColPtr->nextPtr == NULL) { |
| 492 |
Tcl_DeleteHashEntry(tkColPtr->hashPtr); |
| 493 |
} else { |
| 494 |
Tcl_SetHashValue(tkColPtr->hashPtr, tkColPtr->nextPtr); |
| 495 |
} |
| 496 |
} else { |
| 497 |
while (prevPtr->nextPtr != tkColPtr) { |
| 498 |
prevPtr = prevPtr->nextPtr; |
| 499 |
} |
| 500 |
prevPtr->nextPtr = tkColPtr->nextPtr; |
| 501 |
} |
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
if (tkColPtr->objRefCount == 0) { |
| 511 |
ckfree((char *) tkColPtr); |
| 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 |
void |
| 537 |
Tk_FreeColorFromObj(tkwin, objPtr) |
| 538 |
Tk_Window tkwin; |
| 539 |
|
| 540 |
Tcl_Obj *objPtr; |
| 541 |
{ |
| 542 |
Tk_FreeColor(Tk_GetColorFromObj(tkwin, objPtr)); |
| 543 |
FreeColorObjProc(objPtr); |
| 544 |
} |
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
static void |
| 567 |
FreeColorObjProc(objPtr) |
| 568 |
Tcl_Obj *objPtr; |
| 569 |
{ |
| 570 |
TkColor *tkColPtr = (TkColor *) objPtr->internalRep.twoPtrValue.ptr1; |
| 571 |
|
| 572 |
if (tkColPtr != NULL) { |
| 573 |
tkColPtr->objRefCount--; |
| 574 |
if ((tkColPtr->objRefCount == 0) |
| 575 |
&& (tkColPtr->resourceRefCount == 0)) { |
| 576 |
ckfree((char *) tkColPtr); |
| 577 |
} |
| 578 |
objPtr->internalRep.twoPtrValue.ptr1 = (VOID *) NULL; |
| 579 |
} |
| 580 |
} |
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
static void |
| 601 |
DupColorObjProc(srcObjPtr, dupObjPtr) |
| 602 |
Tcl_Obj *srcObjPtr; |
| 603 |
Tcl_Obj *dupObjPtr; |
| 604 |
{ |
| 605 |
TkColor *tkColPtr = (TkColor *) srcObjPtr->internalRep.twoPtrValue.ptr1; |
| 606 |
|
| 607 |
dupObjPtr->typePtr = srcObjPtr->typePtr; |
| 608 |
dupObjPtr->internalRep.twoPtrValue.ptr1 = (VOID *) tkColPtr; |
| 609 |
|
| 610 |
if (tkColPtr != NULL) { |
| 611 |
tkColPtr->objRefCount++; |
| 612 |
} |
| 613 |
} |
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
XColor * |
| 636 |
Tk_GetColorFromObj(tkwin, objPtr) |
| 637 |
Tk_Window tkwin; |
| 638 |
|
| 639 |
Tcl_Obj *objPtr; |
| 640 |
|
| 641 |
{ |
| 642 |
TkColor *tkColPtr; |
| 643 |
Tcl_HashEntry *hashPtr; |
| 644 |
TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr; |
| 645 |
|
| 646 |
if (objPtr->typePtr != &tkColorObjType) { |
| 647 |
InitColorObj(objPtr); |
| 648 |
} |
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
tkColPtr = (TkColor *) objPtr->internalRep.twoPtrValue.ptr1; |
| 656 |
if ((tkColPtr != NULL) |
| 657 |
&& (tkColPtr->resourceRefCount > 0) |
| 658 |
&& (Tk_Screen(tkwin) == tkColPtr->screen) |
| 659 |
&& (Tk_Colormap(tkwin) == tkColPtr->colormap)) { |
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
return (XColor *) tkColPtr; |
| 666 |
} |
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
hashPtr = Tcl_FindHashEntry(&dispPtr->colorNameTable, |
| 677 |
Tcl_GetString(objPtr)); |
| 678 |
if (hashPtr == NULL) { |
| 679 |
goto error; |
| 680 |
} |
| 681 |
for (tkColPtr = (TkColor *) Tcl_GetHashValue(hashPtr); |
| 682 |
(tkColPtr != NULL); tkColPtr = tkColPtr->nextPtr) { |
| 683 |
if ((Tk_Screen(tkwin) == tkColPtr->screen) |
| 684 |
&& (Tk_Colormap(tkwin) == tkColPtr->colormap)) { |
| 685 |
FreeColorObjProc(objPtr); |
| 686 |
objPtr->internalRep.twoPtrValue.ptr1 = (VOID *) tkColPtr; |
| 687 |
tkColPtr->objRefCount++; |
| 688 |
return (XColor *) tkColPtr; |
| 689 |
} |
| 690 |
} |
| 691 |
|
| 692 |
error: |
| 693 |
panic(" Tk_GetColorFromObj called with non-existent color!"); |
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
return NULL; |
| 698 |
} |
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
static void |
| 720 |
InitColorObj(objPtr) |
| 721 |
Tcl_Obj *objPtr; |
| 722 |
{ |
| 723 |
Tcl_ObjType *typePtr; |
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
Tcl_GetString(objPtr); |
| 730 |
typePtr = objPtr->typePtr; |
| 731 |
if ((typePtr != NULL) && (typePtr->freeIntRepProc != NULL)) { |
| 732 |
(*typePtr->freeIntRepProc)(objPtr); |
| 733 |
} |
| 734 |
TclObjSetType(objPtr,&tkColorObjType); |
| 735 |
objPtr->internalRep.twoPtrValue.ptr1 = (VOID *) NULL; |
| 736 |
} |
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
static void |
| 755 |
ColorInit(dispPtr) |
| 756 |
TkDisplay *dispPtr; |
| 757 |
{ |
| 758 |
if (!dispPtr->colorInit) { |
| 759 |
dispPtr->colorInit = 1; |
| 760 |
Tcl_InitHashTable(&dispPtr->colorNameTable, TCL_STRING_KEYS); |
| 761 |
Tcl_InitHashTable(&dispPtr->colorValueTable, |
| 762 |
sizeof(ValueKey)/sizeof(int)); |
| 763 |
} |
| 764 |
} |
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
Tcl_Obj * |
| 786 |
TkDebugColor(tkwin, name) |
| 787 |
Tk_Window tkwin; |
| 788 |
|
| 789 |
char *name; |
| 790 |
{ |
| 791 |
TkColor *tkColPtr; |
| 792 |
Tcl_HashEntry *hashPtr; |
| 793 |
Tcl_Obj *resultPtr, *objPtr; |
| 794 |
TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr; |
| 795 |
|
| 796 |
resultPtr = Tcl_NewObj(); |
| 797 |
hashPtr = Tcl_FindHashEntry(&dispPtr->colorNameTable, name); |
| 798 |
if (hashPtr != NULL) { |
| 799 |
tkColPtr = (TkColor *) Tcl_GetHashValue(hashPtr); |
| 800 |
if (tkColPtr == NULL) { |
| 801 |
panic("TkDebugColor found empty hash table entry"); |
| 802 |
} |
| 803 |
for ( ; (tkColPtr != NULL); tkColPtr = tkColPtr->nextPtr) { |
| 804 |
objPtr = Tcl_NewObj(); |
| 805 |
Tcl_ListObjAppendElement(NULL, objPtr, |
| 806 |
Tcl_NewIntObj(tkColPtr->resourceRefCount)); |
| 807 |
Tcl_ListObjAppendElement(NULL, objPtr, |
| 808 |
Tcl_NewIntObj(tkColPtr->objRefCount)); |
| 809 |
Tcl_ListObjAppendElement(NULL, resultPtr, objPtr); |
| 810 |
} |
| 811 |
} |
| 812 |
return resultPtr; |
| 813 |
} |
| 814 |
|
| 815 |
|