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