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