summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--macosx/tkMacOSXMenu.c26
-rw-r--r--tests/menu.test2
2 files changed, 16 insertions, 12 deletions
diff --git a/macosx/tkMacOSXMenu.c b/macosx/tkMacOSXMenu.c
index f36da42..ed8d0c3 100644
--- a/macosx/tkMacOSXMenu.c
+++ b/macosx/tkMacOSXMenu.c
@@ -779,7 +779,7 @@ TkpPostMenu(
* entry, will be located. */
int index)
{
- /* Get the object that holds this Tk Window.*/
+ int result, oldMode;
Tk_Window root = Tk_MainWindow(interp);
if (root == NULL) {
@@ -790,9 +790,10 @@ TkpPostMenu(
NSWindow *win = [rootview window];
NSView *view = [win contentView];
NSMenu *menu = (NSMenu *) menuPtr->platformData;
+ NSInteger itemIndex = index;
+ NSInteger numItems = [menu numberOfItems];
NSMenuItem *item = nil;
NSPoint location = NSMakePoint(x, tkMacOSXZeroScreenHeight - y);
- int result, oldMode;
inPostMenu = 1;
result = TkPreprocessMenu(menuPtr);
@@ -800,17 +801,19 @@ TkpPostMenu(
inPostMenu = 0;
return result;
}
- if (index >= [menu numberOfItems]) {
- index = [menu numberOfItems] - 1;
+ if (itemIndex >= numItems) {
+ itemIndex = numItems - 1;
+ }
+ if (itemIndex >= 0) {
+ item = [menu itemAtIndex:itemIndex];
}
- if (index >= 0) {
- item = [menu itemAtIndex:(NSInteger)index];
+ if (menu != nil && item != nil) {
+ oldMode = Tcl_SetServiceMode(TCL_SERVICE_NONE);
+ [menu popUpMenuPositioningItem:item
+ atLocation:[win tkConvertPointFromScreen:location]
+ inView:view];
+ Tcl_SetServiceMode(oldMode);
}
- oldMode = Tcl_SetServiceMode(TCL_SERVICE_NONE);
- [menu popUpMenuPositioningItem:item
- atLocation:[win tkConvertPointFromScreen:location]
- inView:view];
- Tcl_SetServiceMode(oldMode);
inPostMenu = 0;
return TCL_OK;
}
@@ -824,6 +827,7 @@ TkpPostTearoffMenu(
* entry, will be located. */
int index)
{
+ menuPtr->active = -1;
return TkpPostMenu(interp, menuPtr, x, y, index);
}
diff --git a/tests/menu.test b/tests/menu.test
index dcc578f..9ad2a0c 100644
--- a/tests/menu.test
+++ b/tests/menu.test
@@ -1606,7 +1606,7 @@ test menu-3.47 {MenuWidgetCmd procedure, "post" option} -setup {
.m1 post
} -cleanup {
destroy .m1
-} -returnCodes error -result {wrong # args: should be ".m1 post x y ?entry?"}
+} -returnCodes error -result {wrong # args: should be ".m1 post x y ?index?"}
test menu-3.48 {MenuWidgetCmd procedure, "post" option} -setup {
destroy .m1
} -body {