Is MessageBoxOptions::withAssociatedComponent does something?

I try to use MessageBoxOptions::withAssociatedComponent to put the native dialog onto the document closed without any success. The dialog remains at the same position on screen. Is it supposed to work on macOS (BigSur)?

void PatchHolder::showSaveRequest (const std::shared_ptr<Patch>& p)
{
    const juce::MessageBoxOptions options (juce::MessageBoxOptions().withTitle (p->getFile().getFileName())
            .withAssociatedComponent (p->getMainWindow())
            .withMessage (NEEDS_TRANS ("Save the patch before closing?"))
            .withButton (NEEDS_TRANS ("Yes"))
            .withButton (NEEDS_TRANS ("No")));
    
    auto f = [u = p->getUnique()] (int result)
    {
        const bool save = (result == 0); Spaghettis()->getPatches().handleSaveRequest (u, save);
    };
    
    juce::NativeMessageBox::showAsync (options, f);
    
    requests_.push_back (p);
}

The doc says that it might be used for positioning the windows “depending on the look and feel”.
It’s true that I would expect the default L&F to position it correctly, but maybe it’s worth stepping in the stack to see if it at least tries to?

1 Like

I’ll have a look later in the JUCE’s code to see what’s happen.

Just wanted to save some time avoiding to go that way. :wink:

1 Like

It has no effect on macOS. Also only the warning icon is supported (there are no other possibilities in macOS). Maybe worth to mention it in the docs? From juce_mac_Windowing.mm:

    NSInteger getRawResult() const
    {
        NSAlert* alert = [[[NSAlert alloc] init] autorelease];

        [alert setMessageText:     juceStringToNS (options.getTitle())];
        [alert setInformativeText: juceStringToNS (options.getMessage())];

        [alert setAlertStyle: options.getIconType() == MessageBoxIconType::WarningIcon ? NSAlertStyleCritical
                                                                                       : NSAlertStyleInformational];

        const auto button1Text = options.getButtonText (0);

        addButton (alert, button1Text.isEmpty() ? "OK" : button1Text);
        addButton (alert, options.getButtonText (1));
        addButton (alert, options.getButtonText (2));

        return [alert runModal];
    }
1 Like

Good to know.

Is this something planned to be implemented?

It has be done there but surprisingly it is not handled in NativeMessageBox::showYesNoBox also.