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