| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include "tk.h" |
| 17 |
#include "tkText.h" |
| 18 |
#include "tkPort.h" |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#define ALIGN_BOTTOM 0 |
| 25 |
#define ALIGN_CENTER 1 |
| 26 |
#define ALIGN_TOP 2 |
| 27 |
#define ALIGN_BASELINE 3 |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
#define EI_SEG_SIZE ((unsigned) (Tk_Offset(TkTextSegment, body) \ |
| 34 |
+ sizeof(TkTextEmbImage))) |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
static int AlignParseProc _ANSI_ARGS_((ClientData clientData, |
| 41 |
Tcl_Interp *interp, Tk_Window tkwin, |
| 42 |
Tcl_Obj *value, char *widgRec, int offset)); |
| 43 |
static Tcl_Obj * AlignPrintProc _ANSI_ARGS_((ClientData clientData, |
| 44 |
Tk_Window tkwin, char *widgRec, int offset, |
| 45 |
Tcl_FreeProc **freeProcPtr)); |
| 46 |
static TkTextSegment * EmbImageCleanupProc _ANSI_ARGS_((TkTextSegment *segPtr, |
| 47 |
TkTextLine *linePtr)); |
| 48 |
static void EmbImageCheckProc _ANSI_ARGS_((TkTextSegment *segPtr, |
| 49 |
TkTextLine *linePtr)); |
| 50 |
static void EmbImageBboxProc _ANSI_ARGS_((TkTextDispChunk *chunkPtr, |
| 51 |
int index, int y, int lineHeight, int baseline, |
| 52 |
int *xPtr, int *yPtr, int *widthPtr, |
| 53 |
int *heightPtr)); |
| 54 |
static int EmbImageConfigure _ANSI_ARGS_((TkText *textPtr, |
| 55 |
TkTextSegment *eiPtr, int argc, char **argv)); |
| 56 |
static int EmbImageDeleteProc _ANSI_ARGS_((TkTextSegment *segPtr, |
| 57 |
TkTextLine *linePtr, int treeGone)); |
| 58 |
static void EmbImageDisplayProc _ANSI_ARGS_(( |
| 59 |
TkTextDispChunk *chunkPtr, int x, int y, |
| 60 |
int lineHeight, int baseline, Display *display, |
| 61 |
Drawable dst, int screenY)); |
| 62 |
static int EmbImageLayoutProc _ANSI_ARGS_((TkText *textPtr, |
| 63 |
TkTextIndex *indexPtr, TkTextSegment *segPtr, |
| 64 |
int offset, int maxX, int maxChars, |
| 65 |
int noCharsYet, TkWrapMode wrapMode, |
| 66 |
TkTextDispChunk *chunkPtr)); |
| 67 |
static void EmbImageProc _ANSI_ARGS_((ClientData clientData, |
| 68 |
int x, int y, int width, int height, |
| 69 |
int imageWidth, int imageHeight)); |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
static Tk_SegType tkTextEmbImageType = { |
| 76 |
"image", |
| 77 |
0, |
| 78 |
(Tk_SegSplitProc *) NULL, |
| 79 |
EmbImageDeleteProc, |
| 80 |
EmbImageCleanupProc, |
| 81 |
(Tk_SegLineChangeProc *) NULL, |
| 82 |
EmbImageLayoutProc, |
| 83 |
EmbImageCheckProc |
| 84 |
}; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
static Tk_CustomOption alignOption = {AlignParseProc, AlignPrintProc, |
| 91 |
(ClientData) NULL}; |
| 92 |
|
| 93 |
static Tk_ConfigSpec configSpecs[] = { |
| 94 |
{TK_CONFIG_CUSTOM, "-align", (char *) NULL, (char *) NULL, |
| 95 |
"center", 0, TK_CONFIG_DONT_SET_DEFAULT, &alignOption}, |
| 96 |
{TK_CONFIG_PIXELS, "-padx", (char *) NULL, (char *) NULL, |
| 97 |
"0", Tk_Offset(TkTextEmbImage, padX), |
| 98 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 99 |
{TK_CONFIG_PIXELS, "-pady", (char *) NULL, (char *) NULL, |
| 100 |
"0", Tk_Offset(TkTextEmbImage, padY), |
| 101 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 102 |
{TK_CONFIG_STRING, "-image", (char *) NULL, (char *) NULL, |
| 103 |
(char *) NULL, Tk_Offset(TkTextEmbImage, imageString), |
| 104 |
TK_CONFIG_DONT_SET_DEFAULT|TK_CONFIG_NULL_OK}, |
| 105 |
{TK_CONFIG_STRING, "-name", (char *) NULL, (char *) NULL, |
| 106 |
(char *) NULL, Tk_Offset(TkTextEmbImage, imageName), |
| 107 |
TK_CONFIG_DONT_SET_DEFAULT|TK_CONFIG_NULL_OK}, |
| 108 |
{TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL, |
| 109 |
(char *) NULL, 0, 0} |
| 110 |
}; |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
int |
| 131 |
TkTextImageCmd(textPtr, interp, argc, argv) |
| 132 |
register TkText *textPtr; |
| 133 |
Tcl_Interp *interp; |
| 134 |
int argc; |
| 135 |
char **argv; |
| 136 |
|
| 137 |
|
| 138 |
{ |
| 139 |
size_t length; |
| 140 |
register TkTextSegment *eiPtr; |
| 141 |
|
| 142 |
if (argc < 3) { |
| 143 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 144 |
argv[0], " image option ?arg arg ...?\"", (char *) NULL); |
| 145 |
return TCL_ERROR; |
| 146 |
} |
| 147 |
length = strlen(argv[2]); |
| 148 |
if ((strncmp(argv[2], "cget", length) == 0) && (length >= 2)) { |
| 149 |
TkTextIndex index; |
| 150 |
TkTextSegment *eiPtr; |
| 151 |
|
| 152 |
if (argc != 5) { |
| 153 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 154 |
argv[0], " image cget index option\"", |
| 155 |
(char *) NULL); |
| 156 |
return TCL_ERROR; |
| 157 |
} |
| 158 |
if (TkTextGetIndex(interp, textPtr, argv[3], &index) != TCL_OK) { |
| 159 |
return TCL_ERROR; |
| 160 |
} |
| 161 |
eiPtr = TkTextIndexToSeg(&index, (int *) NULL); |
| 162 |
if (eiPtr->typePtr != &tkTextEmbImageType) { |
| 163 |
Tcl_AppendResult(interp, "no embedded image at index \"", |
| 164 |
argv[3], "\"", (char *) NULL); |
| 165 |
return TCL_ERROR; |
| 166 |
} |
| 167 |
return Tk_ConfigureValue(interp, textPtr->tkwin, configSpecs, |
| 168 |
(char *) &eiPtr->body.ei, argv[4], 0); |
| 169 |
} else if ((strncmp(argv[2], "configure", length) == 0) && (length >= 2)) { |
| 170 |
TkTextIndex index; |
| 171 |
TkTextSegment *eiPtr; |
| 172 |
|
| 173 |
if (argc < 4) { |
| 174 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 175 |
argv[0], " image configure index ?option value ...?\"", |
| 176 |
(char *) NULL); |
| 177 |
return TCL_ERROR; |
| 178 |
} |
| 179 |
if (TkTextGetIndex(interp, textPtr, argv[3], &index) != TCL_OK) { |
| 180 |
return TCL_ERROR; |
| 181 |
} |
| 182 |
eiPtr = TkTextIndexToSeg(&index, (int *) NULL); |
| 183 |
if (eiPtr->typePtr != &tkTextEmbImageType) { |
| 184 |
Tcl_AppendResult(interp, "no embedded image at index \"", |
| 185 |
argv[3], "\"", (char *) NULL); |
| 186 |
return TCL_ERROR; |
| 187 |
} |
| 188 |
if (argc == 4) { |
| 189 |
return Tk_ConfigureInfo(interp, textPtr->tkwin, configSpecs, |
| 190 |
(char *) &eiPtr->body.ei, (char *) NULL, 0); |
| 191 |
} else if (argc == 5) { |
| 192 |
return Tk_ConfigureInfo(interp, textPtr->tkwin, configSpecs, |
| 193 |
(char *) &eiPtr->body.ei, argv[4], 0); |
| 194 |
} else { |
| 195 |
TkTextChanged(textPtr, &index, &index); |
| 196 |
return EmbImageConfigure(textPtr, eiPtr, argc-4, argv+4); |
| 197 |
} |
| 198 |
} else if ((strncmp(argv[2], "create", length) == 0) && (length >= 2)) { |
| 199 |
TkTextIndex index; |
| 200 |
int lineIndex; |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
if (argc < 4) { |
| 208 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 209 |
argv[0], " image create index ?option value ...?\"", |
| 210 |
(char *) NULL); |
| 211 |
return TCL_ERROR; |
| 212 |
} |
| 213 |
if (TkTextGetIndex(interp, textPtr, argv[3], &index) != TCL_OK) { |
| 214 |
return TCL_ERROR; |
| 215 |
} |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
lineIndex = TkBTreeLineIndex(index.linePtr); |
| 222 |
if (lineIndex == TkBTreeNumLines(textPtr->tree)) { |
| 223 |
lineIndex--; |
| 224 |
TkTextMakeByteIndex(textPtr->tree, lineIndex, 1000000, &index); |
| 225 |
} |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
eiPtr = (TkTextSegment *) ckalloc(EI_SEG_SIZE); |
| 232 |
eiPtr->typePtr = &tkTextEmbImageType; |
| 233 |
eiPtr->size = 1; |
| 234 |
eiPtr->body.ei.textPtr = textPtr; |
| 235 |
eiPtr->body.ei.linePtr = NULL; |
| 236 |
eiPtr->body.ei.imageName = NULL; |
| 237 |
eiPtr->body.ei.imageString = NULL; |
| 238 |
eiPtr->body.ei.name = NULL; |
| 239 |
eiPtr->body.ei.image = NULL; |
| 240 |
eiPtr->body.ei.align = ALIGN_CENTER; |
| 241 |
eiPtr->body.ei.padX = eiPtr->body.ei.padY = 0; |
| 242 |
eiPtr->body.ei.chunkCount = 0; |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
TkTextChanged(textPtr, &index, &index); |
| 250 |
TkBTreeLinkSegment(eiPtr, &index); |
| 251 |
if (EmbImageConfigure(textPtr, eiPtr, argc-4, argv+4) != TCL_OK) { |
| 252 |
TkTextIndex index2; |
| 253 |
|
| 254 |
TkTextIndexForwChars(&index, 1, &index2); |
| 255 |
TkBTreeDeleteChars(&index, &index2); |
| 256 |
return TCL_ERROR; |
| 257 |
} |
| 258 |
} else if (strncmp(argv[2], "names", length) == 0) { |
| 259 |
Tcl_HashSearch search; |
| 260 |
Tcl_HashEntry *hPtr; |
| 261 |
|
| 262 |
if (argc != 3) { |
| 263 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 264 |
argv[0], " image names\"", (char *) NULL); |
| 265 |
return TCL_ERROR; |
| 266 |
} |
| 267 |
for (hPtr = Tcl_FirstHashEntry(&textPtr->imageTable, &search); |
| 268 |
hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) { |
| 269 |
Tcl_AppendElement(interp, |
| 270 |
Tcl_GetHashKey(&textPtr->markTable, hPtr)); |
| 271 |
} |
| 272 |
} else { |
| 273 |
Tcl_AppendResult(interp, "bad image option \"", argv[2], |
| 274 |
"\": must be cget, configure, create, or names", |
| 275 |
(char *) NULL); |
| 276 |
return TCL_ERROR; |
| 277 |
} |
| 278 |
return TCL_OK; |
| 279 |
} |
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
static int |
| 301 |
EmbImageConfigure(textPtr, eiPtr, argc, argv) |
| 302 |
TkText *textPtr; |
| 303 |
|
| 304 |
TkTextSegment *eiPtr; |
| 305 |
int argc; |
| 306 |
char **argv; |
| 307 |
|
| 308 |
{ |
| 309 |
Tk_Image image; |
| 310 |
Tcl_DString newName; |
| 311 |
Tcl_HashEntry *hPtr; |
| 312 |
Tcl_HashSearch search; |
| 313 |
int new; |
| 314 |
char *name; |
| 315 |
int count = 0; |
| 316 |
int conflict = 0; |
| 317 |
unsigned int len; |
| 318 |
|
| 319 |
if (Tk_ConfigureWidget(textPtr->interp, textPtr->tkwin, configSpecs, |
| 320 |
argc, argv, (char *) &eiPtr->body.ei,TK_CONFIG_ARGV_ONLY) |
| 321 |
!= TCL_OK) { |
| 322 |
return TCL_ERROR; |
| 323 |
} |
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
if (eiPtr->body.ei.imageString != NULL) { |
| 333 |
image = Tk_GetImage(textPtr->interp, textPtr->tkwin, eiPtr->body.ei.imageString, |
| 334 |
EmbImageProc, (ClientData) eiPtr); |
| 335 |
if (image == NULL) { |
| 336 |
return TCL_ERROR; |
| 337 |
} |
| 338 |
} else { |
| 339 |
image = NULL; |
| 340 |
} |
| 341 |
if (eiPtr->body.ei.image != NULL) { |
| 342 |
Tk_FreeImage(eiPtr->body.ei.image); |
| 343 |
} |
| 344 |
eiPtr->body.ei.image = image; |
| 345 |
|
| 346 |
if (eiPtr->body.ei.name != NULL) { |
| 347 |
return TCL_OK; |
| 348 |
} |
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
name = eiPtr->body.ei.imageName; |
| 357 |
if (name == NULL) { |
| 358 |
name = eiPtr->body.ei.imageString; |
| 359 |
} |
| 360 |
if (name == NULL) { |
| 361 |
Tcl_AppendResult(textPtr->interp,"Either a \"-name\" ", |
| 362 |
"or a \"-image\" argument must be provided ", |
| 363 |
"to the \"image create\" subcommand.", |
| 364 |
(char *) NULL); |
| 365 |
return TCL_ERROR; |
| 366 |
} |
| 367 |
len = strlen(name); |
| 368 |
for (hPtr = Tcl_FirstHashEntry(&textPtr->imageTable, &search); |
| 369 |
hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) { |
| 370 |
char *haveName = Tcl_GetHashKey(&textPtr->imageTable, hPtr); |
| 371 |
if (strncmp(name, haveName, len) == 0) { |
| 372 |
new = 0; |
| 373 |
sscanf(haveName+len,"#%d",&new); |
| 374 |
if (new > count) { |
| 375 |
count = new; |
| 376 |
} |
| 377 |
if (len == strlen(haveName)) { |
| 378 |
conflict = 1; |
| 379 |
} |
| 380 |
} |
| 381 |
} |
| 382 |
|
| 383 |
Tcl_DStringInit(&newName); |
| 384 |
Tcl_DStringAppend(&newName,name, -1); |
| 385 |
|
| 386 |
if (conflict) { |
| 387 |
char buf[4 + TCL_INTEGER_SPACE]; |
| 388 |
sprintf(buf, "#%d",count+1); |
| 389 |
Tcl_DStringAppend(&newName,buf, -1); |
| 390 |
} |
| 391 |
name = Tcl_DStringValue(&newName); |
| 392 |
hPtr = Tcl_CreateHashEntry(&textPtr->imageTable, name, &new); |
| 393 |
Tcl_SetHashValue(hPtr, eiPtr); |
| 394 |
Tcl_AppendResult(textPtr->interp, name , (char *) NULL); |
| 395 |
eiPtr->body.ei.name = ckalloc((unsigned) Tcl_DStringLength(&newName)+1); |
| 396 |
strcpy(eiPtr->body.ei.name,name); |
| 397 |
Tcl_DStringFree(&newName); |
| 398 |
|
| 399 |
return TCL_OK; |
| 400 |
} |
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
static int |
| 422 |
AlignParseProc(clientData, interp, tkwin, valuearg, widgRec, offset) |
| 423 |
ClientData clientData; |
| 424 |
Tcl_Interp *interp; |
| 425 |
Tk_Window tkwin; |
| 426 |
Tcl_Obj *valuearg; |
| 427 |
char *widgRec; |
| 428 |
|
| 429 |
int offset; |
| 430 |
{ |
| 431 |
char *value = Tcl_GetString(valuearg); |
| 432 |
register TkTextEmbImage *embPtr = (TkTextEmbImage *) widgRec; |
| 433 |
|
| 434 |
if (strcmp(value, "baseline") == 0) { |
| 435 |
embPtr->align = ALIGN_BASELINE; |
| 436 |
} else if (strcmp(value, "bottom") == 0) { |
| 437 |
embPtr->align = ALIGN_BOTTOM; |
| 438 |
} else if (strcmp(value, "center") == 0) { |
| 439 |
embPtr->align = ALIGN_CENTER; |
| 440 |
} else if (strcmp(value, "top") == 0) { |
| 441 |
embPtr->align = ALIGN_TOP; |
| 442 |
} else { |
| 443 |
Tcl_AppendResult(interp, "bad alignment \"", value, |
| 444 |
"\": must be baseline, bottom, center, or top", |
| 445 |
(char *) NULL); |
| 446 |
return TCL_ERROR; |
| 447 |
} |
| 448 |
return TCL_OK; |
| 449 |
} |
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
Tcl_Obj * |
| 472 |
AlignPrintProc(clientData, tkwin, widgRec, offset, freeProcPtr) |
| 473 |
ClientData clientData; |
| 474 |
Tk_Window tkwin; |
| 475 |
char *widgRec; |
| 476 |
|
| 477 |
int offset; |
| 478 |
Tcl_FreeProc **freeProcPtr; |
| 479 |
|
| 480 |
|
| 481 |
{ |
| 482 |
Tcl_Obj * result = NULL; |
| 483 |
*freeProcPtr = (Tcl_FreeProc *) NULL; |
| 484 |
switch (((TkTextEmbImage *) widgRec)->align) { |
| 485 |
case ALIGN_BASELINE: |
| 486 |
LangSetDefault(&result,"baseline"); |
| 487 |
return result; |
| 488 |
case ALIGN_BOTTOM: |
| 489 |
LangSetDefault(&result,"bottom"); |
| 490 |
return result; |
| 491 |
case ALIGN_CENTER: |
| 492 |
LangSetDefault(&result,"center"); |
| 493 |
return result; |
| 494 |
case ALIGN_TOP: |
| 495 |
LangSetDefault(&result,"top"); |
| 496 |
return result; |
| 497 |
default: |
| 498 |
LangSetDefault(&result,""); |
| 499 |
return result; |
| 500 |
} |
| 501 |
} |
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
static int |
| 523 |
EmbImageDeleteProc(eiPtr, linePtr, treeGone) |
| 524 |
TkTextSegment *eiPtr; |
| 525 |
TkTextLine *linePtr; |
| 526 |
int treeGone; |
| 527 |
|
| 528 |
|
| 529 |
{ |
| 530 |
Tcl_HashEntry *hPtr; |
| 531 |
|
| 532 |
if (eiPtr->body.ei.image != NULL) { |
| 533 |
hPtr = Tcl_FindHashEntry(&eiPtr->body.ei.textPtr->imageTable, |
| 534 |
eiPtr->body.ei.name); |
| 535 |
if (hPtr != NULL) { |
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
Tcl_DeleteHashEntry(hPtr); |
| 543 |
} |
| 544 |
Tk_FreeImage(eiPtr->body.ei.image); |
| 545 |
} |
| 546 |
Tk_FreeOptions(configSpecs, (char *) &eiPtr->body.ei, |
| 547 |
eiPtr->body.ei.textPtr->display, 0); |
| 548 |
if (eiPtr->body.ei.name != NULL) { |
| 549 |
ckfree(eiPtr->body.ei.name); |
| 550 |
} |
| 551 |
ckfree((char *) eiPtr); |
| 552 |
return 0; |
| 553 |
} |
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
static TkTextSegment * |
| 574 |
EmbImageCleanupProc(eiPtr, linePtr) |
| 575 |
TkTextSegment *eiPtr; |
| 576 |
TkTextLine *linePtr; |
| 577 |
{ |
| 578 |
eiPtr->body.ei.linePtr = linePtr; |
| 579 |
return eiPtr; |
| 580 |
} |
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
static int |
| 602 |
EmbImageLayoutProc(textPtr, indexPtr, eiPtr, offset, maxX, maxChars, |
| 603 |
noCharsYet, wrapMode, chunkPtr) |
| 604 |
TkText *textPtr; |
| 605 |
TkTextIndex *indexPtr; |
| 606 |
TkTextSegment *eiPtr; |
| 607 |
int offset; |
| 608 |
|
| 609 |
int maxX; |
| 610 |
|
| 611 |
int maxChars; |
| 612 |
|
| 613 |
int noCharsYet; |
| 614 |
|
| 615 |
TkWrapMode wrapMode; |
| 616 |
|
| 617 |
register TkTextDispChunk *chunkPtr; |
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
{ |
| 622 |
int width, height; |
| 623 |
|
| 624 |
if (offset != 0) { |
| 625 |
panic("Non-zero offset in EmbImageLayoutProc"); |
| 626 |
} |
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
if (eiPtr->body.ei.image == NULL) { |
| 633 |
width = 0; |
| 634 |
height = 0; |
| 635 |
} else { |
| 636 |
Tk_SizeOfImage(eiPtr->body.ei.image, &width, &height); |
| 637 |
width += 2*eiPtr->body.ei.padX; |
| 638 |
height += 2*eiPtr->body.ei.padY; |
| 639 |
} |
| 640 |
if ((width > (maxX - chunkPtr->x)) |
| 641 |
&& !noCharsYet && (textPtr->wrapMode != TEXT_WRAPMODE_NONE)) { |
| 642 |
return 0; |
| 643 |
} |
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
chunkPtr->displayProc = EmbImageDisplayProc; |
| 650 |
chunkPtr->undisplayProc = (Tk_ChunkUndisplayProc *) NULL; |
| 651 |
chunkPtr->measureProc = (Tk_ChunkMeasureProc *) NULL; |
| 652 |
chunkPtr->bboxProc = EmbImageBboxProc; |
| 653 |
chunkPtr->numBytes = 1; |
| 654 |
if (eiPtr->body.ei.align == ALIGN_BASELINE) { |
| 655 |
chunkPtr->minAscent = height - eiPtr->body.ei.padY; |
| 656 |
chunkPtr->minDescent = eiPtr->body.ei.padY; |
| 657 |
chunkPtr->minHeight = 0; |
| 658 |
} else { |
| 659 |
chunkPtr->minAscent = 0; |
| 660 |
chunkPtr->minDescent = 0; |
| 661 |
chunkPtr->minHeight = height; |
| 662 |
} |
| 663 |
chunkPtr->width = width; |
| 664 |
chunkPtr->breakIndex = -1; |
| 665 |
chunkPtr->breakIndex = 1; |
| 666 |
chunkPtr->clientData = (ClientData) eiPtr; |
| 667 |
eiPtr->body.ei.chunkCount += 1; |
| 668 |
return 1; |
| 669 |
} |
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
static void |
| 690 |
EmbImageCheckProc(eiPtr, linePtr) |
| 691 |
TkTextSegment *eiPtr; |
| 692 |
TkTextLine *linePtr; |
| 693 |
{ |
| 694 |
if (eiPtr->nextPtr == NULL) { |
| 695 |
panic("EmbImageCheckProc: embedded image is last segment in line"); |
| 696 |
} |
| 697 |
if (eiPtr->size != 1) { |
| 698 |
panic("EmbImageCheckProc: embedded image has size %d", eiPtr->size); |
| 699 |
} |
| 700 |
} |
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
static void |
| 722 |
EmbImageDisplayProc(chunkPtr, x, y, lineHeight, baseline, display, dst, screenY) |
| 723 |
TkTextDispChunk *chunkPtr; |
| 724 |
int x; |
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
int y; |
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
int lineHeight; |
| 733 |
int baseline; |
| 734 |
Display *display; |
| 735 |
Drawable dst; |
| 736 |
int screenY; |
| 737 |
|
| 738 |
{ |
| 739 |
TkTextSegment *eiPtr = (TkTextSegment *) chunkPtr->clientData; |
| 740 |
int lineX, imageX, imageY, width, height; |
| 741 |
Tk_Image image; |
| 742 |
|
| 743 |
image = eiPtr->body.ei.image; |
| 744 |
if (image == NULL) { |
| 745 |
return; |
| 746 |
} |
| 747 |
if ((x + chunkPtr->width) <= 0) { |
| 748 |
return; |
| 749 |
} |
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
EmbImageBboxProc(chunkPtr, 0, y, lineHeight, baseline, &lineX, |
| 757 |
&imageY, &width, &height); |
| 758 |
imageX = lineX - chunkPtr->x + x; |
| 759 |
|
| 760 |
Tk_RedrawImage(image, 0, 0, width, height, dst, |
| 761 |
imageX, imageY); |
| 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 |
static void |
| 788 |
EmbImageBboxProc(chunkPtr, index, y, lineHeight, baseline, xPtr, yPtr, |
| 789 |
widthPtr, heightPtr) |
| 790 |
TkTextDispChunk *chunkPtr; |
| 791 |
int index; |
| 792 |
|
| 793 |
int y; |
| 794 |
|
| 795 |
int lineHeight; |
| 796 |
int baseline; |
| 797 |
|
| 798 |
int *xPtr, *yPtr; |
| 799 |
|
| 800 |
int *widthPtr; |
| 801 |
|
| 802 |
int *heightPtr; |
| 803 |
|
| 804 |
{ |
| 805 |
TkTextSegment *eiPtr = (TkTextSegment *) chunkPtr->clientData; |
| 806 |
Tk_Image image; |
| 807 |
|
| 808 |
image = eiPtr->body.ei.image; |
| 809 |
if (image != NULL) { |
| 810 |
Tk_SizeOfImage(image, widthPtr, heightPtr); |
| 811 |
} else { |
| 812 |
*widthPtr = 0; |
| 813 |
*heightPtr = 0; |
| 814 |
} |
| 815 |
*xPtr = chunkPtr->x + eiPtr->body.ei.padX; |
| 816 |
switch (eiPtr->body.ei.align) { |
| 817 |
case ALIGN_BOTTOM: |
| 818 |
*yPtr = y + (lineHeight - *heightPtr - eiPtr->body.ei.padY); |
| 819 |
break; |
| 820 |
case ALIGN_CENTER: |
| 821 |
*yPtr = y + (lineHeight - *heightPtr)/2; |
| 822 |
break; |
| 823 |
case ALIGN_TOP: |
| 824 |
*yPtr = y + eiPtr->body.ei.padY; |
| 825 |
break; |
| 826 |
case ALIGN_BASELINE: |
| 827 |
*yPtr = y + (baseline - *heightPtr); |
| 828 |
break; |
| 829 |
} |
| 830 |
} |
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
int |
| 853 |
TkTextImageIndex(textPtr, name, indexPtr) |
| 854 |
TkText *textPtr; |
| 855 |
CONST char *name; |
| 856 |
TkTextIndex *indexPtr; |
| 857 |
{ |
| 858 |
Tcl_HashEntry *hPtr; |
| 859 |
TkTextSegment *eiPtr; |
| 860 |
|
| 861 |
hPtr = Tcl_FindHashEntry(&textPtr->imageTable, name); |
| 862 |
if (hPtr == NULL) { |
| 863 |
return 0; |
| 864 |
} |
| 865 |
eiPtr = (TkTextSegment *) Tcl_GetHashValue(hPtr); |
| 866 |
indexPtr->tree = textPtr->tree; |
| 867 |
indexPtr->linePtr = eiPtr->body.ei.linePtr; |
| 868 |
indexPtr->byteIndex = TkTextSegToOffset(eiPtr, indexPtr->linePtr); |
| 869 |
return 1; |
| 870 |
} |
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
static void |
| 890 |
EmbImageProc(clientData, x, y, width, height, imgWidth, imgHeight) |
| 891 |
ClientData clientData; |
| 892 |
int x, y; |
| 893 |
|
| 894 |
int width, height; |
| 895 |
|
| 896 |
int imgWidth, imgHeight; |
| 897 |
|
| 898 |
{ |
| 899 |
TkTextSegment *eiPtr = (TkTextSegment *) clientData; |
| 900 |
TkTextIndex index; |
| 901 |
|
| 902 |
index.tree = eiPtr->body.ei.textPtr->tree; |
| 903 |
index.linePtr = eiPtr->body.ei.linePtr; |
| 904 |
index.byteIndex = TkTextSegToOffset(eiPtr, eiPtr->body.ei.linePtr); |
| 905 |
TkTextChanged(eiPtr->body.ei.textPtr, &index, &index); |
| 906 |
} |
| 907 |
|
| 908 |
|