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 const 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 const 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
) )
123 EndModal(wxID_CANCEL
);
126 SetReturnCode(wxID_CANCEL
);
131 void wxDialog::OnOk( wxCommandEvent
&WXUNUSED(event
) )
133 if ( Validate() && TransferDataFromWindow())
139 SetReturnCode(wxID_OK
);
146 void wxDialog::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
151 bool wxDialog::OnClose(void)
153 static wxList closing
;
155 if (closing
.Member(this)) return FALSE
; // no loops
157 closing
.Append(this);
159 wxCommandEvent
cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
160 cancelEvent
.SetEventObject( this );
161 GetEventHandler()->ProcessEvent(cancelEvent
);
162 closing
.DeleteObject(this);
167 void wxDialog::OnCloseWindow(wxCloseEvent
& event
)
169 if (GetEventHandler()->OnClose() || event
.GetForce())
175 bool wxDialog::Show( const bool show
)
177 if (!show
&& m_modalShowing
)
179 EndModal( wxID_CANCEL
);
182 wxWindow::Show( show
);
184 if (show
) InitDialog();
186 if (show
&& m_modalShowing
)
188 gtk_grab_add( m_widget
);
190 gtk_grab_remove( m_widget
);
196 int wxDialog::ShowModal(void)
199 return GetReturnCode();
202 void wxDialog::EndModal( int retCode
)
205 SetReturnCode( retCode
);
208 void wxDialog::InitDialog(void)
210 wxWindow::InitDialog();