X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3ccc5735bfb404f46639d417c613ff77f413c612..7c60222510bc5e197b12f153c4bf05db66cb0f4a:/src/osx/dialog_osx.cpp diff --git a/src/osx/dialog_osx.cpp b/src/osx/dialog_osx.cpp index fabbf00687..cb127f323b 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,8 @@ #include "wx/wxprec.h" #include "wx/dialog.h" +#include "wx/evtloop.h" +#include "wx/modalhook.h" #ifndef WX_PRECOMP #include "wx/app.h" @@ -22,17 +24,27 @@ #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 - -wxList wxModalDialogs; +void wxDialog::OSXBeginModalDialog() +{ + s_openDialogs++; +} -IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow) +void wxDialog::OSXEndModalDialog() +{ + wxASSERT_MSG( s_openDialogs > 0, "incorrect internal modal dialog count"); + s_openDialogs--; +} void wxDialog::Init() { - m_isModalStyle = false; + m_modality = wxDIALOG_MODALITY_NONE; + m_eventLoop = NULL; } bool wxDialog::Create( wxWindow *parent, @@ -57,21 +69,9 @@ bool wxDialog::Create( wxWindow *parent, return true; } -void wxDialog::SetModal( bool flag ) -{ - if ( flag ) - { - m_isModalStyle = true; - } - else - { - m_isModalStyle = false; - } -} - wxDialog::~wxDialog() { - m_isBeingDeleted = true; + SendDestroyEvent(); // if the dialog is modal, this will end its event loop Show(false); @@ -81,7 +81,7 @@ wxDialog::~wxDialog() // about it bool wxDialog::IsEscapeKey(const wxKeyEvent& event) { - if ( event.GetKeyCode() == '.' && event.GetModifiers() == wxMOD_CMD ) + if ( event.GetKeyCode() == '.' && event.GetModifiers() == wxMOD_CONTROL ) return true; return wxDialogBase::IsEscapeKey(event); @@ -89,16 +89,23 @@ bool wxDialog::IsEscapeKey(const wxKeyEvent& event) bool wxDialog::IsModal() const { - return wxModalDialogs.Find((wxDialog *)this) != NULL; // const_cast - // return m_isModalStyle; + return m_modality != wxDIALOG_MODALITY_NONE; } - bool wxDialog::Show(bool show) { - if ( !wxDialogBase::Show(show) ) - // nothing to do - return false; + if ( m_modality == wxDIALOG_MODALITY_WINDOW_MODAL ) + { + if ( !wxWindow::Show(show) ) + // nothing to do + return false; + } + else + { + if ( !wxDialogBase::Show(show) ) + // nothing to do + return false; + } if (show && CanDoLayoutAdaptation()) DoLayoutAdaptation(); @@ -107,17 +114,21 @@ bool wxDialog::Show(bool show) // usually will result in TransferDataToWindow() being called InitDialog(); - if ( m_isModalStyle ) + if ( !show ) { - if ( show ) - { - DoShowModal(); - } - else // end of modal dialog + const int modalityOrig = m_modality; + + // complete the 'hiding' before we send the event + m_modality = wxDIALOG_MODALITY_NONE; + + switch ( modalityOrig ) { - // this will cause IsModalShowing() return false and our local - // message loop will terminate - wxModalDialogs.DeleteObject(this); + case wxDIALOG_MODALITY_WINDOW_MODAL: + EndWindowModal(); // OS X implementation method for cleanup + SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED ); + break; + default: + break; } } @@ -127,23 +138,46 @@ bool wxDialog::Show(bool show) // Replacement for Show(true) for modal dialogs - returns return code int wxDialog::ShowModal() { - if ( !m_isModalStyle ) - SetModal(true); + WX_HOOK_MODAL_DIALOG(); - if ( IsShown() ) - DoShowModal(); - else - Show(true); + m_modality = wxDIALOG_MODALITY_APP_MODAL; + + Show(); + + wxModalEventLoop modalLoop(this); + m_eventLoop = &modalLoop; + + wxDialog::OSXBeginModalDialog(); + modalLoop.Run(); + wxDialog::OSXEndModalDialog(); + + m_eventLoop = NULL; return GetReturnCode(); } -// NB: this function (surprizingly) may be called for both modal and modeless +void wxDialog::ShowWindowModal() +{ + m_modality = wxDIALOG_MODALITY_WINDOW_MODAL; + + Show(); + + DoShowWindowModal(); +} + +wxDialogModality wxDialog::GetModality() const +{ + return m_modality; +} + +// NB: this function (surprisingly) may be called for both modal and modeless // dialogs and should work for both of them void wxDialog::EndModal(int retCode) { + if ( m_eventLoop ) + m_eventLoop->Exit(retCode); + SetReturnCode(retCode); Show(false); - SetModal(false); }