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