]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dialog.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
a81258be | 5 | // Id: $Id$ |
01111366 | 6 | // Copyright: (c) 1998 Robert Roebling |
c801d85f KB |
7 | // Licence: wxWindows licence |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | #ifdef __GNUG__ | |
11 | #pragma implementation "dialog.h" | |
12 | #endif | |
13 | ||
14 | #include "wx/dialog.h" | |
15 | #include "wx/frame.h" | |
16 | #include "wx/app.h" | |
17 | #include "wx/gtk/win_gtk.h" | |
18 | ||
e2414cbe RR |
19 | //----------------------------------------------------------------------------- |
20 | ||
21 | extern wxList wxPendingDelete; | |
22 | ||
c801d85f | 23 | //----------------------------------------------------------------------------- |
e1e955e1 RR |
24 | // "delete_event" |
25 | //----------------------------------------------------------------------------- | |
c801d85f KB |
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; | |
c33c4050 | 39 | } |
c801d85f KB |
40 | |
41 | //----------------------------------------------------------------------------- | |
42 | // wxDialog | |
43 | //----------------------------------------------------------------------------- | |
44 | ||
a60c99e6 | 45 | BEGIN_EVENT_TABLE(wxDialog,wxPanel) |
903f689b | 46 | EVT_BUTTON (wxID_OK, wxDialog::OnOK) |
c801d85f KB |
47 | EVT_BUTTON (wxID_CANCEL, wxDialog::OnCancel) |
48 | EVT_BUTTON (wxID_APPLY, wxDialog::OnApply) | |
49 | EVT_CLOSE (wxDialog::OnCloseWindow) | |
50 | END_EVENT_TABLE() | |
51 | ||
a60c99e6 | 52 | IMPLEMENT_DYNAMIC_CLASS(wxDialog,wxPanel) |
c801d85f KB |
53 | |
54 | wxDialog::wxDialog(void) | |
55 | { | |
56 | m_title = ""; | |
d355d3fe | 57 | m_modalShowing = FALSE; |
c801d85f | 58 | wxTopLevelWindows.Insert( this ); |
c33c4050 | 59 | } |
c801d85f KB |
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 ); | |
c33c4050 | 69 | } |
c801d85f KB |
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 | ||
903f689b RR |
96 | if ((m_x != -1) || (m_y != -1)) |
97 | gtk_widget_set_uposition( m_widget, m_x, m_y ); | |
98 | ||
99 | gtk_widget_set_usize( m_widget, m_width, m_height ); | |
100 | ||
c801d85f KB |
101 | PostCreation(); |
102 | ||
103 | return TRUE; | |
c33c4050 | 104 | } |
c801d85f KB |
105 | |
106 | wxDialog::~wxDialog(void) | |
107 | { | |
108 | wxTopLevelWindows.DeleteObject( this ); | |
109 | if (wxTopLevelWindows.Number() == 0) wxTheApp->ExitMainLoop(); | |
c33c4050 | 110 | } |
c801d85f KB |
111 | |
112 | void wxDialog::SetTitle(const wxString& title ) | |
113 | { | |
114 | m_title = title; | |
b6af8d80 | 115 | if (m_title.IsNull()) m_title = ""; |
c801d85f | 116 | gtk_window_set_title( GTK_WINDOW(m_widget), m_title ); |
c33c4050 | 117 | } |
c801d85f KB |
118 | |
119 | wxString wxDialog::GetTitle(void) const | |
120 | { | |
121 | return (wxString&)m_title; | |
c33c4050 | 122 | } |
c801d85f KB |
123 | |
124 | void wxDialog::OnApply( wxCommandEvent &WXUNUSED(event) ) | |
125 | { | |
126 | if (Validate()) TransferDataFromWindow(); | |
c33c4050 | 127 | } |
c801d85f KB |
128 | |
129 | void wxDialog::OnCancel( wxCommandEvent &WXUNUSED(event) ) | |
130 | { | |
131 | if (IsModal()) | |
1a6944fd | 132 | { |
c801d85f | 133 | EndModal(wxID_CANCEL); |
1a6944fd | 134 | } |
c801d85f KB |
135 | else |
136 | { | |
137 | SetReturnCode(wxID_CANCEL); | |
138 | this->Show(FALSE); | |
c33c4050 RR |
139 | } |
140 | } | |
c801d85f | 141 | |
903f689b | 142 | void wxDialog::OnOK( wxCommandEvent &WXUNUSED(event) ) |
c801d85f KB |
143 | { |
144 | if ( Validate() && TransferDataFromWindow()) | |
145 | { | |
146 | if (IsModal()) | |
1a6944fd | 147 | { |
c801d85f | 148 | EndModal(wxID_OK); |
1a6944fd | 149 | } |
c801d85f KB |
150 | else |
151 | { | |
152 | SetReturnCode(wxID_OK); | |
153 | this->Show(FALSE); | |
c33c4050 RR |
154 | } |
155 | } | |
156 | } | |
c801d85f KB |
157 | |
158 | void wxDialog::OnPaint( wxPaintEvent& WXUNUSED(event) ) | |
159 | { | |
160 | // yes | |
c33c4050 | 161 | } |
c801d85f KB |
162 | |
163 | bool wxDialog::OnClose(void) | |
164 | { | |
165 | static wxList closing; | |
166 | ||
167 | if (closing.Member(this)) return FALSE; // no loops | |
1a6944fd | 168 | |
c801d85f KB |
169 | closing.Append(this); |
170 | ||
171 | wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); | |
172 | cancelEvent.SetEventObject( this ); | |
173 | GetEventHandler()->ProcessEvent(cancelEvent); | |
174 | closing.DeleteObject(this); | |
175 | ||
176 | return FALSE; | |
177 | } | |
178 | ||
e2414cbe RR |
179 | bool wxDialog::Destroy(void) |
180 | { | |
181 | if (!wxPendingDelete.Member(this)) | |
182 | wxPendingDelete.Append(this); | |
183 | ||
184 | return TRUE; | |
185 | } | |
186 | ||
c801d85f KB |
187 | void wxDialog::OnCloseWindow(wxCloseEvent& event) |
188 | { | |
189 | if (GetEventHandler()->OnClose() || event.GetForce()) | |
190 | { | |
191 | this->Destroy(); | |
c33c4050 RR |
192 | } |
193 | } | |
c801d85f | 194 | |
903f689b RR |
195 | void wxDialog::ImplementSetPosition(void) |
196 | { | |
197 | if ((m_x != -1) || (m_y != -1)) | |
198 | gtk_widget_set_uposition( m_widget, m_x, m_y ); | |
199 | } | |
200 | ||
201 | void wxDialog::Centre( int direction ) | |
202 | { | |
203 | if (direction & wxHORIZONTAL == wxHORIZONTAL) m_x = (gdk_screen_width () - m_width) / 2; | |
204 | if (direction & wxVERTICAL == wxVERTICAL) m_y = (gdk_screen_height () - m_height) / 2; | |
205 | ImplementSetPosition(); | |
206 | } | |
207 | ||
debe6624 | 208 | bool wxDialog::Show( bool show ) |
c801d85f | 209 | { |
e1e955e1 | 210 | if (!show && IsModal()) |
c801d85f KB |
211 | { |
212 | EndModal( wxID_CANCEL ); | |
c33c4050 | 213 | } |
c801d85f KB |
214 | |
215 | wxWindow::Show( show ); | |
216 | ||
217 | if (show) InitDialog(); | |
218 | ||
c801d85f | 219 | return TRUE; |
c33c4050 RR |
220 | } |
221 | ||
e1e955e1 RR |
222 | bool wxDialog::IsModal(void) const |
223 | { | |
224 | return m_modalShowing; | |
225 | } | |
226 | ||
227 | void wxDialog::SetModal( bool WXUNUSED(flag) ) | |
c33c4050 | 228 | { |
e1e955e1 | 229 | /* |
c33c4050 RR |
230 | if (flag) |
231 | m_windowStyle |= wxDIALOG_MODAL; | |
232 | else | |
233 | if (m_windowStyle & wxDIALOG_MODAL) m_windowStyle -= wxDIALOG_MODAL; | |
e1e955e1 RR |
234 | */ |
235 | wxFAIL_MSG( "wxDialog:SetModal obsolete now" ); | |
c33c4050 | 236 | } |
c801d85f KB |
237 | |
238 | int wxDialog::ShowModal(void) | |
239 | { | |
e1e955e1 | 240 | if (IsModal()) |
5b011451 RR |
241 | { |
242 | wxFAIL_MSG( "wxDialog:ShowModal called twice" ); | |
243 | return GetReturnCode(); | |
244 | } | |
d355d3fe | 245 | |
c801d85f | 246 | Show( TRUE ); |
d355d3fe RR |
247 | |
248 | m_modalShowing = TRUE; | |
249 | ||
250 | gtk_grab_add( m_widget ); | |
251 | gtk_main(); | |
252 | gtk_grab_remove( m_widget ); | |
253 | ||
c801d85f | 254 | return GetReturnCode(); |
c33c4050 | 255 | } |
c801d85f KB |
256 | |
257 | void wxDialog::EndModal( int retCode ) | |
258 | { | |
c801d85f | 259 | SetReturnCode( retCode ); |
d355d3fe | 260 | |
e1e955e1 | 261 | if (!IsModal()) |
b6af8d80 | 262 | { |
5b011451 | 263 | wxFAIL_MSG( "wxDialog:EndModal called twice" ); |
b6af8d80 | 264 | return; |
c33c4050 | 265 | } |
b6af8d80 | 266 | |
d355d3fe RR |
267 | m_modalShowing = FALSE; |
268 | ||
e2414cbe | 269 | gtk_main_quit(); |
5b011451 RR |
270 | |
271 | Show( FALSE ); | |
c33c4050 | 272 | } |
c801d85f KB |
273 | |
274 | void wxDialog::InitDialog(void) | |
275 | { | |
276 | wxWindow::InitDialog(); | |
c33c4050 RR |
277 | } |
278 | ||
c33c4050 RR |
279 | void wxDialog::SetIcon( const wxIcon &icon ) |
280 | { | |
281 | m_icon = icon; | |
282 | if (!icon.Ok()) return; | |
283 | ||
284 | wxMask *mask = icon.GetMask(); | |
c67daf87 | 285 | GdkBitmap *bm = (GdkBitmap *) NULL; |
c33c4050 RR |
286 | if (mask) bm = mask->GetBitmap(); |
287 | ||
c67daf87 | 288 | gdk_window_set_icon( m_widget->window, (GdkWindow *) NULL, icon.GetPixmap(), bm ); |
c33c4050 | 289 | } |