1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/osx/dialog_osx.cpp 
   3 // Purpose:     wxDialog class 
   4 // Author:      Stefan Csomor 
   8 // Copyright:   (c) Stefan Csomor 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 #include "wx/wxprec.h" 
  14 #include "wx/dialog.h" 
  15 #include "wx/evtloop.h" 
  21     #include "wx/settings.h" 
  24 #include "wx/osx/private.h" 
  26 static int s_openDialogs 
= 0; 
  27 bool wxDialog::OSXHasModalDialogsOpen() 
  29     return s_openDialogs 
> 0; 
  32 void wxDialog::OSXBeginModalDialog() 
  37 void wxDialog::OSXEndModalDialog() 
  39     wxASSERT_MSG( s_openDialogs 
> 0, "incorrect internal modal dialog count"); 
  45     m_modality 
= wxDIALOG_MODALITY_NONE
; 
  49 bool wxDialog::Create( wxWindow 
*parent
, 
  51     const wxString
& title
, 
  55     const wxString
& name 
) 
  57     SetExtraStyle( GetExtraStyle() | wxTOPLEVEL_EX_DIALOG 
); 
  59     // All dialogs should really have this style... 
  60     style 
|= wxTAB_TRAVERSAL
; 
  62     // ...but not these styles 
  63     style 
&= ~(wxYES 
| wxOK 
| wxNO
); // | wxCANCEL 
  65     if ( !wxTopLevelWindow::Create( parent
, id
, title
, pos
, size
, style
, name 
) ) 
  75     // if the dialog is modal, this will end its event loop 
  79 // On mac command-stop does the same thing as Esc, let the base class know 
  81 bool wxDialog::IsEscapeKey(const wxKeyEvent
& event
) 
  83     if ( event
.GetKeyCode() == '.' && event
.GetModifiers() == wxMOD_CONTROL 
) 
  86     return wxDialogBase::IsEscapeKey(event
); 
  89 bool wxDialog::IsModal() const 
  91     return m_modality 
!= wxDIALOG_MODALITY_NONE
; 
  94 bool wxDialog::Show(bool show
) 
  96     if ( m_modality 
== wxDIALOG_MODALITY_WINDOW_MODAL 
) 
  98         if ( !wxWindow::Show(show
) ) 
 104         if ( !wxDialogBase::Show(show
) ) 
 109     if (show 
&& CanDoLayoutAdaptation()) 
 110         DoLayoutAdaptation(); 
 113         // usually will result in TransferDataToWindow() being called 
 118         const int modalityOrig 
= m_modality
; 
 120         // complete the 'hiding' before we send the event 
 121         m_modality 
= wxDIALOG_MODALITY_NONE
; 
 123         switch ( modalityOrig 
) 
 125             case wxDIALOG_MODALITY_WINDOW_MODAL
: 
 126                 EndWindowModal(); // OS X implementation method for cleanup 
 127                 SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED  
); 
 137 // Replacement for Show(true) for modal dialogs - returns return code 
 138 int wxDialog::ShowModal() 
 140     m_modality 
= wxDIALOG_MODALITY_APP_MODAL
; 
 144     wxModalEventLoop 
modalLoop(this); 
 145     m_eventLoop 
= &modalLoop
; 
 147     wxDialog::OSXBeginModalDialog(); 
 149     wxDialog::OSXEndModalDialog(); 
 153     return GetReturnCode(); 
 156 void wxDialog::ShowWindowModal() 
 158     m_modality 
= wxDIALOG_MODALITY_WINDOW_MODAL
; 
 165 wxDialogModality 
wxDialog::GetModality() const 
 170 // NB: this function (surprisingly) may be called for both modal and modeless 
 171 //     dialogs and should work for both of them 
 172 void wxDialog::EndModal(int retCode
) 
 175         m_eventLoop
->Exit(retCode
); 
 177     SetReturnCode(retCode
);