| Flutter macOS Embedder |

Classes | Functions | Variables
FlutterMenuPlugin.mm File Reference
`#import "FlutterMenuPlugin.h"`
`#include <map>`
`#import "flutter/shell/platform/common/platform_provided_menu.h"`
`#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h"`
`#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterCodecs.h"`

Go to the source code of this file.

## Classes
class | FlutterMenuDelegate

## Functions
static NSDictionary< NSNumber *, NSNumber * > * | GetMacOsSpecialKeys ()
static const std::map< flutter::PlatformProvidedMenu, SEL > | GetMacOSProvidedMenus ()
static NSEventModifierFlags | KeyEquivalentModifierMaskForModifiers (NSNumber *modifiers)

## Variables
static NSString *const | kChannelName = @"@"flutter/menu"
static NSString *const | kIsPluginAvailableMethod = @"@"Menu.isPluginAvailable"
static NSString *const | kMenuSetMenusMethod = @"@"Menu.setMenus"
static NSString *const | kMenuSelectedCallbackMethod = @"@"Menu.selectedCallback"
static NSString *const | kMenuOpenedMethod = @"@"Menu.opened"
static NSString *const | kMenuClosedMethod = @"@"Menu.closed"
static NSString *const | kIdKey = @"@"id"
static NSString *const | kLabelKey = @"@"label"
static NSString *const | kTooltipKey = @"@"tooltip"
static NSString *const | kEnabledKey = @"@"enabled"
static NSString *const | kChildrenKey = @"@"children"
static NSString *const | kDividerKey = @"@"isDivider"
static NSString *const | kShortcutCharacterKey = @"@"shortcutCharacter"
static NSString *const | kShortcutTriggerKey = @"@"shortcutTrigger"
static NSString *const | kShortcutModifiersKey = @"@"shortcutModifiers"
static NSString *const | kPlatformProvidedMenuKey = @"@"platformProvidedMenu"
constexpr int | kFlutterShortcutModifierMeta = 1 << 0
constexpr int | kFlutterShortcutModifierShift = 1 << 1
constexpr int | kFlutterShortcutModifierAlt = 1 << 2
constexpr int | kFlutterShortcutModifierControl = 1 << 3
constexpr uint64_t | kFlutterKeyIdPlaneMask = 0xff00000000l
constexpr uint64_t | kFlutterKeyIdUnicodePlane = 0x0000000000l
constexpr uint64_t | kFlutterKeyIdValueMask = 0x00ffffffffl
static const NSDictionary * | logicalKeyToKeyCode = {}
static NSString *const | kAppName = @"@"APP_NAME"
int64_t | _identifier
NSArray< NSMenuItem * > * | _platformProvidedItems
NSMutableArray< FlutterMenuDelegate * > * | _menuDelegates

## Function Documentation

## ◆ GetMacOSProvidedMenus()

static const std::map<flutter::PlatformProvidedMenu, SEL> GetMacOSProvidedMenus | ( |  | ) |
| static

The mapping from the PlatformProvidedMenu enum to the macOS selectors for the provided menus.

Definition at line 112 of file FlutterMenuPlugin.mm.

