X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ee658398812ab334b39a2632cd99e2ffe6d4bc79..da2101204027855793c4264388b95a208967ae15:/src/mac/carbon/utils.cpp diff --git a/src/mac/carbon/utils.cpp b/src/mac/carbon/utils.cpp index 83f2258105..1fc365d163 100644 --- a/src/mac/carbon/utils.cpp +++ b/src/mac/carbon/utils.cpp @@ -45,9 +45,9 @@ #include #endif -#include "ATSUnicode.h" -#include "TextCommon.h" -#include "TextEncodingConverter.h" +#include +#include +#include #include "wx/mac/private.h" // includes mac headers @@ -80,8 +80,150 @@ static int DoGetOSVersion(int *majorVsn, int *minorVsn) #endif } + #if wxUSE_BASE +// ---------------------------------------------------------------------------- +// debugging support +// ---------------------------------------------------------------------------- + +#if defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400) + +// MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds... + +#ifndef __MetroNubUtils__ +#include "MetroNubUtils.h" +#endif + +#ifndef __GESTALT__ +#include +#endif + +#if TARGET_API_MAC_CARBON + + #include + + extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr, ProcInfoType procInfo, ...); + + ProcPtr gCallUniversalProc_Proc = NULL; + +#endif + +static MetroNubUserEntryBlock* gMetroNubEntry = NULL; + +static long fRunOnce = false; + +/* --------------------------------------------------------------------------- + IsMetroNubInstalled + --------------------------------------------------------------------------- */ + +Boolean IsMetroNubInstalled() +{ + if (!fRunOnce) + { + long result, value; + + fRunOnce = true; + gMetroNubEntry = NULL; + + if (Gestalt(gestaltSystemVersion, &value) == noErr && value < 0x1000) + { + /* look for MetroNub's Gestalt selector */ + if (Gestalt(kMetroNubUserSignature, &result) == noErr) + { + + #if TARGET_API_MAC_CARBON + if (gCallUniversalProc_Proc == NULL) + { + CFragConnectionID connectionID; + Ptr mainAddress; + Str255 errorString; + ProcPtr symbolAddress; + OSErr err; + CFragSymbolClass symbolClass; + + symbolAddress = NULL; + err = GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch, kFindCFrag, + &connectionID, &mainAddress, errorString); + + if (err != noErr) + { + gCallUniversalProc_Proc = NULL; + goto end; + } + + err = FindSymbol(connectionID, "\pCallUniversalProc", + (Ptr *) &gCallUniversalProc_Proc, &symbolClass); + + if (err != noErr) + { + gCallUniversalProc_Proc = NULL; + goto end; + } + } + #endif + + { + MetroNubUserEntryBlock* block = (MetroNubUserEntryBlock *)result; + + /* make sure the version of the API is compatible */ + if (block->apiLowVersion <= kMetroNubUserAPIVersion && + kMetroNubUserAPIVersion <= block->apiHiVersion) + gMetroNubEntry = block; /* success! */ + } + + } + } + } + +end: + +#if TARGET_API_MAC_CARBON + return (gMetroNubEntry != NULL && gCallUniversalProc_Proc != NULL); +#else + return (gMetroNubEntry != NULL); +#endif +} + +/* --------------------------------------------------------------------------- + IsMWDebuggerRunning [v1 API] + --------------------------------------------------------------------------- */ + +Boolean IsMWDebuggerRunning() +{ + if (IsMetroNubInstalled()) + return CallIsDebuggerRunningProc(gMetroNubEntry->isDebuggerRunning); + else + return false; +} + +/* --------------------------------------------------------------------------- + AmIBeingMWDebugged [v1 API] + --------------------------------------------------------------------------- */ + +Boolean AmIBeingMWDebugged() +{ + if (IsMetroNubInstalled()) + return CallAmIBeingDebuggedProc(gMetroNubEntry->amIBeingDebugged); + else + return false; +} + +extern bool WXDLLEXPORT wxIsDebuggerRunning() +{ + return IsMWDebuggerRunning() && AmIBeingMWDebugged(); +} + +#else + +extern bool WXDLLEXPORT wxIsDebuggerRunning() +{ + return false; +} + +#endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400) + + #ifndef __DARWIN__ // defined in unix/utilsunx.cpp for Mac OS X @@ -198,11 +340,15 @@ long wxGetFreeMemory() void wxUsleep(unsigned long milliseconds) { + // TODO remove if we don't encounter any other problemsy + /* clock_t start = clock() ; do { YieldToAnyThread() ; } while( clock() - start < milliseconds / 1000.0 * CLOCKS_PER_SEC ) ; + */ + wxThread::Sleep( milliseconds ) ; } void wxSleep(int nSecs) @@ -456,7 +602,6 @@ void wxDisplaySizeMM(int *width, int *height) void wxClientDisplayRect(int *x, int *y, int *width, int *height) { -#if TARGET_CARBON Rect r ; GetAvailableWindowPositioningBounds( GetMainDevice() , &r ) ; if ( x ) @@ -467,32 +612,6 @@ void wxClientDisplayRect(int *x, int *y, int *width, int *height) *width = r.right - r.left ; if ( height ) *height = r.bottom - r.top ; -#else - BitMap screenBits; - GetQDGlobalsScreenBits( &screenBits ); - - if (x) *x = 0; - if (y) *y = 0; - - if (width != NULL) { - *width = screenBits.bounds.right - screenBits.bounds.left ; - } - if (height != NULL) { - *height = screenBits.bounds.bottom - screenBits.bounds.top ; - } - - SInt16 mheight ; -#if TARGET_CARBON - GetThemeMenuBarHeight( &mheight ) ; -#else - mheight = LMGetMBarHeight() ; -#endif - if (height != NULL) { - *height -= mheight ; - } - if (y) - *y = mheight ; -#endif } wxWindow* wxFindWindowAtPoint(const wxPoint& pt) @@ -1103,10 +1222,6 @@ wxFontEncoding wxMacGetFontEncFromSystemEnc(wxUint32 encoding) return enc ; } -#endif // wxUSE_BASE - -#if wxUSE_GUI - // // CFStringRefs (Carbon only) @@ -1252,144 +1367,112 @@ void wxMacConvertNewlines10To13( wxChar * data ) #endif // ---------------------------------------------------------------------------- -// debugging support +// Common Event Support // ---------------------------------------------------------------------------- -#if defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400) - -// MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds... - -#ifndef __MetroNubUtils__ -#include "MetroNubUtils.h" -#endif - -#ifndef __GESTALT__ -#include -#endif - -#if TARGET_API_MAC_CARBON - - #include - - extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr, ProcInfoType procInfo, ...); - - ProcPtr gCallUniversalProc_Proc = NULL; - -#endif - -static MetroNubUserEntryBlock* gMetroNubEntry = NULL; - -static long fRunOnce = false; -/* --------------------------------------------------------------------------- - IsMetroNubInstalled - --------------------------------------------------------------------------- */ +extern ProcessSerialNumber gAppProcess ; -Boolean IsMetroNubInstalled() +void wxMacWakeUp() { - if (!fRunOnce) + ProcessSerialNumber psn ; + Boolean isSame ; + psn.highLongOfPSN = 0 ; + psn.lowLongOfPSN = kCurrentProcess ; + SameProcess( &gAppProcess , &psn , &isSame ) ; + if ( isSame ) { - long result, value; - - fRunOnce = true; - gMetroNubEntry = NULL; - - if (Gestalt(gestaltSystemVersion, &value) == noErr && value < 0x1000) +#if TARGET_CARBON + EventRef dummyEvent ; + OSStatus err = MacCreateEvent(nil, 'WXMC', 'WXMC', GetCurrentEventTime(), + kEventAttributeNone, &dummyEvent); + if (err == noErr) { - /* look for MetroNub's Gestalt selector */ - if (Gestalt(kMetroNubUserSignature, &result) == noErr) - { - - #if TARGET_API_MAC_CARBON - if (gCallUniversalProc_Proc == NULL) - { - CFragConnectionID connectionID; - Ptr mainAddress; - Str255 errorString; - ProcPtr symbolAddress; - OSErr err; - CFragSymbolClass symbolClass; - - symbolAddress = NULL; - err = GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch, kFindCFrag, - &connectionID, &mainAddress, errorString); - - if (err != noErr) - { - gCallUniversalProc_Proc = NULL; - goto end; - } + err = PostEventToQueue(GetMainEventQueue(), dummyEvent, + kEventPriorityHigh); + } +#else + PostEvent( nullEvent , 0 ) ; +#endif + } + else + { + WakeUpProcess( &gAppProcess ) ; + } +} - err = FindSymbol(connectionID, "\pCallUniversalProc", - (Ptr *) &gCallUniversalProc_Proc, &symbolClass); +#endif // wxUSE_BASE - if (err != noErr) - { - gCallUniversalProc_Proc = NULL; - goto end; - } - } - #endif +#if wxUSE_GUI - { - MetroNubUserEntryBlock* block = (MetroNubUserEntryBlock *)result; - /* make sure the version of the API is compatible */ - if (block->apiLowVersion <= kMetroNubUserAPIVersion && - kMetroNubUserAPIVersion <= block->apiHiVersion) - gMetroNubEntry = block; /* success! */ - } +// ---------------------------------------------------------------------------- +// Carbon Event Support +// ---------------------------------------------------------------------------- - } - } - } -end: +OSStatus wxMacCarbonEvent::GetParameter(EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData) +{ + return ::GetEventParameter( m_eventRef , inName , inDesiredType , NULL , inBufferSize , NULL , outData ) ; +} -#if TARGET_API_MAC_CARBON - return (gMetroNubEntry != NULL && gCallUniversalProc_Proc != NULL); -#else - return (gMetroNubEntry != NULL); -#endif +OSStatus wxMacCarbonEvent::SetParameter(EventParamName inName, EventParamType inType, UInt32 inBufferSize, const void * inData) +{ + return ::SetEventParameter( m_eventRef , inName , inType , inBufferSize , inData ) ; } -/* --------------------------------------------------------------------------- - IsMWDebuggerRunning [v1 API] - --------------------------------------------------------------------------- */ +// ---------------------------------------------------------------------------- +// Control Access Support +// ---------------------------------------------------------------------------- -Boolean IsMWDebuggerRunning() +OSStatus wxMacControl::GetData(ControlPartCode inPartCode , ResType inTag , Size inBufferSize , void * inOutBuffer , Size * outActualSize ) { - if (IsMetroNubInstalled()) - return CallIsDebuggerRunningProc(gMetroNubEntry->isDebuggerRunning); - else - return false; + return ::GetControlData( m_controlRef , inPartCode , inTag , inBufferSize , inOutBuffer , outActualSize ) ; } -/* --------------------------------------------------------------------------- - AmIBeingMWDebugged [v1 API] - --------------------------------------------------------------------------- */ - -Boolean AmIBeingMWDebugged() +OSStatus wxMacControl::GetDataSize(ControlPartCode inPartCode , ResType inTag , Size * outActualSize ) { - if (IsMetroNubInstalled()) - return CallAmIBeingDebuggedProc(gMetroNubEntry->amIBeingDebugged); - else - return false; + return ::GetControlDataSize( m_controlRef , inPartCode , inTag , outActualSize ) ; } -extern bool WXDLLEXPORT wxIsDebuggerRunning() +OSStatus wxMacControl::SetData(ControlPartCode inPartCode , ResType inTag , Size inSize , const void * inData) { - return IsMWDebuggerRunning() && AmIBeingMWDebugged(); + return ::SetControlData( m_controlRef , inPartCode , inTag , inSize , inData ) ; } +OSStatus wxMacControl::SendEvent( EventRef event , OptionBits inOptions ) +{ +#if TARGET_API_MAC_OSX + return SendEventToEventTargetWithOptions( event, + HIObjectGetEventTarget( (HIObjectRef) m_controlRef ), inOptions ); #else + #pragma unused(inOptions) + return SendEventToEventTarget(event,GetControlEventTarget( m_controlRef ) ) ; +#endif +} -extern bool WXDLLEXPORT wxIsDebuggerRunning() +OSStatus wxMacControl::SendHICommand( HICommand &command , OptionBits inOptions ) { - return false; + wxMacCarbonEvent event( kEventClassCommand , kEventCommandProcess ) ; + event.SetParameter(kEventParamDirectObject,command) ; + return SendEvent( event , inOptions ) ; } -#endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400) +OSStatus wxMacControl::SendHICommand( UInt32 commandID , OptionBits inOptions ) +{ + HICommand command ; + memset( &command, 0 , sizeof(command) ) ; + command.commandID = commandID ; + return SendHICommand( command , inOptions ) ; +} + +void wxMacControl::Flash( ControlPartCode part , UInt32 ticks ) +{ + HiliteControl( m_controlRef , part ) ; + unsigned long finalTicks ; + Delay( ticks , &finalTicks ) ; + HiliteControl( m_controlRef , kControlNoPart ) ; +} #endif // wxUSE_GUI