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
);
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
);
106 wxDialog::~wxDialog(void)
108 wxTopLevelWindows
.DeleteObject( this );
109 if (wxTopLevelWindows
.Number() == 0) wxTheApp
->ExitMainLoop();
112 void wxDialog::SetTitle(const wxString
& title
)
115 if (m_title
.IsNull()) m_title
= "";
116 gtk_window_set_title( GTK_WINDOW(m_widget
), m_title
);
119 wxString
wxDialog::GetTitle(void) const
121 return (wxString
&)m_title
;
124 void wxDialog::OnApply( wxCommandEvent
&WXUNUSED(event
) )
126 if (Validate()) TransferDataFromWindow();
129 void wxDialog::OnCancel( wxCommandEvent
&WXUNUSED(event
) )
133 EndModal(wxID_CANCEL
);
137 SetReturnCode(wxID_CANCEL
);
142 void wxDialog::OnOK( wxCommandEvent
&WXUNUSED(event
) )
144 if ( Validate() && TransferDataFromWindow())
152 SetReturnCode(wxID_OK
);
158 void wxDialog::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
163 bool wxDialog::OnClose(void)
165 static wxList closing
;
167 if (closing
.Member(this)) return FALSE
; // no loops
169 closing
.Append(this);
171 wxCommandEvent
cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
172 cancelEvent
.SetEventObject( this );
173 GetEventHandler()->ProcessEvent(cancelEvent
);
174 closing
.DeleteObject(this);
179 bool wxDialog::Destroy(void)
181 if (!wxPendingDelete
.Member(this))
182 wxPendingDelete
.Append(this);
187 void wxDialog::OnCloseWindow(wxCloseEvent
& event
)
189 if (GetEventHandler()->OnClose() || event
.GetForce())
195 void wxDialog::ImplementSetPosition(void)
197 if ((m_x
!= -1) || (m_y
!= -1))
198 gtk_widget_set_uposition( m_widget
, m_x
, m_y
);
201 void wxDialog::Centre( int direction
)
203 if (direction
& wxHORIZONTAL
== wxHORIZONTAL
) m_x
= (gdk_screen_width () - m_width
) / 2;
204 if (direction
& wxVERTICAL
== wxVERTICAL
) m_y
= (gdk_screen_height () - m_height
) / 2;
205 ImplementSetPosition();
208 bool wxDialog::Show( bool show
)
210 if (!show
&& IsModal() && m_modalShowing
)
212 EndModal( wxID_CANCEL
);
215 wxWindow::Show( show
);
217 if (show
) InitDialog();
222 void wxDialog::SetModal(bool flag
)
225 m_windowStyle
|= wxDIALOG_MODAL
;
227 if (m_windowStyle
& wxDIALOG_MODAL
) m_windowStyle
-= wxDIALOG_MODAL
;
230 int wxDialog::ShowModal(void)
232 if (m_modalShowing
) return GetReturnCode();
236 m_modalShowing
= TRUE
;
238 gtk_grab_add( m_widget
);
240 gtk_grab_remove( m_widget
);
242 return GetReturnCode();
245 void wxDialog::EndModal( int retCode
)
247 SetReturnCode( retCode
);
251 wxFAIL_MSG( "wxDialog: called EndModal twice" );
255 m_modalShowing
= FALSE
;
260 void wxDialog::InitDialog(void)
262 wxWindow::InitDialog();
265 void wxDialog::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int WXUNUSED(incW
) )
267 gdk_window_set_hints( m_widget
->window
, -1, -1,
268 minW
, minH
, maxW
, maxH
, GDK_HINT_MIN_SIZE
| GDK_HINT_MIN_SIZE
);
271 void wxDialog::SetIcon( const wxIcon
&icon
)
274 if (!icon
.Ok()) return;
276 wxMask
*mask
= icon
.GetMask();
277 GdkBitmap
*bm
= NULL
;
278 if (mask
) bm
= mask
->GetBitmap();
280 gdk_window_set_icon( m_widget
->window
, NULL
, icon
.GetPixmap(), bm
);