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 );
67 SetWindowModality( (WindowRef
)MacGetWindowRef(), kWindowModalityAppModal
, NULL
) ;
71 m_isModalStyle
= false;
73 wxModelessWindows
.Append( this );
79 m_isBeingDeleted
= true;
83 // On mac command-stop does the same thing as Esc, let the base class know
85 bool wxDialog::IsEscapeKey(const wxKeyEvent
& event
)
87 if ( event
.GetKeyCode() == '.' && event
.GetModifiers() == wxMOD_CMD
)
90 return wxDialogBase::IsEscapeKey(event
);
93 bool wxDialog::IsModal() const
95 return wxModalDialogs
.Find((wxDialog
*)this) != NULL
; // const_cast
96 // return m_isModalStyle;
100 bool wxDialog::Show(bool show
)
102 if ( !wxDialogBase::Show(show
) )
107 // usually will result in TransferDataToWindow() being called
112 if ( m_isModalStyle
)
118 else // end of modal dialog
120 // this will cause IsModalShowing() return false and our local
121 // message loop will terminate
122 wxModalDialogs
.DeleteObject(this);
129 void wxDialog::DoShowModal()
131 wxCHECK_RET( !IsModal(), wxT("DoShowModal() called twice") );
133 wxModalDialogs
.Append(this);
137 WindowRef windowRef
= (WindowRef
) MacGetWindowRef();
138 WindowGroupRef windowGroup
;
139 WindowGroupRef formerParentGroup
;
140 bool resetGroupParent
= false;
142 if ( GetParent() == NULL
)
144 windowGroup
= GetWindowGroup(windowRef
) ;
145 formerParentGroup
= GetWindowGroupParent( windowGroup
);
146 SetWindowGroupParent( windowGroup
, GetWindowGroupOfClass( kMovableModalWindowClass
) );
147 resetGroupParent
= true;
149 BeginAppModalStateForWindow(windowRef
) ;
153 wxTheApp
->MacDoOneEvent() ;
154 // calls process idle itself
157 EndAppModalStateForWindow(windowRef
) ;
158 if ( resetGroupParent
)
160 SetWindowGroupParent( windowGroup
, formerParentGroup
);
165 // Replacement for Show(true) for modal dialogs - returns return code
166 int wxDialog::ShowModal()
168 if ( !m_isModalStyle
)
173 return GetReturnCode();
176 // NB: this function (surprizingly) may be called for both modal and modeless
177 // dialogs and should work for both of them
178 void wxDialog::EndModal(int retCode
)
180 SetReturnCode(retCode
);