1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "dialog.h"
15 #include "wx/dialog.h"
18 #include "wx/gtk/win_gtk.h"
20 //-----------------------------------------------------------------------------
22 extern wxList wxPendingDelete
;
24 //-----------------------------------------------------------------------------
27 bool gtk_dialog_delete_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxDialog
*win
)
30 printf( "OnDelete from " );
31 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
32 printf( win->GetClassInfo()->GetClassName() );
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
45 BEGIN_EVENT_TABLE(wxDialog
,wxWindow
)
46 EVT_BUTTON (wxID_OK
, wxDialog::OnOk
)
47 EVT_BUTTON (wxID_CANCEL
, wxDialog::OnCancel
)
48 EVT_BUTTON (wxID_APPLY
, wxDialog::OnApply
)
49 EVT_CLOSE (wxDialog::OnCloseWindow
)
52 IMPLEMENT_DYNAMIC_CLASS(wxDialog
,wxWindow
)
54 wxDialog::wxDialog(void)
57 m_modalShowing
= TRUE
;
58 wxTopLevelWindows
.Insert( this );
61 wxDialog::wxDialog( wxWindow
*parent
,
62 wxWindowID id
, const wxString
&title
,
63 const wxPoint
&pos
, const wxSize
&size
,
64 long style
, const wxString
&name
)
66 wxTopLevelWindows
.Insert( this );
67 Create( parent
, id
, title
, pos
, size
, style
, name
);
70 bool wxDialog::Create( wxWindow
*parent
,
71 wxWindowID id
, const wxString
&title
,
72 const wxPoint
&pos
, const wxSize
&size
,
73 long style
, const wxString
&name
)
77 PreCreation( parent
, id
, pos
, size
, style
, name
);
79 m_modalShowing
= ((m_windowStyle
& wxDIALOG_MODAL
) == wxDIALOG_MODAL
);
81 m_widget
= gtk_window_new( GTK_WINDOW_TOPLEVEL
);
82 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
84 gtk_widget_set( m_widget
, "GtkWindow::allow_shrink", TRUE
, NULL
);
86 gtk_signal_connect( GTK_OBJECT(m_widget
), "delete_event",
87 GTK_SIGNAL_FUNC(gtk_dialog_delete_callback
), (gpointer
)this );
89 m_wxwindow
= gtk_myfixed_new();
90 gtk_widget_show( m_wxwindow
);
91 GTK_WIDGET_UNSET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
93 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
102 wxDialog::~wxDialog(void)
104 wxTopLevelWindows
.DeleteObject( this );
105 if (wxTopLevelWindows
.Number() == 0) wxTheApp
->ExitMainLoop();
108 void wxDialog::SetTitle(const wxString
& title
)
111 gtk_window_set_title( GTK_WINDOW(m_widget
), m_title
);
114 wxString
wxDialog::GetTitle(void) const
116 return (wxString
&)m_title
;
119 void wxDialog::OnApply( wxCommandEvent
&WXUNUSED(event
) )
121 if (Validate()) TransferDataFromWindow();
124 void wxDialog::OnCancel( wxCommandEvent
&WXUNUSED(event
) )
128 EndModal(wxID_CANCEL
);
132 SetReturnCode(wxID_CANCEL
);
137 void wxDialog::OnOk( wxCommandEvent
&WXUNUSED(event
) )
139 if ( Validate() && TransferDataFromWindow())
147 SetReturnCode(wxID_OK
);
153 void wxDialog::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
158 bool wxDialog::OnClose(void)
160 static wxList closing
;
162 if (closing
.Member(this)) return FALSE
; // no loops
164 closing
.Append(this);
166 wxCommandEvent
cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
167 cancelEvent
.SetEventObject( this );
168 GetEventHandler()->ProcessEvent(cancelEvent
);
169 closing
.DeleteObject(this);
174 bool wxDialog::Destroy(void)
176 if (!wxPendingDelete
.Member(this))
177 wxPendingDelete
.Append(this);
182 void wxDialog::OnCloseWindow(wxCloseEvent
& event
)
184 if (GetEventHandler()->OnClose() || event
.GetForce())
190 bool wxDialog::Show( bool show
)
192 if (!show
&& m_modalShowing
)
194 EndModal( wxID_CANCEL
);
197 wxWindow::Show( show
);
199 if (show
) InitDialog();
201 if (show
&& m_modalShowing
)
203 gtk_grab_add( m_widget
);
205 gtk_grab_remove( m_widget
);
211 int wxDialog::ShowModal(void)
214 return GetReturnCode();
217 void wxDialog::EndModal( int retCode
)
219 SetReturnCode( retCode
);
223 void wxDialog::InitDialog(void)
225 wxWindow::InitDialog();