1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "dialog.h"
15 #include "wx/dialog.h"
19 //-----------------------------------------------------------------------------
21 extern wxList wxPendingDelete
;
23 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
27 BEGIN_EVENT_TABLE(wxDialog
,wxWindow
)
28 EVT_BUTTON (wxID_OK
, wxDialog::OnOk
)
29 EVT_BUTTON (wxID_CANCEL
, wxDialog::OnCancel
)
30 EVT_BUTTON (wxID_APPLY
, wxDialog::OnApply
)
31 EVT_CLOSE (wxDialog::OnCloseWindow
)
34 IMPLEMENT_DYNAMIC_CLASS(wxDialog
,wxWindow
)
36 wxDialog::wxDialog(void)
39 m_modalShowing
= FALSE
;
40 wxTopLevelWindows
.Insert( this );
43 wxDialog::wxDialog( wxWindow
*parent
,
44 wxWindowID id
, const wxString
&title
,
45 const wxPoint
&pos
, const wxSize
&size
,
46 long style
, const wxString
&name
)
48 m_modalShowing
= FALSE
;
49 wxTopLevelWindows
.Insert( this );
50 Create( parent
, id
, title
, pos
, size
, style
, name
);
53 bool wxDialog::Create( wxWindow
*parent
,
54 wxWindowID id
, const wxString
&title
,
55 const wxPoint
&pos
, const wxSize
&size
,
56 long style
, const wxString
&name
)
61 wxDialog::~wxDialog(void)
63 wxTopLevelWindows
.DeleteObject( this );
64 if (wxTopLevelWindows
.Number() == 0) wxTheApp
->ExitMainLoop();
67 void wxDialog::SetTitle(const wxString
& title
)
72 wxString
wxDialog::GetTitle(void) const
74 return (wxString
&)m_title
;
77 void wxDialog::OnApply( wxCommandEvent
&WXUNUSED(event
) )
79 if (Validate()) TransferDataFromWindow();
82 void wxDialog::OnCancel( wxCommandEvent
&WXUNUSED(event
) )
86 EndModal(wxID_CANCEL
);
90 SetReturnCode(wxID_CANCEL
);
95 void wxDialog::OnOk( wxCommandEvent
&WXUNUSED(event
) )
97 if ( Validate() && TransferDataFromWindow())
105 SetReturnCode(wxID_OK
);
111 void wxDialog::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
116 bool wxDialog::OnClose(void)
118 static wxList closing
;
120 if (closing
.Member(this)) return FALSE
; // no loops
122 closing
.Append(this);
124 wxCommandEvent
cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
125 cancelEvent
.SetEventObject( this );
126 GetEventHandler()->ProcessEvent(cancelEvent
);
127 closing
.DeleteObject(this);
132 bool wxDialog::Destroy(void)
134 if (!wxPendingDelete
.Member(this))
135 wxPendingDelete
.Append(this);
140 void wxDialog::OnCloseWindow(wxCloseEvent
& event
)
142 if (GetEventHandler()->OnClose() || event
.GetForce())
148 bool wxDialog::Show( bool show
)
150 if (!show
&& IsModal() && m_modalShowing
)
152 EndModal( wxID_CANCEL
);
155 wxWindow::Show( show
);
157 if (show
) InitDialog();
162 int wxDialog::ShowModal(void)
164 if (m_modalShowing
) return GetReturnCode();
168 m_modalShowing
= TRUE
;
174 return GetReturnCode();
177 void wxDialog::EndModal( int retCode
)
179 SetReturnCode( retCode
);
181 if (!m_modalShowing
) return;
182 m_modalShowing
= FALSE
;
187 void wxDialog::InitDialog(void)
189 wxWindow::InitDialog();