Modal dialog question

My main window is creating a dialog window, and showing it using
myDialog.runModalLoop()

This dialog doesn’t close on exitModalState(). This, it turns out, is because IsCurrentlyModal() is false when I call exitModalState().

So, there’s something I’m missing about running a dialog. Why doesn’t runModalLoop() put me in a modal state automatically?

That does put it in a modal state. Is there something else that became modal after it was created?

I’m still not sure what’s happening. I don’t believe anything else is becoming modal after the creation of this dialog. What I know is that the currentlyModalFlag is being set in the call to runModalLoop(), but that by the time the OK button in my dialog is clicked, the dialog is no longer considered modal.

I’m going to post the calling code, which I think I stole from a juce example:

CWarningDialog		theDialogPane;
theDialogPane.centreWithSize(350,100);

DialogWindow theDialog (T("My dialog"),  Colours::white, false);

theDialog.setContentComponent (&theDialogPane, true, true);
theDialog.centreAroundComponent (NULL, theDialog.getWidth(), theDialog.getHeight());
theDialog.setResizable (false, false);
theDialog.toFront(true);
theDialog.runModalLoop();
theDialog.setContentComponent (0, false);

I put breakpoints on the Component::enterModalState(), which is the only place I thought the currentlyModalFlag could be set, but it doesn’t get hit by any other component.

Ah. Duh. I got it. I put the window in a modal state, but am trying to do the exitModalState() from the window’s content component.

Thanks for the posts–they enabled me to quickly solve a similar problem using DialogWindow::showModalDialog. Since this is a static function, the dialog needs to be controlled by the component passed in to the second argument. To exit, call getParentComponent()->exitModalState(result). The documentation for modal loop methods is in the Component class documentation and it’s not completely clear (at least to this non-gui programmer) which component’s methods should be called. I think an added sentence or two to the showModalDialog method documentation would clear it up. For example, in the documentation to contentComponent (the second argument to showModalDialog), you could append the following sentence: “To close the dialog from the content component, call getParentComponent()->exitModalState(result) where result is the value you wish showModalDialog to return.”

Ok, I’ll add some clarification there. Thanks!

BTW, getParent() is making a bit of an assumption about the hierarchy, which may change in future. Better to use findParentComponentOfClass().