Tk Source Code

Check-in [8317b198]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Now -insertwidth will be honored, and the visibility of the cursor at very right side will be ensured.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | revised_text | tip-466
Files: files | file ages | folders
SHA3-256: 8317b198ebe23aa2daf1356dc7aea83cee1090a843d73ab1e26b2a8561750c7a
User & Date: gcramer 2018-11-04 13:43:04
References
2018-11-04
13:46 Ticket [6e16952a] revised_text insertion cursor and -padx issues status still Open with 3 other changes artifact: 72cfa880 user: gcramer
Context
2018-11-12
11:28
A few corrections in manual. check-in: 9cc89227 user: gcramer tags: revised_text, tip-466
2018-11-04
13:43
Now -insertwidth will be honored, and the visibility of the cursor at very right side will be ensured. check-in: 8317b198 user: gcramer tags: revised_text, tip-466
2018-11-02
18:43
Show cursor in any case, even if padx=0. check-in: b5d2bf70 user: gcramer tags: revised_text, tip-466
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/tkTextMark.c.

2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
....
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
....
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
....
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
    assert(textPtr);
    assert(x);
    assert(y);
    assert(w);
    assert(h);

    cursorExtent = MAX(1, MIN(textPtr->padX, textPtr->insertWidth/2));
    TkTextMarkSegToIndex(textPtr, textPtr->insertMarkPtr, &index);

    if (!TkTextIndexBbox(textPtr, &index, false, x, y, w, h, &charWidth, &thisChar)) {
	int base, ix, iw;

	/*
	 * Testing whether the cursor is visible is not as trivial at it seems,
................................................................................
	*x -= charWidth;
    }

    if (textPtr->blockCursorType) {
	/* NOTE: the block cursor extent is always rounded towards zero. */
	*w = charWidth + 2*cursorExtent;
    } else {
	*w = MIN(textPtr->insertWidth, textPtr->padX + cursorExtent);
    }

    *x -= cursorExtent;
    return true;
}
 
/*
................................................................................
unsigned
TkTextGetCursorWidth(
    TkText *textPtr,		/* The current text widget. */
    int *x,			/* Shift x coordinate, can be NULL. */
    int *extent)		/* Extent of cursor to left side, can be NULL. */
{
    int width;
    int cursorExtent = MAX(1, MIN(textPtr->padX, textPtr->insertWidth/2));

    if (extent) {
	*extent = -cursorExtent;
    }

    if (textPtr->blockCursorType) {
	int ix, iy, ih;

	if (!TkTextGetCursorBbox(textPtr, &ix, &iy, &width, &ih)) {
	    return 0; /* cursor is not visible at all */
	}
    } else {
	width = MIN(textPtr->insertWidth, textPtr->padX + cursorExtent);
    }

    return width;
}
 
/*
 *--------------------------------------------------------------
................................................................................
    int baseline,		/* Offset of baseline from y. */
    Display *display,		/* Display to use for drawing. */
    Drawable dst,		/* Pixmap or window in which to draw chunk. */
    int screenY)		/* Y-coordinate in text window that corresponds to y. */
{
    int halfWidth = textPtr->insertWidth/2;
    int width = TkTextGetCursorWidth(textPtr, &x, NULL);
    int rightSideWidth = width + halfWidth - textPtr->insertWidth;

    if ((x + rightSideWidth) < 0) {
	/*
	 * The insertion cursor is off-screen. Indicate caret at 0,0 and return.
	 */

	Tk_SetCaretPos(textPtr->tkwin, 0, 0, height);
	return;
    }

    /*
     * Always show insert cursor, so don't allow negative x position.
     * See also function ComputeCursorExtents() in file tkTextDisp.c.
     */

    x = MAX(0, x - halfWidth);

    Tk_SetCaretPos(textPtr->tkwin, x, screenY, height);

    if (POINTER_IS_MARKED(chunkPtr)) {
	/*
	 * HACK: We are drawing into a tailored pixmap, because Tk has no clipping;
	 * see DisplayDLine().






|







 







|







 







|












|







 







|










|
|
|
|
|
<







2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
....
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
....
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
....
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755

2756
2757
2758
2759
2760
2761
2762
    assert(textPtr);
    assert(x);
    assert(y);
    assert(w);
    assert(h);

    cursorExtent = MAX(1, textPtr->insertWidth/2);
    TkTextMarkSegToIndex(textPtr, textPtr->insertMarkPtr, &index);

    if (!TkTextIndexBbox(textPtr, &index, false, x, y, w, h, &charWidth, &thisChar)) {
	int base, ix, iw;

	/*
	 * Testing whether the cursor is visible is not as trivial at it seems,
................................................................................
	*x -= charWidth;
    }

    if (textPtr->blockCursorType) {
	/* NOTE: the block cursor extent is always rounded towards zero. */
	*w = charWidth + 2*cursorExtent;
    } else {
	*w = textPtr->insertWidth;
    }

    *x -= cursorExtent;
    return true;
}
 
/*
................................................................................
unsigned
TkTextGetCursorWidth(
    TkText *textPtr,		/* The current text widget. */
    int *x,			/* Shift x coordinate, can be NULL. */
    int *extent)		/* Extent of cursor to left side, can be NULL. */
{
    int width;
    int cursorExtent = MAX(1, textPtr->insertWidth/2);

    if (extent) {
	*extent = -cursorExtent;
    }

    if (textPtr->blockCursorType) {
	int ix, iy, ih;

	if (!TkTextGetCursorBbox(textPtr, &ix, &iy, &width, &ih)) {
	    return 0; /* cursor is not visible at all */
	}
    } else {
	width = textPtr->insertWidth;
    }

    return width;
}
 
/*
 *--------------------------------------------------------------
................................................................................
    int baseline,		/* Offset of baseline from y. */
    Display *display,		/* Display to use for drawing. */
    Drawable dst,		/* Pixmap or window in which to draw chunk. */
    int screenY)		/* Y-coordinate in text window that corresponds to y. */
{
    int halfWidth = textPtr->insertWidth/2;
    int width = TkTextGetCursorWidth(textPtr, &x, NULL);
    int rightSideWidth = MAX(1, width + halfWidth - textPtr->insertWidth);

    if ((x + rightSideWidth) < 0) {
	/*
	 * The insertion cursor is off-screen. Indicate caret at 0,0 and return.
	 */

	Tk_SetCaretPos(textPtr->tkwin, 0, 0, height);
	return;
    }

    x -= halfWidth;
    if (halfWidth == 0 && x >= TkTextGetLastXPixel(textPtr)) {
	/* Ensure visibility of at least 1 pixel */
	x -= 1;
    }


    Tk_SetCaretPos(textPtr->tkwin, x, screenY, height);

    if (POINTER_IS_MARKED(chunkPtr)) {
	/*
	 * HACK: We are drawing into a tailored pixmap, because Tk has no clipping;
	 * see DisplayDLine().