]>
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 | |
cd17aeff | 56 | #if TARGET_API_MAC_OSX |
5e02e8e8 | 57 | HIViewRef growBoxRef = 0 ; |
efb064f7 | 58 | OSStatus err = HIViewFindByID( HIViewGetRoot( (WindowRef)m_macWindow ), kHIViewWindowGrowBoxID, &growBoxRef ); |
5e02e8e8 | 59 | if ( err == noErr && growBoxRef != 0 ) |
efb064f7 | 60 | HIGrowBoxViewSetTransparent( growBoxRef, true ) ; |
cd17aeff | 61 | #endif |
efb064f7 | 62 | |
1aa7b427 | 63 | return true; |
e9576ca5 SC |
64 | } |
65 | ||
efb064f7 | 66 | void wxDialog::SetModal( bool flag ) |
e9576ca5 | 67 | { |
e40298d5 | 68 | if ( flag ) |
2f1ae414 | 69 | { |
2c326ada | 70 | m_isModalStyle = true; |
eeacbb8c | 71 | |
efb064f7 DS |
72 | wxModelessWindows.DeleteObject( this ); |
73 | ||
643a0828 | 74 | #if TARGET_CARBON |
efb064f7 | 75 | SetWindowModality( (WindowRef)MacGetWindowRef(), kWindowModalityAppModal, NULL ) ; |
643a0828 | 76 | #endif |
2f1ae414 SC |
77 | } |
78 | else | |
79 | { | |
2c326ada | 80 | m_isModalStyle = false; |
eeacbb8c | 81 | |
efb064f7 | 82 | wxModelessWindows.Append( this ); |
2f1ae414 | 83 | } |
e9576ca5 SC |
84 | } |
85 | ||
86 | wxDialog::~wxDialog() | |
87 | { | |
1aa7b427 DS |
88 | m_isBeingDeleted = true; |
89 | Show(false); | |
e9576ca5 SC |
90 | } |
91 | ||
0be27418 VZ |
92 | // On mac command-stop does the same thing as Esc, let the base class know |
93 | // about it | |
94 | bool wxDialog::IsEscapeKey(const wxKeyEvent& event) | |
e9576ca5 | 95 | { |
0be27418 VZ |
96 | if ( event.GetKeyCode() == '.' && event.GetModifiers() == wxMOD_CMD ) |
97 | return true; | |
efb064f7 | 98 | |
0be27418 | 99 | return wxDialogBase::IsEscapeKey(event); |
e9576ca5 SC |
100 | } |
101 | ||
2f1ae414 | 102 | bool wxDialog::IsModal() const |
51abe921 | 103 | { |
285ce5a3 JS |
104 | return wxModalDialogs.Find((wxDialog *)this) != NULL; // const_cast |
105 | // return m_isModalStyle; | |
51abe921 SC |
106 | } |
107 | ||
2f1ae414 | 108 | |
e9576ca5 SC |
109 | bool wxDialog::Show(bool show) |
110 | { | |
2f1ae414 | 111 | if ( !wxDialogBase::Show(show) ) |
2f1ae414 | 112 | // nothing to do |
1aa7b427 | 113 | return false; |
e9576ca5 | 114 | |
2f1ae414 | 115 | if ( show ) |
2f1ae414 SC |
116 | // usually will result in TransferDataToWindow() being called |
117 | InitDialog(); | |
e9576ca5 | 118 | |
285ce5a3 | 119 | if ( m_isModalStyle ) |
e7549107 | 120 | { |
2f1ae414 SC |
121 | if ( show ) |
122 | { | |
123 | DoShowModal(); | |
124 | } | |
125 | else // end of modal dialog | |
126 | { | |
1aa7b427 | 127 | // this will cause IsModalShowing() return false and our local |
2f1ae414 SC |
128 | // message loop will terminate |
129 | wxModalDialogs.DeleteObject(this); | |
130 | } | |
131 | } | |
e7549107 | 132 | |
1aa7b427 | 133 | return true; |
e9576ca5 SC |
134 | } |
135 | ||
2726cac5 SC |
136 | #if !TARGET_CARBON |
137 | extern bool s_macIsInModalLoop ; | |
138 | #endif | |
139 | ||
2f1ae414 | 140 | void wxDialog::DoShowModal() |
51abe921 | 141 | { |
5a2b31a0 | 142 | wxCHECK_RET( !IsModal(), wxT("DoShowModal() called twice") ); |
51abe921 | 143 | |
2f1ae414 | 144 | wxModalDialogs.Append(this); |
51abe921 | 145 | |
90b78a56 | 146 | SetFocus() ; |
670f9935 | 147 | |
2726cac5 | 148 | #if TARGET_CARBON |
f697130e | 149 | BeginAppModalStateForWindow( (WindowRef) MacGetWindowRef()) ; |
2726cac5 | 150 | #else |
e40298d5 JS |
151 | // TODO : test whether parent gets disabled |
152 | bool formerModal = s_macIsInModalLoop ; | |
153 | s_macIsInModalLoop = true ; | |
2726cac5 | 154 | #endif |
efb064f7 | 155 | |
5a2b31a0 | 156 | while ( IsModal() ) |
e40298d5 JS |
157 | { |
158 | wxTheApp->MacDoOneEvent() ; | |
159 | // calls process idle itself | |
160 | } | |
eeacbb8c | 161 | |
2726cac5 | 162 | #if TARGET_CARBON |
f697130e | 163 | EndAppModalStateForWindow( (WindowRef) MacGetWindowRef() ) ; |
2726cac5 SC |
164 | #else |
165 | // TODO probably reenable the parent window if any | |
e40298d5 | 166 | s_macIsInModalLoop = formerModal ; |
2726cac5 | 167 | #endif |
51abe921 | 168 | } |
519cb848 | 169 | |
2f1ae414 | 170 | |
1aa7b427 | 171 | // Replacement for Show(true) for modal dialogs - returns return code |
e9576ca5 SC |
172 | int wxDialog::ShowModal() |
173 | { | |
285ce5a3 | 174 | if ( !m_isModalStyle ) |
1aa7b427 | 175 | SetModal(true); |
81b41c03 | 176 | |
1aa7b427 | 177 | Show(true); |
efb064f7 | 178 | |
e40298d5 | 179 | return GetReturnCode(); |
e9576ca5 SC |
180 | } |
181 | ||
2f1ae414 SC |
182 | // NB: this function (surprizingly) may be called for both modal and modeless |
183 | // dialogs and should work for both of them | |
e9576ca5 SC |
184 | void wxDialog::EndModal(int retCode) |
185 | { | |
285ce5a3 | 186 | SetReturnCode(retCode); |
1aa7b427 | 187 | Show(false); |
285ce5a3 | 188 | SetModal(false); |
e9576ca5 SC |
189 | } |
190 |