]>
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" | |
15 | ||
16 | #ifndef WX_PRECOMP | |
17 | #include "wx/app.h" | |
18 | #include "wx/utils.h" | |
19 | #include "wx/frame.h" | |
20 | #include "wx/settings.h" | |
21 | #endif // WX_PRECOMP | |
22 | ||
23 | #include "wx/osx/private.h" | |
24 | ||
25 | ||
26 | // Lists to keep track of windows, so we can disable/enable them | |
27 | // for modal dialogs | |
28 | ||
29 | wxList wxModalDialogs; | |
30 | ||
31 | IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow) | |
32 | ||
33 | void wxDialog::Init() | |
34 | { | |
4d572a2c | 35 | m_modality = wxDIALOG_MODALITY_NONE; |
3ccc5735 SC |
36 | } |
37 | ||
38 | bool wxDialog::Create( wxWindow *parent, | |
39 | wxWindowID id, | |
40 | const wxString& title, | |
41 | const wxPoint& pos, | |
42 | const wxSize& size, | |
43 | long style, | |
44 | const wxString& name ) | |
45 | { | |
46 | SetExtraStyle( GetExtraStyle() | wxTOPLEVEL_EX_DIALOG ); | |
47 | ||
48 | // All dialogs should really have this style... | |
49 | style |= wxTAB_TRAVERSAL; | |
50 | ||
51 | // ...but not these styles | |
52 | style &= ~(wxYES | wxOK | wxNO); // | wxCANCEL | |
53 | ||
54 | if ( !wxTopLevelWindow::Create( parent, id, title, pos, size, style, name ) ) | |
55 | return false; | |
56 | ||
57 | return true; | |
58 | } | |
59 | ||
3ccc5735 SC |
60 | wxDialog::~wxDialog() |
61 | { | |
c6212a0c | 62 | SendDestroyEvent(); |
3ccc5735 SC |
63 | |
64 | // if the dialog is modal, this will end its event loop | |
65 | Show(false); | |
66 | } | |
67 | ||
68 | // On mac command-stop does the same thing as Esc, let the base class know | |
69 | // about it | |
70 | bool wxDialog::IsEscapeKey(const wxKeyEvent& event) | |
71 | { | |
72 | if ( event.GetKeyCode() == '.' && event.GetModifiers() == wxMOD_CMD ) | |
73 | return true; | |
74 | ||
75 | return wxDialogBase::IsEscapeKey(event); | |
76 | } | |
77 | ||
78 | bool wxDialog::IsModal() const | |
79 | { | |
4d572a2c | 80 | return m_modality != wxDIALOG_MODALITY_NONE; |
3ccc5735 SC |
81 | } |
82 | ||
3ccc5735 SC |
83 | bool wxDialog::Show(bool show) |
84 | { | |
4d572a2c SC |
85 | if ( m_modality == wxDIALOG_MODALITY_WINDOW_MODAL ) |
86 | { | |
87 | if ( !wxWindow::Show(show) ) | |
88 | // nothing to do | |
89 | return false; | |
90 | } | |
91 | else | |
92 | { | |
93 | if ( !wxDialogBase::Show(show) ) | |
94 | // nothing to do | |
95 | return false; | |
96 | } | |
3ccc5735 SC |
97 | |
98 | if (show && CanDoLayoutAdaptation()) | |
99 | DoLayoutAdaptation(); | |
100 | ||
101 | if ( show ) | |
102 | // usually will result in TransferDataToWindow() being called | |
103 | InitDialog(); | |
104 | ||
4d572a2c | 105 | if ( !show ) |
3ccc5735 | 106 | { |
4d572a2c | 107 | switch( m_modality ) |
3ccc5735 | 108 | { |
4d572a2c SC |
109 | case wxDIALOG_MODALITY_WINDOW_MODAL: |
110 | EndWindowModal(); // OS X implementation method for cleanup | |
111 | SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED ); | |
112 | break; | |
113 | default: | |
114 | break; | |
3ccc5735 | 115 | } |
4d572a2c | 116 | m_modality = wxDIALOG_MODALITY_NONE; |
3ccc5735 | 117 | } |
4d572a2c | 118 | |
3ccc5735 SC |
119 | return true; |
120 | } | |
121 | ||
122 | // Replacement for Show(true) for modal dialogs - returns return code | |
123 | int wxDialog::ShowModal() | |
124 | { | |
bfa92264 | 125 | m_modality = wxDIALOG_MODALITY_APP_MODAL; |
4d572a2c SC |
126 | |
127 | Show(); | |
3ccc5735 | 128 | |
4d572a2c | 129 | DoShowModal(); |
3ccc5735 SC |
130 | |
131 | return GetReturnCode(); | |
132 | } | |
133 | ||
4d572a2c SC |
134 | void wxDialog::ShowWindowModal() |
135 | { | |
136 | m_modality = wxDIALOG_MODALITY_WINDOW_MODAL; | |
137 | ||
138 | Show(); | |
139 | ||
140 | DoShowWindowModal(); | |
141 | } | |
142 | ||
143 | wxDialogModality wxDialog::GetModality() const | |
144 | { | |
145 | return m_modality; | |
146 | } | |
147 | ||
cbab1556 | 148 | // NB: this function (surprisingly) may be called for both modal and modeless |
3ccc5735 SC |
149 | // dialogs and should work for both of them |
150 | void wxDialog::EndModal(int retCode) | |
151 | { | |
152 | SetReturnCode(retCode); | |
153 | Show(false); | |
3ccc5735 SC |
154 | } |
155 |