Include wx/timer.h according to precompiled headers of wx/wx.h (with other minor...
[wxWidgets.git] / src / x11 / app.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/x11/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 // for compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #include "wx/app.h"
16
17 #ifndef WX_PRECOMP
18 #include "wx/hash.h"
19 #include "wx/intl.h"
20 #include "wx/log.h"
21 #include "wx/utils.h"
22 #include "wx/frame.h"
23 #include "wx/icon.h"
24 #include "wx/dialog.h"
25 #include "wx/timer.h"
26 #endif
27
28 #include "wx/gdicmn.h"
29 #include "wx/module.h"
30 #include "wx/memory.h"
31 #include "wx/evtloop.h"
32 #include "wx/filename.h"
33
34 #include "wx/univ/theme.h"
35 #include "wx/univ/renderer.h"
36
37 #if wxUSE_THREADS
38 #include "wx/thread.h"
39 #endif
40
41 #include "wx/x11/private.h"
42
43 #include <string.h>
44
45 //------------------------------------------------------------------------
46 // global data
47 //------------------------------------------------------------------------
48
49 extern wxList wxPendingDelete;
50
51 wxWindowHash *wxWidgetHashTable = NULL;
52 wxWindowHash *wxClientWidgetHashTable = NULL;
53
54 static bool g_showIconic = false;
55 static wxSize g_initialSize = wxDefaultSize;
56
57 // This is required for wxFocusEvent::SetWindow(). It will only
58 // work for focus events which we provoke ourselves (by calling
59 // SetFocus()). It will not work for those events, which X11
60 // generates itself.
61 static wxWindow *g_nextFocus = NULL;
62 static wxWindow *g_prevFocus = NULL;
63
64 //------------------------------------------------------------------------
65 // X11 error handling
66 //------------------------------------------------------------------------
67
68 #ifdef __WXDEBUG__
69 typedef int (*XErrorHandlerFunc)(Display *, XErrorEvent *);
70
71 XErrorHandlerFunc gs_pfnXErrorHandler = 0;
72
73 static int wxXErrorHandler(Display *dpy, XErrorEvent *xevent)
74 {
75 // just forward to the default handler for now
76 if (gs_pfnXErrorHandler)
77 return gs_pfnXErrorHandler(dpy, xevent);
78 else
79 return 0;
80 }
81 #endif // __WXDEBUG__
82
83 //------------------------------------------------------------------------
84 // wxApp
85 //------------------------------------------------------------------------
86
87 long wxApp::sm_lastMessageTime = 0;
88 WXDisplay *wxApp::ms_display = NULL;
89
90 IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
91
92 BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
93 EVT_IDLE(wxAppBase::OnIdle)
94 END_EVENT_TABLE()
95
96 bool wxApp::Initialize(int& argC, wxChar **argV)
97 {
98 #if defined(__WXDEBUG__) && !wxUSE_NANOX
99 // install the X error handler
100 gs_pfnXErrorHandler = XSetErrorHandler( wxXErrorHandler );
101 #endif // __WXDEBUG__
102
103 wxString displayName;
104 bool syncDisplay = false;
105
106 int argCOrig = argC;
107 for ( int i = 0; i < argCOrig; i++ )
108 {
109 if (wxStrcmp( argV[i], _T("-display") ) == 0)
110 {
111 if (i < (argC - 1))
112 {
113 argV[i++] = NULL;
114
115 displayName = argV[i];
116
117 argV[i] = NULL;
118 argC -= 2;
119 }
120 }
121 else if (wxStrcmp( argV[i], _T("-geometry") ) == 0)
122 {
123 if (i < (argC - 1))
124 {
125 argV[i++] = NULL;
126
127 int w, h;
128 if (wxSscanf(argV[i], _T("%dx%d"), &w, &h) != 2)
129 {
130 wxLogError( _("Invalid geometry specification '%s'"),
131 wxString(argV[i]).c_str() );
132 }
133 else
134 {
135 g_initialSize = wxSize(w, h);
136 }
137
138 argV[i] = NULL;
139 argC -= 2;
140 }
141 }
142 else if (wxStrcmp( argV[i], _T("-sync") ) == 0)
143 {
144 syncDisplay = true;
145
146 argV[i] = NULL;
147 argC--;
148 }
149 else if (wxStrcmp( argV[i], _T("-iconic") ) == 0)
150 {
151 g_showIconic = true;
152
153 argV[i] = NULL;
154 argC--;
155 }
156 }
157
158 if ( argC != argCOrig )
159 {
160 // remove the argumens we consumed
161 for ( int i = 0; i < argC; i++ )
162 {
163 while ( !argV[i] )
164 {
165 memmove(argV + i, argV + i + 1, argCOrig - i);
166 }
167 }
168 }
169
170 // X11 display stuff
171 Display *xdisplay;
172 if ( displayName.empty() )
173 xdisplay = XOpenDisplay( NULL );
174 else
175 xdisplay = XOpenDisplay( displayName.ToAscii() );
176 if (!xdisplay)
177 {
178 wxLogError( _("wxWidgets could not open display. Exiting.") );
179 return false;
180 }
181
182 if (syncDisplay)
183 XSynchronize(xdisplay, True);
184
185 ms_display = (WXDisplay*) xdisplay;
186
187 XSelectInput( xdisplay, XDefaultRootWindow(xdisplay), PropertyChangeMask);
188
189 // Misc.
190 wxSetDetectableAutoRepeat( true );
191
192 if ( !wxAppBase::Initialize(argC, argV) )
193 {
194 XCloseDisplay(xdisplay);
195
196 return false;
197 }
198
199 #if wxUSE_UNICODE
200 // Glib's type system required by Pango
201 g_type_init();
202 #endif
203
204 #if wxUSE_INTL
205 wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
206 #endif
207
208 wxWidgetHashTable = new wxWindowHash;
209 wxClientWidgetHashTable = new wxWindowHash;
210
211 return true;
212 }
213
214 void wxApp::CleanUp()
215 {
216 delete wxWidgetHashTable;
217 wxWidgetHashTable = NULL;
218 delete wxClientWidgetHashTable;
219 wxClientWidgetHashTable = NULL;
220
221 wxAppBase::CleanUp();
222 }
223
224 wxApp::wxApp()
225 {
226 // TODO: parse the command line
227 argc = 0;
228 argv = NULL;
229
230 m_mainColormap = (WXColormap) NULL;
231 m_topLevelWidget = (WXWindow) NULL;
232 m_maxRequestSize = 0;
233 m_showIconic = false;
234 m_initialSize = wxDefaultSize;
235
236 #if !wxUSE_NANOX
237 m_visualInfo = NULL;
238 #endif
239 }
240
241 wxApp::~wxApp()
242 {
243 #if !wxUSE_NANOX
244 delete m_visualInfo;
245 #endif
246 }
247
248 #if !wxUSE_NANOX
249
250 //-----------------------------------------------------------------------
251 // X11 predicate function for exposure compression
252 //-----------------------------------------------------------------------
253
254 struct wxExposeInfo
255 {
256 Window window;
257 Bool found_non_matching;
258 };
259
260 extern "C"
261 Bool wxX11ExposePredicate (Display *display, XEvent *xevent, XPointer arg)
262 {
263 wxExposeInfo *info = (wxExposeInfo*) arg;
264
265 if (info->found_non_matching)
266 return FALSE;
267
268 if (xevent->xany.type != Expose)
269 {
270 info->found_non_matching = true;
271 return FALSE;
272 }
273
274 if (xevent->xexpose.window != info->window)
275 {
276 info->found_non_matching = true;
277 return FALSE;
278 }
279
280 return TRUE;
281 }
282
283 #endif // wxUSE_NANOX
284
285 //-----------------------------------------------------------------------
286 // Processes an X event, returning true if the event was processed.
287 //-----------------------------------------------------------------------
288
289 bool wxApp::ProcessXEvent(WXEvent* _event)
290 {
291 XEvent* event = (XEvent*) _event;
292
293 wxWindow* win = NULL;
294 Window window = XEventGetWindow(event);
295 #if 0
296 Window actualWindow = window;
297 #endif
298
299 // Find the first wxWindow that corresponds to this event window
300 // Because we're receiving events after a window
301 // has been destroyed, assume a 1:1 match between
302 // Window and wxWindow, so if it's not in the table,
303 // it must have been destroyed.
304
305 win = wxGetWindowFromTable(window);
306 if (!win)
307 {
308 #if wxUSE_TWO_WINDOWS
309 win = wxGetClientWindowFromTable(window);
310 if (!win)
311 #endif
312 return false;
313 }
314
315 #ifdef __WXDEBUG__
316 wxString windowClass = win->GetClassInfo()->GetClassName();
317 #endif
318
319 switch (event->type)
320 {
321 case Expose:
322 {
323 #if wxUSE_TWO_WINDOWS && !wxUSE_NANOX
324 if (event->xexpose.window != (Window)win->GetClientAreaWindow())
325 {
326 XEvent tmp_event;
327 wxExposeInfo info;
328 info.window = event->xexpose.window;
329 info.found_non_matching = false;
330 while (XCheckIfEvent( wxGlobalDisplay(), &tmp_event, wxX11ExposePredicate, (XPointer) &info ))
331 {
332 // Don't worry about optimizing redrawing the border etc.
333 }
334 win->NeedUpdateNcAreaInIdle();
335 }
336 else
337 #endif
338 {
339 win->GetUpdateRegion().Union( XExposeEventGetX(event), XExposeEventGetY(event),
340 XExposeEventGetWidth(event), XExposeEventGetHeight(event));
341 win->GetClearRegion().Union( XExposeEventGetX(event), XExposeEventGetY(event),
342 XExposeEventGetWidth(event), XExposeEventGetHeight(event));
343
344 #if !wxUSE_NANOX
345 XEvent tmp_event;
346 wxExposeInfo info;
347 info.window = event->xexpose.window;
348 info.found_non_matching = false;
349 while (XCheckIfEvent( wxGlobalDisplay(), &tmp_event, wxX11ExposePredicate, (XPointer) &info ))
350 {
351 win->GetUpdateRegion().Union( tmp_event.xexpose.x, tmp_event.xexpose.y,
352 tmp_event.xexpose.width, tmp_event.xexpose.height );
353
354 win->GetClearRegion().Union( tmp_event.xexpose.x, tmp_event.xexpose.y,
355 tmp_event.xexpose.width, tmp_event.xexpose.height );
356 }
357 #endif
358
359 // This simplifies the expose and clear areas to simple
360 // rectangles.
361 win->GetUpdateRegion() = win->GetUpdateRegion().GetBox();
362 win->GetClearRegion() = win->GetClearRegion().GetBox();
363
364 // If we only have one X11 window, always indicate
365 // that borders might have to be redrawn.
366 if (win->GetMainWindow() == win->GetClientAreaWindow())
367 win->NeedUpdateNcAreaInIdle();
368
369 // Only erase background, paint in idle time.
370 win->SendEraseEvents();
371
372 // EXPERIMENT
373 //win->Update();
374 }
375
376 return true;
377 }
378
379 #if !wxUSE_NANOX
380 case GraphicsExpose:
381 {
382 wxLogTrace( _T("expose"), _T("GraphicsExpose from %s"), win->GetName().c_str());
383
384 win->GetUpdateRegion().Union( event->xgraphicsexpose.x, event->xgraphicsexpose.y,
385 event->xgraphicsexpose.width, event->xgraphicsexpose.height);
386
387 win->GetClearRegion().Union( event->xgraphicsexpose.x, event->xgraphicsexpose.y,
388 event->xgraphicsexpose.width, event->xgraphicsexpose.height);
389
390 if (event->xgraphicsexpose.count == 0)
391 {
392 // Only erase background, paint in idle time.
393 win->SendEraseEvents();
394 // win->Update();
395 }
396
397 return true;
398 }
399 #endif
400
401 case KeyPress:
402 {
403 if (!win->IsEnabled())
404 return false;
405
406 wxKeyEvent keyEvent(wxEVT_KEY_DOWN);
407 wxTranslateKeyEvent(keyEvent, win, window, event);
408
409 // wxLogDebug( "OnKey from %s", win->GetName().c_str() );
410
411 // We didn't process wxEVT_KEY_DOWN, so send wxEVT_CHAR
412 if (win->GetEventHandler()->ProcessEvent( keyEvent ))
413 return true;
414
415 keyEvent.SetEventType(wxEVT_CHAR);
416 // Do the translation again, retaining the ASCII
417 // code.
418 wxTranslateKeyEvent(keyEvent, win, window, event, true);
419 if (win->GetEventHandler()->ProcessEvent( keyEvent ))
420 return true;
421
422 if ( (keyEvent.m_keyCode == WXK_TAB) &&
423 win->GetParent() && (win->GetParent()->HasFlag( wxTAB_TRAVERSAL)) )
424 {
425 wxNavigationKeyEvent new_event;
426 new_event.SetEventObject( win->GetParent() );
427 /* GDK reports GDK_ISO_Left_Tab for SHIFT-TAB */
428 new_event.SetDirection( (keyEvent.m_keyCode == WXK_TAB) );
429 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
430 new_event.SetWindowChange( keyEvent.ControlDown() );
431 new_event.SetCurrentFocus( win );
432 return win->GetParent()->GetEventHandler()->ProcessEvent( new_event );
433 }
434
435 return false;
436 }
437 case KeyRelease:
438 {
439 if (!win->IsEnabled())
440 return false;
441
442 wxKeyEvent keyEvent(wxEVT_KEY_UP);
443 wxTranslateKeyEvent(keyEvent, win, window, event);
444
445 return win->GetEventHandler()->ProcessEvent( keyEvent );
446 }
447 case ConfigureNotify:
448 {
449 #if wxUSE_NANOX
450 if (event->update.utype == GR_UPDATE_SIZE)
451 #endif
452 {
453 wxTopLevelWindow *tlw = wxDynamicCast(win, wxTopLevelWindow);
454 if ( tlw )
455 {
456 tlw->SetConfigureGeometry( XConfigureEventGetX(event), XConfigureEventGetY(event),
457 XConfigureEventGetWidth(event), XConfigureEventGetHeight(event) );
458 }
459
460 if ( tlw && tlw->IsShown() )
461 {
462 tlw->SetNeedResizeInIdle();
463 }
464 else
465 {
466 wxSizeEvent sizeEvent( wxSize(XConfigureEventGetWidth(event), XConfigureEventGetHeight(event)), win->GetId() );
467 sizeEvent.SetEventObject( win );
468
469 return win->GetEventHandler()->ProcessEvent( sizeEvent );
470 }
471 }
472 return false;
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 #ifdef HAVE_PANGO_XFT
698 #include <pango/pangoxft.h>
699 #endif
700
701 PangoContext* wxApp::GetPangoContext()
702 {
703 static PangoContext *ret = NULL;
704 if (ret)
705 return ret;
706
707 Display *xdisplay = (Display*) wxApp::GetDisplay();
708
709 #ifdef HAVE_PANGO_XFT
710 int xscreen = DefaultScreen(xdisplay);
711 static int use_xft = -1;
712 if (use_xft == -1)
713 {
714 wxString val = wxGetenv( L"GDK_USE_XFT" );
715 use_xft = (val == L"1");
716 }
717
718 if (use_xft)
719 ret = pango_xft_get_context( xdisplay, xscreen );
720 else
721 #endif
722 ret = pango_x_get_context( xdisplay );
723
724 if (!PANGO_IS_CONTEXT(ret))
725 wxLogError( wxT("No pango context.") );
726
727 return ret;
728 }
729 #endif
730
731 WXColormap wxApp::GetMainColormap(WXDisplay* display)
732 {
733 if (!display) /* Must be called first with non-NULL display */
734 return m_mainColormap;
735
736 int defaultScreen = DefaultScreen((Display*) display);
737 Screen* screen = XScreenOfDisplay((Display*) display, defaultScreen);
738
739 Colormap c = DefaultColormapOfScreen(screen);
740
741 if (!m_mainColormap)
742 m_mainColormap = (WXColormap) c;
743
744 return (WXColormap) c;
745 }
746
747 Window wxGetWindowParent(Window window)
748 {
749 wxASSERT_MSG( window, _T("invalid window") );
750
751 return (Window) 0;
752
753 #ifndef __VMS
754 // VMS chokes on unreacheable code
755 Window parent, root = 0;
756 #if wxUSE_NANOX
757 int noChildren = 0;
758 #else
759 unsigned int noChildren = 0;
760 #endif
761 Window* children = NULL;
762
763 // #define XQueryTree(d,w,r,p,c,nc) GrQueryTree(w,p,c,nc)
764 int res = 1;
765 #if !wxUSE_NANOX
766 res =
767 #endif
768 XQueryTree((Display*) wxGetDisplay(), window, & root, & parent,
769 & children, & noChildren);
770 if (children)
771 XFree(children);
772 if (res)
773 return parent;
774 else
775 return (Window) 0;
776 #endif
777 }
778
779 void wxApp::Exit()
780 {
781 wxApp::CleanUp();
782
783 wxAppConsole::Exit();
784 }
785
786 // Yield to other processes
787
788 bool wxApp::Yield(bool onlyIfNeeded)
789 {
790 // Sometimes only 2 yields seem
791 // to do the trick, e.g. in the
792 // progress dialog
793 int i;
794 for (i = 0; i < 2; i++)
795 {
796 static bool s_inYield = false;
797
798 if ( s_inYield )
799 {
800 if ( !onlyIfNeeded )
801 {
802 wxFAIL_MSG( wxT("wxYield called recursively" ) );
803 }
804
805 return false;
806 }
807
808 s_inYield = true;
809
810 // Make sure we have an event loop object,
811 // or Pending/Dispatch will fail
812 wxEventLoop* eventLoop = wxEventLoop::GetActive();
813 wxEventLoop* newEventLoop = NULL;
814 if (!eventLoop)
815 {
816 newEventLoop = new wxEventLoop;
817 wxEventLoop::SetActive(newEventLoop);
818 }
819
820 // Call dispatch at least once so that sockets
821 // can be tested
822 wxTheApp->Dispatch();
823
824 while (wxTheApp && wxTheApp->Pending())
825 wxTheApp->Dispatch();
826
827 #if wxUSE_TIMER
828 wxTimer::NotifyTimers();
829 #endif
830 ProcessIdle();
831
832 if (newEventLoop)
833 {
834 wxEventLoop::SetActive(NULL);
835 delete newEventLoop;
836 }
837
838 s_inYield = false;
839 }
840
841 return true;
842 }
843
844 #ifdef __WXDEBUG__
845
846 void wxApp::OnAssert(const wxChar *file, int line, const wxChar* cond, const wxChar *msg)
847 {
848 // While the GUI isn't working that well, just print out the
849 // message.
850 #if 1
851 wxAppBase::OnAssert(file, line, cond, msg);
852 #else
853 wxString msg2;
854 msg2.Printf("At file %s:%d: %s", file, line, msg);
855 wxLogDebug(msg2);
856 #endif
857 }
858
859 #endif // __WXDEBUG__