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/osx/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 SetWindowModality( (WindowRef
)MacGetWindowRef(), kWindowModalityAppModal
, NULL
) ;
69 m_isModalStyle
= false;
75 m_isBeingDeleted
= true;
77 // if the dialog is modal, this will end its event loop
81 // On mac command-stop does the same thing as Esc, let the base class know
83 bool wxDialog::IsEscapeKey(const wxKeyEvent
& event
)
85 if ( event
.GetKeyCode() == '.' && event
.GetModifiers() == wxMOD_CMD
)
88 return wxDialogBase::IsEscapeKey(event
);
91 bool wxDialog::IsModal() const
93 return wxModalDialogs
.Find((wxDialog
*)this) != NULL
; // const_cast
94 // return m_isModalStyle;
98 bool wxDialog::Show(bool show
)
100 if ( !wxDialogBase::Show(show
) )
104 if (show
&& CanDoLayoutAdaptation())
105 DoLayoutAdaptation();
108 // usually will result in TransferDataToWindow() being called
113 if ( m_isModalStyle
)
119 else // end of modal dialog
121 // this will cause IsModalShowing() return false and our local
122 // message loop will terminate
123 wxModalDialogs
.DeleteObject(this);
130 void wxDialog::DoShowModal()
132 wxCHECK_RET( !IsModal(), wxT("DoShowModal() called twice") );
134 wxModalDialogs
.Append(this);
138 WindowRef windowRef
= (WindowRef
) MacGetWindowRef();
139 WindowGroupRef windowGroup
;
140 WindowGroupRef formerParentGroup
;
141 bool resetGroupParent
= false;
143 if ( GetParent() == NULL
)
145 windowGroup
= GetWindowGroup(windowRef
) ;
146 formerParentGroup
= GetWindowGroupParent( windowGroup
);
147 SetWindowGroupParent( windowGroup
, GetWindowGroupOfClass( kMovableModalWindowClass
) );
148 resetGroupParent
= true;
150 BeginAppModalStateForWindow(windowRef
) ;
154 wxTheApp
->MacDoOneEvent() ;
155 // calls process idle itself
158 EndAppModalStateForWindow(windowRef
) ;
159 if ( resetGroupParent
)
161 SetWindowGroupParent( windowGroup
, formerParentGroup
);
166 // Replacement for Show(true) for modal dialogs - returns return code
167 int wxDialog::ShowModal()
169 if ( !m_isModalStyle
)
174 return GetReturnCode();
177 // NB: this function (surprizingly) may be called for both modal and modeless
178 // dialogs and should work for both of them
179 void wxDialog::EndModal(int retCode
)
181 SetReturnCode(retCode
);