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