1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
13 #include "wx/dialog.h"
16 #include "wx/cursor.h"
17 #include "wx/evtloop.h"
21 #include <gdk/gdkkeysyms.h>
23 #include "wx/gtk1/win_gtk.h"
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
29 extern int g_openDialogs
;
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 BEGIN_EVENT_TABLE(wxDialog
,wxDialogBase
)
36 EVT_BUTTON (wxID_OK
, wxDialog::OnOK
)
37 EVT_BUTTON (wxID_CANCEL
, wxDialog::OnCancel
)
38 EVT_BUTTON (wxID_APPLY
, wxDialog::OnApply
)
39 EVT_CLOSE (wxDialog::OnCloseWindow
)
42 IMPLEMENT_DYNAMIC_CLASS(wxDialog
,wxTopLevelWindow
)
48 m_modalShowing
= false;
49 m_themeEnabled
= true;
52 wxDialog::wxDialog( wxWindow
*parent
,
53 wxWindowID id
, const wxString
&title
,
54 const wxPoint
&pos
, const wxSize
&size
,
55 long style
, const wxString
&name
)
59 (void)Create( parent
, id
, title
, pos
, size
, style
, name
);
62 bool wxDialog::Create( wxWindow
*parent
,
63 wxWindowID id
, const wxString
&title
,
64 const wxPoint
&pos
, const wxSize
&size
,
65 long style
, const wxString
&name
)
67 SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG
);
69 // all dialogs should have tab traversal enabled
70 style
|= wxTAB_TRAVERSAL
;
72 return wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
);
75 void wxDialog::OnApply( wxCommandEvent
&WXUNUSED(event
) )
78 TransferDataFromWindow();
81 void wxDialog::OnCancel( wxCommandEvent
&WXUNUSED(event
) )
85 EndModal(wxID_CANCEL
);
89 SetReturnCode(wxID_CANCEL
);
94 void wxDialog::OnOK( wxCommandEvent
&WXUNUSED(event
) )
96 if (Validate() && TransferDataFromWindow())
104 SetReturnCode(wxID_OK
);
110 void wxDialog::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
115 void wxDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
117 // We'll send a Cancel message by default,
118 // which may close the dialog.
119 // Check for looping if the Cancel event handler calls Close().
121 // Note that if a cancel button and handler aren't present in the dialog,
122 // nothing will happen when you close the dialog via the window manager, or
124 // We wouldn't want to destroy the dialog by default, since the dialog may have been
125 // created on the stack.
126 // However, this does mean that calling dialog->Close() won't delete the dialog
127 // unless the handler for wxID_CANCEL does so. So use Destroy() if you want to be
128 // sure to destroy the dialog.
129 // The default OnCancel (above) simply ends a modal dialog, and hides a modeless dialog.
131 static wxList s_closing
;
133 if (s_closing
.Member(this))
136 s_closing
.Append(this);
138 wxCommandEvent
cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
139 cancelEvent
.SetEventObject( this );
140 GetEventHandler()->ProcessEvent(cancelEvent
);
141 s_closing
.DeleteObject(this);
144 bool wxDialog::Show( bool show
)
146 if (!show
&& IsModal())
148 EndModal( wxID_CANCEL
);
151 if (show
&& !m_sizeSet
)
153 /* by calling GtkOnSize here, we don't have to call
154 either after showing the frame, which would entail
155 much ugly flicker nor from within the size_allocate
156 handler, because GTK 1.1.X forbids that. */
158 GtkOnSize( m_x
, m_y
, m_width
, m_height
);
161 bool ret
= wxWindow::Show( show
);
163 if (show
) InitDialog();
168 bool wxDialog::IsModal() const
170 return m_modalShowing
;
173 void wxDialog::SetModal( bool WXUNUSED(flag
) )
175 wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") );
178 int wxDialog::ShowModal()
182 wxFAIL_MSG( wxT("wxDialog:ShowModal called twice") );
183 return GetReturnCode();
186 // use the apps top level window as parent if none given unless explicitly
188 if ( !GetParent() && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT
) )
190 wxWindow
*parent
= wxTheApp
->GetTopWindow();
193 parent
->IsBeingDeleted() &&
194 !(parent
->GetExtraStyle() & wxWS_EX_TRANSIENT
) )
197 gtk_window_set_transient_for( GTK_WINDOW(m_widget
), GTK_WINDOW(parent
->m_widget
) );
201 wxBusyCursorSuspender cs
; // temporarily suppress the busy cursor
205 m_modalShowing
= true;
209 gtk_grab_add( m_widget
);
213 gtk_grab_remove( m_widget
);
217 return GetReturnCode();
220 void wxDialog::EndModal( int retCode
)
222 SetReturnCode( retCode
);
226 wxFAIL_MSG( wxT("wxDialog:EndModal called twice") );
230 m_modalShowing
= false;