]> git.saurik.com Git - wxWidgets.git/blame - src/motif/app.cpp
some conflicts resolved
[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
MB
348#if 1
349 // It seemed before that this hack was redundant and
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 }
364c7f3c 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
486// Send idle event to all top-level windows
487bool wxApp::SendIdleEvents()
488{
489 bool needMore = FALSE;
e146b8c8
VZ
490
491 wxWindowList::Node* node = wxTopLevelWindows.GetFirst();
2d120f83
JS
492 while (node)
493 {
e146b8c8 494 wxWindow* win = node->GetData();
2d120f83 495 if (SendIdleEvents(win))
4bb6408c 496 needMore = TRUE;
e146b8c8 497 node = node->GetNext();
2d120f83 498 }
e146b8c8 499
4bb6408c
JS
500 return needMore;
501}
502
503// Send idle event to window and all subwindows
504bool wxApp::SendIdleEvents(wxWindow* win)
505{
506 bool needMore = FALSE;
afb74891 507
2d120f83
JS
508 wxIdleEvent event;
509 event.SetEventObject(win);
510 win->ProcessEvent(event);
afb74891 511
4bb6408c
JS
512 if (event.MoreRequested())
513 needMore = TRUE;
afb74891 514
2d120f83
JS
515 wxNode* node = win->GetChildren().First();
516 while (node)
517 {
518 wxWindow* win = (wxWindow*) node->Data();
519 if (SendIdleEvents(win))
4bb6408c 520 needMore = TRUE;
afb74891 521
2d120f83
JS
522 node = node->Next();
523 }
4bb6408c
JS
524 return needMore ;
525}
526
527void wxApp::DeletePendingObjects()
528{
529 wxNode *node = wxPendingDelete.First();
530 while (node)
531 {
2d120f83 532 wxObject *obj = (wxObject *)node->Data();
afb74891 533
2d120f83 534 delete obj;
afb74891 535
2d120f83
JS
536 if (wxPendingDelete.Member(obj))
537 delete node;
afb74891 538
2d120f83
JS
539 // Deleting one object may have deleted other pending
540 // objects, so start from beginning of list again.
541 node = wxPendingDelete.First();
4bb6408c
JS
542 }
543}
544
4bb6408c
JS
545// Create an application context
546bool wxApp::OnInitGui()
547{
548 XtToolkitInitialize() ;
549 wxTheApp->m_appContext = (WXAppContext) XtCreateApplicationContext() ;
550 Display *dpy = XtOpenDisplay((XtAppContext) wxTheApp->m_appContext,(String)NULL,NULL,
9c6e1335 551 (const char*) wxTheApp->GetClassName(), NULL, 0,
4bb6408c 552# if XtSpecificationRelease < 5
9c6e1335 553 (Cardinal*) &argc,
4bb6408c 554# else
9c6e1335 555 &argc,
4bb6408c 556# endif
9c6e1335
VZ
557 argv);
558
4bb6408c 559 if (!dpy) {
7bcb11d3 560 wxString className(wxTheApp->GetClassName());
9c6e1335 561 wxLogError(_("wxWindows could not open display for '%s': exiting."),
7bcb11d3 562 (const char*) className);
2d120f83 563 exit(-1);
4bb6408c 564 }
47bc1060 565 m_initialDisplay = (WXDisplay*) dpy;
afb74891 566
4bb6408c 567 wxTheApp->m_topLevelWidget = (WXWidget) XtAppCreateShell((String)NULL, (const char*) wxTheApp->GetClassName(),
2d120f83
JS
568 applicationShellWidgetClass,dpy,
569 NULL,0) ;
afb74891 570
4bb6408c
JS
571 // Add general resize proc
572 XtActionsRec rec;
573 rec.string = "resize";
574 rec.proc = (XtActionProc)wxWidgetResizeProc;
575 XtAppAddActions((XtAppContext) wxTheApp->m_appContext, &rec, 1);
afb74891 576
4bb6408c
JS
577 GetMainColormap(dpy);
578 m_maxRequestSize = XMaxRequestSize((Display*) dpy);
afb74891 579
4bb6408c
JS
580 return TRUE;
581}
582
583WXColormap wxApp::GetMainColormap(WXDisplay* display)
584{
585 if (!display) /* Must be called first with non-NULL display */
2d120f83 586 return m_mainColormap;
a91b47e8
JS
587
588 int defaultScreen = DefaultScreen((Display*) display);
589 Screen* screen = XScreenOfDisplay((Display*) display, defaultScreen);
afb74891 590
a91b47e8 591 Colormap c = DefaultColormapOfScreen(screen);
afb74891 592
4bb6408c 593 if (!m_mainColormap)
2d120f83 594 m_mainColormap = (WXColormap) c;
afb74891 595
4bb6408c
JS
596 return (WXColormap) c;
597}
598
8aa04e8b
JS
599// Returns TRUE if an accelerator has been processed
600bool wxApp::CheckForAccelerator(WXEvent* event)
601{
602 XEvent* xEvent = (XEvent*) event;
603 if (xEvent->xany.type == KeyPress)
604 {
605 // Find a wxWindow for this window
606 // TODO: should get display for the window, not the current display
607 Widget widget = XtWindowToWidget((Display*) wxGetDisplay(), xEvent->xany.window);
608 wxWindow* win = NULL;
afb74891 609
8aa04e8b
JS
610 // Find the first wxWindow that corresponds to this event window
611 while (widget && !(win = wxGetWindowFromTable(widget)))
612 widget = XtParent(widget);
afb74891 613
8aa04e8b
JS
614 if (!widget || !win)
615 return FALSE;
afb74891 616
8aa04e8b
JS
617 wxKeyEvent keyEvent(wxEVT_CHAR);
618 wxTranslateKeyEvent(keyEvent, win, (Widget) 0, xEvent);
afb74891 619
8aa04e8b
JS
620 // Now we have a wxKeyEvent and we have a wxWindow.
621 // Go up the hierarchy until we find a matching accelerator,
622 // or we get to the top.
623 while (win)
624 {
625 if (win->ProcessAccelerator(keyEvent))
626 return TRUE;
627 win = win->GetParent();
628 }
629 return FALSE;
630 }
631 return FALSE;
632}
633
ee31c392
VZ
634bool wxApp::CheckForKeyDown(WXEvent* event)
635{
636 XEvent* xEvent = (XEvent*) event;
ee31c392
VZ
637 if (xEvent->xany.type == KeyPress)
638 {
3d9431bf
MB
639 Widget widget = XtWindowToWidget((Display*) wxGetDisplay(),
640 xEvent->xany.window);
641 wxWindow* win = NULL;
642
643 // Find the first wxWindow that corresponds to this event window
644 while (widget && !(win = wxGetWindowFromTable(widget)))
645 widget = XtParent(widget);
646
647 if (!widget || !win)
648 return FALSE;
649
650 wxKeyEvent keyEvent(wxEVT_KEY_DOWN);
651 wxTranslateKeyEvent(keyEvent, win, (Widget) 0, xEvent);
652
653 return win->ProcessEvent( keyEvent );
654 }
655
656 return FALSE;
657}
658
659bool wxApp::CheckForKeyUp(WXEvent* event)
660{
661 XEvent* xEvent = (XEvent*) event;
662 if (xEvent->xany.type == KeyRelease)
663 {
664 Widget widget = XtWindowToWidget((Display*) wxGetDisplay(),
665 xEvent->xany.window);
666 wxWindow* win = NULL;
ee31c392 667
3d9431bf
MB
668 // Find the first wxWindow that corresponds to this event window
669 while (widget && !(win = wxGetWindowFromTable(widget)))
670 widget = XtParent(widget);
ee31c392 671
3d9431bf
MB
672 if (!widget || !win)
673 return FALSE;
ee31c392 674
3d9431bf
MB
675 wxKeyEvent keyEvent(wxEVT_KEY_UP);
676 wxTranslateKeyEvent(keyEvent, win, (Widget) 0, xEvent);
ee31c392 677
3d9431bf 678 return win->ProcessEvent( keyEvent );
ee31c392 679 }
ee31c392
VZ
680
681 return FALSE;
682}
683
4bb6408c
JS
684void wxExit()
685{
686 int retValue = 0;
687 if (wxTheApp)
2d120f83 688 retValue = wxTheApp->OnExit();
afb74891 689
4bb6408c
JS
690 wxApp::CleanUp();
691 /*
2d120f83
JS
692 * Exit in some platform-specific way. Not recommended that the app calls this:
693 * only for emergencies.
694 */
4bb6408c
JS
695 exit(retValue);
696}
697
698// Yield to other processes
699bool wxYield()
700{
701 while (wxTheApp && wxTheApp->Pending())
2d120f83 702 wxTheApp->Dispatch();
518b5d2f
VZ
703
704 // VZ: is it the same as this (taken from old wxExecute)?
705#if 0
706 XtAppProcessEvent((XtAppContext) wxTheApp->GetAppContext(), XtIMAll);
707#endif
708
4bb6408c
JS
709 return TRUE;
710}
711
ee31c392
VZ
712// TODO use XmGetPixmap (?) to get the really standard icons!
713
714#include "wx/generic/info.xpm"
715#include "wx/generic/error.xpm"
716#include "wx/generic/question.xpm"
717#include "wx/generic/warning.xpm"
718
719wxIcon
720wxApp::GetStdIcon(int which) const
721{
722 switch(which)
723 {
724 case wxICON_INFORMATION:
725 return wxIcon(info_xpm);
726
727 case wxICON_QUESTION:
728 return wxIcon(question_xpm);
729
730 case wxICON_EXCLAMATION:
731 return wxIcon(warning_xpm);
732
733 default:
734 wxFAIL_MSG("requested non existent standard icon");
735 // still fall through
736
737 case wxICON_HAND:
738 return wxIcon(error_xpm);
739 }
740}
d391a345
VZ
741
742// ----------------------------------------------------------------------------
743// accessors for C modules
744// ----------------------------------------------------------------------------
745
746extern "C" XtAppContext wxGetAppContext()
747{
748 return (XtAppContext)wxTheApp->GetAppContext();
749}