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 /////////////////////////////////////////////////////////////////////////////
10 #pragma implementation "univdialog.h"
13 #include "wx/dialog.h"
15 #include "wx/evtloop.h"
18 //-----------------------------------------------------------------------------
20 //-----------------------------------------------------------------------------
22 BEGIN_EVENT_TABLE(wxDialog
,wxDialogBase
)
23 EVT_BUTTON (wxID_OK
, wxDialog::OnOK
)
24 EVT_BUTTON (wxID_CANCEL
, wxDialog::OnCancel
)
25 EVT_BUTTON (wxID_APPLY
, wxDialog::OnApply
)
26 EVT_CLOSE (wxDialog::OnCloseWindow
)
29 IMPLEMENT_DYNAMIC_CLASS(wxDialog
,wxTopLevelWindow
)
34 m_windowDisabler
= NULL
;
36 m_isShowingModal
= FALSE
;
44 bool wxDialog::Create(wxWindow
*parent
,
45 wxWindowID id
, const wxString
&title
,
46 const wxPoint
&pos
, const wxSize
&size
,
47 long style
, const wxString
&name
)
49 SetExtraStyle(GetExtraStyle() | wxTLW_EX_DIALOG
);
51 // all dialogs should have tab traversal enabled
52 style
|= wxTAB_TRAVERSAL
;
54 return wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
);
57 void wxDialog::OnApply(wxCommandEvent
&WXUNUSED(event
))
60 TransferDataFromWindow();
63 void wxDialog::OnCancel(wxCommandEvent
&WXUNUSED(event
))
67 EndModal(wxID_CANCEL
);
71 SetReturnCode(wxID_CANCEL
);
76 void wxDialog::OnOK(wxCommandEvent
&WXUNUSED(event
))
78 if ( Validate() && TransferDataFromWindow() )
86 SetReturnCode(wxID_OK
);
92 void wxDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
94 // We'll send a Cancel message by default,
95 // which may close the dialog.
96 // Check for looping if the Cancel event handler calls Close().
98 // Note that if a cancel button and handler aren't present in the dialog,
99 // nothing will happen when you close the dialog via the window manager, or
101 // We wouldn't want to destroy the dialog by default, since the dialog may have been
102 // created on the stack.
103 // However, this does mean that calling dialog->Close() won't delete the dialog
104 // unless the handler for wxID_CANCEL does so. So use Destroy() if you want to be
105 // sure to destroy the dialog.
106 // The default OnCancel (above) simply ends a modal dialog, and hides a modeless dialog.
108 static wxList s_closing
;
110 if (s_closing
.Member(this))
113 s_closing
.Append(this);
115 wxCommandEvent
cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
116 cancelEvent
.SetEventObject(this);
117 GetEventHandler()->ProcessEvent(cancelEvent
);
118 s_closing
.DeleteObject(this);
121 bool wxDialog::Show(bool show
)
125 // if we had disabled other app windows, reenable them back now because
126 // if they stay disabled Windows will activate another window (one
127 // which is enabled, anyhow) and we will lose activation
128 if ( m_windowDisabler
)
130 delete m_windowDisabler
;
131 m_windowDisabler
= NULL
;
135 EndModal(wxID_CANCEL
);
138 bool ret
= wxDialogBase::Show(show
);
146 bool wxDialog::IsModal() const
148 return m_isShowingModal
;
151 void wxDialog::SetModal(bool WXUNUSED(flag
))
153 wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") );
156 int wxDialog::ShowModal()
160 wxFAIL_MSG( wxT("wxDialog:ShowModal called twice") );
161 return GetReturnCode();
164 // use the apps top level window as parent if none given unless explicitly
166 if ( !GetParent() && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT
) )
168 wxWindow
*parent
= wxTheApp
->GetTopWindow();
169 if ( parent
&& parent
!= this )
175 wxBusyCursorSuspender cs
; // temporarily suppress the busy cursor
179 m_isShowingModal
= TRUE
;
181 wxASSERT_MSG( !m_windowDisabler
, _T("disabling windows twice?") );
183 m_windowDisabler
= new wxWindowDisabler(this);
185 m_eventLoop
= new wxEventLoop
;
189 return GetReturnCode();
192 void wxDialog::EndModal(int retCode
)
194 wxASSERT_MSG( m_eventLoop
, _T("wxDialog is not modal") );
196 SetReturnCode(retCode
);
200 wxFAIL_MSG( wxT("wxDialog:EndModal called twice") );
204 m_isShowingModal
= FALSE
;