]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dialog.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
a81258be | 5 | // Id: $Id$ |
01111366 | 6 | // Copyright: (c) 1998 Robert Roebling |
65571936 | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
14f355c2 | 10 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
c801d85f KB |
11 | #pragma implementation "dialog.h" |
12 | #endif | |
13 | ||
14f355c2 VS |
14 | // For compilers that support precompilation, includes "wx.h". |
15 | #include "wx/wxprec.h" | |
16 | ||
c801d85f KB |
17 | #include "wx/dialog.h" |
18 | #include "wx/frame.h" | |
19 | #include "wx/app.h" | |
69ffe1d2 | 20 | #include "wx/cursor.h" |
83624f79 | 21 | |
071a2d78 RR |
22 | #include <gdk/gdk.h> |
23 | #include <gtk/gtk.h> | |
24 | #include <gdk/gdkkeysyms.h> | |
25 | ||
c801d85f | 26 | #include "wx/gtk/win_gtk.h" |
5e014a0c | 27 | |
acfd422a | 28 | //----------------------------------------------------------------------------- |
91af0895 | 29 | // global data |
acfd422a RR |
30 | //----------------------------------------------------------------------------- |
31 | ||
2d68e1b4 | 32 | extern int g_openDialogs; |
acfd422a | 33 | |
c801d85f KB |
34 | //----------------------------------------------------------------------------- |
35 | // wxDialog | |
36 | //----------------------------------------------------------------------------- | |
37 | ||
7d9f12f3 | 38 | BEGIN_EVENT_TABLE(wxDialog,wxDialogBase) |
fb1585ae RR |
39 | EVT_BUTTON (wxID_OK, wxDialog::OnOK) |
40 | EVT_BUTTON (wxID_CANCEL, wxDialog::OnCancel) | |
41 | EVT_BUTTON (wxID_APPLY, wxDialog::OnApply) | |
42 | EVT_CLOSE (wxDialog::OnCloseWindow) | |
c801d85f KB |
43 | END_EVENT_TABLE() |
44 | ||
7d9f12f3 | 45 | IMPLEMENT_DYNAMIC_CLASS(wxDialog,wxTopLevelWindow) |
c801d85f | 46 | |
68995f26 | 47 | void wxDialog::Init() |
c801d85f | 48 | { |
f03fc89f | 49 | m_returnCode = 0; |
91af0895 WS |
50 | m_sizeSet = false; |
51 | m_modalShowing = false; | |
52 | m_themeEnabled = true; | |
c33c4050 | 53 | } |
c801d85f | 54 | |
2b854a32 | 55 | wxDialog::wxDialog( wxWindow *parent, |
fb1585ae | 56 | wxWindowID id, const wxString &title, |
2b854a32 | 57 | const wxPoint &pos, const wxSize &size, |
fb1585ae | 58 | long style, const wxString &name ) |
c801d85f | 59 | { |
68995f26 VZ |
60 | Init(); |
61 | ||
82c9f85c | 62 | (void)Create( parent, id, title, pos, size, style, name ); |
c33c4050 | 63 | } |
c801d85f KB |
64 | |
65 | bool wxDialog::Create( wxWindow *parent, | |
fb1585ae | 66 | wxWindowID id, const wxString &title, |
2b854a32 | 67 | const wxPoint &pos, const wxSize &size, |
fb1585ae | 68 | long style, const wxString &name ) |
c801d85f | 69 | { |
21f4383a | 70 | SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG); |
2b854a32 | 71 | |
82c9f85c VZ |
72 | // all dialogs should have tab traversal enabled |
73 | style |= wxTAB_TRAVERSAL; | |
74 | ||
7d9f12f3 | 75 | return wxTopLevelWindow::Create(parent, id, title, pos, size, style, name); |
c33c4050 | 76 | } |
c801d85f KB |
77 | |
78 | void wxDialog::OnApply( wxCommandEvent &WXUNUSED(event) ) | |
79 | { | |
82c9f85c VZ |
80 | if (Validate()) |
81 | TransferDataFromWindow(); | |
c33c4050 | 82 | } |
c801d85f KB |
83 | |
84 | void wxDialog::OnCancel( wxCommandEvent &WXUNUSED(event) ) | |
85 | { | |
fb1585ae RR |
86 | if (IsModal()) |
87 | { | |
88 | EndModal(wxID_CANCEL); | |
89 | } | |
90 | else | |
91 | { | |
92 | SetReturnCode(wxID_CANCEL); | |
91af0895 | 93 | Show(false); |
fb1585ae | 94 | } |
c33c4050 | 95 | } |
c801d85f | 96 | |
903f689b | 97 | void wxDialog::OnOK( wxCommandEvent &WXUNUSED(event) ) |
c801d85f | 98 | { |
32ac755d | 99 | if (Validate() && TransferDataFromWindow()) |
1a6944fd | 100 | { |
2b854a32 | 101 | if (IsModal()) |
fb1585ae RR |
102 | { |
103 | EndModal(wxID_OK); | |
104 | } | |
105 | else | |
106 | { | |
107 | SetReturnCode(wxID_OK); | |
91af0895 | 108 | Show(false); |
fb1585ae | 109 | } |
1a6944fd | 110 | } |
c33c4050 | 111 | } |
c801d85f KB |
112 | |
113 | void wxDialog::OnPaint( wxPaintEvent& WXUNUSED(event) ) | |
114 | { | |
2b854a32 | 115 | // yes |
c33c4050 | 116 | } |
c801d85f | 117 | |
a492cb0f | 118 | void wxDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) |
c801d85f | 119 | { |
e3065973 JS |
120 | // We'll send a Cancel message by default, |
121 | // which may close the dialog. | |
122 | // Check for looping if the Cancel event handler calls Close(). | |
123 | ||
124 | // Note that if a cancel button and handler aren't present in the dialog, | |
125 | // nothing will happen when you close the dialog via the window manager, or | |
126 | // via Close(). | |
127 | // We wouldn't want to destroy the dialog by default, since the dialog may have been | |
128 | // created on the stack. | |
129 | // However, this does mean that calling dialog->Close() won't delete the dialog | |
130 | // unless the handler for wxID_CANCEL does so. So use Destroy() if you want to be | |
131 | // sure to destroy the dialog. | |
132 | // The default OnCancel (above) simply ends a modal dialog, and hides a modeless dialog. | |
133 | ||
ab2b3dd4 | 134 | static wxList s_closing; |
c801d85f | 135 | |
ab2b3dd4 | 136 | if (s_closing.Member(this)) |
2b854a32 VZ |
137 | return; // no loops |
138 | ||
ab2b3dd4 | 139 | s_closing.Append(this); |
c801d85f | 140 | |
fb1585ae RR |
141 | wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); |
142 | cancelEvent.SetEventObject( this ); | |
143 | GetEventHandler()->ProcessEvent(cancelEvent); | |
ab2b3dd4 | 144 | s_closing.DeleteObject(this); |
c801d85f KB |
145 | } |
146 | ||
debe6624 | 147 | bool wxDialog::Show( bool show ) |
c801d85f | 148 | { |
fb1585ae RR |
149 | if (!show && IsModal()) |
150 | { | |
de8113d9 | 151 | EndModal( wxID_CANCEL ); |
fb1585ae | 152 | } |
c801d85f | 153 | |
de8113d9 RR |
154 | if (show && !m_sizeSet) |
155 | { | |
156 | /* by calling GtkOnSize here, we don't have to call | |
157 | either after showing the frame, which would entail | |
158 | much ugly flicker nor from within the size_allocate | |
159 | handler, because GTK 1.1.X forbids that. */ | |
160 | ||
161 | GtkOnSize( m_x, m_y, m_width, m_height ); | |
162 | } | |
2b854a32 | 163 | |
739730ca | 164 | bool ret = wxWindow::Show( show ); |
e146b8c8 | 165 | |
fb1585ae | 166 | if (show) InitDialog(); |
2b854a32 | 167 | |
739730ca | 168 | return ret; |
c33c4050 RR |
169 | } |
170 | ||
43a18898 | 171 | bool wxDialog::IsModal() const |
e1e955e1 | 172 | { |
fb1585ae | 173 | return m_modalShowing; |
e1e955e1 RR |
174 | } |
175 | ||
176 | void wxDialog::SetModal( bool WXUNUSED(flag) ) | |
c33c4050 | 177 | { |
223d09f6 | 178 | wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") ); |
c33c4050 | 179 | } |
c801d85f | 180 | |
43a18898 | 181 | int wxDialog::ShowModal() |
c801d85f | 182 | { |
fb1585ae RR |
183 | if (IsModal()) |
184 | { | |
223d09f6 | 185 | wxFAIL_MSG( wxT("wxDialog:ShowModal called twice") ); |
fb1585ae RR |
186 | return GetReturnCode(); |
187 | } | |
e146b8c8 | 188 | |
b3daa5a3 VZ |
189 | // use the apps top level window as parent if none given unless explicitly |
190 | // forbidden | |
191 | if ( !GetParent() && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT) ) | |
f6bcfd97 BP |
192 | { |
193 | wxWindow *parent = wxTheApp->GetTopWindow(); | |
39cc7a0b VZ |
194 | if ( parent && |
195 | parent != this && | |
196 | parent->IsBeingDeleted() && | |
197 | !(parent->GetExtraStyle() & wxWS_EX_TRANSIENT) ) | |
f6bcfd97 BP |
198 | { |
199 | m_parent = parent; | |
200 | gtk_window_set_transient_for( GTK_WINDOW(m_widget), GTK_WINDOW(parent->m_widget) ); | |
201 | } | |
202 | } | |
203 | ||
eebe4016 | 204 | wxBusyCursorSuspender cs; // temporarily suppress the busy cursor |
91af0895 WS |
205 | |
206 | Show( true ); | |
2b854a32 | 207 | |
2b5f62a0 VZ |
208 | SetFocus(); |
209 | ||
91af0895 | 210 | m_modalShowing = true; |
2b854a32 | 211 | |
304e5625 RR |
212 | g_openDialogs++; |
213 | ||
fb1585ae RR |
214 | gtk_grab_add( m_widget ); |
215 | gtk_main(); | |
216 | gtk_grab_remove( m_widget ); | |
2b854a32 | 217 | |
304e5625 RR |
218 | g_openDialogs--; |
219 | ||
fb1585ae | 220 | return GetReturnCode(); |
c33c4050 | 221 | } |
c801d85f KB |
222 | |
223 | void wxDialog::EndModal( int retCode ) | |
224 | { | |
fb1585ae | 225 | SetReturnCode( retCode ); |
2b854a32 | 226 | |
fb1585ae RR |
227 | if (!IsModal()) |
228 | { | |
223d09f6 | 229 | wxFAIL_MSG( wxT("wxDialog:EndModal called twice") ); |
fb1585ae RR |
230 | return; |
231 | } | |
2b854a32 | 232 | |
91af0895 | 233 | m_modalShowing = false; |
2b854a32 | 234 | |
fb1585ae | 235 | gtk_main_quit(); |
2b854a32 | 236 | |
91af0895 | 237 | Show( false ); |
c33c4050 | 238 | } |