]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
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 | #include "wx/gtk/win_gtk.h" | |
19 | ||
e2414cbe RR |
20 | //----------------------------------------------------------------------------- |
21 | ||
22 | extern wxList wxPendingDelete; | |
23 | ||
c801d85f KB |
24 | //----------------------------------------------------------------------------- |
25 | // delete | |
26 | ||
27 | bool gtk_dialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxDialog *win ) | |
28 | { | |
29 | /* | |
30 | printf( "OnDelete from " ); | |
31 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
32 | printf( win->GetClassInfo()->GetClassName() ); | |
33 | printf( ".\n" ); | |
34 | */ | |
35 | ||
36 | win->Close(); | |
37 | ||
38 | return TRUE; | |
39 | }; | |
40 | ||
41 | //----------------------------------------------------------------------------- | |
42 | // wxDialog | |
43 | //----------------------------------------------------------------------------- | |
44 | ||
45 | BEGIN_EVENT_TABLE(wxDialog,wxWindow) | |
46 | EVT_BUTTON (wxID_OK, wxDialog::OnOk) | |
47 | EVT_BUTTON (wxID_CANCEL, wxDialog::OnCancel) | |
48 | EVT_BUTTON (wxID_APPLY, wxDialog::OnApply) | |
49 | EVT_CLOSE (wxDialog::OnCloseWindow) | |
50 | END_EVENT_TABLE() | |
51 | ||
52 | IMPLEMENT_DYNAMIC_CLASS(wxDialog,wxWindow) | |
53 | ||
54 | wxDialog::wxDialog(void) | |
55 | { | |
56 | m_title = ""; | |
d355d3fe | 57 | m_modalShowing = FALSE; |
c801d85f KB |
58 | wxTopLevelWindows.Insert( this ); |
59 | }; | |
60 | ||
61 | wxDialog::wxDialog( wxWindow *parent, | |
62 | wxWindowID id, const wxString &title, | |
63 | const wxPoint &pos, const wxSize &size, | |
debe6624 | 64 | long style, const wxString &name ) |
c801d85f | 65 | { |
d355d3fe | 66 | m_modalShowing = FALSE; |
c801d85f KB |
67 | wxTopLevelWindows.Insert( this ); |
68 | Create( parent, id, title, pos, size, style, name ); | |
69 | }; | |
70 | ||
71 | bool wxDialog::Create( wxWindow *parent, | |
72 | wxWindowID id, const wxString &title, | |
73 | const wxPoint &pos, const wxSize &size, | |
debe6624 | 74 | long style, const wxString &name ) |
c801d85f KB |
75 | { |
76 | m_needParent = FALSE; | |
77 | ||
78 | PreCreation( parent, id, pos, size, style, name ); | |
79 | ||
c801d85f KB |
80 | m_widget = gtk_window_new( GTK_WINDOW_TOPLEVEL ); |
81 | GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS ); | |
82 | ||
83 | gtk_widget_set( m_widget, "GtkWindow::allow_shrink", TRUE, NULL); | |
84 | ||
85 | gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event", | |
86 | GTK_SIGNAL_FUNC(gtk_dialog_delete_callback), (gpointer)this ); | |
87 | ||
88 | m_wxwindow = gtk_myfixed_new(); | |
89 | gtk_widget_show( m_wxwindow ); | |
90 | GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); | |
91 | ||
92 | gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow ); | |
93 | ||
94 | SetTitle( title ); | |
95 | ||
96 | PostCreation(); | |
97 | ||
98 | return TRUE; | |
99 | }; | |
100 | ||
101 | wxDialog::~wxDialog(void) | |
102 | { | |
103 | wxTopLevelWindows.DeleteObject( this ); | |
104 | if (wxTopLevelWindows.Number() == 0) wxTheApp->ExitMainLoop(); | |
105 | }; | |
106 | ||
107 | void wxDialog::SetTitle(const wxString& title ) | |
108 | { | |
109 | m_title = title; | |
b6af8d80 | 110 | if (m_title.IsNull()) m_title = ""; |
c801d85f KB |
111 | gtk_window_set_title( GTK_WINDOW(m_widget), m_title ); |
112 | }; | |
113 | ||
114 | wxString wxDialog::GetTitle(void) const | |
115 | { | |
116 | return (wxString&)m_title; | |
117 | }; | |
118 | ||
119 | void wxDialog::OnApply( wxCommandEvent &WXUNUSED(event) ) | |
120 | { | |
121 | if (Validate()) TransferDataFromWindow(); | |
122 | }; | |
123 | ||
124 | void wxDialog::OnCancel( wxCommandEvent &WXUNUSED(event) ) | |
125 | { | |
126 | if (IsModal()) | |
1a6944fd | 127 | { |
c801d85f | 128 | EndModal(wxID_CANCEL); |
1a6944fd | 129 | } |
c801d85f KB |
130 | else |
131 | { | |
132 | SetReturnCode(wxID_CANCEL); | |
133 | this->Show(FALSE); | |
134 | }; | |
135 | }; | |
136 | ||
137 | void wxDialog::OnOk( wxCommandEvent &WXUNUSED(event) ) | |
138 | { | |
139 | if ( Validate() && TransferDataFromWindow()) | |
140 | { | |
141 | if (IsModal()) | |
1a6944fd | 142 | { |
c801d85f | 143 | EndModal(wxID_OK); |
1a6944fd | 144 | } |
c801d85f KB |
145 | else |
146 | { | |
147 | SetReturnCode(wxID_OK); | |
148 | this->Show(FALSE); | |
149 | }; | |
150 | }; | |
c801d85f KB |
151 | }; |
152 | ||
153 | void wxDialog::OnPaint( wxPaintEvent& WXUNUSED(event) ) | |
154 | { | |
155 | // yes | |
156 | }; | |
157 | ||
158 | bool wxDialog::OnClose(void) | |
159 | { | |
160 | static wxList closing; | |
161 | ||
162 | if (closing.Member(this)) return FALSE; // no loops | |
1a6944fd | 163 | |
c801d85f KB |
164 | closing.Append(this); |
165 | ||
166 | wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); | |
167 | cancelEvent.SetEventObject( this ); | |
168 | GetEventHandler()->ProcessEvent(cancelEvent); | |
169 | closing.DeleteObject(this); | |
170 | ||
171 | return FALSE; | |
172 | } | |
173 | ||
e2414cbe RR |
174 | bool wxDialog::Destroy(void) |
175 | { | |
176 | if (!wxPendingDelete.Member(this)) | |
177 | wxPendingDelete.Append(this); | |
178 | ||
179 | return TRUE; | |
180 | } | |
181 | ||
c801d85f KB |
182 | void wxDialog::OnCloseWindow(wxCloseEvent& event) |
183 | { | |
184 | if (GetEventHandler()->OnClose() || event.GetForce()) | |
185 | { | |
186 | this->Destroy(); | |
187 | }; | |
188 | }; | |
189 | ||
debe6624 | 190 | bool wxDialog::Show( bool show ) |
c801d85f | 191 | { |
d355d3fe | 192 | if (!show && IsModal() && m_modalShowing) |
c801d85f KB |
193 | { |
194 | EndModal( wxID_CANCEL ); | |
195 | }; | |
196 | ||
197 | wxWindow::Show( show ); | |
198 | ||
199 | if (show) InitDialog(); | |
200 | ||
c801d85f KB |
201 | return TRUE; |
202 | }; | |
203 | ||
204 | int wxDialog::ShowModal(void) | |
205 | { | |
d355d3fe RR |
206 | if (m_modalShowing) return GetReturnCode(); |
207 | ||
c801d85f | 208 | Show( TRUE ); |
d355d3fe RR |
209 | |
210 | m_modalShowing = TRUE; | |
211 | ||
212 | gtk_grab_add( m_widget ); | |
213 | gtk_main(); | |
214 | gtk_grab_remove( m_widget ); | |
215 | ||
c801d85f KB |
216 | return GetReturnCode(); |
217 | }; | |
218 | ||
219 | void wxDialog::EndModal( int retCode ) | |
220 | { | |
c801d85f | 221 | SetReturnCode( retCode ); |
d355d3fe | 222 | |
b6af8d80 RR |
223 | if (!m_modalShowing) |
224 | { | |
225 | wxFAIL_MSG( "wxDialog: called EndModal twice" ); | |
226 | return; | |
227 | }; | |
228 | ||
d355d3fe RR |
229 | m_modalShowing = FALSE; |
230 | ||
e2414cbe | 231 | gtk_main_quit(); |
c801d85f KB |
232 | }; |
233 | ||
234 | void wxDialog::InitDialog(void) | |
235 | { | |
236 | wxWindow::InitDialog(); | |
237 | }; | |
238 |