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