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