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