112 {
113 return {
114 {flutter::PlatformProvidedMenu::kAbout, @selector(orderFrontStandardAboutPanel:)},
115 {flutter::PlatformProvidedMenu::kQuit, @selector(terminate:)},
116 // servicesSubmenu is handled specially below: it is assumed to be the first
117 // submenu in the preserved platform provided menus, since it doesn't have a
118 // definitive selector like the rest.
119 {flutter::PlatformProvidedMenu::kServicesSubmenu, @selector(submenuAction:)},
120 {flutter::PlatformProvidedMenu::kHide, @selector(hide:)},
121 {flutter::PlatformProvidedMenu::kHideOtherApplications, @selector(hideOtherApplications:)},
122 {flutter::PlatformProvidedMenu::kShowAllApplications, @selector(unhideAllApplications:)},
123 {flutter::PlatformProvidedMenu::kStartSpeaking, @selector(startSpeaking:)},
124 {flutter::PlatformProvidedMenu::kStopSpeaking, @selector(stopSpeaking:)},
125 {flutter::PlatformProvidedMenu::kToggleFullScreen, @selector(toggleFullScreen:)},
126 {flutter::PlatformProvidedMenu::kMinimizeWindow, @selector(performMiniaturize:)},
127 {flutter::PlatformProvidedMenu::kZoomWindow, @selector(performZoom:)},
128 {flutter::PlatformProvidedMenu::kArrangeWindowsInFront, @selector(arrangeInFront:)},
129 };
130 }
flutter::PlatformProvidedMenu::kQuit
@ kQuit
flutter::PlatformProvidedMenu::kMinimizeWindow
@ kMinimizeWindow
flutter::PlatformProvidedMenu::kArrangeWindowsInFront
@ kArrangeWindowsInFront
flutter::PlatformProvidedMenu::kHide
@ kHide
flutter::PlatformProvidedMenu::kAbout
@ kAbout
flutter::PlatformProvidedMenu::kHideOtherApplications
@ kHideOtherApplications
flutter::PlatformProvidedMenu::kServicesSubmenu
@ kServicesSubmenu
flutter::PlatformProvidedMenu::kToggleFullScreen
@ kToggleFullScreen
flutter::PlatformProvidedMenu::kStartSpeaking
@ kStartSpeaking
flutter::PlatformProvidedMenu::kStopSpeaking
@ kStopSpeaking
flutter::PlatformProvidedMenu::kShowAllApplications
@ kShowAllApplications
flutter::PlatformProvidedMenu::kZoomWindow
@ kZoomWindow

References flutter::kAbout, flutter::kArrangeWindowsInFront, flutter::kHide, flutter::kHideOtherApplications, flutter::kMinimizeWindow, flutter::kQuit, flutter::kServicesSubmenu, flutter::kShowAllApplications, flutter::kStartSpeaking, flutter::kStopSpeaking, flutter::kToggleFullScreen, and flutter::kZoomWindow.

## ◆ GetMacOsSpecialKeys()

static NSDictionary<NSNumber*, NSNumber*>* GetMacOsSpecialKeys | ( |  | ) |
| static

Maps the string used by NSMenuItem for the given special key equivalent. Keys are the logical key ids of matching trigger keys.

Definition at line 64 of file FlutterMenuPlugin.mm.

64 {
65 return @{
66 @0x00100000008 : [NSNumber numberWithInt:NSBackspaceCharacter],
67 @0x00100000009 : [NSNumber numberWithInt:NSTabCharacter],
68 @0x0010000000a : [NSNumber numberWithInt:NSNewlineCharacter],
69 @0x0010000000c : [NSNumber numberWithInt:NSFormFeedCharacter],
70 @0x0010000000d : [NSNumber numberWithInt:NSCarriageReturnCharacter],
71 @0x0010000007f : [NSNumber numberWithInt:NSDeleteCharacter],
72 @0x00100000801 : [NSNumber numberWithInt:NSF1FunctionKey],
73 @0x00100000802 : [NSNumber numberWithInt:NSF2FunctionKey],
74 @0x00100000803 : [NSNumber numberWithInt:NSF3FunctionKey],
75 @0x00100000804 : [NSNumber numberWithInt:NSF4FunctionKey],
76 @0x00100000805 : [NSNumber numberWithInt:NSF5FunctionKey],
77 @0x00100000806 : [NSNumber numberWithInt:NSF6FunctionKey],
78 @0x00100000807 : [NSNumber numberWithInt:NSF7FunctionKey],
79 @0x00100000808 : [NSNumber numberWithInt:NSF8FunctionKey],
80 @0x00100000809 : [NSNumber numberWithInt:NSF9FunctionKey],
81 @0x0010000080a : [NSNumber numberWithInt:NSF10FunctionKey],
82 @0x0010000080b : [NSNumber numberWithInt:NSF11FunctionKey],
83 @0x0010000080c : [NSNumber numberWithInt:NSF12FunctionKey],
84 @0x0010000080d : [NSNumber numberWithInt:NSF13FunctionKey],
85 @0x0010000080e : [NSNumber numberWithInt:NSF14FunctionKey],
86 @0x0010000080f : [NSNumber numberWithInt:NSF15FunctionKey],
87 @0x00100000810 : [NSNumber numberWithInt:NSF16FunctionKey],
88 @0x00100000811 : [NSNumber numberWithInt:NSF17FunctionKey],
89 @0x00100000812 : [NSNumber numberWithInt:NSF18FunctionKey],
90 @0x00100000813 : [NSNumber numberWithInt:NSF19FunctionKey],
91 @0x00100000814 : [NSNumber numberWithInt:NSF20FunctionKey],
92
93 // For some reason, there don't appear to be constants for these in ObjC. In
94 // Swift, there is a class with static members for these: KeyEquivalent. The
95 // values below are taken from that (where they don't already appear above).
96 @0x00100000302 : @0xf702, // ArrowLeft
97 @0x00100000303 : @0xf703, // ArrowRight
98 @0x00100000304 : @0xf700, // ArrowUp
99 @0x00100000301 : @0xf701, // ArrowDown
100 @0x00100000306 : @0xf729, // Home
101 @0x00100000305 : @0xf72B, // End
102 @0x00100000308 : @0xf72c, // PageUp
103 @0x00100000307 : @0xf72d, // PageDown
104 @0x0010000001b : @0x001B, // Escape
105 };
106 }

