1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "dialog.h"
14 #include "wx/dialog.h"
17 #include "wx/gtk/win_gtk.h"
19 //-----------------------------------------------------------------------------
21 extern wxList wxPendingDelete
;
23 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
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
,wxPanel
)
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
,wxPanel
)
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
);
96 if ((m_x
!= -1) || (m_y
!= -1))
97 gtk_widget_set_uposition( m_widget
, m_x
, m_y
);
99 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
101 if (m_parent
) m_parent
->AddChild( this );
109 wxDialog::~wxDialog(void)
111 wxTopLevelWindows
.DeleteObject( this );
112 if (wxTopLevelWindows
.Number() == 0) wxTheApp
->ExitMainLoop();
115 void wxDialog::SetTitle(const wxString
& title
)
118 if (m_title
.IsNull()) m_title
= "";
119 gtk_window_set_title( GTK_WINDOW(m_widget
), m_title
);
122 wxString
wxDialog::GetTitle(void) const
124 return (wxString
&)m_title
;
127 void wxDialog::OnApply( wxCommandEvent
&WXUNUSED(event
) )
129 if (Validate()) TransferDataFromWindow();
132 void wxDialog::OnCancel( wxCommandEvent
&WXUNUSED(event
) )
136 EndModal(wxID_CANCEL
);
140 SetReturnCode(wxID_CANCEL
);
145 void wxDialog::OnOK( wxCommandEvent
&WXUNUSED(event
) )
147 if ( Validate() && TransferDataFromWindow())
155 SetReturnCode(wxID_OK
);
161 void wxDialog::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
166 bool wxDialog::OnClose(void)
168 static wxList closing
;
170 if (closing
.Member(this)) return FALSE
; // no loops
172 closing
.Append(this);
174 wxCommandEvent
cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
175 cancelEvent
.SetEventObject( this );
176 GetEventHandler()->ProcessEvent(cancelEvent
);
177 closing
.DeleteObject(this);
182 bool wxDialog::Destroy(void)
184 if (!wxPendingDelete
.Member(this))
185 wxPendingDelete
.Append(this);
190 void wxDialog::OnCloseWindow(wxCloseEvent
& event
)
192 if (GetEventHandler()->OnClose() || event
.GetForce())
198 void wxDialog::ImplementSetPosition(void)
200 if ((m_x
!= -1) || (m_y
!= -1))
201 gtk_widget_set_uposition( m_widget
, m_x
, m_y
);
204 void wxDialog::Centre( int direction
)
206 if (direction
& wxHORIZONTAL
== wxHORIZONTAL
) m_x
= (gdk_screen_width () - m_width
) / 2;
207 if (direction
& wxVERTICAL
== wxVERTICAL
) m_y
= (gdk_screen_height () - m_height
) / 2;
208 ImplementSetPosition();
211 bool wxDialog::Show( bool show
)
213 if (!show
&& IsModal())
215 EndModal( wxID_CANCEL
);
218 wxWindow::Show( show
);
220 if (show
) InitDialog();
225 bool wxDialog::IsModal(void) const
227 return m_modalShowing
;
230 void wxDialog::SetModal( bool WXUNUSED(flag
) )
234 m_windowStyle |= wxDIALOG_MODAL;
236 if (m_windowStyle & wxDIALOG_MODAL) m_windowStyle -= wxDIALOG_MODAL;
238 wxFAIL_MSG( "wxDialog:SetModal obsolete now" );
241 int wxDialog::ShowModal(void)
245 wxFAIL_MSG( "wxDialog:ShowModal called twice" );
246 return GetReturnCode();
251 m_modalShowing
= TRUE
;
253 gtk_grab_add( m_widget
);
255 gtk_grab_remove( m_widget
);
257 return GetReturnCode();
260 void wxDialog::EndModal( int retCode
)
262 SetReturnCode( retCode
);
266 wxFAIL_MSG( "wxDialog:EndModal called twice" );
270 m_modalShowing
= FALSE
;
277 void wxDialog::InitDialog(void)
279 wxWindow::InitDialog();
282 void wxDialog::SetIcon( const wxIcon
&icon
)
285 if (!icon
.Ok()) return;
287 wxMask
*mask
= icon
.GetMask();
288 GdkBitmap
*bm
= (GdkBitmap
*) NULL
;
289 if (mask
) bm
= mask
->GetBitmap();
291 gdk_window_set_icon( m_widget
->window
, (GdkWindow
*) NULL
, icon
.GetPixmap(), bm
);