]> git.saurik.com Git - wxWidgets.git/blob - src/x11/app.cpp
Added expose event compression.
[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
29 #include "wx/univ/theme.h"
30 #include "wx/univ/renderer.h"
31
32 #if wxUSE_THREADS
33 #include "wx/thread.h"
34 #endif
35
36 #if wxUSE_WX_RESOURCES
37 #include "wx/resource.h"
38 #endif
39
40 #include "wx/x11/private.h"
41
42 #include <string.h>
43
44 //------------------------------------------------------------------------
45 // global data
46 //------------------------------------------------------------------------
47
48 extern wxList wxPendingDelete;
49
50 wxHashTable *wxWidgetHashTable = NULL;
51
52 wxApp *wxTheApp = NULL;
53
54 // This is set within wxEntryStart -- too early on
55 // to put these in wxTheApp
56 static int g_newArgc = 0;
57 static wxChar** g_newArgv = NULL;
58 static bool g_showIconic = FALSE;
59 static wxSize g_initialSize = wxDefaultSize;
60
61 // This is required for wxFocusEvent::SetWindow(). It will only
62 // work for focus events which we provoke ourselves (by calling
63 // SetFocus()). It will not work for those events, which X11
64 // generates itself.
65 static wxWindow *g_nextFocus = NULL;
66 static wxWindow *g_prevFocus = NULL;
67
68 //------------------------------------------------------------------------
69 // X11 error handling
70 //------------------------------------------------------------------------
71
72 #ifdef __WXDEBUG__
73 typedef int (*XErrorHandlerFunc)(Display *, XErrorEvent *);
74
75 XErrorHandlerFunc gs_pfnXErrorHandler = 0;
76
77 static int wxXErrorHandler(Display *dpy, XErrorEvent *xevent)
78 {
79 // just forward to the default handler for now
80 if (gs_pfnXErrorHandler)
81 return gs_pfnXErrorHandler(dpy, xevent);
82 else
83 return 0;
84 }
85 #endif // __WXDEBUG__
86
87 //------------------------------------------------------------------------
88 // wxApp
89 //------------------------------------------------------------------------
90
91 long wxApp::sm_lastMessageTime = 0;
92 WXDisplay *wxApp::ms_display = NULL;
93
94 IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
95
96 BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
97 EVT_IDLE(wxApp::OnIdle)
98 END_EVENT_TABLE()
99
100 bool wxApp::Initialize()
101 {
102 wxClassInfo::InitializeClasses();
103
104 // GL: I'm annoyed ... I don't know where to put this and I don't want to
105 // create a module for that as it's part of the core.
106 #if wxUSE_THREADS
107 wxPendingEventsLocker = new wxCriticalSection();
108 #endif
109
110 wxTheColourDatabase = new wxColourDatabase(wxKEY_STRING);
111 wxTheColourDatabase->Initialize();
112
113 wxInitializeStockLists();
114 wxInitializeStockObjects();
115
116 #if wxUSE_WX_RESOURCES
117 wxInitializeResourceSystem();
118 #endif
119
120 wxWidgetHashTable = new wxHashTable(wxKEY_INTEGER);
121
122 wxModule::RegisterModules();
123 if (!wxModule::InitializeModules()) return FALSE;
124
125 return TRUE;
126 }
127
128 void wxApp::CleanUp()
129 {
130 if (g_newArgv)
131 delete[] g_newArgv;
132 g_newArgv = NULL;
133
134 delete wxWidgetHashTable;
135 wxWidgetHashTable = NULL;
136
137 wxModule::CleanUpModules();
138
139 #if wxUSE_WX_RESOURCES
140 wxCleanUpResourceSystem();
141 #endif
142
143 delete wxTheColourDatabase;
144 wxTheColourDatabase = NULL;
145
146 wxDeleteStockObjects();
147
148 wxDeleteStockLists();
149
150 delete wxTheApp;
151 wxTheApp = NULL;
152
153 wxClassInfo::CleanUpClasses();
154
155 #if wxUSE_THREADS
156 delete wxPendingEvents;
157 delete wxPendingEventsLocker;
158 #endif
159
160 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
161 // At this point we want to check if there are any memory
162 // blocks that aren't part of the wxDebugContext itself,
163 // as a special case. Then when dumping we need to ignore
164 // wxDebugContext, too.
165 if (wxDebugContext::CountObjectsLeft(TRUE) > 0)
166 {
167 wxLogDebug("There were memory leaks.");
168 wxDebugContext::Dump();
169 wxDebugContext::PrintStatistics();
170 }
171 #endif
172
173 // do it as the very last thing because everything else can log messages
174 wxLog::DontCreateOnDemand();
175 // do it as the very last thing because everything else can log messages
176 delete wxLog::SetActiveTarget(NULL);
177 }
178
179 // NB: argc and argv may be changed here, pass by reference!
180 int wxEntryStart( int& argc, char *argv[] )
181 {
182 #ifdef __WXDEBUG__
183 // install the X error handler
184 gs_pfnXErrorHandler = XSetErrorHandler( wxXErrorHandler );
185 #endif // __WXDEBUG__
186
187 wxString displayName;
188 bool syncDisplay = FALSE;
189
190 // Parse the arguments.
191 // We can't use wxCmdLineParser or OnInitCmdLine and friends because
192 // we have to create the Display earlier. If we can find a way to
193 // use the wxAppBase API then I'll be quite happy to change it.
194 g_newArgv = new wxChar*[argc];
195 g_newArgc = 0;
196 int i;
197 for (i = 0; i < argc; i++)
198 {
199 wxString arg(argv[i]);
200 if (arg == wxT("-display"))
201 {
202 if (i < (argc - 1))
203 {
204 i ++;
205 displayName = argv[i];
206 continue;
207 }
208 }
209 else if (arg == wxT("-geometry"))
210 {
211 if (i < (argc - 1))
212 {
213 i ++;
214 wxString windowGeometry = argv[i];
215 int w, h;
216 if (wxSscanf(windowGeometry.c_str(), _T("%dx%d"), &w, &h) != 2)
217 {
218 wxLogError(_("Invalid geometry specification '%s'"), windowGeometry.c_str());
219 }
220 else
221 {
222 g_initialSize = wxSize(w, h);
223 }
224 continue;
225 }
226 }
227 else if (arg == wxT("-sync"))
228 {
229 syncDisplay = TRUE;
230 continue;
231 }
232 else if (arg == wxT("-iconic"))
233 {
234 g_showIconic = TRUE;
235
236 continue;
237 }
238
239 // Not eaten by wxWindows, so pass through
240 g_newArgv[g_newArgc] = argv[i];
241 g_newArgc ++;
242 }
243
244 Display* xdisplay = NULL;
245 if (displayName.IsEmpty())
246 xdisplay = XOpenDisplay(NULL);
247 else
248 xdisplay = XOpenDisplay((char*) displayName.c_str());
249
250 if (!xdisplay)
251 {
252 wxLogError( _("wxWindows could not open display. Exiting.") );
253 return -1;
254 }
255
256 if (syncDisplay)
257 {
258 XSynchronize(xdisplay, True);
259 }
260
261 wxApp::ms_display = (WXDisplay*) xdisplay;
262
263 XSelectInput( xdisplay, XDefaultRootWindow(xdisplay), PropertyChangeMask);
264
265 wxSetDetectableAutoRepeat( TRUE );
266
267 if (!wxApp::Initialize())
268 return -1;
269
270 return 0;
271 }
272
273 int wxEntryInitGui()
274 {
275 int retValue = 0;
276
277 if ( !wxTheApp->OnInitGui() )
278 retValue = -1;
279
280 return retValue;
281 }
282
283
284 int wxEntry( int argc, char *argv[] )
285 {
286 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
287 // This seems to be necessary since there are 'rogue'
288 // objects present at this point (perhaps global objects?)
289 // Setting a checkpoint will ignore them as far as the
290 // memory checking facility is concerned.
291 // Of course you may argue that memory allocated in globals should be
292 // checked, but this is a reasonable compromise.
293 wxDebugContext::SetCheckpoint();
294 #endif
295 int err = wxEntryStart(argc, argv);
296 if (err)
297 return err;
298
299 if (!wxTheApp)
300 {
301 if (!wxApp::GetInitializerFunction())
302 {
303 printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" );
304 return 0;
305 };
306
307 wxTheApp = (wxApp*) (* wxApp::GetInitializerFunction()) ();
308 };
309
310 if (!wxTheApp)
311 {
312 printf( "wxWindows error: wxTheApp == NULL\n" );
313 return 0;
314 };
315
316 wxTheApp->SetClassName(wxFileNameFromPath(argv[0]));
317 wxTheApp->SetAppName(wxFileNameFromPath(argv[0]));
318
319 // The command line may have been changed
320 // by stripping out -display etc.
321 if (g_newArgc > 0)
322 {
323 wxTheApp->argc = g_newArgc;
324 wxTheApp->argv = g_newArgv;
325 }
326 else
327 {
328 wxTheApp->argc = argc;
329 wxTheApp->argv = argv;
330 }
331 wxTheApp->m_showIconic = g_showIconic;
332 wxTheApp->m_initialSize = g_initialSize;
333
334 int retValue;
335 retValue = wxEntryInitGui();
336
337 // Here frames insert themselves automatically into wxTopLevelWindows by
338 // getting created in OnInit().
339 if ( retValue == 0 )
340 {
341 if ( !wxTheApp->OnInit() )
342 retValue = -1;
343 }
344
345 if ( retValue == 0 )
346 {
347 if (wxTheApp->Initialized()) retValue = wxTheApp->OnRun();
348 }
349
350 // flush the logged messages if any
351 wxLog *pLog = wxLog::GetActiveTarget();
352 if ( pLog != NULL && pLog->HasPendingMessages() )
353 pLog->Flush();
354
355 delete wxLog::SetActiveTarget(new wxLogStderr); // So dialog boxes aren't used
356 // for further messages
357
358 if (wxTheApp->GetTopWindow())
359 {
360 delete wxTheApp->GetTopWindow();
361 wxTheApp->SetTopWindow(NULL);
362 }
363
364 wxTheApp->DeletePendingObjects();
365
366 wxTheApp->OnExit();
367
368 wxApp::CleanUp();
369
370 return retValue;
371 };
372
373 // Static member initialization
374 wxAppInitializerFunction wxAppBase::m_appInitFn = (wxAppInitializerFunction) NULL;
375
376 wxApp::wxApp()
377 {
378 m_topWindow = NULL;
379 wxTheApp = this;
380 m_className = "";
381 m_wantDebugOutput = TRUE ;
382 m_appName = "";
383 argc = 0;
384 argv = NULL;
385 m_exitOnFrameDelete = TRUE;
386 m_mainColormap = (WXColormap) NULL;
387 m_topLevelWidget = (WXWindow) NULL;
388 m_maxRequestSize = 0;
389 m_mainLoop = NULL;
390 m_showIconic = FALSE;
391 m_initialSize = wxDefaultSize;
392 }
393
394 bool wxApp::Initialized()
395 {
396 if (GetTopWindow())
397 return TRUE;
398 else
399 return FALSE;
400 }
401
402 int wxApp::MainLoop()
403 {
404 int rt;
405 m_mainLoop = new wxEventLoop;
406
407 rt = m_mainLoop->Run();
408
409 delete m_mainLoop;
410 m_mainLoop = NULL;
411 return rt;
412 }
413
414 //-----------------------------------------------------------------------
415 // X11 predicate function for exposure compression
416 //-----------------------------------------------------------------------
417
418 struct wxExposeInfo
419 {
420 Window window;
421 Bool found_non_matching;
422 };
423
424 static Bool expose_predicate (Display *display, XEvent *xevent, XPointer arg)
425 {
426 wxExposeInfo *info = (wxExposeInfo*) arg;
427
428 if (info->found_non_matching)
429 return FALSE;
430
431 if (xevent->xany.type != Expose)
432 {
433 info->found_non_matching = TRUE;
434 return FALSE;
435 }
436
437 if (xevent->xexpose.window != info->window)
438 {
439 info->found_non_matching = TRUE;
440 return FALSE;
441 }
442
443 return TRUE;
444 }
445
446 //-----------------------------------------------------------------------
447 // Processes an X event.
448 //-----------------------------------------------------------------------
449
450 void wxApp::ProcessXEvent(WXEvent* _event)
451 {
452 XEvent* event = (XEvent*) _event;
453
454 wxWindow* win = NULL;
455 Window window = XEventGetWindow(event);
456 Window actualWindow = window;
457
458 // Find the first wxWindow that corresponds to this event window
459 // Because we're receiving events after a window
460 // has been destroyed, assume a 1:1 match between
461 // Window and wxWindow, so if it's not in the table,
462 // it must have been destroyed.
463
464 win = wxGetWindowFromTable(window);
465 if (!win)
466 return;
467
468 switch (event->type)
469 {
470 case KeyPress:
471 {
472 if (!win->IsEnabled())
473 return;
474
475 wxKeyEvent keyEvent(wxEVT_KEY_DOWN);
476 wxTranslateKeyEvent(keyEvent, win, window, event);
477
478 // wxLogDebug( "OnKey from %s", win->GetName().c_str() );
479
480 // We didn't process wxEVT_KEY_DOWN, so send
481 // wxEVT_CHAR
482 if (!win->GetEventHandler()->ProcessEvent( keyEvent ))
483 {
484 keyEvent.SetEventType(wxEVT_CHAR);
485 win->GetEventHandler()->ProcessEvent( keyEvent );
486 }
487 return;
488 }
489 case KeyRelease:
490 {
491 if (!win->IsEnabled())
492 return;
493
494 wxKeyEvent keyEvent(wxEVT_KEY_UP);
495 wxTranslateKeyEvent(keyEvent, win, window, event);
496
497 win->GetEventHandler()->ProcessEvent( keyEvent );
498 return;
499 }
500 case ConfigureNotify:
501 {
502 #if wxUSE_NANOX
503 if (event->update.utype == GR_UPDATE_SIZE)
504 #endif
505 {
506 wxSizeEvent sizeEvent( wxSize(XConfigureEventGetWidth(event), XConfigureEventGetHeight(event)), win->GetId() );
507 sizeEvent.SetEventObject( win );
508
509 win->GetEventHandler()->ProcessEvent( sizeEvent );
510 }
511 }
512 #if !wxUSE_NANOX
513 case PropertyNotify:
514 {
515 HandlePropertyChange(_event);
516 return;
517 }
518 case ClientMessage:
519 {
520 if (!win->IsEnabled())
521 return;
522
523 Atom wm_delete_window = XInternAtom(wxGlobalDisplay(), "WM_DELETE_WINDOW", True);
524 Atom wm_protocols = XInternAtom(wxGlobalDisplay(), "WM_PROTOCOLS", True);
525
526 if (event->xclient.message_type == wm_protocols)
527 {
528 if ((Atom) (event->xclient.data.l[0]) == wm_delete_window)
529 {
530 win->Close(FALSE);
531 }
532 }
533 return;
534 }
535 case ResizeRequest:
536 {
537 /*
538 * If resize event, don't resize until the last resize event for this
539 * window is recieved. Prevents flicker as windows are resized.
540 */
541
542 Display *disp = (Display*) wxGetDisplay();
543 XEvent report;
544
545 // to avoid flicker
546 report = * event;
547 while( XCheckTypedWindowEvent (disp, actualWindow, ResizeRequest, &report));
548
549 if (win)
550 {
551 wxSize sz = win->GetSize();
552 wxSizeEvent sizeEvent(sz, win->GetId());
553 sizeEvent.SetEventObject(win);
554
555 win->GetEventHandler()->ProcessEvent( sizeEvent );
556 }
557
558 return;
559 }
560 #endif
561 #if wxUSE_NANOX
562 case GR_EVENT_TYPE_CLOSE_REQ:
563 {
564 if (win)
565 {
566 win->Close(FALSE);
567 }
568 break;
569 }
570 #endif
571 case Expose:
572 {
573 win->GetUpdateRegion().Union( XExposeEventGetX(event), XExposeEventGetY(event),
574 XExposeEventGetWidth(event), XExposeEventGetHeight(event));
575
576 win->GetClearRegion().Union( XExposeEventGetX(event), XExposeEventGetY(event),
577 XExposeEventGetWidth(event), XExposeEventGetHeight(event));
578
579
580 #if !wxUSE_NANOX
581 XEvent tmp_event;
582 wxExposeInfo info;
583 info.window = event->xexpose.window;
584 info.found_non_matching = FALSE;
585 while (XCheckIfEvent( wxGlobalDisplay(), &tmp_event, expose_predicate, (XPointer) &info ))
586 {
587 win->GetUpdateRegion().Union( tmp_event.xexpose.x, tmp_event.xexpose.y,
588 tmp_event.xexpose.width, tmp_event.xexpose.height );
589
590 win->GetClearRegion().Union( tmp_event.xexpose.x, tmp_event.xexpose.y,
591 tmp_event.xexpose.width, tmp_event.xexpose.height );
592 }
593 #endif
594
595 win->SendEraseEvents();
596
597 return;
598 }
599 #if !wxUSE_NANOX
600 case GraphicsExpose:
601 {
602 // wxLogDebug( "GraphicsExpose from %s", win->GetName().c_str(),
603 // event->xgraphicsexpose.x, event->xgraphicsexpose.y,
604 // event->xgraphicsexpose.width, event->xgraphicsexpose.height);
605
606 win->GetUpdateRegion().Union( event->xgraphicsexpose.x, event->xgraphicsexpose.y,
607 event->xgraphicsexpose.width, event->xgraphicsexpose.height);
608
609 win->GetClearRegion().Union( event->xgraphicsexpose.x, event->xgraphicsexpose.y,
610 event->xgraphicsexpose.width, event->xgraphicsexpose.height);
611
612 if (event->xgraphicsexpose.count == 0)
613 {
614 // Only erase background, paint in idle time.
615 win->SendEraseEvents();
616 }
617
618 return;
619 }
620 #endif
621 case EnterNotify:
622 case LeaveNotify:
623 case ButtonPress:
624 case ButtonRelease:
625 case MotionNotify:
626 {
627 if (!win->IsEnabled())
628 return;
629
630 // Here we check if the top level window is
631 // disabled, which is one aspect of modality.
632 wxWindow *tlw = win;
633 while (tlw && !tlw->IsTopLevel())
634 tlw = tlw->GetParent();
635 if (tlw && !tlw->IsEnabled())
636 return;
637
638 if (event->type == ButtonPress)
639 {
640 if ((win != wxWindow::FindFocus()) && win->AcceptsFocus())
641 {
642 // This might actually be done in wxWindow::SetFocus()
643 // and not here.
644 g_prevFocus = wxWindow::FindFocus();
645 g_nextFocus = win;
646
647 win->SetFocus();
648 }
649 }
650
651 wxMouseEvent wxevent;
652 wxTranslateMouseEvent(wxevent, win, window, event);
653 win->GetEventHandler()->ProcessEvent( wxevent );
654 return;
655 }
656 case FocusIn:
657 {
658 #if !wxUSE_NANOX
659 if ((event->xfocus.detail != NotifyPointer) &&
660 (event->xfocus.mode == NotifyNormal))
661 #endif
662 {
663 // wxLogDebug( "FocusIn from %s of type %s", win->GetName().c_str(), win->GetClassInfo()->GetClassName() );
664
665 wxFocusEvent focusEvent(wxEVT_SET_FOCUS, win->GetId());
666 focusEvent.SetEventObject(win);
667 focusEvent.SetWindow( g_prevFocus );
668 g_prevFocus = NULL;
669
670 win->GetEventHandler()->ProcessEvent(focusEvent);
671 }
672 break;
673 }
674 case FocusOut:
675 {
676 #if !wxUSE_NANOX
677 if ((event->xfocus.detail != NotifyPointer) &&
678 (event->xfocus.mode == NotifyNormal))
679 #endif
680 {
681 // wxLogDebug( "FocusOut from %s of type %s", win->GetName().c_str(), win->GetClassInfo()->GetClassName() );
682
683 wxFocusEvent focusEvent(wxEVT_KILL_FOCUS, win->GetId());
684 focusEvent.SetEventObject(win);
685 focusEvent.SetWindow( g_nextFocus );
686 g_nextFocus = NULL;
687 win->GetEventHandler()->ProcessEvent(focusEvent);
688 }
689 break;
690 }
691 #ifndef wxUSE_NANOX
692 case DestroyNotify:
693 {
694 // Do we want to process this (for top-level windows)?
695 // But we want to be able to veto closes, anyway
696 break;
697 }
698 #endif
699 default:
700 {
701 #ifdef __WXDEBUG__
702 //wxString eventName = wxGetXEventName(XEvent& event);
703 //wxLogDebug(wxT("Event %s not handled"), eventName.c_str());
704 #endif
705 break;
706 }
707 }
708 }
709
710 // Returns TRUE if more time is needed.
711 // Note that this duplicates wxEventLoopImpl::SendIdleEvent
712 // but ProcessIdle may be needed by apps, so is kept.
713 bool wxApp::ProcessIdle()
714 {
715 wxIdleEvent event;
716 event.SetEventObject(this);
717 ProcessEvent(event);
718
719 return event.MoreRequested();
720 }
721
722 void wxApp::ExitMainLoop()
723 {
724 if (m_mainLoop)
725 m_mainLoop->Exit(0);
726 }
727
728 // Is a message/event pending?
729 bool wxApp::Pending()
730 {
731 return wxEventLoop::GetActive()->Pending();
732 }
733
734 // Dispatch a message.
735 void wxApp::Dispatch()
736 {
737 wxEventLoop::GetActive()->Dispatch();
738 }
739
740 // This should be redefined in a derived class for
741 // handling property change events for XAtom IPC.
742 void wxApp::HandlePropertyChange(WXEvent *event)
743 {
744 // by default do nothing special
745 // TODO: what to do for X11
746 // XtDispatchEvent((XEvent*) event);
747 }
748
749 void wxApp::OnIdle(wxIdleEvent& event)
750 {
751 static bool s_inOnIdle = FALSE;
752
753 // Avoid recursion (via ProcessEvent default case)
754 if (s_inOnIdle)
755 return;
756
757 s_inOnIdle = TRUE;
758
759 // Resend in the main thread events which have been prepared in other
760 // threads
761 ProcessPendingEvents();
762
763 // 'Garbage' collection of windows deleted with Close()
764 DeletePendingObjects();
765
766 // Send OnIdle events to all windows
767 bool needMore = SendIdleEvents();
768
769 if (needMore)
770 event.RequestMore(TRUE);
771
772 s_inOnIdle = FALSE;
773 }
774
775 void wxWakeUpIdle()
776 {
777 // **** please implement me! ****
778 // Wake up the idle handler processor, even if it is in another thread...
779 }
780
781
782 // Send idle event to all top-level windows
783 bool wxApp::SendIdleEvents()
784 {
785 bool needMore = FALSE;
786
787 wxWindowList::Node* node = wxTopLevelWindows.GetFirst();
788 while (node)
789 {
790 wxWindow* win = node->GetData();
791 if (SendIdleEvents(win))
792 needMore = TRUE;
793 node = node->GetNext();
794 }
795
796 return needMore;
797 }
798
799 // Send idle event to window and all subwindows
800 bool wxApp::SendIdleEvents(wxWindow* win)
801 {
802 bool needMore = FALSE;
803
804 wxIdleEvent event;
805 event.SetEventObject(win);
806
807 win->GetEventHandler()->ProcessEvent(event);
808
809 win->OnInternalIdle();
810
811 if (event.MoreRequested())
812 needMore = TRUE;
813
814 wxNode* node = win->GetChildren().First();
815 while (node)
816 {
817 wxWindow* win = (wxWindow*) node->Data();
818 if (SendIdleEvents(win))
819 needMore = TRUE;
820
821 node = node->Next();
822 }
823
824 return needMore;
825 }
826
827 void wxApp::DeletePendingObjects()
828 {
829 wxNode *node = wxPendingDelete.First();
830 while (node)
831 {
832 wxObject *obj = (wxObject *)node->Data();
833
834 delete obj;
835
836 if (wxPendingDelete.Member(obj))
837 delete node;
838
839 // Deleting one object may have deleted other pending
840 // objects, so start from beginning of list again.
841 node = wxPendingDelete.First();
842 }
843 }
844
845 // Create display, and other initialization
846 bool wxApp::OnInitGui()
847 {
848 // Eventually this line will be removed, but for
849 // now we don't want to try popping up a dialog
850 // for error messages.
851 delete wxLog::SetActiveTarget(new wxLogStderr);
852
853 if (!wxAppBase::OnInitGui())
854 return FALSE;
855
856 GetMainColormap( wxApp::GetDisplay() );
857
858 m_maxRequestSize = XMaxRequestSize( (Display*) wxApp::GetDisplay() );
859
860 return TRUE;
861 }
862
863 WXColormap wxApp::GetMainColormap(WXDisplay* display)
864 {
865 if (!display) /* Must be called first with non-NULL display */
866 return m_mainColormap;
867
868 int defaultScreen = DefaultScreen((Display*) display);
869 Screen* screen = XScreenOfDisplay((Display*) display, defaultScreen);
870
871 Colormap c = DefaultColormapOfScreen(screen);
872
873 if (!m_mainColormap)
874 m_mainColormap = (WXColormap) c;
875
876 return (WXColormap) c;
877 }
878
879 Window wxGetWindowParent(Window window)
880 {
881 wxASSERT_MSG( window, "invalid window" );
882
883 return (Window) 0;
884
885 Window parent, root = 0;
886 #if wxUSE_NANOX
887 int noChildren = 0;
888 #else
889 unsigned int noChildren = 0;
890 #endif
891 Window* children = NULL;
892
893 // #define XQueryTree(d,w,r,p,c,nc) GrQueryTree(w,p,c,nc)
894 int res = 1;
895 #if !wxUSE_NANOX
896 res =
897 #endif
898 XQueryTree((Display*) wxGetDisplay(), window, & root, & parent,
899 & children, & noChildren);
900 if (children)
901 XFree(children);
902 if (res)
903 return parent;
904 else
905 return (Window) 0;
906 }
907
908 void wxExit()
909 {
910 int retValue = 0;
911 if (wxTheApp)
912 retValue = wxTheApp->OnExit();
913
914 wxApp::CleanUp();
915 /*
916 * Exit in some platform-specific way. Not recommended that the app calls this:
917 * only for emergencies.
918 */
919 exit(retValue);
920 }
921
922 // Yield to other processes
923
924 bool wxApp::Yield(bool onlyIfNeeded)
925 {
926 bool s_inYield = FALSE;
927
928 if ( s_inYield )
929 {
930 if ( !onlyIfNeeded )
931 {
932 wxFAIL_MSG( wxT("wxYield called recursively" ) );
933 }
934
935 return FALSE;
936 }
937
938 s_inYield = TRUE;
939
940 while (wxTheApp && wxTheApp->Pending())
941 wxTheApp->Dispatch();
942
943 s_inYield = FALSE;
944
945 return TRUE;
946 }
947
948 wxIcon wxApp::GetStdIcon(int which) const
949 {
950 return wxTheme::Get()->GetRenderer()->GetStdIcon(which);
951 }
952
953 void wxApp::OnAssert(const wxChar *file, int line, const wxChar *msg)
954 {
955 // While the GUI isn't working that well, just print out the
956 // message.
957 #if 0
958 wxAppBase::OnAssert(file, line, msg);
959 #else
960 wxString msg2;
961 msg2.Printf("At file %s:%d: %s", file, line, msg);
962 wxLogDebug(msg2);
963 #endif
964 }
965