diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-03-20 08:31:04 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-03-20 08:31:04 (GMT) |
commit | 522f8027b2de092fb9684f8135dedc0aba75217c (patch) | |
tree | cd2c4c457e71e8ea2303c50cf887eb3d15bc6d87 /generic/ttk | |
parent | 55b8b289c6821cff7faa7552c53d0ee5d11e93f4 (diff) | |
download | tk-522f8027b2de092fb9684f8135dedc0aba75217c.zip tk-522f8027b2de092fb9684f8135dedc0aba75217c.tar.gz tk-522f8027b2de092fb9684f8135dedc0aba75217c.tar.bz2 |
More usage of (internal) TkGetIntForIndex() function, and give this function an additional parameter "lastOK". This way,
"end" doesn't need to be handled especially in other code places, all is centralized in this single functions.
Only Ttk's "treeview" not done yet, since that requires handling a linked list in stead of an array.
Diffstat (limited to 'generic/ttk')
-rw-r--r-- | generic/ttk/ttkEntry.c | 4 | ||||
-rw-r--r-- | generic/ttk/ttkManager.c | 6 | ||||
-rw-r--r-- | generic/ttk/ttkNotebook.c | 27 | ||||
-rw-r--r-- | generic/ttk/ttkPanedwindow.c | 8 |
4 files changed, 26 insertions, 19 deletions
diff --git a/generic/ttk/ttkEntry.c b/generic/ttk/ttkEntry.c index 8abcd9b..12a0b57 100644 --- a/generic/ttk/ttkEntry.c +++ b/generic/ttk/ttkEntry.c @@ -1372,7 +1372,7 @@ EntryIndex( TkSizeT length, idx; const char *string; - if (TCL_OK == TkGetIntForIndex(indexObj, entryPtr->entry.numChars, &idx)) { + if (TCL_OK == TkGetIntForIndex(indexObj, entryPtr->entry.numChars - 1, 1, &idx)) { if (idx + 1 > (TkSizeT)entryPtr->entry.numChars + 1) { idx = (TkSizeT)entryPtr->entry.numChars; } @@ -1852,7 +1852,7 @@ static int ComboboxCurrentCommand( } else if (objc == 3) { TkSizeT idx; - if (TCL_OK == TkGetIntForIndex(objv[2], nValues - 1, &idx)) { + if (TCL_OK == TkGetIntForIndex(objv[2], nValues - 1, 0, &idx)) { if (idx == TCL_INDEX_NONE || idx > (TkSizeT)nValues) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "index \"%s\" out of range", Tcl_GetString(objv[2]))); diff --git a/generic/ttk/ttkManager.c b/generic/ttk/ttkManager.c index 5de14bd..b1e6cfd 100644 --- a/generic/ttk/ttkManager.c +++ b/generic/ttk/ttkManager.c @@ -448,12 +448,14 @@ int Ttk_GetSlaveIndexFromObj( { const char *string = Tcl_GetString(objPtr); int slaveIndex = 0; + TkSizeT idx; Tk_Window tkwin; /* Try interpreting as an integer first: */ - if (Tcl_GetIntFromObj(NULL, objPtr, &slaveIndex) == TCL_OK) { - if (slaveIndex < 0 || slaveIndex >= mgr->nSlaves) { + if (TkGetIntForIndex(objPtr, mgr->nSlaves - 1, 1, &idx) == TCL_OK) { + slaveIndex = idx; + if (slaveIndex < 0 || slaveIndex > mgr->nSlaves) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "Slave index %d out of bounds", slaveIndex)); Tcl_SetErrorCode(interp, "TTK", "SLAVE", "INDEX", NULL); diff --git a/generic/ttk/ttkNotebook.c b/generic/ttk/ttkNotebook.c index 2ad900a..e8cd905 100644 --- a/generic/ttk/ttkNotebook.c +++ b/generic/ttk/ttkNotebook.c @@ -852,6 +852,12 @@ static int FindTabIndex( { return TCL_OK; } + if (*index_rtn == Ttk_NumberSlaves(nb->notebook.mgr)) { + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "Invalid slave specification %s", string)); + Tcl_SetErrorCode(interp, "TTK", "SLAVE", "SPEC", NULL); + return TCL_ERROR; + } /* Nothing matched; Ttk_GetSlaveIndexFromObj will have left error message. */ @@ -867,6 +873,12 @@ static int GetTabIndex( Tcl_Interp *interp, Notebook *nb, Tcl_Obj *objPtr, int *index_rtn) { int status = FindTabIndex(interp, nb, objPtr, index_rtn); + if (status == TCL_OK && *index_rtn >= Ttk_NumberSlaves(nb->notebook.mgr)) { + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "Slave index %s out of bounds", Tcl_GetString(objPtr))); + Tcl_SetErrorCode(interp, "TTK", "SLAVE", "INDEX", NULL); + return TCL_ERROR; + } if (status == TCL_OK && *index_rtn < 0) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( @@ -936,9 +948,7 @@ static int NotebookInsertCommand( return TCL_ERROR; } - if (!strcmp(Tcl_GetString(objv[2]), "end")) { - destIndex = Ttk_NumberSlaves(nb->notebook.mgr); - } else if (TCL_OK != Ttk_GetSlaveIndexFromObj( + if (TCL_OK != Ttk_GetSlaveIndexFromObj( interp, nb->notebook.mgr, objv[2], &destIndex)) { return TCL_ERROR; } @@ -961,6 +971,8 @@ static int NotebookInsertCommand( interp, nb->notebook.mgr, objv[3], &srcIndex) != TCL_OK) { return TCL_ERROR; + } else if (srcIndex >= Ttk_NumberSlaves(nb->notebook.mgr)) { + srcIndex = Ttk_NumberSlaves(nb->notebook.mgr) - 1; } /* Move existing slave: @@ -1120,15 +1132,6 @@ static int NotebookIndexCommand( return TCL_ERROR; } - /* - * Special-case for "end": - */ - if (!strcmp("end", Tcl_GetString(objv[2]))) { - TkSizeT nSlaves = Ttk_NumberSlaves(nb->notebook.mgr); - Tcl_SetObjResult(interp, Tcl_NewWideIntObj(nSlaves)); - return TCL_OK; - } - status = FindTabIndex(interp, nb, objv[2], &index); if (status == TCL_OK && index != -1) { Tcl_SetObjResult(interp, Tcl_NewWideIntObj(index)); diff --git a/generic/ttk/ttkPanedwindow.c b/generic/ttk/ttkPanedwindow.c index c8d0b99..2d494de 100644 --- a/generic/ttk/ttkPanedwindow.c +++ b/generic/ttk/ttkPanedwindow.c @@ -662,9 +662,7 @@ static int PanedInsertCommand( return TCL_ERROR; } - if (!strcmp(Tcl_GetString(objv[2]), "end")) { - destIndex = Ttk_NumberSlaves(pw->paned.mgr); - } else if (TCL_OK != Ttk_GetSlaveIndexFromObj( + if (TCL_OK != Ttk_GetSlaveIndexFromObj( interp,pw->paned.mgr,objv[2],&destIndex)) { return TCL_ERROR; @@ -703,6 +701,8 @@ static int PanedForgetCommand( interp, pw->paned.mgr, objv[2], &paneIndex)) { return TCL_ERROR; + } else if (paneIndex >= Ttk_NumberSlaves(pw->paned.mgr)) { + paneIndex = Ttk_NumberSlaves(pw->paned.mgr) - 1; } Ttk_ForgetSlave(pw->paned.mgr, paneIndex); @@ -783,6 +783,8 @@ static int PanedPaneCommand( interp,pw->paned.mgr,objv[2],&paneIndex)) { return TCL_ERROR; + } else if (paneIndex >= Ttk_NumberSlaves(pw->paned.mgr)) { + paneIndex = Ttk_NumberSlaves(pw->paned.mgr) - 1; } pane = (Pane *)Ttk_SlaveData(pw->paned.mgr, paneIndex); |