summaryrefslogtreecommitdiffstats
path: root/generic/ttk
diff options
context:
space:
mode:
authorfvogel <fvogelnew1@free.fr>2019-05-03 20:48:18 (GMT)
committerfvogel <fvogelnew1@free.fr>2019-05-03 20:48:18 (GMT)
commitbd4341f10b3d578fa90169f24e61d8db933d680d (patch)
treeadc1b7844e0a4b56585b148890e973b16c4858e9 /generic/ttk
parent2ec7162d109eca92bb2ef89add0826b71e241e95 (diff)
downloadtk-bd4341f10b3d578fa90169f24e61d8db933d680d.zip
tk-bd4341f10b3d578fa90169f24e61d8db933d680d.tar.gz
tk-bd4341f10b3d578fa90169f24e61d8db933d680d.tar.bz2
Fix [2858503fff]: 'end' index for ttk::combobox current
Diffstat (limited to 'generic/ttk')
-rw-r--r--generic/ttk/ttkEntry.c55
1 files changed, 46 insertions, 9 deletions
diff --git a/generic/ttk/ttkEntry.c b/generic/ttk/ttkEntry.c
index ebc485e..a8d4f15 100644
--- a/generic/ttk/ttkEntry.c
+++ b/generic/ttk/ttkEntry.c
@@ -1700,6 +1700,16 @@ static WidgetSpec EntryWidgetSpec = {
};
/*------------------------------------------------------------------------
+ * Named indices for the combobox "current" command
+ */
+static const char *const comboboxCurrentIndexNames[] = {
+ "end", NULL
+};
+enum comboboxCurrentIndices {
+ INDEX_END
+};
+
+/*------------------------------------------------------------------------
* +++ Combobox widget record.
*/
@@ -1800,15 +1810,42 @@ static int ComboboxCurrentCommand(
Tcl_SetObjResult(interp, Tcl_NewIntObj(currentIndex));
return TCL_OK;
} else if (objc == 3) {
- if (Tcl_GetIntFromObj(interp, objv[2], &currentIndex) != TCL_OK) {
- return TCL_ERROR;
- }
- if (currentIndex < 0 || currentIndex >= nValues) {
- Tcl_SetObjResult(interp, Tcl_ObjPrintf(
- "Index %s out of range", Tcl_GetString(objv[2])));
- Tcl_SetErrorCode(interp, "TTK", "COMBOBOX", "IDX_RANGE", NULL);
- return TCL_ERROR;
- }
+ int result, index;
+
+ result = Tcl_GetIndexFromObj(NULL, objv[2], comboboxCurrentIndexNames,
+ "", 0, &index);
+ if (result == TCL_OK) {
+
+ /*
+ * The index is one of the named indices.
+ */
+
+ switch (index) {
+ case INDEX_END:
+ /* "end" index */
+ currentIndex = nValues - 1;
+ break;
+ }
+ } else {
+
+ /*
+ * The index should be just an integer.
+ */
+
+ if (Tcl_GetIntFromObj(NULL, objv[2], &currentIndex) != TCL_OK) {
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "Incorrect index %s", Tcl_GetString(objv[2])));
+ Tcl_SetErrorCode(interp, "TTK", "COMBOBOX", "IDX_VALUE", NULL);
+ return TCL_ERROR;
+ }
+
+ if (currentIndex < 0 || currentIndex >= nValues) {
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "Index %s out of range", Tcl_GetString(objv[2])));
+ Tcl_SetErrorCode(interp, "TTK", "COMBOBOX", "IDX_RANGE", NULL);
+ return TCL_ERROR;
+ }
+ }
cbPtr->combobox.currentIndex = currentIndex;