1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/dialog.cpp
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"
20 #include "wx/cursor.h"
21 #include "wx/evtloop.h"
25 #include <gdk/gdkkeysyms.h>
27 #include "wx/gtk1/win_gtk.h"
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
33 extern int g_openDialogs
;
35 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
39 BEGIN_EVENT_TABLE(wxDialog
,wxDialogBase
)
40 EVT_BUTTON (wxID_OK
, wxDialog::OnOK
)
41 EVT_BUTTON (wxID_CANCEL
, wxDialog::OnCancel
)
42 EVT_BUTTON (wxID_APPLY
, wxDialog::OnApply
)
43 EVT_CLOSE (wxDialog::OnCloseWindow
)
46 IMPLEMENT_DYNAMIC_CLASS(wxDialog
,wxTopLevelWindow
)
52 m_modalShowing
= false;
53 m_themeEnabled
= true;
56 wxDialog::wxDialog( wxWindow
*parent
,
57 wxWindowID id
, const wxString
&title
,
58 const wxPoint
&pos
, const wxSize
&size
,
59 long style
, const wxString
&name
)
63 (void)Create( parent
, id
, title
, pos
, size
, style
, name
);
66 bool wxDialog::Create( wxWindow
*parent
,
67 wxWindowID id
, const wxString
&title
,
68 const wxPoint
&pos
, const wxSize
&size
,
69 long style
, const wxString
&name
)
71 SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG
);
73 // all dialogs should have tab traversal enabled
74 style
|= wxTAB_TRAVERSAL
;
76 return wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
);
79 void wxDialog::OnApply( wxCommandEvent
&WXUNUSED(event
) )
82 TransferDataFromWindow();
85 void wxDialog::OnCancel( wxCommandEvent
&WXUNUSED(event
) )
89 EndModal(wxID_CANCEL
);
93 SetReturnCode(wxID_CANCEL
);
98 void wxDialog::OnOK( wxCommandEvent
&WXUNUSED(event
) )
100 if (Validate() && TransferDataFromWindow())
108 SetReturnCode(wxID_OK
);
114 void wxDialog::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
119 void wxDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
121 // We'll send a Cancel message by default,
122 // which may close the dialog.
123 // Check for looping if the Cancel event handler calls Close().
125 // Note that if a cancel button and handler aren't present in the dialog,
126 // nothing will happen when you close the dialog via the window manager, or
128 // We wouldn't want to destroy the dialog by default, since the dialog may have been
129 // created on the stack.
130 // However, this does mean that calling dialog->Close() won't delete the dialog
131 // unless the handler for wxID_CANCEL does so. So use Destroy() if you want to be
132 // sure to destroy the dialog.
133 // The default OnCancel (above) simply ends a modal dialog, and hides a modeless dialog.
135 static wxList s_closing
;
137 if (s_closing
.Member(this))
140 s_closing
.Append(this);
142 wxCommandEvent
cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
143 cancelEvent
.SetEventObject( this );
144 GetEventHandler()->ProcessEvent(cancelEvent
);
145 s_closing
.DeleteObject(this);
148 bool wxDialog::Show( bool show
)
150 if (!show
&& IsModal())
152 EndModal( wxID_CANCEL
);
155 if (show
&& !m_sizeSet
)
157 /* by calling GtkOnSize here, we don't have to call
158 either after showing the frame, which would entail
159 much ugly flicker nor from within the size_allocate
160 handler, because GTK 1.1.X forbids that. */
162 GtkOnSize( m_x
, m_y
, m_width
, m_height
);
165 bool ret
= wxWindow::Show( show
);
167 if (show
) InitDialog();
172 bool wxDialog::IsModal() const
174 return m_modalShowing
;
177 void wxDialog::SetModal( bool WXUNUSED(flag
) )
179 wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") );
182 int wxDialog::ShowModal()
186 wxFAIL_MSG( wxT("wxDialog:ShowModal called twice") );
187 return GetReturnCode();
190 // use the apps top level window as parent if none given unless explicitly
192 if ( !GetParent() && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT
) )
194 wxWindow
*parent
= wxTheApp
->GetTopWindow();
197 parent
->IsBeingDeleted() &&
198 !(parent
->GetExtraStyle() & wxWS_EX_TRANSIENT
) )
201 gtk_window_set_transient_for( GTK_WINDOW(m_widget
), GTK_WINDOW(parent
->m_widget
) );
205 wxBusyCursorSuspender cs
; // temporarily suppress the busy cursor
209 m_modalShowing
= true;
213 gtk_grab_add( m_widget
);
217 gtk_grab_remove( m_widget
);
221 return GetReturnCode();
224 void wxDialog::EndModal( int retCode
)
226 SetReturnCode( retCode
);
230 wxFAIL_MSG( wxT("wxDialog:EndModal called twice") );
234 m_modalShowing
= false;