X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f97c985452b20a8c2f0bbfb1d0275298bf09fb45..e23d0e958e1776cf9e7a8c61a41dbf57e16b4b60:/src/motif/app.cpp diff --git a/src/motif/app.cpp b/src/motif/app.cpp index df82c80919..79e667aa01 100644 --- a/src/motif/app.cpp +++ b/src/motif/app.cpp @@ -33,10 +33,6 @@ #include "wx/resource.h" #endif -#if wxUSE_POSTSCRIPT -#include "wx/postscrp.h" -#endif - #include #include #include @@ -71,7 +67,7 @@ bool wxApp::Initialize() wxBuffer = new char[BUFSIZ + 512]; #endif -#if (WXDEBUG && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT +#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT streambuf* sBuf = new wxDebugStreamBuf; ostream* oStr = new ostream(sBuf) ; @@ -83,6 +79,8 @@ bool wxApp::Initialize() wxTheColourDatabase = new wxColourDatabase(wxKEY_STRING); wxTheColourDatabase->Initialize(); + + wxInitializeStockLists(); wxInitializeStockObjects(); #if wxUSE_WX_RESOURCES @@ -91,9 +89,11 @@ bool wxApp::Initialize() // For PostScript printing #if wxUSE_POSTSCRIPT +/* Done using wxModule now wxInitializePrintSetupData(); wxThePrintPaperDatabase = new wxPrintPaperDatabase; wxThePrintPaperDatabase->CreateDatabase(); +*/ #endif wxBitmap::InitStandardHandlers(); @@ -137,9 +137,11 @@ void wxApp::CleanUp() wxTheColourDatabase = NULL; #if wxUSE_POSTSCRIPT +/* Done using wxModule now wxInitializePrintSetupData(FALSE); delete wxThePrintPaperDatabase; wxThePrintPaperDatabase = NULL; +*/ #endif wxBitmap::CleanUpHandlers(); @@ -195,6 +197,14 @@ int wxEntry( int argc, char *argv[] ) if (wxTheApp->Initialized()) retValue = wxTheApp->OnRun(); + // flush the logged messages if any + wxLog *pLog = wxLog::GetActiveTarget(); + if ( pLog != NULL && pLog->HasPendingMessages() ) + pLog->Flush(); + + delete wxLog::SetActiveTarget(new wxLogStderr); // So dialog boxes aren't used + // for further messages + if (wxTheApp->GetTopWindow()) { delete wxTheApp->GetTopWindow(); @@ -204,13 +214,14 @@ int wxEntry( int argc, char *argv[] ) wxTheApp->DeletePendingObjects(); wxTheApp->OnExit(); + wxApp::CleanUp(); delete wxTheApp; wxTheApp = NULL; -#if (WXDEBUG && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT +#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT // At this point we want to check if there are any memory // blocks that aren't part of the wxDebugContext itself, // as a special case. Then when dumping we need to ignore @@ -247,6 +258,7 @@ wxApp::wxApp() m_appContext = (WXAppContext) NULL; m_topLevelWidget = (WXWidget) NULL; m_maxRequestSize = 0; + m_initialDisplay = (WXDisplay*) 0; } bool wxApp::Initialized() @@ -278,34 +290,53 @@ int wxApp::MainLoop() while (m_keepGoing) { XtAppNextEvent( (XtAppContext) wxTheApp->GetAppContext(), &event); - if(event.type == PropertyNotify) - { - HandlePropertyChange((WXEvent*) &event); - } else - { - // Terry Gitnick - 1/21/98 - /* if resize event, don't resize until the last resize event for this - window is recieved. Prevents flicker as windows are resized. */ - if (event.type == ResizeRequest) - { - Display *disp = XtDisplay((Widget) wxTheApp->GetTopLevelWidget()); - Window win = event.xany.window; - XEvent report; + + ProcessXEvent((WXEvent*) & event); + ProcessIdle(); + } + + return 0; +} + +// Processes an X event. +void wxApp::ProcessXEvent(WXEvent* _event) +{ + XEvent* event = (XEvent*) _event; + + if ((event->type == KeyPress) && CheckForAccelerator(_event)) + { + // Do nothing! We intercepted and processed the event as an accelerator. + return; + } + else if (event->type == PropertyNotify) + { + HandlePropertyChange(_event); + return; + } + else if (event->type == ResizeRequest) + { + /* Terry Gitnick - 1/21/98 + * If resize event, don't resize until the last resize event for this + * window is recieved. Prevents flicker as windows are resized. + */ + + Display *disp = XtDisplay((Widget) wxTheApp->GetTopLevelWidget()); + Window win = event->xany.window; + XEvent report; - // to avoid flicker - report = event; - while( XCheckTypedWindowEvent (disp, win, ResizeRequest, &report)); - } + // to avoid flicker + report = * event; + while( XCheckTypedWindowEvent (disp, win, ResizeRequest, &report)); + // TODO: when implementing refresh optimization, we can use // XtAddExposureToRegion to expand the window's paint region. - XtDispatchEvent(&event); - - DeletePendingObjects(); - } + XtDispatchEvent(event); + } + else + { + XtDispatchEvent(event); } - - return 0; } // Returns TRUE if more time is needed. @@ -327,13 +358,20 @@ void wxApp::ExitMainLoop() bool wxApp::Pending() { XFlush(XtDisplay( (Widget) wxTheApp->GetTopLevelWidget() )); - return (XtAppPending( (XtAppContext) wxTheApp->GetAppContext() ) != 0) ; + + // Fix by Doug from STI, to prevent a stall if non-X event + // is found. + return ((XtAppPending( (XtAppContext) GetAppContext() ) & XtIMXEvent) != 0) ; } // Dispatch a message. void wxApp::Dispatch() { - XtAppProcessEvent( (XtAppContext) wxTheApp->GetAppContext(), XtIMAll); +// XtAppProcessEvent( (XtAppContext) wxTheApp->GetAppContext(), XtIMAll); + + XEvent event; + XtAppNextEvent((XtAppContext) GetAppContext(), &event); + ProcessXEvent((WXEvent*) & event); } // This should be redefined in a derived class for @@ -460,6 +498,8 @@ bool wxApp::OnInitGui() cerr << "wxWindows could not open display for " << wxTheApp->GetClassName() << ": exiting.\n"; exit(-1); } + m_initialDisplay = (WXDisplay*) dpy; + wxTheApp->m_topLevelWidget = (WXWidget) XtAppCreateShell((String)NULL, (const char*) wxTheApp->GetClassName(), applicationShellWidgetClass,dpy, NULL,0) ; @@ -491,6 +531,41 @@ WXColormap wxApp::GetMainColormap(WXDisplay* display) return (WXColormap) c; } +// Returns TRUE if an accelerator has been processed +bool wxApp::CheckForAccelerator(WXEvent* event) +{ + XEvent* xEvent = (XEvent*) event; + if (xEvent->xany.type == KeyPress) + { + // Find a wxWindow for this window + // TODO: should get display for the window, not the current display + Widget widget = XtWindowToWidget((Display*) wxGetDisplay(), xEvent->xany.window); + wxWindow* win = NULL; + + // Find the first wxWindow that corresponds to this event window + while (widget && !(win = wxGetWindowFromTable(widget))) + widget = XtParent(widget); + + if (!widget || !win) + return FALSE; + + wxKeyEvent keyEvent(wxEVT_CHAR); + wxTranslateKeyEvent(keyEvent, win, (Widget) 0, xEvent); + + // Now we have a wxKeyEvent and we have a wxWindow. + // Go up the hierarchy until we find a matching accelerator, + // or we get to the top. + while (win) + { + if (win->ProcessAccelerator(keyEvent)) + return TRUE; + win = win->GetParent(); + } + return FALSE; + } + return FALSE; +} + void wxExit() { int retValue = 0;