Tk Source Code

Check-in [94b42ed3]
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:Implementation of TIP #438 - Solution using virtual events
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tip-438-events
Files: files | file ages | folders
SHA1: 94b42ed36a2ac091d2a615c43e36d8a6c25cabe3
User & Date: fvogel 2015-11-10 21:03:04
Context
2015-11-14
13:05
TIP #438 - <<TextLineHeightsInvalid>> event added, with corresponding new tests check-in: 83bb08d7 user: fvogel tags: tip-438
2015-11-10
21:03
Implementation of TIP #438 - Solution using virtual events Closed-Leaf check-in: 94b42ed3 user: fvogel tags: tip-438-events
18:38
Typos in comments check-in: a44fe929 user: fvogel tags: core-8-5-branch
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/tkTextDisp.c.

586
587
588
589
590
591
592


593
594
595
596
597
598
599
....
2940
2941
2942
2943
2944
2945
2946

2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958













































2959
2960
2961
2962
2963
2964
2965
....
3332
3333
3334
3335
3336
3337
3338

3339
3340
3341
3342
3343
3344
3345
....
5036
5037
5038
5039
5040
5041
5042

5043
5044
5045
5046
5047
5048
5049
static int		DlineXOfIndex(TkText *textPtr,
			    DLine *dlPtr, int byteIndex);
static int		TextGetScrollInfoObj(Tcl_Interp *interp,
			    TkText *textPtr, int objc,
			    Tcl_Obj *CONST objv[], double *dblPtr,
			    int *intPtr);
static void		AsyncUpdateLineMetrics(ClientData clientData);


static void		AsyncUpdateYScrollbar(ClientData clientData);
static int              IsStartOfNotMergedLine(TkText *textPtr,
                            CONST TkTextIndex *indexPtr);

/*
 * Result values returned by TextGetScrollInfoObj:
 */
................................................................................
	 * above).
	 */

	textPtr->refCount--;
	if (textPtr->refCount == 0) {
	    ckfree((char *) textPtr);
	}

	return;
    }
    dInfoPtr->currentMetricUpdateLine = lineNum;

    /*
     * Re-arm the timer. We already have a refCount on the text widget so no
     * need to adjust that.
     */

    dInfoPtr->lineUpdateTimer = Tcl_CreateTimerHandler(1,
	    AsyncUpdateLineMetrics, (ClientData) textPtr);
}













































 
/*
 *----------------------------------------------------------------------
 *
 * TkTextUpdateLineMetrics --
 *
 *	This function updates the pixel height calculations of a range of
................................................................................
     * Now re-set the current update calculations.
     */

    if (dInfoPtr->lineUpdateTimer == NULL) {
	textPtr->refCount++;
	dInfoPtr->lineUpdateTimer = Tcl_CreateTimerHandler(1,
		AsyncUpdateLineMetrics, (ClientData) textPtr);

    }
}
 
/*
 *----------------------------------------------------------------------
 *
 * TkTextFindDisplayLineEnd --
................................................................................

	dInfoPtr->metricEpoch = -1;

	if (dInfoPtr->lineUpdateTimer == NULL) {
	    textPtr->refCount++;
	    dInfoPtr->lineUpdateTimer = Tcl_CreateTimerHandler(1,
		    AsyncUpdateLineMetrics, (ClientData) textPtr);

	}
    }
}
 
/*
 *----------------------------------------------------------------------
 *






>
>







 







>












>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>







 







>







586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
....
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
....
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
....
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
static int		DlineXOfIndex(TkText *textPtr,
			    DLine *dlPtr, int byteIndex);
static int		TextGetScrollInfoObj(Tcl_Interp *interp,
			    TkText *textPtr, int objc,
			    Tcl_Obj *CONST objv[], double *dblPtr,
			    int *intPtr);
static void		AsyncUpdateLineMetrics(ClientData clientData);
static void		GenerateMetricsEvent(TkText *textPtr,
                            CONST char *eventname);
static void		AsyncUpdateYScrollbar(ClientData clientData);
static int              IsStartOfNotMergedLine(TkText *textPtr,
                            CONST TkTextIndex *indexPtr);

/*
 * Result values returned by TextGetScrollInfoObj:
 */
................................................................................
	 * above).
	 */

	textPtr->refCount--;
	if (textPtr->refCount == 0) {
	    ckfree((char *) textPtr);
	}
        GenerateMetricsEvent(textPtr, "MetricsDone");
	return;
    }
    dInfoPtr->currentMetricUpdateLine = lineNum;

    /*
     * Re-arm the timer. We already have a refCount on the text widget so no
     * need to adjust that.
     */

    dInfoPtr->lineUpdateTimer = Tcl_CreateTimerHandler(1,
	    AsyncUpdateLineMetrics, (ClientData) textPtr);
}
 
/*
 *----------------------------------------------------------------------
 *
 * GenerateMetricsEvent --
 *
 *      Send an event related to the text widget metrics asynchronous update
 *      Two events are used:
 *      - <<MetricsOutdated>>: the asynchronous update of line metrics is
 *        currently running
 *      - <<MetricsDone>>    : the asynchronous update of line metrics is
 *        over
 *      This is equivalent to:
 *         event generate $textWidget <<MetricsOutdated>>
 *      or
 *         event generate $textWidget <<MetricsDone>>
 *
 * Results:
 *      None
 *
 * Side effects:
 *      May force the text window into existence.
 *      If corresponding bindings are present, they will trigger.
 *
 *----------------------------------------------------------------------
 */

static void
GenerateMetricsEvent(
    TkText *textPtr,		/* Information about text widget. */
    CONST char *eventname)	/* Name of the virtual event to send. */
{
    union {XEvent general; XVirtualEvent virtual;} event;

    Tk_MakeWindowExist(textPtr->tkwin);

    memset(&event, 0, sizeof(event));
    event.general.xany.type = VirtualEvent;
    event.general.xany.serial = NextRequest(Tk_Display(textPtr->tkwin));
    event.general.xany.send_event = False;
    event.general.xany.window = Tk_WindowId(textPtr->tkwin);
    event.general.xany.display = Tk_Display(textPtr->tkwin);
    event.virtual.name = Tk_GetUid(eventname);
    Tk_HandleEvent(&event.general);
}
 
/*
 *----------------------------------------------------------------------
 *
 * TkTextUpdateLineMetrics --
 *
 *	This function updates the pixel height calculations of a range of
................................................................................
     * Now re-set the current update calculations.
     */

    if (dInfoPtr->lineUpdateTimer == NULL) {
	textPtr->refCount++;
	dInfoPtr->lineUpdateTimer = Tcl_CreateTimerHandler(1,
		AsyncUpdateLineMetrics, (ClientData) textPtr);
        GenerateMetricsEvent(textPtr, "MetricsOutdated");
    }
}
 
/*
 *----------------------------------------------------------------------
 *
 * TkTextFindDisplayLineEnd --
................................................................................

	dInfoPtr->metricEpoch = -1;

	if (dInfoPtr->lineUpdateTimer == NULL) {
	    textPtr->refCount++;
	    dInfoPtr->lineUpdateTimer = Tcl_CreateTimerHandler(1,
		    AsyncUpdateLineMetrics, (ClientData) textPtr);
            GenerateMetricsEvent(textPtr, "MetricsOutdated");
	}
    }
}
 
/*
 *----------------------------------------------------------------------
 *