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