diff options
author | fvogel <fvogelnew1@free.fr> | 2019-04-28 12:52:43 (GMT) |
---|---|---|
committer | fvogel <fvogelnew1@free.fr> | 2019-04-28 12:52:43 (GMT) |
commit | faf3d3197da965a56835db30b149ef85ce2384f1 (patch) | |
tree | 5f96923234c06f80f20f5a122e3d1b89b3fd1621 | |
parent | a45cd9e5e3fc6da137e7a23ebd4b507b3905c142 (diff) | |
download | tk-faf3d3197da965a56835db30b149ef85ce2384f1.zip tk-faf3d3197da965a56835db30b149ef85ce2384f1.tar.gz tk-faf3d3197da965a56835db30b149ef85ce2384f1.tar.bz2 |
Factorize the code a bit, and avoid calling the layoutProc twice when calling xview moveto|units|pages.
-rw-r--r-- | generic/ttk/ttkEntry.c | 2 | ||||
-rw-r--r-- | generic/ttk/ttkScroll.c | 47 | ||||
-rw-r--r-- | generic/ttk/ttkTreeview.c | 4 | ||||
-rw-r--r-- | generic/ttk/ttkWidget.h | 2 |
4 files changed, 25 insertions, 30 deletions
diff --git a/generic/ttk/ttkEntry.c b/generic/ttk/ttkEntry.c index ebc485e..e306953 100644 --- a/generic/ttk/ttkEntry.c +++ b/generic/ttk/ttkEntry.c @@ -1656,7 +1656,7 @@ static int EntryXViewCommand( if (EntryIndex(interp, entryPtr, objv[2], &newFirst) != TCL_OK) { return TCL_ERROR; } - TtkScrollTo(entryPtr->entry.xscrollHandle, newFirst); + TtkScrollTo(entryPtr->entry.xscrollHandle, newFirst, 1); return TCL_OK; } return TtkScrollviewCommand(interp, objc, objv, entryPtr->entry.xscrollHandle); diff --git a/generic/ttk/ttkScroll.c b/generic/ttk/ttkScroll.c index 84fbff2..47db6ac 100644 --- a/generic/ttk/ttkScroll.c +++ b/generic/ttk/ttkScroll.c @@ -181,6 +181,19 @@ void TtkScrollbarUpdateRequired(ScrollHandle h) h->flags |= SCROLL_UPDATE_REQUIRED; } +/* TtkUpdateScrollInfo -- + * Call the layoutProc to update the scroll info first, last, and total. + * Do it only if needed, that is when a redisplay is pending (which + * indicates scroll info are possibly out of date). + */ + +void TtkUpdateScrollInfo(ScrollHandle h) +{ + if (h->corePtr->flags & REDISPLAY_PENDING) { + h->corePtr->widgetSpec->layoutProc(h->corePtr); + } +} + /* TtkScrollviewCommand -- * Widget [xy]view command implementation. * @@ -193,19 +206,13 @@ int TtkScrollviewCommand( Tcl_Interp *interp, int objc, Tcl_Obj *const objv[], ScrollHandle h) { Scrollable *s = h->scrollPtr; - int newFirst = s->first; + int newFirst; + + TtkUpdateScrollInfo(h); + newFirst = s->first; if (objc == 2) { Tcl_Obj *result[2]; - - /* - * Update the scroll info (first, last, total) if needed. - */ - - if (h->corePtr->flags & REDISPLAY_PENDING) { - h->corePtr->widgetSpec->layoutProc(h->corePtr); - } - result[0] = Tcl_NewDoubleObj((double)s->first / s->total); result[1] = Tcl_NewDoubleObj((double)s->last / s->total); Tcl_SetObjResult(interp, Tcl_NewListObj(2, result)); @@ -218,14 +225,6 @@ int TtkScrollviewCommand( double fraction; int count; - /* - * Update the scroll info (first, last, total) if needed. - */ - - if (h->corePtr->flags & REDISPLAY_PENDING) { - h->corePtr->widgetSpec->layoutProc(h->corePtr); - } - switch (Tk_GetScrollInfoObj(interp, objc, objv, &fraction, &count)) { case TK_SCROLL_ERROR: return TCL_ERROR; @@ -243,21 +242,17 @@ int TtkScrollviewCommand( } } - TtkScrollTo(h, newFirst); + TtkScrollTo(h, newFirst, 0); return TCL_OK; } -void TtkScrollTo(ScrollHandle h, int newFirst) +void TtkScrollTo(ScrollHandle h, int newFirst, int updateScrollInfo) { Scrollable *s = h->scrollPtr; - /* - * Update the scroll info (first, last, total) if needed. - */ - - if (h->corePtr->flags & REDISPLAY_PENDING) { - h->corePtr->widgetSpec->layoutProc(h->corePtr); + if (updateScrollInfo) { + TtkUpdateScrollInfo(h); } if (newFirst >= s->total) diff --git a/generic/ttk/ttkTreeview.c b/generic/ttk/ttkTreeview.c index 68a9b6d..d78df5f 100644 --- a/generic/ttk/ttkTreeview.c +++ b/generic/ttk/ttkTreeview.c @@ -2845,10 +2845,10 @@ static int TreeviewSeeCommand( */ rowNumber = RowNumber(tv, item); if (rowNumber < tv->tree.yscroll.first) { - TtkScrollTo(tv->tree.yscrollHandle, rowNumber); + TtkScrollTo(tv->tree.yscrollHandle, rowNumber, 1); } else if (rowNumber >= tv->tree.yscroll.last) { TtkScrollTo(tv->tree.yscrollHandle, - tv->tree.yscroll.first + (1+rowNumber - tv->tree.yscroll.last)); + tv->tree.yscroll.first + (1+rowNumber - tv->tree.yscroll.last), 1); } return TCL_OK; diff --git a/generic/ttk/ttkWidget.h b/generic/ttk/ttkWidget.h index e4dd712..7ccc1f3 100644 --- a/generic/ttk/ttkWidget.h +++ b/generic/ttk/ttkWidget.h @@ -195,7 +195,7 @@ MODULE_SCOPE void TtkFreeScrollHandle(ScrollHandle); MODULE_SCOPE int TtkScrollviewCommand( Tcl_Interp *interp, int objc, Tcl_Obj *const objv[], ScrollHandle); -MODULE_SCOPE void TtkScrollTo(ScrollHandle, int newFirst); +MODULE_SCOPE void TtkScrollTo(ScrollHandle, int newFirst, int updateScrollInfo); MODULE_SCOPE void TtkScrolled(ScrollHandle, int first, int last, int total); MODULE_SCOPE void TtkScrollbarUpdateRequired(ScrollHandle); |