X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2f1ae4143271ae63a17e052a1a471d16e9cd8c44..22e0ea84c89c61cceb3deb2b62145afa047a0dff:/src/mac/app.cpp diff --git a/src/mac/app.cpp b/src/mac/app.cpp index a11ff6db93..97c3590a5e 100644 --- a/src/mac/app.cpp +++ b/src/mac/app.cpp @@ -13,6 +13,7 @@ #pragma implementation "app.h" #endif +#include "wx/window.h" #include "wx/frame.h" #include "wx/app.h" #include "wx/utils.h" @@ -20,6 +21,7 @@ #include "wx/pen.h" #include "wx/brush.h" #include "wx/cursor.h" +#include "wx/intl.h" #include "wx/icon.h" #include "wx/palette.h" #include "wx/dc.h" @@ -29,6 +31,7 @@ #include "wx/module.h" #include "wx/memory.h" #include "wx/tooltip.h" +#include "wx/menu.h" #if wxUSE_WX_RESOURCES #include "wx/resource.h" #endif @@ -37,18 +40,24 @@ // mac -#if __option(profile) +#ifndef __UNIX__ + #if __option(profile) #include + #endif #endif #include "apprsrc.h" -#include -#include +#include "wx/mac/uma.h" +#include "wx/mac/macnotfy.h" #if wxUSE_SOCKETS -#include -#include + #ifdef __APPLE__ + #include + #else + #include + #include + #endif #endif extern char *wxBuffer; @@ -89,28 +98,28 @@ wxString wxApp::s_macHelpMenuTitleName = "&Help" ; pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , unsigned long refcon ) { wxApp* app = (wxApp*) refcon ; - return wxTheApp->MacHandleAEODoc( event , reply) ; + return wxTheApp->MacHandleAEODoc( (AppleEvent*) event , reply) ; } pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , unsigned long refcon ) { wxApp* app = (wxApp*) refcon ; - return wxTheApp->MacHandleAEOApp( event , reply ) ; + return wxTheApp->MacHandleAEOApp( (AppleEvent*) event , reply ) ; } pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , unsigned long refcon ) { wxApp* app = (wxApp*) refcon ; - return wxTheApp->MacHandleAEPDoc( event , reply ) ; + return wxTheApp->MacHandleAEPDoc( (AppleEvent*) event , reply ) ; } pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , unsigned long refcon ) { wxApp* app = (wxApp*) refcon ; - return wxTheApp->MacHandleAEQuit( event , reply) ; + return wxTheApp->MacHandleAEQuit( (AppleEvent*) event , reply) ; } -OSErr wxApp::MacHandleAEODoc(AppleEvent *event , AppleEvent *reply) +OSErr wxApp::MacHandleAEODoc(const AppleEvent *event , AppleEvent *reply) { ProcessSerialNumber PSN ; PSN.highLongOfPSN = 0 ; @@ -119,17 +128,17 @@ OSErr wxApp::MacHandleAEODoc(AppleEvent *event , AppleEvent *reply) return noErr ; } -OSErr wxApp::MacHandleAEPDoc(AppleEvent *event , AppleEvent *reply) +OSErr wxApp::MacHandleAEPDoc(const AppleEvent *event , AppleEvent *reply) { return noErr ; } -OSErr wxApp::MacHandleAEOApp(AppleEvent *event , AppleEvent *reply) +OSErr wxApp::MacHandleAEOApp(const AppleEvent *event , AppleEvent *reply) { return noErr ; } -OSErr wxApp::MacHandleAEQuit(AppleEvent *event , AppleEvent *reply) +OSErr wxApp::MacHandleAEQuit(const AppleEvent *event , AppleEvent *reply) { wxWindow* win = GetTopWindow() ; if ( win ) @@ -327,12 +336,28 @@ bool wxApp::Initialize() UMAInitToolbox( 4 ) ; UMAShowWatchCursor() ; - AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments , NewAEEventHandlerProc(AEHandleODoc) , (long) wxTheApp , FALSE ) ; - AEInstallEventHandler( kCoreEventClass , kAEOpenApplication , NewAEEventHandlerProc(AEHandleOApp) , (long) wxTheApp , FALSE ) ; - AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments , NewAEEventHandlerProc(AEHandlePDoc) , (long) wxTheApp , FALSE ) ; - AEInstallEventHandler( kCoreEventClass , kAEQuitApplication , NewAEEventHandlerProc(AEHandleQuit) , (long) wxTheApp , FALSE ) ; +#ifdef __UNIX__ + AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments , AEHandleODoc , + (long) wxTheApp , FALSE ) ; + AEInstallEventHandler( kCoreEventClass , kAEOpenApplication , AEHandleOApp , + (long) wxTheApp , FALSE ) ; + AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments , AEHandlePDoc , + (long) wxTheApp , FALSE ) ; + AEInstallEventHandler( kCoreEventClass , kAEQuitApplication , AEHandleQuit , + (long) wxTheApp , FALSE ) ; +#else + AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments , NewAEEventHandlerProc(AEHandleODoc) , + (long) wxTheApp , FALSE ) ; + AEInstallEventHandler( kCoreEventClass , kAEOpenApplication , NewAEEventHandlerProc(AEHandleOApp) , + (long) wxTheApp , FALSE ) ; + AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments , NewAEEventHandlerProc(AEHandlePDoc) , + (long) wxTheApp , FALSE ) ; + AEInstallEventHandler( kCoreEventClass , kAEQuitApplication , NewAEEventHandlerProc(AEHandleQuit) , + (long) wxTheApp , FALSE ) ; +#endif +#ifndef __UNIX__ // test the minimal configuration necessary long theSystem ; @@ -369,6 +394,7 @@ bool wxApp::Initialize() } } */ +#endif // if we encountered any problems so far, give the error code and exit immediately @@ -384,13 +410,17 @@ bool wxApp::Initialize() return FALSE ; } -#if __option(profile) +#ifndef __UNIX__ + #if __option(profile) ProfilerInit( collectDetailed, bestTimeBase , 20000 , 40 ) ; + #endif #endif // now avoid exceptions thrown for new (bad_alloc) +#ifndef __UNIX__ std::__throws_bad_alloc = FALSE ; +#endif s_macCursorRgn = ::NewRgn() ; @@ -422,8 +452,9 @@ bool wxApp::Initialize() wxBitmap::InitStandardHandlers(); wxModule::RegisterModules(); - if (!wxModule::InitializeModules()) + if (!wxModule::InitializeModules()) { return FALSE; + } wxWinMacWindowList = new wxList(wxKEY_INTEGER); wxWinMacControlList = new wxList(wxKEY_INTEGER); @@ -483,9 +514,11 @@ void wxApp::CleanUp() wxClassInfo::CleanUpClasses(); -#if __option(profile) - ProfilerDump( "\papp.prof" ) ; - ProfilerTerm() ; +#ifndef __UNIX__ + #if __option(profile) + ProfilerDump( "\papp.prof" ) ; + ProfilerTerm() ; + #endif #endif delete wxTheApp; @@ -510,6 +543,7 @@ void wxApp::CleanUp() delete wxLog::SetActiveTarget(NULL); #endif // wxUSE_LOG + UMACleanupToolbox() ; if (s_macCursorRgn) ::DisposeRgn(s_macCursorRgn); @@ -531,8 +565,9 @@ int wxEntry( int argc, char *argv[] , bool enterLoop ) wxDebugContext::SetCheckpoint(); #endif #endif - if (!wxApp::Initialize()) + if (!wxApp::Initialize()) { return 0; + } // create the application object or ensure that one already exists if (!wxTheApp) { @@ -600,7 +635,7 @@ int wxEntry( int argc, char *argv[] , bool enterLoop ) wxApp::CleanUp(); return retValue; -}; +} // Static member initialization wxAppInitializerFunction wxAppBase::m_appInitFn = (wxAppInitializerFunction) NULL; @@ -820,12 +855,22 @@ void wxCYield() } // Yield to other processes + +static bool gs_inYield = FALSE; + bool wxYield() { +#ifdef __WXDEBUG__ + if (gs_inYield) + wxFAIL_MSG( wxT("wxYield called recursively" ) ); +#endif + + gs_inYield = TRUE; + #if wxUSE_THREADS - YieldToAnyThread() ; + YieldToAnyThread() ; #endif - EventRecord event ; + EventRecord event ; long sleepTime = 0 ; //::GetCaretTime(); @@ -835,7 +880,19 @@ bool wxYield() } wxMacProcessNotifierAndPendingEvents() ; - return TRUE; + + gs_inYield = FALSE; + + return TRUE; +} + +// Yield to incoming messages; but fail silently if recursion is detected. +bool wxYieldIfNeeded() +{ + if (gs_inYield) + return FALSE; + + return wxYield(); } // platform specifics @@ -1037,6 +1094,7 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev ) s_lastMouseDown = 0; break; case inGrow: + { int growResult = GrowWindow(window , ev->where, &screenBits.bounds); if (growResult != 0) { @@ -1044,16 +1102,19 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev ) int newHeight = HiWord(growResult); int oldWidth, oldHeight; - win->GetSize(&oldWidth, &oldHeight); - if (newWidth == 0) - newWidth = oldWidth; - if (newHeight == 0) - newHeight = oldHeight; if (win) + { + win->GetSize(&oldWidth, &oldHeight); + if (newWidth == 0) + newWidth = oldWidth; + if (newHeight == 0) + newHeight = oldHeight; win->SetSize( -1, -1, newWidth, newHeight, wxSIZE_USE_EXISTING); + } } s_lastMouseDown = 0; + } break; case inZoomIn: case inZoomOut: @@ -1253,7 +1314,10 @@ void wxApp::MacHandleKeyDownEvent( EventRecord *ev ) UInt32 menuresult = UMAMenuEvent(ev) ; if ( HiWord( menuresult ) ) + { + if ( !s_macIsInModalLoop ) MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) ) ; + } else { short keycode ; @@ -1373,6 +1437,14 @@ void wxApp::MacHandleUpdateEvent( EventRecord *ev ) { win->MacUpdate( ev ) ; } + else + { + // since there is no way of telling this foreign window to update itself + // we have to invalidate the update region otherwise we keep getting the same + // event over and over again + BeginUpdate( window ) ; + EndUpdate( window ) ; + } } void wxApp::MacHandleDiskEvent( EventRecord *ev ) @@ -1450,7 +1522,8 @@ void wxApp::MacHandleOSEvent( EventRecord *ev ) wxWindow* currentMouseWindow = NULL ; - MacGetWindowFromPoint( wxPoint( ev->where.h , ev->where.v ) , ¤tMouseWindow ) ; + wxWindow::MacGetWindowFromPoint( wxPoint( ev->where.h , ev->where.v ) , + ¤tMouseWindow ) ; if ( currentMouseWindow != wxWindow::s_lastMouseWindow ) { @@ -1490,9 +1563,12 @@ void wxApp::MacHandleOSEvent( EventRecord *ev ) switch (windowPart) { + // fixes for setting the cursor back from dominic mazzoni case inMenuBar : + UMAShowArrowCursor(); break ; case inSysWindow : + UMAShowArrowCursor(); break ; default: { @@ -1502,6 +1578,9 @@ void wxApp::MacHandleOSEvent( EventRecord *ev ) wxWindow* win = wxFindWinFromMacWindow( window ) ; if ( win ) win->MacMouseMoved( ev , windowPart ) ; + else + UMAShowArrowCursor(); + } break; }