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 //-----------------------------------------------------------------------------
23 bool gtk_dialog_delete_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxDialog
*win
)
26 printf( "OnDelete from " );
27 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
28 printf( win->GetClassInfo()->GetClassName() );
37 //-----------------------------------------------------------------------------
39 //-----------------------------------------------------------------------------
41 BEGIN_EVENT_TABLE(wxDialog
,wxWindow
)
42 EVT_BUTTON (wxID_OK
, wxDialog::OnOk
)
43 EVT_BUTTON (wxID_CANCEL
, wxDialog::OnCancel
)
44 EVT_BUTTON (wxID_APPLY
, wxDialog::OnApply
)
45 EVT_CLOSE (wxDialog::OnCloseWindow
)
48 IMPLEMENT_DYNAMIC_CLASS(wxDialog
,wxWindow
)
50 wxDialog::wxDialog(void)
53 m_modalShowing
= TRUE
;
54 wxTopLevelWindows
.Insert( this );
57 wxDialog::wxDialog( wxWindow
*parent
,
58 wxWindowID id
, const wxString
&title
,
59 const wxPoint
&pos
, const wxSize
&size
,
60 long style
, const wxString
&name
)
62 wxTopLevelWindows
.Insert( this );
63 Create( parent
, id
, title
, pos
, size
, style
, name
);
66 bool wxDialog::Create( wxWindow
*parent
,
67 wxWindowID id
, const wxString
&title
,
68 const wxPoint
&pos
, const wxSize
&size
,
69 long style
, const wxString
&name
)
73 PreCreation( parent
, id
, pos
, size
, style
, name
);
75 m_modalShowing
= ((m_windowStyle
& wxDIALOG_MODAL
) == wxDIALOG_MODAL
);
77 m_widget
= gtk_window_new( GTK_WINDOW_TOPLEVEL
);
78 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
80 gtk_widget_set( m_widget
, "GtkWindow::allow_shrink", TRUE
, NULL
);
82 gtk_signal_connect( GTK_OBJECT(m_widget
), "delete_event",
83 GTK_SIGNAL_FUNC(gtk_dialog_delete_callback
), (gpointer
)this );
85 m_wxwindow
= gtk_myfixed_new();
86 gtk_widget_show( m_wxwindow
);
87 GTK_WIDGET_UNSET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
89 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
98 wxDialog::~wxDialog(void)
100 wxTopLevelWindows
.DeleteObject( this );
101 if (wxTopLevelWindows
.Number() == 0) wxTheApp
->ExitMainLoop();
104 void wxDialog::SetTitle(const wxString
& title
)
107 gtk_window_set_title( GTK_WINDOW(m_widget
), m_title
);
110 wxString
wxDialog::GetTitle(void) const
112 return (wxString
&)m_title
;
115 void wxDialog::OnApply( wxCommandEvent
&WXUNUSED(event
) )
117 if (Validate()) TransferDataFromWindow();
120 void wxDialog::OnCancel( wxCommandEvent
&WXUNUSED(event
) )
124 EndModal(wxID_CANCEL
);
128 SetReturnCode(wxID_CANCEL
);
133 void wxDialog::OnOk( wxCommandEvent
&WXUNUSED(event
) )
135 if ( Validate() && TransferDataFromWindow())
143 SetReturnCode(wxID_OK
);
149 void wxDialog::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
154 bool wxDialog::OnClose(void)
156 static wxList closing
;
158 if (closing
.Member(this)) return FALSE
; // no loops
160 closing
.Append(this);
162 wxCommandEvent
cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
163 cancelEvent
.SetEventObject( this );
164 GetEventHandler()->ProcessEvent(cancelEvent
);
165 closing
.DeleteObject(this);
170 void wxDialog::OnCloseWindow(wxCloseEvent
& event
)
172 if (GetEventHandler()->OnClose() || event
.GetForce())
178 bool wxDialog::Show( bool show
)
180 if (!show
&& m_modalShowing
)
182 EndModal( wxID_CANCEL
);
185 wxWindow::Show( show
);
187 if (show
) InitDialog();
189 if (show
&& m_modalShowing
)
191 gtk_grab_add( m_widget
);
193 gtk_grab_remove( m_widget
);
199 int wxDialog::ShowModal(void)
202 return GetReturnCode();
205 void wxDialog::EndModal( int retCode
)
208 SetReturnCode( retCode
);
211 void wxDialog::InitDialog(void)
213 wxWindow::InitDialog();