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