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"
16 #include "wx/testing.h"
22 #include "wx/settings.h"
25 #include "wx/osx/private.h"
27 static int s_openDialogs
= 0;
28 bool wxDialog::OSXHasModalDialogsOpen()
30 return s_openDialogs
> 0;
33 void wxDialog::OSXBeginModalDialog()
38 void wxDialog::OSXEndModalDialog()
40 wxASSERT_MSG( s_openDialogs
> 0, "incorrect internal modal dialog count");
46 m_modality
= wxDIALOG_MODALITY_NONE
;
50 bool wxDialog::Create( wxWindow
*parent
,
52 const wxString
& title
,
56 const wxString
& name
)
58 SetExtraStyle( GetExtraStyle() | wxTOPLEVEL_EX_DIALOG
);
60 // All dialogs should really have this style...
61 style
|= wxTAB_TRAVERSAL
;
63 // ...but not these styles
64 style
&= ~(wxYES
| wxOK
| wxNO
); // | wxCANCEL
66 if ( !wxTopLevelWindow::Create( parent
, id
, title
, pos
, size
, style
, name
) )
76 // if the dialog is modal, this will end its event loop
80 // On mac command-stop does the same thing as Esc, let the base class know
82 bool wxDialog::IsEscapeKey(const wxKeyEvent
& event
)
84 if ( event
.GetKeyCode() == '.' && event
.GetModifiers() == wxMOD_CONTROL
)
87 return wxDialogBase::IsEscapeKey(event
);
90 bool wxDialog::IsModal() const
92 return m_modality
!= wxDIALOG_MODALITY_NONE
;
95 bool wxDialog::Show(bool show
)
97 if ( m_modality
== wxDIALOG_MODALITY_WINDOW_MODAL
)
99 if ( !wxWindow::Show(show
) )
105 if ( !wxDialogBase::Show(show
) )
110 if (show
&& CanDoLayoutAdaptation())
111 DoLayoutAdaptation();
114 // usually will result in TransferDataToWindow() being called
119 const int modalityOrig
= m_modality
;
121 // complete the 'hiding' before we send the event
122 m_modality
= wxDIALOG_MODALITY_NONE
;
124 switch ( modalityOrig
)
126 case wxDIALOG_MODALITY_WINDOW_MODAL
:
127 EndWindowModal(); // OS X implementation method for cleanup
128 SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED
);
138 // Replacement for Show(true) for modal dialogs - returns return code
139 int wxDialog::ShowModal()
141 WX_TESTING_SHOW_MODAL_HOOK();
143 m_modality
= wxDIALOG_MODALITY_APP_MODAL
;
147 wxModalEventLoop
modalLoop(this);
148 m_eventLoop
= &modalLoop
;
150 wxDialog::OSXBeginModalDialog();
152 wxDialog::OSXEndModalDialog();
156 return GetReturnCode();
159 void wxDialog::ShowWindowModal()
161 m_modality
= wxDIALOG_MODALITY_WINDOW_MODAL
;
168 wxDialogModality
wxDialog::GetModality() const
173 // NB: this function (surprisingly) may be called for both modal and modeless
174 // dialogs and should work for both of them
175 void wxDialog::EndModal(int retCode
)
178 m_eventLoop
->Exit(retCode
);
180 SetReturnCode(retCode
);