summaryrefslogtreecommitdiff
path: root/src/macos.m
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-09-21 14:09:29 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-09-21 14:09:29 +0300
commit2ed9d1bbd3b92b8d39a368963c3fd5d0fbcdc974 (patch)
tree2221cdb8f6337830ed8ffed81b8b76368fa167db /src/macos.m
parentcb7795c12a40b2c8f749d9848276f58199819799 (diff)
Disabling items in native menus
Added the special prefix `///` to mark items disabled.
Diffstat (limited to 'src/macos.m')
-rw-r--r--src/macos.m17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/macos.m b/src/macos.m
index d9ee71e7..24c83aec 100644
--- a/src/macos.m
+++ b/src/macos.m
@@ -553,10 +553,15 @@ static void makeMenuItems_(NSMenu *menu, MenuCommands *commands, const iMenuItem
553 else { 553 else {
554 const iBool hasCommand = (items[i].command && items[i].command[0]); 554 const iBool hasCommand = (items[i].command && items[i].command[0]);
555 iBool isChecked = iFalse; 555 iBool isChecked = iFalse;
556 iBool isDisabled = iFalse;
556 if (startsWith_CStr(label, "###")) { 557 if (startsWith_CStr(label, "###")) {
557 isChecked = iTrue; 558 isChecked = iTrue;
558 label += 3; 559 label += 3;
559 } 560 }
561 else if (startsWith_CStr(label, "///")) {
562 isDisabled = iTrue;
563 label += 3;
564 }
560 iString itemTitle; 565 iString itemTitle;
561 initCStr_String(&itemTitle, label); 566 initCStr_String(&itemTitle, label);
562 removeIconPrefix_String(&itemTitle); 567 removeIconPrefix_String(&itemTitle);
@@ -571,6 +576,7 @@ static void makeMenuItems_(NSMenu *menu, MenuCommands *commands, const iMenuItem
571 if (isChecked) { 576 if (isChecked) {
572 [item setState:NSControlStateValueOn]; 577 [item setState:NSControlStateValueOn];
573 } 578 }
579 [item setEnabled:!isDisabled];
574 int key = items[i].key; 580 int key = items[i].key;
575 int kmods = items[i].kmods; 581 int kmods = items[i].kmods;
576 if (hasCommand) { 582 if (hasCommand) {
@@ -653,11 +659,22 @@ void showPopupMenu_MacOS(iWidget *source, iInt2 windowCoord, const iMenuItem *it
653 iWindow * window = as_Window(mainWindow_App()); 659 iWindow * window = as_Window(mainWindow_App());
654 NSWindow * nsWindow = nsWindow_(window->win); 660 NSWindow * nsWindow = nsWindow_(window->win);
655 /* View coordinates are flipped. */ 661 /* View coordinates are flipped. */
662 iBool isCentered = iFalse;
663 if (isEqual_I2(windowCoord, zero_I2())) {
664 windowCoord = divi_I2(window->size, 2);
665 isCentered = iTrue;
666 }
656 windowCoord.y = window->size.y - windowCoord.y; 667 windowCoord.y = window->size.y - windowCoord.y;
657 windowCoord = divf_I2(windowCoord, window->pixelRatio); 668 windowCoord = divf_I2(windowCoord, window->pixelRatio);
658 NSPoint screenPoint = [nsWindow convertPointToScreen:(CGPoint){ windowCoord.x, windowCoord.y }]; 669 NSPoint screenPoint = [nsWindow convertPointToScreen:(CGPoint){ windowCoord.x, windowCoord.y }];
659 makeMenuItems_(menu, menuCommands, items, n); 670 makeMenuItems_(menu, menuCommands, items, n);
660 [menuCommands setSource:source]; 671 [menuCommands setSource:source];
672 if (isCentered) {
673 NSSize menuSize = [menu size];
674 screenPoint.x -= menuSize.width / 2;
675 screenPoint.y += menuSize.height / 2;
676 }
677 [menu setAutoenablesItems:NO];
661 [menu popUpMenuPositioningItem:nil atLocation:screenPoint inView:nil]; 678 [menu popUpMenuPositioningItem:nil atLocation:screenPoint inView:nil];
662 [menu release]; 679 [menu release];
663 [menuCommands release]; 680 [menuCommands release];