diff options
Diffstat (limited to 'generic/tkMenu.c')
-rw-r--r-- | generic/tkMenu.c | 666 |
1 files changed, 381 insertions, 285 deletions
diff --git a/generic/tkMenu.c b/generic/tkMenu.c index 715c6d7..7819b11 100644 --- a/generic/tkMenu.c +++ b/generic/tkMenu.c @@ -6,8 +6,8 @@ * supplemented by platform-specific files. The geometry calculation and * drawing code for menus is in the file tkMenuDraw.c * - * Copyright (c) 1990-1994 The Regents of the University of California. - * Copyright (c) 1994-1998 Sun Microsystems, Inc. + * Copyright © 1990-1994 The Regents of the University of California. + * Copyright © 1994-1998 Sun Microsystems, Inc. * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -101,126 +101,124 @@ TCL_DECLARE_MUTEX(menuMutex) * to update code in TkpMenuInit that changes the font string entry. */ -static const char *const menuStateStrings[] = {"active", "normal", "disabled", NULL}; - static const char *const menuEntryTypeStrings[] = { "cascade", "checkbutton", "command", "radiobutton", "separator", NULL }; static const Tk_OptionSpec tkBasicMenuEntryConfigSpecs[] = { {TK_OPTION_BORDER, "-activebackground", NULL, NULL, - DEF_MENU_ENTRY_ACTIVE_BG, Tk_Offset(TkMenuEntry, activeBorderPtr), -1, + DEF_MENU_ENTRY_ACTIVE_BG, offsetof(TkMenuEntry, activeBorderPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0}, {TK_OPTION_COLOR, "-activeforeground", NULL, NULL, DEF_MENU_ENTRY_ACTIVE_FG, - Tk_Offset(TkMenuEntry, activeFgPtr), -1, TK_OPTION_NULL_OK, NULL, 0}, + offsetof(TkMenuEntry, activeFgPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0}, {TK_OPTION_STRING, "-accelerator", NULL, NULL, DEF_MENU_ENTRY_ACCELERATOR, - Tk_Offset(TkMenuEntry, accelPtr), -1, TK_OPTION_NULL_OK, NULL, 0}, + offsetof(TkMenuEntry, accelPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0}, {TK_OPTION_BORDER, "-background", NULL, NULL, DEF_MENU_ENTRY_BG, - Tk_Offset(TkMenuEntry, borderPtr), -1, TK_OPTION_NULL_OK, NULL, 0}, + offsetof(TkMenuEntry, borderPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0}, {TK_OPTION_BITMAP, "-bitmap", NULL, NULL, DEF_MENU_ENTRY_BITMAP, - Tk_Offset(TkMenuEntry, bitmapPtr), -1, TK_OPTION_NULL_OK, NULL, 0}, + offsetof(TkMenuEntry, bitmapPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0}, {TK_OPTION_BOOLEAN, "-columnbreak", NULL, NULL, DEF_MENU_ENTRY_COLUMN_BREAK, - -1, Tk_Offset(TkMenuEntry, columnBreak), 0, NULL, 0}, + TCL_INDEX_NONE, offsetof(TkMenuEntry, columnBreak), 0, NULL, 0}, {TK_OPTION_STRING, "-command", NULL, NULL, DEF_MENU_ENTRY_COMMAND, - Tk_Offset(TkMenuEntry, commandPtr), -1, TK_OPTION_NULL_OK, NULL, 0}, + offsetof(TkMenuEntry, commandPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0}, {TK_OPTION_STRING_TABLE, "-compound", "compound", "Compound", - DEF_MENU_ENTRY_COMPOUND, -1, Tk_Offset(TkMenuEntry, compound), 0, + DEF_MENU_ENTRY_COMPOUND, TCL_INDEX_NONE, offsetof(TkMenuEntry, compound), 0, tkCompoundStrings, 0}, {TK_OPTION_FONT, "-font", NULL, NULL, DEF_MENU_ENTRY_FONT, - Tk_Offset(TkMenuEntry, fontPtr), -1, TK_OPTION_NULL_OK, NULL, 0}, + offsetof(TkMenuEntry, fontPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0}, {TK_OPTION_COLOR, "-foreground", NULL, NULL, DEF_MENU_ENTRY_FG, - Tk_Offset(TkMenuEntry, fgPtr), -1, TK_OPTION_NULL_OK, NULL, 0}, + offsetof(TkMenuEntry, fgPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0}, {TK_OPTION_BOOLEAN, "-hidemargin", NULL, NULL, DEF_MENU_ENTRY_HIDE_MARGIN, - -1, Tk_Offset(TkMenuEntry, hideMargin), 0, NULL, 0}, + TCL_INDEX_NONE, offsetof(TkMenuEntry, hideMargin), 0, NULL, 0}, {TK_OPTION_STRING, "-image", NULL, NULL, DEF_MENU_ENTRY_IMAGE, - Tk_Offset(TkMenuEntry, imagePtr), -1, TK_OPTION_NULL_OK, NULL, 0}, + offsetof(TkMenuEntry, imagePtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0}, {TK_OPTION_STRING, "-label", NULL, NULL, DEF_MENU_ENTRY_LABEL, - Tk_Offset(TkMenuEntry, labelPtr), -1, 0, NULL, 0}, + offsetof(TkMenuEntry, labelPtr), TCL_INDEX_NONE, 0, NULL, 0}, {TK_OPTION_STRING_TABLE, "-state", NULL, NULL, DEF_MENU_ENTRY_STATE, - -1, Tk_Offset(TkMenuEntry, state), - 0, menuStateStrings, 0}, - {TK_OPTION_INT, "-underline", NULL, NULL, - DEF_MENU_ENTRY_UNDERLINE, -1, Tk_Offset(TkMenuEntry, underline), 0, NULL, 0}, + TCL_INDEX_NONE, offsetof(TkMenuEntry, state), + 0, tkStateStrings, 0}, + {TK_OPTION_INDEX, "-underline", NULL, NULL, + TK_OPTION_UNDERLINE_DEF(TkMenuEntry, underline), 0}, {TK_OPTION_END, NULL, NULL, NULL, 0, 0, 0, 0, NULL, 0} }; static const Tk_OptionSpec tkSeparatorEntryConfigSpecs[] = { {TK_OPTION_BORDER, "-background", NULL, NULL, DEF_MENU_ENTRY_BG, - Tk_Offset(TkMenuEntry, borderPtr), -1, TK_OPTION_NULL_OK, NULL, 0}, + offsetof(TkMenuEntry, borderPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0}, {TK_OPTION_END, NULL, NULL, NULL, 0, 0, 0, 0, NULL, 0} }; static const Tk_OptionSpec tkCheckButtonEntryConfigSpecs[] = { {TK_OPTION_BOOLEAN, "-indicatoron", NULL, NULL, DEF_MENU_ENTRY_INDICATOR, - -1, Tk_Offset(TkMenuEntry, indicatorOn), 0, NULL, 0}, + TCL_INDEX_NONE, offsetof(TkMenuEntry, indicatorOn), 0, NULL, 0}, {TK_OPTION_STRING, "-offvalue", NULL, NULL, DEF_MENU_ENTRY_OFF_VALUE, - Tk_Offset(TkMenuEntry, offValuePtr), -1, 0, NULL, 0}, + offsetof(TkMenuEntry, offValuePtr), TCL_INDEX_NONE, 0, NULL, 0}, {TK_OPTION_STRING, "-onvalue", NULL, NULL, DEF_MENU_ENTRY_ON_VALUE, - Tk_Offset(TkMenuEntry, onValuePtr), -1, 0, NULL, 0}, + offsetof(TkMenuEntry, onValuePtr), TCL_INDEX_NONE, 0, NULL, 0}, {TK_OPTION_COLOR, "-selectcolor", NULL, NULL, DEF_MENU_ENTRY_SELECT, - Tk_Offset(TkMenuEntry, indicatorFgPtr), -1, TK_OPTION_NULL_OK, NULL, 0}, + offsetof(TkMenuEntry, indicatorFgPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0}, {TK_OPTION_STRING, "-selectimage", NULL, NULL, DEF_MENU_ENTRY_SELECT_IMAGE, - Tk_Offset(TkMenuEntry, selectImagePtr), -1, TK_OPTION_NULL_OK, NULL, 0}, + offsetof(TkMenuEntry, selectImagePtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0}, {TK_OPTION_STRING, "-variable", NULL, NULL, DEF_MENU_ENTRY_CHECK_VARIABLE, - Tk_Offset(TkMenuEntry, namePtr), -1, TK_OPTION_NULL_OK, NULL, 0}, + offsetof(TkMenuEntry, namePtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0}, {TK_OPTION_END, NULL, NULL, NULL, - NULL, 0, -1, 0, tkBasicMenuEntryConfigSpecs, 0} + NULL, 0, TCL_INDEX_NONE, 0, tkBasicMenuEntryConfigSpecs, 0} }; static const Tk_OptionSpec tkRadioButtonEntryConfigSpecs[] = { {TK_OPTION_BOOLEAN, "-indicatoron", NULL, NULL, DEF_MENU_ENTRY_INDICATOR, - -1, Tk_Offset(TkMenuEntry, indicatorOn), 0, NULL, 0}, + TCL_INDEX_NONE, offsetof(TkMenuEntry, indicatorOn), 0, NULL, 0}, {TK_OPTION_COLOR, "-selectcolor", NULL, NULL, DEF_MENU_ENTRY_SELECT, - Tk_Offset(TkMenuEntry, indicatorFgPtr), -1, TK_OPTION_NULL_OK, NULL, 0}, + offsetof(TkMenuEntry, indicatorFgPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0}, {TK_OPTION_STRING, "-selectimage", NULL, NULL, DEF_MENU_ENTRY_SELECT_IMAGE, - Tk_Offset(TkMenuEntry, selectImagePtr), -1, TK_OPTION_NULL_OK, NULL, 0}, + offsetof(TkMenuEntry, selectImagePtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0}, {TK_OPTION_STRING, "-value", NULL, NULL, DEF_MENU_ENTRY_VALUE, - Tk_Offset(TkMenuEntry, onValuePtr), -1, TK_OPTION_NULL_OK, NULL, 0}, + offsetof(TkMenuEntry, onValuePtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0}, {TK_OPTION_STRING, "-variable", NULL, NULL, DEF_MENU_ENTRY_RADIO_VARIABLE, - Tk_Offset(TkMenuEntry, namePtr), -1, 0, NULL, 0}, + offsetof(TkMenuEntry, namePtr), TCL_INDEX_NONE, 0, NULL, 0}, {TK_OPTION_END, NULL, NULL, NULL, - NULL, 0, -1, 0, tkBasicMenuEntryConfigSpecs, 0} + NULL, 0, TCL_INDEX_NONE, 0, tkBasicMenuEntryConfigSpecs, 0} }; static const Tk_OptionSpec tkCascadeEntryConfigSpecs[] = { {TK_OPTION_STRING, "-menu", NULL, NULL, DEF_MENU_ENTRY_MENU, - Tk_Offset(TkMenuEntry, namePtr), -1, TK_OPTION_NULL_OK, NULL, 0}, + offsetof(TkMenuEntry, namePtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0}, {TK_OPTION_END, NULL, NULL, NULL, - NULL, 0, -1, 0, tkBasicMenuEntryConfigSpecs, 0} + NULL, 0, TCL_INDEX_NONE, 0, tkBasicMenuEntryConfigSpecs, 0} }; static const Tk_OptionSpec tkTearoffEntryConfigSpecs[] = { {TK_OPTION_BORDER, "-background", NULL, NULL, DEF_MENU_ENTRY_BG, - Tk_Offset(TkMenuEntry, borderPtr), -1, TK_OPTION_NULL_OK, NULL, 0}, + offsetof(TkMenuEntry, borderPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0}, {TK_OPTION_STRING_TABLE, "-state", NULL, NULL, - DEF_MENU_ENTRY_STATE, -1, Tk_Offset(TkMenuEntry, state), - 0, menuStateStrings, 0}, + DEF_MENU_ENTRY_STATE, TCL_INDEX_NONE, offsetof(TkMenuEntry, state), + 0, tkStateStrings, 0}, {TK_OPTION_END, NULL, NULL, NULL, 0, 0, 0, 0, NULL, 0} }; @@ -235,65 +233,68 @@ static const Tk_OptionSpec *specsArray[] = { */ static const char *const menuTypeStrings[] = { - "normal", "tearoff", "menubar", NULL + "menubar", "normal", "tearoff", NULL }; static const Tk_OptionSpec tkMenuConfigSpecs[] = { {TK_OPTION_BORDER, "-activebackground", "activeBackground", "Foreground", DEF_MENU_ACTIVE_BG_COLOR, - Tk_Offset(TkMenu, activeBorderPtr), -1, 0, - (ClientData) DEF_MENU_ACTIVE_BG_MONO, 0}, + offsetof(TkMenu, activeBorderPtr), TCL_INDEX_NONE, 0, + DEF_MENU_ACTIVE_BG_MONO, 0}, {TK_OPTION_PIXELS, "-activeborderwidth", "activeBorderWidth", "BorderWidth", DEF_MENU_ACTIVE_BORDER_WIDTH, - Tk_Offset(TkMenu, activeBorderWidthPtr), -1, 0, NULL, 0}, + offsetof(TkMenu, activeBorderWidthPtr), TCL_INDEX_NONE, 0, NULL, 0}, {TK_OPTION_COLOR, "-activeforeground", "activeForeground", "Background", DEF_MENU_ACTIVE_FG_COLOR, - Tk_Offset(TkMenu, activeFgPtr), -1, 0, - (ClientData) DEF_MENU_ACTIVE_FG_MONO, 0}, + offsetof(TkMenu, activeFgPtr), TCL_INDEX_NONE, 0, + DEF_MENU_ACTIVE_FG_MONO, 0}, + {TK_OPTION_RELIEF, "-activerelief", "activeRelief", "Relief", + DEF_MENU_ACTIVE_RELIEF, offsetof(TkMenu, activeReliefPtr), + TCL_INDEX_NONE, 0, NULL, 0}, {TK_OPTION_BORDER, "-background", "background", "Background", - DEF_MENU_BG_COLOR, Tk_Offset(TkMenu, borderPtr), -1, 0, - (ClientData) DEF_MENU_BG_MONO, 0}, + DEF_MENU_BG_COLOR, offsetof(TkMenu, borderPtr), TCL_INDEX_NONE, 0, + DEF_MENU_BG_MONO, 0}, {TK_OPTION_SYNONYM, "-bd", NULL, NULL, - NULL, 0, -1, 0, "-borderwidth", 0}, + NULL, 0, TCL_INDEX_NONE, 0, "-borderwidth", 0}, {TK_OPTION_SYNONYM, "-bg", NULL, NULL, - NULL, 0, -1, 0, "-background", 0}, + NULL, 0, TCL_INDEX_NONE, 0, "-background", 0}, {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth", DEF_MENU_BORDER_WIDTH, - Tk_Offset(TkMenu, borderWidthPtr), -1, 0, NULL, 0}, + offsetof(TkMenu, borderWidthPtr), TCL_INDEX_NONE, 0, NULL, 0}, {TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor", DEF_MENU_CURSOR, - Tk_Offset(TkMenu, cursorPtr), -1, TK_OPTION_NULL_OK, NULL, 0}, + offsetof(TkMenu, cursorPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0}, {TK_OPTION_COLOR, "-disabledforeground", "disabledForeground", "DisabledForeground", DEF_MENU_DISABLED_FG_COLOR, - Tk_Offset(TkMenu, disabledFgPtr), -1, TK_OPTION_NULL_OK, - (ClientData) DEF_MENU_DISABLED_FG_MONO, 0}, + offsetof(TkMenu, disabledFgPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, + DEF_MENU_DISABLED_FG_MONO, 0}, {TK_OPTION_SYNONYM, "-fg", NULL, NULL, - NULL, 0, -1, 0, "-foreground", 0}, + NULL, 0, TCL_INDEX_NONE, 0, "-foreground", 0}, {TK_OPTION_FONT, "-font", "font", "Font", - DEF_MENU_FONT, Tk_Offset(TkMenu, fontPtr), -1, 0, NULL, 0}, + DEF_MENU_FONT, offsetof(TkMenu, fontPtr), TCL_INDEX_NONE, 0, NULL, 0}, {TK_OPTION_COLOR, "-foreground", "foreground", "Foreground", - DEF_MENU_FG, Tk_Offset(TkMenu, fgPtr), -1, 0, NULL, 0}, + DEF_MENU_FG, offsetof(TkMenu, fgPtr), TCL_INDEX_NONE, 0, NULL, 0}, {TK_OPTION_STRING, "-postcommand", "postCommand", "Command", DEF_MENU_POST_COMMAND, - Tk_Offset(TkMenu, postCommandPtr), -1, TK_OPTION_NULL_OK, NULL, 0}, + offsetof(TkMenu, postCommandPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0}, {TK_OPTION_RELIEF, "-relief", "relief", "Relief", - DEF_MENU_RELIEF, Tk_Offset(TkMenu, reliefPtr), -1, 0, NULL, 0}, + DEF_MENU_RELIEF, offsetof(TkMenu, reliefPtr), TCL_INDEX_NONE, 0, NULL, 0}, {TK_OPTION_COLOR, "-selectcolor", "selectColor", "Background", - DEF_MENU_SELECT_COLOR, Tk_Offset(TkMenu, indicatorFgPtr), -1, 0, - (ClientData) DEF_MENU_SELECT_MONO, 0}, + DEF_MENU_SELECT_COLOR, offsetof(TkMenu, indicatorFgPtr), TCL_INDEX_NONE, 0, + DEF_MENU_SELECT_MONO, 0}, {TK_OPTION_STRING, "-takefocus", "takeFocus", "TakeFocus", DEF_MENU_TAKE_FOCUS, - Tk_Offset(TkMenu, takeFocusPtr), -1, TK_OPTION_NULL_OK, NULL, 0}, + offsetof(TkMenu, takeFocusPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0}, {TK_OPTION_BOOLEAN, "-tearoff", "tearOff", "TearOff", - DEF_MENU_TEAROFF, -1, Tk_Offset(TkMenu, tearoff), 0, NULL, 0}, + DEF_MENU_TEAROFF, TCL_INDEX_NONE, offsetof(TkMenu, tearoff), 0, NULL, 0}, {TK_OPTION_STRING, "-tearoffcommand", "tearOffCommand", "TearOffCommand", DEF_MENU_TEAROFF_CMD, - Tk_Offset(TkMenu, tearoffCommandPtr), -1, TK_OPTION_NULL_OK, NULL, 0}, + offsetof(TkMenu, tearoffCommandPtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0}, {TK_OPTION_STRING, "-title", "title", "Title", - DEF_MENU_TITLE, Tk_Offset(TkMenu, titlePtr), -1, + DEF_MENU_TITLE, offsetof(TkMenu, titlePtr), TCL_INDEX_NONE, TK_OPTION_NULL_OK, NULL, 0}, {TK_OPTION_STRING_TABLE, "-type", "type", "Type", - DEF_MENU_TYPE, Tk_Offset(TkMenu, menuTypePtr), -1, + DEF_MENU_TYPE, offsetof(TkMenu, menuTypePtr), TCL_INDEX_NONE, 0, menuTypeStrings, 0}, {TK_OPTION_END, NULL, NULL, NULL, 0, 0, 0, 0, NULL, 0} }; @@ -305,12 +306,12 @@ static const Tk_OptionSpec tkMenuConfigSpecs[] = { static const char *const menuOptions[] = { "activate", "add", "cget", "clone", "configure", "delete", "entrycget", - "entryconfigure", "index", "insert", "invoke", "post", "postcascade", + "entryconfigure", "id", "index", "insert", "invoke", "post", "postcascade", "type", "unpost", "xposition", "yposition", NULL }; enum options { MENU_ACTIVATE, MENU_ADD, MENU_CGET, MENU_CLONE, MENU_CONFIGURE, - MENU_DELETE, MENU_ENTRYCGET, MENU_ENTRYCONFIGURE, MENU_INDEX, + MENU_DELETE, MENU_ENTRYCGET, MENU_ENTRYCONFIGURE, MENU_ID, MENU_INDEX, MENU_INSERT, MENU_INVOKE, MENU_POST, MENU_POSTCASCADE, MENU_TYPE, MENU_UNPOST, MENU_XPOSITION, MENU_YPOSITION }; @@ -322,41 +323,40 @@ enum options { static int CloneMenu(TkMenu *menuPtr, Tcl_Obj *newMenuName, Tcl_Obj *newMenuTypeString); static int ConfigureMenu(Tcl_Interp *interp, TkMenu *menuPtr, - int objc, Tcl_Obj *const objv[]); -static int ConfigureMenuCloneEntries(Tcl_Interp *interp, - TkMenu *menuPtr, int index, - int objc, Tcl_Obj *const objv[]); + Tcl_Size objc, Tcl_Obj *const objv[]); +static int ConfigureMenuCloneEntries(TkMenu *menuPtr, int index, + Tcl_Size objc, Tcl_Obj *const objv[]); static int ConfigureMenuEntry(TkMenuEntry *mePtr, - int objc, Tcl_Obj *const objv[]); + Tcl_Size objc, Tcl_Obj *const objv[]); static void DeleteMenuCloneEntries(TkMenu *menuPtr, int first, int last); -static void DestroyMenuHashTable(ClientData clientData, +static void DestroyMenuHashTable(void *clientData, Tcl_Interp *interp); static void DestroyMenuInstance(TkMenu *menuPtr); static Tcl_FreeProc DestroyMenuEntry; -static int GetIndexFromCoords(Tcl_Interp *interp, +static Tcl_Size GetIndexFromCoords(Tcl_Interp *interp, TkMenu *menuPtr, const char *string, - int *indexPtr); + Tcl_Size *indexPtr); static int MenuDoYPosition(Tcl_Interp *interp, TkMenu *menuPtr, Tcl_Obj *objPtr); static int MenuDoXPosition(Tcl_Interp *interp, TkMenu *menuPtr, Tcl_Obj *objPtr); static int MenuAddOrInsert(Tcl_Interp *interp, - TkMenu *menuPtr, Tcl_Obj *indexPtr, int objc, + TkMenu *menuPtr, Tcl_Obj *indexPtr, Tcl_Size objc, Tcl_Obj *const objv[]); -static void MenuCmdDeletedProc(ClientData clientData); -static TkMenuEntry * MenuNewEntry(TkMenu *menuPtr, int index, int type); -static char * MenuVarProc(ClientData clientData, +static void MenuCmdDeletedProc(void *clientData); +static TkMenuEntry * MenuNewEntry(TkMenu *menuPtr, Tcl_Size index, int type); +static char * MenuVarProc(void *clientData, Tcl_Interp *interp, const char *name1, const char *name2, int flags); -static int MenuWidgetObjCmd(ClientData clientData, - Tcl_Interp *interp, int objc, - Tcl_Obj *const objv[]); -static void MenuWorldChanged(ClientData instanceData); +static Tcl_ObjCmdProc MenuWidgetObjCmd; +static void MenuWorldChanged(void *instanceData); static int PostProcessEntry(TkMenuEntry *mePtr); static void RecursivelyDeleteMenu(TkMenu *menuPtr); static void UnhookCascadeEntry(TkMenuEntry *mePtr); -static void TkMenuCleanup(ClientData unused); +static void MenuCleanup(void *unused); +static int GetMenuIndex(Tcl_Interp *interp, TkMenu *menuPtr, + Tcl_Obj *objPtr, int lastOK, Tcl_Size *indexPtr); /* * The structure below is a list of procs that respond to certain window @@ -390,7 +390,7 @@ static const Tk_ClassProcs menuClass = { int Tk_MenuObjCmd( - ClientData clientData, /* Main window associated with interpreter. */ + void *clientData, /* Main window associated with interpreter. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument strings. */ @@ -399,7 +399,7 @@ Tk_MenuObjCmd( Tk_Window newWin; TkMenu *menuPtr; TkMenuReferences *menuRefPtr; - int i; + Tcl_Size i; int index, toplevel; const char *windowName; static const char *const typeStringList[] = {"-type", NULL}; @@ -446,10 +446,12 @@ Tk_MenuObjCmd( menuPtr->widgetCmd = Tcl_CreateObjCommand(interp, Tk_PathName(menuPtr->tkwin), MenuWidgetObjCmd, menuPtr, MenuCmdDeletedProc); - menuPtr->active = -1; + menuPtr->active = TCL_INDEX_NONE; menuPtr->cursorPtr = NULL; - menuPtr->masterMenuPtr = menuPtr; + menuPtr->mainMenuPtr = menuPtr; menuPtr->menuType = UNKNOWN_TYPE; + Tcl_InitHashTable(&menuPtr->items, TCL_STRING_KEYS); + menuPtr->serial = 0; TkMenuInitializeDrawingFields(menuPtr); Tk_SetClass(menuPtr->tkwin, "Menu"); @@ -457,7 +459,7 @@ Tk_MenuObjCmd( Tk_CreateEventHandler(newWin, ExposureMask|StructureNotifyMask|ActivateMask, TkMenuEventProc, menuPtr); - if (Tk_InitOptions(interp, (char *) menuPtr, + if (Tk_InitOptions(interp, menuPtr, tsdPtr->menuOptionTable, menuPtr->tkwin) != TCL_OK) { Tk_DestroyWindow(menuPtr->tkwin); @@ -513,11 +515,11 @@ Tk_MenuObjCmd( * creating exists. */ - if ((menuPtr->masterMenuPtr != menuPtr) - || ((menuPtr->masterMenuPtr == menuPtr) - && ((cascadeListPtr->menuPtr->masterMenuPtr + if ((menuPtr->mainMenuPtr != menuPtr) + || ((menuPtr->mainMenuPtr == menuPtr) + && ((cascadeListPtr->menuPtr->mainMenuPtr == cascadeListPtr->menuPtr)))) { - newObjv[0] = Tcl_NewStringObj("-menu", -1); + newObjv[0] = Tcl_NewStringObj("-menu", TCL_INDEX_NONE); newObjv[1] = Tcl_NewStringObj(Tk_PathName(menuPtr->tkwin),-1); Tcl_IncrRefCount(newObjv[0]); Tcl_IncrRefCount(newObjv[1]); @@ -525,9 +527,9 @@ Tk_MenuObjCmd( Tcl_DecrRefCount(newObjv[0]); Tcl_DecrRefCount(newObjv[1]); } else { - Tcl_Obj *normalPtr = Tcl_NewStringObj("normal", -1); + Tcl_Obj *normalPtr = Tcl_NewStringObj("normal", TCL_INDEX_NONE); Tcl_Obj *windowNamePtr = Tcl_NewStringObj( - Tk_PathName(cascadeListPtr->menuPtr->tkwin), -1); + Tk_PathName(cascadeListPtr->menuPtr->tkwin), TCL_INDEX_NONE); Tcl_IncrRefCount(normalPtr); Tcl_IncrRefCount(windowNamePtr); @@ -541,7 +543,7 @@ Tk_MenuObjCmd( * entry of the parent's instance. */ - newObjv[0] = Tcl_NewStringObj("-menu", -1); + newObjv[0] = Tcl_NewStringObj("-menu", TCL_INDEX_NONE); newObjv[1] = newMenuName; Tcl_IncrRefCount(newObjv[0]); ConfigureMenuEntry(cascadeListPtr, 2, newObjv); @@ -567,20 +569,20 @@ Tk_MenuObjCmd( while (topLevelListPtr != NULL) { /* - * Need to get the next pointer first. TkSetWindowMenuBar changes + * Need to get the next pointer first. Tk_SetWindowMenubar changes * the list, so that the next pointer is different after calling * it. */ nextPtr = topLevelListPtr->nextPtr; listtkwin = topLevelListPtr->tkwin; - TkSetWindowMenuBar(menuPtr->interp, listtkwin, + Tk_SetWindowMenubar(menuPtr->interp, listtkwin, Tk_PathName(menuPtr->tkwin), Tk_PathName(menuPtr->tkwin)); topLevelListPtr = nextPtr; } } - Tcl_SetObjResult(interp, TkNewWindowObj(menuPtr->tkwin)); + Tcl_SetObjResult(interp, Tk_NewWindowObj(menuPtr->tkwin)); return TCL_OK; } @@ -604,7 +606,7 @@ Tk_MenuObjCmd( static int MenuWidgetObjCmd( - ClientData clientData, /* Information about menu widget. */ + void *clientData, /* Information about menu widget. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument strings. */ @@ -628,13 +630,13 @@ MenuWidgetObjCmd( switch ((enum options) option) { case MENU_ACTIVATE: { - int index; + Tcl_Size index; if (objc != 3) { Tcl_WrongNumArgs(interp, 2, objv, "index"); goto error; } - if (TkGetMenuIndex(interp, menuPtr, objv[2], 0, &index) != TCL_OK) { + if (GetMenuIndex(interp, menuPtr, objv[2], 0, &index) != TCL_OK) { goto error; } if (menuPtr->active == index) { @@ -642,7 +644,7 @@ MenuWidgetObjCmd( } if ((index >= 0) && ((menuPtr->entries[index]->type==SEPARATOR_ENTRY) || (menuPtr->entries[index]->state == ENTRY_DISABLED))) { - index = -1; + index = TCL_INDEX_NONE; } result = TkActivateMenuEntry(menuPtr, index); break; @@ -664,7 +666,7 @@ MenuWidgetObjCmd( Tcl_WrongNumArgs(interp, 2, objv, "option"); goto error; } - resultPtr = Tk_GetOptionValue(interp, (char *) menuPtr, + resultPtr = Tk_GetOptionValue(interp, menuPtr, tsdPtr->menuOptionTable, objv[2], menuPtr->tkwin); if (resultPtr == NULL) { @@ -684,7 +686,7 @@ MenuWidgetObjCmd( Tcl_Obj *resultPtr; if (objc == 2) { - resultPtr = Tk_GetOptionInfo(interp, (char *) menuPtr, + resultPtr = Tk_GetOptionInfo(interp, menuPtr, tsdPtr->menuOptionTable, NULL, menuPtr->tkwin); if (resultPtr == NULL) { @@ -694,7 +696,7 @@ MenuWidgetObjCmd( Tcl_SetObjResult(interp, resultPtr); } } else if (objc == 3) { - resultPtr = Tk_GetOptionInfo(interp, (char *) menuPtr, + resultPtr = Tk_GetOptionInfo(interp, menuPtr, tsdPtr->menuOptionTable, objv[2], menuPtr->tkwin); if (resultPtr == NULL) { @@ -712,7 +714,8 @@ MenuWidgetObjCmd( break; } case MENU_DELETE: { - int first, last; + Tcl_Size first, last; + Tcl_WideInt w; if ((objc != 3) && (objc != 4)) { Tcl_WrongNumArgs(interp, 2, objv, "first ?last?"); @@ -725,16 +728,17 @@ MenuWidgetObjCmd( */ if (isdigit(UCHAR(Tcl_GetString(objv[2])[0])) - && Tcl_GetIntFromObj(NULL, objv[2], &first) == TCL_OK) { + && Tcl_GetWideIntFromObj(NULL, objv[2], &w) == TCL_OK) { + first = w; if (first >= menuPtr->numEntries) { goto done; } - } else if (TkGetMenuIndex(interp,menuPtr,objv[2],0,&first) != TCL_OK){ + } else if (GetMenuIndex(interp,menuPtr,objv[2],0,&first) != TCL_OK){ goto error; } if (objc == 3) { last = first; - } else if (TkGetMenuIndex(interp,menuPtr,objv[3],0,&last) != TCL_OK) { + } else if (GetMenuIndex(interp,menuPtr,objv[3],0,&last) != TCL_OK) { goto error; } @@ -746,21 +750,21 @@ MenuWidgetObjCmd( first = 1; } - if ((first == -1) || (last < first)) { + if ((first < 0) || (last < first)) { goto done; } DeleteMenuCloneEntries(menuPtr, first, last); break; } case MENU_ENTRYCGET: { - int index; + Tcl_Size index; Tcl_Obj *resultPtr; if (objc != 4) { Tcl_WrongNumArgs(interp, 2, objv, "index option"); goto error; } - if (TkGetMenuIndex(interp, menuPtr, objv[2], 0, &index) != TCL_OK) { + if (GetMenuIndex(interp, menuPtr, objv[2], 0, &index) != TCL_OK) { goto error; } if (index < 0) { @@ -768,7 +772,7 @@ MenuWidgetObjCmd( } mePtr = menuPtr->entries[index]; Tcl_Preserve(mePtr); - resultPtr = Tk_GetOptionValue(interp, (char *) mePtr, + resultPtr = Tk_GetOptionValue(interp, mePtr, mePtr->optionTable, objv[3], menuPtr->tkwin); Tcl_Release(mePtr); if (resultPtr == NULL) { @@ -778,14 +782,14 @@ MenuWidgetObjCmd( break; } case MENU_ENTRYCONFIGURE: { - int index; + Tcl_Size index; Tcl_Obj *resultPtr; if (objc < 3) { Tcl_WrongNumArgs(interp, 2, objv, "index ?-option value ...?"); goto error; } - if (TkGetMenuIndex(interp, menuPtr, objv[2], 0, &index) != TCL_OK) { + if (GetMenuIndex(interp, menuPtr, objv[2], 0, &index) != TCL_OK) { goto error; } if (index < 0) { @@ -794,7 +798,7 @@ MenuWidgetObjCmd( mePtr = menuPtr->entries[index]; Tcl_Preserve(mePtr); if (objc == 3) { - resultPtr = Tk_GetOptionInfo(interp, (char *) mePtr, + resultPtr = Tk_GetOptionInfo(interp, mePtr, mePtr->optionTable, NULL, menuPtr->tkwin); if (resultPtr == NULL) { result = TCL_ERROR; @@ -803,7 +807,7 @@ MenuWidgetObjCmd( Tcl_SetObjResult(interp, resultPtr); } } else if (objc == 4) { - resultPtr = Tk_GetOptionInfo(interp, (char *) mePtr, + resultPtr = Tk_GetOptionInfo(interp, mePtr, mePtr->optionTable, objv[3], menuPtr->tkwin); if (resultPtr == NULL) { result = TCL_ERROR; @@ -812,26 +816,52 @@ MenuWidgetObjCmd( Tcl_SetObjResult(interp, resultPtr); } } else { - result = ConfigureMenuCloneEntries(interp, menuPtr, index, + result = ConfigureMenuCloneEntries(menuPtr, index, objc-3, objv+3); } Tcl_Release(mePtr); break; } + case MENU_ID: { + Tcl_Size index; + const char *idStr; + Tcl_HashEntry *entryPtr; + + if (objc != 3) { + Tcl_WrongNumArgs(interp, 2, objv, "index"); + goto error; + } + if (GetMenuIndex(interp, menuPtr, objv[2], 0, &index) != TCL_OK) { + goto error; + } + if (index < 0) { + goto done; + } + entryPtr = menuPtr->entries[index]->entryPtr; + if (entryPtr) { + idStr = (const char *)Tcl_GetHashKey(&menuPtr->items, entryPtr); + Tcl_SetObjResult(interp, Tcl_NewStringObj(idStr, TCL_INDEX_NONE)); + } + break; + } case MENU_INDEX: { - int index; + Tcl_Size index; if (objc != 3) { Tcl_WrongNumArgs(interp, 2, objv, "string"); goto error; } - if (TkGetMenuIndex(interp, menuPtr, objv[2], 0, &index) != TCL_OK) { + if (GetMenuIndex(interp, menuPtr, objv[2], 0, &index) != TCL_OK) { goto error; } if (index < 0) { - Tcl_SetObjResult(interp, Tcl_NewStringObj("none", -1)); +#if defined(TK_NO_DEPRECATED) + Tcl_SetObjResult(interp, Tcl_NewObj()); +#else + Tcl_SetObjResult(interp, Tcl_NewStringObj("none", TCL_INDEX_NONE)); +#endif } else { - Tcl_SetObjResult(interp, Tcl_NewIntObj(index)); + Tcl_SetObjResult(interp, TkNewIndexObj(index)); } break; } @@ -846,13 +876,13 @@ MenuWidgetObjCmd( } break; case MENU_INVOKE: { - int index; + Tcl_Size index; if (objc != 3) { Tcl_WrongNumArgs(interp, 2, objv, "index"); goto error; } - if (TkGetMenuIndex(interp, menuPtr, objv[2], 0, &index) != TCL_OK) { + if (GetMenuIndex(interp, menuPtr, objv[2], 0, &index) != TCL_OK) { goto error; } if (index < 0) { @@ -863,7 +893,7 @@ MenuWidgetObjCmd( } case MENU_POST: { int x, y; - int index = -1; + Tcl_Size index = TCL_INDEX_NONE; if (objc != 4 && objc != 5) { Tcl_WrongNumArgs(interp, 2, objv, "x y ?index?"); @@ -874,7 +904,7 @@ MenuWidgetObjCmd( goto error; } if (objc == 5) { - if (TkGetMenuIndex(interp, menuPtr, objv[4], 0, &index) != TCL_OK) { + if (GetMenuIndex(interp, menuPtr, objv[4], 0, &index) != TCL_OK) { goto error; } } @@ -898,14 +928,14 @@ MenuWidgetObjCmd( break; } case MENU_POSTCASCADE: { - int index; + Tcl_Size index; if (objc != 3) { Tcl_WrongNumArgs(interp, 2, objv, "index"); goto error; } - if (TkGetMenuIndex(interp, menuPtr, objv[2], 0, &index) != TCL_OK) { + if (GetMenuIndex(interp, menuPtr, objv[2], 0, &index) != TCL_OK) { goto error; } if ((index < 0) || (menuPtr->entries[index]->type != CASCADE_ENTRY)) { @@ -916,14 +946,14 @@ MenuWidgetObjCmd( break; } case MENU_TYPE: { - int index; + Tcl_Size index; const char *typeStr; if (objc != 3) { Tcl_WrongNumArgs(interp, 2, objv, "index"); goto error; } - if (TkGetMenuIndex(interp, menuPtr, objv[2], 0, &index) != TCL_OK) { + if (GetMenuIndex(interp, menuPtr, objv[2], 0, &index) != TCL_OK) { goto error; } if (index < 0) { @@ -934,7 +964,7 @@ MenuWidgetObjCmd( } else { typeStr = menuEntryTypeStrings[menuPtr->entries[index]->type]; } - Tcl_SetObjResult(interp, Tcl_NewStringObj(typeStr, -1)); + Tcl_SetObjResult(interp, Tcl_NewStringObj(typeStr, TCL_INDEX_NONE)); break; } case MENU_UNPOST: @@ -991,7 +1021,7 @@ int TkInvokeMenu( Tcl_Interp *interp, /* The interp that the menu lives in. */ TkMenu *menuPtr, /* The menu we are invoking. */ - int index) /* The zero based index of the item we are + Tcl_Size index) /* The zero based index of the item we are * invoking. */ { int result = TCL_OK; @@ -1010,9 +1040,9 @@ TkInvokeMenu( Tcl_DString ds; Tcl_DStringInit(&ds); - Tcl_DStringAppend(&ds, "tk::TearOffMenu ", -1); - Tcl_DStringAppend(&ds, Tk_PathName(menuPtr->tkwin), -1); - result = Tcl_EvalEx(interp, Tcl_DStringValue(&ds), -1, TCL_EVAL_GLOBAL); + Tcl_DStringAppend(&ds, "tk::TearOffMenu ", TCL_INDEX_NONE); + Tcl_DStringAppend(&ds, Tk_PathName(menuPtr->tkwin), TCL_INDEX_NONE); + result = Tcl_EvalEx(interp, Tcl_DStringValue(&ds), TCL_INDEX_NONE, TCL_EVAL_GLOBAL); Tcl_DStringFree(&ds); } else if ((mePtr->type == CHECK_BUTTON_ENTRY) && (mePtr->namePtr != NULL)) { @@ -1125,10 +1155,10 @@ DestroyMenuInstance( for (; cascadePtr != NULL; cascadePtr = nextCascadePtr) { nextCascadePtr = cascadePtr->nextCascadePtr; - if (menuPtr->masterMenuPtr != menuPtr) { - Tcl_Obj *menuNamePtr = Tcl_NewStringObj("-menu", -1); + if (menuPtr->mainMenuPtr != menuPtr) { + Tcl_Obj *menuNamePtr = Tcl_NewStringObj("-menu", TCL_INDEX_NONE); - parentMainMenuPtr = cascadePtr->menuPtr->masterMenuPtr; + parentMainMenuPtr = cascadePtr->menuPtr->mainMenuPtr; parentMainEntryPtr = parentMainMenuPtr->entries[cascadePtr->index]; newObjv[0] = menuNamePtr; @@ -1151,8 +1181,8 @@ DestroyMenuInstance( } } - if (menuPtr->masterMenuPtr != menuPtr) { - for (menuInstancePtr = menuPtr->masterMenuPtr; + if (menuPtr->mainMenuPtr != menuPtr) { + for (menuInstancePtr = menuPtr->mainMenuPtr; menuInstancePtr != NULL; menuInstancePtr = menuInstancePtr->nextInstancePtr) { if (menuInstancePtr->nextInstancePtr == menuPtr) { @@ -1171,6 +1201,17 @@ DestroyMenuInstance( */ for (i = menuPtr->numEntries; --i >= 0; ) { + /* + * Clean up the hash entry for the menu item ID. + * This cannot be postponed until the entry is eventually freed, + * because the hash table may already have been deleted by then. + */ + + if (menuPtr->entries[i]->entryPtr) { + Tcl_DeleteHashEntry(menuPtr->entries[i]->entryPtr); + menuPtr->entries[i]->entryPtr = NULL; + } + /* * As each menu entry is deleted from the end of the array of entries, * decrement menuPtr->numEntries. Otherwise, the act of deleting menu @@ -1178,7 +1219,8 @@ DestroyMenuInstance( * for menu entries (i+1)...numEntries. */ - Tcl_EventuallyFree(menuPtr->entries[i], DestroyMenuEntry); + Tcl_EventuallyFree(menuPtr->entries[i], + DestroyMenuEntry); menuPtr->numEntries = i; } menuPtr->active = -1; @@ -1186,8 +1228,9 @@ DestroyMenuInstance( ckfree(menuPtr->entries); menuPtr->entries = NULL; } + Tcl_DeleteHashTable(&menuPtr->items); TkMenuFreeDrawOptions(menuPtr); - Tk_FreeConfigOptions((char *) menuPtr, + Tk_FreeConfigOptions(menuPtr, tsdPtr->menuOptionTable, menuPtr->tkwin); if (menuPtr->tkwin != NULL) { Tk_Window tkwin = menuPtr->tkwin; @@ -1250,7 +1293,7 @@ TkDestroyMenu( topLevelListPtr = nextTopLevelPtr; } } - if (menuPtr->masterMenuPtr == menuPtr) { + if (menuPtr->mainMenuPtr == menuPtr) { while (menuPtr->nextInstancePtr != NULL) { menuInstancePtr = menuPtr->nextInstancePtr; menuPtr->nextInstancePtr = menuInstancePtr->nextInstancePtr; @@ -1377,7 +1420,11 @@ UnhookCascadeEntry( static void DestroyMenuEntry( - char *memPtr) /* Pointer to entry to be freed. */ +#if TCL_MAJOR_VERSION > 8 + void *memPtr) /* Pointer to entry to be freed. */ +#else + char *memPtr) +#endif { TkMenuEntry *mePtr = (TkMenuEntry *)memPtr; TkMenu *menuPtr = mePtr->menuPtr; @@ -1398,7 +1445,7 @@ DestroyMenuEntry( */ if (mePtr->type == CASCADE_ENTRY) { - if (menuPtr->masterMenuPtr != menuPtr) { + if (menuPtr->mainMenuPtr != menuPtr) { TkMenu *destroyThis = NULL; TkMenuReferences *menuRefPtr = mePtr->childMenuRefPtr; @@ -1418,7 +1465,7 @@ DestroyMenuEntry( */ if ((destroyThis != NULL) - && (destroyThis->masterMenuPtr == destroyThis)) { + && (destroyThis->mainMenuPtr == destroyThis)) { destroyThis = NULL; } } @@ -1451,9 +1498,13 @@ DestroyMenuEntry( TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, MenuVarProc, mePtr); } + if (mePtr->entryPtr) { + Tcl_DeleteHashEntry(mePtr->entryPtr); + mePtr->entryPtr = NULL; + } TkpDestroyMenuEntry(mePtr); TkMenuEntryFreeDrawOptions(mePtr); - Tk_FreeConfigOptions((char *) mePtr, mePtr->optionTable, menuPtr->tkwin); + Tk_FreeConfigOptions(mePtr, mePtr->optionTable, menuPtr->tkwin); ckfree(mePtr); } @@ -1477,10 +1528,10 @@ DestroyMenuEntry( static void MenuWorldChanged( - ClientData instanceData) /* Information about widget. */ + void *instanceData) /* Information about widget. */ { TkMenu *menuPtr = (TkMenu *)instanceData; - int i; + Tcl_Size i; TkMenuConfigureDrawOptions(menuPtr); for (i = 0; i < menuPtr->numEntries; i++) { @@ -1515,7 +1566,7 @@ ConfigureMenu( Tcl_Interp *interp, /* Used for error reporting. */ TkMenu *menuPtr, /* Information about widget; may or may not * already have values for some fields. */ - int objc, /* Number of valid entries in argv. */ + Tcl_Size objc, /* Number of valid entries in argv. */ Tcl_Obj *const objv[]) /* Arguments. */ { int i; @@ -1524,14 +1575,14 @@ ConfigureMenu( ThreadSpecificData *tsdPtr = (ThreadSpecificData *) Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); - for (menuListPtr = menuPtr->masterMenuPtr; menuListPtr != NULL; + for (menuListPtr = menuPtr->mainMenuPtr; menuListPtr != NULL; menuListPtr = menuListPtr->nextInstancePtr) { menuListPtr->errorStructPtr = (Tk_SavedOptions *)ckalloc(sizeof(Tk_SavedOptions)); - result = Tk_SetOptions(interp, (char *) menuListPtr, + result = Tk_SetOptions(interp, menuListPtr, tsdPtr->menuOptionTable, objc, objv, menuListPtr->tkwin, menuListPtr->errorStructPtr, NULL); if (result != TCL_OK) { - for (cleanupPtr = menuPtr->masterMenuPtr; + for (cleanupPtr = menuPtr->mainMenuPtr; cleanupPtr != menuListPtr; cleanupPtr = cleanupPtr->nextInstancePtr) { Tk_RestoreSavedOptions(cleanupPtr->errorStructPtr); @@ -1600,7 +1651,7 @@ ConfigureMenu( if ((menuListPtr->numEntries == 0) || (menuListPtr->entries[0]->type != TEAROFF_ENTRY)) { if (MenuNewEntry(menuListPtr, 0, TEAROFF_ENTRY) == NULL) { - for (cleanupPtr = menuPtr->masterMenuPtr; + for (cleanupPtr = menuPtr->mainMenuPtr; cleanupPtr != menuListPtr; cleanupPtr = cleanupPtr->nextInstancePtr) { Tk_RestoreSavedOptions(cleanupPtr->errorStructPtr); @@ -1649,7 +1700,7 @@ ConfigureMenu( TkEventuallyRecomputeMenu(menuListPtr); } - for (cleanupPtr = menuPtr->masterMenuPtr; cleanupPtr != NULL; + for (cleanupPtr = menuPtr->mainMenuPtr; cleanupPtr != NULL; cleanupPtr = cleanupPtr->nextInstancePtr) { Tk_FreeSavedOptions(cleanupPtr->errorStructPtr); ckfree(cleanupPtr->errorStructPtr); @@ -1697,12 +1748,12 @@ PostProcessEntry( if (mePtr->labelPtr == NULL) { mePtr->labelLength = 0; } else { - Tcl_GetStringFromObj(mePtr->labelPtr, &mePtr->labelLength); + (void)Tcl_GetStringFromObj(mePtr->labelPtr, &mePtr->labelLength); } if (mePtr->accelPtr == NULL) { mePtr->accelLength = 0; } else { - Tcl_GetStringFromObj(mePtr->accelPtr, &mePtr->accelLength); + (void)Tcl_GetStringFromObj(mePtr->accelPtr, &mePtr->accelLength); } /* @@ -1896,7 +1947,7 @@ static int ConfigureMenuEntry( TkMenuEntry *mePtr,/* Information about menu entry; may or may * not already have values for some fields. */ - int objc, /* Number of valid entries in argv. */ + Tcl_Size objc, /* Number of valid entries in argv. */ Tcl_Obj *const objv[]) /* Arguments. */ { TkMenu *menuPtr = mePtr->menuPtr; @@ -1920,7 +1971,7 @@ ConfigureMenuEntry( result = TCL_OK; if (menuPtr->tkwin != NULL) { - if (Tk_SetOptions(menuPtr->interp, (char *) mePtr, + if (Tk_SetOptions(menuPtr->interp, mePtr, mePtr->optionTable, objc, objv, menuPtr->tkwin, &errorStruct, NULL) != TCL_OK) { return TCL_ERROR; @@ -1946,8 +1997,7 @@ ConfigureMenuEntry( * Calls ConfigureMenuEntry for each menu in the clone chain. * * Results: - * The return value is a standard Tcl result. If TCL_ERROR is returned, - * then the interp's result contains an error message. + * The return value is a standard Tcl result. * * Side effects: * Configuration information such as label and accelerator get set for @@ -1958,10 +2008,9 @@ ConfigureMenuEntry( static int ConfigureMenuCloneEntries( - Tcl_Interp *interp, /* Used for error reporting. */ TkMenu *menuPtr, /* Information about whole menu. */ int index, /* Index of mePtr within menuPtr's entries. */ - int objc, /* Number of valid entries in argv. */ + Tcl_Size objc, /* Number of valid entries in argv. */ Tcl_Obj *const objv[]) /* Arguments. */ { TkMenuEntry *mePtr; @@ -1980,7 +2029,7 @@ ConfigureMenuCloneEntries( * configure the entry to point to the new clone. */ - mePtr = menuPtr->masterMenuPtr->entries[index]; + mePtr = menuPtr->mainMenuPtr->entries[index]; if (mePtr->type == CASCADE_ENTRY) { oldCascadePtr = mePtr->namePtr; if (oldCascadePtr != NULL) { @@ -2025,7 +2074,7 @@ ConfigureMenuCloneEntries( } } - for (menuListPtr = menuPtr->masterMenuPtr->nextInstancePtr; + for (menuListPtr = menuPtr->mainMenuPtr->nextInstancePtr; menuListPtr != NULL; menuListPtr = menuListPtr->nextInstancePtr) { @@ -2050,9 +2099,9 @@ ConfigureMenuCloneEntries( Tcl_Obj *newObjv[2]; Tcl_Obj *newCloneNamePtr; Tcl_Obj *pathNamePtr = Tcl_NewStringObj( - Tk_PathName(menuListPtr->tkwin), -1); - Tcl_Obj *normalPtr = Tcl_NewStringObj("normal", -1); - Tcl_Obj *menuObjPtr = Tcl_NewStringObj("-menu", -1); + Tk_PathName(menuListPtr->tkwin), TCL_INDEX_NONE); + Tcl_Obj *normalPtr = Tcl_NewStringObj("normal", TCL_INDEX_NONE); + Tcl_Obj *menuObjPtr = Tcl_NewStringObj("-menu", TCL_INDEX_NONE); Tcl_IncrRefCount(pathNamePtr); newCloneNamePtr = TkNewMenuName(menuPtr->interp, @@ -2080,7 +2129,7 @@ ConfigureMenuCloneEntries( /* *-------------------------------------------------------------- * - * TkGetMenuIndex -- + * GetMenuIndex -- * * Parse a textual index into a menu and return the numerical index of * the indicated entry. @@ -2098,7 +2147,7 @@ ConfigureMenuCloneEntries( */ int -TkGetMenuIndex( +GetMenuIndex( Tcl_Interp *interp, /* For error messages. */ TkMenu *menuPtr, /* Menu for which the index is being * specified. */ @@ -2106,27 +2155,44 @@ TkGetMenuIndex( * manual entry for valid .*/ int lastOK, /* Non-zero means its OK to return index just * *after* last entry. */ - int *indexPtr) /* Where to store converted index. */ + Tcl_Size *indexPtr) /* Where to store converted index. */ { - int i; - const char *string = Tcl_GetString(objPtr); + Tcl_Size i; + const char *string; + Tcl_HashEntry *entryPtr; + + if (TkGetIntForIndex(objPtr, menuPtr->numEntries - 1, lastOK, indexPtr) == TCL_OK) { + /* TCL_INDEX_NONE is only accepted if it does not result from a negative number */ + if (*indexPtr >= 0 || Tcl_GetString(objPtr)[0] != '-') { + if (*indexPtr >= menuPtr->numEntries) { + *indexPtr = menuPtr->numEntries - ((lastOK) ? 0 : 1); + } + return TCL_OK; + } + } + + string = Tcl_GetString(objPtr); if ((string[0] == 'a') && (strcmp(string, "active") == 0)) { *indexPtr = menuPtr->active; return TCL_OK; } - if (((string[0] == 'l') && (strcmp(string, "last") == 0)) - || ((string[0] == 'e') && (strcmp(string, "end") == 0))) { + if ((string[0] == 'l') && (strcmp(string, "last") == 0)) { *indexPtr = menuPtr->numEntries - ((lastOK) ? 0 : 1); return TCL_OK; } - if ((string[0] == '\0') || - ((string[0] == 'n') && (strcmp(string, "none") == 0))) { - *indexPtr = -1; + if (string[0] == 0) { + *indexPtr = TCL_INDEX_NONE; + return TCL_OK; + } +#if !defined(TK_NO_DEPRECATED) + if ((string[0] == 'n') && (strcmp(string, "none") == 0)) { + *indexPtr = TCL_INDEX_NONE; return TCL_OK; } +#endif if (string[0] == '@') { if (GetIndexFromCoords(interp, menuPtr, string, indexPtr) @@ -2135,21 +2201,11 @@ TkGetMenuIndex( } } - if (isdigit(UCHAR(string[0]))) { - if (Tcl_GetIntFromObj(interp, objPtr, &i) == TCL_OK) { - if (i >= menuPtr->numEntries) { - if (lastOK) { - i = menuPtr->numEntries; - } else { - i = menuPtr->numEntries-1; - } - } else if (i < 0) { - i = -1; - } - *indexPtr = i; - return TCL_OK; - } - Tcl_ResetResult(interp); + entryPtr = Tcl_FindHashEntry(&menuPtr->items, string); + if (entryPtr) { + TkMenuEntry *mePtr = (TkMenuEntry *)Tcl_GetHashValue(entryPtr); + *indexPtr = mePtr->index; + return TCL_OK; } for (i = 0; i < menuPtr->numEntries; i++) { @@ -2188,7 +2244,7 @@ TkGetMenuIndex( static void MenuCmdDeletedProc( - ClientData clientData) /* Pointer to widget record for widget. */ + void *clientData) /* Pointer to widget record for widget. */ { TkMenu *menuPtr = (TkMenu *)clientData; Tk_Window tkwin = menuPtr->tkwin; @@ -2232,13 +2288,13 @@ MenuCmdDeletedProc( static TkMenuEntry * MenuNewEntry( TkMenu *menuPtr, /* Menu that will hold the new entry. */ - int index, /* Where in the menu the new entry is to + Tcl_Size index, /* Where in the menu the new entry is to * go. */ int type) /* The type of the new entry. */ { TkMenuEntry *mePtr; TkMenuEntry **newEntries; - int i; + Tcl_Size i; ThreadSpecificData *tsdPtr = (ThreadSpecificData *) Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); @@ -2266,7 +2322,7 @@ MenuNewEntry( mePtr->menuPtr = menuPtr; mePtr->labelPtr = NULL; mePtr->labelLength = 0; - mePtr->underline = -1; + mePtr->underline = INT_MIN; mePtr->bitmapPtr = NULL; mePtr->imagePtr = NULL; mePtr->image = NULL; @@ -2292,14 +2348,15 @@ MenuNewEntry( mePtr->entryFlags = 0; mePtr->index = index; mePtr->nextCascadePtr = NULL; - if (Tk_InitOptions(menuPtr->interp, (char *) mePtr, + if (Tk_InitOptions(menuPtr->interp, mePtr, mePtr->optionTable, menuPtr->tkwin) != TCL_OK) { ckfree(mePtr); return NULL; } + mePtr->entryPtr = NULL; TkMenuInitializeEntryDrawingFields(mePtr); if (TkpMenuNewEntry(mePtr) != TCL_OK) { - Tk_FreeConfigOptions((char *) mePtr, mePtr->optionTable, + Tk_FreeConfigOptions(mePtr, mePtr->optionTable, menuPtr->tkwin); ckfree(mePtr); return NULL; @@ -2331,17 +2388,21 @@ MenuAddOrInsert( TkMenu *menuPtr, /* Widget in which to create new entry. */ Tcl_Obj *indexPtr, /* Object describing index at which to insert. * NULL means insert at end. */ - int objc, /* Number of elements in objv. */ + Tcl_Size objc, /* Number of elements in objv. */ Tcl_Obj *const objv[]) /* Arguments to command: first arg is type of * entry, others are config options. */ { int type; - int index; + Tcl_Size index; TkMenuEntry *mePtr; TkMenu *menuListPtr; + Tcl_HashEntry *entryPtr; + Tcl_Obj *idPtr = NULL; + int isNew; + int offs; if (indexPtr != NULL) { - if (TkGetMenuIndex(interp, menuPtr, indexPtr, 1, &index) != TCL_OK) { + if (GetMenuIndex(interp, menuPtr, indexPtr, 1, &index) != TCL_OK) { return TCL_ERROR; } } else { @@ -2349,7 +2410,7 @@ MenuAddOrInsert( } if (index < 0) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "bad index \"%s\"", Tcl_GetString(indexPtr))); + "bad menu entry index \"%s\"", Tcl_GetString(indexPtr))); Tcl_SetErrorCode(interp, "TK", "MENU", "INDEX", NULL); return TCL_ERROR; } @@ -2365,26 +2426,42 @@ MenuAddOrInsert( sizeof(char *), "menu entry type", 0, &type) != TCL_OK) { return TCL_ERROR; } + offs = 1; /* - * Now we have to add an entry for every instance related to this menu. + * Check for a user supplied id */ - for (menuListPtr = menuPtr->masterMenuPtr; menuListPtr != NULL; + if (objc % 2 == 0) { + idPtr = objv[offs]; + if (Tcl_FindHashEntry(&menuPtr->items, Tcl_GetString(idPtr))) { + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "entry \"%s\" already exists", Tcl_GetString(idPtr))); + Tcl_SetErrorCode(interp, "TK", "MENU", "ENTRY_EXISTS", NULL); + return TCL_ERROR; + } + offs++; + } + + /* + * Now we have to add an entry for every instance related to this menu. + */ + for (menuListPtr = menuPtr->mainMenuPtr; menuListPtr != NULL; menuListPtr = menuListPtr->nextInstancePtr) { mePtr = MenuNewEntry(menuListPtr, index, type); if (mePtr == NULL) { return TCL_ERROR; } - if (ConfigureMenuEntry(mePtr, objc - 1, objv + 1) != TCL_OK) { + if (ConfigureMenuEntry(mePtr, objc - offs, objv + offs) != TCL_OK) { TkMenu *errorMenuPtr; - int i; + Tcl_Size i; - for (errorMenuPtr = menuPtr->masterMenuPtr; + for (errorMenuPtr = menuPtr->mainMenuPtr; errorMenuPtr != NULL; errorMenuPtr = errorMenuPtr->nextInstancePtr) { - Tcl_EventuallyFree(errorMenuPtr->entries[index], DestroyMenuEntry); + Tcl_EventuallyFree(errorMenuPtr->entries[index], + DestroyMenuEntry); for (i = index; i < errorMenuPtr->numEntries - 1; i++) { errorMenuPtr->entries[i] = errorMenuPtr->entries[i + 1]; errorMenuPtr->entries[i]->index = i; @@ -2400,6 +2477,23 @@ MenuAddOrInsert( return TCL_ERROR; } + if (idPtr == NULL) { + char idbuf[16]; + /* Generate an id for the new entry on the main menu */ + do { + snprintf(idbuf, sizeof(idbuf), "e%03X", ++menuPtr->serial); + entryPtr = Tcl_CreateHashEntry( + &menuListPtr->items, idbuf, &isNew); + } while (!isNew); + idPtr = Tcl_NewStringObj(idbuf, TCL_INDEX_NONE); + } else { + /* Reuse the specified or previously generated id on all clones */ + entryPtr = Tcl_CreateHashEntry( + &menuListPtr->items, Tcl_GetString(idPtr), &isNew); + } + Tcl_SetHashValue(entryPtr, mePtr); + mePtr->entryPtr = entryPtr; + /* * If a menu has cascades, then every instance of the menu has to have * its own parallel cascade structure. So adding an entry to a menu @@ -2413,12 +2507,12 @@ MenuAddOrInsert( && (mePtr->childMenuRefPtr != NULL) && (mePtr->childMenuRefPtr->menuPtr != NULL)) { TkMenu *cascadeMenuPtr = - mePtr->childMenuRefPtr->menuPtr->masterMenuPtr; + mePtr->childMenuRefPtr->menuPtr->mainMenuPtr; Tcl_Obj *newCascadePtr, *newObjv[2]; - Tcl_Obj *menuNamePtr = Tcl_NewStringObj("-menu", -1); + Tcl_Obj *menuNamePtr = Tcl_NewStringObj("-menu", TCL_INDEX_NONE); Tcl_Obj *windowNamePtr = - Tcl_NewStringObj(Tk_PathName(menuListPtr->tkwin), -1); - Tcl_Obj *normalPtr = Tcl_NewStringObj("normal", -1); + Tcl_NewStringObj(Tk_PathName(menuListPtr->tkwin), TCL_INDEX_NONE); + Tcl_Obj *normalPtr = Tcl_NewStringObj("normal", TCL_INDEX_NONE); TkMenuReferences *menuRefPtr; Tcl_IncrRefCount(windowNamePtr); @@ -2445,6 +2539,8 @@ MenuAddOrInsert( } } } + + Tcl_SetObjResult(interp, idPtr); return TCL_OK; } @@ -2468,10 +2564,10 @@ MenuAddOrInsert( static char * MenuVarProc( - ClientData clientData, /* Information about menu entry. */ + void *clientData, /* Information about menu entry. */ Tcl_Interp *interp, /* Interpreter containing variable. */ - const char *name1, /* First part of variable's name. */ - const char *name2, /* Second part of variable's name. */ + TCL_UNUSED(const char *), /* First part of variable's name. */ + TCL_UNUSED(const char *), /* Second part of variable's name. */ int flags) /* Describes what just happened. */ { TkMenuEntry *mePtr = (TkMenuEntry *)clientData; @@ -2501,14 +2597,14 @@ MenuVarProc( */ if (flags & TCL_TRACE_UNSETS) { - ClientData probe = NULL; + void *probe = NULL; mePtr->entryFlags &= ~ENTRY_SELECTED; do { probe = Tcl_VarTraceInfo(interp, name, TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, MenuVarProc, probe); - if (probe == (ClientData)mePtr) { + if (probe == (void *)mePtr) { break; } } while (probe); @@ -2580,8 +2676,8 @@ MenuVarProc( int TkActivateMenuEntry( TkMenu *menuPtr, /* Menu in which to activate. */ - int index) /* Index of entry to activate, or -1 to - * deactivate all entries. */ + Tcl_Size index) /* Index of entry to activate, or + * TCL_INDEX_NONE to deactivate all entries. */ { TkMenuEntry *mePtr; int result = TCL_OK; @@ -2681,7 +2777,7 @@ CloneMenu( { int returnResult; int menuType; - int i; + Tcl_Size i; TkMenuReferences *menuRefPtr; Tcl_Obj *menuDupCommandArray[4]; @@ -2694,11 +2790,11 @@ CloneMenu( } } - menuDupCommandArray[0] = Tcl_NewStringObj("tk::MenuDup", -1); - menuDupCommandArray[1] = Tcl_NewStringObj(Tk_PathName(menuPtr->tkwin), -1); + menuDupCommandArray[0] = Tcl_NewStringObj("tk::MenuDup", TCL_INDEX_NONE); + menuDupCommandArray[1] = Tcl_NewStringObj(Tk_PathName(menuPtr->tkwin), TCL_INDEX_NONE); menuDupCommandArray[2] = newMenuNamePtr; if (newMenuTypePtr == NULL) { - menuDupCommandArray[3] = Tcl_NewStringObj("normal", -1); + menuDupCommandArray[3] = Tcl_NewStringObj("normal", TCL_INDEX_NONE); } else { menuDupCommandArray[3] = newMenuTypePtr; } @@ -2721,7 +2817,7 @@ CloneMenu( && (menuPtr->numEntries == menuRefPtr->menuPtr->numEntries)) { TkMenu *newMenuPtr = menuRefPtr->menuPtr; Tcl_Obj *newObjv[3]; - int numElements; + Tcl_Size numElements; /* * Now put this newly created menu into the parent menu's instance @@ -2730,14 +2826,14 @@ CloneMenu( if (menuPtr->nextInstancePtr == NULL) { menuPtr->nextInstancePtr = newMenuPtr; - newMenuPtr->masterMenuPtr = menuPtr->masterMenuPtr; + newMenuPtr->mainMenuPtr = menuPtr->mainMenuPtr; } else { - TkMenu *masterMenuPtr; + TkMenu *mainMenuPtr; - masterMenuPtr = menuPtr->masterMenuPtr; - newMenuPtr->nextInstancePtr = masterMenuPtr->nextInstancePtr; - masterMenuPtr->nextInstancePtr = newMenuPtr; - newMenuPtr->masterMenuPtr = masterMenuPtr; + mainMenuPtr = menuPtr->mainMenuPtr; + newMenuPtr->nextInstancePtr = mainMenuPtr->nextInstancePtr; + mainMenuPtr->nextInstancePtr = newMenuPtr; + newMenuPtr->mainMenuPtr = mainMenuPtr; } /* @@ -2747,8 +2843,8 @@ CloneMenu( * structure. */ - newObjv[0] = Tcl_NewStringObj("bindtags", -1); - newObjv[1] = Tcl_NewStringObj(Tk_PathName(newMenuPtr->tkwin), -1); + newObjv[0] = Tcl_NewStringObj("bindtags", TCL_INDEX_NONE); + newObjv[1] = Tcl_NewStringObj(Tk_PathName(newMenuPtr->tkwin), TCL_INDEX_NONE); Tcl_IncrRefCount(newObjv[0]); Tcl_IncrRefCount(newObjv[1]); if (Tk_BindtagsObjCmd(newMenuPtr->tkwin, newMenuPtr->interp, 2, @@ -2767,7 +2863,7 @@ CloneMenu( if (strcmp(windowName, Tk_PathName(newMenuPtr->tkwin)) == 0) { Tcl_Obj *newElementPtr = Tcl_NewStringObj( - Tk_PathName(newMenuPtr->masterMenuPtr->tkwin), -1); + Tk_PathName(newMenuPtr->mainMenuPtr->tkwin), TCL_INDEX_NONE); /* * The newElementPtr will have its refCount incremented @@ -2815,7 +2911,7 @@ CloneMenu( Tcl_IncrRefCount(newCascadePtr); CloneMenu(oldCascadePtr, newCascadePtr, NULL); - newObjv[0] = Tcl_NewStringObj("-menu", -1); + newObjv[0] = Tcl_NewStringObj("-menu", TCL_INDEX_NONE); newObjv[1] = newCascadePtr; Tcl_IncrRefCount(newObjv[0]); ConfigureMenuEntry(newMenuPtr->entries[i], 2, newObjv); @@ -2856,17 +2952,17 @@ MenuDoXPosition( TkMenu *menuPtr, Tcl_Obj *objPtr) { - int index; + Tcl_Size index; TkRecomputeMenu(menuPtr); - if (TkGetMenuIndex(interp, menuPtr, objPtr, 0, &index) != TCL_OK) { + if (GetMenuIndex(interp, menuPtr, objPtr, 0, &index) != TCL_OK) { return TCL_ERROR; } Tcl_ResetResult(interp); if (index < 0) { - Tcl_SetObjResult(interp, Tcl_NewIntObj(0)); + Tcl_SetObjResult(interp, Tcl_NewWideIntObj(0)); } else { - Tcl_SetObjResult(interp, Tcl_NewIntObj(menuPtr->entries[index]->x)); + Tcl_SetObjResult(interp, Tcl_NewWideIntObj(menuPtr->entries[index]->x)); } return TCL_OK; } @@ -2893,17 +2989,17 @@ MenuDoYPosition( TkMenu *menuPtr, Tcl_Obj *objPtr) { - int index; + Tcl_Size index; TkRecomputeMenu(menuPtr); - if (TkGetMenuIndex(interp, menuPtr, objPtr, 0, &index) != TCL_OK) { + if (GetMenuIndex(interp, menuPtr, objPtr, 0, &index) != TCL_OK) { goto error; } Tcl_ResetResult(interp); if (index < 0) { - Tcl_SetObjResult(interp, Tcl_NewIntObj(0)); + Tcl_SetObjResult(interp, Tcl_NewWideIntObj(0)); } else { - Tcl_SetObjResult(interp, Tcl_NewIntObj(menuPtr->entries[index]->y)); + Tcl_SetObjResult(interp, Tcl_NewWideIntObj(menuPtr->entries[index]->y)); } return TCL_OK; @@ -2931,40 +3027,40 @@ MenuDoYPosition( *---------------------------------------------------------------------- */ -static int +static Tcl_Size GetIndexFromCoords( Tcl_Interp *interp, /* Interpreter of menu. */ TkMenu *menuPtr, /* The menu we are searching. */ const char *string, /* The @string we are parsing. */ - int *indexPtr) /* The index of the item that matches. */ + Tcl_Size *indexPtr) /* The index of the item that matches. */ { int x, y; - int i; + Tcl_Size i; const char *p; - char *end; + const char *rest; int x2, borderwidth, max; TkRecomputeMenu(menuPtr); p = string + 1; - y = strtol(p, &end, 0); - if (end == p) { - goto error; - } - Tk_GetPixelsFromObj(interp, menuPtr->tkwin, - menuPtr->borderWidthPtr, &borderwidth); - if (*end == ',') { - x = y; - p = end + 1; - y = strtol(p, &end, 0); - if ((end == p) || (*end != '\0')) { + Tk_GetPixelsFromObj(NULL, menuPtr->tkwin, + menuPtr->borderWidthPtr, &borderwidth); + rest = strchr(p, ','); + if (rest) { + Tcl_DString ds; + Tcl_DStringInit(&ds); + Tcl_DStringAppend(&ds, p, rest - p); + + if (Tcl_GetInt(NULL, Tcl_DStringValue(&ds), &x) != TCL_OK) { goto error; } } else { - if (*end != '\0') { - goto error; - } x = borderwidth; + rest = string; } + p = rest + 1; + if (Tcl_GetInt(NULL, p, &y) != TCL_OK) { + goto error; + } *indexPtr = -1; @@ -3018,7 +3114,7 @@ static void RecursivelyDeleteMenu( TkMenu *menuPtr) /* The menubar instance we are deleting. */ { - int i; + Tcl_Size i; TkMenuEntry *mePtr; /* @@ -3081,7 +3177,7 @@ TkNewMenuName( doDot = parentName[strlen(parentName) - 1] != '.'; - childPtr = Tcl_NewStringObj(Tk_PathName(menuPtr->tkwin), -1); + childPtr = Tcl_NewStringObj(Tk_PathName(menuPtr->tkwin), TCL_INDEX_NONE); for (destString = Tcl_GetString(childPtr); *destString != '\0'; destString++) { if (*destString == '.') { @@ -3093,7 +3189,7 @@ TkNewMenuName( if (i == 0) { resultPtr = Tcl_DuplicateObj(parentPtr); if (doDot) { - Tcl_AppendToObj(resultPtr, ".", -1); + Tcl_AppendToObj(resultPtr, ".", TCL_INDEX_NONE); } Tcl_AppendObjToObj(resultPtr, childPtr); } else { @@ -3102,10 +3198,10 @@ TkNewMenuName( Tcl_DecrRefCount(resultPtr); resultPtr = Tcl_DuplicateObj(parentPtr); if (doDot) { - Tcl_AppendToObj(resultPtr, ".", -1); + Tcl_AppendToObj(resultPtr, ".", TCL_INDEX_NONE); } Tcl_AppendObjToObj(resultPtr, childPtr); - intPtr = Tcl_NewIntObj(i); + intPtr = Tcl_NewWideIntObj(i); Tcl_AppendObjToObj(resultPtr, intPtr); Tcl_DecrRefCount(intPtr); } @@ -3123,7 +3219,7 @@ TkNewMenuName( /* *---------------------------------------------------------------------- * - * TkSetWindowMenuBar -- + * Tk_SetWindowMenubar -- * * Associates a menu with a window. Called by ConfigureFrame in in * response to a "-menu .foo" configuration option for a top level. @@ -3139,7 +3235,7 @@ TkNewMenuName( */ void -TkSetWindowMenuBar( +Tk_SetWindowMenubar( Tcl_Interp *interp, /* The interpreter the toplevel lives in. */ Tk_Window tkwin, /* The toplevel window. */ const char *oldMenuName, /* The name of the menubar previously set in @@ -3171,7 +3267,7 @@ TkSetWindowMenuBar( menuPtr = menuRefPtr->menuPtr; - for (instancePtr = menuPtr->masterMenuPtr; + for (instancePtr = menuPtr->mainMenuPtr; instancePtr != NULL; instancePtr = instancePtr->nextInstancePtr) { if (instancePtr->menuType == MENUBAR @@ -3230,7 +3326,7 @@ TkSetWindowMenuBar( Tcl_Obj *newObjv[4]; Tcl_Obj *windowNamePtr = Tcl_NewStringObj(Tk_PathName(tkwin), -1); - Tcl_Obj *menubarPtr = Tcl_NewStringObj("menubar", -1); + Tcl_Obj *menubarPtr = Tcl_NewStringObj("menubar", TCL_INDEX_NONE); /* * Clone the menu and all of the cascades underneath it. @@ -3246,7 +3342,7 @@ TkSetWindowMenuBar( cloneMenuRefPtr = TkFindMenuReferencesObj(interp, cloneMenuPtr); if ((cloneMenuRefPtr != NULL) && (cloneMenuRefPtr->menuPtr != NULL)) { - Tcl_Obj *cursorPtr = Tcl_NewStringObj("-cursor", -1); + Tcl_Obj *cursorPtr = Tcl_NewStringObj("-cursor", TCL_INDEX_NONE); Tcl_Obj *nullPtr = Tcl_NewObj(); cloneMenuRefPtr->menuPtr->parentTopLevelPtr = tkwin; @@ -3281,7 +3377,7 @@ TkSetWindowMenuBar( } else { TkpSetWindowMenuBar(tkwin, NULL); } - TkpSetMainMenubar(interp, tkwin, menuName); + Tk_SetMainMenubar(interp, tkwin, menuName); } /* @@ -3303,8 +3399,8 @@ TkSetWindowMenuBar( static void DestroyMenuHashTable( - ClientData clientData, /* The menu hash table we are destroying. */ - Tcl_Interp *interp) /* The interpreter we are destroying. */ + void *clientData, /* The menu hash table we are destroying. */ + TCL_UNUSED(Tcl_Interp *)) /* The interpreter we are destroying. */ { Tcl_DeleteHashTable((Tcl_HashTable *)clientData); ckfree(clientData); @@ -3514,10 +3610,10 @@ DeleteMenuCloneEntries( int last) /* The zero-based last entry. */ { TkMenu *menuListPtr; - int numDeleted, i, j; + Tcl_Size numDeleted, i, j; numDeleted = last + 1 - first; - for (menuListPtr = menuPtr->masterMenuPtr; menuListPtr != NULL; + for (menuListPtr = menuPtr->mainMenuPtr; menuListPtr != NULL; menuListPtr = menuListPtr->nextInstancePtr) { for (i = last; i >= first; i--) { Tcl_EventuallyFree(menuListPtr->entries[i], DestroyMenuEntry); @@ -3532,10 +3628,10 @@ DeleteMenuCloneEntries( ckfree(menuListPtr->entries); menuListPtr->entries = NULL; } - if ((menuListPtr->active >= first) - && (menuListPtr->active <= last)) { + if (((int)menuListPtr->active >= first) + && ((int)menuListPtr->active <= last)) { menuListPtr->active = -1; - } else if (menuListPtr->active > last) { + } else if ((int)menuListPtr->active > last) { menuListPtr->active -= numDeleted; } TkEventuallyRecomputeMenu(menuListPtr); @@ -3545,7 +3641,7 @@ DeleteMenuCloneEntries( /* *---------------------------------------------------------------------- * - * TkMenuCleanup -- + * MenuCleanup -- * * Resets menusInitialized to allow Tk to be finalized and reused without * the DLL being unloaded. @@ -3560,8 +3656,8 @@ DeleteMenuCloneEntries( */ static void -TkMenuCleanup( - ClientData unused) +MenuCleanup( + TCL_UNUSED(void *)) { menusInitialized = 0; } @@ -3600,7 +3696,7 @@ TkMenuInit(void) * Make sure we cleanup on finalize. */ - TkCreateExitHandler((Tcl_ExitProc *) TkMenuCleanup, NULL); + TkCreateExitHandler((Tcl_ExitProc *) MenuCleanup, NULL); Tcl_MutexUnlock(&menuMutex); } if (!tsdPtr->menusInitialized) { |