removed wxApp::Initialized() (replaced with a dummy version in wxApp itself); wxApp...
[wxWidgets.git] / src / x11 / app.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: app.cpp
3 // Purpose: wxApp
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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "app.h"
14 #endif
15
16 #include "wx/frame.h"
17 #include "wx/app.h"
18 #include "wx/utils.h"
19 #include "wx/gdicmn.h"
20 #include "wx/icon.h"
21 #include "wx/dialog.h"
22 #include "wx/log.h"
23 #include "wx/module.h"
24 #include "wx/memory.h"
25 #include "wx/log.h"
26 #include "wx/intl.h"
27 #include "wx/evtloop.h"
28 #include "wx/timer.h"
29 #include "wx/filename.h"
30 #include "wx/hash.h"
31
32 #include "wx/univ/theme.h"
33 #include "wx/univ/renderer.h"
34
35 #if wxUSE_THREADS
36 #include "wx/thread.h"
37 #endif
38
39 #include "wx/x11/private.h"
40
41 #include <string.h>
42
43 //------------------------------------------------------------------------
44 // global data
45 //------------------------------------------------------------------------
46
47 extern wxList wxPendingDelete;
48
49 wxHashTable *wxWidgetHashTable = NULL;
50 wxHashTable *wxClientWidgetHashTable = NULL;
51
52 static bool g_showIconic = FALSE;
53 static wxSize g_initialSize = wxDefaultSize;
54
55 // This is required for wxFocusEvent::SetWindow(). It will only
56 // work for focus events which we provoke ourselves (by calling
57 // SetFocus()). It will not work for those events, which X11
58 // generates itself.
59 static wxWindow *g_nextFocus = NULL;
60 static wxWindow *g_prevFocus = NULL;
61
62 //------------------------------------------------------------------------
63 // X11 error handling
64 //------------------------------------------------------------------------
65
66 #ifdef __WXDEBUG__
67 typedef int (*XErrorHandlerFunc)(Display *, XErrorEvent *);
68
69 XErrorHandlerFunc gs_pfnXErrorHandler = 0;
70
71 static int wxXErrorHandler(Display *dpy, XErrorEvent *xevent)
72 {
73 // just forward to the default handler for now
74 if (gs_pfnXErrorHandler)
75 return gs_pfnXErrorHandler(dpy, xevent);
76 else
77 return 0;
78 }
79 #endif // __WXDEBUG__
80
81 //------------------------------------------------------------------------
82 // wxApp
83 //------------------------------------------------------------------------
84
85 long wxApp::sm_lastMessageTime = 0;
86 WXDisplay *wxApp::ms_display = NULL;
87
88 IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
89
90 BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
91 EVT_IDLE(wxAppBase::OnIdle)
92 END_EVENT_TABLE()
93
94 bool wxApp::Initialize(int& argc, wxChar **argv)
95 {
96 #if defined(__WXDEBUG__) && !wxUSE_NANOX
97 // install the X error handler
98 gs_pfnXErrorHandler = XSetErrorHandler( wxXErrorHandler );
99 #endif // __WXDEBUG__
100
101 wxString displayName;
102 bool syncDisplay = FALSE;
103
104 int argcOrig = argc;
105 for ( int i = 0; i < argcOrig; i++ )
106 {
107 if (wxStrcmp( argv[i], _T("-display") ) == 0)
108 {
109 if (i < (argc - 1))
110 {
111 argv[i++] = NULL;
112
113 displayName = argv[i];
114
115 argv[i] = NULL;
116 argc -= 2;
117 }
118 }
119 else if (wxStrcmp( argv[i], _T("-geometry") ) == 0)
120 {
121 if (i < (argc - 1))
122 {
123 argv[i++] = NULL;
124
125 int w, h;
126 if (wxSscanf(argv[i], _T("%dx%d"), &w, &h) != 2)
127 {
128 wxLogError( _("Invalid geometry specification '%s'"),
129 wxString(argv[i]).c_str() );
130 }
131 else
132 {
133 g_initialSize = wxSize(w, h);
134 }
135
136 argv[i] = NULL;
137 argc -= 2;
138 }
139 }
140 else if (wxStrcmp( argv[i], _T("-sync") ) == 0)
141 {
142 syncDisplay = TRUE;
143
144 argv[i] = NULL;
145 argc--;
146 }
147 else if (wxStrcmp( argv[i], _T("-iconic") ) == 0)
148 {
149 g_showIconic = TRUE;
150
151 argv[i] = NULL;
152 argc--;
153 }
154 }
155
156 if ( argc != argcOrig )
157 {
158 // remove the argumens we consumed
159 for ( int i = 0; i < argc; i++ )
160 {
161 while ( !argv[i] )
162 {
163 memmove(argv + i, argv + i + 1, argcOrig - i);
164 }
165 }
166 }
167
168 // X11 display stuff
169 Display *xdisplay;
170 if ( displayName.empty() )
171 xdisplay = XOpenDisplay( NULL );
172 else
173 xdisplay = XOpenDisplay( displayName.ToAscii() );
174 if (!xdisplay)
175 {
176 wxLogError( _("wxWindows could not open display. Exiting.") );
177 return false;
178 }
179
180 if (syncDisplay)
181 XSynchronize(xdisplay, True);
182
183 ms_display = (WXDisplay*) xdisplay;
184
185 XSelectInput( xdisplay, XDefaultRootWindow(xdisplay), PropertyChangeMask);
186
187 // Misc.
188 wxSetDetectableAutoRepeat( TRUE );
189
190 if ( !wxAppBase::Initialize(argc, argv) )
191 {
192 XCloseDisplay(xdisplay);
193
194 return false;
195 }
196
197 #if wxUSE_UNICODE
198 // Glib's type system required by Pango
199 g_type_init();
200 #endif
201
202 #if wxUSE_INTL
203 wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
204 #endif
205
206 wxWidgetHashTable = new wxHashTable(wxKEY_INTEGER);
207 wxClientWidgetHashTable = new wxHashTable(wxKEY_INTEGER);
208
209 return true;
210 }
211
212 void wxApp::CleanUp()
213 {
214 delete wxWidgetHashTable;
215 wxWidgetHashTable = NULL;
216 delete wxClientWidgetHashTable;
217 wxClientWidgetHashTable = NULL;
218
219 wxAppBase::CleanUp();
220 }
221
222 wxApp::wxApp()
223 {
224 // TODO: parse the command line
225 argc = 0;
226 argv = NULL;
227
228 m_mainColormap = (WXColormap) NULL;
229 m_topLevelWidget = (WXWindow) NULL;
230 m_maxRequestSize = 0;
231 m_showIconic = FALSE;
232 m_initialSize = wxDefaultSize;
233
234 #if !wxUSE_NANOX
235 m_visualInfo = NULL;
236 #endif
237 }
238
239 wxApp::~wxApp()
240 {
241 #if !wxUSE_NANOX
242 delete m_visualInfo;
243 #endif
244 }
245
246 #if !wxUSE_NANOX
247 //-----------------------------------------------------------------------
248 // X11 predicate function for exposure compression
249 //-----------------------------------------------------------------------
250
251 struct wxExposeInfo
252 {
253 Window window;
254 Bool found_non_matching;
255 };
256
257 static Bool expose_predicate (Display *display, XEvent *xevent, XPointer arg)
258 {
259 wxExposeInfo *info = (wxExposeInfo*) arg;
260
261 if (info->found_non_matching)
262 return FALSE;
263
264 if (xevent->xany.type != Expose)
265 {
266 info->found_non_matching = TRUE;
267 return FALSE;
268 }
269
270 if (xevent->xexpose.window != info->window)
271 {
272 info->found_non_matching = TRUE;
273 return FALSE;
274 }
275
276 return TRUE;
277 }
278 #endif
279 // wxUSE_NANOX
280
281 //-----------------------------------------------------------------------
282 // Processes an X event, returning TRUE if the event was processed.
283 //-----------------------------------------------------------------------
284
285 bool wxApp::ProcessXEvent(WXEvent* _event)
286 {
287 XEvent* event = (XEvent*) _event;
288
289 wxWindow* win = NULL;
290 Window window = XEventGetWindow(event);
291 #if 0
292 Window actualWindow = window;
293 #endif
294
295 // Find the first wxWindow that corresponds to this event window
296 // Because we're receiving events after a window
297 // has been destroyed, assume a 1:1 match between
298 // Window and wxWindow, so if it's not in the table,
299 // it must have been destroyed.
300
301 win = wxGetWindowFromTable(window);
302 if (!win)
303 {
304 #if wxUSE_TWO_WINDOWS
305 win = wxGetClientWindowFromTable(window);
306 if (!win)
307 #endif
308 return FALSE;
309 }
310
311 #ifdef __WXDEBUG__
312 wxString windowClass = win->GetClassInfo()->GetClassName();
313 #endif
314
315 switch (event->type)
316 {
317 case Expose:
318 {
319 #if wxUSE_TWO_WINDOWS && !wxUSE_NANOX
320 if (event->xexpose.window != (Window)win->GetClientAreaWindow())
321 {
322 XEvent tmp_event;
323 wxExposeInfo info;
324 info.window = event->xexpose.window;
325 info.found_non_matching = FALSE;
326 while (XCheckIfEvent( wxGlobalDisplay(), &tmp_event, expose_predicate, (XPointer) &info ))
327 {
328 // Don't worry about optimizing redrawing the border etc.
329 }
330 win->NeedUpdateNcAreaInIdle();
331 }
332 else
333 #endif
334 {
335 win->GetUpdateRegion().Union( XExposeEventGetX(event), XExposeEventGetY(event),
336 XExposeEventGetWidth(event), XExposeEventGetHeight(event));
337 win->GetClearRegion().Union( XExposeEventGetX(event), XExposeEventGetY(event),
338 XExposeEventGetWidth(event), XExposeEventGetHeight(event));
339
340 #if !wxUSE_NANOX
341 XEvent tmp_event;
342 wxExposeInfo info;
343 info.window = event->xexpose.window;
344 info.found_non_matching = FALSE;
345 while (XCheckIfEvent( wxGlobalDisplay(), &tmp_event, expose_predicate, (XPointer) &info ))
346 {
347 win->GetUpdateRegion().Union( tmp_event.xexpose.x, tmp_event.xexpose.y,
348 tmp_event.xexpose.width, tmp_event.xexpose.height );
349
350 win->GetClearRegion().Union( tmp_event.xexpose.x, tmp_event.xexpose.y,
351 tmp_event.xexpose.width, tmp_event.xexpose.height );
352 }
353 #endif
354
355 // This simplifies the expose and clear areas to simple
356 // rectangles.
357 win->GetUpdateRegion() = win->GetUpdateRegion().GetBox();
358 win->GetClearRegion() = win->GetClearRegion().GetBox();
359
360 // If we only have one X11 window, always indicate
361 // that borders might have to be redrawn.
362 if (win->GetMainWindow() == win->GetClientAreaWindow())
363 win->NeedUpdateNcAreaInIdle();
364
365 // Only erase background, paint in idle time.
366 win->SendEraseEvents();
367
368 // EXPERIMENT
369 //win->Update();
370 }
371
372 return TRUE;
373 }
374
375 #if !wxUSE_NANOX
376 case GraphicsExpose:
377 {
378 printf( "GraphicExpose event\n" );
379
380 wxLogTrace( _T("expose"), _T("GraphicsExpose from %s"), win->GetName().c_str());
381
382 win->GetUpdateRegion().Union( event->xgraphicsexpose.x, event->xgraphicsexpose.y,
383 event->xgraphicsexpose.width, event->xgraphicsexpose.height);
384
385 win->GetClearRegion().Union( event->xgraphicsexpose.x, event->xgraphicsexpose.y,
386 event->xgraphicsexpose.width, event->xgraphicsexpose.height);
387
388 if (event->xgraphicsexpose.count == 0)
389 {
390 // Only erase background, paint in idle time.
391 win->SendEraseEvents();
392 // win->Update();
393 }
394
395 return TRUE;
396 }
397 #endif
398
399 case KeyPress:
400 {
401 if (!win->IsEnabled())
402 return FALSE;
403
404 wxKeyEvent keyEvent(wxEVT_KEY_DOWN);
405 wxTranslateKeyEvent(keyEvent, win, window, event);
406
407 // wxLogDebug( "OnKey from %s", win->GetName().c_str() );
408
409 // We didn't process wxEVT_KEY_DOWN, so send wxEVT_CHAR
410 if (win->GetEventHandler()->ProcessEvent( keyEvent ))
411 return TRUE;
412
413 keyEvent.SetEventType(wxEVT_CHAR);
414 // Do the translation again, retaining the ASCII
415 // code.
416 wxTranslateKeyEvent(keyEvent, win, window, event, TRUE);
417 if (win->GetEventHandler()->ProcessEvent( keyEvent ))
418 return TRUE;
419
420 if ( (keyEvent.m_keyCode == WXK_TAB) &&
421 win->GetParent() && (win->GetParent()->HasFlag( wxTAB_TRAVERSAL)) )
422 {
423 wxNavigationKeyEvent new_event;
424 new_event.SetEventObject( win->GetParent() );
425 /* GDK reports GDK_ISO_Left_Tab for SHIFT-TAB */
426 new_event.SetDirection( (keyEvent.m_keyCode == WXK_TAB) );
427 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
428 new_event.SetWindowChange( keyEvent.ControlDown() );
429 new_event.SetCurrentFocus( win );
430 return win->GetParent()->GetEventHandler()->ProcessEvent( new_event );
431 }
432
433 return FALSE;
434 }
435 case KeyRelease:
436 {
437 if (!win->IsEnabled())
438 return FALSE;
439
440 wxKeyEvent keyEvent(wxEVT_KEY_UP);
441 wxTranslateKeyEvent(keyEvent, win, window, event);
442
443 return win->GetEventHandler()->ProcessEvent( keyEvent );
444 }
445 case ConfigureNotify:
446 {
447 #if wxUSE_NANOX
448 if (event->update.utype == GR_UPDATE_SIZE)
449 #endif
450 {
451 if (win->IsTopLevel())
452 {
453 wxTopLevelWindow *tlw = (wxTopLevelWindow*) win;
454 tlw->SetConfigureGeometry( XConfigureEventGetX(event), XConfigureEventGetY(event),
455 XConfigureEventGetWidth(event), XConfigureEventGetHeight(event) );
456 }
457
458 if (win->IsTopLevel() && win->IsShown())
459 {
460 wxTopLevelWindowX11 *tlw = (wxTopLevelWindowX11 *) win;
461 tlw->SetNeedResizeInIdle();
462 }
463 else
464 {
465 wxSizeEvent sizeEvent( wxSize(XConfigureEventGetWidth(event), XConfigureEventGetHeight(event)), win->GetId() );
466 sizeEvent.SetEventObject( win );
467
468 return win->GetEventHandler()->ProcessEvent( sizeEvent );
469 }
470 }
471 return FALSE;
472 break;
473 }
474 #if !wxUSE_NANOX
475 case PropertyNotify:
476 {
477 //wxLogDebug("PropertyNotify: %s", windowClass.c_str());
478 return HandlePropertyChange(_event);
479 }
480 case ClientMessage:
481 {
482 if (!win->IsEnabled())
483 return FALSE;
484
485 Atom wm_delete_window = XInternAtom(wxGlobalDisplay(), "WM_DELETE_WINDOW", True);
486 Atom wm_protocols = XInternAtom(wxGlobalDisplay(), "WM_PROTOCOLS", True);
487
488 if (event->xclient.message_type == wm_protocols)
489 {
490 if ((Atom) (event->xclient.data.l[0]) == wm_delete_window)
491 {
492 win->Close(FALSE);
493 return TRUE;
494 }
495 }
496 return FALSE;
497 }
498 #if 0
499 case DestroyNotify:
500 {
501 printf( "destroy from %s\n", win->GetName().c_str() );
502 break;
503 }
504 case CreateNotify:
505 {
506 printf( "create from %s\n", win->GetName().c_str() );
507 break;
508 }
509 case MapRequest:
510 {
511 printf( "map request from %s\n", win->GetName().c_str() );
512 break;
513 }
514 case ResizeRequest:
515 {
516 printf( "resize request from %s\n", win->GetName().c_str() );
517
518 Display *disp = (Display*) wxGetDisplay();
519 XEvent report;
520
521 // to avoid flicker
522 report = * event;
523 while( XCheckTypedWindowEvent (disp, actualWindow, ResizeRequest, &report));
524
525 wxSize sz = win->GetSize();
526 wxSizeEvent sizeEvent(sz, win->GetId());
527 sizeEvent.SetEventObject(win);
528
529 return win->GetEventHandler()->ProcessEvent( sizeEvent );
530 }
531 #endif
532 #endif
533 #if wxUSE_NANOX
534 case GR_EVENT_TYPE_CLOSE_REQ:
535 {
536 if (win)
537 {
538 win->Close(FALSE);
539 return TRUE;
540 }
541 return FALSE;
542 break;
543 }
544 #endif
545 case EnterNotify:
546 case LeaveNotify:
547 case ButtonPress:
548 case ButtonRelease:
549 case MotionNotify:
550 {
551 if (!win->IsEnabled())
552 return FALSE;
553
554 // Here we check if the top level window is
555 // disabled, which is one aspect of modality.
556 wxWindow *tlw = win;
557 while (tlw && !tlw->IsTopLevel())
558 tlw = tlw->GetParent();
559 if (tlw && !tlw->IsEnabled())
560 return FALSE;
561
562 if (event->type == ButtonPress)
563 {
564 if ((win != wxWindow::FindFocus()) && win->AcceptsFocus())
565 {
566 // This might actually be done in wxWindow::SetFocus()
567 // and not here. TODO.
568 g_prevFocus = wxWindow::FindFocus();
569 g_nextFocus = win;
570
571 wxLogTrace( _T("focus"), _T("About to call SetFocus on %s of type %s due to button press"), win->GetName().c_str(), win->GetClassInfo()->GetClassName() );
572
573 // Record the fact that this window is
574 // getting the focus, because we'll need to
575 // check if its parent is getting a bogus
576 // focus and duly ignore it.
577 // TODO: may need to have this code in SetFocus, too.
578 extern wxWindow* g_GettingFocus;
579 g_GettingFocus = win;
580 win->SetFocus();
581 }
582 }
583
584 #if !wxUSE_NANOX
585 if (event->type == LeaveNotify || event->type == EnterNotify)
586 {
587 // Throw out NotifyGrab and NotifyUngrab
588 if (event->xcrossing.mode != NotifyNormal)
589 return FALSE;
590 }
591 #endif
592 wxMouseEvent wxevent;
593 wxTranslateMouseEvent(wxevent, win, window, event);
594 return win->GetEventHandler()->ProcessEvent( wxevent );
595 }
596 case FocusIn:
597 #if !wxUSE_NANOX
598 if ((event->xfocus.detail != NotifyPointer) &&
599 (event->xfocus.mode == NotifyNormal))
600 #endif
601 {
602 wxLogTrace( _T("focus"), _T("FocusIn from %s of type %s"), win->GetName().c_str(), win->GetClassInfo()->GetClassName() );
603
604 extern wxWindow* g_GettingFocus;
605 if (g_GettingFocus && g_GettingFocus->GetParent() == win)
606 {
607 // Ignore this, this can be a spurious FocusIn
608 // caused by a child having its focus set.
609 g_GettingFocus = NULL;
610 wxLogTrace( _T("focus"), _T("FocusIn from %s of type %s being deliberately ignored"), win->GetName().c_str(), win->GetClassInfo()->GetClassName() );
611 return TRUE;
612 }
613 else
614 {
615 wxFocusEvent focusEvent(wxEVT_SET_FOCUS, win->GetId());
616 focusEvent.SetEventObject(win);
617 focusEvent.SetWindow( g_prevFocus );
618 g_prevFocus = NULL;
619
620 return win->GetEventHandler()->ProcessEvent(focusEvent);
621 }
622 }
623 return FALSE;
624
625 case FocusOut:
626 #if !wxUSE_NANOX
627 if ((event->xfocus.detail != NotifyPointer) &&
628 (event->xfocus.mode == NotifyNormal))
629 #endif
630 {
631 wxLogTrace( _T("focus"), _T("FocusOut from %s of type %s"), win->GetName().c_str(), win->GetClassInfo()->GetClassName() );
632
633 wxFocusEvent focusEvent(wxEVT_KILL_FOCUS, win->GetId());
634 focusEvent.SetEventObject(win);
635 focusEvent.SetWindow( g_nextFocus );
636 g_nextFocus = NULL;
637 return win->GetEventHandler()->ProcessEvent(focusEvent);
638 }
639 return FALSE;
640
641 #ifdef __WXDEBUG__
642 default:
643 //wxString eventName = wxGetXEventName(XEvent& event);
644 //wxLogDebug(wxT("Event %s not handled"), eventName.c_str());
645 break;
646 #endif // __WXDEBUG__
647 }
648
649 return FALSE;
650 }
651
652 // This should be redefined in a derived class for
653 // handling property change events for XAtom IPC.
654 bool wxApp::HandlePropertyChange(WXEvent *event)
655 {
656 // by default do nothing special
657 // TODO: what to do for X11
658 // XtDispatchEvent((XEvent*) event);
659 return FALSE;
660 }
661
662 void wxApp::WakeUpIdle()
663 {
664 // TODO: use wxMotif implementation?
665
666 // Wake up the idle handler processor, even if it is in another thread...
667 }
668
669
670 // Create display, and other initialization
671 bool wxApp::OnInitGui()
672 {
673 // Eventually this line will be removed, but for
674 // now we don't want to try popping up a dialog
675 // for error messages.
676 delete wxLog::SetActiveTarget(new wxLogStderr);
677
678 if (!wxAppBase::OnInitGui())
679 return FALSE;
680
681 GetMainColormap( wxApp::GetDisplay() );
682
683 m_maxRequestSize = XMaxRequestSize( (Display*) wxApp::GetDisplay() );
684
685 #if !wxUSE_NANOX
686 m_visualInfo = new wxXVisualInfo;
687 wxFillXVisualInfo( m_visualInfo, (Display*) wxApp::GetDisplay() );
688 #endif
689
690 return TRUE;
691 }
692
693 #if wxUSE_UNICODE
694
695 #include <pango/pango.h>
696 #include <pango/pangox.h>
697 #include <pango/pangoxft.h>
698
699 PangoContext* wxApp::GetPangoContext()
700 {
701 static PangoContext *ret = NULL;
702 if (ret)
703 return ret;
704
705 Display *xdisplay = (Display*) wxApp::GetDisplay();
706
707 #if 1
708 int xscreen = DefaultScreen(xdisplay);
709 static int use_xft = -1;
710 if (use_xft == -1)
711 {
712 wxString val = wxGetenv( L"GDK_USE_XFT" );
713 use_xft = (val == L"1");
714 }
715
716 if (use_xft)
717 ret = pango_xft_get_context( xdisplay, xscreen );
718 else
719 #endif
720 ret = pango_x_get_context( xdisplay );
721
722 if (!PANGO_IS_CONTEXT(ret))
723 wxLogError( wxT("No pango context.") );
724
725 return ret;
726 }
727 #endif
728
729 WXColormap wxApp::GetMainColormap(WXDisplay* display)
730 {
731 if (!display) /* Must be called first with non-NULL display */
732 return m_mainColormap;
733
734 int defaultScreen = DefaultScreen((Display*) display);
735 Screen* screen = XScreenOfDisplay((Display*) display, defaultScreen);
736
737 Colormap c = DefaultColormapOfScreen(screen);
738
739 if (!m_mainColormap)
740 m_mainColormap = (WXColormap) c;
741
742 return (WXColormap) c;
743 }
744
745 Window wxGetWindowParent(Window window)
746 {
747 wxASSERT_MSG( window, _T("invalid window") );
748
749 return (Window) 0;
750
751 Window parent, root = 0;
752 #if wxUSE_NANOX
753 int noChildren = 0;
754 #else
755 unsigned int noChildren = 0;
756 #endif
757 Window* children = NULL;
758
759 // #define XQueryTree(d,w,r,p,c,nc) GrQueryTree(w,p,c,nc)
760 int res = 1;
761 #if !wxUSE_NANOX
762 res =
763 #endif
764 XQueryTree((Display*) wxGetDisplay(), window, & root, & parent,
765 & children, & noChildren);
766 if (children)
767 XFree(children);
768 if (res)
769 return parent;
770 else
771 return (Window) 0;
772 }
773
774 void wxApp::Exit()
775 {
776 wxApp::CleanUp();
777
778 wxAppConsole::Exit();
779 }
780
781 // Yield to other processes
782
783 bool wxApp::Yield(bool onlyIfNeeded)
784 {
785 // Sometimes only 2 yields seem
786 // to do the trick, e.g. in the
787 // progress dialog
788 int i;
789 for (i = 0; i < 2; i++)
790 {
791 bool s_inYield = FALSE;
792
793 if ( s_inYield )
794 {
795 if ( !onlyIfNeeded )
796 {
797 wxFAIL_MSG( wxT("wxYield called recursively" ) );
798 }
799
800 return FALSE;
801 }
802
803 s_inYield = TRUE;
804
805 // Make sure we have an event loop object,
806 // or Pending/Dispatch will fail
807 wxEventLoop* eventLoop = wxEventLoop::GetActive();
808 wxEventLoop* newEventLoop = NULL;
809 if (!eventLoop)
810 {
811 newEventLoop = new wxEventLoop;
812 wxEventLoop::SetActive(newEventLoop);
813 }
814
815 // Call dispatch at least once so that sockets
816 // can be tested
817 wxTheApp->Dispatch();
818
819 while (wxTheApp && wxTheApp->Pending())
820 wxTheApp->Dispatch();
821
822 #if wxUSE_TIMER
823 wxTimer::NotifyTimers();
824 #endif
825 ProcessIdle();
826
827 if (newEventLoop)
828 {
829 wxEventLoop::SetActive(NULL);
830 delete newEventLoop;
831 }
832
833 s_inYield = FALSE;
834 }
835
836 return TRUE;
837 }
838
839 #ifdef __WXDEBUG__
840
841 void wxApp::OnAssert(const wxChar *file, int line, const wxChar* cond, const wxChar *msg)
842 {
843 // While the GUI isn't working that well, just print out the
844 // message.
845 #if 1
846 wxAppBase::OnAssert(file, line, cond, msg);
847 #else
848 wxString msg2;
849 msg2.Printf("At file %s:%d: %s", file, line, msg);
850 wxLogDebug(msg2);
851 #endif
852 }
853
854 #endif // __WXDEBUG__
855