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