]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/utils.cpp
removed commented out code
[wxWidgets.git] / src / mac / carbon / utils.cpp
index c2f1be7ea19fb143ec6a9cc57041dd0fa9bd6937..13a54704edfdb60568c03c051f56814df8130e06 100644 (file)
 #include <Sound.h>
 #endif
 
+#if TARGET_API_MAC_OSX
+#include <CoreServices/CoreServices.h>
+#else
+#include <DriverServices.h>
+#include <Multiprocessing.h>
+#endif
+
 #include <ATSUnicode.h>
 #include <TextCommon.h>
 #include <TextEncodingConverter.h>
@@ -80,8 +87,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 <Gestalt.h>
+#endif
+
+#if TARGET_API_MAC_CARBON
+
+    #include <CodeFragments.h>
+
+    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
 
@@ -196,24 +345,27 @@ long wxGetFreeMemory()
     return FreeMem() ;
 }
 
-void wxUsleep(unsigned long milliseconds)
+#ifndef __DARWIN__
+
+void wxMicroSleep(unsigned long microseconds)
 {
-    // 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 ) ;
+       AbsoluteTime wakeup = AddDurationToAbsolute( microseconds * durationMicrosecond , UpTime());
+       MPDelayUntil( & wakeup);
+}
+
+void wxMilliSleep(unsigned long milliseconds)
+{
+       AbsoluteTime wakeup = AddDurationToAbsolute( milliseconds, UpTime());
+       MPDelayUntil( & wakeup);
 }
 
 void wxSleep(int nSecs)
 {
-    wxUsleep(1000*nSecs);
+    wxMilliSleep(1000*nSecs);
 }
 
+#endif
+
 // Consume all events until no more left
 void wxFlushEvents()
 {
@@ -1080,10 +1232,6 @@ wxFontEncoding wxMacGetFontEncFromSystemEnc(wxUint32 encoding)
        return enc ;
 }
 
-#endif // wxUSE_BASE
-
-#if wxUSE_GUI
-
 
 //
 // CFStringRefs (Carbon only)
@@ -1232,9 +1380,6 @@ void wxMacConvertNewlines10To13( wxChar * data )
 // Common Event Support
 // ----------------------------------------------------------------------------
 
-#endif // wxUSE_GUI
-
-#if wxUSE_BASE
 
 extern ProcessSerialNumber gAppProcess ;
 
@@ -1290,12 +1435,12 @@ OSStatus wxMacCarbonEvent::SetParameter(EventParamName inName, EventParamType in
 // Control Access Support
 // ----------------------------------------------------------------------------
 
-OSStatus wxMacControl::GetData(ControlPartCode inPartCode , ResType inTag , Size inBufferSize , void * inOutBuffer , Size * outActualSize )
+OSStatus wxMacControl::GetData(ControlPartCode inPartCode , ResType inTag , Size inBufferSize , void * inOutBuffer , Size * outActualSize ) const
 {
     return ::GetControlData( m_controlRef , inPartCode , inTag , inBufferSize , inOutBuffer , outActualSize ) ;   
 }
 
-OSStatus wxMacControl::GetDataSize(ControlPartCode inPartCode , ResType inTag , Size * outActualSize )
+OSStatus wxMacControl::GetDataSize(ControlPartCode inPartCode , ResType inTag , Size * outActualSize ) const
 {
     return ::GetControlDataSize( m_controlRef , inPartCode , inTag , outActualSize ) ;   
 }
@@ -1307,9 +1452,13 @@ OSStatus wxMacControl::SetData(ControlPartCode inPartCode , ResType inTag , Size
 
 OSStatus wxMacControl::SendEvent(  EventRef event , OptionBits inOptions ) 
 {
+#if TARGET_API_MAC_OSX
     return SendEventToEventTargetWithOptions( event, 
-        HIObjectGetEventTarget( (HIObjectRef) m_controlRef ),
-               inOptions );        
+        HIObjectGetEventTarget(  (HIObjectRef) m_controlRef ), inOptions );        
+#else
+    #pragma unused(inOptions) 
+    return SendEventToEventTarget(event,GetControlEventTarget( m_controlRef ) ) ;
+#endif
 }
 
 OSStatus wxMacControl::SendHICommand( HICommand &command , OptionBits inOptions ) 
@@ -1335,145 +1484,95 @@ void wxMacControl::Flash( ControlPartCode part , UInt32 ticks )
     HiliteControl( m_controlRef , kControlNoPart ) ;
 }
 
-// ----------------------------------------------------------------------------
-// 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 <Gestalt.h>
-#endif
-
-#if TARGET_API_MAC_CARBON
-
-    #include <CodeFragments.h>
-
-    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;
+SInt32 wxMacControl::GetValue() const
+{ 
+    return ::GetControl32BitValue( m_controlRef ) ; 
+}
 
