The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

670 lines
25KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. class JuceMainMenuHandler : private MenuBarModel::Listener,
  19. private DeletedAtShutdown
  20. {
  21. public:
  22. JuceMainMenuHandler()
  23. : currentModel (nullptr),
  24. lastUpdateTime (0),
  25. isOpen (false)
  26. {
  27. static JuceMenuCallbackClass cls;
  28. callback = [cls.createInstance() init];
  29. JuceMenuCallbackClass::setOwner (callback, this);
  30. }
  31. ~JuceMainMenuHandler()
  32. {
  33. setMenu (nullptr, nullptr, String::empty);
  34. jassert (instance == this);
  35. instance = nullptr;
  36. [callback release];
  37. }
  38. void setMenu (MenuBarModel* const newMenuBarModel,
  39. const PopupMenu* newExtraAppleMenuItems,
  40. const String& recentItemsName)
  41. {
  42. recentItemsMenuName = recentItemsName;
  43. if (currentModel != newMenuBarModel)
  44. {
  45. if (currentModel != nullptr)
  46. currentModel->removeListener (this);
  47. currentModel = newMenuBarModel;
  48. if (currentModel != nullptr)
  49. currentModel->addListener (this);
  50. menuBarItemsChanged (nullptr);
  51. }
  52. extraAppleMenuItems = createCopyIfNotNull (newExtraAppleMenuItems);
  53. }
  54. void addTopLevelMenu (NSMenu* parent, const PopupMenu& child,
  55. const String& name, const int menuId, const int tag)
  56. {
  57. NSMenuItem* item = [parent addItemWithTitle: juceStringToNS (name)
  58. action: nil
  59. keyEquivalent: nsEmptyString()];
  60. [item setTag: tag];
  61. NSMenu* sub = createMenu (child, name, menuId, tag, true);
  62. [parent setSubmenu: sub forItem: item];
  63. [sub setAutoenablesItems: false];
  64. [sub release];
  65. }
  66. void updateTopLevelMenu (NSMenuItem* parentItem, const PopupMenu& menuToCopy,
  67. const String& name, const int menuId, const int tag)
  68. {
  69. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  70. static bool is10_4 = (SystemStats::getOperatingSystemType() == SystemStats::MacOSX_10_4);
  71. if (is10_4)
  72. {
  73. [parentItem setTag: tag];
  74. NSMenu* menu = [parentItem submenu];
  75. [menu setTitle: juceStringToNS (name)];
  76. while ([menu numberOfItems] > 0)
  77. [menu removeItemAtIndex: 0];
  78. for (PopupMenu::MenuItemIterator iter (menuToCopy); iter.next();)
  79. addMenuItem (iter, menu, menuId, tag);
  80. [menu setAutoenablesItems: false];
  81. [menu update];
  82. return;
  83. }
  84. #endif
  85. // Note: This method used to update the contents of the existing menu in-place, but that caused
  86. // weird side-effects which messed-up keyboard focus when switching between windows. By creating
  87. // a new menu and replacing the old one with it, that problem seems to be avoided..
  88. NSMenu* menu = [[NSMenu alloc] initWithTitle: juceStringToNS (name)];
  89. for (PopupMenu::MenuItemIterator iter (menuToCopy); iter.next();)
  90. addMenuItem (iter, menu, menuId, tag);
  91. [menu setAutoenablesItems: false];
  92. [menu update];
  93. [parentItem setTag: tag];
  94. [parentItem setSubmenu: menu];
  95. [menu release];
  96. }
  97. void menuBarItemsChanged (MenuBarModel*)
  98. {
  99. if (isOpen)
  100. return;
  101. lastUpdateTime = Time::getMillisecondCounter();
  102. StringArray menuNames;
  103. if (currentModel != nullptr)
  104. menuNames = currentModel->getMenuBarNames();
  105. NSMenu* menuBar = [NSApp mainMenu];
  106. while ([menuBar numberOfItems] > 1 + menuNames.size())
  107. [menuBar removeItemAtIndex: [menuBar numberOfItems] - 1];
  108. int menuId = 1;
  109. for (int i = 0; i < menuNames.size(); ++i)
  110. {
  111. const PopupMenu menu (currentModel->getMenuForIndex (i, menuNames [i]));
  112. if (i >= [menuBar numberOfItems] - 1)
  113. addTopLevelMenu (menuBar, menu, menuNames[i], menuId, i);
  114. else
  115. updateTopLevelMenu ([menuBar itemAtIndex: 1 + i], menu, menuNames[i], menuId, i);
  116. }
  117. }
  118. void menuCommandInvoked (MenuBarModel*, const ApplicationCommandTarget::InvocationInfo& info)
  119. {
  120. if (NSMenuItem* item = findMenuItem ([NSApp mainMenu], info))
  121. flashMenuBar ([item menu]);
  122. }
  123. void updateMenus (NSMenu* menu)
  124. {
  125. if (PopupMenu::dismissAllActiveMenus())
  126. {
  127. // If we were running a juce menu, then we should let that modal loop finish before allowing
  128. // the OS menus to start their own modal loop - so cancel the menu that was being opened..
  129. if ([menu respondsToSelector: @selector (cancelTracking)])
  130. [menu performSelector: @selector (cancelTracking)];
  131. }
  132. if (Time::getMillisecondCounter() > lastUpdateTime + 100)
  133. (new AsyncMenuUpdater())->post();
  134. }
  135. void invoke (const int commandId, ApplicationCommandManager* const commandManager, const int topLevelIndex) const
  136. {
  137. if (currentModel != nullptr)
  138. {
  139. if (commandManager != nullptr)
  140. {
  141. ApplicationCommandTarget::InvocationInfo info (commandId);
  142. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  143. commandManager->invoke (info, true);
  144. }
  145. (new AsyncCommandInvoker (commandId, topLevelIndex))->post();
  146. }
  147. }
  148. void invokeDirectly (const int commandId, const int topLevelIndex)
  149. {
  150. if (currentModel != nullptr)
  151. currentModel->menuItemSelected (commandId, topLevelIndex);
  152. }
  153. void addMenuItem (PopupMenu::MenuItemIterator& iter, NSMenu* menuToAddTo,
  154. const int topLevelMenuId, const int topLevelIndex)
  155. {
  156. NSString* text = juceStringToNS (iter.itemName.upToFirstOccurrenceOf ("<end>", false, true));
  157. if (text == nil)
  158. text = nsEmptyString();
  159. if (iter.isSeparator)
  160. {
  161. [menuToAddTo addItem: [NSMenuItem separatorItem]];
  162. }
  163. else if (iter.isSectionHeader)
  164. {
  165. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  166. action: nil
  167. keyEquivalent: nsEmptyString()];
  168. [item setEnabled: false];
  169. }
  170. else if (iter.subMenu != nullptr)
  171. {
  172. if (iter.itemName == recentItemsMenuName)
  173. {
  174. if (recent == nullptr)
  175. recent = new RecentFilesMenuItem();
  176. if (recent->recentItem != nil)
  177. {
  178. [menuToAddTo addItem: [recent->recentItem copyWithZone: nil]];
  179. return;
  180. }
  181. }
  182. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  183. action: nil
  184. keyEquivalent: nsEmptyString()];
  185. [item setTag: iter.itemId];
  186. [item setEnabled: iter.isEnabled];
  187. NSMenu* sub = createMenu (*iter.subMenu, iter.itemName, topLevelMenuId, topLevelIndex, false);
  188. [menuToAddTo setSubmenu: sub forItem: item];
  189. [sub release];
  190. }
  191. else
  192. {
  193. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  194. action: @selector (menuItemInvoked:)
  195. keyEquivalent: nsEmptyString()];
  196. [item setTag: iter.itemId];
  197. [item setEnabled: iter.isEnabled];
  198. [item setState: iter.isTicked ? NSOnState : NSOffState];
  199. [item setTarget: (id) callback];
  200. NSMutableArray* info = [NSMutableArray arrayWithObject: [NSNumber numberWithUnsignedLongLong: (pointer_sized_uint) (void*) iter.commandManager]];
  201. [info addObject: [NSNumber numberWithInt: topLevelIndex]];
  202. [item setRepresentedObject: info];
  203. if (iter.commandManager != nullptr)
  204. {
  205. const Array <KeyPress> keyPresses (iter.commandManager->getKeyMappings()
  206. ->getKeyPressesAssignedToCommand (iter.itemId));
  207. if (keyPresses.size() > 0)
  208. {
  209. const KeyPress& kp = keyPresses.getReference(0);
  210. if (kp != KeyPress::backspaceKey // (adding these is annoying because it flashes the menu bar
  211. && kp != KeyPress::deleteKey) // every time you press the key while editing text)
  212. {
  213. juce_wchar key = kp.getTextCharacter();
  214. if (key == 0)
  215. key = (juce_wchar) kp.getKeyCode();
  216. [item setKeyEquivalent: juceStringToNS (String::charToString (key).toLowerCase())];
  217. [item setKeyEquivalentModifierMask: juceModsToNSMods (kp.getModifiers())];
  218. }
  219. }
  220. }
  221. }
  222. }
  223. static JuceMainMenuHandler* instance;
  224. MenuBarModel* currentModel;
  225. ScopedPointer<PopupMenu> extraAppleMenuItems;
  226. uint32 lastUpdateTime;
  227. NSObject* callback;
  228. String recentItemsMenuName;
  229. bool isOpen;
  230. private:
  231. struct RecentFilesMenuItem
  232. {
  233. RecentFilesMenuItem() : recentItem (nil)
  234. {
  235. if (NSNib* menuNib = [[[NSNib alloc] initWithNibNamed: @"RecentFilesMenuTemplate" bundle: nil] autorelease])
  236. {
  237. NSArray* array = nil;
  238. [menuNib instantiateNibWithOwner: NSApp topLevelObjects: &array];
  239. for (id object in array)
  240. {
  241. if ([object isKindOfClass: [NSMenu class]])
  242. {
  243. if (NSArray* items = [object itemArray])
  244. {
  245. NSMenuItem* item = findRecentFilesItem (items);
  246. recentItem = [item retain];
  247. break;
  248. }
  249. }
  250. }
  251. }
  252. }
  253. ~RecentFilesMenuItem()
  254. {
  255. [recentItem release];
  256. }
  257. NSMenuItem* recentItem;
  258. private:
  259. static NSMenuItem* findRecentFilesItem (NSArray* const items)
  260. {
  261. for (id object in items)
  262. if (NSArray* subMenuItems = [[object submenu] itemArray])
  263. for (id subObject in subMenuItems)
  264. if ([subObject isKindOfClass: [NSMenuItem class]])
  265. return subObject;
  266. return nil;
  267. }
  268. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (RecentFilesMenuItem)
  269. };
  270. ScopedPointer<RecentFilesMenuItem> recent;
  271. //==============================================================================
  272. NSMenu* createMenu (const PopupMenu menu,
  273. const String& menuName,
  274. const int topLevelMenuId,
  275. const int topLevelIndex,
  276. const bool addDelegate)
  277. {
  278. NSMenu* m = [[NSMenu alloc] initWithTitle: juceStringToNS (menuName)];
  279. [m setAutoenablesItems: false];
  280. if (addDelegate)
  281. {
  282. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  283. [m setDelegate: (id<NSMenuDelegate>) callback];
  284. #else
  285. [m setDelegate: callback];
  286. #endif
  287. }
  288. for (PopupMenu::MenuItemIterator iter (menu); iter.next();)
  289. addMenuItem (iter, m, topLevelMenuId, topLevelIndex);
  290. [m update];
  291. return m;
  292. }
  293. static NSMenuItem* findMenuItem (NSMenu* const menu, const ApplicationCommandTarget::InvocationInfo& info)
  294. {
  295. for (NSInteger i = [menu numberOfItems]; --i >= 0;)
  296. {
  297. NSMenuItem* m = [menu itemAtIndex: i];
  298. if ([m tag] == info.commandID)
  299. return m;
  300. if (NSMenu* sub = [m submenu])
  301. if (NSMenuItem* found = findMenuItem (sub, info))
  302. return found;
  303. }
  304. return nil;
  305. }
  306. static void flashMenuBar (NSMenu* menu)
  307. {
  308. if ([[menu title] isEqualToString: nsStringLiteral ("Apple")])
  309. return;
  310. [menu retain];
  311. const unichar f35Key = NSF35FunctionKey;
  312. NSString* f35String = [NSString stringWithCharacters: &f35Key length: 1];
  313. NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: nsStringLiteral ("x")
  314. action: nil
  315. keyEquivalent: f35String];
  316. [item setTarget: nil];
  317. [menu insertItem: item atIndex: [menu numberOfItems]];
  318. [item release];
  319. if ([menu indexOfItem: item] >= 0)
  320. {
  321. NSEvent* f35Event = [NSEvent keyEventWithType: NSKeyDown
  322. location: NSZeroPoint
  323. modifierFlags: NSCommandKeyMask
  324. timestamp: 0
  325. windowNumber: 0
  326. context: [NSGraphicsContext currentContext]
  327. characters: f35String
  328. charactersIgnoringModifiers: f35String
  329. isARepeat: NO
  330. keyCode: 0];
  331. [menu performKeyEquivalent: f35Event];
  332. if ([menu indexOfItem: item] >= 0)
  333. [menu removeItem: item]; // (this throws if the item isn't actually in the menu)
  334. }
  335. [menu release];
  336. }
  337. static unsigned int juceModsToNSMods (const ModifierKeys& mods)
  338. {
  339. unsigned int m = 0;
  340. if (mods.isShiftDown()) m |= NSShiftKeyMask;
  341. if (mods.isCtrlDown()) m |= NSControlKeyMask;
  342. if (mods.isAltDown()) m |= NSAlternateKeyMask;
  343. if (mods.isCommandDown()) m |= NSCommandKeyMask;
  344. return m;
  345. }
  346. class AsyncMenuUpdater : public CallbackMessage
  347. {
  348. public:
  349. AsyncMenuUpdater() {}
  350. void messageCallback()
  351. {
  352. if (instance != nullptr)
  353. instance->menuBarItemsChanged (nullptr);
  354. }
  355. private:
  356. JUCE_DECLARE_NON_COPYABLE (AsyncMenuUpdater)
  357. };
  358. class AsyncCommandInvoker : public CallbackMessage
  359. {
  360. public:
  361. AsyncCommandInvoker (const int commandId_, const int topLevelIndex_)
  362. : commandId (commandId_), topLevelIndex (topLevelIndex_)
  363. {}
  364. void messageCallback()
  365. {
  366. if (instance != nullptr)
  367. instance->invokeDirectly (commandId, topLevelIndex);
  368. }
  369. private:
  370. const int commandId, topLevelIndex;
  371. JUCE_DECLARE_NON_COPYABLE (AsyncCommandInvoker)
  372. };
  373. //==============================================================================
  374. struct JuceMenuCallbackClass : public ObjCClass <NSObject>
  375. {
  376. JuceMenuCallbackClass() : ObjCClass <NSObject> ("JUCEMainMenu_")
  377. {
  378. addIvar<JuceMainMenuHandler*> ("owner");
  379. addMethod (@selector (menuItemInvoked:), menuItemInvoked, "v@:@");
  380. addMethod (@selector (menuNeedsUpdate:), menuNeedsUpdate, "v@:@");
  381. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  382. addProtocol (@protocol (NSMenuDelegate));
  383. #endif
  384. registerClass();
  385. }
  386. static void setOwner (id self, JuceMainMenuHandler* owner)
  387. {
  388. object_setInstanceVariable (self, "owner", owner);
  389. }
  390. private:
  391. static void menuItemInvoked (id self, SEL, NSMenuItem* item)
  392. {
  393. JuceMainMenuHandler* const owner = getIvar<JuceMainMenuHandler*> (self, "owner");
  394. if ([[item representedObject] isKindOfClass: [NSArray class]])
  395. {
  396. // If the menu is being triggered by a keypress, the OS will have picked it up before we had a chance to offer it to
  397. // our own components, which may have wanted to intercept it. So, rather than dispatching directly, we'll feed it back
  398. // into the focused component and let it trigger the menu item indirectly.
  399. NSEvent* e = [NSApp currentEvent];
  400. if ([e type] == NSKeyDown || [e type] == NSKeyUp)
  401. {
  402. if (juce::Component* focused = juce::Component::getCurrentlyFocusedComponent())
  403. {
  404. if (juce::NSViewComponentPeer* peer = dynamic_cast <juce::NSViewComponentPeer*> (focused->getPeer()))
  405. {
  406. if ([e type] == NSKeyDown)
  407. peer->redirectKeyDown (e);
  408. else
  409. peer->redirectKeyUp (e);
  410. return;
  411. }
  412. }
  413. }
  414. NSArray* info = (NSArray*) [item representedObject];
  415. owner->invoke ((int) [item tag],
  416. (ApplicationCommandManager*) (pointer_sized_int)
  417. [((NSNumber*) [info objectAtIndex: 0]) unsignedLongLongValue],
  418. (int) [((NSNumber*) [info objectAtIndex: 1]) intValue]);
  419. }
  420. }
  421. static void menuNeedsUpdate (id, SEL, NSMenu* menu)
  422. {
  423. if (instance != nullptr)
  424. instance->updateMenus (menu);
  425. }
  426. };
  427. };
  428. JuceMainMenuHandler* JuceMainMenuHandler::instance = nullptr;
  429. //==============================================================================
  430. namespace MainMenuHelpers
  431. {
  432. static NSString* translateMenuName (const String& name)
  433. {
  434. return NSLocalizedString (juceStringToNS (TRANS (name)), nil);
  435. }
  436. static NSMenuItem* createMenuItem (NSMenu* menu, const String& name, SEL sel, NSString* key)
  437. {
  438. NSMenuItem* item = [[[NSMenuItem alloc] initWithTitle: translateMenuName (name)
  439. action: sel
  440. keyEquivalent: key] autorelease];
  441. [item setTarget: NSApp];
  442. [menu addItem: item];
  443. return item;
  444. }
  445. static void createStandardAppMenu (NSMenu* menu, const String& appName, const PopupMenu* extraItems)
  446. {
  447. if (extraItems != nullptr && JuceMainMenuHandler::instance != nullptr && extraItems->getNumItems() > 0)
  448. {
  449. for (PopupMenu::MenuItemIterator iter (*extraItems); iter.next();)
  450. JuceMainMenuHandler::instance->addMenuItem (iter, menu, 0, -1);
  451. [menu addItem: [NSMenuItem separatorItem]];
  452. }
  453. // Services...
  454. NSMenuItem* services = [[[NSMenuItem alloc] initWithTitle: translateMenuName ("Services")
  455. action: nil keyEquivalent: nsEmptyString()] autorelease];
  456. [menu addItem: services];
  457. NSMenu* servicesMenu = [[[NSMenu alloc] initWithTitle: translateMenuName ("Services")] autorelease];
  458. [menu setSubmenu: servicesMenu forItem: services];
  459. [NSApp setServicesMenu: servicesMenu];
  460. [menu addItem: [NSMenuItem separatorItem]];
  461. createMenuItem (menu, "Hide " + appName, @selector (hide:), nsStringLiteral ("h"));
  462. [createMenuItem (menu, "Hide Others", @selector (hideOtherApplications:), nsStringLiteral ("h"))
  463. setKeyEquivalentModifierMask: NSCommandKeyMask | NSAlternateKeyMask];
  464. createMenuItem (menu, "Show All", @selector (unhideAllApplications:), nsEmptyString());
  465. [menu addItem: [NSMenuItem separatorItem]];
  466. createMenuItem (menu, "Quit " + appName, @selector (terminate:), nsStringLiteral ("q"));
  467. }
  468. // Since our app has no NIB, this initialises a standard app menu...
  469. static void rebuildMainMenu (const PopupMenu* extraItems)
  470. {
  471. // this can't be used in a plugin!
  472. jassert (JUCEApplication::isStandaloneApp());
  473. if (JUCEApplication* app = JUCEApplication::getInstance())
  474. {
  475. JUCE_AUTORELEASEPOOL
  476. NSMenu* mainMenu = [[NSMenu alloc] initWithTitle: nsStringLiteral ("MainMenu")];
  477. NSMenuItem* item = [mainMenu addItemWithTitle: nsStringLiteral ("Apple") action: nil keyEquivalent: nsEmptyString()];
  478. NSMenu* appMenu = [[NSMenu alloc] initWithTitle: nsStringLiteral ("Apple")];
  479. [NSApp performSelector: @selector (setAppleMenu:) withObject: appMenu];
  480. [mainMenu setSubmenu: appMenu forItem: item];
  481. [NSApp setMainMenu: mainMenu];
  482. MainMenuHelpers::createStandardAppMenu (appMenu, app->getApplicationName(), extraItems);
  483. [appMenu release];
  484. [mainMenu release];
  485. }
  486. }
  487. }
  488. void MenuBarModel::setMacMainMenu (MenuBarModel* newMenuBarModel,
  489. const PopupMenu* extraAppleMenuItems,
  490. const String& recentItemsMenuName)
  491. {
  492. if (getMacMainMenu() != newMenuBarModel)
  493. {
  494. JUCE_AUTORELEASEPOOL
  495. if (newMenuBarModel == nullptr)
  496. {
  497. delete JuceMainMenuHandler::instance;
  498. jassert (JuceMainMenuHandler::instance == nullptr); // should be zeroed in the destructor
  499. jassert (extraAppleMenuItems == nullptr); // you can't specify some extra items without also supplying a model
  500. extraAppleMenuItems = nullptr;
  501. }
  502. else
  503. {
  504. if (JuceMainMenuHandler::instance == nullptr)
  505. JuceMainMenuHandler::instance = new JuceMainMenuHandler();
  506. JuceMainMenuHandler::instance->setMenu (newMenuBarModel, extraAppleMenuItems, recentItemsMenuName);
  507. }
  508. }
  509. MainMenuHelpers::rebuildMainMenu (extraAppleMenuItems);
  510. if (newMenuBarModel != nullptr)
  511. newMenuBarModel->menuItemsChanged();
  512. }
  513. MenuBarModel* MenuBarModel::getMacMainMenu()
  514. {
  515. return JuceMainMenuHandler::instance != nullptr
  516. ? JuceMainMenuHandler::instance->currentModel : nullptr;
  517. }
  518. const PopupMenu* MenuBarModel::getMacExtraAppleItemsMenu()
  519. {
  520. return JuceMainMenuHandler::instance != nullptr
  521. ? JuceMainMenuHandler::instance->extraAppleMenuItems.get() : nullptr;
  522. }
  523. typedef void (*MenuTrackingChangedCallback) (bool);
  524. extern MenuTrackingChangedCallback menuTrackingChangedCallback;
  525. static void mainMenuTrackingChanged (bool isTracking)
  526. {
  527. PopupMenu::dismissAllActiveMenus();
  528. if (JuceMainMenuHandler::instance != nullptr)
  529. JuceMainMenuHandler::instance->isOpen = isTracking;
  530. }
  531. void juce_initialiseMacMainMenu()
  532. {
  533. menuTrackingChangedCallback = mainMenuTrackingChanged;
  534. if (JuceMainMenuHandler::instance == nullptr)
  535. MainMenuHelpers::rebuildMainMenu (nullptr);
  536. }