]> git.saurik.com Git - wxWidgets.git/blame - src/motif/app.cpp
Fixed blatant non-initialisation bug
[wxWidgets.git] / src / motif / app.cpp
CommitLineData
4bb6408c
JS
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
afb74891 9// Licence: wxWindows licence
4bb6408c
JS
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
ee31c392 13 #pragma implementation "app.h"
4bb6408c
JS
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/pen.h"
21#include "wx/brush.h"
22#include "wx/cursor.h"
23#include "wx/icon.h"
24#include "wx/palette.h"
25#include "wx/dc.h"
26#include "wx/dialog.h"
27#include "wx/msgdlg.h"
28#include "wx/log.h"
29#include "wx/module.h"
30#include "wx/memory.h"
8bedcdce
RR
31#include "wx/log.h"
32#include "wx/intl.h"
b412f9be 33
7bcb11d3 34#if wxUSE_THREADS
dfe1eee3 35 #include "wx/thread.h"
7bcb11d3 36#endif
4bb6408c 37
47d67540 38#if wxUSE_WX_RESOURCES
9c6e1335 39 #include "wx/resource.h"
4bb6408c
JS
40#endif
41
338dd992
JJ
42#ifdef __VMS__
43#pragma message disable nosimpint
44#endif
4bb6408c
JS
45#include <Xm/Xm.h>
46#include <X11/Xlib.h>
47#include <X11/Xutil.h>
48#include <X11/Xresource.h>
49#include <X11/Xatom.h>
338dd992
JJ
50#ifdef __VMS__
51#pragma message enable nosimpint
52#endif
4bb6408c
JS
53
54#include "wx/motif/private.h"
55
56#include <string.h>
57
58extern char *wxBuffer;
59extern wxList wxPendingDelete;
7491d644 60
4bb6408c
JS
61wxApp *wxTheApp = NULL;
62
63wxHashTable *wxWidgetHashTable = NULL;
64
4bb6408c 65IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
9c6e1335 66
4bb6408c 67BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
9c6e1335 68 EVT_IDLE(wxApp::OnIdle)
4bb6408c 69END_EVENT_TABLE()
4bb6408c 70
e838cc14
VZ
71#ifdef __WXDEBUG__
72 typedef int (*XErrorHandlerFunc)(Display *, XErrorEvent *);
73
74 XErrorHandlerFunc gs_pfnXErrorHandler = 0;
75
76 static int wxXErrorHandler(Display *dpy, XErrorEvent *xevent)
77 {
78 // just forward to the default handler for now
79 return gs_pfnXErrorHandler(dpy, xevent);
80 }
81#endif // __WXDEBUG__
82
4bb6408c
JS
83long wxApp::sm_lastMessageTime = 0;
84
85bool wxApp::Initialize()
86{
4bb6408c 87 wxBuffer = new char[BUFSIZ + 512];
afb74891 88
4bb6408c 89 wxClassInfo::InitializeClasses();
afb74891 90
ee31c392 91 // GL: I'm annoyed ... I don't know where to put this and I don't want to
4d3a259a
GL
92 // create a module for that as it's part of the core.
93#if wxUSE_THREADS
4d3a259a
GL
94 wxPendingEventsLocker = new wxCriticalSection();
95#endif
96
4bb6408c
JS
97 wxTheColourDatabase = new wxColourDatabase(wxKEY_STRING);
98 wxTheColourDatabase->Initialize();
afb74891 99
4b5f3fe6 100 wxInitializeStockLists();
4bb6408c 101 wxInitializeStockObjects();
afb74891 102
47d67540 103#if wxUSE_WX_RESOURCES
4bb6408c
JS
104 wxInitializeResourceSystem();
105#endif
afb74891 106
2d120f83 107 // For PostScript printing
47d67540 108#if wxUSE_POSTSCRIPT
2d120f83 109 /* Done using wxModule now
4bb6408c
JS
110 wxInitializePrintSetupData();
111 wxThePrintPaperDatabase = new wxPrintPaperDatabase;
112 wxThePrintPaperDatabase->CreateDatabase();
2d120f83 113 */
4bb6408c 114#endif
afb74891 115
4bb6408c 116 wxBitmap::InitStandardHandlers();
afb74891 117
4bb6408c 118 wxWidgetHashTable = new wxHashTable(wxKEY_INTEGER);
afb74891 119
4bb6408c 120 wxModule::RegisterModules();
aaa38880 121 if (!wxModule::InitializeModules()) return FALSE;
afb74891 122
4bb6408c
JS
123 return TRUE;
124}
125
126void wxApp::CleanUp()
127{
128 delete wxWidgetHashTable;
129 wxWidgetHashTable = NULL;
afb74891 130
4bb6408c 131 wxModule::CleanUpModules();
afb74891 132
47d67540 133#if wxUSE_WX_RESOURCES
4bb6408c
JS
134 wxCleanUpResourceSystem();
135#endif
afb74891 136
4bb6408c 137 wxDeleteStockObjects() ;
afb74891 138
4bb6408c 139 // Destroy all GDI lists, etc.
afb74891 140
4bb6408c
JS
141 delete wxTheBrushList;
142 wxTheBrushList = NULL;
afb74891 143
4bb6408c
JS
144 delete wxThePenList;
145 wxThePenList = NULL;
afb74891 146
4bb6408c
JS
147 delete wxTheFontList;
148 wxTheFontList = NULL;
afb74891 149
4bb6408c
JS
150 delete wxTheBitmapList;
151 wxTheBitmapList = NULL;
afb74891 152
4bb6408c
JS
153 delete wxTheColourDatabase;
154 wxTheColourDatabase = NULL;
afb74891 155
47d67540 156#if wxUSE_POSTSCRIPT
2d120f83 157 /* Done using wxModule now
4bb6408c
JS
158 wxInitializePrintSetupData(FALSE);
159 delete wxThePrintPaperDatabase;
160 wxThePrintPaperDatabase = NULL;
2d120f83 161 */
4bb6408c 162#endif
afb74891 163
4bb6408c 164 wxBitmap::CleanUpHandlers();
afb74891 165
4bb6408c
JS
166 delete[] wxBuffer;
167 wxBuffer = NULL;
afb74891 168
4bb6408c 169 wxClassInfo::CleanUpClasses();
afb74891 170
184b5d99
JS
171 delete wxTheApp;
172 wxTheApp = NULL;
afb74891 173
4d3a259a
GL
174 // GL: I'm annoyed ... I don't know where to put this and I don't want to
175 // create a module for that as it's part of the core.
176#if wxUSE_THREADS
177 delete wxPendingEvents;
178 delete wxPendingEventsLocker;
179#endif
180
184b5d99
JS
181#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
182 // At this point we want to check if there are any memory
183 // blocks that aren't part of the wxDebugContext itself,
184 // as a special case. Then when dumping we need to ignore
185 // wxDebugContext, too.
4fabb575 186 if (wxDebugContext::CountObjectsLeft(TRUE) > 0)
184b5d99 187 {
2d120f83
JS
188 wxLogDebug("There were memory leaks.\n");
189 wxDebugContext::Dump();
190 wxDebugContext::PrintStatistics();
184b5d99 191 }
184b5d99 192#endif
afb74891 193
4bb6408c
JS
194 // do it as the very last thing because everything else can log messages
195 wxLog::DontCreateOnDemand();
196 // do it as the very last thing because everything else can log messages
197 delete wxLog::SetActiveTarget(NULL);
198}
199
200int wxEntry( int argc, char *argv[] )
201{
4fabb575
JS
202#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
203 // This seems to be necessary since there are 'rogue'
204 // objects present at this point (perhaps global objects?)
205 // Setting a checkpoint will ignore them as far as the
206 // memory checking facility is concerned.
207 // Of course you may argue that memory allocated in globals should be
208 // checked, but this is a reasonable compromise.
209 wxDebugContext::SetCheckpoint();
210#endif
afb74891 211
4bb6408c 212 if (!wxApp::Initialize())
2d120f83 213 return FALSE;
afb74891 214
4bb6408c
JS
215 if (!wxTheApp)
216 {
2d120f83
JS
217 if (!wxApp::GetInitializerFunction())
218 {
219 printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" );
220 return 0;
221 };
afb74891 222
2d120f83 223 wxTheApp = (wxApp*) (* wxApp::GetInitializerFunction()) ();
4bb6408c 224 };
afb74891 225
4bb6408c
JS
226 if (!wxTheApp)
227 {
2d120f83
JS
228 printf( "wxWindows error: wxTheApp == NULL\n" );
229 return 0;
4bb6408c 230 };
afb74891 231
4bb6408c
JS
232 wxTheApp->SetClassName(wxFileNameFromPath(argv[0]));
233 wxTheApp->SetAppName(wxFileNameFromPath(argv[0]));
afb74891 234
4bb6408c
JS
235 wxTheApp->argc = argc;
236 wxTheApp->argv = argv;
afb74891 237
4bb6408c
JS
238 // GUI-specific initialization, such as creating an app context.
239 wxTheApp->OnInitGui();
afb74891 240
e146b8c8
VZ
241 // Here frames insert themselves automatically into wxTopLevelWindows by
242 // getting created in OnInit().
afb74891 243
4bb6408c 244 int retValue = 0;
4fabb575
JS
245 if (wxTheApp->OnInit())
246 {
2d120f83 247 if (wxTheApp->Initialized()) retValue = wxTheApp->OnRun();
4fabb575 248 }
afb74891 249
f57fe24c
JS
250 // flush the logged messages if any
251 wxLog *pLog = wxLog::GetActiveTarget();
252 if ( pLog != NULL && pLog->HasPendingMessages() )
2d120f83 253 pLog->Flush();
afb74891 254
f57fe24c 255 delete wxLog::SetActiveTarget(new wxLogStderr); // So dialog boxes aren't used
2d120f83 256 // for further messages
afb74891 257
4bb6408c
JS
258 if (wxTheApp->GetTopWindow())
259 {
2d120f83
JS
260 delete wxTheApp->GetTopWindow();
261 wxTheApp->SetTopWindow(NULL);
4bb6408c 262 }
afb74891 263
4bb6408c 264 wxTheApp->DeletePendingObjects();
afb74891 265
4bb6408c 266 wxTheApp->OnExit();
afb74891 267
4bb6408c 268 wxApp::CleanUp();
afb74891 269
4bb6408c
JS
270 return retValue;
271};
272
273// Static member initialization
ee31c392 274wxAppInitializerFunction wxAppBase::m_appInitFn = (wxAppInitializerFunction) NULL;
4bb6408c
JS
275
276wxApp::wxApp()
277{
278 m_topWindow = NULL;
279 wxTheApp = this;
280 m_className = "";
281 m_wantDebugOutput = TRUE ;
282 m_appName = "";
283 argc = 0;
284 argv = NULL;
4bb6408c 285 m_exitOnFrameDelete = TRUE;
afb74891 286
4bb6408c
JS
287 m_mainColormap = (WXColormap) NULL;
288 m_appContext = (WXAppContext) NULL;
289 m_topLevelWidget = (WXWidget) NULL;
290 m_maxRequestSize = 0;
47bc1060 291 m_initialDisplay = (WXDisplay*) 0;
4bb6408c
JS
292}
293
294bool wxApp::Initialized()
295{
296 if (GetTopWindow())
2d120f83 297 return TRUE;
4bb6408c 298 else
2d120f83 299 return FALSE;
4bb6408c
JS
300}
301
302int wxApp::MainLoop()
303{
304 m_keepGoing = TRUE;
afb74891 305
2d120f83 306 /*
4bb6408c
JS
307 * Sit around forever waiting to process X-events. Property Change
308 * event are handled special, because they have to refer to
309 * the root window rather than to a widget. therefore we can't
310 * use an Xt-eventhandler.
311 */
afb74891 312
4bb6408c 313 XSelectInput(XtDisplay((Widget) wxTheApp->GetTopLevelWidget()),
2d120f83
JS
314 XDefaultRootWindow(XtDisplay((Widget) wxTheApp->GetTopLevelWidget())),
315 PropertyChangeMask);
afb74891 316
4bb6408c 317 XEvent event;
afb74891 318
4bb6408c
JS
319 // Use this flag to allow breaking the loop via wxApp::ExitMainLoop()
320 while (m_keepGoing)
321 {
2d120f83 322 XtAppNextEvent( (XtAppContext) wxTheApp->GetAppContext(), &event);
afb74891 323
2d120f83 324 ProcessXEvent((WXEvent*) & event);
afb74891 325
2d120f83
JS
326 if (XtAppPending( (XtAppContext) wxTheApp->GetAppContext() ) == 0)
327 {
328 if (!ProcessIdle())
afb74891 329 {
7bcb11d3 330#if wxUSE_THREADS
afb74891
VZ
331 // leave the main loop to give other threads a chance to
332 // perform their GUI work
2d120f83 333 wxMutexGuiLeave();
afb74891 334 wxUsleep(20);
2d120f83 335 wxMutexGuiEnter();
7bcb11d3 336#endif
2d120f83
JS
337 }
338 }
afb74891 339
8aa04e8b 340 }
afb74891 341
8aa04e8b
JS
342 return 0;
343}
344
345// Processes an X event.
346void wxApp::ProcessXEvent(WXEvent* _event)
347{
348 XEvent* event = (XEvent*) _event;
afb74891 349
ee31c392 350 if (event->type == KeyPress)
8aa04e8b 351 {
dc1efb1d 352#if 0 // def __WXDEBUG__
31528cd3
VZ
353 Widget widget = XtWindowToWidget(event->xany.display, event->xany.window);
354 wxLogDebug("Got key press event for 0x%08x (parent = 0x%08x)",
355 widget, XtParent(widget));
356#endif // DEBUG
357
3d9431bf
MB
358 if (CheckForAccelerator(_event))
359 {
360 // Do nothing! We intercepted and processed the event as an
361 // accelerator.
362 return;
363 }
a3736ef4 364#if 1
9779893b 365 // It seemed before that this hack was redundant and
a3736ef4
MB
366 // key down events were being generated by wxCanvasInputEvent.
367 // But no longer - why ???
368 //
3d9431bf
MB
369 else if (CheckForKeyDown(_event))
370 {
371 // We intercepted and processed the key down event
372 return;
373 }
9779893b 374#endif
3d9431bf
MB
375 else
376 {
377 XtDispatchEvent(event);
378 return;
379 }
380 }
381 else if (event->type == KeyRelease)
382 {
364c7f3c
MB
383 // TODO: work out why we still need this ! -michael
384 //
3d9431bf
MB
385 if (CheckForKeyUp(_event))
386 {
387 // We intercepted and processed the key up event
388 return;
389 }
390 else
391 {
392 XtDispatchEvent(event);
393 return;
394 }
8aa04e8b
JS
395 }
396 else if (event->type == PropertyNotify)
397 {
398 HandlePropertyChange(_event);
399 return;
400 }
401 else if (event->type == ResizeRequest)
402 {
ee31c392
VZ
403 /* Terry Gitnick <terryg@scientech.com> - 1/21/98
404 * If resize event, don't resize until the last resize event for this
405 * window is recieved. Prevents flicker as windows are resized.
406 */
afb74891 407
8aa04e8b
JS
408 Display *disp = XtDisplay((Widget) wxTheApp->GetTopLevelWidget());
409 Window win = event->xany.window;
410 XEvent report;
afb74891 411
8aa04e8b
JS
412 // to avoid flicker
413 report = * event;
414 while( XCheckTypedWindowEvent (disp, win, ResizeRequest, &report));
afb74891 415
f97c9854
JS
416 // TODO: when implementing refresh optimization, we can use
417 // XtAddExposureToRegion to expand the window's paint region.
afb74891 418
8aa04e8b
JS
419 XtDispatchEvent(event);
420 }
421 else
422 {
423 XtDispatchEvent(event);
4bb6408c 424 }
4bb6408c
JS
425}
426
427// Returns TRUE if more time is needed.
428bool wxApp::ProcessIdle()
429{
430 wxIdleEvent event;
431 event.SetEventObject(this);
432 ProcessEvent(event);
afb74891 433
4bb6408c
JS
434 return event.MoreRequested();
435}
436
437void wxApp::ExitMainLoop()
438{
439 m_keepGoing = FALSE;
440}
441
442// Is a message/event pending?
443bool wxApp::Pending()
444{
445 XFlush(XtDisplay( (Widget) wxTheApp->GetTopLevelWidget() ));
afb74891 446
8aa04e8b
JS
447 // Fix by Doug from STI, to prevent a stall if non-X event
448 // is found.
449 return ((XtAppPending( (XtAppContext) GetAppContext() ) & XtIMXEvent) != 0) ;
4bb6408c
JS
450}
451
452// Dispatch a message.
453void wxApp::Dispatch()
454{
2d120f83 455 // XtAppProcessEvent( (XtAppContext) wxTheApp->GetAppContext(), XtIMAll);
afb74891 456
8aa04e8b
JS
457 XEvent event;
458 XtAppNextEvent((XtAppContext) GetAppContext(), &event);
459 ProcessXEvent((WXEvent*) & event);
4bb6408c
JS
460}
461
462// This should be redefined in a derived class for
463// handling property change events for XAtom IPC.
464void wxApp::HandlePropertyChange(WXEvent *event)
465{
466 // by default do nothing special
467 XtDispatchEvent((XEvent*) event); /* let Motif do the work */
468}
469
470void wxApp::OnIdle(wxIdleEvent& event)
471{
472 static bool inOnIdle = FALSE;
afb74891 473
4bb6408c
JS
474 // Avoid recursion (via ProcessEvent default case)
475 if (inOnIdle)
2d120f83 476 return;
afb74891 477
4bb6408c 478 inOnIdle = TRUE;
afb74891 479
4bb6408c
JS
480 // 'Garbage' collection of windows deleted with Close().
481 DeletePendingObjects();
afb74891 482
7214297d
GL
483#if wxUSE_THREADS
484 // Flush pending events.
485 ProcessPendingEvents();
486#endif
487
4bb6408c
JS
488 // flush the logged messages if any
489 wxLog *pLog = wxLog::GetActiveTarget();
490 if ( pLog != NULL && pLog->HasPendingMessages() )
2d120f83 491 pLog->Flush();
afb74891 492
4bb6408c
JS
493 // Send OnIdle events to all windows
494 bool needMore = SendIdleEvents();
afb74891 495
4bb6408c 496 if (needMore)
2d120f83 497 event.RequestMore(TRUE);
afb74891 498
4bb6408c
JS
499 inOnIdle = FALSE;
500}
501
9779893b
RD
502void wxWakeUpIdle()
503{
504 // **** please implement me! ****
505 // Wake up the idle handler processor, even if it is in another thread...
506}
507
508
4bb6408c
JS
509// Send idle event to all top-level windows
510bool wxApp::SendIdleEvents()
511{
512 bool needMore = FALSE;
e146b8c8
VZ
513
514 wxWindowList::Node* node = wxTopLevelWindows.GetFirst();
2d120f83
JS
515 while (node)
516 {
e146b8c8 517 wxWindow* win = node->GetData();
2d120f83 518 if (SendIdleEvents(win))
4bb6408c 519 needMore = TRUE;
e146b8c8 520 node = node->GetNext();
2d120f83 521 }
e146b8c8 522
4bb6408c
JS
523 return needMore;
524}
525
526// Send idle event to window and all subwindows
527bool wxApp::SendIdleEvents(wxWindow* win)
528{
529 bool needMore = FALSE;
afb74891 530
2d120f83
JS
531 wxIdleEvent event;
532 event.SetEventObject(win);
533 win->ProcessEvent(event);
afb74891 534
4bb6408c
JS
535 if (event.MoreRequested())
536 needMore = TRUE;
afb74891 537
2d120f83
JS
538 wxNode* node = win->GetChildren().First();
539 while (node)
540 {
541 wxWindow* win = (wxWindow*) node->Data();
542 if (SendIdleEvents(win))
4bb6408c 543 needMore = TRUE;
afb74891 544
2d120f83
JS
545 node = node->Next();
546 }
4bb6408c
JS
547 return needMore ;
548}
549
550void wxApp::DeletePendingObjects()
551{
552 wxNode *node = wxPendingDelete.First();
553 while (node)
554 {
2d120f83 555 wxObject *obj = (wxObject *)node->Data();
afb74891 556
2d120f83 557 delete obj;
afb74891 558
2d120f83
JS
559 if (wxPendingDelete.Member(obj))
560 delete node;
afb74891 561
2d120f83
JS
562 // Deleting one object may have deleted other pending
563 // objects, so start from beginning of list again.
564 node = wxPendingDelete.First();
4bb6408c
JS
565 }
566}
567
4bb6408c
JS
568// Create an application context
569bool wxApp::OnInitGui()
570{
571 XtToolkitInitialize() ;
572 wxTheApp->m_appContext = (WXAppContext) XtCreateApplicationContext() ;
573 Display *dpy = XtOpenDisplay((XtAppContext) wxTheApp->m_appContext,(String)NULL,NULL,
9c6e1335 574 (const char*) wxTheApp->GetClassName(), NULL, 0,
4bb6408c 575# if XtSpecificationRelease < 5
9c6e1335 576 (Cardinal*) &argc,
4bb6408c 577# else
9c6e1335 578 &argc,
4bb6408c 579# endif
9c6e1335
VZ
580 argv);
581
4bb6408c 582 if (!dpy) {
7bcb11d3 583 wxString className(wxTheApp->GetClassName());
9c6e1335 584 wxLogError(_("wxWindows could not open display for '%s': exiting."),
7bcb11d3 585 (const char*) className);
2d120f83 586 exit(-1);
4bb6408c 587 }
47bc1060 588 m_initialDisplay = (WXDisplay*) dpy;
afb74891 589
e838cc14
VZ
590#ifdef __WXDEBUG__
591 // install the X error handler
592 gs_pfnXErrorHandler = XSetErrorHandler(wxXErrorHandler);
593#endif // __WXDEBUG__
594
4bb6408c 595 wxTheApp->m_topLevelWidget = (WXWidget) XtAppCreateShell((String)NULL, (const char*) wxTheApp->GetClassName(),
2d120f83
JS
596 applicationShellWidgetClass,dpy,
597 NULL,0) ;
afb74891 598
4bb6408c
JS
599 // Add general resize proc
600 XtActionsRec rec;
601 rec.string = "resize";
602 rec.proc = (XtActionProc)wxWidgetResizeProc;
603 XtAppAddActions((XtAppContext) wxTheApp->m_appContext, &rec, 1);
afb74891 604
4bb6408c
JS
605 GetMainColormap(dpy);
606 m_maxRequestSize = XMaxRequestSize((Display*) dpy);
afb74891 607
4bb6408c
JS
608 return TRUE;
609}
610
611WXColormap wxApp::GetMainColormap(WXDisplay* display)
612{
613 if (!display) /* Must be called first with non-NULL display */
2d120f83 614 return m_mainColormap;
a91b47e8
JS
615
616 int defaultScreen = DefaultScreen((Display*) display);
617 Screen* screen = XScreenOfDisplay((Display*) display, defaultScreen);
afb74891 618
a91b47e8 619 Colormap c = DefaultColormapOfScreen(screen);
afb74891 620
4bb6408c 621 if (!m_mainColormap)
2d120f83 622 m_mainColormap = (WXColormap) c;
afb74891 623
4bb6408c
JS
624 return (WXColormap) c;
625}
626
8aa04e8b
JS
627// Returns TRUE if an accelerator has been processed
628bool wxApp::CheckForAccelerator(WXEvent* event)
629{
630 XEvent* xEvent = (XEvent*) event;
631 if (xEvent->xany.type == KeyPress)
632 {
633 // Find a wxWindow for this window
634 // TODO: should get display for the window, not the current display
635 Widget widget = XtWindowToWidget((Display*) wxGetDisplay(), xEvent->xany.window);
636 wxWindow* win = NULL;
afb74891 637
8aa04e8b
JS
638 // Find the first wxWindow that corresponds to this event window
639 while (widget && !(win = wxGetWindowFromTable(widget)))
640 widget = XtParent(widget);
afb74891 641
8aa04e8b
JS
642 if (!widget || !win)
643 return FALSE;
afb74891 644
8aa04e8b
JS
645 wxKeyEvent keyEvent(wxEVT_CHAR);
646 wxTranslateKeyEvent(keyEvent, win, (Widget) 0, xEvent);
afb74891 647
8aa04e8b
JS
648 // Now we have a wxKeyEvent and we have a wxWindow.
649 // Go up the hierarchy until we find a matching accelerator,
650 // or we get to the top.
651 while (win)
652 {
653 if (win->ProcessAccelerator(keyEvent))
654 return TRUE;
655 win = win->GetParent();
656 }
657 return FALSE;
658 }
659 return FALSE;
660}
661
ee31c392
VZ
662bool wxApp::CheckForKeyDown(WXEvent* event)
663{
664 XEvent* xEvent = (XEvent*) event;
ee31c392
VZ
665 if (xEvent->xany.type == KeyPress)
666 {
3d9431bf
MB
667 Widget widget = XtWindowToWidget((Display*) wxGetDisplay(),
668 xEvent->xany.window);
669 wxWindow* win = NULL;
670
671 // Find the first wxWindow that corresponds to this event window
672 while (widget && !(win = wxGetWindowFromTable(widget)))
673 widget = XtParent(widget);
674
675 if (!widget || !win)
676 return FALSE;
677
678 wxKeyEvent keyEvent(wxEVT_KEY_DOWN);
679 wxTranslateKeyEvent(keyEvent, win, (Widget) 0, xEvent);
680
681 return win->ProcessEvent( keyEvent );
682 }
683
684 return FALSE;
685}
686
687bool wxApp::CheckForKeyUp(WXEvent* event)
688{
689 XEvent* xEvent = (XEvent*) event;
690 if (xEvent->xany.type == KeyRelease)
691 {
692 Widget widget = XtWindowToWidget((Display*) wxGetDisplay(),
693 xEvent->xany.window);
694 wxWindow* win = NULL;
ee31c392 695
3d9431bf
MB
696 // Find the first wxWindow that corresponds to this event window
697 while (widget && !(win = wxGetWindowFromTable(widget)))
698 widget = XtParent(widget);
ee31c392 699
3d9431bf
MB
700 if (!widget || !win)
701 return FALSE;
ee31c392 702
3d9431bf
MB
703 wxKeyEvent keyEvent(wxEVT_KEY_UP);
704 wxTranslateKeyEvent(keyEvent, win, (Widget) 0, xEvent);
ee31c392 705
3d9431bf 706 return win->ProcessEvent( keyEvent );
ee31c392 707 }
ee31c392
VZ
708
709 return FALSE;
710}
711
4bb6408c
JS
712void wxExit()
713{
714 int retValue = 0;
715 if (wxTheApp)
2d120f83 716 retValue = wxTheApp->OnExit();
afb74891 717
4bb6408c
JS
718 wxApp::CleanUp();
719 /*
2d120f83
JS
720 * Exit in some platform-specific way. Not recommended that the app calls this:
721 * only for emergencies.
722 */
4bb6408c
JS
723 exit(retValue);
724}
725
726// Yield to other processes
727bool wxYield()
728{
729 while (wxTheApp && wxTheApp->Pending())
2d120f83 730 wxTheApp->Dispatch();
518b5d2f
VZ
731
732 // VZ: is it the same as this (taken from old wxExecute)?
733#if 0
734 XtAppProcessEvent((XtAppContext) wxTheApp->GetAppContext(), XtIMAll);
735#endif
736
4bb6408c
JS
737 return TRUE;
738}
739
ee31c392
VZ
740// TODO use XmGetPixmap (?) to get the really standard icons!
741
742#include "wx/generic/info.xpm"
743#include "wx/generic/error.xpm"
744#include "wx/generic/question.xpm"
745#include "wx/generic/warning.xpm"
746
747wxIcon
748wxApp::GetStdIcon(int which) const
749{
750 switch(which)
751 {
752 case wxICON_INFORMATION:
753 return wxIcon(info_xpm);
754
755 case wxICON_QUESTION:
756 return wxIcon(question_xpm);
757
758 case wxICON_EXCLAMATION:
759 return wxIcon(warning_xpm);
760
761 default:
762 wxFAIL_MSG("requested non existent standard icon");
763 // still fall through
764
765 case wxICON_HAND:
766 return wxIcon(error_xpm);
767 }
768}
d391a345
VZ
769
770// ----------------------------------------------------------------------------
771// accessors for C modules
772// ----------------------------------------------------------------------------
773
774extern "C" XtAppContext wxGetAppContext()
775{
776 return (XtAppContext)wxTheApp->GetAppContext();
777}