-                    /* make sure the version of the API is compatible */
-                    if (block->apiLowVersion <= kMetroNubUserAPIVersion &&
-                        kMetroNubUserAPIVersion <= block->apiHiVersion)
-                        gMetroNubEntry = block;        /* success! */
-                }
+SInt32 wxMacControl::GetMaximum() const
+{ 
+    return ::GetControl32BitMaximum( m_controlRef ) ; 
+}
 
-            }
-        }
-    }
+SInt32 wxMacControl::GetMinimum() const
+{ 
+    return ::GetControl32BitMinimum( m_controlRef ) ; 
+}
 
-end:
+void wxMacControl::SetValue( SInt32 v ) 
+{ 
+    ::SetControl32BitValue( m_controlRef , v ) ; 
+}
 
-#if TARGET_API_MAC_CARBON
-    return (gMetroNubEntry != NULL && gCallUniversalProc_Proc != NULL);
-#else
-    return (gMetroNubEntry != NULL);
-#endif
+void wxMacControl::SetMinimum( SInt32 v ) 
+{ 
+    ::SetControl32BitMinimum( m_controlRef , v ) ; 
 }
 
-/* ---------------------------------------------------------------------------
-        IsMWDebuggerRunning                                            [v1 API]
-   --------------------------------------------------------------------------- */
+void wxMacControl::SetMaximum( SInt32 v ) 
+{ 
+    ::SetControl32BitMaximum( m_controlRef , v ) ;
+}
 
-Boolean IsMWDebuggerRunning()
+void wxMacControl::SetValueAndRange( SInt32 value , SInt32 minimum , SInt32 maximum )
 {
-    if (IsMetroNubInstalled())
-        return CallIsDebuggerRunningProc(gMetroNubEntry->isDebuggerRunning);
-    else
-        return false;
+    ::SetControl32BitMinimum( m_controlRef , minimum ) ;
+    ::SetControl32BitMaximum( m_controlRef , maximum ) ; 
+    ::SetControl32BitValue( m_controlRef , value ) ;
 }
 
-/* ---------------------------------------------------------------------------
-        AmIBeingMWDebugged                                            [v1 API]
-   --------------------------------------------------------------------------- */
-
-Boolean AmIBeingMWDebugged()
+void wxMacControl::VisibilityChanged(bool shown) 
 {
-    if (IsMetroNubInstalled())
-        return CallAmIBeingDebuggedProc(gMetroNubEntry->amIBeingDebugged);
-    else
-        return false;
 }
 
-extern bool WXDLLEXPORT wxIsDebuggerRunning()
+void wxMacControl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle ) 
 {
-    return IsMWDebuggerRunning() && AmIBeingMWDebugged();
-}
+    m_font = font ;
+       ControlFontStyleRec     fontStyle;
+       if ( font.MacGetThemeFontID() != kThemeCurrentPortFont )
+       {
+           switch( font.MacGetThemeFontID() )
+           {
+               case kThemeSmallSystemFont :    fontStyle.font = kControlFontSmallSystemFont ;  break ;
+               case 109 /*mini font */ :       fontStyle.font = -5 ;                           break ;
+               case kThemeSystemFont :         fontStyle.font = kControlFontBigSystemFont ;    break ;
+               default :                       fontStyle.font = kControlFontBigSystemFont ;    break ;
+           }
+           fontStyle.flags = kControlUseFontMask ; 
+       }
+       else
+       {
+           fontStyle.font = font.MacGetFontNum() ;
+           fontStyle.style = font.MacGetFontStyle() ;
+           fontStyle.size = font.MacGetFontSize() ;
+           fontStyle.flags = kControlUseFontMask | kControlUseFaceMask | kControlUseSizeMask ;
+       }
 
-#else
+    fontStyle.just = teJustLeft ;
+    fontStyle.flags |= kControlUseJustMask ;
+    if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_CENTER_HORIZONTAL )
+        fontStyle.just = teJustCenter ;
+    else if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_RIGHT )
+        fontStyle.just = teJustRight ;
 
-extern bool WXDLLEXPORT wxIsDebuggerRunning()
-{
-    return false;
+    
+    // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
+    // won't get grayed out by the system anymore
+    
+    if ( foreground != *wxBLACK )
+    {
+        fontStyle.foreColor = MAC_WXCOLORREF(foreground.GetPixel() ) ;
+        fontStyle.flags |= kControlUseForeColorMask ;
+    }
+       
+       ::SetControlFontStyle( m_controlRef , &fontStyle );
 }
 
-#endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)
+void wxMacControl::SetRange( SInt32 minimum , SInt32 maximum )
+{
+    ::SetControl32BitMinimum( m_controlRef , minimum ) ;
+    ::SetControl32BitMaximum( m_controlRef , maximum ) ; 
+}
 
 #endif // wxUSE_GUI