1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/univ/dialog.cpp
3 // Author: Robert Roebling, Vaclav Slavik
5 // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
9 // ============================================================================
11 // ============================================================================
13 // ----------------------------------------------------------------------------
15 // ----------------------------------------------------------------------------
18 #pragma implementation "univdialog.h"
21 // For compilers that support precompilation, includes "wx.h".
22 #include "wx/wxprec.h"
29 #include "wx/dialog.h"
34 #include "wx/evtloop.h"
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
40 BEGIN_EVENT_TABLE(wxDialog
,wxDialogBase
)
41 EVT_BUTTON (wxID_OK
, wxDialog::OnOK
)
42 EVT_BUTTON (wxID_CANCEL
, wxDialog::OnCancel
)
43 EVT_BUTTON (wxID_APPLY
, wxDialog::OnApply
)
44 EVT_CLOSE (wxDialog::OnCloseWindow
)
47 IMPLEMENT_DYNAMIC_CLASS(wxDialog
,wxTopLevelWindow
)
52 m_windowDisabler
= NULL
;
54 m_isShowingModal
= FALSE
;
62 bool wxDialog::Create(wxWindow
*parent
,
63 wxWindowID id
, const wxString
&title
,
64 const wxPoint
&pos
, const wxSize
&size
,
65 long style
, const wxString
&name
)
67 SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG
);
69 // all dialogs should have tab traversal enabled
70 style
|= wxTAB_TRAVERSAL
;
72 return wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
);
75 void wxDialog::OnApply(wxCommandEvent
&WXUNUSED(event
))
78 TransferDataFromWindow();
81 void wxDialog::OnCancel(wxCommandEvent
&WXUNUSED(event
))
85 EndModal(wxID_CANCEL
);
89 SetReturnCode(wxID_CANCEL
);
94 void wxDialog::OnOK(wxCommandEvent
&WXUNUSED(event
))
96 if ( Validate() && TransferDataFromWindow() )
104 SetReturnCode(wxID_OK
);
110 void wxDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
112 // We'll send a Cancel message by default,
113 // which may close the dialog.
114 // Check for looping if the Cancel event handler calls Close().
116 // Note that if a cancel button and handler aren't present in the dialog,
117 // nothing will happen when you close the dialog via the window manager, or
119 // We wouldn't want to destroy the dialog by default, since the dialog may have been
120 // created on the stack.
121 // However, this does mean that calling dialog->Close() won't delete the dialog
122 // unless the handler for wxID_CANCEL does so. So use Destroy() if you want to be
123 // sure to destroy the dialog.
124 // The default OnCancel (above) simply ends a modal dialog, and hides a modeless dialog.
126 static wxList s_closing
;
128 if (s_closing
.Member(this))
131 s_closing
.Append(this);
133 wxCommandEvent
cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
134 cancelEvent
.SetEventObject(this);
135 GetEventHandler()->ProcessEvent(cancelEvent
);
136 s_closing
.DeleteObject(this);
139 bool wxDialog::Show(bool show
)
143 // if we had disabled other app windows, reenable them back now because
144 // if they stay disabled Windows will activate another window (one
145 // which is enabled, anyhow) and we will lose activation
146 if ( m_windowDisabler
)
148 delete m_windowDisabler
;
149 m_windowDisabler
= NULL
;
153 EndModal(wxID_CANCEL
);
156 // Not sure how to put this in platform-specific
157 // code just yet. Nano-X has to force a size event,
158 // else there's no initial size.
162 wxSizeEvent
event(GetSize(), GetId());
163 event
.SetEventObject(this);
164 GetEventHandler()->ProcessEvent(event
);
168 bool ret
= wxDialogBase::Show(show
);
176 bool wxDialog::IsModal() const
178 return m_isShowingModal
;
181 void wxDialog::SetModal(bool WXUNUSED(flag
))
183 wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") );
186 int wxDialog::ShowModal()
190 wxFAIL_MSG( wxT("wxDialog:ShowModal called twice") );
191 return GetReturnCode();
194 // use the apps top level window as parent if none given unless explicitly
196 if ( !GetParent() && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT
) )
198 wxWindow
*parent
= wxTheApp
->GetTopWindow();
199 if ( parent
&& parent
!= this )
207 m_isShowingModal
= TRUE
;
209 wxASSERT_MSG( !m_windowDisabler
, _T("disabling windows twice?") );
211 #if defined(__WXGTK__) || defined(__WXMGL__)
212 wxBusyCursorSuspender suspender
;
213 // FIXME (FIXME_MGL) - make sure busy cursor disappears under MSW too
216 m_windowDisabler
= new wxWindowDisabler(this);
218 m_eventLoop
= new wxEventLoop
;
222 return GetReturnCode();
225 void wxDialog::EndModal(int retCode
)
227 wxASSERT_MSG( m_eventLoop
, _T("wxDialog is not modal") );
229 SetReturnCode(retCode
);
233 wxFAIL_MSG( wxT("wxDialog:EndModal called twice") );
237 m_isShowingModal
= FALSE
;