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