virtual bool IsModal() const = 0;
// show the dialog frame-modally (needs a parent), using app-modal
// dialogs on platforms that don't support it
- virtual bool ShowWindowModal () ;
+ virtual void ShowWindowModal () ;
virtual void SendWindowModalDialogEvent ( wxEventType type );
// Modal dialogs have a return code - usually the id of the last
// For now, same as Show(TRUE) but returns return code
virtual int ShowModal();
+
+ virtual void ShowWindowModal();
// may be called to terminate the dialog with the given return code
virtual void EndModal(int retCode);
// mac also takes command-period as cancel
virtual bool IsEscapeKey(const wxKeyEvent& event);
+ // needed for cleanup on the Cocoa side.
+ void EndWindowModal();
+
private:
void Init();
extern wxList wxModalDialogs;
+void wxDialog::EndWindowModal()
+{
+ // Nothing to do for now.
+}
+
+void wxDialog::ShowWindowModal()
+{
+ // If someone wants to add support for this to wxOSX Carbon, here would
+ // be the place to start: http://trac.wxwidgets.org/ticket/9459
+ // Unfortunately, supporting sheets in Carbon isn't as straightforward
+ // as with Cocoa, so it will probably take some tweaking.
+ wxDialogBase::ShowWindowModal();
+}
+
void wxDialog::DoShowModal()
{
wxCHECK_RET( !IsModal(), wxT("DoShowModal() called twice") );
extern wxList wxModalDialogs;
+void wxDialog::ShowWindowModal()
+{
+ wxTopLevelWindow* parent = static_cast<wxTopLevelWindow*>(wxGetTopLevelParent(GetParent()));
+
+ wxASSERT_MSG(parent, "ShowWindowModal requires the dialog to have a parent.");
+
+ NSWindow* parentWindow = parent->GetWXWindow();
+ NSWindow* theWindow = GetWXWindow();
+
+ wxASSERT_MSG([theWindow styleMask] & NSDocModalWindowMask, "Window must have DocModal mask set.");
+
+ [NSApp beginSheet: theWindow
+ modalForWindow: parentWindow
+ modalDelegate: theWindow
+ didEndSelector: nil
+ contextInfo: nil];
+}
+
+void wxDialog::EndWindowModal()
+{
+ [NSApp endSheet: GetWXWindow()];
+}
+
void wxDialog::DoShowModal()
{
wxCHECK_RET( !IsModal(), wxT("DoShowModal() called twice") );
SetReturnCode(retCode);
Show(false);
SetModal(false);
+ if (GetModality() == wxDIALOG_MODALITY_WINDOW_MODAL)
+ {
+ EndWindowModal(); // OS X implementation method for cleanup
+ SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED );
+ }
}