(textPtr, interp, argc, argv)
| 1459 | * |
| 1460 | * TextScanCmd -- |
| 1461 | * |
| 1462 | * This procedure is invoked to process the "scan" options of |
| 1463 | * the widget command for text widgets. See the user documentation |
| 1464 | * for details on what it does. |
| 1465 | * |
| 1466 | * Results: |
| 1467 | * A standard Tcl result. |
| 1468 | * |
| 1469 | * Side effects: |
| 1470 | * See the user documentation. |
| 1471 | * |
| 1472 | *-------------------------------------------------------------- |
| 1473 | */ |
| 1474 | |
| 1475 | static int |
| 1476 | TextScanCmd(textPtr, interp, argc, argv) |
| 1477 | register TkText *textPtr; /* Information about text widget. */ |
| 1478 | Tcl_Interp *interp; /* Current interpreter. */ |
| 1479 | int argc; /* Number of arguments. */ |
| 1480 | char **argv; /* Argument strings. Someone else has already |
| 1481 | * parsed this command enough to know that |
| 1482 | * argv[1] is "tag". */ |
| 1483 | { |
| 1484 | int length, y, line, lastLine; |
| 1485 | char c; |
| 1486 | |
| 1487 | if (argc != 4) { |
| 1488 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 1489 | argv[0], " scan mark|dragto y\"", (char *) NULL); |
| 1490 | return TCL_ERROR; |
| 1491 | } |
| 1492 | if (Tcl_GetInt(interp, argv[3], &y) != TCL_OK) { |
| 1493 | return TCL_ERROR; |
| 1494 | } |
| 1495 | c = argv[2][0]; |
| 1496 | length = strlen(argv[2]); |
| 1497 | if ((c == 'd') && (strncmp(argv[2], "dragto", length) == 0)) { |
| 1498 | /* |
| 1499 | * Amplify the difference between the current y position and the |
| 1500 | * mark position to compute how many lines up or down the view |
| 1501 | * should shift, then update the mark position to correspond to |
| 1502 | * the new view. If we run off the top or bottom of the text, |
| 1503 | * reset the mark point so that the current position continues |
| 1504 | * to correspond to the edge of the window. This means that the |
| 1505 | * picture will start dragging as soon as the mouse reverses |
| 1506 | * direction (without this reset, might have to slide mouse a |
| 1507 | * long ways back before the picture starts moving again). |
| 1508 | */ |
| 1509 | |
| 1510 | line = textPtr->scanMarkLine + (10*(textPtr->scanMarkY - y)) |
| 1511 | / (textPtr->fontPtr->ascent + textPtr->fontPtr->descent); |
| 1512 | lastLine = TkBTreeNumLines(textPtr->tree) - 1; |
| 1513 | if (line < 0) { |
| 1514 | textPtr->scanMarkLine = line = 0; |
| 1515 | textPtr->scanMarkY = y; |
| 1516 | } else if (line > lastLine) { |
| 1517 | textPtr->scanMarkLine = line = lastLine; |
| 1518 | textPtr->scanMarkY = y; |
no test coverage detected