diff options
-rw-r--r-- | src/macos.m | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/macos.m b/src/macos.m index 658acb05..3106d9e3 100644 --- a/src/macos.m +++ b/src/macos.m | |||
@@ -538,7 +538,9 @@ enum iColorId removeColorEscapes_String(iString *d) { | |||
538 | return color; | 538 | return color; |
539 | } | 539 | } |
540 | 540 | ||
541 | static void makeMenuItems_(NSMenu *menu, MenuCommands *commands, const iMenuItem *items, size_t n) { | 541 | // returns the selected item, if any |
542 | static NSMenuItem *makeMenuItems_(NSMenu *menu, MenuCommands *commands, const iMenuItem *items, size_t n) { | ||
543 | NSMenuItem *selectedItem = nil; | ||
542 | for (size_t i = 0; i < n && items[i].label; ++i) { | 544 | for (size_t i = 0; i < n && items[i].label; ++i) { |
543 | const char *label = translateCStr_Lang(items[i].label); | 545 | const char *label = translateCStr_Lang(items[i].label); |
544 | if (equal_CStr(label, "---")) { | 546 | if (equal_CStr(label, "---")) { |
@@ -569,6 +571,7 @@ static void makeMenuItems_(NSMenu *menu, MenuCommands *commands, const iMenuItem | |||
569 | [item setTarget:commands]; | 571 | [item setTarget:commands]; |
570 | if (isChecked) { | 572 | if (isChecked) { |
571 | [item setState:NSControlStateValueOn]; | 573 | [item setState:NSControlStateValueOn]; |
574 | selectedItem = item; | ||
572 | } | 575 | } |
573 | [item setEnabled:!isDisabled]; | 576 | [item setEnabled:!isDisabled]; |
574 | int key = items[i].key; | 577 | int key = items[i].key; |
@@ -586,6 +589,7 @@ static void makeMenuItems_(NSMenu *menu, MenuCommands *commands, const iMenuItem | |||
586 | setShortcut_NSMenuItem_(item, key, kmods); | 589 | setShortcut_NSMenuItem_(item, key, kmods); |
587 | } | 590 | } |
588 | } | 591 | } |
592 | return selectedItem; | ||
589 | } | 593 | } |
590 | 594 | ||
591 | void insertMenuItems_MacOS(const char *menuLabel, int atIndex, const iMenuItem *items, size_t count) { | 595 | void insertMenuItems_MacOS(const char *menuLabel, int atIndex, const iMenuItem *items, size_t count) { |
@@ -661,7 +665,7 @@ void showPopupMenu_MacOS(iWidget *source, iInt2 windowCoord, const iMenuItem *it | |||
661 | windowCoord.y = window->size.y - windowCoord.y; | 665 | windowCoord.y = window->size.y - windowCoord.y; |
662 | windowCoord = divf_I2(windowCoord, window->pixelRatio); | 666 | windowCoord = divf_I2(windowCoord, window->pixelRatio); |
663 | NSPoint screenPoint = [nsWindow convertPointToScreen:(CGPoint){ windowCoord.x, windowCoord.y }]; | 667 | NSPoint screenPoint = [nsWindow convertPointToScreen:(CGPoint){ windowCoord.x, windowCoord.y }]; |
664 | makeMenuItems_(menu, menuCommands, items, n); | 668 | NSMenuItem *selectedItem = makeMenuItems_(menu, menuCommands, items, n); |
665 | [menuCommands setSource:source]; | 669 | [menuCommands setSource:source]; |
666 | if (isCentered) { | 670 | if (isCentered) { |
667 | NSSize menuSize = [menu size]; | 671 | NSSize menuSize = [menu size]; |
@@ -669,7 +673,7 @@ void showPopupMenu_MacOS(iWidget *source, iInt2 windowCoord, const iMenuItem *it | |||
669 | screenPoint.y += menuSize.height / 2; | 673 | screenPoint.y += menuSize.height / 2; |
670 | } | 674 | } |
671 | [menu setAutoenablesItems:NO]; | 675 | [menu setAutoenablesItems:NO]; |
672 | [menu popUpMenuPositioningItem:nil atLocation:screenPoint inView:nil]; | 676 | [menu popUpMenuPositioningItem:selectedItem atLocation:screenPoint inView:nil]; |
673 | [menu release]; | 677 | [menu release]; |
674 | [menuCommands release]; | 678 | [menuCommands release]; |
675 | /* The right mouse button has now been released so let SDL know about it. The button up event | 679 | /* The right mouse button has now been released so let SDL know about it. The button up event |