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