]>
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 | |
7 | // RCS-ID: $Id: dialog.cpp 54820 2008-07-29 20:04:11Z 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 | |
44 | IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow) | |
45 | ||
46 | void wxDialog::Init() | |
47 | { | |
4d572a2c | 48 | m_modality = wxDIALOG_MODALITY_NONE; |
62068535 | 49 | m_eventLoop = NULL; |
3ccc5735 SC |
50 | } |
51 | ||
52 | bool wxDialog::Create( wxWindow *parent, | |
53 | wxWindowID id, | |
54 | const wxString& title, | |
55 | const wxPoint& pos, | |
56 | const wxSize& size, | |
57 | long style, | |
58 | const wxString& name ) | |
59 | { | |
60 | SetExtraStyle( GetExtraStyle() | wxTOPLEVEL_EX_DIALOG ); | |
61 | ||
62 | // All dialogs should really have this style... | |
63 | style |= wxTAB_TRAVERSAL; | |
64 | ||
65 | // ...but not these styles | |
66 | style &= ~(wxYES | wxOK | wxNO); // | wxCANCEL | |
67 | ||
68 | if ( !wxTopLevelWindow::Create( parent, id, title, pos, size, style, name ) ) | |
69 | return false; | |
70 | ||
71 | return true; | |
72 | } | |
73 | ||
3ccc5735 SC |
74 | wxDialog::~wxDialog() |
75 | { | |
c6212a0c | 76 | SendDestroyEvent(); |
3ccc5735 SC |
77 | |
78 | // if the dialog is modal, this will end its event loop | |
79 | Show(false); | |
80 | } | |
81 | ||
82 | // On mac command-stop does the same thing as Esc, let the base class know | |
83 | // about it | |
84 | bool wxDialog::IsEscapeKey(const wxKeyEvent& event) | |
85 | { | |
86 | if ( event.GetKeyCode() == '.' && event.GetModifiers() == wxMOD_CMD ) | |
87 | return true; | |
88 | ||
89 | return wxDialogBase::IsEscapeKey(event); | |
90 | } | |
91 | ||
92 | bool wxDialog::IsModal() const | |
93 | { | |
4d572a2c | 94 | return m_modality != wxDIALOG_MODALITY_NONE; |
3ccc5735 SC |
95 | } |
96 | ||
3ccc5735 SC |
97 | bool wxDialog::Show(bool show) |
98 | { | |
4d572a2c SC |
99 | if ( m_modality == wxDIALOG_MODALITY_WINDOW_MODAL ) |
100 | { | |
101 | if ( !wxWindow::Show(show) ) | |
102 | // nothing to do | |
103 | return false; | |
104 | } | |
105 | else | |
106 | { | |
107 | if ( !wxDialogBase::Show(show) ) | |
108 | // nothing to do | |
109 | return false; | |
110 | } | |
3ccc5735 SC |
111 | |
112 | if (show && CanDoLayoutAdaptation()) | |
113 | DoLayoutAdaptation(); | |
114 | ||
115 | if ( show ) | |
116 | // usually will result in TransferDataToWindow() being called | |
117 | InitDialog(); | |
118 | ||
4d572a2c | 119 | if ( !show ) |
3ccc5735 | 120 | { |
4d572a2c | 121 | switch( m_modality ) |
3ccc5735 | 122 | { |
4d572a2c SC |
123 | case wxDIALOG_MODALITY_WINDOW_MODAL: |
124 | EndWindowModal(); // OS X implementation method for cleanup | |
125 | SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED ); | |
126 | break; | |
127 | default: | |
128 | break; | |
3ccc5735 | 129 | } |
4d572a2c | 130 | m_modality = wxDIALOG_MODALITY_NONE; |
3ccc5735 | 131 | } |
4d572a2c | 132 | |
3ccc5735 SC |
133 | return true; |
134 | } | |
135 | ||
136 | // Replacement for Show(true) for modal dialogs - returns return code | |
137 | int wxDialog::ShowModal() | |
138 | { | |
bfa92264 | 139 | m_modality = wxDIALOG_MODALITY_APP_MODAL; |
4d572a2c SC |
140 | |
141 | Show(); | |
3ccc5735 | 142 | |
62068535 SC |
143 | wxModalEventLoop modalLoop(this); |
144 | m_eventLoop = &modalLoop; | |
145 | ||
445e564f | 146 | wxDialog::OSXBeginModalDialog(); |
62068535 | 147 | modalLoop.Run(); |
445e564f | 148 | wxDialog::OSXEndModalDialog(); |
62068535 SC |
149 | |
150 | m_eventLoop = NULL; | |
151 | ||
3ccc5735 SC |
152 | return GetReturnCode(); |
153 | } | |
154 | ||
4d572a2c SC |
155 | void wxDialog::ShowWindowModal() |
156 | { | |
157 | m_modality = wxDIALOG_MODALITY_WINDOW_MODAL; | |
158 | ||
159 | Show(); | |
160 | ||
161 | DoShowWindowModal(); | |
162 | } | |
163 | ||
164 | wxDialogModality wxDialog::GetModality() const | |
165 | { | |
166 | return m_modality; | |
167 | } | |
168 | ||
cbab1556 | 169 | // NB: this function (surprisingly) may be called for both modal and modeless |
3ccc5735 SC |
170 | // dialogs and should work for both of them |
171 | void wxDialog::EndModal(int retCode) | |
172 | { | |
62068535 SC |
173 | if ( m_eventLoop ) |
174 | m_eventLoop->Exit(retCode); | |
175 | ||
3ccc5735 SC |
176 | SetReturnCode(retCode); |
177 | Show(false); | |
3ccc5735 SC |
178 | } |
179 |