X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cb2713bfa8fc9b8864eb2c0cebde8df2a7654444..b9b7804a435e969fcb48ae8634ecc41f49858d65:/src/mac/carbon/app.cpp diff --git a/src/mac/carbon/app.cpp b/src/mac/carbon/app.cpp index 97c3590a5e..095156baa1 100644 --- a/src/mac/carbon/app.cpp +++ b/src/mac/carbon/app.cpp @@ -31,6 +31,7 @@ #include "wx/module.h" #include "wx/memory.h" #include "wx/tooltip.h" +#include "wx/textctrl.h" #include "wx/menu.h" #if wxUSE_WX_RESOURCES #include "wx/resource.h" @@ -40,7 +41,7 @@ // mac -#ifndef __UNIX__ +#ifndef __DARWIN__ #if __option(profile) #include #endif @@ -52,8 +53,8 @@ #include "wx/mac/macnotfy.h" #if wxUSE_SOCKETS - #ifdef __APPLE__ - #include + #ifdef __DARWIN__ + #include #else #include #include @@ -88,32 +89,46 @@ wxWindow* wxApp::s_captureWindow = NULL ; int wxApp::s_lastMouseDown = 0 ; long wxApp::sm_lastMessageTime = 0; -#ifdef __WXMAC__ - bool wxApp::s_macDefaultEncodingIsPC = true ; bool wxApp::s_macSupportPCMenuShortcuts = true ; long wxApp::s_macAboutMenuItemId = wxID_ABOUT ; wxString wxApp::s_macHelpMenuTitleName = "&Help" ; +#if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340) +pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , long refcon ) +#else pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , unsigned long refcon ) +#endif { wxApp* app = (wxApp*) refcon ; return wxTheApp->MacHandleAEODoc( (AppleEvent*) event , reply) ; } +#if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340) +pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , long refcon ) +#else pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , unsigned long refcon ) +#endif { wxApp* app = (wxApp*) refcon ; return wxTheApp->MacHandleAEOApp( (AppleEvent*) event , reply ) ; } +#if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340) +pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , long refcon ) +#else pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , unsigned long refcon ) +#endif { wxApp* app = (wxApp*) refcon ; return wxTheApp->MacHandleAEPDoc( (AppleEvent*) event , reply ) ; } +#if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340) +pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , long refcon ) +#else pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , unsigned long refcon ) +#endif { wxApp* app = (wxApp*) refcon ; return wxTheApp->MacHandleAEQuit( (AppleEvent*) event , reply) ; @@ -121,6 +136,7 @@ pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , unsigne OSErr wxApp::MacHandleAEODoc(const AppleEvent *event , AppleEvent *reply) { + SysBeep(40) ; ProcessSerialNumber PSN ; PSN.highLongOfPSN = 0 ; PSN.lowLongOfPSN = kCurrentProcess ; @@ -325,7 +341,44 @@ wxString wxMacMakePCStringFromMac( const char * p ) return result ; } -#endif +wxString wxMacMakeStringFromMacString( const char* from , bool mac2pcEncoding ) +{ + if (mac2pcEncoding) + { + return wxMacMakePCStringFromMac( from ) ; + } + else + { + return wxString( from ) ; + } +} + +wxString wxMacMakeStringFromPascal( StringPtr from , bool mac2pcEncoding ) +{ + // this is safe since a pascal string can never be larger than 256 bytes + char s[256] ; + CopyPascalStringToC( from , s ) ; + if (mac2pcEncoding) + { + return wxMacMakePCStringFromMac( s ) ; + } + else + { + return wxString( s ) ; + } +} + +void wxMacStringToPascal( const char * from , StringPtr to , bool pc2macEncoding ) +{ + if (pc2macEncoding) + { + CopyCStringToPascal( wxMacMakeMacStringFromPC( from ) , to ) ; + } + else + { + CopyCStringToPascal( from , to ) ; + } +} bool wxApp::Initialize() { @@ -334,34 +387,36 @@ bool wxApp::Initialize() // Mac-specific UMAInitToolbox( 4 ) ; + SetEventMask( everyEvent ) ; UMAShowWatchCursor() ; -#ifdef __UNIX__ - AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments , AEHandleODoc , +#if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340) + AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments , NewAEEventHandlerUPP(AEHandleODoc) , (long) wxTheApp , FALSE ) ; - AEInstallEventHandler( kCoreEventClass , kAEOpenApplication , AEHandleOApp , + AEInstallEventHandler( kCoreEventClass , kAEOpenApplication , NewAEEventHandlerUPP(AEHandleOApp) , (long) wxTheApp , FALSE ) ; - AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments , AEHandlePDoc , + AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments , NewAEEventHandlerUPP(AEHandlePDoc) , (long) wxTheApp , FALSE ) ; - AEInstallEventHandler( kCoreEventClass , kAEQuitApplication , AEHandleQuit , + AEInstallEventHandler( kCoreEventClass , kAEQuitApplication , NewAEEventHandlerUPP(AEHandleQuit) , (long) wxTheApp , FALSE ) ; #else AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments , NewAEEventHandlerProc(AEHandleODoc) , - (long) wxTheApp , FALSE ) ; + (long) wxTheApp , FALSE ) ; AEInstallEventHandler( kCoreEventClass , kAEOpenApplication , NewAEEventHandlerProc(AEHandleOApp) , - (long) wxTheApp , FALSE ) ; + (long) wxTheApp , FALSE ) ; AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments , NewAEEventHandlerProc(AEHandlePDoc) , - (long) wxTheApp , FALSE ) ; + (long) wxTheApp , FALSE ) ; AEInstallEventHandler( kCoreEventClass , kAEQuitApplication , NewAEEventHandlerProc(AEHandleQuit) , - (long) wxTheApp , FALSE ) ; + (long) wxTheApp , FALSE ) ; #endif -#ifndef __UNIX__ +#ifndef __DARWIN__ // test the minimal configuration necessary + #if !TARGET_CARBON long theSystem ; - long theMachine; + long theMachine; if (Gestalt(gestaltMachineType, &theMachine) != noErr) { @@ -379,7 +434,6 @@ bool wxApp::Initialize() { error = kMacSTROldSystem ; } - #if !TARGET_CARBON else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap) { error = kMacSTRSmallSize; @@ -410,7 +464,7 @@ bool wxApp::Initialize() return FALSE ; } -#ifndef __UNIX__ +#ifndef __DARWIN__ #if __option(profile) ProfilerInit( collectDetailed, bestTimeBase , 20000 , 40 ) ; #endif @@ -418,7 +472,7 @@ bool wxApp::Initialize() // now avoid exceptions thrown for new (bad_alloc) -#ifndef __UNIX__ +#ifndef __DARWIN__ std::__throws_bad_alloc = FALSE ; #endif @@ -442,6 +496,19 @@ bool wxApp::Initialize() wxTheColourDatabase = new wxColourDatabase(wxKEY_STRING); wxTheColourDatabase->Initialize(); +#ifdef __WXDEBUG__ +#if wxUSE_LOG + // flush the logged messages if any and install a 'safer' log target: the + // default one (wxLogGui) can't be used after the resources are freed just + // below and the user suppliedo ne might be even more unsafe (using any + // wxWindows GUI function is unsafe starting from now) + wxLog::DontCreateOnDemand(); + + // this will flush the old messages if any + delete wxLog::SetActiveTarget(new wxLogStderr); +#endif // wxUSE_LOG +#endif + wxInitializeStockLists(); wxInitializeStockObjects(); @@ -514,7 +581,7 @@ void wxApp::CleanUp() wxClassInfo::CleanUpClasses(); -#ifndef __UNIX__ +#ifndef __DARWIN__ #if __option(profile) ProfilerDump( "\papp.prof" ) ; ProfilerTerm() ; @@ -872,11 +939,13 @@ bool wxYield() #endif EventRecord event ; - long sleepTime = 0 ; //::GetCaretTime(); + long sleepTime = 1 ; //::GetCaretTime(); while ( !wxTheApp->IsExiting() && WaitNextEvent(everyEvent, &event,sleepTime, wxApp::s_macCursorRgn)) { wxTheApp->MacHandleOneEvent( &event ); + if ( event.what != kHighLevelEvent ) + SetRectRgn( wxApp::s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ; } wxMacProcessNotifierAndPendingEvents() ; @@ -937,7 +1006,7 @@ void wxApp::MacDoOneEvent() { EventRecord event ; - long sleepTime = ::GetCaretTime(); + long sleepTime = 1 ; // GetCaretTime() / 4 ; if (WaitNextEvent(everyEvent, &event,sleepTime, s_macCursorRgn)) { @@ -953,10 +1022,11 @@ void wxApp::MacDoOneEvent() wxTheApp->ProcessIdle() ; } if ( event.what != kHighLevelEvent ) - SetRectRgn( s_macCursorRgn , event.where.h - 1 , event.where.v - 1, event.where.h + 1 , event.where.v + 1 ) ; + SetRectRgn( s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ; // repeaters + DeletePendingObjects() ; wxMacProcessNotifierAndPendingEvents() ; } @@ -1034,6 +1104,8 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev ) short windowPart = ::FindWindow(ev->where, &window); wxWindow* win = wxFindWinFromMacWindow( window ) ; + if ( wxPendingDelete.Member(win) ) + return ; BitMap screenBits; GetQDGlobalsScreenBits( &screenBits ); @@ -1150,7 +1222,7 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev ) SetOrigin( 0 , 0 ) ; SetPort( port ) ; } - if ( window != frontWindow ) + if ( window != frontWindow && wxTheApp->s_captureWindow == NULL ) { if ( s_macIsInModalLoop ) { @@ -1163,6 +1235,8 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev ) } else { + if ( win ) + win->MacMouseDown( ev , windowPart ) ; UMASelectWindow( window ) ; } } @@ -1407,7 +1481,37 @@ void wxApp::MacHandleKeyDownEvent( EventRecord *ev ) void wxApp::MacHandleKeyUpEvent( EventRecord *ev ) { - // nothing to do + wxToolTip::RemoveToolTips() ; + + UInt32 menuresult = UMAMenuEvent(ev) ; + if ( HiWord( menuresult ) ) + { + } + else + { + short keycode ; + short keychar ; + keychar = short(ev->message & charCodeMask); + keycode = short(ev->message & keyCodeMask) >> 8 ; + + wxWindow* focus = wxWindow::FindFocus() ; + if ( focus ) + { + long keyval = wxMacTranslateKey(keychar, keycode) ; + + wxKeyEvent event(wxEVT_KEY_UP); + event.m_shiftDown = ev->modifiers & shiftKey; + event.m_controlDown = ev->modifiers & controlKey; + event.m_altDown = ev->modifiers & optionKey; + event.m_metaDown = ev->modifiers & cmdKey; + event.m_keyCode = keyval; + event.m_x = ev->where.h; + event.m_y = ev->where.v; + event.m_timeStamp = ev->when; + event.SetEventObject(focus); + bool handled = focus->GetEventHandler()->ProcessEvent( event ) ; + } + } } void wxApp::MacHandleActivateEvent( EventRecord *ev ) @@ -1435,7 +1539,8 @@ void wxApp::MacHandleUpdateEvent( EventRecord *ev ) wxWindow * win = wxFindWinFromMacWindow( window ) ; if ( win ) { - win->MacUpdate( ev ) ; + if ( !wxPendingDelete.Member(win) ) + win->MacUpdate( ev ) ; } else { @@ -1469,7 +1574,11 @@ void wxApp::MacHandleOSEvent( EventRecord *ev ) case suspendResumeMessage : { bool isResuming = ev->message & resumeFlag ; +#if !TARGET_CARBON bool convertClipboard = ev->message & convertClipboardFlag ; +#else + bool convertClipboard = false; +#endif bool doesActivate = UMAGetProcessModeDoesActivateOnFGSwitch() ; if ( isResuming ) {