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