From 1238f724da65d098cb652af93972b4d0ac6e8f72 Mon Sep 17 00:00:00 2001 From: fvogel Date: Sat, 21 Nov 2015 08:43:25 +0000 Subject: Adjusted when <> fires. Also %d now only has boolean value. Implementation in sync with TIP #438 rev. 1.10 --- generic/tkTextDisp.c | 24 +++++++++++++++++------- tests/text.test | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/generic/tkTextDisp.c b/generic/tkTextDisp.c index 3cee288..d8a17a9 100644 --- a/generic/tkTextDisp.c +++ b/generic/tkTextDisp.c @@ -590,7 +590,7 @@ static int TextGetScrollInfoObj(Tcl_Interp *interp, Tcl_Obj *CONST objv[], double *dblPtr, int *intPtr); static void AsyncUpdateLineMetrics(ClientData clientData); -static void GenerateWidgetViewSyncEvent(TkText *textPtr); +static void GenerateWidgetViewSyncEvent(TkText *textPtr, Bool InSync); static void AsyncUpdateYScrollbar(ClientData clientData); static int IsStartOfNotMergedLine(TkText *textPtr, CONST TkTextIndex *indexPtr); @@ -2930,8 +2930,6 @@ AsyncUpdateLineMetrics( LOG("tk_textInvalidateLine", buffer); } - GenerateWidgetViewSyncEvent(textPtr); - /* * If we're not in the middle of a long-line calculation (metricEpoch==-1) * and we've reached the last line, then we're done. @@ -2959,6 +2957,14 @@ AsyncUpdateLineMetrics( textPtr->afterSyncCmd = 0; } + /* + * Fire the <> event since the widget view is in sync + * with its internal data (actually it will be after the next trip + * through the event loop, because the widget redraws at idle-time). + */ + + GenerateWidgetViewSyncEvent(textPtr, 1); + textPtr->refCount--; if (textPtr->refCount == 0) { ckfree((char *) textPtr); @@ -2983,8 +2989,9 @@ AsyncUpdateLineMetrics( * Send the <> event related to the text widget * line metrics asynchronous update. * This is equivalent to: - * event generate $textWidget <> -detail $N - * where $N is the number of lines for which the height is outdated. + * event generate $textWidget <> -detail $s + * where $s is the sync status: true (when the widget view is in + * sync with its internal data) or false (when it is not). * * Results: * None @@ -2997,7 +3004,8 @@ AsyncUpdateLineMetrics( static void GenerateWidgetViewSyncEvent( - TkText *textPtr) /* Information about text widget. */ + TkText *textPtr, /* Information about text widget. */ + Bool InSync) /* True if in sync, false otherwise */ { union {XEvent general; XVirtualEvent virtual;} event; @@ -3008,7 +3016,7 @@ GenerateWidgetViewSyncEvent( event.general.xany.window = Tk_WindowId(textPtr->tkwin); event.general.xany.display = Tk_Display(textPtr->tkwin); event.virtual.name = Tk_GetUid("WidgetViewSync"); - event.virtual.user_data = Tcl_NewIntObj(TkTextPendingsync(textPtr)); + event.virtual.user_data = Tcl_NewBooleanObj(InSync); Tk_HandleEvent(&event.general); } @@ -3391,6 +3399,7 @@ TextInvalidateLineMetrics( textPtr->refCount++; dInfoPtr->lineUpdateTimer = Tcl_CreateTimerHandler(1, AsyncUpdateLineMetrics, (ClientData) textPtr); + GenerateWidgetViewSyncEvent(textPtr, 0); } } @@ -5095,6 +5104,7 @@ TkTextRelayoutWindow( textPtr->refCount++; dInfoPtr->lineUpdateTimer = Tcl_CreateTimerHandler(1, AsyncUpdateLineMetrics, (ClientData) textPtr); + GenerateWidgetViewSyncEvent(textPtr, 0); } } } diff --git a/tests/text.test b/tests/text.test index 3532546..3ba85b7 100644 --- a/tests/text.test +++ b/tests/text.test @@ -1035,7 +1035,7 @@ test text-11a.21 {"<>" event} { } .top.yt insert 1.0 $content update - bind .top.yt <> { if {%d == 0} {set yud(%W) 1} } + bind .top.yt <> { if {%d} {set yud(%W) 1} } # wait for end of line metrics calculation to get correct $fraction1 # as a reference if {[.top.yt pendingsync]} {vwait yud(.top.yt)} -- cgit v0.12