## ◆ KeyEquivalentModifierMaskForModifiers()

static NSEventModifierFlags KeyEquivalentModifierMaskForModifiers | ( | NSNumber * | modifiers | ) |
| static

Returns the NSEventModifierFlags of |modifiers|, a value from kShortcutKeyModifiers.

Definition at line 136 of file FlutterMenuPlugin.mm.

136 {
137 int flutterModifierFlags = modifiers.intValue;
138 NSEventModifierFlags flags = 0;
139 if (flutterModifierFlags & kFlutterShortcutModifierMeta) {
140 flags |= NSEventModifierFlagCommand;
141 }
142 if (flutterModifierFlags & kFlutterShortcutModifierShift) {
143 flags |= NSEventModifierFlagShift;
144 }
145 if (flutterModifierFlags & kFlutterShortcutModifierAlt) {
146 flags |= NSEventModifierFlagOption;
147 }
148 if (flutterModifierFlags & kFlutterShortcutModifierControl) {
149 flags |= NSEventModifierFlagControl;
150 }
151 // There are also modifier flags for things like the function (Fn) key, but
152 // the framework doesn't support those.
153 return flags;
154 }

References kFlutterShortcutModifierAlt, kFlutterShortcutModifierControl, kFlutterShortcutModifierMeta, and kFlutterShortcutModifierShift.

## Variable Documentation

## ◆ _identifier

int64_t _identifier

