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
= FALSE
;
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 m_modalShowing
= FALSE
;
67 wxTopLevelWindows
.Insert( this );
68 Create( parent
, id
, title
, pos
, size
, style
, name
);
71 bool wxDialog::Create( wxWindow
*parent
,
72 wxWindowID id
, const wxString
&title
,
73 const wxPoint
&pos
, const wxSize
&size
,
74 long style
, const wxString
&name
)
78 PreCreation( parent
, id
, pos
, size
, style
, name
);
80 m_widget
= gtk_window_new( GTK_WINDOW_TOPLEVEL
);
81 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
83 gtk_widget_set( m_widget
, "GtkWindow::allow_shrink", TRUE
, NULL
);
85 gtk_signal_connect( GTK_OBJECT(m_widget
), "delete_event",
86 GTK_SIGNAL_FUNC(gtk_dialog_delete_callback
), (gpointer
)this );
88 m_wxwindow
= gtk_myfixed_new();
89 gtk_widget_show( m_wxwindow
);
90 GTK_WIDGET_UNSET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
92 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
101 wxDialog::~wxDialog(void)
103 wxTopLevelWindows
.DeleteObject( this );
104 if (wxTopLevelWindows
.Number() == 0) wxTheApp
->ExitMainLoop();
107 void wxDialog::SetTitle(const wxString
& title
)
110 gtk_window_set_title( GTK_WINDOW(m_widget
), m_title
);
113 wxString
wxDialog::GetTitle(void) const
115 return (wxString
&)m_title
;
118 void wxDialog::OnApply( wxCommandEvent
&WXUNUSED(event
) )
120 if (Validate()) TransferDataFromWindow();
123 void wxDialog::OnCancel( wxCommandEvent
&WXUNUSED(event
) )
127 EndModal(wxID_CANCEL
);
131 SetReturnCode(wxID_CANCEL
);
136 void wxDialog::OnOk( wxCommandEvent
&WXUNUSED(event
) )
138 if ( Validate() && TransferDataFromWindow())
146 SetReturnCode(wxID_OK
);
152 void wxDialog::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
157 bool wxDialog::OnClose(void)
159 static wxList closing
;
161 if (closing
.Member(this)) return FALSE
; // no loops
163 closing
.Append(this);
165 wxCommandEvent
cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
166 cancelEvent
.SetEventObject( this );
167 GetEventHandler()->ProcessEvent(cancelEvent
);
168 closing
.DeleteObject(this);
173 bool wxDialog::Destroy(void)
175 if (!wxPendingDelete
.Member(this))
176 wxPendingDelete
.Append(this);
181 void wxDialog::OnCloseWindow(wxCloseEvent
& event
)
183 if (GetEventHandler()->OnClose() || event
.GetForce())
189 bool wxDialog::Show( bool show
)
191 if (!show
&& IsModal() && m_modalShowing
)
193 EndModal( wxID_CANCEL
);
196 wxWindow::Show( show
);
198 if (show
) InitDialog();
203 int wxDialog::ShowModal(void)
205 if (m_modalShowing
) return GetReturnCode();
209 m_modalShowing
= TRUE
;
211 gtk_grab_add( m_widget
);
213 gtk_grab_remove( m_widget
);
215 return GetReturnCode();
218 void wxDialog::EndModal( int retCode
)
220 SetReturnCode( retCode
);
222 if (!m_modalShowing
) return;
223 m_modalShowing
= FALSE
;
228 void wxDialog::InitDialog(void)
230 wxWindow::InitDialog();