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