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