]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/dialog.cpp
Compile fix for wxDataFormat cast,
[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"
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
466 if ((sizeFlags & wxSIZE_AUTO_WIDTH) == wxSIZE_AUTO_WIDTH)
467 {
468 if (width == -1) m_width = 80;
469 }
470
471 if ((sizeFlags & wxSIZE_AUTO_HEIGHT) == wxSIZE_AUTO_HEIGHT)
472 {
473 if (height == -1) m_height = 26;
474 }
2b854a32 475
fb1585ae
RR
476 if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth;
477 if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight;
0c77152e
RR
478 if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_maxWidth;
479 if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_maxHeight;
fb1585ae
RR
480
481 if ((m_x != -1) || (m_y != -1))
482 {
2b854a32 483 if ((m_x != old_x) || (m_y != old_y))
f03fc89f
VZ
484 {
485 /* we set the position here and when showing the dialog
486 for the first time in idle time */
e146b8c8 487 gtk_widget_set_uposition( m_widget, m_x, m_y );
f03fc89f 488 }
fb1585ae 489 }
2b854a32 490
fb1585ae
RR
491 if ((m_width != old_width) || (m_height != old_height))
492 {
227e5e99 493 /* actual resizing is deferred to GtkOnSize in idle time and
f03fc89f 494 when showing the dialog */
de8113d9 495 m_sizeSet = FALSE;
fb1585ae 496 }
2b854a32 497
fb1585ae 498 m_resizing = FALSE;
903f689b
RR
499}
500
de8113d9
RR
501void wxDialog::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int height )
502{
503 // due to a bug in gtk, x,y are always 0
504 // m_x = x;
505 // m_y = y;
506
507 if ((m_height == height) && (m_width == width) && (m_sizeSet)) return;
508 if (!m_wxwindow) return;
509
510 m_width = width;
511 m_height = height;
512
513 if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth;
514 if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight;
515 if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_maxWidth;
516 if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_maxHeight;
517
518 /* we actually set the size of a frame here and no-where else */
519 gtk_widget_set_usize( m_widget, m_width, m_height );
520
521 m_sizeSet = TRUE;
522
523 wxSizeEvent event( wxSize(m_width,m_height), GetId() );
524 event.SetEventObject( this );
525 GetEventHandler()->ProcessEvent( event );
526}
903f689b 527
de8113d9
RR
528void wxDialog::OnInternalIdle()
529{
1b3667ab 530 if (!m_sizeSet && GTK_WIDGET_REALIZED(m_wxwindow))
de8113d9 531 GtkOnSize( m_x, m_y, m_width, m_height );
5e014a0c
RR
532
533 wxWindow::OnInternalIdle();
de8113d9
RR
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*/
223d09f6 573 wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") );
c33c4050 574}
c801d85f 575
43a18898 576int wxDialog::ShowModal()
c801d85f 577{
fb1585ae
RR
578 if (IsModal())
579 {
223d09f6 580 wxFAIL_MSG( wxT("wxDialog:ShowModal called twice") );
fb1585ae
RR
581 return GetReturnCode();
582 }
e146b8c8 583
eebe4016
KB
584 wxBusyCursorSuspender cs; // temporarily suppress the busy cursor
585
fb1585ae 586 Show( TRUE );
2b854a32 587
fb1585ae 588 m_modalShowing = TRUE;
2b854a32 589
fb1585ae
RR
590 gtk_grab_add( m_widget );
591 gtk_main();
592 gtk_grab_remove( m_widget );
2b854a32 593
fb1585ae 594 return GetReturnCode();
c33c4050 595}
c801d85f
KB
596
597void wxDialog::EndModal( int retCode )
598{
fb1585ae 599 SetReturnCode( retCode );
2b854a32 600
fb1585ae
RR
601 if (!IsModal())
602 {
223d09f6 603 wxFAIL_MSG( wxT("wxDialog:EndModal called twice") );
fb1585ae
RR
604 return;
605 }
2b854a32 606
fb1585ae 607 m_modalShowing = FALSE;
2b854a32 608
fb1585ae 609 gtk_main_quit();
2b854a32 610
fb1585ae 611 Show( FALSE );
c33c4050 612}
c801d85f 613
43a18898 614void wxDialog::InitDialog()
c801d85f 615{
fb1585ae 616 wxWindow::InitDialog();
c33c4050
RR
617}
618
c33c4050
RR
619void wxDialog::SetIcon( const wxIcon &icon )
620{
fb1585ae
RR
621 m_icon = icon;
622 if (!icon.Ok()) return;
2b854a32 623
f9241296
RR
624 if (!m_widget->window) return;
625
fb1585ae
RR
626 wxMask *mask = icon.GetMask();
627 GdkBitmap *bm = (GdkBitmap *) NULL;
628 if (mask) bm = mask->GetBitmap();
2b854a32 629
fb1585ae 630 gdk_window_set_icon( m_widget->window, (GdkWindow *) NULL, icon.GetPixmap(), bm );
c33c4050 631}