]> git.saurik.com Git - wxWidgets.git/blob - src/x11/app.cpp
fixed VC++ warning in release build
[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 #ifdef __GNUG__
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(wxApp::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 ( !wxAppBase::Initialize(argc, argv) )
177 {
178 XCloseDisplay(xdisplay);
179
180 return false;
181 }
182
183 if (syncDisplay)
184 XSynchronize(xdisplay, True);
185
186 ms_display = (WXDisplay*) xdisplay;
187
188 XSelectInput( xdisplay, XDefaultRootWindow(xdisplay), PropertyChangeMask);
189
190 // Misc.
191 wxSetDetectableAutoRepeat( TRUE );
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 // Returns TRUE if more time is needed.
676 // Note that this duplicates wxEventLoopImpl::SendIdleEvent
677 // but ProcessIdle may be needed by apps, so is kept.
678 bool wxApp::ProcessIdle()
679 {
680 wxIdleEvent event;
681 event.SetEventObject(this);
682 ProcessEvent(event);
683
684 return event.MoreRequested();
685 }
686
687 void wxApp::ExitMainLoop()
688 {
689 if (m_mainLoop)
690 m_mainLoop->Exit(0);
691 }
692
693 // Is a message/event pending?
694 bool wxApp::Pending()
695 {
696 return wxEventLoop::GetActive()->Pending();
697 }
698
699 // Dispatch a message.
700 void wxApp::Dispatch()
701 {
702 wxEventLoop::GetActive()->Dispatch();
703 }
704
705 // This should be redefined in a derived class for
706 // handling property change events for XAtom IPC.
707 bool wxApp::HandlePropertyChange(WXEvent *event)
708 {
709 // by default do nothing special
710 // TODO: what to do for X11
711 // XtDispatchEvent((XEvent*) event);
712 return FALSE;
713 }
714
715 void wxApp::OnIdle(wxIdleEvent& event)
716 {
717 static bool s_inOnIdle = FALSE;
718
719 // Avoid recursion (via ProcessEvent default case)
720 if (s_inOnIdle)
721 return;
722
723 s_inOnIdle = TRUE;
724
725 // Resend in the main thread events which have been prepared in other
726 // threads
727 ProcessPendingEvents();
728
729 // 'Garbage' collection of windows deleted with Close()
730 DeletePendingObjects();
731
732 // Send OnIdle events to all windows
733 bool needMore = SendIdleEvents();
734
735 if (needMore)
736 event.RequestMore(TRUE);
737
738 s_inOnIdle = FALSE;
739 }
740
741 void wxApp::WakeUpIdle()
742 {
743 // TODO: use wxMotif implementation?
744
745 // Wake up the idle handler processor, even if it is in another thread...
746 }
747
748
749 // Send idle event to all top-level windows
750 bool wxApp::SendIdleEvents()
751 {
752 bool needMore = FALSE;
753
754 wxWindowList::Node* node = wxTopLevelWindows.GetFirst();
755 while (node)
756 {
757 wxWindow* win = node->GetData();
758 if (SendIdleEvents(win))
759 needMore = TRUE;
760 node = node->GetNext();
761 }
762
763 return needMore;
764 }
765
766 // Send idle event to window and all subwindows
767 bool wxApp::SendIdleEvents(wxWindow* win)
768 {
769 bool needMore = FALSE;
770
771 wxIdleEvent event;
772 event.SetEventObject(win);
773
774 win->GetEventHandler()->ProcessEvent(event);
775
776 if (event.MoreRequested())
777 needMore = TRUE;
778
779 wxWindowListNode* node = win->GetChildren().GetFirst();
780 while (node)
781 {
782 wxWindow* win = (wxWindow*) node->GetData();
783 if (SendIdleEvents(win))
784 needMore = TRUE;
785
786 node = node->GetNext();
787 }
788
789 win->OnInternalIdle();
790
791 return needMore;
792 }
793
794 // Create display, and other initialization
795 bool wxApp::OnInitGui()
796 {
797 // Eventually this line will be removed, but for
798 // now we don't want to try popping up a dialog
799 // for error messages.
800 delete wxLog::SetActiveTarget(new wxLogStderr);
801
802 if (!wxAppBase::OnInitGui())
803 return FALSE;
804
805 GetMainColormap( wxApp::GetDisplay() );
806
807 m_maxRequestSize = XMaxRequestSize( (Display*) wxApp::GetDisplay() );
808
809 #if !wxUSE_NANOX
810 m_visualInfo = new wxXVisualInfo;
811 wxFillXVisualInfo( m_visualInfo, (Display*) wxApp::GetDisplay() );
812 #endif
813
814 return TRUE;
815 }
816
817 #if wxUSE_UNICODE
818
819 #include <pango/pango.h>
820 #include <pango/pangox.h>
821 #include <pango/pangoxft.h>
822
823 PangoContext* wxApp::GetPangoContext()
824 {
825 static PangoContext *ret = NULL;
826 if (ret)
827 return ret;
828
829 Display *xdisplay = (Display*) wxApp::GetDisplay();
830
831 #if 1
832 int xscreen = DefaultScreen(xdisplay);
833 static int use_xft = -1;
834 if (use_xft == -1)
835 {
836 wxString val = wxGetenv( L"GDK_USE_XFT" );
837 use_xft = (val == L"1");
838 }
839
840 if (use_xft)
841 ret = pango_xft_get_context( xdisplay, xscreen );
842 else
843 #endif
844 ret = pango_x_get_context( xdisplay );
845
846 if (!PANGO_IS_CONTEXT(ret))
847 wxLogError( wxT("No pango context.") );
848
849 return ret;
850 }
851 #endif
852
853 WXColormap wxApp::GetMainColormap(WXDisplay* display)
854 {
855 if (!display) /* Must be called first with non-NULL display */
856 return m_mainColormap;
857
858 int defaultScreen = DefaultScreen((Display*) display);
859 Screen* screen = XScreenOfDisplay((Display*) display, defaultScreen);
860
861 Colormap c = DefaultColormapOfScreen(screen);
862
863 if (!m_mainColormap)
864 m_mainColormap = (WXColormap) c;
865
866 return (WXColormap) c;
867 }
868
869 Window wxGetWindowParent(Window window)
870 {
871 wxASSERT_MSG( window, "invalid window" );
872
873 return (Window) 0;
874
875 Window parent, root = 0;
876 #if wxUSE_NANOX
877 int noChildren = 0;
878 #else
879 unsigned int noChildren = 0;
880 #endif
881 Window* children = NULL;
882
883 // #define XQueryTree(d,w,r,p,c,nc) GrQueryTree(w,p,c,nc)
884 int res = 1;
885 #if !wxUSE_NANOX
886 res =
887 #endif
888 XQueryTree((Display*) wxGetDisplay(), window, & root, & parent,
889 & children, & noChildren);
890 if (children)
891 XFree(children);
892 if (res)
893 return parent;
894 else
895 return (Window) 0;
896 }
897
898 void wxApp::Exit()
899 {
900 wxApp::CleanUp();
901
902 wxAppConsole::Exit();
903 }
904
905 // Yield to other processes
906
907 bool wxApp::Yield(bool onlyIfNeeded)
908 {
909 // Sometimes only 2 yields seem
910 // to do the trick, e.g. in the
911 // progress dialog
912 int i;
913 for (i = 0; i < 2; i++)
914 {
915 bool s_inYield = FALSE;
916
917 if ( s_inYield )
918 {
919 if ( !onlyIfNeeded )
920 {
921 wxFAIL_MSG( wxT("wxYield called recursively" ) );
922 }
923
924 return FALSE;
925 }
926
927 s_inYield = TRUE;
928
929 // Make sure we have an event loop object,
930 // or Pending/Dispatch will fail
931 wxEventLoop* eventLoop = wxEventLoop::GetActive();
932 wxEventLoop* newEventLoop = NULL;
933 if (!eventLoop)
934 {
935 newEventLoop = new wxEventLoop;
936 wxEventLoop::SetActive(newEventLoop);
937 }
938
939 // Call dispatch at least once so that sockets
940 // can be tested
941 wxTheApp->Dispatch();
942
943 while (wxTheApp && wxTheApp->Pending())
944 wxTheApp->Dispatch();
945
946 #if wxUSE_TIMER
947 wxTimer::NotifyTimers();
948 #endif
949 ProcessIdle();
950
951 if (newEventLoop)
952 {
953 wxEventLoop::SetActive(NULL);
954 delete newEventLoop;
955 }
956
957 s_inYield = FALSE;
958 }
959
960 return TRUE;
961 }
962
963 #ifdef __WXDEBUG__
964
965 void wxApp::OnAssert(const wxChar *file, int line, const wxChar* cond, const wxChar *msg)
966 {
967 // While the GUI isn't working that well, just print out the
968 // message.
969 #if 1
970 wxAppBase::OnAssert(file, line, cond, msg);
971 #else
972 wxString msg2;
973 msg2.Printf("At file %s:%d: %s", file, line, msg);
974 wxLogDebug(msg2);
975 #endif
976 }
977
978 #endif // __WXDEBUG__
979