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