]> git.saurik.com Git - wxWidgets.git/blob - src/x11/app.cpp
[ 1502010 ] Cast to wrong type.
[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 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 //-----------------------------------------------------------------------
249 // X11 predicate function for exposure compression
250 //-----------------------------------------------------------------------
251
252 struct wxExposeInfo
253 {
254 Window window;
255 Bool found_non_matching;
256 };
257
258 extern "C"
259 Bool wxX11ExposePredicate (Display *display, XEvent *xevent, XPointer arg)
260 {
261 wxExposeInfo *info = (wxExposeInfo*) arg;
262
263 if (info->found_non_matching)
264 return FALSE;
265
266 if (xevent->xany.type != Expose)
267 {
268 info->found_non_matching = true;
269 return FALSE;
270 }
271
272 if (xevent->xexpose.window != info->window)
273 {
274 info->found_non_matching = true;
275 return FALSE;
276 }
277
278 return TRUE;
279 }
280
281 #endif // wxUSE_NANOX
282
283 //-----------------------------------------------------------------------
284 // Processes an X event, returning true if the event was processed.
285 //-----------------------------------------------------------------------
286
287 bool wxApp::ProcessXEvent(WXEvent* _event)
288 {
289 XEvent* event = (XEvent*) _event;
290
291 wxWindow* win = NULL;
292 Window window = XEventGetWindow(event);
293 #if 0
294 Window actualWindow = window;
295 #endif
296
297 // Find the first wxWindow that corresponds to this event window
298 // Because we're receiving events after a window
299 // has been destroyed, assume a 1:1 match between
300 // Window and wxWindow, so if it's not in the table,
301 // it must have been destroyed.
302
303 win = wxGetWindowFromTable(window);
304 if (!win)
305 {
306 #if wxUSE_TWO_WINDOWS
307 win = wxGetClientWindowFromTable(window);
308 if (!win)
309 #endif
310 return false;
311 }
312
313 #ifdef __WXDEBUG__
314 wxString windowClass = win->GetClassInfo()->GetClassName();
315 #endif
316
317 switch (event->type)
318 {
319 case Expose:
320 {
321 #if wxUSE_TWO_WINDOWS && !wxUSE_NANOX
322 if (event->xexpose.window != (Window)win->GetClientAreaWindow())
323 {
324 XEvent tmp_event;
325 wxExposeInfo info;
326 info.window = event->xexpose.window;
327 info.found_non_matching = false;
328 while (XCheckIfEvent( wxGlobalDisplay(), &tmp_event, wxX11ExposePredicate, (XPointer) &info ))
329 {
330 // Don't worry about optimizing redrawing the border etc.
331 }
332 win->NeedUpdateNcAreaInIdle();
333 }
334 else
335 #endif
336 {
337 win->GetUpdateRegion().Union( XExposeEventGetX(event), XExposeEventGetY(event),
338 XExposeEventGetWidth(event), XExposeEventGetHeight(event));
339 win->GetClearRegion().Union( XExposeEventGetX(event), XExposeEventGetY(event),
340 XExposeEventGetWidth(event), XExposeEventGetHeight(event));
341
342 #if !wxUSE_NANOX
343 XEvent tmp_event;
344 wxExposeInfo info;
345 info.window = event->xexpose.window;
346 info.found_non_matching = false;
347 while (XCheckIfEvent( wxGlobalDisplay(), &tmp_event, wxX11ExposePredicate, (XPointer) &info ))
348 {
349 win->GetUpdateRegion().Union( tmp_event.xexpose.x, tmp_event.xexpose.y,
350 tmp_event.xexpose.width, tmp_event.xexpose.height );
351
352 win->GetClearRegion().Union( tmp_event.xexpose.x, tmp_event.xexpose.y,
353 tmp_event.xexpose.width, tmp_event.xexpose.height );
354 }
355 #endif
356
357 // This simplifies the expose and clear areas to simple
358 // rectangles.
359 win->GetUpdateRegion() = win->GetUpdateRegion().GetBox();
360 win->GetClearRegion() = win->GetClearRegion().GetBox();
361
362 // If we only have one X11 window, always indicate
363 // that borders might have to be redrawn.
364 if (win->GetMainWindow() == win->GetClientAreaWindow())
365 win->NeedUpdateNcAreaInIdle();
366
367 // Only erase background, paint in idle time.
368 win->SendEraseEvents();
369
370 // EXPERIMENT
371 //win->Update();
372 }
373
374 return true;
375 }
376
377 #if !wxUSE_NANOX
378 case GraphicsExpose:
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 wxTopLevelWindow *tlw = wxDynamicCast(win, wxTopLevelWindow);
452 if ( tlw )
453 {
454 tlw->SetConfigureGeometry( XConfigureEventGetX(event), XConfigureEventGetY(event),
455 XConfigureEventGetWidth(event), XConfigureEventGetHeight(event) );
456 }
457
458 if ( tlw && tlw->IsShown() )
459 {
460 tlw->SetNeedResizeInIdle();
461 }
462 else
463 {
464 wxSizeEvent sizeEvent( wxSize(XConfigureEventGetWidth(event), XConfigureEventGetHeight(event)), win->GetId() );
465 sizeEvent.SetEventObject( win );
466
467 return win->GetEventHandler()->ProcessEvent( sizeEvent );
468 }
469 }
470 return false;
471 }
472 #if !wxUSE_NANOX
473 case PropertyNotify:
474 {
475 //wxLogDebug("PropertyNotify: %s", windowClass.c_str());
476 return HandlePropertyChange(_event);
477 }
478 case ClientMessage:
479 {
480 if (!win->IsEnabled())
481 return false;
482
483 Atom wm_delete_window = XInternAtom(wxGlobalDisplay(), "WM_DELETE_WINDOW", True);
484 Atom wm_protocols = XInternAtom(wxGlobalDisplay(), "WM_PROTOCOLS", True);
485
486 if (event->xclient.message_type == wm_protocols)
487 {
488 if ((Atom) (event->xclient.data.l[0]) == wm_delete_window)
489 {
490 win->Close(false);
491 return true;
492 }
493 }
494 return false;
495 }
496 #if 0
497 case DestroyNotify:
498 {
499 printf( "destroy from %s\n", win->GetName().c_str() );
500 break;
501 }
502 case CreateNotify:
503 {
504 printf( "create from %s\n", win->GetName().c_str() );
505 break;
506 }
507 case MapRequest:
508 {
509 printf( "map request from %s\n", win->GetName().c_str() );
510 break;
511 }
512 case ResizeRequest:
513 {
514 printf( "resize request from %s\n", win->GetName().c_str() );
515
516 Display *disp = (Display*) wxGetDisplay();
517 XEvent report;
518
519 // to avoid flicker
520 report = * event;
521 while( XCheckTypedWindowEvent (disp, actualWindow, ResizeRequest, &report));
522
523 wxSize sz = win->GetSize();
524 wxSizeEvent sizeEvent(sz, win->GetId());
525 sizeEvent.SetEventObject(win);
526
527 return win->GetEventHandler()->ProcessEvent( sizeEvent );
528 }
529 #endif
530 #endif
531 #if wxUSE_NANOX
532 case GR_EVENT_TYPE_CLOSE_REQ:
533 {
534 if (win)
535 {
536 win->Close(false);
537 return true;
538 }
539 return false;
540 break;
541 }
542 #endif
543 case EnterNotify:
544 case LeaveNotify:
545 case ButtonPress:
546 case ButtonRelease:
547 case MotionNotify:
548 {
549 if (!win->IsEnabled())
550 return false;
551
552 // Here we check if the top level window is
553 // disabled, which is one aspect of modality.
554 wxWindow *tlw = win;
555 while (tlw && !tlw->IsTopLevel())
556 tlw = tlw->GetParent();
557 if (tlw && !tlw->IsEnabled())
558 return false;
559
560 if (event->type == ButtonPress)
561 {
562 if ((win != wxWindow::FindFocus()) && win->AcceptsFocus())
563 {
564 // This might actually be done in wxWindow::SetFocus()
565 // and not here. TODO.
566 g_prevFocus = wxWindow::FindFocus();
567 g_nextFocus = win;
568
569 wxLogTrace( _T("focus"), _T("About to call SetFocus on %s of type %s due to button press"), win->GetName().c_str(), win->GetClassInfo()->GetClassName() );
570
571 // Record the fact that this window is
572 // getting the focus, because we'll need to
573 // check if its parent is getting a bogus
574 // focus and duly ignore it.
575 // TODO: may need to have this code in SetFocus, too.
576 extern wxWindow* g_GettingFocus;
577 g_GettingFocus = win;
578 win->SetFocus();
579 }
580 }
581
582 #if !wxUSE_NANOX
583 if (event->type == LeaveNotify || event->type == EnterNotify)
584 {
585 // Throw out NotifyGrab and NotifyUngrab
586 if (event->xcrossing.mode != NotifyNormal)
587 return false;
588 }
589 #endif
590 wxMouseEvent wxevent;
591 wxTranslateMouseEvent(wxevent, win, window, event);
592 return win->GetEventHandler()->ProcessEvent( wxevent );
593 }
594 case FocusIn:
595 #if !wxUSE_NANOX
596 if ((event->xfocus.detail != NotifyPointer) &&
597 (event->xfocus.mode == NotifyNormal))
598 #endif
599 {
600 wxLogTrace( _T("focus"), _T("FocusIn from %s of type %s"), win->GetName().c_str(), win->GetClassInfo()->GetClassName() );
601
602 extern wxWindow* g_GettingFocus;
603 if (g_GettingFocus && g_GettingFocus->GetParent() == win)
604 {
605 // Ignore this, this can be a spurious FocusIn
606 // caused by a child having its focus set.
607 g_GettingFocus = NULL;
608 wxLogTrace( _T("focus"), _T("FocusIn from %s of type %s being deliberately ignored"), win->GetName().c_str(), win->GetClassInfo()->GetClassName() );
609 return true;
610 }
611 else
612 {
613 wxFocusEvent focusEvent(wxEVT_SET_FOCUS, win->GetId());
614 focusEvent.SetEventObject(win);
615 focusEvent.SetWindow( g_prevFocus );
616 g_prevFocus = NULL;
617
618 return win->GetEventHandler()->ProcessEvent(focusEvent);
619 }
620 }
621 return false;
622
623 case FocusOut:
624 #if !wxUSE_NANOX
625 if ((event->xfocus.detail != NotifyPointer) &&
626 (event->xfocus.mode == NotifyNormal))
627 #endif
628 {
629 wxLogTrace( _T("focus"), _T("FocusOut from %s of type %s"), win->GetName().c_str(), win->GetClassInfo()->GetClassName() );
630
631 wxFocusEvent focusEvent(wxEVT_KILL_FOCUS, win->GetId());
632 focusEvent.SetEventObject(win);
633 focusEvent.SetWindow( g_nextFocus );
634 g_nextFocus = NULL;
635 return win->GetEventHandler()->ProcessEvent(focusEvent);
636 }
637 return false;
638
639 #ifdef __WXDEBUG__
640 default:
641 //wxString eventName = wxGetXEventName(XEvent& event);
642 //wxLogDebug(wxT("Event %s not handled"), eventName.c_str());
643 break;
644 #endif // __WXDEBUG__
645 }
646
647 return false;
648 }
649
650 // This should be redefined in a derived class for
651 // handling property change events for XAtom IPC.
652 bool wxApp::HandlePropertyChange(WXEvent *event)
653 {
654 // by default do nothing special
655 // TODO: what to do for X11
656 // XtDispatchEvent((XEvent*) event);
657 return false;
658 }
659
660 void wxApp::WakeUpIdle()
661 {
662 // TODO: use wxMotif implementation?
663
664 // Wake up the idle handler processor, even if it is in another thread...
665 }
666
667
668 // Create display, and other initialization
669 bool wxApp::OnInitGui()
670 {
671 // Eventually this line will be removed, but for
672 // now we don't want to try popping up a dialog
673 // for error messages.
674 delete wxLog::SetActiveTarget(new wxLogStderr);
675
676 if (!wxAppBase::OnInitGui())
677 return false;
678
679 GetMainColormap( wxApp::GetDisplay() );
680
681 m_maxRequestSize = XMaxRequestSize( (Display*) wxApp::GetDisplay() );
682
683 #if !wxUSE_NANOX
684 m_visualInfo = new wxXVisualInfo;
685 wxFillXVisualInfo( m_visualInfo, (Display*) wxApp::GetDisplay() );
686 #endif
687
688 return true;
689 }
690
691 #if wxUSE_UNICODE
692
693 #include <pango/pango.h>
694 #include <pango/pangox.h>
695 #ifdef HAVE_PANGO_XFT
696 #include <pango/pangoxft.h>
697 #endif
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 #ifdef HAVE_PANGO_XFT
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 #ifndef __VMS
752 // VMS chokes on unreacheable code
753 Window parent, root = 0;
754 #if wxUSE_NANOX
755 int noChildren = 0;
756 #else
757 unsigned int noChildren = 0;
758 #endif
759 Window* children = NULL;
760
761 // #define XQueryTree(d,w,r,p,c,nc) GrQueryTree(w,p,c,nc)
762 int res = 1;
763 #if !wxUSE_NANOX
764 res =
765 #endif
766 XQueryTree((Display*) wxGetDisplay(), window, & root, & parent,
767 & children, & noChildren);
768 if (children)
769 XFree(children);
770 if (res)
771 return parent;
772 else
773 return (Window) 0;
774 #endif
775 }
776
777 void wxApp::Exit()
778 {
779 wxApp::CleanUp();
780
781 wxAppConsole::Exit();
782 }
783
784 // Yield to other processes
785
786 bool wxApp::Yield(bool onlyIfNeeded)
787 {
788 // Sometimes only 2 yields seem
789 // to do the trick, e.g. in the
790 // progress dialog
791 int i;
792 for (i = 0; i < 2; i++)
793 {
794 static bool s_inYield = false;
795
796 if ( s_inYield )
797 {
798 if ( !onlyIfNeeded )
799 {
800 wxFAIL_MSG( wxT("wxYield called recursively" ) );
801 }
802
803 return false;
804 }
805
806 s_inYield = true;
807
808 // Make sure we have an event loop object,
809 // or Pending/Dispatch will fail
810 wxEventLoop* eventLoop = wxEventLoop::GetActive();
811 wxEventLoop* newEventLoop = NULL;
812 if (!eventLoop)
813 {
814 newEventLoop = new wxEventLoop;
815 wxEventLoop::SetActive(newEventLoop);
816 }
817
818 // Call dispatch at least once so that sockets
819 // can be tested
820 wxTheApp->Dispatch();
821
822 while (wxTheApp && wxTheApp->Pending())
823 wxTheApp->Dispatch();
824
825 #if wxUSE_TIMER
826 wxTimer::NotifyTimers();
827 #endif
828 ProcessIdle();
829
830 if (newEventLoop)
831 {
832 wxEventLoop::SetActive(NULL);
833 delete newEventLoop;
834 }
835
836 s_inYield = false;
837 }
838
839 return true;
840 }
841
842 #ifdef __WXDEBUG__
843
844 void wxApp::OnAssert(const wxChar *file, int line, const wxChar* cond, const wxChar *msg)
845 {
846 // While the GUI isn't working that well, just print out the
847 // message.
848 #if 1
849 wxAppBase::OnAssert(file, line, cond, msg);
850 #else
851 wxString msg2;
852 msg2.Printf("At file %s:%d: %s", file, line, msg);
853 wxLogDebug(msg2);
854 #endif
855 }
856
857 #endif // __WXDEBUG__