mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
On OSX, made sure popup menus are dismissed when the main menu is opened.
This commit is contained in:
parent
7ce0bf15d3
commit
8a586adc8b
2 changed files with 25 additions and 2 deletions
|
|
@ -29,6 +29,9 @@ AppFocusChangeCallback appFocusChangeCallback = nullptr;
|
|||
typedef bool (*CheckEventBlockedByModalComps) (NSEvent*);
|
||||
CheckEventBlockedByModalComps isEventBlockedByModalComps = nullptr;
|
||||
|
||||
typedef void (*MenuTrackingBeganCallback)();
|
||||
MenuTrackingBeganCallback menuTrackingBeganCallback = nullptr;
|
||||
|
||||
//==============================================================================
|
||||
struct AppDelegate
|
||||
{
|
||||
|
|
@ -38,6 +41,11 @@ public:
|
|||
static AppDelegateClass cls;
|
||||
delegate = [cls.createInstance() init];
|
||||
|
||||
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
|
||||
|
||||
[center addObserver: delegate selector: @selector (trackingBegan:)
|
||||
name: NSMenuDidBeginTrackingNotification object: nil];
|
||||
|
||||
if (JUCEApplicationBase::isStandaloneApp())
|
||||
{
|
||||
[NSApp setDelegate: delegate];
|
||||
|
|
@ -49,8 +57,6 @@ public:
|
|||
}
|
||||
else
|
||||
{
|
||||
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
|
||||
|
||||
[center addObserver: delegate selector: @selector (applicationDidResignActive:)
|
||||
name: NSApplicationDidResignActiveNotification object: NSApp];
|
||||
|
||||
|
|
@ -104,6 +110,7 @@ private:
|
|||
addMethod (@selector (applicationDidResignActive:), applicationDidResignActive, "v@:@");
|
||||
addMethod (@selector (applicationWillUnhide:), applicationWillUnhide, "v@:@");
|
||||
addMethod (@selector (broadcastMessageCallback:), broadcastMessageCallback, "v@:@");
|
||||
addMethod (@selector (trackingBegan:), trackingBegan, "v@:@");
|
||||
addMethod (@selector (dummyMethod), dummyMethod, "v@:");
|
||||
|
||||
registerClass();
|
||||
|
|
@ -169,6 +176,12 @@ private:
|
|||
MessageManager::getInstance()->deliverBroadcastMessage (messageString);
|
||||
}
|
||||
|
||||
static void trackingBegan (id /*self*/, SEL, NSNotification*)
|
||||
{
|
||||
if (menuTrackingBeganCallback != nullptr)
|
||||
(*menuTrackingBeganCallback)();
|
||||
}
|
||||
|
||||
static void dummyMethod (id /*self*/, SEL) {} // (used as a way of running a dummy thread)
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -595,8 +595,18 @@ const PopupMenu* MenuBarModel::getMacExtraAppleItemsMenu()
|
|||
? JuceMainMenuHandler::instance->extraAppleMenuItems.get() : nullptr;
|
||||
}
|
||||
|
||||
typedef void (*MenuTrackingBeganCallback)();
|
||||
extern MenuTrackingBeganCallback menuTrackingBeganCallback;
|
||||
|
||||
static void mainMenuTrackingBegan()
|
||||
{
|
||||
PopupMenu::dismissAllActiveMenus();
|
||||
}
|
||||
|
||||
void juce_initialiseMacMainMenu()
|
||||
{
|
||||
menuTrackingBeganCallback = mainMenuTrackingBegan;
|
||||
|
||||
if (JuceMainMenuHandler::instance == nullptr)
|
||||
MainMenuHelpers::rebuildMainMenu (nullptr);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue