]> git.saurik.com Git - wxWidgets.git/blame - src/univ/dialog.cpp
Clean up the tools for offline checking of the configuration.
[wxWidgets.git] / src / univ / dialog.cpp
CommitLineData
0e0de6b8
VS
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/univ/dialog.cpp
3// Author: Robert Roebling, Vaclav Slavik
4// Id: $Id$
5// Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
65571936 6// Licence: wxWindows licence
0e0de6b8
VS
7/////////////////////////////////////////////////////////////////////////////
8
2e9f62da
VZ
9// ============================================================================
10// declarations
11// ============================================================================
12
13// ----------------------------------------------------------------------------
14// headers
15// ----------------------------------------------------------------------------
16
2e9f62da
VZ
17// For compilers that support precompilation, includes "wx.h".
18#include "wx/wxprec.h"
19
20#ifdef __BORLANDC__
21 #pragma hdrstop
22#endif
23
fdf565fe
WS
24#include "wx/dialog.h"
25
2e9f62da 26#ifndef WX_PRECOMP
2e9f62da
VZ
27 #include "wx/utils.h"
28 #include "wx/app.h"
0e0de6b8
VS
29#endif
30
0e0de6b8 31#include "wx/evtloop.h"
0e0de6b8
VS
32
33//-----------------------------------------------------------------------------
34// wxDialog
35//-----------------------------------------------------------------------------
36
37BEGIN_EVENT_TABLE(wxDialog,wxDialogBase)
38 EVT_BUTTON (wxID_OK, wxDialog::OnOK)
39 EVT_BUTTON (wxID_CANCEL, wxDialog::OnCancel)
40 EVT_BUTTON (wxID_APPLY, wxDialog::OnApply)
41 EVT_CLOSE (wxDialog::OnCloseWindow)
42END_EVENT_TABLE()
43
44IMPLEMENT_DYNAMIC_CLASS(wxDialog,wxTopLevelWindow)
45
46void wxDialog::Init()
47{
48 m_returnCode = 0;
49 m_windowDisabler = NULL;
50 m_eventLoop = NULL;
a290fa5a 51 m_isShowingModal = false;
0e0de6b8
VS
52}
53
54wxDialog::~wxDialog()
55{
56 delete m_eventLoop;
57}
58
59bool wxDialog::Create(wxWindow *parent,
60 wxWindowID id, const wxString &title,
61 const wxPoint &pos, const wxSize &size,
62 long style, const wxString &name)
63{
21f4383a 64 SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG);
0e0de6b8
VS
65
66 // all dialogs should have tab traversal enabled
67 style |= wxTAB_TRAVERSAL;
68
69 return wxTopLevelWindow::Create(parent, id, title, pos, size, style, name);
70}
71
72void wxDialog::OnApply(wxCommandEvent &WXUNUSED(event))
73{
3aa8e4ea 74 if ( Validate() )
0e0de6b8
VS
75 TransferDataFromWindow();
76}
77
78void wxDialog::OnCancel(wxCommandEvent &WXUNUSED(event))
79{
80 if ( IsModal() )
81 {
82 EndModal(wxID_CANCEL);
83 }
84 else
85 {
86 SetReturnCode(wxID_CANCEL);
a290fa5a 87 Show(false);
0e0de6b8
VS
88 }
89}
90
91void wxDialog::OnOK(wxCommandEvent &WXUNUSED(event))
92{
93 if ( Validate() && TransferDataFromWindow() )
94 {
95 if ( IsModal() )
96 {
97 EndModal(wxID_OK);
98 }
99 else
100 {
101 SetReturnCode(wxID_OK);
a290fa5a 102 Show(false);
0e0de6b8
VS
103 }
104 }
105}
106
107void wxDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
108{
109 // We'll send a Cancel message by default,
110 // which may close the dialog.
111 // Check for looping if the Cancel event handler calls Close().
112
113 // Note that if a cancel button and handler aren't present in the dialog,
114 // nothing will happen when you close the dialog via the window manager, or
115 // via Close().
116 // We wouldn't want to destroy the dialog by default, since the dialog may have been
117 // created on the stack.
118 // However, this does mean that calling dialog->Close() won't delete the dialog
119 // unless the handler for wxID_CANCEL does so. So use Destroy() if you want to be
120 // sure to destroy the dialog.
121 // The default OnCancel (above) simply ends a modal dialog, and hides a modeless dialog.
122
123 static wxList s_closing;
124
125 if (s_closing.Member(this))
126 return; // no loops
127
128 s_closing.Append(this);
129
130 wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
131 cancelEvent.SetEventObject(this);
132 GetEventHandler()->ProcessEvent(cancelEvent);
133 s_closing.DeleteObject(this);
134}
135
136bool wxDialog::Show(bool show)
137{
138 if ( !show )
139 {
140 // if we had disabled other app windows, reenable them back now because
141 // if they stay disabled Windows will activate another window (one
142 // which is enabled, anyhow) and we will lose activation
143 if ( m_windowDisabler )
144 {
145 delete m_windowDisabler;
146 m_windowDisabler = NULL;
147 }
148
149 if ( IsModal() )
150 EndModal(wxID_CANCEL);
151 }
152
3aa8e4ea
JS
153 if (show && CanDoLayoutAdaptation())
154 DoLayoutAdaptation();
155
0e0de6b8
VS
156 bool ret = wxDialogBase::Show(show);
157
3aa8e4ea 158 if ( show )
0e0de6b8
VS
159 InitDialog();
160
161 return ret;
162}
163
164bool wxDialog::IsModal() const
165{
166 return m_isShowingModal;
167}
168
0e0de6b8
VS
169int wxDialog::ShowModal()
170{
171 if ( IsModal() )
172 {
173 wxFAIL_MSG( wxT("wxDialog:ShowModal called twice") );
174 return GetReturnCode();
175 }
176
177 // use the apps top level window as parent if none given unless explicitly
178 // forbidden
179 if ( !GetParent() && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT) )
180 {
71d1d0e2 181 wxWindow * const parent = GetParentForModalDialog();
0e0de6b8
VS
182 if ( parent && parent != this )
183 {
184 m_parent = parent;
185 }
186 }
187
a290fa5a 188 Show(true);
0e0de6b8 189
a290fa5a 190 m_isShowingModal = true;
0e0de6b8
VS
191
192 wxASSERT_MSG( !m_windowDisabler, _T("disabling windows twice?") );
193
e3fc616c 194#if defined(__WXGTK__) || defined(__WXMGL__)
b22d16ad 195 wxBusyCursorSuspender suspender;
e3fc616c 196 // FIXME (FIXME_MGL) - make sure busy cursor disappears under MSW too
b22d16ad
VS
197#endif
198
0e0de6b8
VS
199 m_windowDisabler = new wxWindowDisabler(this);
200 if ( !m_eventLoop )
201 m_eventLoop = new wxEventLoop;
202
203 m_eventLoop->Run();
204
205 return GetReturnCode();
206}
207
208void wxDialog::EndModal(int retCode)
209{
210 wxASSERT_MSG( m_eventLoop, _T("wxDialog is not modal") );
211
212 SetReturnCode(retCode);
213
214 if ( !IsModal() )
215 {
216 wxFAIL_MSG( wxT("wxDialog:EndModal called twice") );
217 return;
218 }
219
a290fa5a 220 m_isShowingModal = false;
fdf565fe 221
0e0de6b8
VS
222 m_eventLoop->Exit();
223
a290fa5a 224 Show(false);
0e0de6b8 225}