1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/dialog.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"
20 #include "wx/settings.h"
23 #include "wx/mac/uma.h"
26 // Lists to keep track of windows, so we can disable/enable them
28 wxList wxModalDialogs
;
30 IMPLEMENT_DYNAMIC_CLASS(wxDialog
, wxTopLevelWindow
)
34 m_isModalStyle
= false;
37 bool wxDialog::Create( wxWindow
*parent
,
39 const wxString
& title
,
43 const wxString
& name
)
45 SetExtraStyle( GetExtraStyle() | wxTOPLEVEL_EX_DIALOG
);
47 // All dialogs should really have this style...
48 style
|= wxTAB_TRAVERSAL
;
50 // ...but not these styles
51 style
&= ~(wxYES
| wxOK
| wxNO
); // | wxCANCEL
53 if ( !wxTopLevelWindow::Create( parent
, id
, title
, pos
, size
, style
, name
) )
59 void wxDialog::SetModal( bool flag
)
63 m_isModalStyle
= true;
65 wxModelessWindows
.DeleteObject( this );
68 SetWindowModality( (WindowRef
)MacGetWindowRef(), kWindowModalityAppModal
, NULL
) ;
73 m_isModalStyle
= false;
75 wxModelessWindows
.Append( this );
81 m_isBeingDeleted
= true;
85 // On mac command-stop does the same thing as Esc, let the base class know
87 bool wxDialog::IsEscapeKey(const wxKeyEvent
& event
)
89 if ( event
.GetKeyCode() == '.' && event
.GetModifiers() == wxMOD_CMD
)
92 return wxDialogBase::IsEscapeKey(event
);
95 bool wxDialog::IsModal() const
97 return wxModalDialogs
.Find((wxDialog
*)this) != NULL
; // const_cast
98 // return m_isModalStyle;
102 bool wxDialog::Show(bool show
)
104 if ( !wxDialogBase::Show(show
) )
109 // usually will result in TransferDataToWindow() being called
114 if ( m_isModalStyle
)
120 else // end of modal dialog
122 // this will cause IsModalShowing() return false and our local
123 // message loop will terminate
124 wxModalDialogs
.DeleteObject(this);
132 extern bool s_macIsInModalLoop
;
135 void wxDialog::DoShowModal()
137 wxCHECK_RET( !IsModal(), wxT("DoShowModal() called twice") );
139 wxModalDialogs
.Append(this);
143 WindowRef windowRef
= (WindowRef
) MacGetWindowRef();
144 WindowGroupRef windowGroup
;
145 WindowGroupRef formerParentGroup
;
146 bool resetGroupParent
= false;
148 if ( GetParent() == NULL
)
150 windowGroup
= GetWindowGroup(windowRef
) ;
151 formerParentGroup
= GetWindowGroupParent( windowGroup
);
152 SetWindowGroupParent( windowGroup
, GetWindowGroupOfClass( kMovableModalWindowClass
) );
153 resetGroupParent
= true;
155 BeginAppModalStateForWindow(windowRef
) ;
159 wxTheApp
->MacDoOneEvent() ;
160 // calls process idle itself
163 EndAppModalStateForWindow(windowRef
) ;
164 if ( resetGroupParent
)
166 SetWindowGroupParent( windowGroup
, formerParentGroup
);
171 // Replacement for Show(true) for modal dialogs - returns return code
172 int wxDialog::ShowModal()
174 if ( !m_isModalStyle
)
179 return GetReturnCode();
182 // NB: this function (surprizingly) may be called for both modal and modeless
183 // dialogs and should work for both of them
184 void wxDialog::EndModal(int retCode
)
186 SetReturnCode(retCode
);