1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/dialog_osx.cpp
3 // Purpose: wxDialog class
4 // Author: Stefan Csomor
7 // RCS-ID: $Id: dialog.cpp 54820 2008-07-29 20:04:11Z SC $
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 // Lists to keep track of windows, so we can disable/enable them
29 wxList wxModalDialogs
;
31 IMPLEMENT_DYNAMIC_CLASS(wxDialog
, wxTopLevelWindow
)
35 m_modality
= wxDIALOG_MODALITY_NONE
;
39 bool wxDialog::Create( wxWindow
*parent
,
41 const wxString
& title
,
45 const wxString
& name
)
47 SetExtraStyle( GetExtraStyle() | wxTOPLEVEL_EX_DIALOG
);
49 // All dialogs should really have this style...
50 style
|= wxTAB_TRAVERSAL
;
52 // ...but not these styles
53 style
&= ~(wxYES
| wxOK
| wxNO
); // | wxCANCEL
55 if ( !wxTopLevelWindow::Create( parent
, id
, title
, pos
, size
, style
, name
) )
65 // if the dialog is modal, this will end its event loop
69 // On mac command-stop does the same thing as Esc, let the base class know
71 bool wxDialog::IsEscapeKey(const wxKeyEvent
& event
)
73 if ( event
.GetKeyCode() == '.' && event
.GetModifiers() == wxMOD_CMD
)
76 return wxDialogBase::IsEscapeKey(event
);
79 bool wxDialog::IsModal() const
81 return m_modality
!= wxDIALOG_MODALITY_NONE
;
84 bool wxDialog::Show(bool show
)
86 if ( m_modality
== wxDIALOG_MODALITY_WINDOW_MODAL
)
88 if ( !wxWindow::Show(show
) )
94 if ( !wxDialogBase::Show(show
) )
99 if (show
&& CanDoLayoutAdaptation())
100 DoLayoutAdaptation();
103 // usually will result in TransferDataToWindow() being called
110 case wxDIALOG_MODALITY_WINDOW_MODAL
:
111 EndWindowModal(); // OS X implementation method for cleanup
112 SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED
);
117 m_modality
= wxDIALOG_MODALITY_NONE
;
123 // Replacement for Show(true) for modal dialogs - returns return code
124 int wxDialog::ShowModal()
126 m_modality
= wxDIALOG_MODALITY_APP_MODAL
;
130 wxModalEventLoop
modalLoop(this);
131 m_eventLoop
= &modalLoop
;
137 return GetReturnCode();
140 void wxDialog::ShowWindowModal()
142 m_modality
= wxDIALOG_MODALITY_WINDOW_MODAL
;
149 wxDialogModality
wxDialog::GetModality() const
154 // NB: this function (surprisingly) may be called for both modal and modeless
155 // dialogs and should work for both of them
156 void wxDialog::EndModal(int retCode
)
159 m_eventLoop
->Exit(retCode
);
161 SetReturnCode(retCode
);