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
) )
106 if (show
&& CanDoLayoutAdaptation())
107 DoLayoutAdaptation();
110 // usually will result in TransferDataToWindow() being called
115 if ( m_isModalStyle
)
121 else // end of modal dialog
123 // this will cause IsModalShowing() return false and our local
124 // message loop will terminate
125 wxModalDialogs
.DeleteObject(this);
132 void wxDialog::DoShowModal()
134 wxCHECK_RET( !IsModal(), wxT("DoShowModal() called twice") );
136 wxModalDialogs
.Append(this);
140 WindowRef windowRef
= (WindowRef
) MacGetWindowRef();
141 WindowGroupRef windowGroup
;
142 WindowGroupRef formerParentGroup
;
143 bool resetGroupParent
= false;
145 if ( GetParent() == NULL
)
147 windowGroup
= GetWindowGroup(windowRef
) ;
148 formerParentGroup
= GetWindowGroupParent( windowGroup
);
149 SetWindowGroupParent( windowGroup
, GetWindowGroupOfClass( kMovableModalWindowClass
) );
150 resetGroupParent
= true;
152 BeginAppModalStateForWindow(windowRef
) ;
156 wxTheApp
->MacDoOneEvent() ;
157 // calls process idle itself
160 EndAppModalStateForWindow(windowRef
) ;
161 if ( resetGroupParent
)
163 SetWindowGroupParent( windowGroup
, formerParentGroup
);
168 // Replacement for Show(true) for modal dialogs - returns return code
169 int wxDialog::ShowModal()
171 if ( !m_isModalStyle
)
176 return GetReturnCode();
179 // NB: this function (surprizingly) may be called for both modal and modeless
180 // dialogs and should work for both of them
181 void wxDialog::EndModal(int retCode
)
183 SetReturnCode(retCode
);