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