| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include "tkInt.h" |
| 17 |
#include "tixPort.h" |
| 18 |
#include "tixInt.h" |
| 19 |
#include "tixImgXpm.h" |
| 20 |
#include "tkVMacro.h" |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
static int ImgXpmCreate _ANSI_ARGS_((Tcl_Interp *interp, |
| 27 |
char *name, int argc, Tcl_Obj *CONST *objv, |
| 28 |
Tk_ImageType *typePtr, Tk_ImageMaster master, |
| 29 |
ClientData *clientDataPtr)); |
| 30 |
static ClientData ImgXpmGet _ANSI_ARGS_((Tk_Window tkwin, |
| 31 |
ClientData clientData)); |
| 32 |
static void ImgXpmDisplay _ANSI_ARGS_((ClientData clientData, |
| 33 |
Display *display, Drawable drawable, |
| 34 |
int imageX, int imageY, int width, int height, |
| 35 |
int drawableX, int drawableY)); |
| 36 |
static void ImgXpmFree _ANSI_ARGS_((ClientData clientData, |
| 37 |
Display *display)); |
| 38 |
static void ImgXpmDelete _ANSI_ARGS_((ClientData clientData)); |
| 39 |
static int ImgXpmCmd _ANSI_ARGS_((ClientData clientData, |
| 40 |
Tcl_Interp *interp, int argc, char **argv)); |
| 41 |
static void ImgXpmCmdDeletedProc _ANSI_ARGS_(( |
| 42 |
ClientData clientData)); |
| 43 |
static void ImgXpmConfigureInstance _ANSI_ARGS_(( |
| 44 |
PixmapInstance *instancePtr)); |
| 45 |
static int ImgXpmConfigureMaster _ANSI_ARGS_(( |
| 46 |
PixmapMaster *masterPtr, int argc, Tcl_Obj *CONST *objv, |
| 47 |
int flags)); |
| 48 |
static int ImgXpmGetData _ANSI_ARGS_((Tcl_Interp *interp, |
| 49 |
PixmapMaster *masterPtr)); |
| 50 |
static char ** ImgXpmGetDataFromFile _ANSI_ARGS_((Tcl_Interp * interp, |
| 51 |
char * string, int * numLines_return)); |
| 52 |
static char ** ImgXpmGetDataFromId _ANSI_ARGS_((Tcl_Interp * interp, |
| 53 |
Tk_Uid id)); |
| 54 |
static char ** ImgXpmGetDataFromString _ANSI_ARGS_((Tcl_Interp*interp, |
| 55 |
char * string, int * numLines_return)); |
| 56 |
static void ImgXpmGetPixmapFromData _ANSI_ARGS_(( |
| 57 |
Tcl_Interp * interp, |
| 58 |
PixmapMaster *masterPtr, |
| 59 |
PixmapInstance *instancePtr)); |
| 60 |
static char * GetType _ANSI_ARGS_((char * colorDefn, |
| 61 |
int * type_ret)); |
| 62 |
static char * GetColor _ANSI_ARGS_((char * colorDefn, |
| 63 |
char * colorName, int * type_ret)); |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
static Tk_ConfigSpec configSpecs[] = { |
| 70 |
{TK_CONFIG_STRING, "-data", (char *) NULL, (char *) NULL, |
| 71 |
(char *) NULL, Tk_Offset(PixmapMaster, dataString), TK_CONFIG_NULL_OK}, |
| 72 |
{TK_CONFIG_STRING, "-file", (char *) NULL, (char *) NULL, |
| 73 |
(char *) NULL, Tk_Offset(PixmapMaster, fileString), TK_CONFIG_NULL_OK}, |
| 74 |
{TK_CONFIG_UID, "-id", (char *) NULL, (char *) NULL, |
| 75 |
(char *) NULL, Tk_Offset(PixmapMaster, id), TK_CONFIG_NULL_OK}, |
| 76 |
{TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL, |
| 77 |
(char *) NULL, 0, 0} |
| 78 |
}; |
| 79 |
|
| 80 |
Tk_ImageType tixPixmapImageType = { |
| 81 |
"pixmap", |
| 82 |
ImgXpmCreate, |
| 83 |
ImgXpmGet, |
| 84 |
ImgXpmDisplay, |
| 85 |
ImgXpmFree, |
| 86 |
ImgXpmDelete, |
| 87 |
NULL, |
| 88 |
(Tk_ImageType *) NULL |
| 89 |
}; |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
static Tcl_HashTable xpmTable; |
| 96 |
static int xpmTableInited = 0; |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
static int |
| 116 |
ImgXpmCreate(interp, name, argc, objv, typePtr, master, clientDataPtr) |
| 117 |
Tcl_Interp *interp; |
| 118 |
|
| 119 |
char *name; |
| 120 |
int argc; |
| 121 |
Tcl_Obj *CONST *objv; |
| 122 |
|
| 123 |
Tk_ImageType *typePtr; |
| 124 |
Tk_ImageMaster master; |
| 125 |
|
| 126 |
ClientData *clientDataPtr; |
| 127 |
|
| 128 |
{ |
| 129 |
PixmapMaster *masterPtr; |
| 130 |
int i; |
| 131 |
|
| 132 |
#ifndef _LANG |
| 133 |
char *argvbuf[10]; |
| 134 |
char **argv = argvbuf; |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
if (argc > 10) { |
| 140 |
argv = (char **) ckalloc(argc * sizeof(char *)); |
| 141 |
} |
| 142 |
for (i = 0; i < argc; i++) { |
| 143 |
argv[i] = TixGetStringFromObj(objv[i], NULL); |
| 144 |
} |
| 145 |
#endif |
| 146 |
|
| 147 |
masterPtr = (PixmapMaster *) ckalloc(sizeof(PixmapMaster)); |
| 148 |
masterPtr->tkMaster = master; |
| 149 |
masterPtr->interp = interp; |
| 150 |
masterPtr->imageCmd = Lang_CreateImage(interp, name, ImgXpmCmd, |
| 151 |
(ClientData) masterPtr, ImgXpmCmdDeletedProc, typePtr); |
| 152 |
|
| 153 |
masterPtr->fileString = NULL; |
| 154 |
masterPtr->dataString = NULL; |
| 155 |
masterPtr->id = NULL; |
| 156 |
masterPtr->data = NULL; |
| 157 |
masterPtr->isDataAlloced = 0; |
| 158 |
masterPtr->instancePtr = NULL; |
| 159 |
|
| 160 |
if (ImgXpmConfigureMaster(masterPtr, argc, objv, 0) != TCL_OK) { |
| 161 |
ImgXpmDelete((ClientData) masterPtr); |
| 162 |
return TCL_ERROR; |
| 163 |
} |
| 164 |
*clientDataPtr = (ClientData) masterPtr; |
| 165 |
return TCL_OK; |
| 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 |
static int |
| 191 |
ImgXpmConfigureMaster(masterPtr, argc, objv, flags) |
| 192 |
PixmapMaster *masterPtr; |
| 193 |
|
| 194 |
int argc; |
| 195 |
Tcl_Obj *CONST *objv; |
| 196 |
int flags; |
| 197 |
|
| 198 |
{ |
| 199 |
PixmapInstance *instancePtr; |
| 200 |
char * oldData, * oldFile; |
| 201 |
Tk_Uid oldId; |
| 202 |
|
| 203 |
oldData = masterPtr->dataString; |
| 204 |
oldFile = masterPtr->fileString; |
| 205 |
oldId = masterPtr->id; |
| 206 |
|
| 207 |
if (Tk_ConfigureWidget(masterPtr->interp, Tk_MainWindow(masterPtr->interp), |
| 208 |
configSpecs, argc, objv, (char *) masterPtr, flags) |
| 209 |
!= TCL_OK) { |
| 210 |
return TCL_ERROR; |
| 211 |
} |
| 212 |
|
| 213 |
if (masterPtr->id != NULL || |
| 214 |
masterPtr->dataString != NULL || |
| 215 |
masterPtr->fileString != NULL) { |
| 216 |
if (ImgXpmGetData(masterPtr->interp, masterPtr) != TCL_OK) { |
| 217 |
goto error; |
| 218 |
} |
| 219 |
} else { |
| 220 |
Tcl_AppendResult(masterPtr->interp, |
| 221 |
"must specify one of -data, -file, -array or -id", NULL); |
| 222 |
goto error; |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
for (instancePtr = masterPtr->instancePtr; instancePtr != NULL; |
| 231 |
instancePtr = instancePtr->nextPtr) { |
| 232 |
ImgXpmConfigureInstance(instancePtr); |
| 233 |
} |
| 234 |
|
| 235 |
if (masterPtr->data) { |
| 236 |
Tk_ImageChanged(masterPtr->tkMaster, 0, 0, |
| 237 |
masterPtr->size[0], masterPtr->size[1], |
| 238 |
masterPtr->size[0], masterPtr->size[1]); |
| 239 |
} else { |
| 240 |
Tk_ImageChanged(masterPtr->tkMaster, 0, 0, 0, 0, 0, 0); |
| 241 |
} |
| 242 |
|
| 243 |
return TCL_OK; |
| 244 |
|
| 245 |
error: |
| 246 |
|
| 247 |
if (masterPtr->dataString && masterPtr->dataString != oldData) { |
| 248 |
ckfree(masterPtr->dataString); |
| 249 |
} |
| 250 |
if (masterPtr->fileString && masterPtr->fileString != oldFile) { |
| 251 |
ckfree(masterPtr->fileString); |
| 252 |
} |
| 253 |
masterPtr->dataString = oldData; |
| 254 |
masterPtr->fileString = oldFile; |
| 255 |
masterPtr->id = oldId; |
| 256 |
return TCL_ERROR; |
| 257 |
} |
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
static int |
| 278 |
ImgXpmGetData(interp, masterPtr) |
| 279 |
Tcl_Interp *interp; |
| 280 |
PixmapMaster *masterPtr; |
| 281 |
{ |
| 282 |
char ** data = NULL; |
| 283 |
int isAllocated = 0; |
| 284 |
int count; |
| 285 |
int numLines; |
| 286 |
int size[2]; |
| 287 |
int cpp; |
| 288 |
int ncolors; |
| 289 |
int code = TCL_OK; |
| 290 |
|
| 291 |
if (masterPtr->id != NULL) { |
| 292 |
data = ImgXpmGetDataFromId(interp, masterPtr->id); |
| 293 |
isAllocated = 0; |
| 294 |
} |
| 295 |
else if (masterPtr->fileString != NULL) { |
| 296 |
data = ImgXpmGetDataFromFile(interp, masterPtr->fileString, &numLines); |
| 297 |
isAllocated = 1; |
| 298 |
} |
| 299 |
else if (masterPtr->dataString != NULL) { |
| 300 |
data = ImgXpmGetDataFromString(interp,masterPtr->dataString,&numLines); |
| 301 |
isAllocated = 1; |
| 302 |
} |
| 303 |
else { |
| 304 |
|
| 305 |
panic("ImgXpmGetData(): -data, -file, -array and -id are all NULL"); |
| 306 |
} |
| 307 |
|
| 308 |
if (data == NULL) { |
| 309 |
|
| 310 |
return TCL_ERROR; |
| 311 |
} |
| 312 |
|
| 313 |
|
| 314 |
count = sscanf(data[0],"%i %i %i %i", |
| 315 |
&size[0], &size[1], &ncolors, &cpp); |
| 316 |
|
| 317 |
if (count != 4) { |
| 318 |
code = TCL_ERROR; goto done; |
| 319 |
} |
| 320 |
|
| 321 |
if (isAllocated) { |
| 322 |
if (numLines != size[1] + ncolors + 1) { |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
code = TCL_ERROR; goto done; |
| 327 |
} |
| 328 |
} |
| 329 |
|
| 330 |
done: |
| 331 |
if (code == TCL_OK) { |
| 332 |
if (masterPtr->isDataAlloced && masterPtr->data) { |
| 333 |
ckfree((char*)masterPtr->data); |
| 334 |
} |
| 335 |
masterPtr->isDataAlloced = isAllocated; |
| 336 |
masterPtr->data = data; |
| 337 |
masterPtr->size[0] = size[0]; |
| 338 |
masterPtr->size[1] = size[1]; |
| 339 |
masterPtr->cpp = cpp; |
| 340 |
masterPtr->ncolors = ncolors; |
| 341 |
} else { |
| 342 |
if (isAllocated && data) { |
| 343 |
ckfree((char*)data); |
| 344 |
} |
| 345 |
|
| 346 |
Tcl_ResetResult(interp); |
| 347 |
Tcl_AppendResult(interp, "File format error", NULL); |
| 348 |
} |
| 349 |
|
| 350 |
return code; |
| 351 |
} |
| 352 |
|
| 353 |
static char ** ImgXpmGetDataFromId(interp, id) |
| 354 |
Tcl_Interp * interp; |
| 355 |
Tk_Uid id; |
| 356 |
{ |
| 357 |
Tcl_HashEntry * hashPtr; |
| 358 |
|
| 359 |
if (xpmTableInited == 0) { |
| 360 |
hashPtr = NULL; |
| 361 |
} else { |
| 362 |
hashPtr = Tcl_FindHashEntry(&xpmTable, id); |
| 363 |
} |
| 364 |
|
| 365 |
if (hashPtr == NULL) { |
| 366 |
Tcl_AppendResult(interp, "unknown pixmap ID \"", id, |
| 367 |
"\"", NULL); |
| 368 |
return (char**)NULL; |
| 369 |
} else { |
| 370 |
return (char**)Tcl_GetHashValue(hashPtr); |
| 371 |
} |
| 372 |
} |
| 373 |
|
| 374 |
static char ** ImgXpmGetDataFromString(interp, string, numLines_return) |
| 375 |
Tcl_Interp * interp; |
| 376 |
char * string; |
| 377 |
int * numLines_return; |
| 378 |
{ |
| 379 |
char *quoted; |
| 380 |
char * p; |
| 381 |
int numLines = 0; |
| 382 |
size_t bytes = 0; |
| 383 |
char ** data = NULL; |
| 384 |
char ** ptr; |
| 385 |
char *store; |
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
while (isspace(UCHAR(*string))) { |
| 393 |
++ string; |
| 394 |
} |
| 395 |
|
| 396 |
|
| 397 |
if (strncmp("/* XPM", string, 6) != 0) { |
| 398 |
goto error; |
| 399 |
} |
| 400 |
|
| 401 |
|
| 402 |
for (quoted = NULL, p=string; *p;) { |
| 403 |
if (!quoted) { |
| 404 |
if (*p == '"') { |
| 405 |
quoted = ++p; |
| 406 |
continue; |
| 407 |
} |
| 408 |
|
| 409 |
if (*p == '/' && *(p+1) == '*') { |
| 410 |
*p++ = ' '; |
| 411 |
*p++ = ' '; |
| 412 |
while (1) { |
| 413 |
if (*p == 0) { |
| 414 |
break; |
| 415 |
} |
| 416 |
if (*p == '*' && *(p+1) == '/') { |
| 417 |
*p++ = ' '; |
| 418 |
*p++ = ' '; |
| 419 |
break; |
| 420 |
} |
| 421 |
*p++ = ' '; |
| 422 |
} |
| 423 |
continue; |
| 424 |
} |
| 425 |
++ p; |
| 426 |
} else { |
| 427 |
if (*p == '"') { |
| 428 |
bytes += (p-quoted)+1; |
| 429 |
numLines ++; |
| 430 |
quoted = NULL; |
| 431 |
} |
| 432 |
++ p; |
| 433 |
} |
| 434 |
} |
| 435 |
|
| 436 |
if (numLines == 0) { |
| 437 |
goto error; |
| 438 |
} |
| 439 |
|
| 440 |
bytes += (numLines + 1) * sizeof(char *); |
| 441 |
data = (char **) ckalloc(bytes); |
| 442 |
|
| 443 |
memset((VOID *) data, 0, bytes ); |
| 444 |
|
| 445 |
ptr = data; |
| 446 |
store = (char *) (&data[numLines + 1]); |
| 447 |
|
| 448 |
|
| 449 |
for (p=string; *p;) { |
| 450 |
if (*p != '{') { |
| 451 |
++ p; |
| 452 |
} else { |
| 453 |
++p; |
| 454 |
break; |
| 455 |
} |
| 456 |
} |
| 457 |
|
| 458 |
quoted = NULL; |
| 459 |
|
| 460 |
while (*p) { |
| 461 |
if (!quoted) { |
| 462 |
if (*p == '"') { |
| 463 |
quoted = ++p; |
| 464 |
*ptr++ = store; |
| 465 |
continue; |
| 466 |
} |
| 467 |
|
| 468 |
if (isspace(UCHAR(*p)) || *p == ',') { |
| 469 |
} |
| 470 |
else if (*p == '}') { |
| 471 |
break; |
| 472 |
} |
| 473 |
else { |
| 474 |
goto error; |
| 475 |
} |
| 476 |
++p; |
| 477 |
} |
| 478 |
else { |
| 479 |
if (*p == '"') { |
| 480 |
*store++ = '\0'; |
| 481 |
quoted = NULL; |
| 482 |
} |
| 483 |
else { |
| 484 |
*store++ = *p; |
| 485 |
} |
| 486 |
++ p; |
| 487 |
} |
| 488 |
} |
| 489 |
|
| 490 |
*numLines_return = numLines; |
| 491 |
|
| 492 |
#if 0 |
| 493 |
printf("Lines %d\n",numLines); |
| 494 |
for (ptr = data; *ptr; *ptr++) |
| 495 |
{ |
| 496 |
printf("%d \"%s\"\n",ptr-data,*ptr); |
| 497 |
} |
| 498 |
#endif |
| 499 |
|
| 500 |
return data; |
| 501 |
|
| 502 |
error: |
| 503 |
if (data) { |
| 504 |
ckfree((char *) data); |
| 505 |
data = NULL; |
| 506 |
} |
| 507 |
Tcl_AppendResult(interp, "File format error", NULL); |
| 508 |
*numLines_return = 0; |
| 509 |
return (char**) NULL; |
| 510 |
} |
| 511 |
|
| 512 |
static char ** ImgXpmGetDataFromFile(interp, fileName, numLines_return) |
| 513 |
Tcl_Interp * interp; |
| 514 |
char * fileName; |
| 515 |
int * numLines_return; |
| 516 |
{ |
| 517 |
Tcl_Channel chan; |
| 518 |
int size; |
| 519 |
char ** data; |
| 520 |
struct stat statBuf; |
| 521 |
char *cmdBuffer = NULL; |
| 522 |
Tcl_DString buffer; |
| 523 |
|
| 524 |
fileName = Tcl_TranslateFileName(interp, fileName, &buffer); |
| 525 |
if (fileName == NULL) { |
| 526 |
goto error; |
| 527 |
} |
| 528 |
|
| 529 |
chan = Tcl_OpenFileChannel(interp, fileName, "r", 0); |
| 530 |
if (chan == NULL) { |
| 531 |
goto error; |
| 532 |
} |
| 533 |
|
| 534 |
size = Tcl_Seek(chan, 0, SEEK_END); |
| 535 |
if (size == -1) { |
| 536 |
Tcl_AppendResult(interp, "couldn't seek to end of file \"", fileName, |
| 537 |
"\": ", Tcl_PosixError(interp), (char *) NULL); |
| 538 |
Tcl_Close(interp, chan); |
| 539 |
goto error; |
| 540 |
} |
| 541 |
|
| 542 |
|
| 543 |
if (Tcl_Seek(chan, 0, SEEK_SET) == -1) { |
| 544 |
goto error; |
| 545 |
} |
| 546 |
|
| 547 |
cmdBuffer = (char *) ckalloc((unsigned) size+1); |
| 548 |
size = Tcl_Read(chan, cmdBuffer, size); |
| 549 |
if (size < 0) { |
| 550 |
Tcl_AppendResult(interp, "error in reading file \"", fileName, |
| 551 |
"\": ", Tcl_PosixError(interp), (char *) NULL); |
| 552 |
Tcl_Close(interp,chan); |
| 553 |
goto error; |
| 554 |
} |
| 555 |
|
| 556 |
if (Tcl_Close(interp,chan) != TCL_OK) { |
| 557 |
Tcl_AppendResult(interp, "error closing file \"", fileName, |
| 558 |
"\": ", Tcl_PosixError(interp), (char *) NULL); |
| 559 |
goto error; |
| 560 |
} |
| 561 |
cmdBuffer[size] = 0; |
| 562 |
|
| 563 |
data = ImgXpmGetDataFromString(interp, cmdBuffer, numLines_return); |
| 564 |
ckfree(cmdBuffer); |
| 565 |
Tcl_DStringFree(&buffer); |
| 566 |
return data; |
| 567 |
|
| 568 |
error: |
| 569 |
if (cmdBuffer != NULL) { |
| 570 |
ckfree(cmdBuffer); |
| 571 |
} |
| 572 |
Tcl_DStringFree(&buffer); |
| 573 |
return (char**)NULL; |
| 574 |
} |
| 575 |
|
| 576 |
|
| 577 |
static char * |
| 578 |
GetType(colorDefn, type_ret) |
| 579 |
char * colorDefn; |
| 580 |
int * type_ret; |
| 581 |
{ |
| 582 |
char * p = colorDefn; |
| 583 |
|
| 584 |
|
| 585 |
while (*p && isspace(UCHAR(*p))) { |
| 586 |
p ++; |
| 587 |
} |
| 588 |
|
| 589 |
|
| 590 |
if (p[0] != '\0' && p[0] == 'm' && |
| 591 |
p[1] != '\0' && isspace(UCHAR(p[1]))) { |
| 592 |
*type_ret = XPM_MONO; |
| 593 |
p += 2; |
| 594 |
} |
| 595 |
else if (p[0] != '\0' && p[0] == 'g' && |
| 596 |
p[1] != '\0' && p[1] == '4' && |
| 597 |
p[2] != '\0' && isspace(UCHAR(p[2]))) { |
| 598 |
*type_ret = XPM_GRAY_4; |
| 599 |
p += 3; |
| 600 |
} |
| 601 |
else if (p[0] != '\0' && p[0] == 'g' && |
| 602 |
p[1] != '\0' && isspace(UCHAR(p[1]))) { |
| 603 |
*type_ret = XPM_GRAY; |
| 604 |
p += 2; |
| 605 |
} |
| 606 |
else if (p[0] != '\0' && p[0] == 'c' && |
| 607 |
p[1] != '\0' && isspace(UCHAR(p[1]))) { |
| 608 |
*type_ret = XPM_COLOR; |
| 609 |
p += 2; |
| 610 |
} |
| 611 |
else if (p[0] != '\0' && p[0] == 's' && |
| 612 |
p[1] != '\0' && isspace(UCHAR(p[1]))) { |
| 613 |
*type_ret = XPM_SYMBOLIC; |
| 614 |
p += 2; |
| 615 |
} |
| 616 |
else { |
| 617 |
*type_ret = XPM_UNKNOWN; |
| 618 |
return NULL; |
| 619 |
} |
| 620 |
|
| 621 |
return p; |
| 622 |
} |
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
static char * |
| 628 |
GetColor(colorDefn, colorName, type_ret) |
| 629 |
char * colorDefn; |
| 630 |
char * colorName; |
| 631 |
int * type_ret; |
| 632 |
{ |
| 633 |
int type; |
| 634 |
char * p; |
| 635 |
|
| 636 |
if (!colorDefn) { |
| 637 |
return NULL; |
| 638 |
} |
| 639 |
|
| 640 |
if ((colorDefn = GetType(colorDefn, &type)) == NULL) { |
| 641 |
|
| 642 |
return NULL; |
| 643 |
} |
| 644 |
else { |
| 645 |
*type_ret = type; |
| 646 |
} |
| 647 |
|
| 648 |
|
| 649 |
while (*colorDefn && isspace(UCHAR(*colorDefn))) { |
| 650 |
colorDefn ++; |
| 651 |
} |
| 652 |
|
| 653 |
p = colorName; |
| 654 |
|
| 655 |
while (1) { |
| 656 |
int dummy; |
| 657 |
|
| 658 |
while (*colorDefn && !isspace(UCHAR(*colorDefn))) { |
| 659 |
*p++ = *colorDefn++; |
| 660 |
} |
| 661 |
|
| 662 |
if (!*colorDefn) { |
| 663 |
break; |
| 664 |
} |
| 665 |
|
| 666 |
if (GetType(colorDefn, &dummy) == NULL) { |
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
while (*colorDefn && isspace(UCHAR(*colorDefn))) { |
| 671 |
*p++ = *colorDefn++; |
| 672 |
} |
| 673 |
} else { |
| 674 |
break; |
| 675 |
} |
| 676 |
if (!*colorDefn) { |
| 677 |
break; |
| 678 |
} |
| 679 |
} |
| 680 |
|
| 681 |
|
| 682 |
*p = '\0'; |
| 683 |
|
| 684 |
return colorDefn; |
| 685 |
} |
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
static void |
| 694 |
ImgXpmGetPixmapFromData(interp, masterPtr, instancePtr) |
| 695 |
Tcl_Interp * interp; |
| 696 |
PixmapMaster *masterPtr; |
| 697 |
PixmapInstance *instancePtr; |
| 698 |
{ |
| 699 |
XImage * image = NULL, * mask = NULL; |
| 700 |
int depth, i, j, k, lOffset, isTransp = 0, isMono; |
| 701 |
ColorStruct * colors; |
| 702 |
|
| 703 |
depth = Tk_Depth(instancePtr->tkwin); |
| 704 |
|
| 705 |
switch ((Tk_Visual(instancePtr->tkwin))->class) { |
| 706 |
case StaticGray: |
| 707 |
case GrayScale: |
| 708 |
isMono = 1; |
| 709 |
break; |
| 710 |
default: |
| 711 |
isMono = 0; |
| 712 |
} |
| 713 |
|
| 714 |
TixpXpmAllocTmpBuffer(masterPtr, instancePtr, &image, &mask); |
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
lOffset = 1; |
| 720 |
colors = (ColorStruct*)ckalloc(sizeof(ColorStruct)*masterPtr->ncolors); |
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
for (i=0; i<masterPtr->ncolors; i++) { |
| 726 |
colors[i].colorPtr = NULL; |
| 727 |
if (masterPtr->cpp == 1) { |
| 728 |
colors[i].c = 0; |
| 729 |
} else { |
| 730 |
colors[i].cstring = (char*)ckalloc(masterPtr->cpp); |
| 731 |
colors[i].cstring[0] = 0; |
| 732 |
} |
| 733 |
} |
| 734 |
|
| 735 |
for (i=0; i<masterPtr->ncolors; i++) { |
| 736 |
char * colorDefn; |
| 737 |
char * colorName; |
| 738 |
|
| 739 |
char * useName; |
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
int found; |
| 745 |
|
| 746 |
colorDefn = masterPtr->data[i+lOffset]+masterPtr->cpp; |
| 747 |
colorName = (char*)ckalloc(strlen(colorDefn)); |
| 748 |
useName = (char*)ckalloc(strlen(colorDefn)); |
| 749 |
found = 0; |
| 750 |
|
| 751 |
while (colorDefn && *colorDefn) { |
| 752 |
int type; |
| 753 |
|
| 754 |
if ((colorDefn=GetColor(colorDefn, colorName, &type)) == NULL) { |
| 755 |
break; |
| 756 |
} |
| 757 |
if (colorName[0] == '\0') { |
| 758 |
continue; |
| 759 |
} |
| 760 |
|
| 761 |
switch (type) { |
| 762 |
case XPM_MONO: |
| 763 |
if (isMono && depth == 1) { |
| 764 |
strcpy(useName, colorName); |
| 765 |
found = 1; goto gotcolor; |
| 766 |
} |
| 767 |
break; |
| 768 |
case XPM_GRAY_4: |
| 769 |
if (isMono && depth == 4) { |
| 770 |
strcpy(useName, colorName); |
| 771 |
found = 1; goto gotcolor; |
| 772 |
} |
| 773 |
break; |
| 774 |
case XPM_GRAY: |
| 775 |
if (isMono && depth > 4) { |
| 776 |
strcpy(useName, colorName); |
| 777 |
found = 1; goto gotcolor; |
| 778 |
} |
| 779 |
break; |
| 780 |
case XPM_COLOR: |
| 781 |
if (!isMono) { |
| 782 |
strcpy(useName, colorName); |
| 783 |
found = 1; goto gotcolor; |
| 784 |
} |
| 785 |
break; |
| 786 |
} |
| 787 |
if (type != XPM_SYMBOLIC && type != XPM_UNKNOWN) { |
| 788 |
if (!found) { |
| 789 |
strcpy(useName, colorName); |
| 790 |
found = 1; |
| 791 |
} |
| 792 |
} |
| 793 |
} |
| 794 |
|
| 795 |
gotcolor: |
| 796 |
if (masterPtr->cpp == 1) { |
| 797 |
colors[i].c = masterPtr->data[i+lOffset][0]; |
| 798 |
} else { |
| 799 |
strncpy(colors[i].cstring, masterPtr->data[i+lOffset], |
| 800 |
(size_t)masterPtr->cpp); |
| 801 |
} |
| 802 |
|
| 803 |
if (found) { |
| 804 |
if (strcasecmp(useName, "none") != 0) { |
| 805 |
colors[i].colorPtr = Tk_GetColor(interp, |
| 806 |
instancePtr->tkwin, Tk_GetUid(useName)); |
| 807 |
if (colors[i].colorPtr == NULL) { |
| 808 |
colors[i].colorPtr = Tk_GetColor(interp, |
| 809 |
instancePtr->tkwin, Tk_GetUid("black")); |
| 810 |
} |
| 811 |
} |
| 812 |
} else { |
| 813 |
colors[i].colorPtr = Tk_GetColor(interp, |
| 814 |
instancePtr->tkwin, Tk_GetUid("black")); |
| 815 |
} |
| 816 |
|
| 817 |
ckfree(colorName); |
| 818 |
ckfree(useName); |
| 819 |
} |
| 820 |
|
| 821 |
lOffset += masterPtr->ncolors; |
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
for (i=0; i<masterPtr->size[1]; i++) { |
| 827 |
char * p = masterPtr->data[i+lOffset]; |
| 828 |
|
| 829 |
for (j=0; j<masterPtr->size[0]; j++) { |
| 830 |
if (masterPtr->cpp == 1) { |
| 831 |
for (k=0; k<masterPtr->ncolors; k++) { |
| 832 |
if (*p == colors[k].c) { |
| 833 |
TixpXpmSetPixel(instancePtr, image, mask, j, i, |
| 834 |
colors[k].colorPtr, &isTransp); |
| 835 |
break; |
| 836 |
} |
| 837 |
} |
| 838 |
if (*p) { |
| 839 |
p++; |
| 840 |
} |
| 841 |
} else { |
| 842 |
for (k=0; k<masterPtr->ncolors; k++) { |
| 843 |
if (strncmp(p, colors[k].cstring, |
| 844 |
(size_t)masterPtr->cpp) == 0) { |
| 845 |
TixpXpmSetPixel(instancePtr, image, mask, j, i, |
| 846 |
colors[k].colorPtr, &isTransp); |
| 847 |
break; |
| 848 |
} |
| 849 |
} |
| 850 |
for (k=0; *p && k<masterPtr->cpp; k++) { |
| 851 |
p++; |
| 852 |
} |
| 853 |
} |
| 854 |
} |
| 855 |
} |
| 856 |
|
| 857 |
instancePtr->colors = colors; |
| 858 |
|
| 859 |
TixpXpmRealizePixmap(masterPtr, instancePtr, image, mask, isTransp); |
| 860 |
TixpXpmFreeTmpBuffer(masterPtr, instancePtr, image, mask); |
| 861 |
} |
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
static void |
| 883 |
ImgXpmConfigureInstance(instancePtr) |
| 884 |
PixmapInstance *instancePtr; |
| 885 |
{ |
| 886 |
PixmapMaster *masterPtr = instancePtr->masterPtr; |
| 887 |
|
| 888 |
if (instancePtr->pixmap != None) { |
| 889 |
Tk_FreePixmap(Tk_Display(instancePtr->tkwin), instancePtr->pixmap); |
| 890 |
} |
| 891 |
TixpXpmFreeInstanceData(instancePtr, 0, Tk_Display(instancePtr->tkwin)); |
| 892 |
|
| 893 |
if (instancePtr->colors != NULL) { |
| 894 |
int i; |
| 895 |
for (i=0; i<masterPtr->ncolors; i++) { |
| 896 |
if (instancePtr->colors[i].colorPtr != NULL) { |
| 897 |
Tk_FreeColor(instancePtr->colors[i].colorPtr); |
| 898 |
} |
| 899 |
if (masterPtr->cpp != 1) { |
| 900 |
ckfree(instancePtr->colors[i].cstring); |
| 901 |
} |
| 902 |
} |
| 903 |
ckfree((char*)instancePtr->colors); |
| 904 |
} |
| 905 |
|
| 906 |
if (Tk_WindowId(instancePtr->tkwin) == None) { |
| 907 |
Tk_MakeWindowExist(instancePtr->tkwin); |
| 908 |
} |
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
ImgXpmGetPixmapFromData(masterPtr->interp, masterPtr, instancePtr); |
| 917 |
} |
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
static int |
| 938 |
ImgXpmCmd(clientData, interp, argc, argv) |
| 939 |
ClientData clientData; |
| 940 |
Tcl_Interp *interp; |
| 941 |
int argc; |
| 942 |
char **argv; |
| 943 |
{ |
| 944 |
PixmapMaster *masterPtr = (PixmapMaster *) clientData; |
| 945 |
int c, code; |
| 946 |
size_t length; |
| 947 |
|
| 948 |
if (argc < 2) { |
| 949 |
sprintf(interp->result, |
| 950 |
"wrong # args: should be \"%.50s option ?arg arg ...?\"", |
| 951 |
argv[0]); |
| 952 |
return TCL_ERROR; |
| 953 |
} |
| 954 |
c = argv[1][0]; |
| 955 |
length = strlen(argv[1]); |
| 956 |
|
| 957 |
if ((c == 'c') && (strncmp(argv[1], "cget", length) == 0) |
| 958 |
&& (length >= 2)) { |
| 959 |
if (argc != 3) { |
| 960 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 961 |
argv[0], " cget option\"", |
| 962 |
(char *) NULL); |
| 963 |
return TCL_ERROR; |
| 964 |
} |
| 965 |
return Tk_ConfigureValue(interp, Tk_MainWindow(interp), configSpecs, |
| 966 |
(char *) masterPtr, argv[2], 0); |
| 967 |
} else if ((c == 'c') && (strncmp(argv[1], "configure", length) == 0) |
| 968 |
&& (length >= 2)) { |
| 969 |
if (argc == 2) { |
| 970 |
code = Tk_ConfigureInfo(interp, Tk_MainWindow(interp), |
| 971 |
configSpecs, (char *) masterPtr, (char *) NULL, 0); |
| 972 |
} else if (argc == 3) { |
| 973 |
code = Tk_ConfigureInfo(interp, Tk_MainWindow(interp), |
| 974 |
configSpecs, (char *) masterPtr, argv[2], 0); |
| 975 |
} else { |
| 976 |
code = ImgXpmConfigureMaster(masterPtr, argc-2, argv+2, |
| 977 |
TK_CONFIG_ARGV_ONLY); |
| 978 |
} |
| 979 |
return code; |
| 980 |
} else if ((c == 'r') && (strncmp(argv[1], "refcount", length) == 0)) { |
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
PixmapInstance *instancePtr; |
| 985 |
int count = 0; |
| 986 |
|
| 987 |
for (instancePtr=masterPtr->instancePtr; instancePtr; |
| 988 |
instancePtr = instancePtr->nextPtr) { |
| 989 |
count += instancePtr->refCount; |
| 990 |
} |
| 991 |
Tcl_SetIntObj(Tcl_GetObjResult(interp), count); |
| 992 |
return TCL_OK; |
| 993 |
} else { |
| 994 |
Tcl_AppendResult(interp, "bad option \"", argv[1], |
| 995 |
"\": must be cget, configure or refcount", (char *) NULL); |
| 996 |
return TCL_ERROR; |
| 997 |
} |
| 998 |
} |
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
static ClientData |
| 1020 |
ImgXpmGet(tkwin, masterData) |
| 1021 |
Tk_Window tkwin; |
| 1022 |
|
| 1023 |
ClientData masterData; |
| 1024 |
|
| 1025 |
{ |
| 1026 |
PixmapMaster *masterPtr = (PixmapMaster *) masterData; |
| 1027 |
PixmapInstance *instancePtr; |
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
for (instancePtr = masterPtr->instancePtr; instancePtr != NULL; |
| 1035 |
instancePtr = instancePtr->nextPtr) { |
| 1036 |
if (instancePtr->tkwin == tkwin) { |
| 1037 |
instancePtr->refCount++; |
| 1038 |
return (ClientData) instancePtr; |
| 1039 |
} |
| 1040 |
} |
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
instancePtr = (PixmapInstance *) ckalloc(sizeof(PixmapInstance)); |
| 1047 |
instancePtr->refCount = 1; |
| 1048 |
instancePtr->masterPtr = masterPtr; |
| 1049 |
instancePtr->tkwin = tkwin; |
| 1050 |
instancePtr->pixmap = None; |
| 1051 |
instancePtr->nextPtr = masterPtr->instancePtr; |
| 1052 |
instancePtr->colors = NULL; |
| 1053 |
masterPtr->instancePtr = instancePtr; |
| 1054 |
|
| 1055 |
TixpInitPixmapInstance(masterPtr, instancePtr); |
| 1056 |
ImgXpmConfigureInstance(instancePtr); |
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
if (instancePtr->nextPtr == NULL) { |
| 1062 |
if (masterPtr->data) { |
| 1063 |
Tk_ImageChanged(masterPtr->tkMaster, 0, 0, |
| 1064 |
masterPtr->size[0], masterPtr->size[1], |
| 1065 |
masterPtr->size[0], masterPtr->size[1]); |
| 1066 |
} else { |
| 1067 |
Tk_ImageChanged(masterPtr->tkMaster, 0, 0, 0, 0, 0, 0); |
| 1068 |
} |
| 1069 |
} |
| 1070 |
|
| 1071 |
return (ClientData) instancePtr; |
| 1072 |
} |
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
static void |
| 1091 |
ImgXpmDisplay(clientData, display, drawable, imageX, imageY, width, |
| 1092 |
height, drawableX, drawableY) |
| 1093 |
ClientData clientData; |
| 1094 |
|
| 1095 |
Display *display; |
| 1096 |
Drawable drawable; |
| 1097 |
int imageX, imageY; |
| 1098 |
|
| 1099 |
int width, height; |
| 1100 |
int drawableX, drawableY; |
| 1101 |
|
| 1102 |
{ |
| 1103 |
TixpXpmDisplay(clientData, display, drawable, imageX, imageY, width, |
| 1104 |
height, drawableX, drawableY); |
| 1105 |
} |
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
static void |
| 1125 |
ImgXpmFree(clientData, display) |
| 1126 |
ClientData clientData; |
| 1127 |
|
| 1128 |
Display *display; |
| 1129 |
{ |
| 1130 |
PixmapInstance *instancePtr = (PixmapInstance *) clientData; |
| 1131 |
PixmapInstance *prevPtr; |
| 1132 |
|
| 1133 |
instancePtr->refCount--; |
| 1134 |
if (instancePtr->refCount > 0) { |
| 1135 |
return; |
| 1136 |
} |
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
if (instancePtr->pixmap != None) { |
| 1143 |
Tk_FreePixmap(display, instancePtr->pixmap); |
| 1144 |
} |
| 1145 |
TixpXpmFreeInstanceData(instancePtr, 1, display); |
| 1146 |
|
| 1147 |
if (instancePtr->colors != NULL) { |
| 1148 |
int i; |
| 1149 |
for (i=0; i<instancePtr->masterPtr->ncolors; i++) { |
| 1150 |
if (instancePtr->colors[i].colorPtr != NULL) { |
| 1151 |
Tk_FreeColor(instancePtr->colors[i].colorPtr); |
| 1152 |
} |
| 1153 |
if (instancePtr->masterPtr->cpp != 1) { |
| 1154 |
ckfree(instancePtr->colors[i].cstring); |
| 1155 |
} |
| 1156 |
} |
| 1157 |
ckfree((char*)instancePtr->colors); |
| 1158 |
} |
| 1159 |
|
| 1160 |
if (instancePtr->masterPtr->instancePtr == instancePtr) { |
| 1161 |
instancePtr->masterPtr->instancePtr = instancePtr->nextPtr; |
| 1162 |
} else { |
| 1163 |
for (prevPtr = instancePtr->masterPtr->instancePtr; |
| 1164 |
prevPtr->nextPtr != instancePtr; prevPtr = prevPtr->nextPtr) { |
| 1165 |
|
| 1166 |
} |
| 1167 |
prevPtr->nextPtr = instancePtr->nextPtr; |
| 1168 |
} |
| 1169 |
ckfree((char *) instancePtr); |
| 1170 |
} |
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
static void |
| 1190 |
ImgXpmDelete(masterData) |
| 1191 |
ClientData masterData; |
| 1192 |
|
| 1193 |
{ |
| 1194 |
PixmapMaster *masterPtr = (PixmapMaster *) masterData; |
| 1195 |
|
| 1196 |
if (masterPtr->instancePtr != NULL) { |
| 1197 |
panic("tried to delete pixmap image when instances still exist"); |
| 1198 |
} |
| 1199 |
masterPtr->tkMaster = NULL; |
| 1200 |
if (masterPtr->imageCmd != NULL) { |
| 1201 |
Tcl_DeleteCommand(masterPtr->interp, |
| 1202 |
Tcl_GetCommandName(masterPtr->interp, masterPtr->imageCmd)); |
| 1203 |
} |
| 1204 |
if (masterPtr->isDataAlloced && masterPtr->data != NULL) { |
| 1205 |
ckfree((char*)masterPtr->data); |
| 1206 |
masterPtr->data = NULL; |
| 1207 |
} |
| 1208 |
|
| 1209 |
Tk_FreeOptions(configSpecs, (char *) masterPtr, (Display *) NULL, 0); |
| 1210 |
ckfree((char *) masterPtr); |
| 1211 |
} |
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
static void |
| 1230 |
ImgXpmCmdDeletedProc(clientData) |
| 1231 |
ClientData clientData; |
| 1232 |
|
| 1233 |
{ |
| 1234 |
PixmapMaster *masterPtr = (PixmapMaster *) clientData; |
| 1235 |
|
| 1236 |
masterPtr->imageCmd = NULL; |
| 1237 |
if (masterPtr->tkMaster != NULL) { |
| 1238 |
if (Tk_MainWindow(masterPtr->interp) != NULL) { |
| 1239 |
Tk_DeleteImage(masterPtr->interp, |
| 1240 |
Tk_NameOfImage(masterPtr->tkMaster)); |
| 1241 |
} |
| 1242 |
} |
| 1243 |
} |
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
int |
| 1263 |
Tix_DefinePixmap(interp, name, data) |
| 1264 |
Tcl_Interp * interp; |
| 1265 |
Tk_Uid name; |
| 1266 |
|
| 1267 |
char **data; |
| 1268 |
{ |
| 1269 |
int new; |
| 1270 |
Tcl_HashEntry *hshPtr; |
| 1271 |
|
| 1272 |
if (!xpmTableInited) { |
| 1273 |
xpmTableInited = 1; |
| 1274 |
Tcl_InitHashTable(&xpmTable, TCL_ONE_WORD_KEYS); |
| 1275 |
} |
| 1276 |
|
| 1277 |
hshPtr = Tcl_CreateHashEntry(&xpmTable, name, &new); |
| 1278 |
if (!new) { |
| 1279 |
Tcl_AppendResult(interp, "pixmap \"", name, |
| 1280 |
"\" is already defined", (char *) NULL); |
| 1281 |
return TCL_ERROR; |
| 1282 |
} |
| 1283 |
Tcl_SetHashValue(hshPtr, (char*)data); |
| 1284 |
return TCL_OK; |
| 1285 |
} |
| 1286 |
|