]>
Commit | Line | Data |
---|---|---|
3ccc5735 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/osx/dialog_osx.cpp | |
3 | // Purpose: wxDialog class | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 1998-01-01 | |
b5b208a1 | 7 | // RCS-ID: $Id$ |
3ccc5735 SC |
8 | // Copyright: (c) Stefan Csomor |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #include "wx/wxprec.h" | |
13 | ||
14 | #include "wx/dialog.h" | |
62068535 | 15 | #include "wx/evtloop.h" |
3ccc5735 SC |
16 | |
17 | #ifndef WX_PRECOMP | |
18 | #include "wx/app.h" | |
19 | #include "wx/utils.h" | |
20 | #include "wx/frame.h" | |
21 | #include "wx/settings.h" | |
22 | #endif // WX_PRECOMP | |
23 | ||
24 | #include "wx/osx/private.h" | |
25 | ||
445e564f SC |
26 | static int s_openDialogs = 0; |
27 | bool wxDialog::OSXHasModalDialogsOpen() | |
28 | { | |
29 | return s_openDialogs > 0; | |
30 | } | |
31 | ||
32 | void wxDialog::OSXBeginModalDialog() | |
33 | { | |
34 | s_openDialogs++; | |
35 | } | |
36 | ||
37 | void wxDialog::OSXEndModalDialog() | |
38 | { | |
39 | wxASSERT_MSG( s_openDialogs > 0, "incorrect internal modal dialog count"); | |
40 | s_openDialogs--; | |
41 | } | |
3ccc5735 | 42 | |
3ccc5735 SC |
43 | void wxDialog::Init() |
44 | { | |
4d572a2c | 45 | m_modality = wxDIALOG_MODALITY_NONE; |
62068535 | 46 | m_eventLoop = NULL; |
3ccc5735 SC |
47 | } |
48 | ||
49 | bool wxDialog::Create( wxWindow *parent, | |
50 | wxWindowID id, | |
51 | const wxString& title, | |
52 | const wxPoint& pos, | |
53 | const wxSize& size, | |
54 | long style, | |
55 | const wxString& name ) | |
56 | { | |
57 | SetExtraStyle( GetExtraStyle() | wxTOPLEVEL_EX_DIALOG ); | |
58 | ||
59 | // All dialogs should really have this style... | |
60 | style |= wxTAB_TRAVERSAL; | |
61 | ||
62 | // ...but not these styles | |
63 | style &= ~(wxYES | wxOK | wxNO); // | wxCANCEL | |
64 | ||
65 | if ( !wxTopLevelWindow::Create( parent, id, title, pos, size, style, name ) ) | |
66 | return false; | |
67 | ||
68 | return true; | |
69 | } | |
70 | ||
3ccc5735 SC |
71 | wxDialog::~wxDialog() |
72 | { | |
c6212a0c | 73 | SendDestroyEvent(); |
3ccc5735 SC |
74 | |
75 | // if the dialog is modal, this will end its event loop | |
76 | Show(false); | |
77 | } | |
78 | ||
79 | // On mac command-stop does the same thing as Esc, let the base class know | |
80 | // about it | |
81 | bool wxDialog::IsEscapeKey(const wxKeyEvent& event) | |
82 | { | |
3c5f6264 | 83 | if ( event.GetKeyCode() == '.' && event.GetModifiers() == wxMOD_CONTROL ) |
3ccc5735 SC |
84 | return true; |
85 | ||
86 | return wxDialogBase::IsEscapeKey(event); | |
87 | } | |
88 | ||
89 | bool wxDialog::IsModal() const | |
90 | { | |
4d572a2c | 91 | return m_modality != wxDIALOG_MODALITY_NONE; |
3ccc5735 SC |
92 | } |
93 | ||
3ccc5735 SC |
94 | bool wxDialog::Show(bool show) |
95 | { | |
4d572a2c SC |
96 | if ( m_modality == wxDIALOG_MODALITY_WINDOW_MODAL ) |
97 | { | |
98 | if ( !wxWindow::Show(show) ) | |
99 | // nothing to do | |
100 | return false; | |
101 | } | |
ce00f59b | 102 | else |
4d572a2c SC |
103 | { |
104 | if ( !wxDialogBase::Show(show) ) | |
105 | // nothing to do | |
106 | return false; | |
107 | } | |
3ccc5735 SC |
108 | |
109 | if (show && CanDoLayoutAdaptation()) | |
110 | DoLayoutAdaptation(); | |
111 | ||
112 | if ( show ) | |
113 | // usually will result in TransferDataToWindow() being called | |
114 | InitDialog(); | |
115 | ||
4d572a2c | 116 | if ( !show ) |
3ccc5735 | 117 | { |
4be7f29a VZ |
118 | const int modalityOrig = m_modality; |
119 | ||
120 | // complete the 'hiding' before we send the event | |
121 | m_modality = wxDIALOG_MODALITY_NONE; | |
122 | ||
123 | switch ( modalityOrig ) | |
3ccc5735 | 124 | { |
4d572a2c SC |
125 | case wxDIALOG_MODALITY_WINDOW_MODAL: |
126 | EndWindowModal(); // OS X implementation method for cleanup | |
ce00f59b | 127 | SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED ); |
4d572a2c SC |
128 | break; |
129 | default: | |
130 | break; | |
3ccc5735 SC |
131 | } |
132 | } | |
ce00f59b | 133 | |
3ccc5735 SC |
134 | return true; |
135 | } | |
136 | ||
137 | // Replacement for Show(true) for modal dialogs - returns return code | |
138 | int wxDialog::ShowModal() | |
139 | { | |
bfa92264 | 140 | m_modality = wxDIALOG_MODALITY_APP_MODAL; |
ce00f59b | 141 | |
4d572a2c | 142 | Show(); |
3ccc5735 | 143 | |
62068535 SC |
144 | wxModalEventLoop modalLoop(this); |
145 | m_eventLoop = &modalLoop; | |
ce00f59b | 146 | |
445e564f | 147 | wxDialog::OSXBeginModalDialog(); |
62068535 | 148 | modalLoop.Run(); |
445e564f | 149 | wxDialog::OSXEndModalDialog(); |
ce00f59b | 150 | |
62068535 | 151 | m_eventLoop = NULL; |
ce00f59b | 152 | |
3ccc5735 SC |
153 | return GetReturnCode(); |
154 | } | |
155 | ||
4d572a2c SC |
156 | void wxDialog::ShowWindowModal() |
157 | { | |
158 | m_modality = wxDIALOG_MODALITY_WINDOW_MODAL; | |
ce00f59b | 159 | |
4d572a2c | 160 | Show(); |
ce00f59b | 161 | |
4d572a2c SC |
162 | DoShowWindowModal(); |
163 | } | |
164 | ||
165 | wxDialogModality wxDialog::GetModality() const | |
166 | { | |
167 | return m_modality; | |
168 | } | |
169 | ||
cbab1556 | 170 | // NB: this function (surprisingly) may be called for both modal and modeless |
3ccc5735 SC |
171 | // dialogs and should work for both of them |
172 | void wxDialog::EndModal(int retCode) | |
173 | { | |
62068535 SC |
174 | if ( m_eventLoop ) |
175 | m_eventLoop->Exit(retCode); | |
ce00f59b | 176 | |
3ccc5735 SC |
177 | SetReturnCode(retCode); |
178 | Show(false); | |
3ccc5735 SC |
179 | } |
180 |