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