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)) wxPendingDelete
.Append(this);
189 void wxDialog::OnCloseWindow(wxCloseEvent
& event
)
191 if (GetEventHandler()->OnClose() || event
.GetForce())
197 void wxDialog::SetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
199 wxASSERT_MSG( (m_widget
!= NULL
), "invalid window" );
201 // Don't do anything for children of wxMDIChildFrame
202 if (!m_wxwindow
) return;
204 if (m_resizing
) return; // I don't like recursions
209 int old_width
= m_width
;
210 int old_height
= m_height
;
212 if ((sizeFlags
& wxSIZE_USE_EXISTING
) == wxSIZE_USE_EXISTING
)
214 if (x
!= -1) m_x
= x
;
215 if (y
!= -1) m_y
= y
;
216 if (width
!= -1) m_width
= width
;
217 if (height
!= -1) m_height
= height
;
227 if ((sizeFlags
& wxSIZE_AUTO_WIDTH
) == wxSIZE_AUTO_WIDTH
)
229 if (width
== -1) m_width
= 80;
232 if ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) == wxSIZE_AUTO_HEIGHT
)
234 if (height
== -1) m_height
= 26;
237 if ((m_minWidth
!= -1) && (m_width
< m_minWidth
)) m_width
= m_minWidth
;
238 if ((m_minHeight
!= -1) && (m_height
< m_minHeight
)) m_height
= m_minHeight
;
239 if ((m_maxWidth
!= -1) && (m_width
> m_maxWidth
)) m_width
= m_minWidth
;
240 if ((m_maxHeight
!= -1) && (m_height
> m_maxHeight
)) m_height
= m_minHeight
;
242 if ((m_x
!= -1) || (m_y
!= -1))
244 if ((m_x
!= old_x
) || (m_y
!= old_y
))
245 gtk_widget_set_uposition( m_widget
, m_x
, m_y
);
248 if ((m_width
!= old_width
) || (m_height
!= old_height
))
250 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
255 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
256 event
.SetEventObject( this );
257 ProcessEvent( event
);
262 void wxDialog::Centre( int direction
)
264 wxASSERT_MSG( (m_widget
!= NULL
), "invalid frame" );
268 if (direction
& wxHORIZONTAL
== wxHORIZONTAL
) x
= (gdk_screen_width () - m_width
) / 2;
269 if (direction
& wxVERTICAL
== wxVERTICAL
) y
= (gdk_screen_height () - m_height
) / 2;
274 bool wxDialog::Show( bool show
)
276 if (!show
&& IsModal())
278 EndModal( wxID_CANCEL
);
281 wxWindow::Show( show
);
283 if (show
) InitDialog();
288 bool wxDialog::IsModal(void) const
290 return m_modalShowing
;
293 void wxDialog::SetModal( bool WXUNUSED(flag
) )
297 m_windowStyle |= wxDIALOG_MODAL;
299 if (m_windowStyle & wxDIALOG_MODAL) m_windowStyle -= wxDIALOG_MODAL;
301 wxFAIL_MSG( "wxDialog:SetModal obsolete now" );
304 int wxDialog::ShowModal(void)
308 wxFAIL_MSG( "wxDialog:ShowModal called twice" );
309 return GetReturnCode();
314 m_modalShowing
= TRUE
;
316 gtk_grab_add( m_widget
);
318 gtk_grab_remove( m_widget
);
320 return GetReturnCode();
323 void wxDialog::EndModal( int retCode
)
325 SetReturnCode( retCode
);
329 wxFAIL_MSG( "wxDialog:EndModal called twice" );
333 m_modalShowing
= FALSE
;
340 void wxDialog::InitDialog(void)
342 wxWindow::InitDialog();
345 void wxDialog::SetIcon( const wxIcon
&icon
)
348 if (!icon
.Ok()) return;
350 wxMask
*mask
= icon
.GetMask();
351 GdkBitmap
*bm
= (GdkBitmap
*) NULL
;
352 if (mask
) bm
= mask
->GetBitmap();
354 gdk_window_set_icon( m_widget
->window
, (GdkWindow
*) NULL
, icon
.GetPixmap(), bm
);