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