]> git.saurik.com Git - wxWidgets.git/blob - src/x11/app.cpp
Convert back to UNIX line endings (again)
[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 wxWindowHash *wxWidgetHashTable = NULL;
50 wxWindowHash *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( _("wxWidgets 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 wxWindowHash;
207 wxClientWidgetHashTable = new wxWindowHash;
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 wxLogTrace( _T("expose"), _T("GraphicsExpose from %s"), win->GetName().c_str());
379
380 win->GetUpdateRegion().Union( event->xgraphicsexpose.x, event->xgraphicsexpose.y,
381 event->xgraphicsexpose.width, event->xgraphicsexpose.height);
382
383 win->GetClearRegion().Union( event->xgraphicsexpose.x, event->xgraphicsexpose.y,
384 event->xgraphicsexpose.width, event->xgraphicsexpose.height);
385
386 if (event->xgraphicsexpose.count == 0)
387 {
388 // Only erase background, paint in idle time.
389 win->SendEraseEvents();
390 // win->Update();
391 }
392
393 return TRUE;
394 }
395 #endif
396
397 case KeyPress:
398 {
399 if (!win->IsEnabled())
400 return FALSE;
401
402 wxKeyEvent keyEvent(wxEVT_KEY_DOWN);
403 wxTranslateKeyEvent(keyEvent, win, window, event);
404
405 // wxLogDebug( "OnKey from %s", win->GetName().c_str() );
406
407 // We didn't process wxEVT_KEY_DOWN, so send wxEVT_CHAR
408 if (win->GetEventHandler()->ProcessEvent( keyEvent ))
409 return TRUE;
410
411 keyEvent.SetEventType(wxEVT_CHAR);
412 // Do the translation again, retaining the ASCII
413 // code.
414 wxTranslateKeyEvent(keyEvent, win, window, event, TRUE);
415 if (win->GetEventHandler()->ProcessEvent( keyEvent ))
416 return TRUE;
417
418 if ( (keyEvent.m_keyCode == WXK_TAB) &&
419 win->GetParent() && (win->GetParent()->HasFlag( wxTAB_TRAVERSAL)) )
420 {
421 wxNavigationKeyEvent new_event;
422 new_event.SetEventObject( win->GetParent() );
423 /* GDK reports GDK_ISO_Left_Tab for SHIFT-TAB */
424 new_event.SetDirection( (keyEvent.m_keyCode == WXK_TAB) );
425 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
426 new_event.SetWindowChange( keyEvent.ControlDown() );
427 new_event.SetCurrentFocus( win );
428 return win->GetParent()->GetEventHandler()->ProcessEvent( new_event );
429 }
430
431 return FALSE;
432 }
433 case KeyRelease:
434 {
435 if (!win->IsEnabled())
436 return FALSE;
437
438 wxKeyEvent keyEvent(wxEVT_KEY_UP);
439 wxTranslateKeyEvent(keyEvent, win, window, event);
440
441 return win->GetEventHandler()->ProcessEvent( keyEvent );
442 }
443 case ConfigureNotify:
444 {
445 #if wxUSE_NANOX
446 if (event->update.utype == GR_UPDATE_SIZE)
447 #endif
448 {
449 wxTopLevelWindow *tlw = wxDynamicCast(win, wxTopLevelWindow);
450 if ( tlw )
451 {
452 tlw->SetConfigureGeometry( XConfigureEventGetX(event), XConfigureEventGetY(event),
453 XConfigureEventGetWidth(event), XConfigureEventGetHeight(event) );
454 }
455
456 if ( tlw && tlw->IsShown() )
457 {
458 tlw->SetNeedResizeInIdle();
459 }
460 else
461 {
462 wxSizeEvent sizeEvent( wxSize(XConfigureEventGetWidth(event), XConfigureEventGetHeight(event)), win->GetId() );
463 sizeEvent.SetEventObject( win );
464
465 return win->GetEventHandler()->ProcessEvent( sizeEvent );
466 }
467 }
468 return FALSE;
469 }
470 #if !wxUSE_NANOX
471 case PropertyNotify:
472 {
473 //wxLogDebug("PropertyNotify: %s", windowClass.c_str());
474 return HandlePropertyChange(_event);
475 }
476 case ClientMessage:
477 {
478 if (!win->IsEnabled())
479 return FALSE;
480
481 Atom wm_delete_window = XInternAtom(wxGlobalDisplay(), "WM_DELETE_WINDOW", True);
482 Atom wm_protocols = XInternAtom(wxGlobalDisplay(), "WM_PROTOCOLS", True);
483
484 if (event->xclient.message_type == wm_protocols)
485 {
486 if ((Atom) (event->xclient.data.l[0]) == wm_delete_window)
487 {
488 win->Close(FALSE);
489 return TRUE;
490 }
491 }
492 return FALSE;
493 }
494 #if 0
495 case DestroyNotify:
496 {
497 printf( "destroy from %s\n", win->GetName().c_str() );
498 break;
499 }
500 case CreateNotify:
501 {
502 printf( "create from %s\n", win->GetName().c_str() );
503 break;
504 }
505 case MapRequest:
506 {
507 printf( "map request from %s\n", win->GetName().c_str() );
508 break;
509 }
510 case ResizeRequest:
511 {
512 printf( "resize request from %s\n", win->GetName().c_str() );
513
514 Display *disp = (Display*) wxGetDisplay();
515 XEvent report;
516
517 // to avoid flicker
518 report = * event;
519 while( XCheckTypedWindowEvent (disp, actualWindow, ResizeRequest, &report));
520
521 wxSize sz = win->GetSize();
522 wxSizeEvent sizeEvent(sz, win->GetId());
523 sizeEvent.SetEventObject(win);
524
525 return win->GetEventHandler()->ProcessEvent( sizeEvent );
526 }
527 #endif
528 #endif
529 #if wxUSE_NANOX
530 case GR_EVENT_TYPE_CLOSE_REQ:
531 {
532 if (win)
533 {
534 win->Close(FALSE);
535 return TRUE;
536 }
537 return FALSE;
538 break;
539 }
540 #endif
541 case EnterNotify:
542 case LeaveNotify:
543 case ButtonPress:
544 case ButtonRelease:
545 case MotionNotify:
546 {
547 if (!win->IsEnabled())
548 return FALSE;
549
550 // Here we check if the top level window is
551 // disabled, which is one aspect of modality.
552 wxWindow *tlw = win;
553 while (tlw && !tlw->IsTopLevel())
554 tlw = tlw->GetParent();
555 if (tlw && !tlw->IsEnabled())
556 return FALSE;
557
558 if (event->type == ButtonPress)
559 {
560 if ((win != wxWindow::FindFocus()) && win->AcceptsFocus())
561 {
562 // This might actually be done in wxWindow::SetFocus()
563 // and not here. TODO.
564 g_prevFocus = wxWindow::FindFocus();
565 g_nextFocus = win;
566
567 wxLogTrace( _T("focus"), _T("About to call SetFocus on %s of type %s due to button press"), win->GetName().c_str(), win->GetClassInfo()->GetClassName() );
568
569 // Record the fact that this window is
570 // getting the focus, because we'll need to
571 // check if its parent is getting a bogus
572 // focus and duly ignore it.
573 // TODO: may need to have this code in SetFocus, too.
574 extern wxWindow* g_GettingFocus;
575 g_GettingFocus = win;
576 win->SetFocus();
577 }
578 }
579
580 #if !wxUSE_NANOX
581 if (event->type == LeaveNotify || event->type == EnterNotify)
582 {
583 // Throw out NotifyGrab and NotifyUngrab
584 if (event->xcrossing.mode != NotifyNormal)
585 return FALSE;
586 }
587 #endif
588 wxMouseEvent wxevent;
589 wxTranslateMouseEvent(wxevent, win, window, event);
590 return win->GetEventHandler()->ProcessEvent( wxevent );
591 }
592 case FocusIn:
593 #if !wxUSE_NANOX
594 if ((event->xfocus.detail != NotifyPointer) &&
595 (event->xfocus.mode == NotifyNormal))
596 #endif
597 {
598 wxLogTrace( _T("focus"), _T("FocusIn from %s of type %s"), win->GetName().c_str(), win->GetClassInfo()->GetClassName() );
599
600 extern wxWindow* g_GettingFocus;
601 if (g_GettingFocus && g_GettingFocus->GetParent() == win)
602 {
603 // Ignore this, this can be a spurious FocusIn
604 // caused by a child having its focus set.
605 g_GettingFocus = NULL;
606 wxLogTrace( _T("focus"), _T("FocusIn from %s of type %s being deliberately ignored"), win->GetName().c_str(), win->GetClassInfo()->GetClassName() );
607 return TRUE;
608 }
609 else
610 {
611 wxFocusEvent focusEvent(wxEVT_SET_FOCUS, win->GetId());
612 focusEvent.SetEventObject(win);
613 focusEvent.SetWindow( g_prevFocus );
614 g_prevFocus = NULL;
615
616 return win->GetEventHandler()->ProcessEvent(focusEvent);
617 }
618 }
619 return FALSE;
620
621 case FocusOut:
622 #if !wxUSE_NANOX
623 if ((event->xfocus.detail != NotifyPointer) &&
624 (event->xfocus.mode == NotifyNormal))
625 #endif
626 {
627 wxLogTrace( _T("focus"), _T("FocusOut from %s of type %s"), win->GetName().c_str(), win->GetClassInfo()->GetClassName() );
628
629 wxFocusEvent focusEvent(wxEVT_KILL_FOCUS, win->GetId());
630 focusEvent.SetEventObject(win);
631 focusEvent.SetWindow( g_nextFocus );
632 g_nextFocus = NULL;
633 return win->GetEventHandler()->ProcessEvent(focusEvent);
634 }
635 return FALSE;
636
637 #ifdef __WXDEBUG__
638 default:
639 //wxString eventName = wxGetXEventName(XEvent& event);
640 //wxLogDebug(wxT("Event %s not handled"), eventName.c_str());
641 break;
642 #endif // __WXDEBUG__
643 }
644
645 return FALSE;
646 }
647
648 // This should be redefined in a derived class for
649 // handling property change events for XAtom IPC.
650 bool wxApp::HandlePropertyChange(WXEvent *event)
651 {
652 // by default do nothing special
653 // TODO: what to do for X11
654 // XtDispatchEvent((XEvent*) event);
655 return FALSE;
656 }
657
658 void wxApp::WakeUpIdle()
659 {
660 // TODO: use wxMotif implementation?
661
662 // Wake up the idle handler processor, even if it is in another thread...
663 }
664
665
666 // Create display, and other initialization
667 bool wxApp::OnInitGui()
668 {
669 // Eventually this line will be removed, but for
670 // now we don't want to try popping up a dialog
671 // for error messages.
672 delete wxLog::SetActiveTarget(new wxLogStderr);
673
674 if (!wxAppBase::OnInitGui())
675 return FALSE;
676
677 GetMainColormap( wxApp::GetDisplay() );
678
679 m_maxRequestSize = XMaxRequestSize( (Display*) wxApp::GetDisplay() );
680
681 #if !wxUSE_NANOX
682 m_visualInfo = new wxXVisualInfo;
683 wxFillXVisualInfo( m_visualInfo, (Display*) wxApp::GetDisplay() );
684 #endif
685
686 return TRUE;
687 }
688
689 #if wxUSE_UNICODE
690
691 #include <pango/pango.h>
692 #include <pango/pangox.h>
693 #include <pango/pangoxft.h>
694
695 PangoContext* wxApp::GetPangoContext()
696 {
697 static PangoContext *ret = NULL;
698 if (ret)
699 return ret;
700
701 Display *xdisplay = (Display*) wxApp::GetDisplay();
702
703 #if 1
704 int xscreen = DefaultScreen(xdisplay);
705 static int use_xft = -1;
706 if (use_xft == -1)
707 {
708 wxString val = wxGetenv( L"GDK_USE_XFT" );
709 use_xft = (val == L"1");
710 }
711
712 if (use_xft)
713 ret = pango_xft_get_context( xdisplay, xscreen );
714 else
715 #endif
716 ret = pango_x_get_context( xdisplay );
717
718 if (!PANGO_IS_CONTEXT(ret))
719 wxLogError( wxT("No pango context.") );
720
721 return ret;
722 }
723 #endif
724
725 WXColormap wxApp::GetMainColormap(WXDisplay* display)
726 {
727 if (!display) /* Must be called first with non-NULL display */
728 return m_mainColormap;
729
730 int defaultScreen = DefaultScreen((Display*) display);
731 Screen* screen = XScreenOfDisplay((Display*) display, defaultScreen);
732
733 Colormap c = DefaultColormapOfScreen(screen);
734
735 if (!m_mainColormap)
736 m_mainColormap = (WXColormap) c;
737
738 return (WXColormap) c;
739 }
740
741 Window wxGetWindowParent(Window window)
742 {
743 wxASSERT_MSG( window, _T("invalid window") );
744
745 return (Window) 0;
746
747 #ifndef __VMS
748 // VMS chokes on unreacheable code
749 Window parent, root = 0;
750 #if wxUSE_NANOX
751 int noChildren = 0;
752 #else
753 unsigned int noChildren = 0;
754 #endif
755 Window* children = NULL;
756
757 // #define XQueryTree(d,w,r,p,c,nc) GrQueryTree(w,p,c,nc)
758 int res = 1;
759 #if !wxUSE_NANOX
760 res =
761 #endif
762 XQueryTree((Display*) wxGetDisplay(), window, & root, & parent,
763 & children, & noChildren);
764 if (children)
765 XFree(children);
766 if (res)
767 return parent;
768 else
769 return (Window) 0;
770 #endif
771 }
772
773 void wxApp::Exit()
774 {
775 wxApp::CleanUp();
776
777 wxAppConsole::Exit();
778 }
779
780 // Yield to other processes
781
782 bool wxApp::Yield(bool onlyIfNeeded)
783 {
784 // Sometimes only 2 yields seem
785 // to do the trick, e.g. in the
786 // progress dialog
787 int i;
788 for (i = 0; i < 2; i++)
789 {
790 static bool s_inYield = FALSE;
791
792 if ( s_inYield )
793 {
794 if ( !onlyIfNeeded )
795 {
796 wxFAIL_MSG( wxT("wxYield called recursively" ) );
797 }
798
799 return FALSE;
800 }
801
802 s_inYield = TRUE;
803
804 // Make sure we have an event loop object,
805 // or Pending/Dispatch will fail
806 wxEventLoop* eventLoop = wxEventLoop::GetActive();
807 wxEventLoop* newEventLoop = NULL;
808 if (!eventLoop)
809 {
810 newEventLoop = new wxEventLoop;
811 wxEventLoop::SetActive(newEventLoop);
812 }
813
814 // Call dispatch at least once so that sockets
815 // can be tested
816 wxTheApp->Dispatch();
817
818 while (wxTheApp && wxTheApp->Pending())
819 wxTheApp->Dispatch();
820
821 #if wxUSE_TIMER
822 wxTimer::NotifyTimers();
823 #endif
824 ProcessIdle();
825
826 if (newEventLoop)
827 {
828 wxEventLoop::SetActive(NULL);
829 delete newEventLoop;
830 }
831
832 s_inYield = FALSE;
833 }
834
835 return TRUE;
836 }
837
838 #ifdef __WXDEBUG__
839
840 void wxApp::OnAssert(const wxChar *file, int line, const wxChar* cond, const wxChar *msg)
841 {
842 // While the GUI isn't working that well, just print out the
843 // message.
844 #if 1
845 wxAppBase::OnAssert(file, line, cond, msg);
846 #else
847 wxString msg2;
848 msg2.Printf("At file %s:%d: %s", file, line, msg);
849 wxLogDebug(msg2);
850 #endif
851 }
852
853 #endif // __WXDEBUG__
854