| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include "tkInt.h" |
| 17 |
#include "tkText.h" |
| 18 |
#include "tkPort.h" |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#define MSEG_SIZE ((unsigned) (Tk_Offset(TkTextSegment, body) \ |
| 25 |
+ sizeof(TkTextMark))) |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
static void InsertUndisplayProc _ANSI_ARGS_((TkText *textPtr, |
| 32 |
TkTextDispChunk *chunkPtr)); |
| 33 |
static int MarkDeleteProc _ANSI_ARGS_((TkTextSegment *segPtr, |
| 34 |
TkTextLine *linePtr, int treeGone)); |
| 35 |
static TkTextSegment * MarkCleanupProc _ANSI_ARGS_((TkTextSegment *segPtr, |
| 36 |
TkTextLine *linePtr)); |
| 37 |
static void MarkCheckProc _ANSI_ARGS_((TkTextSegment *segPtr, |
| 38 |
TkTextLine *linePtr)); |
| 39 |
static int MarkLayoutProc _ANSI_ARGS_((TkText *textPtr, |
| 40 |
TkTextIndex *indexPtr, TkTextSegment *segPtr, |
| 41 |
int offset, int maxX, int maxChars, |
| 42 |
int noCharsYet, TkWrapMode wrapMode, |
| 43 |
TkTextDispChunk *chunkPtr)); |
| 44 |
static int MarkFindNext _ANSI_ARGS_((Tcl_Interp *interp, |
| 45 |
TkText *textPtr, CONST char *markName)); |
| 46 |
static int MarkFindPrev _ANSI_ARGS_((Tcl_Interp *interp, |
| 47 |
TkText *textPtr, CONST char *markName)); |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
Tk_SegType tkTextRightMarkType = { |
| 58 |
"mark", |
| 59 |
0, |
| 60 |
(Tk_SegSplitProc *) NULL, |
| 61 |
MarkDeleteProc, |
| 62 |
MarkCleanupProc, |
| 63 |
(Tk_SegLineChangeProc *) NULL, |
| 64 |
MarkLayoutProc, |
| 65 |
MarkCheckProc |
| 66 |
}; |
| 67 |
|
| 68 |
Tk_SegType tkTextLeftMarkType = { |
| 69 |
"mark", |
| 70 |
1, |
| 71 |
(Tk_SegSplitProc *) NULL, |
| 72 |
MarkDeleteProc, |
| 73 |
MarkCleanupProc, |
| 74 |
(Tk_SegLineChangeProc *) NULL, |
| 75 |
MarkLayoutProc, |
| 76 |
MarkCheckProc |
| 77 |
}; |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
int |
| 98 |
TkTextMarkCmd(textPtr, interp, argc, argv) |
| 99 |
register TkText *textPtr; |
| 100 |
Tcl_Interp *interp; |
| 101 |
int argc; |
| 102 |
char **argv; |
| 103 |
|
| 104 |
|
| 105 |
{ |
| 106 |
int c, i; |
| 107 |
size_t length; |
| 108 |
Tcl_HashEntry *hPtr; |
| 109 |
TkTextSegment *markPtr; |
| 110 |
Tcl_HashSearch search; |
| 111 |
TkTextIndex index; |
| 112 |
Tk_SegType *newTypePtr; |
| 113 |
|
| 114 |
if (argc < 3) { |
| 115 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 116 |
argv[0], " mark option ?arg arg ...?\"", (char *) NULL); |
| 117 |
return TCL_ERROR; |
| 118 |
} |
| 119 |
c = argv[2][0]; |
| 120 |
length = strlen(argv[2]); |
| 121 |
if ((c == 'g') && (strncmp(argv[2], "gravity", length) == 0)) { |
| 122 |
if (argc < 4 || argc > 5) { |
| 123 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 124 |
argv[0], " mark gravity markName ?gravity?\"", |
| 125 |
(char *) NULL); |
| 126 |
return TCL_ERROR; |
| 127 |
} |
| 128 |
hPtr = Tcl_FindHashEntry(&textPtr->markTable, argv[3]); |
| 129 |
if (hPtr == NULL) { |
| 130 |
Tcl_AppendResult(interp, "there is no mark named \"", |
| 131 |
argv[3], "\"", (char *) NULL); |
| 132 |
return TCL_ERROR; |
| 133 |
} |
| 134 |
markPtr = (TkTextSegment *) Tcl_GetHashValue(hPtr); |
| 135 |
if (argc == 4) { |
| 136 |
if (markPtr->typePtr == &tkTextRightMarkType) { |
| 137 |
Tcl_SetResult(interp, "right", TCL_STATIC); |
| 138 |
} else { |
| 139 |
Tcl_SetResult(interp, "left", TCL_STATIC); |
| 140 |
} |
| 141 |
return TCL_OK; |
| 142 |
} |
| 143 |
length = strlen(argv[4]); |
| 144 |
c = argv[4][0]; |
| 145 |
if ((c == 'l') && (strncmp(argv[4], "left", length) == 0)) { |
| 146 |
newTypePtr = &tkTextLeftMarkType; |
| 147 |
} else if ((c == 'r') && (strncmp(argv[4], "right", length) == 0)) { |
| 148 |
newTypePtr = &tkTextRightMarkType; |
| 149 |
} else { |
| 150 |
Tcl_AppendResult(interp, "bad mark gravity \"", |
| 151 |
argv[4], "\": must be left or right", (char *) NULL); |
| 152 |
return TCL_ERROR; |
| 153 |
} |
| 154 |
TkTextMarkSegToIndex(textPtr, markPtr, &index); |
| 155 |
TkBTreeUnlinkSegment(textPtr->tree, markPtr, |
| 156 |
markPtr->body.mark.linePtr); |
| 157 |
markPtr->typePtr = newTypePtr; |
| 158 |
TkBTreeLinkSegment(markPtr, &index); |
| 159 |
} else if ((c == 'n') && (strncmp(argv[2], "names", length) == 0)) { |
| 160 |
if (argc != 3) { |
| 161 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 162 |
argv[0], " mark names\"", (char *) NULL); |
| 163 |
return TCL_ERROR; |
| 164 |
} |
| 165 |
for (hPtr = Tcl_FirstHashEntry(&textPtr->markTable, &search); |
| 166 |
hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) { |
| 167 |
Tcl_AppendElement(interp, |
| 168 |
Tcl_GetHashKey(&textPtr->markTable, hPtr)); |
| 169 |
} |
| 170 |
} else if ((c == 'n') && (strncmp(argv[2], "next", length) == 0)) { |
| 171 |
if (argc != 4) { |
| 172 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 173 |
argv[0], " mark next index\"", (char *) NULL); |
| 174 |
return TCL_ERROR; |
| 175 |
} |
| 176 |
return MarkFindNext(interp, textPtr, argv[3]); |
| 177 |
} else if ((c == 'p') && (strncmp(argv[2], "previous", length) == 0)) { |
| 178 |
if (argc != 4) { |
| 179 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 180 |
argv[0], " mark previous index\"", (char *) NULL); |
| 181 |
return TCL_ERROR; |
| 182 |
} |
| 183 |
return MarkFindPrev(interp, textPtr, argv[3]); |
| 184 |
} else if ((c == 's') && (strncmp(argv[2], "set", length) == 0)) { |
| 185 |
if (argc != 5) { |
| 186 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 187 |
argv[0], " mark set markName index\"", (char *) NULL); |
| 188 |
return TCL_ERROR; |
| 189 |
} |
| 190 |
if (TkTextGetIndex(interp, textPtr, argv[4], &index) != TCL_OK) { |
| 191 |
return TCL_ERROR; |
| 192 |
} |
| 193 |
TkTextSetMark(textPtr, argv[3], &index); |
| 194 |
} else if ((c == 'u') && (strncmp(argv[2], "unset", length) == 0)) { |
| 195 |
for (i = 3; i < argc; i++) { |
| 196 |
hPtr = Tcl_FindHashEntry(&textPtr->markTable, argv[i]); |
| 197 |
if (hPtr != NULL) { |
| 198 |
markPtr = (TkTextSegment *) Tcl_GetHashValue(hPtr); |
| 199 |
if ((markPtr == textPtr->insertMarkPtr) |
| 200 |
|| (markPtr == textPtr->currentMarkPtr)) { |
| 201 |
continue; |
| 202 |
} |
| 203 |
TkBTreeUnlinkSegment(textPtr->tree, markPtr, |
| 204 |
markPtr->body.mark.linePtr); |
| 205 |
Tcl_DeleteHashEntry(hPtr); |
| 206 |
ckfree((char *) markPtr); |
| 207 |
} |
| 208 |
} |
| 209 |
} else { |
| 210 |
Tcl_AppendResult(interp, "bad mark option \"", argv[2], |
| 211 |
"\": must be gravity, names, next, previous, set, or unset", |
| 212 |
(char *) NULL); |
| 213 |
return TCL_ERROR; |
| 214 |
} |
| 215 |
return TCL_OK; |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
TkTextSegment * |
| 236 |
TkTextSetMark(textPtr, name, indexPtr) |
| 237 |
TkText *textPtr; |
| 238 |
CONST char *name; |
| 239 |
TkTextIndex *indexPtr; |
| 240 |
{ |
| 241 |
Tcl_HashEntry *hPtr; |
| 242 |
TkTextSegment *markPtr; |
| 243 |
TkTextIndex insertIndex; |
| 244 |
int new; |
| 245 |
|
| 246 |
hPtr = Tcl_CreateHashEntry(&textPtr->markTable, name, &new); |
| 247 |
markPtr = (TkTextSegment *) Tcl_GetHashValue(hPtr); |
| 248 |
if (!new) { |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
if (markPtr == textPtr->insertMarkPtr) { |
| 257 |
TkTextIndex index, index2; |
| 258 |
TkTextMarkSegToIndex(textPtr, textPtr->insertMarkPtr, &index); |
| 259 |
TkTextIndexForwChars(&index, 1, &index2); |
| 260 |
TkTextChanged(textPtr, &index, &index2); |
| 261 |
if (TkBTreeLineIndex(indexPtr->linePtr) |
| 262 |
== TkBTreeNumLines(textPtr->tree)) { |
| 263 |
TkTextIndexBackChars(indexPtr, 1, &insertIndex); |
| 264 |
indexPtr = &insertIndex; |
| 265 |
} |
| 266 |
} |
| 267 |
TkBTreeUnlinkSegment(textPtr->tree, markPtr, |
| 268 |
markPtr->body.mark.linePtr); |
| 269 |
} else { |
| 270 |
markPtr = (TkTextSegment *) ckalloc(MSEG_SIZE); |
| 271 |
markPtr->typePtr = &tkTextRightMarkType; |
| 272 |
markPtr->size = 0; |
| 273 |
markPtr->body.mark.textPtr = textPtr; |
| 274 |
markPtr->body.mark.linePtr = indexPtr->linePtr; |
| 275 |
markPtr->body.mark.hPtr = hPtr; |
| 276 |
Tcl_SetHashValue(hPtr, markPtr); |
| 277 |
} |
| 278 |
TkBTreeLinkSegment(markPtr, indexPtr); |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
if (markPtr == textPtr->insertMarkPtr) { |
| 286 |
TkTextIndex index2; |
| 287 |
|
| 288 |
TkTextIndexForwChars(indexPtr, 1, &index2); |
| 289 |
TkTextChanged(textPtr, indexPtr, &index2); |
| 290 |
} |
| 291 |
return markPtr; |
| 292 |
} |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
void |
| 313 |
TkTextMarkSegToIndex(textPtr, markPtr, indexPtr) |
| 314 |
TkText *textPtr; |
| 315 |
TkTextSegment *markPtr; |
| 316 |
TkTextIndex *indexPtr; |
| 317 |
{ |
| 318 |
TkTextSegment *segPtr; |
| 319 |
|
| 320 |
indexPtr->tree = textPtr->tree; |
| 321 |
indexPtr->linePtr = markPtr->body.mark.linePtr; |
| 322 |
indexPtr->byteIndex = 0; |
| 323 |
for (segPtr = indexPtr->linePtr->segPtr; segPtr != markPtr; |
| 324 |
segPtr = segPtr->nextPtr) { |
| 325 |
indexPtr->byteIndex += segPtr->size; |
| 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 |
int |
| 351 |
TkTextMarkNameToIndex(textPtr, name, indexPtr) |
| 352 |
TkText *textPtr; |
| 353 |
CONST char *name; |
| 354 |
TkTextIndex *indexPtr; |
| 355 |
{ |
| 356 |
Tcl_HashEntry *hPtr; |
| 357 |
|
| 358 |
hPtr = Tcl_FindHashEntry(&textPtr->markTable, name); |
| 359 |
if (hPtr == NULL) { |
| 360 |
return TCL_ERROR; |
| 361 |
} |
| 362 |
TkTextMarkSegToIndex(textPtr, (TkTextSegment *) Tcl_GetHashValue(hPtr), |
| 363 |
indexPtr); |
| 364 |
return TCL_OK; |
| 365 |
} |
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
static int |
| 387 |
MarkDeleteProc(segPtr, linePtr, treeGone) |
| 388 |
TkTextSegment *segPtr; |
| 389 |
TkTextLine *linePtr; |
| 390 |
int treeGone; |
| 391 |
|
| 392 |
|
| 393 |
{ |
| 394 |
return 1; |
| 395 |
} |
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
static TkTextSegment * |
| 415 |
MarkCleanupProc(markPtr, linePtr) |
| 416 |
TkTextSegment *markPtr; |
| 417 |
TkTextLine *linePtr; |
| 418 |
{ |
| 419 |
markPtr->body.mark.linePtr = linePtr; |
| 420 |
return markPtr; |
| 421 |
} |
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
static int |
| 444 |
MarkLayoutProc(textPtr, indexPtr, segPtr, offset, maxX, maxChars, |
| 445 |
noCharsYet, wrapMode, chunkPtr) |
| 446 |
TkText *textPtr; |
| 447 |
TkTextIndex *indexPtr; |
| 448 |
TkTextSegment *segPtr; |
| 449 |
int offset; |
| 450 |
|
| 451 |
int maxX; |
| 452 |
|
| 453 |
int maxChars; |
| 454 |
|
| 455 |
int noCharsYet; |
| 456 |
|
| 457 |
TkWrapMode wrapMode; |
| 458 |
register TkTextDispChunk *chunkPtr; |
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
{ |
| 463 |
if (segPtr != textPtr->insertMarkPtr) { |
| 464 |
return -1; |
| 465 |
} |
| 466 |
|
| 467 |
chunkPtr->displayProc = TkTextInsertDisplayProc; |
| 468 |
chunkPtr->undisplayProc = InsertUndisplayProc; |
| 469 |
chunkPtr->measureProc = (Tk_ChunkMeasureProc *) NULL; |
| 470 |
chunkPtr->bboxProc = (Tk_ChunkBboxProc *) NULL; |
| 471 |
chunkPtr->numBytes = 0; |
| 472 |
chunkPtr->minAscent = 0; |
| 473 |
chunkPtr->minDescent = 0; |
| 474 |
chunkPtr->minHeight = 0; |
| 475 |
chunkPtr->width = 0; |
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
chunkPtr->breakIndex = -1; |
| 484 |
chunkPtr->clientData = (ClientData) textPtr; |
| 485 |
return 1; |
| 486 |
} |
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
void |
| 507 |
TkTextInsertDisplayProc(chunkPtr, x, y, height, baseline, display, dst, screenY) |
| 508 |
TkTextDispChunk *chunkPtr; |
| 509 |
int x; |
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
int y; |
| 514 |
|
| 515 |
|
| 516 |
int height; |
| 517 |
int baseline; |
| 518 |
Display *display; |
| 519 |
Drawable dst; |
| 520 |
|
| 521 |
int screenY; |
| 522 |
|
| 523 |
{ |
| 524 |
TkText *textPtr = (TkText *) chunkPtr->clientData; |
| 525 |
int halfWidth = textPtr->insertWidth/2; |
| 526 |
|
| 527 |
if ((x + halfWidth) < 0) { |
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
Tk_SetCaretPos(textPtr->tkwin, 0, 0, height); |
| 534 |
return; |
| 535 |
} |
| 536 |
|
| 537 |
Tk_SetCaretPos(textPtr->tkwin, x - halfWidth, screenY, height); |
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
if (textPtr->flags & INSERT_ON) { |
| 548 |
Tk_Fill3DRectangle(textPtr->tkwin, dst, textPtr->insertBorder, |
| 549 |
x - halfWidth, y, textPtr->insertWidth, height, |
| 550 |
textPtr->insertBorderWidth, TK_RELIEF_RAISED); |
| 551 |
} else if (textPtr->selBorder == textPtr->insertBorder) { |
| 552 |
Tk_Fill3DRectangle(textPtr->tkwin, dst, textPtr->border, |
| 553 |
x - halfWidth, y, textPtr->insertWidth, height, |
| 554 |
0, TK_RELIEF_FLAT); |
| 555 |
} |
| 556 |
} |
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
static void |
| 578 |
InsertUndisplayProc(textPtr, chunkPtr) |
| 579 |
TkText *textPtr; |
| 580 |
|
| 581 |
TkTextDispChunk *chunkPtr; |
| 582 |
{ |
| 583 |
return; |
| 584 |
} |
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
static void |
| 605 |
MarkCheckProc(markPtr, linePtr) |
| 606 |
TkTextSegment *markPtr; |
| 607 |
TkTextLine *linePtr; |
| 608 |
{ |
| 609 |
Tcl_HashSearch search; |
| 610 |
Tcl_HashEntry *hPtr; |
| 611 |
|
| 612 |
if (markPtr->body.mark.linePtr != linePtr) { |
| 613 |
panic("MarkCheckProc: markPtr->body.mark.linePtr bogus"); |
| 614 |
} |
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
for (hPtr = Tcl_FirstHashEntry(&markPtr->body.mark.textPtr->markTable, |
| 622 |
&search); hPtr != markPtr->body.mark.hPtr; |
| 623 |
hPtr = Tcl_NextHashEntry(&search)) { |
| 624 |
if (hPtr == NULL) { |
| 625 |
panic("MarkCheckProc couldn't find hash table entry for mark"); |
| 626 |
} |
| 627 |
} |
| 628 |
} |
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
static int |
| 647 |
MarkFindNext(interp, textPtr, string) |
| 648 |
Tcl_Interp *interp; |
| 649 |
TkText *textPtr; |
| 650 |
CONST char *string; |
| 651 |
{ |
| 652 |
TkTextIndex index; |
| 653 |
Tcl_HashEntry *hPtr; |
| 654 |
register TkTextSegment *segPtr; |
| 655 |
int offset; |
| 656 |
|
| 657 |
|
| 658 |
hPtr = Tcl_FindHashEntry(&textPtr->markTable, string); |
| 659 |
if (hPtr != NULL) { |
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
segPtr = (TkTextSegment *) Tcl_GetHashValue(hPtr); |
| 665 |
TkTextMarkSegToIndex(textPtr, segPtr, &index); |
| 666 |
segPtr = segPtr->nextPtr; |
| 667 |
} else { |
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
if (TkTextGetIndex(interp, textPtr, string, &index) != TCL_OK) { |
| 673 |
return TCL_ERROR; |
| 674 |
} |
| 675 |
for (offset = 0, segPtr = index.linePtr->segPtr; |
| 676 |
segPtr != NULL && offset < index.byteIndex; |
| 677 |
offset += segPtr->size, segPtr = segPtr->nextPtr) { |
| 678 |
; |
| 679 |
} |
| 680 |
} |
| 681 |
while (1) { |
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
for ( ; segPtr != NULL ; segPtr = segPtr->nextPtr) { |
| 687 |
if (segPtr->typePtr == &tkTextRightMarkType || |
| 688 |
segPtr->typePtr == &tkTextLeftMarkType) { |
| 689 |
Tcl_SetResult(interp, |
| 690 |
Tcl_GetHashKey(&textPtr->markTable, segPtr->body.mark.hPtr), |
| 691 |
TCL_STATIC); |
| 692 |
return TCL_OK; |
| 693 |
} |
| 694 |
} |
| 695 |
index.linePtr = TkBTreeNextLine(index.linePtr); |
| 696 |
if (index.linePtr == (TkTextLine *) NULL) { |
| 697 |
return TCL_OK; |
| 698 |
} |
| 699 |
index.byteIndex = 0; |
| 700 |
segPtr = index.linePtr->segPtr; |
| 701 |
} |
| 702 |
} |
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
static int |
| 721 |
MarkFindPrev(interp, textPtr, string) |
| 722 |
Tcl_Interp *interp; |
| 723 |
TkText *textPtr; |
| 724 |
CONST char *string; |
| 725 |
{ |
| 726 |
TkTextIndex index; |
| 727 |
Tcl_HashEntry *hPtr; |
| 728 |
register TkTextSegment *segPtr, *seg2Ptr, *prevPtr; |
| 729 |
int offset; |
| 730 |
|
| 731 |
|
| 732 |
hPtr = Tcl_FindHashEntry(&textPtr->markTable, string); |
| 733 |
if (hPtr != NULL) { |
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
segPtr = (TkTextSegment *) Tcl_GetHashValue(hPtr); |
| 739 |
TkTextMarkSegToIndex(textPtr, segPtr, &index); |
| 740 |
} else { |
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
if (TkTextGetIndex(interp, textPtr, string, &index) != TCL_OK) { |
| 746 |
return TCL_ERROR; |
| 747 |
} |
| 748 |
for (offset = 0, segPtr = index.linePtr->segPtr; |
| 749 |
segPtr != NULL && offset < index.byteIndex; |
| 750 |
offset += segPtr->size, segPtr = segPtr->nextPtr) { |
| 751 |
; |
| 752 |
} |
| 753 |
} |
| 754 |
while (1) { |
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
for (prevPtr = NULL, seg2Ptr = index.linePtr->segPtr; |
| 760 |
seg2Ptr != NULL && seg2Ptr != segPtr; |
| 761 |
seg2Ptr = seg2Ptr->nextPtr) { |
| 762 |
if (seg2Ptr->typePtr == &tkTextRightMarkType || |
| 763 |
seg2Ptr->typePtr == &tkTextLeftMarkType) { |
| 764 |
prevPtr = seg2Ptr; |
| 765 |
} |
| 766 |
} |
| 767 |
if (prevPtr != NULL) { |
| 768 |
Tcl_SetResult(interp, |
| 769 |
Tcl_GetHashKey(&textPtr->markTable, prevPtr->body.mark.hPtr), |
| 770 |
TCL_STATIC); |
| 771 |
return TCL_OK; |
| 772 |
} |
| 773 |
index.linePtr = TkBTreePreviousLine(index.linePtr); |
| 774 |
if (index.linePtr == (TkTextLine *) NULL) { |
| 775 |
return TCL_OK; |
| 776 |
} |
| 777 |
segPtr = NULL; |
| 778 |
} |
| 779 |
} |
| 780 |
|