1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-16 00:34:19 +00:00

Added an OSX-only method SystemTrayIconComponent::showDropdownMenu() and tweaked the highlighting of OSX tray icons.

This commit is contained in:
jules 2015-07-28 15:44:38 +01:00
parent 16fa0e8ad9
commit 969f1a25fc
2 changed files with 36 additions and 5 deletions

View file

@ -84,6 +84,11 @@ public:
void paint (Graphics&) override;
#endif
#if JUCE_MAC
/** Shows a menu attached to the OSX menu bar icon. */
void showDropdownMenu (const PopupMenu& menu);
#endif
private:
//==============================================================================
JUCE_PUBLIC_IN_DLL_BUILD (class Pimpl)

View file

@ -27,13 +27,16 @@ namespace MouseCursorHelpers
extern NSImage* createNSImage (const Image&);
}
class SystemTrayIconComponent::Pimpl
extern NSMenu* createNSMenu (const PopupMenu&, const String& name, int topLevelMenuId,
int topLevelIndex, bool addDelegate);
class SystemTrayIconComponent::Pimpl : private Timer
{
public:
Pimpl (SystemTrayIconComponent& iconComp, const Image& im)
: owner (iconComp), statusItem (nil),
statusIcon (MouseCursorHelpers::createNSImage (im)),
isHighlighted (false)
view (nil), isHighlighted (false)
{
static SystemTrayViewClass cls;
view = [cls.createInstance() init];
@ -104,6 +107,9 @@ public:
if (isLeft || isRight) // Only mouse up is sent by the OS, so simulate a down/up
{
setHighlighted (true);
startTimer (150);
owner.mouseDown (MouseEvent (mouseSource, Point<float>(),
eventMods.withFlags (isLeft ? ModifierKeys::leftButtonModifier
: ModifierKeys::rightButtonModifier),
@ -123,6 +129,17 @@ public:
}
}
void showMenu (const PopupMenu& menu)
{
if (NSMenu* m = createNSMenu (menu, "MenuBarItem", -2, -3, true))
{
setHighlighted (true);
stopTimer();
[statusItem popUpStatusItemMenu: m];
startTimer (1);
}
}
SystemTrayIconComponent& owner;
NSStatusItem* statusItem;
@ -136,6 +153,12 @@ private:
[statusIcon setSize: NSMakeSize (20.0f, 20.0f)];
}
void timerCallback() override
{
stopTimer();
setHighlighted (false);
}
struct SystemTrayViewClass : public ObjCClass<NSControl>
{
SystemTrayViewClass() : ObjCClass<NSControl> ("JUCESystemTrayView_")
@ -171,10 +194,7 @@ private:
static void handleEventDown (id self, SEL, NSEvent* e)
{
if (Pimpl* const owner = getOwner (self))
{
owner->setHighlighted (! owner->isHighlighted);
owner->handleStatusItemAction (e);
}
}
static void drawRect (id self, SEL, NSRect)
@ -244,3 +264,9 @@ void* SystemTrayIconComponent::getNativeHandle() const
{
return pimpl != nullptr ? pimpl->statusItem : nullptr;
}
void SystemTrayIconComponent::showDropdownMenu (const PopupMenu& menu)
{
if (pimpl != nullptr)
pimpl->showMenu (menu);
}