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