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