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