]>
Commit | Line | Data |
---|---|---|
e9576ca5 | 1 | ///////////////////////////////////////////////////////////////////////////// |
670f9935 | 2 | // Name: src/mac/carbon/dialog.cpp |
e9576ca5 | 3 | // Purpose: wxDialog class |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 | 5 | // Modified by: |
a31a5f85 | 6 | // Created: 1998-01-01 |
e9576ca5 | 7 | // RCS-ID: $Id$ |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
670f9935 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
3d1a4878 SC |
12 | #include "wx/wxprec.h" |
13 | ||
e9576ca5 | 14 | #include "wx/dialog.h" |
670f9935 WS |
15 | |
16 | #ifndef WX_PRECOMP | |
17 | #include "wx/app.h" | |
de6185e2 | 18 | #include "wx/utils.h" |
76b49cf4 | 19 | #include "wx/frame.h" |
9eddec69 | 20 | #include "wx/settings.h" |
670f9935 WS |
21 | #endif // WX_PRECOMP |
22 | ||
d497dca4 | 23 | #include "wx/mac/uma.h" |
519cb848 | 24 | |
efb064f7 | 25 | |
e9576ca5 SC |
26 | // Lists to keep track of windows, so we can disable/enable them |
27 | // for modal dialogs | |
28 | wxList wxModalDialogs; | |
efb064f7 | 29 | |
a15eb0a5 | 30 | IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow) |
e9576ca5 | 31 | |
2c326ada | 32 | void wxDialog::Init() |
e9576ca5 | 33 | { |
2c326ada | 34 | m_isModalStyle = false; |
e9576ca5 SC |
35 | } |
36 | ||
efb064f7 DS |
37 | bool wxDialog::Create( wxWindow *parent, |
38 | wxWindowID id, | |
39 | const wxString& title, | |
40 | const wxPoint& pos, | |
41 | const wxSize& size, | |
42 | long style, | |
43 | const wxString& name ) | |
e9576ca5 | 44 | { |
efb064f7 | 45 | SetExtraStyle( GetExtraStyle() | wxTOPLEVEL_EX_DIALOG ); |
eeacbb8c | 46 | |
efb064f7 | 47 | // All dialogs should really have this style... |
facd6764 | 48 | style |= wxTAB_TRAVERSAL; |
eeacbb8c | 49 | |
efb064f7 DS |
50 | // ...but not these styles |
51 | style &= ~(wxYES | wxOK | wxNO); // | wxCANCEL | |
52 | ||
53 | if ( !wxTopLevelWindow::Create( parent, id, title, pos, size, style, name ) ) | |
1aa7b427 | 54 | return false; |
670f9935 | 55 | |
1aa7b427 | 56 | return true; |
e9576ca5 SC |
57 | } |
58 | ||
efb064f7 | 59 | void wxDialog::SetModal( bool flag ) |
e9576ca5 | 60 | { |
e40298d5 | 61 | if ( flag ) |
2f1ae414 | 62 | { |
2c326ada | 63 | m_isModalStyle = true; |
eeacbb8c | 64 | |
efb064f7 DS |
65 | wxModelessWindows.DeleteObject( this ); |
66 | ||
efb064f7 | 67 | SetWindowModality( (WindowRef)MacGetWindowRef(), kWindowModalityAppModal, NULL ) ; |
2f1ae414 SC |
68 | } |
69 | else | |
70 | { | |
2c326ada | 71 | m_isModalStyle = false; |
eeacbb8c | 72 | |
efb064f7 | 73 | wxModelessWindows.Append( this ); |
2f1ae414 | 74 | } |
e9576ca5 SC |
75 | } |
76 | ||
77 | wxDialog::~wxDialog() | |
78 | { | |
1aa7b427 DS |
79 | m_isBeingDeleted = true; |
80 | Show(false); | |
e9576ca5 SC |
81 | } |
82 | ||
0be27418 VZ |
83 | // On mac command-stop does the same thing as Esc, let the base class know |
84 | // about it | |
85 | bool wxDialog::IsEscapeKey(const wxKeyEvent& event) | |
e9576ca5 | 86 | { |
0be27418 VZ |
87 | if ( event.GetKeyCode() == '.' && event.GetModifiers() == wxMOD_CMD ) |
88 | return true; | |
efb064f7 | 89 | |
0be27418 | 90 | return wxDialogBase::IsEscapeKey(event); |
e9576ca5 SC |
91 | } |
92 | ||
2f1ae414 | 93 | bool wxDialog::IsModal() const |
51abe921 | 94 | { |
285ce5a3 JS |
95 | return wxModalDialogs.Find((wxDialog *)this) != NULL; // const_cast |
96 | // return m_isModalStyle; | |
51abe921 SC |
97 | } |
98 | ||
2f1ae414 | 99 | |
e9576ca5 SC |
100 | bool wxDialog::Show(bool show) |
101 | { | |
2f1ae414 | 102 | if ( !wxDialogBase::Show(show) ) |
2f1ae414 | 103 | // nothing to do |
1aa7b427 | 104 | return false; |
e9576ca5 | 105 | |
3aa8e4ea JS |
106 | if (show && CanDoLayoutAdaptation()) |
107 | DoLayoutAdaptation(); | |
108 | ||
2f1ae414 | 109 | if ( show ) |
2f1ae414 SC |
110 | // usually will result in TransferDataToWindow() being called |
111 | InitDialog(); | |
e9576ca5 | 112 | |
6239ee05 SC |
113 | HiliteMenu(0); |
114 | ||
285ce5a3 | 115 | if ( m_isModalStyle ) |
e7549107 | 116 | { |
2f1ae414 SC |
117 | if ( show ) |
118 | { | |
119 | DoShowModal(); | |
120 | } | |
121 | else // end of modal dialog | |
122 | { | |
1aa7b427 | 123 | // this will cause IsModalShowing() return false and our local |
2f1ae414 SC |
124 | // message loop will terminate |
125 | wxModalDialogs.DeleteObject(this); | |
126 | } | |
127 | } | |
e7549107 | 128 | |
1aa7b427 | 129 | return true; |
e9576ca5 SC |
130 | } |
131 | ||
2f1ae414 | 132 | void wxDialog::DoShowModal() |
51abe921 | 133 | { |
5a2b31a0 | 134 | wxCHECK_RET( !IsModal(), wxT("DoShowModal() called twice") ); |
51abe921 | 135 | |
2f1ae414 | 136 | wxModalDialogs.Append(this); |
51abe921 | 137 | |
90b78a56 | 138 | SetFocus() ; |
670f9935 | 139 | |
6239ee05 SC |
140 | WindowRef windowRef = (WindowRef) MacGetWindowRef(); |
141 | WindowGroupRef windowGroup; | |
142 | WindowGroupRef formerParentGroup; | |
143 | bool resetGroupParent = false; | |
144 | ||
145 | if ( GetParent() == NULL ) | |
146 | { | |
147 | windowGroup = GetWindowGroup(windowRef) ; | |
148 | formerParentGroup = GetWindowGroupParent( windowGroup ); | |
149 | SetWindowGroupParent( windowGroup, GetWindowGroupOfClass( kMovableModalWindowClass ) ); | |
150 | resetGroupParent = true; | |
151 | } | |
152 | BeginAppModalStateForWindow(windowRef) ; | |
efb064f7 | 153 | |
5a2b31a0 | 154 | while ( IsModal() ) |
e40298d5 JS |
155 | { |
156 | wxTheApp->MacDoOneEvent() ; | |
157 | // calls process idle itself | |
158 | } | |
eeacbb8c | 159 | |
6239ee05 SC |
160 | EndAppModalStateForWindow(windowRef) ; |
161 | if ( resetGroupParent ) | |
162 | { | |
163 | SetWindowGroupParent( windowGroup , formerParentGroup ); | |
164 | } | |
51abe921 | 165 | } |
519cb848 | 166 | |
2f1ae414 | 167 | |
1aa7b427 | 168 | // Replacement for Show(true) for modal dialogs - returns return code |
e9576ca5 SC |
169 | int wxDialog::ShowModal() |
170 | { | |
285ce5a3 | 171 | if ( !m_isModalStyle ) |
1aa7b427 | 172 | SetModal(true); |
81b41c03 | 173 | |
1aa7b427 | 174 | Show(true); |
efb064f7 | 175 | |
e40298d5 | 176 | return GetReturnCode(); |
e9576ca5 SC |
177 | } |
178 | ||
2f1ae414 SC |
179 | // NB: this function (surprizingly) may be called for both modal and modeless |
180 | // dialogs and should work for both of them | |
e9576ca5 SC |
181 | void wxDialog::EndModal(int retCode) |
182 | { | |
285ce5a3 | 183 | SetReturnCode(retCode); |
1aa7b427 | 184 | Show(false); |
285ce5a3 | 185 | SetModal(false); |
e9576ca5 SC |
186 | } |
187 |