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 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");
44 IMPLEMENT_DYNAMIC_CLASS(wxDialog
, wxTopLevelWindow
)
48 m_modality
= wxDIALOG_MODALITY_NONE
;
52 bool wxDialog::Create( wxWindow
*parent
,
54 const wxString
& title
,
58 const wxString
& name
)
60 SetExtraStyle( GetExtraStyle() | wxTOPLEVEL_EX_DIALOG
);
62 // All dialogs should really have this style...
63 style
|= wxTAB_TRAVERSAL
;
65 // ...but not these styles
66 style
&= ~(wxYES
| wxOK
| wxNO
); // | wxCANCEL
68 if ( !wxTopLevelWindow::Create( parent
, id
, title
, pos
, size
, style
, name
) )
78 // if the dialog is modal, this will end its event loop
82 // On mac command-stop does the same thing as Esc, let the base class know
84 bool wxDialog::IsEscapeKey(const wxKeyEvent
& event
)
86 if ( event
.GetKeyCode() == '.' && event
.GetModifiers() == wxMOD_CMD
)
89 return wxDialogBase::IsEscapeKey(event
);
92 bool wxDialog::IsModal() const
94 return m_modality
!= wxDIALOG_MODALITY_NONE
;
97 bool wxDialog::Show(bool show
)
99 if ( m_modality
== wxDIALOG_MODALITY_WINDOW_MODAL
)
101 if ( !wxWindow::Show(show
) )
107 if ( !wxDialogBase::Show(show
) )
112 if (show
&& CanDoLayoutAdaptation())
113 DoLayoutAdaptation();
116 // usually will result in TransferDataToWindow() being called
123 case wxDIALOG_MODALITY_WINDOW_MODAL
:
124 EndWindowModal(); // OS X implementation method for cleanup
125 SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED
);
130 m_modality
= wxDIALOG_MODALITY_NONE
;
136 // Replacement for Show(true) for modal dialogs - returns return code
137 int wxDialog::ShowModal()
139 m_modality
= wxDIALOG_MODALITY_APP_MODAL
;
143 wxModalEventLoop
modalLoop(this);
144 m_eventLoop
= &modalLoop
;
146 wxDialog::OSXBeginModalDialog();
148 wxDialog::OSXEndModalDialog();
152 return GetReturnCode();
155 void wxDialog::ShowWindowModal()
157 m_modality
= wxDIALOG_MODALITY_WINDOW_MODAL
;
164 wxDialogModality
wxDialog::GetModality() const
169 // NB: this function (surprisingly) may be called for both modal and modeless
170 // dialogs and should work for both of them
171 void wxDialog::EndModal(int retCode
)
174 m_eventLoop
->Exit(retCode
);
176 SetReturnCode(retCode
);