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