]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/dialog.cpp
list ctrl and tree ctrl didn't like the new focus code,
[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"
69ffe1d2 17#include "wx/cursor.h"
83624f79 18
071a2d78
RR
19#include <gdk/gdk.h>
20#include <gtk/gtk.h>
21#include <gdk/gdkkeysyms.h>
22
c801d85f 23#include "wx/gtk/win_gtk.h"
5e014a0c 24
acfd422a
RR
25//-----------------------------------------------------------------------------
26// idle system
27//-----------------------------------------------------------------------------
28
29extern void wxapp_install_idle_handler();
30extern bool g_isIdle;
2d68e1b4 31extern int g_openDialogs;
acfd422a
RR
32
33//-----------------------------------------------------------------------------
34// data
e2414cbe
RR
35//-----------------------------------------------------------------------------
36
37extern wxList wxPendingDelete;
38
69ffe1d2
RR
39//-----------------------------------------------------------------------------
40// "focus" from m_window
41//-----------------------------------------------------------------------------
42
43static gint gtk_dialog_focus_callback( GtkWidget *widget, GtkDirectionType WXUNUSED(d), wxWindow *WXUNUSED(win) )
44{
45 if (g_isIdle)
46 wxapp_install_idle_handler();
47
48 // This disables GTK's tab traversal
49 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "focus" );
50 return TRUE;
51}
52
c801d85f 53//-----------------------------------------------------------------------------
e1e955e1
RR
54// "delete_event"
55//-----------------------------------------------------------------------------
c801d85f
KB
56
57bool gtk_dialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxDialog *win )
2b854a32 58{
7e14e49f 59 if (g_isIdle)
121a3581 60 wxapp_install_idle_handler();
2b854a32 61
fb1585ae 62 win->Close();
c801d85f 63
fb1585ae 64 return TRUE;
c33c4050 65}
c801d85f 66
e52f60e6
RR
67//-----------------------------------------------------------------------------
68// "size_allocate"
69//-----------------------------------------------------------------------------
70
71static void gtk_dialog_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxDialog *win )
72{
7e14e49f 73 if (g_isIdle)
121a3581 74 wxapp_install_idle_handler();
acfd422a 75
a2053b27 76 if (!win->m_hasVMT) return;
e52f60e6 77
121a3581
RR
78 if ((win->m_width != alloc->width) || (win->m_height != alloc->height))
79 {
80 win->m_width = alloc->width;
81 win->m_height = alloc->height;
5b8a521e 82 win->GtkUpdateSize();
121a3581 83 }
e52f60e6
RR
84}
85
36b3b54a
RR
86//-----------------------------------------------------------------------------
87// "configure_event"
88//-----------------------------------------------------------------------------
89
7e14e49f 90static gint
2d68e1b4 91#if (GTK_MINOR_VERSION > 0)
c693edf3
RR
92gtk_dialog_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *WXUNUSED(event), wxDialog *win )
93#else
94gtk_dialog_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *event, wxDialog *win )
95#endif
36b3b54a 96{
7e14e49f 97 if (g_isIdle)
121a3581 98 wxapp_install_idle_handler();
acfd422a 99
a2053b27 100 if (!win->m_hasVMT) return FALSE;
36b3b54a 101
2d68e1b4 102#if (GTK_MINOR_VERSION > 0)
dfc3d7e0
RR
103 int x = 0;
104 int y = 0;
105 gdk_window_get_root_origin( win->m_widget->window, &x, &y );
dfc3d7e0
RR
106 win->m_x = x;
107 win->m_y = y;
c693edf3
RR
108#else
109 win->m_x = event->x;
110 win->m_y = event->y;
111#endif
36b3b54a 112
a2053b27 113 wxMoveEvent mevent( wxPoint(win->m_x,win->m_y), win->GetId() );
36b3b54a
RR
114 mevent.SetEventObject( win );
115 win->GetEventHandler()->ProcessEvent( mevent );
116
117 return FALSE;
118}
119
2b07d713
RR
120//-----------------------------------------------------------------------------
121// "realize" from m_widget
122//-----------------------------------------------------------------------------
123
7e14e49f 124/* we cannot MWM hints and icons before the widget has been realized,
2b07d713
RR
125 so we do this directly after realization */
126
7e14e49f 127static gint
58dea4b0 128gtk_dialog_realized_callback( GtkWidget *widget, wxDialog *win )
2b07d713 129{
7e14e49f 130 if (g_isIdle)
c5b42c87
RR
131 wxapp_install_idle_handler();
132
d6538e2c 133 /* I haven't been able to set the position of
c5b42c87 134 the dialog before it is shown, so I set the
d6538e2c 135 position in "realize" */
8487f887 136 gtk_widget_set_uposition( widget, win->m_x, win->m_y );
acfd422a 137
2b07d713
RR
138 /* all this is for Motif Window Manager "hints" and is supposed to be
139 recognized by other WM as well. not tested. */
051b55ad 140 long decor = (long) GDK_DECOR_BORDER;
aa64626e 141 long func = (long) GDK_FUNC_MOVE ;
cb81efcd
KB
142
143 /* Some WM don't display any border around the frame contents if
144 used with these hints, so we add a resize border around it,
145 without automatically allowinng it to be resized though.
146
147 This avoids the problem, but looks odd. What shall we do?
148 */
149 decor |= GDK_DECOR_RESIZEH;
7e14e49f 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 165 decor |= GDK_DECOR_MAXIMIZE;
7e14e49f 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);
7e14e49f 175
2b07d713 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);
7e14e49f 181
d6538e2c 182 /* set size hints */
7beba2fc 183 gint flag = 0; // GDK_HINT_POS;
d6538e2c
RR
184 if ((win->GetMinWidth() != -1) || (win->GetMinHeight() != -1)) flag |= GDK_HINT_MIN_SIZE;
185 if ((win->GetMaxWidth() != -1) || (win->GetMaxHeight() != -1)) flag |= GDK_HINT_MAX_SIZE;
186 if (flag)
187 {
7e14e49f 188 gdk_window_set_hints( win->m_widget->window,
7beba2fc
VZ
189 win->m_x, win->m_y,
190 win->GetMinWidth(), win->GetMinHeight(),
191 win->GetMaxWidth(), win->GetMaxHeight(),
192 flag );
d6538e2c
RR
193 }
194
195 /* reset the icon */
196 if (win->m_icon != wxNullIcon)
197 {
198 wxIcon icon( win->m_icon );
199 win->m_icon = wxNullIcon;
200 win->SetIcon( icon );
201 }
7e14e49f 202
227e5e99
RR
203 return FALSE;
204}
7e14e49f 205
ddb6bc71
RR
206//-----------------------------------------------------------------------------
207// InsertChild for wxDialog
208//-----------------------------------------------------------------------------
209
210/* Callback for wxFrame. This very strange beast has to be used because
211 * C++ has no virtual methods in a constructor. We have to emulate a
212 * virtual function here as wxWindows requires different ways to insert
213 * a child in container classes. */
214
215static void wxInsertChildInDialog( wxDialog* parent, wxWindow* child )
216{
da048e3d 217 gtk_pizza_put( GTK_PIZZA(parent->m_wxwindow),
ddb6bc71
RR
218 GTK_WIDGET(child->m_widget),
219 child->m_x,
220 child->m_y,
221 child->m_width,
222 child->m_height );
223
224 if (parent->HasFlag(wxTAB_TRAVERSAL))
225 {
226 /* we now allow a window to get the focus as long as it
227 doesn't have any children. */
228 GTK_WIDGET_UNSET_FLAGS( parent->m_wxwindow, GTK_CAN_FOCUS );
229 }
230}
231
c801d85f
KB
232//-----------------------------------------------------------------------------
233// wxDialog
234//-----------------------------------------------------------------------------
235
a60c99e6 236BEGIN_EVENT_TABLE(wxDialog,wxPanel)
fb1585ae
RR
237 EVT_BUTTON (wxID_OK, wxDialog::OnOK)
238 EVT_BUTTON (wxID_CANCEL, wxDialog::OnCancel)
239 EVT_BUTTON (wxID_APPLY, wxDialog::OnApply)
e52f60e6 240 EVT_SIZE (wxDialog::OnSize)
fb1585ae 241 EVT_CLOSE (wxDialog::OnCloseWindow)
c801d85f
KB
242END_EVENT_TABLE()
243
a60c99e6 244IMPLEMENT_DYNAMIC_CLASS(wxDialog,wxPanel)
c801d85f 245
68995f26 246void wxDialog::Init()
c801d85f 247{
f03fc89f 248 m_returnCode = 0;
de8113d9 249 m_sizeSet = FALSE;
fb1585ae 250 m_modalShowing = FALSE;
54517652 251 m_isFrame = TRUE;
c33c4050 252}
c801d85f 253
2b854a32 254wxDialog::wxDialog( wxWindow *parent,
fb1585ae 255 wxWindowID id, const wxString &title,
2b854a32 256 const wxPoint &pos, const wxSize &size,
fb1585ae 257 long style, const wxString &name )
c801d85f 258{
68995f26
VZ
259 Init();
260
fb1585ae 261 Create( parent, id, title, pos, size, style, name );
c33c4050 262}
c801d85f
KB
263
264bool wxDialog::Create( wxWindow *parent,
fb1585ae 265 wxWindowID id, const wxString &title,
2b854a32 266 const wxPoint &pos, const wxSize &size,
fb1585ae 267 long style, const wxString &name )
c801d85f 268{
2d68e1b4
RR
269 g_openDialogs++;
270
a802c3a1 271 wxTopLevelWindows.Append( this );
2b854a32 272
fb1585ae 273 m_needParent = FALSE;
2b854a32 274
4dcaf11a
RR
275 if (!PreCreation( parent, pos, size ) ||
276 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
277 {
223d09f6 278 wxFAIL_MSG( wxT("wxDialog creation failed") );
7beba2fc 279 return FALSE;
4dcaf11a 280 }
2b854a32 281
69ffe1d2
RR
282 // All dialogs should really have this style
283 m_windowStyle |= wxTAB_TRAVERSAL;
284
ddb6bc71 285 m_insertCallback = (wxInsertChildFunction) wxInsertChildInDialog;
7e14e49f 286
173348db 287 m_widget = gtk_window_new( GTK_WINDOW_DIALOG );
7e14e49f 288
76380910
RR
289 if ((m_parent) && (GTK_IS_WINDOW(m_parent->m_widget)))
290 gtk_window_set_transient_for( GTK_WINDOW(m_widget), GTK_WINDOW(m_parent->m_widget) );
7e14e49f 291
de1c750f
RR
292 if (!name.IsEmpty())
293 gtk_window_set_wmclass( GTK_WINDOW(m_widget), name.mb_str(), name.mb_str() );
7e14e49f 294
fb1585ae 295 GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS );
2b854a32 296
2b854a32 297 gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event",
fb1585ae 298 GTK_SIGNAL_FUNC(gtk_dialog_delete_callback), (gpointer)this );
2b854a32 299
da048e3d 300 m_wxwindow = gtk_pizza_new();
fb1585ae
RR
301 gtk_widget_show( m_wxwindow );
302 GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
2b854a32 303
fb1585ae 304 gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow );
2b854a32 305
fb1585ae 306 SetTitle( title );
2b854a32 307
de8113d9 308 if (m_parent) m_parent->AddChild( this );
2b854a32 309
de8113d9 310 PostCreation();
e146b8c8 311
2b07d713
RR
312 /* we cannot set MWM hints before the widget has
313 been realized, so we do this directly after realization */
314 gtk_signal_connect( GTK_OBJECT(m_widget), "realize",
f03fc89f 315 GTK_SIGNAL_FUNC(gtk_dialog_realized_callback), (gpointer) this );
227e5e99 316
2b07d713 317 /* the user resized the frame by dragging etc. */
2b854a32 318 gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate",
36b3b54a 319 GTK_SIGNAL_FUNC(gtk_dialog_size_callback), (gpointer)this );
2b854a32 320
36b3b54a
RR
321 gtk_signal_connect( GTK_OBJECT(m_widget), "configure_event",
322 GTK_SIGNAL_FUNC(gtk_dialog_configure_callback), (gpointer)this );
323
69ffe1d2
RR
324 /* disable native tab traversal */
325 gtk_signal_connect( GTK_OBJECT(m_widget), "focus",
326 GTK_SIGNAL_FUNC(gtk_dialog_focus_callback), (gpointer)this );
327
fb1585ae 328 return TRUE;
c33c4050 329}
c801d85f 330
43a18898 331wxDialog::~wxDialog()
c801d85f 332{
31c6b4fc 333 m_isBeingDeleted = TRUE;
7e14e49f 334
fb1585ae 335 wxTopLevelWindows.DeleteObject( this );
2b854a32 336
0d2a2b60
RR
337 if (wxTheApp->GetTopWindow() == this)
338 {
339 wxTheApp->SetTopWindow( (wxWindow*) NULL );
340 }
2b854a32 341
f59d80ca
RR
342 if ((wxTopLevelWindows.Number() == 0) &&
343 (wxTheApp->GetExitOnFrameDelete()))
2b854a32 344 {
0d2a2b60
RR
345 wxTheApp->ExitMainLoop();
346 }
2d68e1b4
RR
347
348 g_openDialogs--;
c33c4050 349}
c801d85f 350
43a18898 351void wxDialog::SetTitle( const wxString& title )
c801d85f 352{
fb1585ae 353 m_title = title;
223d09f6 354 if (m_title.IsNull()) m_title = wxT("");
ed9b9841 355 gtk_window_set_title( GTK_WINDOW(m_widget), m_title.mbc_str() );
c33c4050 356}
c801d85f 357
43a18898 358wxString wxDialog::GetTitle() const
c801d85f 359{
fb1585ae 360 return (wxString&)m_title;
c33c4050 361}
c801d85f
KB
362
363void wxDialog::OnApply( wxCommandEvent &WXUNUSED(event) )
364{
fb1585ae 365 if (Validate()) TransferDataFromWindow();
c33c4050 366}
c801d85f
KB
367
368void wxDialog::OnCancel( wxCommandEvent &WXUNUSED(event) )
369{
fb1585ae
RR
370 if (IsModal())
371 {
372 EndModal(wxID_CANCEL);
373 }
374 else
375 {
376 SetReturnCode(wxID_CANCEL);
739730ca 377 Show(FALSE);
fb1585ae 378 }
c33c4050 379}
c801d85f 380
903f689b 381void wxDialog::OnOK( wxCommandEvent &WXUNUSED(event) )
c801d85f 382{
32ac755d 383 if (Validate() && TransferDataFromWindow())
1a6944fd 384 {
2b854a32 385 if (IsModal())
fb1585ae
RR
386 {
387 EndModal(wxID_OK);
388 }
389 else
390 {
391 SetReturnCode(wxID_OK);
392 this->Show(FALSE);
393 }
1a6944fd 394 }
c33c4050 395}
c801d85f
KB
396
397void wxDialog::OnPaint( wxPaintEvent& WXUNUSED(event) )
398{
2b854a32 399 // yes
c33c4050 400}
c801d85f 401
a492cb0f 402void wxDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
c801d85f 403{
e3065973
JS
404 // We'll send a Cancel message by default,
405 // which may close the dialog.
406 // Check for looping if the Cancel event handler calls Close().
407
408 // Note that if a cancel button and handler aren't present in the dialog,
409 // nothing will happen when you close the dialog via the window manager, or
410 // via Close().
411 // We wouldn't want to destroy the dialog by default, since the dialog may have been
412 // created on the stack.
413 // However, this does mean that calling dialog->Close() won't delete the dialog
414 // unless the handler for wxID_CANCEL does so. So use Destroy() if you want to be
415 // sure to destroy the dialog.
416 // The default OnCancel (above) simply ends a modal dialog, and hides a modeless dialog.
417
ab2b3dd4 418 static wxList s_closing;
c801d85f 419
ab2b3dd4 420 if (s_closing.Member(this))
2b854a32
VZ
421 return; // no loops
422
ab2b3dd4 423 s_closing.Append(this);
c801d85f 424
fb1585ae
RR
425 wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
426 cancelEvent.SetEventObject( this );
427 GetEventHandler()->ProcessEvent(cancelEvent);
ab2b3dd4 428 s_closing.DeleteObject(this);
c801d85f
KB
429}
430
43a18898 431bool wxDialog::Destroy()
e2414cbe 432{
fb1585ae 433 if (!wxPendingDelete.Member(this)) wxPendingDelete.Append(this);
e2414cbe 434
fb1585ae 435 return TRUE;
e2414cbe
RR
436}
437
e52f60e6
RR
438void wxDialog::OnSize( wxSizeEvent &WXUNUSED(event) )
439{
223d09f6 440 wxASSERT_MSG( (m_widget != NULL), wxT("invalid dialog") );
2b854a32 441
88ac883a 442#if wxUSE_CONSTRAINTS
e52f60e6
RR
443 if (GetAutoLayout())
444 {
445 Layout();
446 }
2b854a32 447 else
88ac883a 448#endif // wxUSE_CONSTRAINTS
e52f60e6 449 {
de8113d9 450 /* no child: go out ! */
db1b4961 451 if (!GetChildren().First()) return;
2b854a32 452
de8113d9 453 /* do we have exactly one child? */
e52f60e6 454 wxWindow *child = (wxWindow *) NULL;
db1b4961 455 for(wxNode *node = GetChildren().First(); node; node = node->Next())
e52f60e6
RR
456 {
457 wxWindow *win = (wxWindow *)node->Data();
de135918 458 if (!wxIS_KIND_OF(win,wxFrame) && !wxIS_KIND_OF(win,wxDialog))
e52f60e6 459 {
de8113d9 460 /* it's the second one: do nothing */
e52f60e6
RR
461 if (child) return;
462 child = win;
463 }
464 }
465
de8113d9 466 /* yes: set it's size to fill all the frame */
e52f60e6
RR
467 int client_x, client_y;
468 GetClientSize( &client_x, &client_y );
469 child->SetSize( 1, 1, client_x-2, client_y);
470 }
471}
472
23efdd02
RR
473void wxDialog::DoMoveWindow(int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(width), int WXUNUSED(height) )
474{
475 wxFAIL_MSG( wxT("DoMoveWindow called for wxDialog") );
476}
477
bfc6fde4 478void wxDialog::DoSetSize( int x, int y, int width, int height, int sizeFlags )
903f689b 479{
223d09f6
KB
480 wxASSERT_MSG( (m_widget != NULL), wxT("invalid dialog") );
481 wxASSERT_MSG( (m_wxwindow != NULL), wxT("invalid dialog") );
fb1585ae 482
de8113d9 483 if (m_resizing) return; /* I don't like recursions */
fb1585ae
RR
484 m_resizing = TRUE;
485
486 int old_x = m_x;
487 int old_y = m_y;
7beba2fc 488
fb1585ae
RR
489 int old_width = m_width;
490 int old_height = m_height;
2b854a32 491
85ad5eb5 492 if ((sizeFlags & wxSIZE_ALLOW_MINUS_ONE) == 0)
fb1585ae
RR
493 {
494 if (x != -1) m_x = x;
495 if (y != -1) m_y = y;
496 if (width != -1) m_width = width;
497 if (height != -1) m_height = height;
498 }
499 else
500 {
501 m_x = x;
502 m_y = y;
503 m_width = width;
504 m_height = height;
505 }
506
11e1c70d 507/*
fb1585ae
RR
508 if ((sizeFlags & wxSIZE_AUTO_WIDTH) == wxSIZE_AUTO_WIDTH)
509 {
510 if (width == -1) m_width = 80;
511 }
512
513 if ((sizeFlags & wxSIZE_AUTO_HEIGHT) == wxSIZE_AUTO_HEIGHT)
514 {
515 if (height == -1) m_height = 26;
516 }
11e1c70d 517*/
2b854a32 518
fb1585ae
RR
519 if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth;
520 if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight;
0c77152e
RR
521 if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_maxWidth;
522 if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_maxHeight;
fb1585ae
RR
523
524 if ((m_x != -1) || (m_y != -1))
525 {
2b854a32 526 if ((m_x != old_x) || (m_y != old_y))
f03fc89f
VZ
527 {
528 /* we set the position here and when showing the dialog
529 for the first time in idle time */
8487f887 530 gtk_widget_set_uposition( m_widget, m_x, m_y );
f03fc89f 531 }
fb1585ae 532 }
2b854a32 533
fb1585ae
RR
534 if ((m_width != old_width) || (m_height != old_height))
535 {
227e5e99 536 /* actual resizing is deferred to GtkOnSize in idle time and
f03fc89f 537 when showing the dialog */
de8113d9 538 m_sizeSet = FALSE;
fb1585ae 539 }
2b854a32 540
fb1585ae 541 m_resizing = FALSE;
903f689b
RR
542}
543
de8113d9
RR
544void wxDialog::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int height )
545{
546 // due to a bug in gtk, x,y are always 0
547 // m_x = x;
548 // m_y = y;
549
550 if ((m_height == height) && (m_width == width) && (m_sizeSet)) return;
551 if (!m_wxwindow) return;
552
553 m_width = width;
554 m_height = height;
555
556 if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth;
557 if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight;
558 if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_maxWidth;
559 if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_maxHeight;
560
561 /* we actually set the size of a frame here and no-where else */
562 gtk_widget_set_usize( m_widget, m_width, m_height );
563
564 m_sizeSet = TRUE;
565
566 wxSizeEvent event( wxSize(m_width,m_height), GetId() );
567 event.SetEventObject( this );
568 GetEventHandler()->ProcessEvent( event );
569}
903f689b 570
de8113d9
RR
571void wxDialog::OnInternalIdle()
572{
1b3667ab 573 if (!m_sizeSet && GTK_WIDGET_REALIZED(m_wxwindow))
de8113d9 574 GtkOnSize( m_x, m_y, m_width, m_height );
5e014a0c
RR
575
576 wxWindow::OnInternalIdle();
de8113d9
RR
577}
578
debe6624 579bool wxDialog::Show( bool show )
c801d85f 580{
fb1585ae
RR
581 if (!show && IsModal())
582 {
de8113d9 583 EndModal( wxID_CANCEL );
fb1585ae 584 }
c801d85f 585
de8113d9
RR
586 if (show && !m_sizeSet)
587 {
588 /* by calling GtkOnSize here, we don't have to call
589 either after showing the frame, which would entail
590 much ugly flicker nor from within the size_allocate
591 handler, because GTK 1.1.X forbids that. */
592
593 GtkOnSize( m_x, m_y, m_width, m_height );
594 }
2b854a32 595
739730ca 596 bool ret = wxWindow::Show( show );
e146b8c8 597
fb1585ae 598 if (show) InitDialog();
2b854a32 599
739730ca 600 return ret;
c33c4050
RR
601}
602
43a18898 603bool wxDialog::IsModal() const
e1e955e1 604{
fb1585ae 605 return m_modalShowing;
e1e955e1
RR
606}
607
608void wxDialog::SetModal( bool WXUNUSED(flag) )
c33c4050 609{
e1e955e1 610/*
c33c4050
RR
611 if (flag)
612 m_windowStyle |= wxDIALOG_MODAL;
613 else
614 if (m_windowStyle & wxDIALOG_MODAL) m_windowStyle -= wxDIALOG_MODAL;
e1e955e1 615*/
223d09f6 616 wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") );
c33c4050 617}
c801d85f 618
43a18898 619int wxDialog::ShowModal()
c801d85f 620{
fb1585ae
RR
621 if (IsModal())
622 {
223d09f6 623 wxFAIL_MSG( wxT("wxDialog:ShowModal called twice") );
fb1585ae
RR
624 return GetReturnCode();
625 }
e146b8c8 626
eebe4016 627 wxBusyCursorSuspender cs; // temporarily suppress the busy cursor
7e14e49f 628
fb1585ae 629 Show( TRUE );
2b854a32 630
fb1585ae 631 m_modalShowing = TRUE;
2b854a32 632
fb1585ae
RR
633 gtk_grab_add( m_widget );
634 gtk_main();
635 gtk_grab_remove( m_widget );
2b854a32 636
fb1585ae 637 return GetReturnCode();
c33c4050 638}
c801d85f
KB
639
640void wxDialog::EndModal( int retCode )
641{
fb1585ae 642 SetReturnCode( retCode );
2b854a32 643
fb1585ae
RR
644 if (!IsModal())
645 {
223d09f6 646 wxFAIL_MSG( wxT("wxDialog:EndModal called twice") );
fb1585ae
RR
647 return;
648 }
2b854a32 649
fb1585ae 650 m_modalShowing = FALSE;
2b854a32 651
fb1585ae 652 gtk_main_quit();
2b854a32 653
fb1585ae 654 Show( FALSE );
c33c4050 655}
c801d85f 656
43a18898 657void wxDialog::InitDialog()
c801d85f 658{
fb1585ae 659 wxWindow::InitDialog();
c33c4050
RR
660}
661
c33c4050
RR
662void wxDialog::SetIcon( const wxIcon &icon )
663{
fb1585ae
RR
664 m_icon = icon;
665 if (!icon.Ok()) return;
2b854a32 666
f9241296
RR
667 if (!m_widget->window) return;
668
fb1585ae
RR
669 wxMask *mask = icon.GetMask();
670 GdkBitmap *bm = (GdkBitmap *) NULL;
671 if (mask) bm = mask->GetBitmap();
2b854a32 672
fb1585ae 673 gdk_window_set_icon( m_widget->window, (GdkWindow *) NULL, icon.GetPixmap(), bm );
c33c4050 674}