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