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