Initial value:
{
FlutterMethodChannel* _channel
FlutterMethodChannel
Definition: FlutterChannels.h:221

Definition at line 172 of file FlutterMenuPlugin.mm.

## ◆ _menuDelegates

NSMutableArray<FlutterMenuDelegate*>* _menuDelegates

Definition at line 230 of file FlutterMenuPlugin.mm.

## ◆ _platformProvidedItems

NSArray<NSMenuItem*>* _platformProvidedItems

Initial value:
{
FlutterMethodChannel* _channel

Definition at line 226 of file FlutterMenuPlugin.mm.

## ◆ kAppName

NSString* const kAppName = @"@"APP_NAME"
| static

Definition at line 46 of file FlutterMenuPlugin.mm.

## ◆ kChannelName

NSString* const kChannelName = @"@"flutter/menu"
| static

Definition at line 14 of file FlutterMenuPlugin.mm.

## ◆ kChildrenKey

NSString* const kChildrenKey = @"@"children"
| static

Definition at line 26 of file FlutterMenuPlugin.mm.

## ◆ kDividerKey

NSString* const kDividerKey = @"@"isDivider"
| static

Definition at line 27 of file FlutterMenuPlugin.mm.

## ◆ kEnabledKey

NSString* const kEnabledKey = @"@"enabled"
| static

Definition at line 25 of file FlutterMenuPlugin.mm.

## ◆ kFlutterKeyIdPlaneMask

constexpr uint64_t kFlutterKeyIdPlaneMask = 0xff00000000l
| constexpr

Definition at line 39 of file FlutterMenuPlugin.mm.

## ◆ kFlutterKeyIdUnicodePlane

constexpr uint64_t kFlutterKeyIdUnicodePlane = 0x0000000000l
| constexpr

Definition at line 40 of file FlutterMenuPlugin.mm.

## ◆ kFlutterKeyIdValueMask

constexpr uint64_t kFlutterKeyIdValueMask = 0x00ffffffffl
| constexpr

Definition at line 41 of file FlutterMenuPlugin.mm.

## ◆ kFlutterShortcutModifierAlt

constexpr int kFlutterShortcutModifierAlt = 1 << 2
| constexpr

Definition at line 36 of file FlutterMenuPlugin.mm.

Referenced by KeyEquivalentModifierMaskForModifiers().

## ◆ kFlutterShortcutModifierControl

constexpr int kFlutterShortcutModifierControl = 1 << 3
| constexpr

Definition at line 37 of file FlutterMenuPlugin.mm.

Referenced by KeyEquivalentModifierMaskForModifiers().

## ◆ kFlutterShortcutModifierMeta

constexpr int kFlutterShortcutModifierMeta = 1 << 0
| constexpr

Definition at line 34 of file FlutterMenuPlugin.mm.

Referenced by KeyEquivalentModifierMaskForModifiers().

## ◆ kFlutterShortcutModifierShift

constexpr int kFlutterShortcutModifierShift = 1 << 1
| constexpr

Definition at line 35 of file FlutterMenuPlugin.mm.

Referenced by KeyEquivalentModifierMaskForModifiers().

## ◆ kIdKey

NSString* const kIdKey = @"@"id"
| static

Definition at line 22 of file FlutterMenuPlugin.mm.

## ◆ kIsPluginAvailableMethod

NSString* const kIsPluginAvailableMethod = @"@"Menu.isPluginAvailable"
| static

Definition at line 15 of file FlutterMenuPlugin.mm.

## ◆ kLabelKey

NSString* const kLabelKey = @"@"label"
| static

Definition at line 23 of file FlutterMenuPlugin.mm.

## ◆ kMenuClosedMethod

NSString* const kMenuClosedMethod = @"@"Menu.closed"
| static

Definition at line 19 of file FlutterMenuPlugin.mm.

## ◆ kMenuOpenedMethod

NSString* const kMenuOpenedMethod = @"@"Menu.opened"
| static

Definition at line 18 of file FlutterMenuPlugin.mm.

## ◆ kMenuSelectedCallbackMethod

NSString* const kMenuSelectedCallbackMethod = @"@"Menu.selectedCallback"
| static

Definition at line 17 of file FlutterMenuPlugin.mm.

## ◆ kMenuSetMenusMethod

NSString* const kMenuSetMenusMethod = @"@"Menu.setMenus"
| static

Definition at line 16 of file FlutterMenuPlugin.mm.

## ◆ kPlatformProvidedMenuKey

NSString* const kPlatformProvidedMenuKey = @"@"platformProvidedMenu"
| static

Definition at line 31 of file FlutterMenuPlugin.mm.

## ◆ kShortcutCharacterKey

NSString* const kShortcutCharacterKey = @"@"shortcutCharacter"
| static

Definition at line 28 of file FlutterMenuPlugin.mm.

## ◆ kShortcutModifiersKey

NSString* const kShortcutModifiersKey = @"@"shortcutModifiers"
| static

Definition at line 30 of file FlutterMenuPlugin.mm.

## ◆ kShortcutTriggerKey

NSString* const kShortcutTriggerKey = @"@"shortcutTrigger"
| static

Definition at line 29 of file FlutterMenuPlugin.mm.

## ◆ kTooltipKey

NSString* const kTooltipKey = @"@"tooltip"
| static

Definition at line 24 of file FlutterMenuPlugin.mm.

## ◆ logicalKeyToKeyCode

const NSDictionary* logicalKeyToKeyCode = {}
| static

Definition at line 43 of file FlutterMenuPlugin.mm.