X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/bfa92264c07d094c05e5a07a17fd7f5bcee8e81f..6f3f38980f10a935f3b47dbf0d3b4643e96a4be2:/src/osx/dialog_osx.cpp diff --git a/src/osx/dialog_osx.cpp b/src/osx/dialog_osx.cpp index 1408ea0fb3..05da19bcc8 100644 --- a/src/osx/dialog_osx.cpp +++ b/src/osx/dialog_osx.cpp @@ -4,7 +4,7 @@ // Author: Stefan Csomor // Modified by: // Created: 1998-01-01 -// RCS-ID: $Id: dialog.cpp 54820 2008-07-29 20:04:11Z SC $ +// RCS-ID: $Id$ // Copyright: (c) Stefan Csomor // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -12,6 +12,7 @@ #include "wx/wxprec.h" #include "wx/dialog.h" +#include "wx/evtloop.h" #ifndef WX_PRECOMP #include "wx/app.h" @@ -22,17 +23,30 @@ #include "wx/osx/private.h" +static int s_openDialogs = 0; +bool wxDialog::OSXHasModalDialogsOpen() +{ + return s_openDialogs > 0; +} -// Lists to keep track of windows, so we can disable/enable them -// for modal dialogs +void wxDialog::OSXBeginModalDialog() +{ + s_openDialogs++; +} + +void wxDialog::OSXEndModalDialog() +{ + wxASSERT_MSG( s_openDialogs > 0, "incorrect internal modal dialog count"); + s_openDialogs--; +} -wxList wxModalDialogs; IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow) void wxDialog::Init() { m_modality = wxDIALOG_MODALITY_NONE; + m_eventLoop = NULL; } bool wxDialog::Create( wxWindow *parent, @@ -88,7 +102,7 @@ bool wxDialog::Show(bool show) // nothing to do return false; } - else + else { if ( !wxDialogBase::Show(show) ) // nothing to do @@ -108,14 +122,14 @@ bool wxDialog::Show(bool show) { case wxDIALOG_MODALITY_WINDOW_MODAL: EndWindowModal(); // OS X implementation method for cleanup - SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED ); + SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED ); break; default: break; } m_modality = wxDIALOG_MODALITY_NONE; } - + return true; } @@ -123,10 +137,17 @@ bool wxDialog::Show(bool show) int wxDialog::ShowModal() { m_modality = wxDIALOG_MODALITY_APP_MODAL; - + Show(); - DoShowModal(); + wxModalEventLoop modalLoop(this); + m_eventLoop = &modalLoop; + + wxDialog::OSXBeginModalDialog(); + modalLoop.Run(); + wxDialog::OSXEndModalDialog(); + + m_eventLoop = NULL; return GetReturnCode(); } @@ -134,9 +155,9 @@ int wxDialog::ShowModal() void wxDialog::ShowWindowModal() { m_modality = wxDIALOG_MODALITY_WINDOW_MODAL; - + Show(); - + DoShowWindowModal(); } @@ -149,6 +170,9 @@ wxDialogModality wxDialog::GetModality() const // dialogs and should work for both of them void wxDialog::EndModal(int retCode) { + if ( m_eventLoop ) + m_eventLoop->Exit(retCode); + SetReturnCode(retCode); Show(false); }