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/cursor.h"
21 #include <gdk/gdkkeysyms.h>
23 #include "wx/gtk/win_gtk.h"
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
29 extern void wxapp_install_idle_handler();
31 extern int g_openDialogs
;
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
37 BEGIN_EVENT_TABLE(wxDialog
,wxDialogBase
)
38 EVT_BUTTON (wxID_OK
, wxDialog::OnOK
)
39 EVT_BUTTON (wxID_CANCEL
, wxDialog::OnCancel
)
40 EVT_BUTTON (wxID_APPLY
, wxDialog::OnApply
)
41 EVT_CLOSE (wxDialog::OnCloseWindow
)
44 IMPLEMENT_DYNAMIC_CLASS(wxDialog
,wxTopLevelWindow
)
50 m_modalShowing
= FALSE
;
51 m_themeEnabled
= TRUE
;
54 wxDialog::wxDialog( wxWindow
*parent
,
55 wxWindowID id
, const wxString
&title
,
56 const wxPoint
&pos
, const wxSize
&size
,
57 long style
, const wxString
&name
)
61 (void)Create( parent
, id
, title
, pos
, size
, style
, name
);
64 bool wxDialog::Create( wxWindow
*parent
,
65 wxWindowID id
, const wxString
&title
,
66 const wxPoint
&pos
, const wxSize
&size
,
67 long style
, const wxString
&name
)
69 SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG
);
71 // all dialogs should have tab traversal enabled
72 style
|= wxTAB_TRAVERSAL
;
74 return wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
);
77 void wxDialog::OnApply( wxCommandEvent
&WXUNUSED(event
) )
80 TransferDataFromWindow();
83 void wxDialog::OnCancel( wxCommandEvent
&WXUNUSED(event
) )
87 EndModal(wxID_CANCEL
);
91 SetReturnCode(wxID_CANCEL
);
96 void wxDialog::OnOK( wxCommandEvent
&WXUNUSED(event
) )
98 if (Validate() && TransferDataFromWindow())
106 SetReturnCode(wxID_OK
);
112 void wxDialog::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
117 void wxDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
119 // We'll send a Cancel message by default,
120 // which may close the dialog.
121 // Check for looping if the Cancel event handler calls Close().
123 // Note that if a cancel button and handler aren't present in the dialog,
124 // nothing will happen when you close the dialog via the window manager, or
126 // We wouldn't want to destroy the dialog by default, since the dialog may have been
127 // created on the stack.
128 // However, this does mean that calling dialog->Close() won't delete the dialog
129 // unless the handler for wxID_CANCEL does so. So use Destroy() if you want to be
130 // sure to destroy the dialog.
131 // The default OnCancel (above) simply ends a modal dialog, and hides a modeless dialog.
133 static wxList s_closing
;
135 if (s_closing
.Member(this))
138 s_closing
.Append(this);
140 wxCommandEvent
cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
141 cancelEvent
.SetEventObject( this );
142 GetEventHandler()->ProcessEvent(cancelEvent
);
143 s_closing
.DeleteObject(this);
146 bool wxDialog::Show( bool show
)
148 if (!show
&& IsModal())
150 EndModal( wxID_CANCEL
);
153 if (show
&& !m_sizeSet
)
155 /* by calling GtkOnSize here, we don't have to call
156 either after showing the frame, which would entail
157 much ugly flicker nor from within the size_allocate
158 handler, because GTK 1.1.X forbids that. */
160 GtkOnSize( m_x
, m_y
, m_width
, m_height
);
163 bool ret
= wxWindow::Show( show
);
165 if (show
) InitDialog();
170 bool wxDialog::IsModal() const
172 return m_modalShowing
;
175 void wxDialog::SetModal( bool WXUNUSED(flag
) )
179 m_windowStyle |= wxDIALOG_MODAL;
181 if (m_windowStyle & wxDIALOG_MODAL) m_windowStyle -= wxDIALOG_MODAL;
183 wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") );
186 int wxDialog::ShowModal()
190 wxFAIL_MSG( wxT("wxDialog:ShowModal called twice") );
191 return GetReturnCode();
194 // use the apps top level window as parent if none given unless explicitly
196 if ( !GetParent() && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT
) )
198 wxWindow
*parent
= wxTheApp
->GetTopWindow();
201 parent
->IsBeingDeleted() &&
202 !(parent
->GetExtraStyle() & wxWS_EX_TRANSIENT
) )
205 gtk_window_set_transient_for( GTK_WINDOW(m_widget
), GTK_WINDOW(parent
->m_widget
) );
209 wxBusyCursorSuspender cs
; // temporarily suppress the busy cursor
215 m_modalShowing
= TRUE
;
219 gtk_grab_add( m_widget
);
221 gtk_grab_remove( m_widget
);
225 return GetReturnCode();
228 void wxDialog::EndModal( int retCode
)
230 SetReturnCode( retCode
);
234 wxFAIL_MSG( wxT("wxDialog:EndModal called twice") );
238 m_modalShowing
= FALSE
;