Using Juce with Adobe AE plug-in - Event handling issues


I've been trying to use Juce in an AE plug-in primarily to create a Modal (I know, I know  it's bad, but more on that later) window in OS X, but I'm running into the following issues.

1. runModal() is not truly modal:

Whenever I create a new Dialog Window with the following code, the resultant window isn't truly modal. The Menubar is still active and any keyboard shortcuts (like Cmd-C/Cmd-V) are still applied to the host window in the background. When I select the label and edit it, only Cmd-V works, that too I'm assuming only because the paste stack is empty/greyed out in the menu bar before starting the window.


     NSWindow* mainWindow = [[NSApplication sharedApplication] keyWindow];

    DialogWindow::LaunchOptions launch_optns;

    launch_optns.dialogTitle  = "Test Window";

    launch_optns.dialogBackgroundColour = Colour(128,128,128);

    launch_optns.content.setOwned(new MainComponent);

    launch_optns.content->setSize(640, 480);

    launch_optns.content->addToDesktop(0,[mainWindow contentView]);


Also, interestingly launchAsync() has the exact similar problem even though now mouse events are no longer blocked. 

2. Force Modal:

Now, after a bit of tinkering, I've made the Juce window 'key' using some Cocoa code and this time forcibly making it Modal in Cocoa.

DialogWindow* mdlDlg =  launch_optns.launchAsync();

    NSWindow* modWin = [(NSView*)mdlDlg->getWindowHandle() window];

    [modWin setParentWindow:mainWindow];

    [modWin makeKeyAndOrderFront:nil];

[NSApp runModalForWindow:modWin];

Now, the modal part is achieved successfully, but none of the keyboard shortcuts work. I can type letters in the label form, but can't copy/cut/paste in it.

So I'm wondering what is the solution for this problem? Juce seems to handle plug-in bundles quite effectively, so not sure what's the issue here. It would be really cool if someone could help to get this working, since I'm really interested to use Juce in my main projects!

Thank you!

P.S: Why Modal? Right now the AE SDK is very limited and modal windows are the only way to go, if one wanst to prevent render calls during active UI changes, AFAIK.


Looks like I might have found a solution. Turns out its rather simple thanks to the NSViewComponent class. Instead of subclassing from a regular "Component" class, I've subclassed my main component from NSViewComponent. Then, subclass NSView and override ":performKeyEquivalent" method, which apparently handles events with modifier keys. Set the view and it's good to go.

Here is the code snippet:

@interface CustomView : NSView

- (BOOL)performKeyEquivalent:(NSEvent *)event;


@implementation CustomView

- (BOOL)performKeyEquivalent:(NSEvent *)event {

    [super keyDown:event];

    return  YES;


class MainComponent  : public juce::NSViewComponent



    MainComponent ();




NSRect frameRect    = NSMakeRect(100, 100 , 256, 256);

    CustomView* tmpView     = [[CustomView alloc] initWithFrame:frameRect];

    DialogWindow::LaunchOptions launch_optns;

    launch_optns.dialogTitle  = "Test Window";

    launch_optns.dialogBackgroundColour = Colour(128,128,128);

    MainComponent* mnC = new MainComponent;

    mnC->setView(tmpView); //IMPORTANT

Thanks and hopefully someone will find it useful.

1 Like

Very useful indeed; I’m making Premiere plugins (same restrictions on having to use true modal dialogs) and also faced copy/paste not working. Your code solved it for me in 2019 with Juce version 5.3.2 - thanks!

As a suggestion to the Juce team: I know true (app-)modal dialogs are not really on Juce’s roadmap and are thus not fully supported, but such a small fix as this goes a long way for when people do need it!