]>
Commit | Line | Data |
---|---|---|
7c78e7c7 RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dialog.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
5 | // Created: 01/02/97 | |
6 | // Id: | |
7 | // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem | |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #ifdef __GNUG__ | |
12 | #pragma implementation "dialog.h" | |
13 | #endif | |
14 | ||
15 | #include "wx/dialog.h" | |
16 | #include "wx/frame.h" | |
17 | #include "wx/app.h" | |
18 | ||
19 | //----------------------------------------------------------------------------- | |
20 | ||
21 | extern wxList wxPendingDelete; | |
22 | ||
23 | //----------------------------------------------------------------------------- | |
24 | // wxDialog | |
25 | //----------------------------------------------------------------------------- | |
26 | ||
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) | |
32 | END_EVENT_TABLE() | |
33 | ||
34 | IMPLEMENT_DYNAMIC_CLASS(wxDialog,wxWindow) | |
35 | ||
36 | wxDialog::wxDialog(void) | |
37 | { | |
38 | m_title = ""; | |
39 | m_modalShowing = FALSE; | |
40 | wxTopLevelWindows.Insert( this ); | |
41 | }; | |
42 | ||
43 | wxDialog::wxDialog( wxWindow *parent, | |
44 | wxWindowID id, const wxString &title, | |
45 | const wxPoint &pos, const wxSize &size, | |
46 | long style, const wxString &name ) | |
47 | { | |
48 | m_modalShowing = FALSE; | |
49 | wxTopLevelWindows.Insert( this ); | |
50 | Create( parent, id, title, pos, size, style, name ); | |
51 | }; | |
52 | ||
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 ) | |
57 | { | |
58 | return TRUE; | |
59 | }; | |
60 | ||
61 | wxDialog::~wxDialog(void) | |
62 | { | |
63 | wxTopLevelWindows.DeleteObject( this ); | |
64 | if (wxTopLevelWindows.Number() == 0) wxTheApp->ExitMainLoop(); | |
65 | }; | |
66 | ||
67 | void wxDialog::SetTitle(const wxString& title ) | |
68 | { | |
69 | m_title = title; | |
70 | }; | |
71 | ||
72 | wxString wxDialog::GetTitle(void) const | |
73 | { | |
74 | return (wxString&)m_title; | |
75 | }; | |
76 | ||
77 | void wxDialog::OnApply( wxCommandEvent &WXUNUSED(event) ) | |
78 | { | |
79 | if (Validate()) TransferDataFromWindow(); | |
80 | }; | |
81 | ||
82 | void wxDialog::OnCancel( wxCommandEvent &WXUNUSED(event) ) | |
83 | { | |
84 | if (IsModal()) | |
85 | { | |
86 | EndModal(wxID_CANCEL); | |
87 | } | |
88 | else | |
89 | { | |
90 | SetReturnCode(wxID_CANCEL); | |
91 | this->Show(FALSE); | |
92 | }; | |
93 | }; | |
94 | ||
95 | void wxDialog::OnOk( wxCommandEvent &WXUNUSED(event) ) | |
96 | { | |
97 | if ( Validate() && TransferDataFromWindow()) | |
98 | { | |
99 | if (IsModal()) | |
100 | { | |
101 | EndModal(wxID_OK); | |
102 | } | |
103 | else | |
104 | { | |
105 | SetReturnCode(wxID_OK); | |
106 | this->Show(FALSE); | |
107 | }; | |
108 | }; | |
109 | }; | |
110 | ||
111 | void wxDialog::OnPaint( wxPaintEvent& WXUNUSED(event) ) | |
112 | { | |
113 | // yes | |
114 | }; | |
115 | ||
116 | bool wxDialog::OnClose(void) | |
117 | { | |
118 | static wxList closing; | |
119 | ||
120 | if (closing.Member(this)) return FALSE; // no loops | |
121 | ||
122 | closing.Append(this); | |
123 | ||
124 | wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); | |
125 | cancelEvent.SetEventObject( this ); | |
126 | GetEventHandler()->ProcessEvent(cancelEvent); | |
127 | closing.DeleteObject(this); | |
128 | ||
129 | return FALSE; | |
130 | } | |
131 | ||
132 | bool wxDialog::Destroy(void) | |
133 | { | |
134 | if (!wxPendingDelete.Member(this)) | |
135 | wxPendingDelete.Append(this); | |
136 | ||
137 | return TRUE; | |
138 | } | |
139 | ||
140 | void wxDialog::OnCloseWindow(wxCloseEvent& event) | |
141 | { | |
142 | if (GetEventHandler()->OnClose() || event.GetForce()) | |
143 | { | |
144 | this->Destroy(); | |
145 | }; | |
146 | }; | |
147 | ||
148 | bool wxDialog::Show( bool show ) | |
149 | { | |
150 | if (!show && IsModal() && m_modalShowing) | |
151 | { | |
152 | EndModal( wxID_CANCEL ); | |
153 | }; | |
154 | ||
155 | wxWindow::Show( show ); | |
156 | ||
157 | if (show) InitDialog(); | |
158 | ||
159 | return TRUE; | |
160 | }; | |
161 | ||
162 | int wxDialog::ShowModal(void) | |
163 | { | |
164 | if (m_modalShowing) return GetReturnCode(); | |
165 | ||
166 | Show( TRUE ); | |
167 | ||
168 | m_modalShowing = TRUE; | |
169 | ||
170 | // grab here | |
171 | // main here | |
172 | // release here | |
173 | ||
174 | return GetReturnCode(); | |
175 | }; | |
176 | ||
177 | void wxDialog::EndModal( int retCode ) | |
178 | { | |
179 | SetReturnCode( retCode ); | |
180 | ||
181 | if (!m_modalShowing) return; | |
182 | m_modalShowing = FALSE; | |
183 | ||
184 | // quit main | |
185 | }; | |
186 | ||
187 | void wxDialog::InitDialog(void) | |
188 | { | |
189 | wxWindow::InitDialog(); | |
190 | }; | |
191 |