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;
81 // if the dialog is modal, this will end its event loop
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
) )
108 if (show
&& CanDoLayoutAdaptation())
109 DoLayoutAdaptation();
112 // usually will result in TransferDataToWindow() being called
117 if ( m_isModalStyle
)
123 else // end of modal dialog
125 // this will cause IsModalShowing() return false and our local
126 // message loop will terminate
127 wxModalDialogs
.DeleteObject(this);
134 void wxDialog::DoShowModal()
136 wxCHECK_RET( !IsModal(), wxT("DoShowModal() called twice") );
138 wxModalDialogs
.Append(this);
142 WindowRef windowRef
= (WindowRef
) MacGetWindowRef();
143 WindowGroupRef windowGroup
;
144 WindowGroupRef formerParentGroup
;
145 bool resetGroupParent
= false;
147 if ( GetParent() == NULL
)
149 windowGroup
= GetWindowGroup(windowRef
) ;
150 formerParentGroup
= GetWindowGroupParent( windowGroup
);
151 SetWindowGroupParent( windowGroup
, GetWindowGroupOfClass( kMovableModalWindowClass
) );
152 resetGroupParent
= true;
154 BeginAppModalStateForWindow(windowRef
) ;
158 wxTheApp
->MacDoOneEvent() ;
159 // calls process idle itself
162 EndAppModalStateForWindow(windowRef
) ;
163 if ( resetGroupParent
)
165 SetWindowGroupParent( windowGroup
, formerParentGroup
);
170 // Replacement for Show(true) for modal dialogs - returns return code
171 int wxDialog::ShowModal()
173 if ( !m_isModalStyle
)
178 return GetReturnCode();
181 // NB: this function (surprizingly) may be called for both modal and modeless
182 // dialogs and should work for both of them
183 void wxDialog::EndModal(int retCode
)
185 SetReturnCode(retCode
);