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 //-----------------------------------------------------------------------------
26 //-----------------------------------------------------------------------------
28 bool gtk_dialog_delete_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxDialog
*win
)
31 printf( "OnDelete from " );
32 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
33 printf( win->GetClassInfo()->GetClassName() );
42 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
46 BEGIN_EVENT_TABLE(wxDialog
,wxPanel
)
47 EVT_BUTTON (wxID_OK
, wxDialog::OnOK
)
48 EVT_BUTTON (wxID_CANCEL
, wxDialog::OnCancel
)
49 EVT_BUTTON (wxID_APPLY
, wxDialog::OnApply
)
50 EVT_CLOSE (wxDialog::OnCloseWindow
)
53 IMPLEMENT_DYNAMIC_CLASS(wxDialog
,wxPanel
)
55 wxDialog::wxDialog(void)
58 m_modalShowing
= FALSE
;
59 wxTopLevelWindows
.Insert( this );
62 wxDialog::wxDialog( wxWindow
*parent
,
63 wxWindowID id
, const wxString
&title
,
64 const wxPoint
&pos
, const wxSize
&size
,
65 long style
, const wxString
&name
)
67 m_modalShowing
= FALSE
;
68 wxTopLevelWindows
.Insert( this );
69 Create( parent
, id
, title
, pos
, size
, style
, name
);
72 bool wxDialog::Create( wxWindow
*parent
,
73 wxWindowID id
, const wxString
&title
,
74 const wxPoint
&pos
, const wxSize
&size
,
75 long style
, const wxString
&name
)
79 PreCreation( parent
, id
, pos
, size
, style
, name
);
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
);
97 if ((m_x
!= -1) || (m_y
!= -1))
98 gtk_widget_set_uposition( m_widget
, m_x
, m_y
);
100 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
107 wxDialog::~wxDialog(void)
109 wxTopLevelWindows
.DeleteObject( this );
110 if (wxTopLevelWindows
.Number() == 0) wxTheApp
->ExitMainLoop();
113 void wxDialog::SetTitle(const wxString
& title
)
116 if (m_title
.IsNull()) m_title
= "";
117 gtk_window_set_title( GTK_WINDOW(m_widget
), m_title
);
120 wxString
wxDialog::GetTitle(void) const
122 return (wxString
&)m_title
;
125 void wxDialog::OnApply( wxCommandEvent
&WXUNUSED(event
) )
127 if (Validate()) TransferDataFromWindow();
130 void wxDialog::OnCancel( wxCommandEvent
&WXUNUSED(event
) )
134 EndModal(wxID_CANCEL
);
138 SetReturnCode(wxID_CANCEL
);
143 void wxDialog::OnOK( wxCommandEvent
&WXUNUSED(event
) )
145 if ( Validate() && TransferDataFromWindow())
153 SetReturnCode(wxID_OK
);
159 void wxDialog::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
164 bool wxDialog::OnClose(void)
166 static wxList closing
;
168 if (closing
.Member(this)) return FALSE
; // no loops
170 closing
.Append(this);
172 wxCommandEvent
cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
173 cancelEvent
.SetEventObject( this );
174 GetEventHandler()->ProcessEvent(cancelEvent
);
175 closing
.DeleteObject(this);
180 bool wxDialog::Destroy(void)
182 if (!wxPendingDelete
.Member(this))
183 wxPendingDelete
.Append(this);
188 void wxDialog::OnCloseWindow(wxCloseEvent
& event
)
190 if (GetEventHandler()->OnClose() || event
.GetForce())
196 void wxDialog::ImplementSetPosition(void)
198 if ((m_x
!= -1) || (m_y
!= -1))
199 gtk_widget_set_uposition( m_widget
, m_x
, m_y
);
202 void wxDialog::Centre( int direction
)
204 if (direction
& wxHORIZONTAL
== wxHORIZONTAL
) m_x
= (gdk_screen_width () - m_width
) / 2;
205 if (direction
& wxVERTICAL
== wxVERTICAL
) m_y
= (gdk_screen_height () - m_height
) / 2;
206 ImplementSetPosition();
209 bool wxDialog::Show( bool show
)
211 if (!show
&& IsModal())
213 EndModal( wxID_CANCEL
);
216 wxWindow::Show( show
);
218 if (show
) InitDialog();
223 bool wxDialog::IsModal(void) const
225 return m_modalShowing
;
228 void wxDialog::SetModal( bool WXUNUSED(flag
) )
232 m_windowStyle |= wxDIALOG_MODAL;
234 if (m_windowStyle & wxDIALOG_MODAL) m_windowStyle -= wxDIALOG_MODAL;
236 wxFAIL_MSG( "wxDialog:SetModal obsolete now" );
239 int wxDialog::ShowModal(void)
243 wxFAIL_MSG( "wxDialog:ShowModal called twice" );
244 return GetReturnCode();
249 m_modalShowing
= TRUE
;
251 gtk_grab_add( m_widget
);
253 gtk_grab_remove( m_widget
);
255 return GetReturnCode();
258 void wxDialog::EndModal( int retCode
)
260 SetReturnCode( retCode
);
264 wxFAIL_MSG( "wxDialog:EndModal called twice" );
268 m_modalShowing
= FALSE
;
275 void wxDialog::InitDialog(void)
277 wxWindow::InitDialog();
280 void wxDialog::SetIcon( const wxIcon
&icon
)
283 if (!icon
.Ok()) return;
285 wxMask
*mask
= icon
.GetMask();
286 GdkBitmap
*bm
= (GdkBitmap
*) NULL
;
287 if (mask
) bm
= mask
->GetBitmap();
289 gdk_window_set_icon( m_widget
->window
, (GdkWindow
*) NULL
, icon
.GetPixmap(), bm
);