]>
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 |
2b854a32 | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
10 | #ifdef __GNUG__ | |
11 | #pragma implementation "dialog.h" | |
12 | #endif | |
13 | ||
14 | #include "wx/dialog.h" | |
15 | #include "wx/frame.h" | |
16 | #include "wx/app.h" | |
69ffe1d2 | 17 | #include "wx/cursor.h" |
83624f79 | 18 | |
071a2d78 RR |
19 | #include <gdk/gdk.h> |
20 | #include <gtk/gtk.h> | |
21 | #include <gdk/gdkkeysyms.h> | |
22 | ||
c801d85f | 23 | #include "wx/gtk/win_gtk.h" |
5e014a0c | 24 | |
acfd422a RR |
25 | //----------------------------------------------------------------------------- |
26 | // idle system | |
27 | //----------------------------------------------------------------------------- | |
28 | ||
29 | extern void wxapp_install_idle_handler(); | |
30 | extern bool g_isIdle; | |
2d68e1b4 | 31 | extern int g_openDialogs; |
acfd422a RR |
32 | |
33 | //----------------------------------------------------------------------------- | |
34 | // data | |
e2414cbe RR |
35 | //----------------------------------------------------------------------------- |
36 | ||
37 | extern wxList wxPendingDelete; | |
38 | ||
69ffe1d2 RR |
39 | //----------------------------------------------------------------------------- |
40 | // "focus" from m_window | |
41 | //----------------------------------------------------------------------------- | |
42 | ||
43 | static gint gtk_dialog_focus_callback( GtkWidget *widget, GtkDirectionType WXUNUSED(d), wxWindow *WXUNUSED(win) ) | |
44 | { | |
45 | if (g_isIdle) | |
46 | wxapp_install_idle_handler(); | |
47 | ||
48 | // This disables GTK's tab traversal | |
49 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "focus" ); | |
50 | return TRUE; | |
51 | } | |
52 | ||
c801d85f | 53 | //----------------------------------------------------------------------------- |
e1e955e1 RR |
54 | // "delete_event" |
55 | //----------------------------------------------------------------------------- | |
c801d85f KB |
56 | |
57 | bool gtk_dialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxDialog *win ) | |
2b854a32 | 58 | { |
7e14e49f | 59 | if (g_isIdle) |
121a3581 | 60 | wxapp_install_idle_handler(); |
2b854a32 | 61 | |
a56fcaaf RR |
62 | if (win->IsEnabled()) |
63 | win->Close(); | |
c801d85f | 64 | |
fb1585ae | 65 | return TRUE; |
c33c4050 | 66 | } |
c801d85f | 67 | |
e52f60e6 RR |
68 | //----------------------------------------------------------------------------- |
69 | // "size_allocate" | |
70 | //----------------------------------------------------------------------------- | |
71 | ||
72 | static void gtk_dialog_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxDialog *win ) | |
73 | { | |
7e14e49f | 74 | if (g_isIdle) |
121a3581 | 75 | wxapp_install_idle_handler(); |
acfd422a | 76 | |
a2053b27 | 77 | if (!win->m_hasVMT) return; |
e52f60e6 | 78 | |
121a3581 RR |
79 | if ((win->m_width != alloc->width) || (win->m_height != alloc->height)) |
80 | { | |
81 | win->m_width = alloc->width; | |
82 | win->m_height = alloc->height; | |
5b8a521e | 83 | win->GtkUpdateSize(); |
121a3581 | 84 | } |
e52f60e6 RR |
85 | } |
86 | ||
36b3b54a RR |
87 | //----------------------------------------------------------------------------- |
88 | // "configure_event" | |
89 | //----------------------------------------------------------------------------- | |
90 | ||
7e14e49f | 91 | static gint |
2d68e1b4 | 92 | #if (GTK_MINOR_VERSION > 0) |
c693edf3 RR |
93 | gtk_dialog_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *WXUNUSED(event), wxDialog *win ) |
94 | #else | |
95 | gtk_dialog_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *event, wxDialog *win ) | |
96 | #endif | |
36b3b54a | 97 | { |
7e14e49f | 98 | if (g_isIdle) |
121a3581 | 99 | wxapp_install_idle_handler(); |
acfd422a | 100 | |
a2053b27 | 101 | if (!win->m_hasVMT) return FALSE; |
36b3b54a | 102 | |
2d68e1b4 | 103 | #if (GTK_MINOR_VERSION > 0) |
dfc3d7e0 RR |
104 | int x = 0; |
105 | int y = 0; | |
106 | gdk_window_get_root_origin( win->m_widget->window, &x, &y ); | |
dfc3d7e0 RR |
107 | win->m_x = x; |
108 | win->m_y = y; | |
c693edf3 RR |
109 | #else |
110 | win->m_x = event->x; | |
111 | win->m_y = event->y; | |
112 | #endif | |
36b3b54a | 113 | |
a2053b27 | 114 | wxMoveEvent mevent( wxPoint(win->m_x,win->m_y), win->GetId() ); |
36b3b54a RR |
115 | mevent.SetEventObject( win ); |
116 | win->GetEventHandler()->ProcessEvent( mevent ); | |
117 | ||
118 | return FALSE; | |
119 | } | |
120 | ||
2b07d713 RR |
121 | //----------------------------------------------------------------------------- |
122 | // "realize" from m_widget | |
123 | //----------------------------------------------------------------------------- | |
124 | ||
7e14e49f | 125 | /* we cannot MWM hints and icons before the widget has been realized, |
2b07d713 RR |
126 | so we do this directly after realization */ |
127 | ||
7e14e49f | 128 | static gint |
58dea4b0 | 129 | gtk_dialog_realized_callback( GtkWidget *widget, wxDialog *win ) |
2b07d713 | 130 | { |
7e14e49f | 131 | if (g_isIdle) |
c5b42c87 RR |
132 | wxapp_install_idle_handler(); |
133 | ||
d6538e2c | 134 | /* I haven't been able to set the position of |
c5b42c87 | 135 | the dialog before it is shown, so I set the |
d6538e2c | 136 | position in "realize" */ |
8487f887 | 137 | gtk_widget_set_uposition( widget, win->m_x, win->m_y ); |
acfd422a | 138 | |
2b07d713 RR |
139 | /* all this is for Motif Window Manager "hints" and is supposed to be |
140 | recognized by other WM as well. not tested. */ | |
051b55ad | 141 | long decor = (long) GDK_DECOR_BORDER; |
aa64626e | 142 | long func = (long) GDK_FUNC_MOVE ; |
cb81efcd KB |
143 | |
144 | /* Some WM don't display any border around the frame contents if | |
145 | used with these hints, so we add a resize border around it, | |
146 | without automatically allowinng it to be resized though. | |
147 | ||
148 | This avoids the problem, but looks odd. What shall we do? | |
149 | */ | |
150 | decor |= GDK_DECOR_RESIZEH; | |
7e14e49f | 151 | |
f03fc89f VZ |
152 | if ((win->GetWindowStyle() & wxCAPTION) != 0) |
153 | decor |= GDK_DECOR_TITLE; | |
154 | if ((win->GetWindowStyle() & wxSYSTEM_MENU) != 0) | |
aa64626e KB |
155 | { |
156 | decor |= GDK_DECOR_MENU; | |
157 | func |= GDK_FUNC_CLOSE; | |
158 | } | |
f03fc89f | 159 | if ((win->GetWindowStyle() & wxMINIMIZE_BOX) != 0) |
15b24b14 | 160 | { |
f03fc89f VZ |
161 | func |= GDK_FUNC_MINIMIZE; |
162 | decor |= GDK_DECOR_MINIMIZE; | |
15b24b14 | 163 | } |
f03fc89f | 164 | if ((win->GetWindowStyle() & wxMAXIMIZE_BOX) != 0) |
15b24b14 | 165 | { |
f03fc89f | 166 | decor |= GDK_DECOR_MAXIMIZE; |
7e14e49f | 167 | func |= GDK_FUNC_MAXIMIZE; |
15b24b14 | 168 | } |
f03fc89f | 169 | if ((win->GetWindowStyle() & wxRESIZE_BORDER) != 0) |
aa64626e KB |
170 | { |
171 | func |= GDK_FUNC_RESIZE; | |
172 | decor |= GDK_DECOR_RESIZEH; | |
173 | } | |
a2053b27 RR |
174 | gdk_window_set_decorations( win->m_widget->window, (GdkWMDecoration)decor); |
175 | gdk_window_set_functions( win->m_widget->window, (GdkWMFunction)func); | |
7e14e49f | 176 | |
2b07d713 | 177 | /* GTK's shrinking/growing policy */ |
f03fc89f | 178 | if ((win->GetWindowStyle() & wxRESIZE_BORDER) == 0) |
a2053b27 | 179 | gtk_window_set_policy(GTK_WINDOW(win->m_widget), 0, 0, 1); |
2b07d713 | 180 | else |
a2053b27 | 181 | gtk_window_set_policy(GTK_WINDOW(win->m_widget), 1, 1, 1); |
7e14e49f | 182 | |
d6538e2c | 183 | /* set size hints */ |
7beba2fc | 184 | gint flag = 0; // GDK_HINT_POS; |
d6538e2c RR |
185 | if ((win->GetMinWidth() != -1) || (win->GetMinHeight() != -1)) flag |= GDK_HINT_MIN_SIZE; |
186 | if ((win->GetMaxWidth() != -1) || (win->GetMaxHeight() != -1)) flag |= GDK_HINT_MAX_SIZE; | |
187 | if (flag) | |
188 | { | |
7e14e49f | 189 | gdk_window_set_hints( win->m_widget->window, |
7beba2fc VZ |
190 | win->m_x, win->m_y, |
191 | win->GetMinWidth(), win->GetMinHeight(), | |
192 | win->GetMaxWidth(), win->GetMaxHeight(), | |
193 | flag ); | |
d6538e2c RR |
194 | } |
195 | ||
196 | /* reset the icon */ | |
197 | if (win->m_icon != wxNullIcon) | |
198 | { | |
199 | wxIcon icon( win->m_icon ); | |
200 | win->m_icon = wxNullIcon; | |
201 | win->SetIcon( icon ); | |
202 | } | |
7e14e49f | 203 | |
227e5e99 RR |
204 | return FALSE; |
205 | } | |
7e14e49f | 206 | |
ddb6bc71 RR |
207 | //----------------------------------------------------------------------------- |
208 | // InsertChild for wxDialog | |
209 | //----------------------------------------------------------------------------- | |
210 | ||
211 | /* Callback for wxFrame. This very strange beast has to be used because | |
212 | * C++ has no virtual methods in a constructor. We have to emulate a | |
213 | * virtual function here as wxWindows requires different ways to insert | |
214 | * a child in container classes. */ | |
215 | ||
216 | static void wxInsertChildInDialog( wxDialog* parent, wxWindow* child ) | |
217 | { | |
da048e3d | 218 | gtk_pizza_put( GTK_PIZZA(parent->m_wxwindow), |
ddb6bc71 RR |
219 | GTK_WIDGET(child->m_widget), |
220 | child->m_x, | |
221 | child->m_y, | |
222 | child->m_width, | |
223 | child->m_height ); | |
224 | ||
225 | if (parent->HasFlag(wxTAB_TRAVERSAL)) | |
226 | { | |
227 | /* we now allow a window to get the focus as long as it | |
228 | doesn't have any children. */ | |
229 | GTK_WIDGET_UNSET_FLAGS( parent->m_wxwindow, GTK_CAN_FOCUS ); | |
230 | } | |
231 | } | |
232 | ||
c801d85f KB |
233 | //----------------------------------------------------------------------------- |
234 | // wxDialog | |
235 | //----------------------------------------------------------------------------- | |
236 | ||
a60c99e6 | 237 | BEGIN_EVENT_TABLE(wxDialog,wxPanel) |
fb1585ae RR |
238 | EVT_BUTTON (wxID_OK, wxDialog::OnOK) |
239 | EVT_BUTTON (wxID_CANCEL, wxDialog::OnCancel) | |
240 | EVT_BUTTON (wxID_APPLY, wxDialog::OnApply) | |
e52f60e6 | 241 | EVT_SIZE (wxDialog::OnSize) |
fb1585ae | 242 | EVT_CLOSE (wxDialog::OnCloseWindow) |
c801d85f KB |
243 | END_EVENT_TABLE() |
244 | ||
a60c99e6 | 245 | IMPLEMENT_DYNAMIC_CLASS(wxDialog,wxPanel) |
c801d85f | 246 | |
68995f26 | 247 | void wxDialog::Init() |
c801d85f | 248 | { |
f03fc89f | 249 | m_returnCode = 0; |
de8113d9 | 250 | m_sizeSet = FALSE; |
fb1585ae | 251 | m_modalShowing = FALSE; |
54517652 | 252 | m_isFrame = TRUE; |
c33c4050 | 253 | } |
c801d85f | 254 | |
2b854a32 | 255 | wxDialog::wxDialog( wxWindow *parent, |
fb1585ae | 256 | wxWindowID id, const wxString &title, |
2b854a32 | 257 | const wxPoint &pos, const wxSize &size, |
fb1585ae | 258 | long style, const wxString &name ) |
c801d85f | 259 | { |
68995f26 VZ |
260 | Init(); |
261 | ||
fb1585ae | 262 | Create( parent, id, title, pos, size, style, name ); |
c33c4050 | 263 | } |
c801d85f KB |
264 | |
265 | bool wxDialog::Create( wxWindow *parent, | |
fb1585ae | 266 | wxWindowID id, const wxString &title, |
2b854a32 | 267 | const wxPoint &pos, const wxSize &size, |
fb1585ae | 268 | long style, const wxString &name ) |
c801d85f | 269 | { |
2d68e1b4 RR |
270 | g_openDialogs++; |
271 | ||
a802c3a1 | 272 | wxTopLevelWindows.Append( this ); |
2b854a32 | 273 | |
fb1585ae | 274 | m_needParent = FALSE; |
2b854a32 | 275 | |
4dcaf11a RR |
276 | if (!PreCreation( parent, pos, size ) || |
277 | !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) | |
278 | { | |
223d09f6 | 279 | wxFAIL_MSG( wxT("wxDialog creation failed") ); |
7beba2fc | 280 | return FALSE; |
4dcaf11a | 281 | } |
2b854a32 | 282 | |
69ffe1d2 RR |
283 | // All dialogs should really have this style |
284 | m_windowStyle |= wxTAB_TRAVERSAL; | |
285 | ||
ddb6bc71 | 286 | m_insertCallback = (wxInsertChildFunction) wxInsertChildInDialog; |
7e14e49f | 287 | |
173348db | 288 | m_widget = gtk_window_new( GTK_WINDOW_DIALOG ); |
7e14e49f | 289 | |
76380910 RR |
290 | if ((m_parent) && (GTK_IS_WINDOW(m_parent->m_widget))) |
291 | gtk_window_set_transient_for( GTK_WINDOW(m_widget), GTK_WINDOW(m_parent->m_widget) ); | |
7e14e49f | 292 | |
de1c750f RR |
293 | if (!name.IsEmpty()) |
294 | gtk_window_set_wmclass( GTK_WINDOW(m_widget), name.mb_str(), name.mb_str() ); | |
7e14e49f | 295 | |
fb1585ae | 296 | GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS ); |
2b854a32 | 297 | |
2b854a32 | 298 | gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event", |
fb1585ae | 299 | GTK_SIGNAL_FUNC(gtk_dialog_delete_callback), (gpointer)this ); |
2b854a32 | 300 | |
da048e3d | 301 | m_wxwindow = gtk_pizza_new(); |
fb1585ae RR |
302 | gtk_widget_show( m_wxwindow ); |
303 | GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); | |
2b854a32 | 304 | |
fb1585ae | 305 | gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow ); |
2b854a32 | 306 | |
fb1585ae | 307 | SetTitle( title ); |
2b854a32 | 308 | |
de8113d9 | 309 | if (m_parent) m_parent->AddChild( this ); |
2b854a32 | 310 | |
de8113d9 | 311 | PostCreation(); |
e146b8c8 | 312 | |
2b07d713 RR |
313 | /* we cannot set MWM hints before the widget has |
314 | been realized, so we do this directly after realization */ | |
315 | gtk_signal_connect( GTK_OBJECT(m_widget), "realize", | |
f03fc89f | 316 | GTK_SIGNAL_FUNC(gtk_dialog_realized_callback), (gpointer) this ); |
227e5e99 | 317 | |
2b07d713 | 318 | /* the user resized the frame by dragging etc. */ |
2b854a32 | 319 | gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate", |
36b3b54a | 320 | GTK_SIGNAL_FUNC(gtk_dialog_size_callback), (gpointer)this ); |
2b854a32 | 321 | |
36b3b54a RR |
322 | gtk_signal_connect( GTK_OBJECT(m_widget), "configure_event", |
323 | GTK_SIGNAL_FUNC(gtk_dialog_configure_callback), (gpointer)this ); | |
324 | ||
69ffe1d2 RR |
325 | /* disable native tab traversal */ |
326 | gtk_signal_connect( GTK_OBJECT(m_widget), "focus", | |
327 | GTK_SIGNAL_FUNC(gtk_dialog_focus_callback), (gpointer)this ); | |
328 | ||
fb1585ae | 329 | return TRUE; |
c33c4050 | 330 | } |
c801d85f | 331 | |
43a18898 | 332 | wxDialog::~wxDialog() |
c801d85f | 333 | { |
31c6b4fc | 334 | m_isBeingDeleted = TRUE; |
7e14e49f | 335 | |
fb1585ae | 336 | wxTopLevelWindows.DeleteObject( this ); |
2b854a32 | 337 | |
0d2a2b60 RR |
338 | if (wxTheApp->GetTopWindow() == this) |
339 | { | |
340 | wxTheApp->SetTopWindow( (wxWindow*) NULL ); | |
341 | } | |
2b854a32 | 342 | |
f59d80ca RR |
343 | if ((wxTopLevelWindows.Number() == 0) && |
344 | (wxTheApp->GetExitOnFrameDelete())) | |
2b854a32 | 345 | { |
0d2a2b60 RR |
346 | wxTheApp->ExitMainLoop(); |
347 | } | |
2d68e1b4 RR |
348 | |
349 | g_openDialogs--; | |
c33c4050 | 350 | } |
c801d85f | 351 | |
43a18898 | 352 | void wxDialog::SetTitle( const wxString& title ) |
c801d85f | 353 | { |
fb1585ae | 354 | m_title = title; |
223d09f6 | 355 | if (m_title.IsNull()) m_title = wxT(""); |
ed9b9841 | 356 | gtk_window_set_title( GTK_WINDOW(m_widget), m_title.mbc_str() ); |
c33c4050 | 357 | } |
c801d85f | 358 | |
43a18898 | 359 | wxString wxDialog::GetTitle() const |
c801d85f | 360 | { |
fb1585ae | 361 | return (wxString&)m_title; |
c33c4050 | 362 | } |
c801d85f KB |
363 | |
364 | void wxDialog::OnApply( wxCommandEvent &WXUNUSED(event) ) | |
365 | { | |
fb1585ae | 366 | if (Validate()) TransferDataFromWindow(); |
c33c4050 | 367 | } |
c801d85f KB |
368 | |
369 | void wxDialog::OnCancel( wxCommandEvent &WXUNUSED(event) ) | |
370 | { | |
fb1585ae RR |
371 | if (IsModal()) |
372 | { | |
373 | EndModal(wxID_CANCEL); | |
374 | } | |
375 | else | |
376 | { | |
377 | SetReturnCode(wxID_CANCEL); | |
739730ca | 378 | Show(FALSE); |
fb1585ae | 379 | } |
c33c4050 | 380 | } |
c801d85f | 381 | |
903f689b | 382 | void wxDialog::OnOK( wxCommandEvent &WXUNUSED(event) ) |
c801d85f | 383 | { |
32ac755d | 384 | if (Validate() && TransferDataFromWindow()) |
1a6944fd | 385 | { |
2b854a32 | 386 | if (IsModal()) |
fb1585ae RR |
387 | { |
388 | EndModal(wxID_OK); | |
389 | } | |
390 | else | |
391 | { | |
392 | SetReturnCode(wxID_OK); | |
393 | this->Show(FALSE); | |
394 | } | |
1a6944fd | 395 | } |
c33c4050 | 396 | } |
c801d85f KB |
397 | |
398 | void wxDialog::OnPaint( wxPaintEvent& WXUNUSED(event) ) | |
399 | { | |
2b854a32 | 400 | // yes |
c33c4050 | 401 | } |
c801d85f | 402 | |
a492cb0f | 403 | void wxDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) |
c801d85f | 404 | { |
e3065973 JS |
405 | // We'll send a Cancel message by default, |
406 | // which may close the dialog. | |
407 | // Check for looping if the Cancel event handler calls Close(). | |
408 | ||
409 | // Note that if a cancel button and handler aren't present in the dialog, | |
410 | // nothing will happen when you close the dialog via the window manager, or | |
411 | // via Close(). | |
412 | // We wouldn't want to destroy the dialog by default, since the dialog may have been | |
413 | // created on the stack. | |
414 | // However, this does mean that calling dialog->Close() won't delete the dialog | |
415 | // unless the handler for wxID_CANCEL does so. So use Destroy() if you want to be | |
416 | // sure to destroy the dialog. | |
417 | // The default OnCancel (above) simply ends a modal dialog, and hides a modeless dialog. | |
418 | ||
ab2b3dd4 | 419 | static wxList s_closing; |
c801d85f | 420 | |
ab2b3dd4 | 421 | if (s_closing.Member(this)) |
2b854a32 VZ |
422 | return; // no loops |
423 | ||
ab2b3dd4 | 424 | s_closing.Append(this); |
c801d85f | 425 | |
fb1585ae RR |
426 | wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); |
427 | cancelEvent.SetEventObject( this ); | |
428 | GetEventHandler()->ProcessEvent(cancelEvent); | |
ab2b3dd4 | 429 | s_closing.DeleteObject(this); |
c801d85f KB |
430 | } |
431 | ||
43a18898 | 432 | bool wxDialog::Destroy() |
e2414cbe | 433 | { |
fb1585ae | 434 | if (!wxPendingDelete.Member(this)) wxPendingDelete.Append(this); |
e2414cbe | 435 | |
fb1585ae | 436 | return TRUE; |
e2414cbe RR |
437 | } |
438 | ||
e52f60e6 RR |
439 | void wxDialog::OnSize( wxSizeEvent &WXUNUSED(event) ) |
440 | { | |
223d09f6 | 441 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid dialog") ); |
2b854a32 | 442 | |
88ac883a | 443 | #if wxUSE_CONSTRAINTS |
e52f60e6 RR |
444 | if (GetAutoLayout()) |
445 | { | |
446 | Layout(); | |
447 | } | |
2b854a32 | 448 | else |
88ac883a | 449 | #endif // wxUSE_CONSTRAINTS |
e52f60e6 | 450 | { |
de8113d9 | 451 | /* no child: go out ! */ |
db1b4961 | 452 | if (!GetChildren().First()) return; |
2b854a32 | 453 | |
de8113d9 | 454 | /* do we have exactly one child? */ |
e52f60e6 | 455 | wxWindow *child = (wxWindow *) NULL; |
db1b4961 | 456 | for(wxNode *node = GetChildren().First(); node; node = node->Next()) |
e52f60e6 RR |
457 | { |
458 | wxWindow *win = (wxWindow *)node->Data(); | |
de135918 | 459 | if (!wxIS_KIND_OF(win,wxFrame) && !wxIS_KIND_OF(win,wxDialog)) |
e52f60e6 | 460 | { |
de8113d9 | 461 | /* it's the second one: do nothing */ |
e52f60e6 RR |
462 | if (child) return; |
463 | child = win; | |
464 | } | |
465 | } | |
466 | ||
de8113d9 | 467 | /* yes: set it's size to fill all the frame */ |
e52f60e6 RR |
468 | int client_x, client_y; |
469 | GetClientSize( &client_x, &client_y ); | |
470 | child->SetSize( 1, 1, client_x-2, client_y); | |
471 | } | |
472 | } | |
473 | ||
23efdd02 RR |
474 | void wxDialog::DoMoveWindow(int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(width), int WXUNUSED(height) ) |
475 | { | |
476 | wxFAIL_MSG( wxT("DoMoveWindow called for wxDialog") ); | |
477 | } | |
478 | ||
bfc6fde4 | 479 | void wxDialog::DoSetSize( int x, int y, int width, int height, int sizeFlags ) |
903f689b | 480 | { |
223d09f6 KB |
481 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid dialog") ); |
482 | wxASSERT_MSG( (m_wxwindow != NULL), wxT("invalid dialog") ); | |
fb1585ae | 483 | |
de8113d9 | 484 | if (m_resizing) return; /* I don't like recursions */ |
fb1585ae RR |
485 | m_resizing = TRUE; |
486 | ||
487 | int old_x = m_x; | |
488 | int old_y = m_y; | |
7beba2fc | 489 | |
fb1585ae RR |
490 | int old_width = m_width; |
491 | int old_height = m_height; | |
2b854a32 | 492 | |
85ad5eb5 | 493 | if ((sizeFlags & wxSIZE_ALLOW_MINUS_ONE) == 0) |
fb1585ae RR |
494 | { |
495 | if (x != -1) m_x = x; | |
496 | if (y != -1) m_y = y; | |
497 | if (width != -1) m_width = width; | |
498 | if (height != -1) m_height = height; | |
499 | } | |
500 | else | |
501 | { | |
502 | m_x = x; | |
503 | m_y = y; | |
504 | m_width = width; | |
505 | m_height = height; | |
506 | } | |
507 | ||
11e1c70d | 508 | /* |
fb1585ae RR |
509 | if ((sizeFlags & wxSIZE_AUTO_WIDTH) == wxSIZE_AUTO_WIDTH) |
510 | { | |
511 | if (width == -1) m_width = 80; | |
512 | } | |
513 | ||
514 | if ((sizeFlags & wxSIZE_AUTO_HEIGHT) == wxSIZE_AUTO_HEIGHT) | |
515 | { | |
516 | if (height == -1) m_height = 26; | |
517 | } | |
11e1c70d | 518 | */ |
2b854a32 | 519 | |
fb1585ae RR |
520 | if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth; |
521 | if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight; | |
0c77152e RR |
522 | if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_maxWidth; |
523 | if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_maxHeight; | |
fb1585ae RR |
524 | |
525 | if ((m_x != -1) || (m_y != -1)) | |
526 | { | |
2b854a32 | 527 | if ((m_x != old_x) || (m_y != old_y)) |
f03fc89f VZ |
528 | { |
529 | /* we set the position here and when showing the dialog | |
530 | for the first time in idle time */ | |
8487f887 | 531 | gtk_widget_set_uposition( m_widget, m_x, m_y ); |
f03fc89f | 532 | } |
fb1585ae | 533 | } |
2b854a32 | 534 | |
fb1585ae RR |
535 | if ((m_width != old_width) || (m_height != old_height)) |
536 | { | |
227e5e99 | 537 | /* actual resizing is deferred to GtkOnSize in idle time and |
f03fc89f | 538 | when showing the dialog */ |
de8113d9 | 539 | m_sizeSet = FALSE; |
fb1585ae | 540 | } |
2b854a32 | 541 | |
fb1585ae | 542 | m_resizing = FALSE; |
903f689b RR |
543 | } |
544 | ||
de8113d9 RR |
545 | void wxDialog::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int height ) |
546 | { | |
547 | // due to a bug in gtk, x,y are always 0 | |
548 | // m_x = x; | |
549 | // m_y = y; | |
550 | ||
551 | if ((m_height == height) && (m_width == width) && (m_sizeSet)) return; | |
552 | if (!m_wxwindow) return; | |
553 | ||
554 | m_width = width; | |
555 | m_height = height; | |
556 | ||
557 | if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth; | |
558 | if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight; | |
559 | if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_maxWidth; | |
560 | if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_maxHeight; | |
561 | ||
562 | /* we actually set the size of a frame here and no-where else */ | |
563 | gtk_widget_set_usize( m_widget, m_width, m_height ); | |
564 | ||
565 | m_sizeSet = TRUE; | |
566 | ||
567 | wxSizeEvent event( wxSize(m_width,m_height), GetId() ); | |
568 | event.SetEventObject( this ); | |
569 | GetEventHandler()->ProcessEvent( event ); | |
570 | } | |
903f689b | 571 | |
de8113d9 RR |
572 | void wxDialog::OnInternalIdle() |
573 | { | |
1b3667ab | 574 | if (!m_sizeSet && GTK_WIDGET_REALIZED(m_wxwindow)) |
de8113d9 | 575 | GtkOnSize( m_x, m_y, m_width, m_height ); |
5e014a0c RR |
576 | |
577 | wxWindow::OnInternalIdle(); | |
de8113d9 RR |
578 | } |
579 | ||
debe6624 | 580 | bool wxDialog::Show( bool show ) |
c801d85f | 581 | { |
fb1585ae RR |
582 | if (!show && IsModal()) |
583 | { | |
de8113d9 | 584 | EndModal( wxID_CANCEL ); |
fb1585ae | 585 | } |
c801d85f | 586 | |
de8113d9 RR |
587 | if (show && !m_sizeSet) |
588 | { | |
589 | /* by calling GtkOnSize here, we don't have to call | |
590 | either after showing the frame, which would entail | |
591 | much ugly flicker nor from within the size_allocate | |
592 | handler, because GTK 1.1.X forbids that. */ | |
593 | ||
594 | GtkOnSize( m_x, m_y, m_width, m_height ); | |
595 | } | |
2b854a32 | 596 | |
739730ca | 597 | bool ret = wxWindow::Show( show ); |
e146b8c8 | 598 | |
fb1585ae | 599 | if (show) InitDialog(); |
2b854a32 | 600 | |
739730ca | 601 | return ret; |
c33c4050 RR |
602 | } |
603 | ||
43a18898 | 604 | bool wxDialog::IsModal() const |
e1e955e1 | 605 | { |
fb1585ae | 606 | return m_modalShowing; |
e1e955e1 RR |
607 | } |
608 | ||
609 | void wxDialog::SetModal( bool WXUNUSED(flag) ) | |
c33c4050 | 610 | { |
e1e955e1 | 611 | /* |
c33c4050 RR |
612 | if (flag) |
613 | m_windowStyle |= wxDIALOG_MODAL; | |
614 | else | |
615 | if (m_windowStyle & wxDIALOG_MODAL) m_windowStyle -= wxDIALOG_MODAL; | |
e1e955e1 | 616 | */ |
223d09f6 | 617 | wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") ); |
c33c4050 | 618 | } |
c801d85f | 619 | |
43a18898 | 620 | int wxDialog::ShowModal() |
c801d85f | 621 | { |
fb1585ae RR |
622 | if (IsModal()) |
623 | { | |
223d09f6 | 624 | wxFAIL_MSG( wxT("wxDialog:ShowModal called twice") ); |
fb1585ae RR |
625 | return GetReturnCode(); |
626 | } | |
e146b8c8 | 627 | |
eebe4016 | 628 | wxBusyCursorSuspender cs; // temporarily suppress the busy cursor |
7e14e49f | 629 | |
fb1585ae | 630 | Show( TRUE ); |
2b854a32 | 631 | |
fb1585ae | 632 | m_modalShowing = TRUE; |
2b854a32 | 633 | |
fb1585ae RR |
634 | gtk_grab_add( m_widget ); |
635 | gtk_main(); | |
636 | gtk_grab_remove( m_widget ); | |
2b854a32 | 637 | |
fb1585ae | 638 | return GetReturnCode(); |
c33c4050 | 639 | } |
c801d85f KB |
640 | |
641 | void wxDialog::EndModal( int retCode ) | |
642 | { | |
fb1585ae | 643 | SetReturnCode( retCode ); |
2b854a32 | 644 | |
fb1585ae RR |
645 | if (!IsModal()) |
646 | { | |
223d09f6 | 647 | wxFAIL_MSG( wxT("wxDialog:EndModal called twice") ); |
fb1585ae RR |
648 | return; |
649 | } | |
2b854a32 | 650 | |
fb1585ae | 651 | m_modalShowing = FALSE; |
2b854a32 | 652 | |
fb1585ae | 653 | gtk_main_quit(); |
2b854a32 | 654 | |
fb1585ae | 655 | Show( FALSE ); |
c33c4050 | 656 | } |
c801d85f | 657 | |
43a18898 | 658 | void wxDialog::InitDialog() |
c801d85f | 659 | { |
fb1585ae | 660 | wxWindow::InitDialog(); |
c33c4050 RR |
661 | } |
662 | ||
c33c4050 RR |
663 | void wxDialog::SetIcon( const wxIcon &icon ) |
664 | { | |
fb1585ae RR |
665 | m_icon = icon; |
666 | if (!icon.Ok()) return; | |
2b854a32 | 667 | |
f9241296 RR |
668 | if (!m_widget->window) return; |
669 | ||
fb1585ae RR |
670 | wxMask *mask = icon.GetMask(); |
671 | GdkBitmap *bm = (GdkBitmap *) NULL; | |
672 | if (mask) bm = mask->GetBitmap(); | |
2b854a32 | 673 | |
fb1585ae | 674 | gdk_window_set_icon( m_widget->window, (GdkWindow *) NULL, icon.GetPixmap(), bm ); |
c33c4050 | 675 | } |