]>
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 |
2b854a32 | 7 | // Licence: wxWindows licence |
c801d85f KB |
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" | |
83624f79 RR |
17 | |
18 | #include "gdk/gdk.h" | |
19 | #include "gtk/gtk.h" | |
c801d85f | 20 | #include "wx/gtk/win_gtk.h" |
eebe4016 | 21 | #include "wx/cursor.h" |
c801d85f | 22 | |
5e014a0c RR |
23 | /* |
24 | #include "gdk/gdkprivate.h" | |
25 | #include "gdk/gdkx.h" | |
26 | */ | |
27 | ||
acfd422a RR |
28 | //----------------------------------------------------------------------------- |
29 | // idle system | |
30 | //----------------------------------------------------------------------------- | |
31 | ||
32 | extern void wxapp_install_idle_handler(); | |
33 | extern bool g_isIdle; | |
34 | ||
35 | //----------------------------------------------------------------------------- | |
36 | // data | |
e2414cbe RR |
37 | //----------------------------------------------------------------------------- |
38 | ||
39 | extern wxList wxPendingDelete; | |
40 | ||
5e014a0c RR |
41 | /* |
42 | //----------------------------------------------------------------------------- | |
43 | // instruct X to set the WM hint for positioning | |
44 | //----------------------------------------------------------------------------- | |
45 | ||
46 | extern "C" { | |
47 | ||
48 | static void gdk_window_set_position_hint( GdkWindow *window, gint x, gint y ) | |
49 | { | |
50 | GdkWindowPrivate *priv; | |
51 | XSizeHints size_hints; | |
52 | ||
53 | g_return_if_fail (window != NULL); | |
54 | ||
55 | priv = (GdkWindowPrivate*) window; | |
56 | if (priv->destroyed) return; | |
57 | ||
58 | size_hints.flags = PPosition; | |
59 | size_hints.x = x; | |
60 | size_hints.y = y; | |
61 | ||
62 | XSetWMNormalHints (priv->xdisplay, priv->xwindow, &size_hints); | |
63 | } | |
64 | ||
65 | } | |
66 | */ | |
67 | ||
c801d85f | 68 | //----------------------------------------------------------------------------- |
e1e955e1 RR |
69 | // "delete_event" |
70 | //----------------------------------------------------------------------------- | |
c801d85f KB |
71 | |
72 | bool gtk_dialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxDialog *win ) | |
2b854a32 | 73 | { |
121a3581 RR |
74 | if (g_isIdle) |
75 | wxapp_install_idle_handler(); | |
2b854a32 | 76 | |
fb1585ae | 77 | win->Close(); |
c801d85f | 78 | |
fb1585ae | 79 | return TRUE; |
c33c4050 | 80 | } |
c801d85f | 81 | |
e52f60e6 RR |
82 | //----------------------------------------------------------------------------- |
83 | // "size_allocate" | |
84 | //----------------------------------------------------------------------------- | |
85 | ||
86 | static void gtk_dialog_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxDialog *win ) | |
87 | { | |
121a3581 RR |
88 | if (g_isIdle) |
89 | wxapp_install_idle_handler(); | |
acfd422a | 90 | |
a2053b27 | 91 | if (!win->m_hasVMT) return; |
e52f60e6 | 92 | |
121a3581 RR |
93 | if ((win->m_width != alloc->width) || (win->m_height != alloc->height)) |
94 | { | |
95 | win->m_width = alloc->width; | |
96 | win->m_height = alloc->height; | |
97 | win->UpdateSize(); | |
98 | } | |
e52f60e6 RR |
99 | } |
100 | ||
36b3b54a RR |
101 | //----------------------------------------------------------------------------- |
102 | // "configure_event" | |
103 | //----------------------------------------------------------------------------- | |
104 | ||
c693edf3 RR |
105 | static gint |
106 | #if (GTK_MINOR_VERSON > 0) | |
107 | gtk_dialog_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *WXUNUSED(event), wxDialog *win ) | |
108 | #else | |
109 | gtk_dialog_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *event, wxDialog *win ) | |
110 | #endif | |
36b3b54a | 111 | { |
121a3581 RR |
112 | if (g_isIdle) |
113 | wxapp_install_idle_handler(); | |
acfd422a | 114 | |
a2053b27 | 115 | if (!win->m_hasVMT) return FALSE; |
36b3b54a | 116 | |
c693edf3 | 117 | #if (GTK_MINOR_VERSON > 0) |
dfc3d7e0 RR |
118 | int x = 0; |
119 | int y = 0; | |
120 | gdk_window_get_root_origin( win->m_widget->window, &x, &y ); | |
dfc3d7e0 RR |
121 | win->m_x = x; |
122 | win->m_y = y; | |
c693edf3 RR |
123 | #else |
124 | win->m_x = event->x; | |
125 | win->m_y = event->y; | |
126 | #endif | |
36b3b54a | 127 | |
a2053b27 | 128 | wxMoveEvent mevent( wxPoint(win->m_x,win->m_y), win->GetId() ); |
36b3b54a RR |
129 | mevent.SetEventObject( win ); |
130 | win->GetEventHandler()->ProcessEvent( mevent ); | |
131 | ||
132 | return FALSE; | |
133 | } | |
134 | ||
2b07d713 RR |
135 | //----------------------------------------------------------------------------- |
136 | // "realize" from m_widget | |
137 | //----------------------------------------------------------------------------- | |
138 | ||
58dea4b0 | 139 | /* we cannot MWM hints and icons before the widget has been realized, |
2b07d713 RR |
140 | so we do this directly after realization */ |
141 | ||
142 | static gint | |
58dea4b0 | 143 | gtk_dialog_realized_callback( GtkWidget *widget, wxDialog *win ) |
2b07d713 | 144 | { |
c5b42c87 RR |
145 | if (g_isIdle) |
146 | wxapp_install_idle_handler(); | |
147 | ||
148 | /* I haven''t been able to set the position of | |
149 | the dialog before it is shown, so I set the | |
150 | position in "realize" and "map" */ | |
151 | gtk_widget_set_uposition( widget, win->m_x, win->m_y ); | |
acfd422a | 152 | |
5e014a0c RR |
153 | /* |
154 | gdk_window_set_position_hint( widget->window, win->m_x, win->m_y ); | |
155 | */ | |
156 | ||
15b24b14 RR |
157 | /* reset the icon */ |
158 | if (win->m_icon != wxNullIcon) | |
159 | { | |
160 | wxIcon icon( win->m_icon ); | |
161 | win->m_icon = wxNullIcon; | |
f03fc89f | 162 | win->SetIcon( icon ); |
15b24b14 RR |
163 | } |
164 | ||
165 | return FALSE; | |
166 | } | |
167 | ||
168 | //----------------------------------------------------------------------------- | |
169 | // "map" from m_widget | |
170 | //----------------------------------------------------------------------------- | |
171 | ||
172 | static gint | |
173 | gtk_dialog_map_callback( GtkWidget *widget, wxDialog *win ) | |
174 | { | |
c5b42c87 RR |
175 | if (g_isIdle) |
176 | wxapp_install_idle_handler(); | |
177 | ||
15b24b14 | 178 | /* I haven''t been able to set the position of |
c5b42c87 RR |
179 | the dialog before it is shown, so I set the |
180 | position in "realize" and "map" */ | |
a2053b27 | 181 | gtk_widget_set_uposition( widget, win->m_x, win->m_y ); |
15b24b14 | 182 | |
2b07d713 RR |
183 | /* all this is for Motif Window Manager "hints" and is supposed to be |
184 | recognized by other WM as well. not tested. */ | |
051b55ad | 185 | long decor = (long) GDK_DECOR_BORDER; |
aa64626e | 186 | long func = (long) GDK_FUNC_MOVE ; |
2b07d713 | 187 | |
f03fc89f VZ |
188 | if ((win->GetWindowStyle() & wxCAPTION) != 0) |
189 | decor |= GDK_DECOR_TITLE; | |
190 | if ((win->GetWindowStyle() & wxSYSTEM_MENU) != 0) | |
aa64626e KB |
191 | { |
192 | decor |= GDK_DECOR_MENU; | |
193 | func |= GDK_FUNC_CLOSE; | |
194 | } | |
f03fc89f | 195 | if ((win->GetWindowStyle() & wxMINIMIZE_BOX) != 0) |
15b24b14 | 196 | { |
f03fc89f VZ |
197 | func |= GDK_FUNC_MINIMIZE; |
198 | decor |= GDK_DECOR_MINIMIZE; | |
15b24b14 | 199 | } |
f03fc89f | 200 | if ((win->GetWindowStyle() & wxMAXIMIZE_BOX) != 0) |
15b24b14 | 201 | { |
f03fc89f VZ |
202 | decor |= GDK_DECOR_MAXIMIZE; |
203 | func |= GDK_FUNC_MAXIMIZE; | |
15b24b14 | 204 | } |
f03fc89f | 205 | if ((win->GetWindowStyle() & wxRESIZE_BORDER) != 0) |
aa64626e KB |
206 | { |
207 | func |= GDK_FUNC_RESIZE; | |
208 | decor |= GDK_DECOR_RESIZEH; | |
209 | } | |
a2053b27 RR |
210 | gdk_window_set_decorations( win->m_widget->window, (GdkWMDecoration)decor); |
211 | gdk_window_set_functions( win->m_widget->window, (GdkWMFunction)func); | |
2b07d713 RR |
212 | |
213 | /* GTK's shrinking/growing policy */ | |
f03fc89f | 214 | if ((win->GetWindowStyle() & wxRESIZE_BORDER) == 0) |
a2053b27 | 215 | gtk_window_set_policy(GTK_WINDOW(win->m_widget), 0, 0, 1); |
2b07d713 | 216 | else |
a2053b27 | 217 | gtk_window_set_policy(GTK_WINDOW(win->m_widget), 1, 1, 1); |
2b07d713 | 218 | |
227e5e99 RR |
219 | return FALSE; |
220 | } | |
221 | ||
ddb6bc71 RR |
222 | //----------------------------------------------------------------------------- |
223 | // InsertChild for wxDialog | |
224 | //----------------------------------------------------------------------------- | |
225 | ||
226 | /* Callback for wxFrame. This very strange beast has to be used because | |
227 | * C++ has no virtual methods in a constructor. We have to emulate a | |
228 | * virtual function here as wxWindows requires different ways to insert | |
229 | * a child in container classes. */ | |
230 | ||
231 | static void wxInsertChildInDialog( wxDialog* parent, wxWindow* child ) | |
232 | { | |
233 | gtk_myfixed_put( GTK_MYFIXED(parent->m_wxwindow), | |
234 | GTK_WIDGET(child->m_widget), | |
235 | child->m_x, | |
236 | child->m_y, | |
237 | child->m_width, | |
238 | child->m_height ); | |
239 | ||
240 | if (parent->HasFlag(wxTAB_TRAVERSAL)) | |
241 | { | |
242 | /* we now allow a window to get the focus as long as it | |
243 | doesn't have any children. */ | |
244 | GTK_WIDGET_UNSET_FLAGS( parent->m_wxwindow, GTK_CAN_FOCUS ); | |
245 | } | |
246 | } | |
247 | ||
c801d85f KB |
248 | //----------------------------------------------------------------------------- |
249 | // wxDialog | |
250 | //----------------------------------------------------------------------------- | |
251 | ||
a60c99e6 | 252 | BEGIN_EVENT_TABLE(wxDialog,wxPanel) |
fb1585ae RR |
253 | EVT_BUTTON (wxID_OK, wxDialog::OnOK) |
254 | EVT_BUTTON (wxID_CANCEL, wxDialog::OnCancel) | |
255 | EVT_BUTTON (wxID_APPLY, wxDialog::OnApply) | |
e52f60e6 | 256 | EVT_SIZE (wxDialog::OnSize) |
fb1585ae | 257 | EVT_CLOSE (wxDialog::OnCloseWindow) |
c801d85f KB |
258 | END_EVENT_TABLE() |
259 | ||
a60c99e6 | 260 | IMPLEMENT_DYNAMIC_CLASS(wxDialog,wxPanel) |
c801d85f | 261 | |
68995f26 | 262 | void wxDialog::Init() |
c801d85f | 263 | { |
f03fc89f | 264 | m_returnCode = 0; |
de8113d9 | 265 | m_sizeSet = FALSE; |
fb1585ae | 266 | m_modalShowing = FALSE; |
c33c4050 | 267 | } |
c801d85f | 268 | |
2b854a32 | 269 | wxDialog::wxDialog( wxWindow *parent, |
fb1585ae | 270 | wxWindowID id, const wxString &title, |
2b854a32 | 271 | const wxPoint &pos, const wxSize &size, |
fb1585ae | 272 | long style, const wxString &name ) |
c801d85f | 273 | { |
68995f26 VZ |
274 | Init(); |
275 | ||
fb1585ae | 276 | Create( parent, id, title, pos, size, style, name ); |
c33c4050 | 277 | } |
c801d85f KB |
278 | |
279 | bool wxDialog::Create( wxWindow *parent, | |
fb1585ae | 280 | wxWindowID id, const wxString &title, |
2b854a32 | 281 | const wxPoint &pos, const wxSize &size, |
fb1585ae | 282 | long style, const wxString &name ) |
c801d85f | 283 | { |
a802c3a1 | 284 | wxTopLevelWindows.Append( this ); |
2b854a32 | 285 | |
fb1585ae | 286 | m_needParent = FALSE; |
2b854a32 | 287 | |
4dcaf11a RR |
288 | if (!PreCreation( parent, pos, size ) || |
289 | !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) | |
290 | { | |
291 | wxFAIL_MSG( _T("wxDialog creation failed") ); | |
292 | return FALSE; | |
293 | } | |
2b854a32 | 294 | |
ddb6bc71 RR |
295 | m_insertCallback = (wxInsertChildFunction) wxInsertChildInDialog; |
296 | ||
fb1585ae | 297 | m_widget = gtk_window_new( GTK_WINDOW_TOPLEVEL ); |
de1c750f RR |
298 | |
299 | if (!name.IsEmpty()) | |
300 | gtk_window_set_wmclass( GTK_WINDOW(m_widget), name.mb_str(), name.mb_str() ); | |
301 | ||
fb1585ae | 302 | GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS ); |
2b854a32 | 303 | |
2b854a32 | 304 | gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event", |
fb1585ae | 305 | GTK_SIGNAL_FUNC(gtk_dialog_delete_callback), (gpointer)this ); |
2b854a32 | 306 | |
fb1585ae RR |
307 | m_wxwindow = gtk_myfixed_new(); |
308 | gtk_widget_show( m_wxwindow ); | |
309 | GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); | |
2b854a32 | 310 | |
fb1585ae | 311 | gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow ); |
2b854a32 | 312 | |
fb1585ae | 313 | SetTitle( title ); |
2b854a32 | 314 | |
de8113d9 | 315 | if (m_parent) m_parent->AddChild( this ); |
2b854a32 | 316 | |
de8113d9 | 317 | PostCreation(); |
e146b8c8 | 318 | |
2b07d713 RR |
319 | /* we cannot set MWM hints before the widget has |
320 | been realized, so we do this directly after realization */ | |
321 | gtk_signal_connect( GTK_OBJECT(m_widget), "realize", | |
f03fc89f | 322 | GTK_SIGNAL_FUNC(gtk_dialog_realized_callback), (gpointer) this ); |
227e5e99 RR |
323 | |
324 | /* we set the position of the window after the map event. setting it | |
325 | before has no effect (with KWM) */ | |
326 | gtk_signal_connect( GTK_OBJECT(m_widget), "map", | |
f03fc89f | 327 | GTK_SIGNAL_FUNC(gtk_dialog_map_callback), (gpointer) this ); |
227e5e99 | 328 | |
2b07d713 | 329 | /* the user resized the frame by dragging etc. */ |
2b854a32 | 330 | gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate", |
36b3b54a | 331 | GTK_SIGNAL_FUNC(gtk_dialog_size_callback), (gpointer)this ); |
2b854a32 | 332 | |
36b3b54a RR |
333 | gtk_signal_connect( GTK_OBJECT(m_widget), "configure_event", |
334 | GTK_SIGNAL_FUNC(gtk_dialog_configure_callback), (gpointer)this ); | |
335 | ||
fb1585ae | 336 | return TRUE; |
c33c4050 | 337 | } |
c801d85f | 338 | |
43a18898 | 339 | wxDialog::~wxDialog() |
c801d85f | 340 | { |
31c6b4fc RR |
341 | m_isBeingDeleted = TRUE; |
342 | ||
fb1585ae | 343 | wxTopLevelWindows.DeleteObject( this ); |
2b854a32 | 344 | |
0d2a2b60 RR |
345 | if (wxTheApp->GetTopWindow() == this) |
346 | { | |
347 | wxTheApp->SetTopWindow( (wxWindow*) NULL ); | |
348 | } | |
2b854a32 | 349 | |
0d2a2b60 | 350 | if (wxTopLevelWindows.Number() == 0) |
2b854a32 | 351 | { |
0d2a2b60 RR |
352 | wxTheApp->ExitMainLoop(); |
353 | } | |
c33c4050 | 354 | } |
c801d85f | 355 | |
43a18898 | 356 | void wxDialog::SetTitle( const wxString& title ) |
c801d85f | 357 | { |
fb1585ae | 358 | m_title = title; |
ed9b9841 OK |
359 | if (m_title.IsNull()) m_title = _T(""); |
360 | gtk_window_set_title( GTK_WINDOW(m_widget), m_title.mbc_str() ); | |
c33c4050 | 361 | } |
c801d85f | 362 | |
43a18898 | 363 | wxString wxDialog::GetTitle() const |
c801d85f | 364 | { |
fb1585ae | 365 | return (wxString&)m_title; |
c33c4050 | 366 | } |
c801d85f KB |
367 | |
368 | void wxDialog::OnApply( wxCommandEvent &WXUNUSED(event) ) | |
369 | { | |
fb1585ae | 370 | if (Validate()) TransferDataFromWindow(); |
c33c4050 | 371 | } |
c801d85f KB |
372 | |
373 | void wxDialog::OnCancel( wxCommandEvent &WXUNUSED(event) ) | |
374 | { | |
fb1585ae RR |
375 | if (IsModal()) |
376 | { | |
377 | EndModal(wxID_CANCEL); | |
378 | } | |
379 | else | |
380 | { | |
381 | SetReturnCode(wxID_CANCEL); | |
739730ca | 382 | Show(FALSE); |
fb1585ae | 383 | } |
c33c4050 | 384 | } |
c801d85f | 385 | |
903f689b | 386 | void wxDialog::OnOK( wxCommandEvent &WXUNUSED(event) ) |
c801d85f | 387 | { |
32ac755d | 388 | if (Validate() && TransferDataFromWindow()) |
1a6944fd | 389 | { |
2b854a32 | 390 | if (IsModal()) |
fb1585ae RR |
391 | { |
392 | EndModal(wxID_OK); | |
393 | } | |
394 | else | |
395 | { | |
396 | SetReturnCode(wxID_OK); | |
397 | this->Show(FALSE); | |
398 | } | |
1a6944fd | 399 | } |
c33c4050 | 400 | } |
c801d85f KB |
401 | |
402 | void wxDialog::OnPaint( wxPaintEvent& WXUNUSED(event) ) | |
403 | { | |
2b854a32 | 404 | // yes |
c33c4050 | 405 | } |
c801d85f | 406 | |
2b854a32 | 407 | void wxDialog::OnCloseWindow(wxCloseEvent& event) |
c801d85f | 408 | { |
e3065973 JS |
409 | // We'll send a Cancel message by default, |
410 | // which may close the dialog. | |
411 | // Check for looping if the Cancel event handler calls Close(). | |
412 | ||
413 | // Note that if a cancel button and handler aren't present in the dialog, | |
414 | // nothing will happen when you close the dialog via the window manager, or | |
415 | // via Close(). | |
416 | // We wouldn't want to destroy the dialog by default, since the dialog may have been | |
417 | // created on the stack. | |
418 | // However, this does mean that calling dialog->Close() won't delete the dialog | |
419 | // unless the handler for wxID_CANCEL does so. So use Destroy() if you want to be | |
420 | // sure to destroy the dialog. | |
421 | // The default OnCancel (above) simply ends a modal dialog, and hides a modeless dialog. | |
422 | ||
ab2b3dd4 | 423 | static wxList s_closing; |
c801d85f | 424 | |
ab2b3dd4 | 425 | if (s_closing.Member(this)) |
2b854a32 VZ |
426 | return; // no loops |
427 | ||
ab2b3dd4 | 428 | s_closing.Append(this); |
c801d85f | 429 | |
fb1585ae RR |
430 | wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); |
431 | cancelEvent.SetEventObject( this ); | |
432 | GetEventHandler()->ProcessEvent(cancelEvent); | |
ab2b3dd4 | 433 | s_closing.DeleteObject(this); |
c801d85f KB |
434 | } |
435 | ||
43a18898 | 436 | bool wxDialog::Destroy() |
e2414cbe | 437 | { |
fb1585ae | 438 | if (!wxPendingDelete.Member(this)) wxPendingDelete.Append(this); |
e2414cbe | 439 | |
fb1585ae | 440 | return TRUE; |
e2414cbe RR |
441 | } |
442 | ||
e52f60e6 RR |
443 | void wxDialog::OnSize( wxSizeEvent &WXUNUSED(event) ) |
444 | { | |
ed9b9841 | 445 | wxASSERT_MSG( (m_widget != NULL), _T("invalid dialog") ); |
2b854a32 | 446 | |
88ac883a | 447 | #if wxUSE_CONSTRAINTS |
e52f60e6 RR |
448 | if (GetAutoLayout()) |
449 | { | |
450 | Layout(); | |
451 | } | |
2b854a32 | 452 | else |
88ac883a | 453 | #endif // wxUSE_CONSTRAINTS |
e52f60e6 | 454 | { |
de8113d9 | 455 | /* no child: go out ! */ |
db1b4961 | 456 | if (!GetChildren().First()) return; |
2b854a32 | 457 | |
de8113d9 | 458 | /* do we have exactly one child? */ |
e52f60e6 | 459 | wxWindow *child = (wxWindow *) NULL; |
db1b4961 | 460 | for(wxNode *node = GetChildren().First(); node; node = node->Next()) |
e52f60e6 RR |
461 | { |
462 | wxWindow *win = (wxWindow *)node->Data(); | |
de135918 | 463 | if (!wxIS_KIND_OF(win,wxFrame) && !wxIS_KIND_OF(win,wxDialog)) |
e52f60e6 | 464 | { |
de8113d9 | 465 | /* it's the second one: do nothing */ |
e52f60e6 RR |
466 | if (child) return; |
467 | child = win; | |
468 | } | |
469 | } | |
470 | ||
de8113d9 | 471 | /* yes: set it's size to fill all the frame */ |
e52f60e6 RR |
472 | int client_x, client_y; |
473 | GetClientSize( &client_x, &client_y ); | |
474 | child->SetSize( 1, 1, client_x-2, client_y); | |
475 | } | |
476 | } | |
477 | ||
bfc6fde4 | 478 | void wxDialog::DoSetSize( int x, int y, int width, int height, int sizeFlags ) |
903f689b | 479 | { |
ed9b9841 OK |
480 | wxASSERT_MSG( (m_widget != NULL), _T("invalid dialog") ); |
481 | wxASSERT_MSG( (m_wxwindow != NULL), _T("invalid dialog") ); | |
fb1585ae | 482 | |
de8113d9 | 483 | if (m_resizing) return; /* I don't like recursions */ |
fb1585ae RR |
484 | m_resizing = TRUE; |
485 | ||
486 | int old_x = m_x; | |
487 | int old_y = m_y; | |
488 | int old_width = m_width; | |
489 | int old_height = m_height; | |
2b854a32 | 490 | |
85ad5eb5 | 491 | if ((sizeFlags & wxSIZE_ALLOW_MINUS_ONE) == 0) |
fb1585ae RR |
492 | { |
493 | if (x != -1) m_x = x; | |
494 | if (y != -1) m_y = y; | |
495 | if (width != -1) m_width = width; | |
496 | if (height != -1) m_height = height; | |
497 | } | |
498 | else | |
499 | { | |
500 | m_x = x; | |
501 | m_y = y; | |
502 | m_width = width; | |
503 | m_height = height; | |
504 | } | |
505 | ||
506 | if ((sizeFlags & wxSIZE_AUTO_WIDTH) == wxSIZE_AUTO_WIDTH) | |
507 | { | |
508 | if (width == -1) m_width = 80; | |
509 | } | |
510 | ||
511 | if ((sizeFlags & wxSIZE_AUTO_HEIGHT) == wxSIZE_AUTO_HEIGHT) | |
512 | { | |
513 | if (height == -1) m_height = 26; | |
514 | } | |
2b854a32 | 515 | |
fb1585ae RR |
516 | if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth; |
517 | if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight; | |
0c77152e RR |
518 | if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_maxWidth; |
519 | if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_maxHeight; | |
fb1585ae RR |
520 | |
521 | if ((m_x != -1) || (m_y != -1)) | |
522 | { | |
2b854a32 | 523 | if ((m_x != old_x) || (m_y != old_y)) |
f03fc89f VZ |
524 | { |
525 | /* we set the position here and when showing the dialog | |
526 | for the first time in idle time */ | |
e146b8c8 | 527 | gtk_widget_set_uposition( m_widget, m_x, m_y ); |
f03fc89f | 528 | } |
fb1585ae | 529 | } |
2b854a32 | 530 | |
fb1585ae RR |
531 | if ((m_width != old_width) || (m_height != old_height)) |
532 | { | |
227e5e99 | 533 | /* actual resizing is deferred to GtkOnSize in idle time and |
f03fc89f | 534 | when showing the dialog */ |
de8113d9 | 535 | m_sizeSet = FALSE; |
fb1585ae | 536 | } |
2b854a32 | 537 | |
fb1585ae | 538 | m_resizing = FALSE; |
903f689b RR |
539 | } |
540 | ||
de8113d9 RR |
541 | void wxDialog::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int height ) |
542 | { | |
543 | // due to a bug in gtk, x,y are always 0 | |
544 | // m_x = x; | |
545 | // m_y = y; | |
546 | ||
547 | if ((m_height == height) && (m_width == width) && (m_sizeSet)) return; | |
548 | if (!m_wxwindow) return; | |
549 | ||
550 | m_width = width; | |
551 | m_height = height; | |
552 | ||
553 | if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth; | |
554 | if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight; | |
555 | if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_maxWidth; | |
556 | if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_maxHeight; | |
557 | ||
558 | /* we actually set the size of a frame here and no-where else */ | |
559 | gtk_widget_set_usize( m_widget, m_width, m_height ); | |
560 | ||
561 | m_sizeSet = TRUE; | |
562 | ||
563 | wxSizeEvent event( wxSize(m_width,m_height), GetId() ); | |
564 | event.SetEventObject( this ); | |
565 | GetEventHandler()->ProcessEvent( event ); | |
566 | } | |
567 | ||
903f689b RR |
568 | void wxDialog::Centre( int direction ) |
569 | { | |
ed9b9841 | 570 | wxASSERT_MSG( (m_widget != NULL), _T("invalid dialog") ); |
2b854a32 | 571 | |
43a18898 RR |
572 | int x = 0; |
573 | int y = 0; | |
2b854a32 | 574 | |
f5eafd0e RR |
575 | if ((direction & wxHORIZONTAL) == wxHORIZONTAL) x = (gdk_screen_width () - m_width) / 2; |
576 | if ((direction & wxVERTICAL) == wxVERTICAL) y = (gdk_screen_height () - m_height) / 2; | |
2b854a32 | 577 | |
fb1585ae | 578 | Move( x, y ); |
903f689b RR |
579 | } |
580 | ||
de8113d9 RR |
581 | void wxDialog::OnInternalIdle() |
582 | { | |
1b3667ab | 583 | if (!m_sizeSet && GTK_WIDGET_REALIZED(m_wxwindow)) |
de8113d9 | 584 | GtkOnSize( m_x, m_y, m_width, m_height ); |
5e014a0c RR |
585 | |
586 | wxWindow::OnInternalIdle(); | |
de8113d9 RR |
587 | } |
588 | ||
debe6624 | 589 | bool wxDialog::Show( bool show ) |
c801d85f | 590 | { |
fb1585ae RR |
591 | if (!show && IsModal()) |
592 | { | |
de8113d9 | 593 | EndModal( wxID_CANCEL ); |
fb1585ae | 594 | } |
c801d85f | 595 | |
de8113d9 RR |
596 | if (show && !m_sizeSet) |
597 | { | |
598 | /* by calling GtkOnSize here, we don't have to call | |
599 | either after showing the frame, which would entail | |
600 | much ugly flicker nor from within the size_allocate | |
601 | handler, because GTK 1.1.X forbids that. */ | |
602 | ||
603 | GtkOnSize( m_x, m_y, m_width, m_height ); | |
604 | } | |
2b854a32 | 605 | |
739730ca | 606 | bool ret = wxWindow::Show( show ); |
e146b8c8 | 607 | |
fb1585ae | 608 | if (show) InitDialog(); |
2b854a32 | 609 | |
739730ca | 610 | return ret; |
c33c4050 RR |
611 | } |
612 | ||
43a18898 | 613 | bool wxDialog::IsModal() const |
e1e955e1 | 614 | { |
fb1585ae | 615 | return m_modalShowing; |
e1e955e1 RR |
616 | } |
617 | ||
618 | void wxDialog::SetModal( bool WXUNUSED(flag) ) | |
c33c4050 | 619 | { |
e1e955e1 | 620 | /* |
c33c4050 RR |
621 | if (flag) |
622 | m_windowStyle |= wxDIALOG_MODAL; | |
623 | else | |
624 | if (m_windowStyle & wxDIALOG_MODAL) m_windowStyle -= wxDIALOG_MODAL; | |
e1e955e1 | 625 | */ |
ed9b9841 | 626 | wxFAIL_MSG( _T("wxDialog:SetModal obsolete now") ); |
c33c4050 | 627 | } |
c801d85f | 628 | |
43a18898 | 629 | int wxDialog::ShowModal() |
c801d85f | 630 | { |
fb1585ae RR |
631 | if (IsModal()) |
632 | { | |
ed9b9841 | 633 | wxFAIL_MSG( _T("wxDialog:ShowModal called twice") ); |
fb1585ae RR |
634 | return GetReturnCode(); |
635 | } | |
e146b8c8 | 636 | |
eebe4016 KB |
637 | wxBusyCursorSuspender cs; // temporarily suppress the busy cursor |
638 | ||
fb1585ae | 639 | Show( TRUE ); |
2b854a32 | 640 | |
fb1585ae | 641 | m_modalShowing = TRUE; |
2b854a32 | 642 | |
fb1585ae RR |
643 | gtk_grab_add( m_widget ); |
644 | gtk_main(); | |
645 | gtk_grab_remove( m_widget ); | |
2b854a32 | 646 | |
fb1585ae | 647 | return GetReturnCode(); |
c33c4050 | 648 | } |
c801d85f KB |
649 | |
650 | void wxDialog::EndModal( int retCode ) | |
651 | { | |
fb1585ae | 652 | SetReturnCode( retCode ); |
2b854a32 | 653 | |
fb1585ae RR |
654 | if (!IsModal()) |
655 | { | |
ed9b9841 | 656 | wxFAIL_MSG( _T("wxDialog:EndModal called twice") ); |
fb1585ae RR |
657 | return; |
658 | } | |
2b854a32 | 659 | |
fb1585ae | 660 | m_modalShowing = FALSE; |
2b854a32 | 661 | |
fb1585ae | 662 | gtk_main_quit(); |
2b854a32 | 663 | |
fb1585ae | 664 | Show( FALSE ); |
c33c4050 | 665 | } |
c801d85f | 666 | |
43a18898 | 667 | void wxDialog::InitDialog() |
c801d85f | 668 | { |
fb1585ae | 669 | wxWindow::InitDialog(); |
c33c4050 RR |
670 | } |
671 | ||
c33c4050 RR |
672 | void wxDialog::SetIcon( const wxIcon &icon ) |
673 | { | |
fb1585ae RR |
674 | m_icon = icon; |
675 | if (!icon.Ok()) return; | |
2b854a32 | 676 | |
f9241296 RR |
677 | if (!m_widget->window) return; |
678 | ||
fb1585ae RR |
679 | wxMask *mask = icon.GetMask(); |
680 | GdkBitmap *bm = (GdkBitmap *) NULL; | |
681 | if (mask) bm = mask->GetBitmap(); | |
2b854a32 | 682 | |
fb1585ae | 683 | gdk_window_set_icon( m_widget->window, (GdkWindow *) NULL, icon.GetPixmap(), bm ); |
c33c4050 | 684 | } |