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