]>
Commit | Line | Data |
---|---|---|
4bb6408c JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dialog.cpp | |
3 | // Purpose: wxDialog class | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 17/09/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "dialog.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/dialog.h" | |
17 | #include "wx/utils.h" | |
18 | #include "wx/frame.h" | |
19 | #include "wx/app.h" | |
20 | #include "wx/settings.h" | |
21 | ||
dfc54541 JS |
22 | #include <Xm/Xm.h> |
23 | ||
24 | #include <X11/Shell.h> | |
25 | #if XmVersion >= 1002 | |
26 | #include <Xm/XmAll.h> | |
27 | #endif | |
28 | #include <Xm/MwmUtil.h> | |
29 | #include <Xm/Label.h> | |
30 | #include <Xm/BulletinB.h> | |
31 | #include <Xm/Frame.h> | |
32 | #include <Xm/Text.h> | |
33 | #include <Xm/DialogS.h> | |
34 | #include <Xm/FileSB.h> | |
35 | #include <Xm/RowColumn.h> | |
36 | #include <Xm/LabelG.h> | |
37 | #include <Xm/AtomMgr.h> | |
38 | #if XmVersion > 1000 | |
39 | #include <Xm/Protocols.h> | |
40 | #endif | |
41 | ||
42 | #include "wx/motif/private.h" | |
43 | ||
44 | static void wxCloseDialogCallback(Widget widget, XtPointer client_data, XmAnyCallbackStruct *cbs); | |
45 | static void wxDialogBoxRepaintProc(Widget w, XtPointer c_data, XEvent *event, char *); | |
46 | static void wxDialogBoxEventHandler (Widget wid, | |
47 | XtPointer client_data, | |
48 | XEvent* event, | |
49 | Boolean *continueToDispatch); | |
50 | ||
51 | static void wxUnmapBulletinBoard(Widget dialog, wxDialog *client,XtPointer call); | |
52 | ||
53 | // A stack of modal_showing flags, since we can't rely | |
54 | // on accessing wxDialog::m_modalShowing within | |
55 | // wxDialog::Show in case a callback has deleted the wxDialog. | |
56 | static wxList wxModalShowingStack; | |
57 | ||
4bb6408c JS |
58 | // Lists to keep track of windows, so we can disable/enable them |
59 | // for modal dialogs | |
60 | wxList wxModalDialogs; | |
61 | wxList wxModelessWindows; // Frames and modeless dialogs | |
62 | extern wxList wxPendingDelete; | |
63 | ||
47d67540 | 64 | #define wxUSE_INVISIBLE_RESIZE 1 |
dfc54541 | 65 | |
4bb6408c JS |
66 | #if !USE_SHARED_LIBRARY |
67 | IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxPanel) | |
68 | ||
69 | BEGIN_EVENT_TABLE(wxDialog, wxPanel) | |
70 | EVT_BUTTON(wxID_OK, wxDialog::OnOK) | |
71 | EVT_BUTTON(wxID_APPLY, wxDialog::OnApply) | |
72 | EVT_BUTTON(wxID_CANCEL, wxDialog::OnCancel) | |
73 | EVT_CHAR_HOOK(wxDialog::OnCharHook) | |
74 | EVT_SYS_COLOUR_CHANGED(wxDialog::OnSysColourChanged) | |
75 | EVT_CLOSE(wxDialog::OnCloseWindow) | |
76 | END_EVENT_TABLE() | |
77 | ||
78 | #endif | |
79 | ||
80 | wxDialog::wxDialog() | |
81 | { | |
dfc54541 | 82 | m_modalShowing = FALSE; |
0d57be45 | 83 | m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE); |
4bb6408c JS |
84 | } |
85 | ||
86 | bool wxDialog::Create(wxWindow *parent, wxWindowID id, | |
87 | const wxString& title, | |
88 | const wxPoint& pos, | |
89 | const wxSize& size, | |
90 | long style, | |
91 | const wxString& name) | |
92 | { | |
dfc54541 JS |
93 | m_windowStyle = style; |
94 | m_modalShowing = FALSE; | |
95 | m_dialogTitle = title; | |
4bb6408c | 96 | |
0d57be45 JS |
97 | m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE); |
98 | m_foregroundColour = *wxBLACK; | |
99 | ||
dfc54541 | 100 | SetName(name); |
4bb6408c | 101 | |
dfc54541 JS |
102 | if (!parent) |
103 | wxTopLevelWindows.Append(this); | |
4bb6408c | 104 | |
dfc54541 | 105 | if (parent) parent->AddChild(this); |
4bb6408c | 106 | |
dfc54541 JS |
107 | if ( id == -1 ) |
108 | m_windowId = (int)NewControlId(); | |
109 | else | |
110 | m_windowId = id; | |
111 | ||
112 | Widget parentWidget = (Widget) 0; | |
113 | if (parent) | |
114 | parentWidget = (Widget) parent->GetTopWidget(); | |
115 | if (!parent) | |
116 | parentWidget = (Widget) wxTheApp->GetTopLevelWidget(); | |
117 | ||
118 | wxASSERT_MSG( (parentWidget != (Widget) 0), "Could not find a suitable parent shell for dialog." ); | |
119 | ||
94b49b93 | 120 | Arg args[2]; |
dfc54541 | 121 | XtSetArg (args[0], XmNdefaultPosition, False); |
94b49b93 JS |
122 | XtSetArg (args[1], XmNautoUnmanage, False); |
123 | Widget dialogShell = XmCreateBulletinBoardDialog(parentWidget, (char*) (const char*) name, args, 2); | |
dfc54541 JS |
124 | m_mainWidget = (WXWidget) dialogShell; |
125 | ||
126 | // We don't want margins, since there is enough elsewhere. | |
127 | XtVaSetValues(dialogShell, | |
128 | XmNmarginHeight, 0, | |
129 | XmNmarginWidth, 0, | |
130 | XmNresizePolicy, XmRESIZE_NONE, | |
131 | NULL) ; | |
132 | ||
133 | Widget shell = XtParent(dialogShell) ; | |
134 | if (!title.IsNull()) | |
135 | { | |
136 | XmString str = XmStringCreateSimple((char*) (const char*)title); | |
137 | XtVaSetValues(dialogShell, | |
138 | XmNdialogTitle, str, | |
139 | NULL); | |
140 | XmStringFree(str); | |
141 | } | |
142 | ||
4b5f3fe6 JS |
143 | m_windowFont = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT); |
144 | ChangeFont(FALSE); | |
145 | ||
dfc54541 JS |
146 | wxAddWindowToTable(dialogShell, this); |
147 | ||
148 | // Intercept CLOSE messages from the window manager | |
149 | Atom WM_DELETE_WINDOW = XmInternAtom(XtDisplay(shell), "WM_DELETE_WINDOW", False); | |
150 | ||
4b5f3fe6 | 151 | /* Remove and add WM_DELETE_WINDOW so ours is only handler */ |
dfc54541 JS |
152 | /* Why do we have to do this for wxDialog, but not wxFrame? */ |
153 | XmRemoveWMProtocols(shell, &WM_DELETE_WINDOW, 1); | |
154 | XmAddWMProtocols(shell, &WM_DELETE_WINDOW, 1); | |
155 | XmActivateWMProtocol(shell, WM_DELETE_WINDOW); | |
156 | ||
157 | // Modified Steve Hammes for Motif 2.0 | |
158 | #if (XmREVISION > 1 || XmVERSION > 1) | |
159 | XmAddWMProtocolCallback(shell, WM_DELETE_WINDOW, (XtCallbackProc) wxCloseDialogCallback, (XtPointer)this); | |
160 | #elif XmREVISION == 1 | |
161 | XmAddWMProtocolCallback(shell, WM_DELETE_WINDOW, (XtCallbackProc) wxCloseDialogCallback, (caddr_t)this); | |
162 | #else | |
163 | XmAddWMProtocolCallback(shell, WM_DELETE_WINDOW, (void (*)())wxCloseDialogCallback, (caddr_t)this); | |
164 | #endif | |
165 | ||
166 | XtTranslations ptr ; | |
167 | XtOverrideTranslations(dialogShell, | |
168 | ptr = XtParseTranslationTable("<Configure>: resize()")); | |
169 | XtFree((char *)ptr); | |
170 | ||
171 | // Can't remember what this was about... but I think it's necessary. | |
172 | ||
dfad0599 | 173 | if (wxUSE_INVISIBLE_RESIZE) |
dfc54541 JS |
174 | { |
175 | if (pos.x > -1) | |
176 | XtVaSetValues(dialogShell, XmNx, pos.x, | |
177 | NULL); | |
178 | if (pos.y > -1) | |
179 | XtVaSetValues(dialogShell, XmNy, pos.y, | |
180 | NULL); | |
181 | ||
182 | if (size.x > -1) | |
183 | XtVaSetValues(dialogShell, XmNwidth, size.x, NULL); | |
184 | if (size.y > -1) | |
185 | XtVaSetValues(dialogShell, XmNheight, size.y, NULL); | |
186 | } | |
187 | ||
188 | // This patch come from Torsten Liermann lier@lier1.muc.de | |
189 | if (XmIsMotifWMRunning(shell)) | |
190 | { | |
191 | int decor = 0 ; | |
192 | if (m_windowStyle & wxRESIZE_BORDER) | |
193 | decor |= MWM_DECOR_RESIZEH ; | |
194 | if (m_windowStyle & wxSYSTEM_MENU) | |
195 | decor |= MWM_DECOR_MENU; | |
196 | if ((m_windowStyle & wxCAPTION) || | |
197 | (m_windowStyle & wxTINY_CAPTION_HORIZ) || | |
198 | (m_windowStyle & wxTINY_CAPTION_VERT)) | |
199 | decor |= MWM_DECOR_TITLE; | |
200 | if (m_windowStyle & wxTHICK_FRAME) | |
201 | decor |= MWM_DECOR_BORDER; | |
202 | if (m_windowStyle & wxMINIMIZE_BOX) | |
203 | decor |= MWM_DECOR_MINIMIZE; | |
204 | if (m_windowStyle & wxMAXIMIZE_BOX) | |
205 | decor |= MWM_DECOR_MAXIMIZE; | |
206 | ||
207 | XtVaSetValues(shell,XmNmwmDecorations,decor,NULL) ; | |
208 | } | |
209 | // This allows non-Motif window managers to support at least the | |
210 | // no-decorations case. | |
211 | else | |
212 | { | |
213 | if ((m_windowStyle & wxCAPTION) != wxCAPTION) | |
214 | XtVaSetValues((Widget) shell,XmNoverrideRedirect,TRUE,NULL); | |
215 | } | |
4bb6408c | 216 | |
dfc54541 | 217 | XtRealizeWidget(dialogShell); |
4bb6408c | 218 | |
dfc54541 JS |
219 | XtAddCallback(dialogShell,XmNunmapCallback, |
220 | (XtCallbackProc)wxUnmapBulletinBoard,this) ; | |
221 | ||
222 | // Positioning of the dialog doesn't work properly unless the dialog | |
223 | // is managed, so we manage without mapping to the screen. | |
224 | // To show, we map the shell (actually it's parent). | |
dfad0599 | 225 | if (!wxUSE_INVISIBLE_RESIZE) |
dfc54541 JS |
226 | XtVaSetValues(shell, XmNmappedWhenManaged, FALSE, NULL); |
227 | ||
dfad0599 | 228 | if (!wxUSE_INVISIBLE_RESIZE) |
dfc54541 JS |
229 | { |
230 | XtManageChild(dialogShell); | |
231 | SetSize(pos.x, pos.y, size.x, size.y); | |
232 | } | |
233 | XtAddEventHandler(dialogShell,ExposureMask,FALSE, | |
234 | wxDialogBoxRepaintProc, (XtPointer) this); | |
235 | ||
236 | XtAddEventHandler(dialogShell, | |
237 | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | KeyPressMask, | |
238 | FALSE, | |
239 | wxDialogBoxEventHandler, | |
240 | (XtPointer)this); | |
241 | ||
0d57be45 JS |
242 | ChangeBackgroundColour(); |
243 | ||
dfc54541 | 244 | return TRUE; |
4bb6408c JS |
245 | } |
246 | ||
247 | void wxDialog::SetModal(bool flag) | |
248 | { | |
dfc54541 JS |
249 | if ( flag ) |
250 | m_windowStyle |= wxDIALOG_MODAL ; | |
251 | else | |
252 | if ( m_windowStyle & wxDIALOG_MODAL ) | |
253 | m_windowStyle -= wxDIALOG_MODAL ; | |
4bb6408c JS |
254 | |
255 | wxModelessWindows.DeleteObject(this); | |
256 | if (!flag) | |
257 | wxModelessWindows.Append(this); | |
258 | } | |
259 | ||
260 | wxDialog::~wxDialog() | |
261 | { | |
dfc54541 | 262 | m_modalShowing = FALSE; |
dfad0599 | 263 | if (!wxUSE_INVISIBLE_RESIZE && m_mainWidget) |
dfc54541 JS |
264 | { |
265 | XtUnmapWidget((Widget) m_mainWidget); | |
266 | } | |
267 | ||
4bb6408c JS |
268 | wxTopLevelWindows.DeleteObject(this); |
269 | ||
270 | if ( (GetWindowStyleFlag() & wxDIALOG_MODAL) != wxDIALOG_MODAL ) | |
271 | wxModelessWindows.DeleteObject(this); | |
272 | ||
273 | // If this is the last top-level window, exit. | |
274 | if (wxTheApp && (wxTopLevelWindows.Number() == 0)) | |
275 | { | |
276 | wxTheApp->SetTopWindow(NULL); | |
277 | ||
278 | if (wxTheApp->GetExitOnFrameDelete()) | |
279 | { | |
dfc54541 | 280 | wxTheApp->ExitMainLoop(); |
4bb6408c JS |
281 | } |
282 | } | |
dfc54541 JS |
283 | |
284 | // This event-flushing code used to be in wxWindow::PostDestroyChildren (wx_dialog.cpp) | |
285 | // but I think this should work, if we destroy the children first. | |
286 | // Note that this might need to be done for wxFrame also. | |
287 | DestroyChildren(); | |
288 | ||
289 | // Now process all events, because otherwise | |
290 | // this might remain on the screen. | |
a4294b78 JS |
291 | Display* display; |
292 | if (m_mainWidget) | |
293 | display = XtDisplay((Widget) m_mainWidget); | |
294 | else | |
295 | display = (Display*) wxGetDisplay(); | |
296 | ||
297 | XSync(display, FALSE); | |
dfc54541 JS |
298 | XEvent event; |
299 | while (XtAppPending((XtAppContext) wxTheApp->GetAppContext())) { | |
a4294b78 | 300 | XFlush(display); |
dfc54541 JS |
301 | XtAppNextEvent((XtAppContext) wxTheApp->GetAppContext(), &event); |
302 | XtDispatchEvent(&event); | |
303 | } | |
4bb6408c JS |
304 | } |
305 | ||
306 | // By default, pressing escape cancels the dialog | |
307 | void wxDialog::OnCharHook(wxKeyEvent& event) | |
308 | { | |
309 | if (event.m_keyCode == WXK_ESCAPE) | |
310 | { | |
311 | // Behaviour changed in 2.0: we'll send a Cancel message | |
312 | // to the dialog instead of Close. | |
313 | wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); | |
314 | cancelEvent.SetEventObject( this ); | |
315 | GetEventHandler()->ProcessEvent(cancelEvent); | |
316 | ||
317 | return; | |
318 | } | |
319 | // We didn't process this event. | |
320 | event.Skip(); | |
321 | } | |
322 | ||
323 | void wxDialog::Iconize(bool WXUNUSED(iconize)) | |
324 | { | |
dfc54541 JS |
325 | // Can't iconize a dialog in Motif, apparently |
326 | // TODO: try using the parent of m_mainShell. | |
327 | // XtVaSetValues((Widget) m_mainWidget, XmNiconic, iconize, NULL); | |
4bb6408c JS |
328 | } |
329 | ||
330 | bool wxDialog::IsIconized() const | |
331 | { | |
dfc54541 JS |
332 | /* |
333 | Boolean iconic; | |
334 | XtVaGetValues((Widget) m_mainWidget, XmNiconic, &iconic, NULL); | |
335 | ||
336 | return iconic; | |
337 | */ | |
4bb6408c JS |
338 | return FALSE; |
339 | } | |
340 | ||
dfc54541 | 341 | void wxDialog::SetSize(int x, int y, int width, int height, int sizeFlags) |
4bb6408c | 342 | { |
dfc54541 JS |
343 | XtVaSetValues((Widget) m_mainWidget, XmNresizePolicy, XmRESIZE_ANY, NULL); |
344 | wxWindow::SetSize(x, y, width, height, sizeFlags); | |
345 | XtVaSetValues((Widget) m_mainWidget, XmNresizePolicy, XmRESIZE_NONE, NULL); | |
4bb6408c JS |
346 | } |
347 | ||
dfc54541 | 348 | void wxDialog::SetClientSize(int width, int height) |
4bb6408c | 349 | { |
dfc54541 | 350 | SetSize(-1, -1, width, height); |
4bb6408c JS |
351 | } |
352 | ||
4bb6408c JS |
353 | |
354 | void wxDialog::SetTitle(const wxString& title) | |
355 | { | |
dfc54541 JS |
356 | m_dialogTitle = title; |
357 | if (!title.IsNull()) | |
358 | { | |
359 | XmString str = XmStringCreateSimple((char*) (const char*) title); | |
360 | XtVaSetValues((Widget) m_mainWidget, | |
361 | XmNtitle, (char*) (const char*) title, | |
362 | XmNdialogTitle, str, // Roberto Cocchi | |
363 | XmNiconName, (char*) (const char*) title, | |
364 | NULL); | |
365 | XmStringFree(str); | |
366 | } | |
4bb6408c JS |
367 | } |
368 | ||
369 | wxString wxDialog::GetTitle() const | |
370 | { | |
dfc54541 | 371 | return m_dialogTitle; |
4bb6408c JS |
372 | } |
373 | ||
374 | void wxDialog::Centre(int direction) | |
375 | { | |
376 | int x_offset,y_offset ; | |
377 | int display_width, display_height; | |
378 | int width, height, x, y; | |
dfc54541 JS |
379 | wxWindow *parent = GetParent(); |
380 | if ((direction & wxCENTER_FRAME) && parent) | |
4bb6408c | 381 | { |
dfc54541 JS |
382 | parent->GetPosition(&x_offset,&y_offset) ; |
383 | parent->GetSize(&display_width,&display_height) ; | |
4bb6408c JS |
384 | } |
385 | else | |
4bb6408c JS |
386 | { |
387 | wxDisplaySize(&display_width, &display_height); | |
388 | x_offset = 0 ; | |
389 | y_offset = 0 ; | |
390 | } | |
391 | ||
392 | GetSize(&width, &height); | |
393 | GetPosition(&x, &y); | |
394 | ||
395 | if (direction & wxHORIZONTAL) | |
396 | x = (int)((display_width - width)/2); | |
397 | if (direction & wxVERTICAL) | |
398 | y = (int)((display_height - height)/2); | |
399 | ||
400 | SetSize(x+x_offset, y+y_offset, width, height); | |
401 | } | |
402 | ||
dfc54541 JS |
403 | void wxDialog::Raise() |
404 | { | |
405 | Window parent_window = XtWindow((Widget) m_mainWidget), | |
406 | next_parent = XtWindow((Widget) m_mainWidget), | |
407 | root = RootWindowOfScreen(XtScreen((Widget) m_mainWidget)); | |
408 | // search for the parent that is child of ROOT, because the WM may | |
409 | // reparent twice and notify only the next parent (like FVWM) | |
410 | while (next_parent != root) { | |
411 | Window *theChildren; unsigned int n; | |
412 | parent_window = next_parent; | |
413 | XQueryTree(XtDisplay((Widget) m_mainWidget), parent_window, &root, | |
414 | &next_parent, &theChildren, &n); | |
415 | XFree(theChildren); // not needed | |
416 | } | |
417 | XRaiseWindow(XtDisplay((Widget) m_mainWidget), parent_window); | |
418 | } | |
419 | ||
420 | void wxDialog::Lower() | |
421 | { | |
422 | Window parent_window = XtWindow((Widget) m_mainWidget), | |
423 | next_parent = XtWindow((Widget) m_mainWidget), | |
424 | root = RootWindowOfScreen(XtScreen((Widget) m_mainWidget)); | |
425 | // search for the parent that is child of ROOT, because the WM may | |
426 | // reparent twice and notify only the next parent (like FVWM) | |
427 | while (next_parent != root) { | |
428 | Window *theChildren; unsigned int n; | |
429 | parent_window = next_parent; | |
430 | XQueryTree(XtDisplay((Widget) m_mainWidget), parent_window, &root, | |
431 | &next_parent, &theChildren, &n); | |
432 | XFree(theChildren); // not needed | |
433 | } | |
434 | XLowerWindow(XtDisplay((Widget) m_mainWidget), parent_window); | |
435 | } | |
436 | ||
437 | bool wxDialog::Show(bool show) | |
438 | { | |
439 | m_isShown = show; | |
440 | ||
441 | if (show) | |
442 | { | |
dfad0599 | 443 | if (!wxUSE_INVISIBLE_RESIZE) |
dfc54541 JS |
444 | XtMapWidget(XtParent((Widget) m_mainWidget)); |
445 | else | |
446 | XtManageChild((Widget) m_mainWidget) ; | |
447 | ||
448 | XRaiseWindow(XtDisplay((Widget) m_mainWidget), XtWindow((Widget) m_mainWidget)); | |
449 | ||
450 | } | |
451 | else | |
452 | { | |
dfad0599 | 453 | if (!wxUSE_INVISIBLE_RESIZE) |
dfc54541 JS |
454 | XtUnmapWidget(XtParent((Widget) m_mainWidget)); |
455 | else | |
456 | XtUnmanageChild((Widget) m_mainWidget) ; | |
457 | ||
458 | XFlush(XtDisplay((Widget) wxTheApp->GetTopLevelWidget())); | |
459 | XSync(XtDisplay((Widget) wxTheApp->GetTopLevelWidget()), FALSE); | |
460 | } | |
461 | ||
462 | return TRUE; | |
463 | } | |
464 | ||
465 | // Shows a dialog modally, returning a return code | |
4bb6408c JS |
466 | int wxDialog::ShowModal() |
467 | { | |
468 | m_windowStyle |= wxDIALOG_MODAL; | |
dfc54541 JS |
469 | |
470 | Show(TRUE); | |
471 | ||
472 | if (m_modalShowing) | |
473 | return 0; | |
474 | ||
475 | wxModalShowingStack.Insert((wxObject *)TRUE); | |
476 | ||
477 | m_modalShowing = TRUE; | |
793f619f | 478 | XtAddGrab((Widget) m_mainWidget, TRUE, FALSE); |
94b49b93 | 479 | |
dfc54541 JS |
480 | XEvent event; |
481 | ||
482 | // Loop until we signal that the dialog should be closed | |
5dcf05ae | 483 | while ((wxModalShowingStack.Number() > 0) && ((int)(wxModalShowingStack.First()->Data()) != 0)) |
dfc54541 | 484 | { |
8aa04e8b JS |
485 | // XtAppProcessEvent((XtAppContext) wxTheApp->GetAppContext(), XtIMAll); |
486 | ||
487 | XtAppNextEvent((XtAppContext) wxTheApp->GetAppContext(), &event); | |
488 | wxTheApp->ProcessXEvent((WXEvent*) &event); | |
dfc54541 JS |
489 | } |
490 | ||
491 | // Remove modal dialog flag from stack | |
492 | wxNode *node = wxModalShowingStack.First(); | |
493 | if (node) | |
494 | delete node; | |
495 | ||
496 | // Now process all events in case they get sent to a destroyed dialog | |
497 | XSync(XtDisplay((Widget) wxTheApp->GetTopLevelWidget()), FALSE); | |
498 | while (XtAppPending((XtAppContext) wxTheApp->GetAppContext())) | |
499 | { | |
500 | XFlush(XtDisplay((Widget) wxTheApp->GetTopLevelWidget())); | |
501 | XtAppNextEvent((XtAppContext) wxTheApp->GetAppContext(), &event); | |
8aa04e8b JS |
502 | |
503 | wxTheApp->ProcessXEvent((WXEvent*) &event); | |
dfc54541 JS |
504 | } |
505 | ||
506 | // TODO: is it safe to call this, if the dialog may have been deleted | |
507 | // by now? Probably only if we're using delayed deletion of dialogs. | |
508 | return GetReturnCode(); | |
4bb6408c JS |
509 | } |
510 | ||
511 | void wxDialog::EndModal(int retCode) | |
512 | { | |
dfc54541 JS |
513 | if (!m_modalShowing) |
514 | return; | |
515 | ||
516 | SetReturnCode(retCode); | |
517 | ||
518 | XtRemoveGrab((Widget) m_mainWidget); | |
519 | ||
520 | Show(FALSE); | |
521 | ||
522 | m_modalShowing = FALSE; | |
523 | ||
524 | wxNode *node = wxModalShowingStack.First(); | |
525 | if (node) | |
526 | node->SetData((wxObject *)FALSE); | |
4bb6408c JS |
527 | } |
528 | ||
529 | // Standard buttons | |
f9e02ac7 | 530 | void wxDialog::OnOK(wxCommandEvent& WXUNUSED(event)) |
4bb6408c JS |
531 | { |
532 | if ( Validate() && TransferDataFromWindow() ) | |
533 | { | |
534 | if ( IsModal() ) | |
535 | EndModal(wxID_OK); | |
536 | else | |
537 | { | |
538 | SetReturnCode(wxID_OK); | |
539 | this->Show(FALSE); | |
540 | } | |
541 | } | |
542 | } | |
543 | ||
f9e02ac7 | 544 | void wxDialog::OnApply(wxCommandEvent& WXUNUSED(event)) |
4bb6408c JS |
545 | { |
546 | if (Validate()) | |
547 | TransferDataFromWindow(); | |
548 | // TODO probably need to disable the Apply button until things change again | |
549 | } | |
550 | ||
f9e02ac7 | 551 | void wxDialog::OnCancel(wxCommandEvent& WXUNUSED(event)) |
4bb6408c JS |
552 | { |
553 | if ( IsModal() ) | |
554 | EndModal(wxID_CANCEL); | |
555 | else | |
556 | { | |
557 | SetReturnCode(wxID_CANCEL); | |
558 | this->Show(FALSE); | |
559 | } | |
560 | } | |
561 | ||
562 | bool wxDialog::OnClose() | |
563 | { | |
564 | // Behaviour changed in 2.0: we'll send a Cancel message by default, | |
565 | // which may close the dialog. | |
566 | // Check for looping if the Cancel event handler calls Close() | |
567 | ||
568 | static wxList closing; | |
569 | ||
570 | if ( closing.Member(this) ) | |
571 | return FALSE; | |
572 | ||
573 | closing.Append(this); | |
574 | ||
575 | wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); | |
576 | cancelEvent.SetEventObject( this ); | |
577 | GetEventHandler()->ProcessEvent(cancelEvent); | |
578 | ||
579 | closing.DeleteObject(this); | |
580 | ||
581 | return FALSE; | |
582 | } | |
583 | ||
584 | void wxDialog::OnCloseWindow(wxCloseEvent& event) | |
585 | { | |
586 | // Compatibility | |
587 | if ( GetEventHandler()->OnClose() || event.GetForce()) | |
588 | { | |
589 | this->Destroy(); | |
590 | } | |
591 | } | |
592 | ||
593 | // Destroy the window (delayed, if a managed window) | |
594 | bool wxDialog::Destroy() | |
595 | { | |
596 | if (!wxPendingDelete.Member(this)) | |
597 | wxPendingDelete.Append(this); | |
598 | return TRUE; | |
599 | } | |
600 | ||
f9e02ac7 | 601 | void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event)) |
4bb6408c JS |
602 | { |
603 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); | |
604 | Refresh(); | |
605 | } | |
606 | ||
607 | void wxDialog::Fit() | |
608 | { | |
609 | } | |
dfc54541 JS |
610 | |
611 | // Handle a close event from the window manager | |
f9e02ac7 RR |
612 | static void wxCloseDialogCallback( Widget WXUNUSED(widget), XtPointer client_data, |
613 | XmAnyCallbackStruct *WXUNUSED(cbs)) | |
dfc54541 JS |
614 | { |
615 | wxDialog *dialog = (wxDialog *)client_data; | |
616 | wxCloseEvent closeEvent(wxEVT_CLOSE_WINDOW, dialog->GetId()); | |
617 | closeEvent.SetEventObject(dialog); | |
618 | ||
619 | // May delete the dialog (with delayed deletion) | |
620 | dialog->GetEventHandler()->ProcessEvent(closeEvent); | |
621 | } | |
622 | ||
623 | // TODO: Preferably, we should have a universal repaint proc. | |
624 | // Meanwhile, use a special one for dialogs. | |
f9e02ac7 | 625 | static void wxDialogBoxRepaintProc(Widget w, XtPointer WXUNUSED(c_data), XEvent *event, char *) |
55acd85e | 626 | { |
dfc54541 | 627 | Window window; |
dfc54541 | 628 | Display *display; |
dfc54541 JS |
629 | |
630 | wxWindow* win = (wxWindow *)wxWidgetHashTable->Get((long)w); | |
631 | if (!win) | |
632 | return; | |
633 | ||
634 | switch(event -> type) | |
55acd85e | 635 | { |
dfc54541 | 636 | case Expose : |
55acd85e | 637 | { |
dfc54541 JS |
638 | window = (Window) win -> GetXWindow(); |
639 | display = (Display *) win -> GetXDisplay(); | |
55acd85e JS |
640 | |
641 | wxRect* rect = new wxRect(event->xexpose.x, event->xexpose.y, | |
642 | event->xexpose.width, event->xexpose.height); | |
643 | win->m_updateRects.Append((wxObject*) rect); | |
644 | ||
645 | if (event -> xexpose.count == 0) | |
646 | { | |
647 | wxPaintEvent event(win->GetId()); | |
648 | event.SetEventObject(win); | |
649 | win->GetEventHandler()->ProcessEvent(event); | |
650 | ||
651 | win->ClearUpdateRects(); | |
652 | } | |
dfc54541 | 653 | break; |
55acd85e JS |
654 | } |
655 | default : | |
656 | { | |
dfc54541 JS |
657 | cout << "\n\nNew Event ! is = " << event -> type << "\n"; |
658 | break; | |
55acd85e JS |
659 | } |
660 | } | |
661 | } | |
dfc54541 JS |
662 | |
663 | static void wxDialogBoxEventHandler (Widget wid, | |
f9e02ac7 | 664 | XtPointer WXUNUSED(client_data), |
dfc54541 JS |
665 | XEvent* event, |
666 | Boolean *continueToDispatch) | |
667 | { | |
668 | wxDialog *dialog = (wxDialog *)wxWidgetHashTable->Get((long)wid); | |
669 | if (dialog) | |
670 | { | |
671 | wxMouseEvent wxevent(wxEVT_NULL); | |
672 | if (wxTranslateMouseEvent(wxevent, dialog, wid, event)) | |
673 | { | |
674 | wxevent.SetEventObject(dialog); | |
675 | wxevent.SetId(dialog->GetId()); | |
676 | dialog->GetEventHandler()->ProcessEvent(wxevent); | |
677 | } | |
678 | else | |
679 | { | |
680 | // An attempt to implement OnCharHook by calling OnCharHook first; | |
681 | // if this returns TRUE, set continueToDispatch to False | |
682 | // (don't continue processing). | |
683 | // Otherwise set it to True and call OnChar. | |
684 | wxKeyEvent keyEvent(wxEVENT_TYPE_CHAR); | |
685 | if (wxTranslateKeyEvent(keyEvent, dialog, wid, event)) | |
686 | { | |
687 | keyEvent.SetEventObject(dialog); | |
688 | keyEvent.SetId(dialog->GetId()); | |
689 | keyEvent.SetEventType(wxEVT_CHAR_HOOK); | |
690 | if (dialog->GetEventHandler()->ProcessEvent(keyEvent)) | |
691 | { | |
692 | *continueToDispatch = False; | |
693 | return; | |
694 | } | |
695 | else | |
696 | { | |
697 | keyEvent.SetEventType(wxEVT_CHAR); | |
698 | dialog->GetEventHandler()->ProcessEvent(keyEvent); | |
699 | } | |
700 | } | |
701 | } | |
702 | } | |
703 | *continueToDispatch = True; | |
704 | } | |
705 | ||
f9e02ac7 | 706 | static void wxUnmapBulletinBoard(Widget WXUNUSED(dialog), wxDialog *WXUNUSED(client), XtPointer WXUNUSED(call) ) |
dfc54541 JS |
707 | { |
708 | /* This gets called when the dialog is being shown, which | |
709 | * defeats modal showing. | |
710 | client->m_modalShowing = FALSE ; | |
711 | client->m_isShown = FALSE; | |
712 | */ | |
713 | } | |
0d57be45 | 714 | |
94b49b93 | 715 | void wxDialog::ChangeFont(bool keepOriginalSize) |
0d57be45 | 716 | { |
94b49b93 | 717 | wxWindow::ChangeFont(keepOriginalSize); |
0d57be45 JS |
718 | } |
719 | ||
720 | void wxDialog::ChangeBackgroundColour() | |
721 | { | |
94b49b93 JS |
722 | if (GetMainWidget()) |
723 | DoChangeBackgroundColour(GetMainWidget(), m_backgroundColour); | |
0d57be45 JS |
724 | } |
725 | ||
726 | void wxDialog::ChangeForegroundColour() | |
727 | { | |
94b49b93 JS |
728 | if (GetMainWidget()) |
729 | DoChangeForegroundColour(GetMainWidget(), m_foregroundColour); | |
0d57be45 JS |
730 | } |
731 |