]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/utils.cpp
Various layout fixes and such
[wxWidgets.git] / src / mac / carbon / utils.cpp
index 45e9cde839961ad6047d6e9898cae0edc67aff48..77fb5aefcffcd0021b2844547c194f9c994c6c0e 100644 (file)
@@ -198,11 +198,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)
@@ -533,15 +537,6 @@ bool wxGetDiskSpace(const wxString& path, wxLongLong *pTotal, wxLongLong *pFree)
 // wxMac Specific utility functions
 //---------------------------------------------------------------------------
 
-Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size ) 
-{
-    int x ,y , w ,h ;
-    
-    window->MacGetBoundsForControl( pos , size , x , y, w, h ) ;
-    Rect bounds =  { y , x , y+h , x+w  };
-    return bounds ;
-}
-
 void wxMacStringToPascal( const wxString&from , StringPtr to )
 {
     wxCharBuffer buf = from.mb_str( wxConvLocal ) ;
@@ -1085,10 +1080,6 @@ wxFontEncoding wxMacGetFontEncFromSystemEnc(wxUint32 encoding)
        return enc ;
 }
 
-#endif // wxUSE_BASE
-
-#if wxUSE_GUI
-
 
 //
 // CFStringRefs (Carbon only)
@@ -1233,6 +1224,46 @@ void wxMacConvertNewlines10To13( wxChar * data )
 }
 #endif
 
+// ----------------------------------------------------------------------------
+// Common Event Support
+// ----------------------------------------------------------------------------
+
+
+extern ProcessSerialNumber gAppProcess ;
+
+void wxMacWakeUp()
+{
+    ProcessSerialNumber psn ;
+    Boolean isSame ;
+    psn.highLongOfPSN = 0 ;
+    psn.lowLongOfPSN = kCurrentProcess ;
+    SameProcess( &gAppProcess , &psn , &isSame ) ;
+    if ( isSame )
+    {
+#if TARGET_CARBON
+        EventRef dummyEvent ;
+        OSStatus err = MacCreateEvent(nil, 'WXMC', 'WXMC', GetCurrentEventTime(),
+                        kEventAttributeNone, &dummyEvent);
+        if (err == noErr) 
+        {
+            err = PostEventToQueue(GetMainEventQueue(), dummyEvent,
+                                  kEventPriorityHigh);
+        } 
+#else
+        PostEvent( nullEvent , 0 ) ;
+#endif
+    }
+    else
+    {
+        WakeUpProcess( &gAppProcess ) ;
+    }
+}
+
+#endif // wxUSE_BASE
+
+#if wxUSE_GUI
+
+
 // ----------------------------------------------------------------------------
 // Carbon Event Support
 // ----------------------------------------------------------------------------
@@ -1243,11 +1274,64 @@ OSStatus wxMacCarbonEvent::GetParameter(EventParamName inName, EventParamType in
     return ::GetEventParameter( m_eventRef , inName , inDesiredType , NULL , inBufferSize , NULL , outData ) ;   
 }
 
-OSStatus wxMacCarbonEvent::SetParameter(EventParamName inName, EventParamType inType, UInt32 inBufferSize, void * inData)
+OSStatus wxMacCarbonEvent::SetParameter(EventParamName inName, EventParamType inType, UInt32 inBufferSize, const void * inData)
 {
     return ::SetEventParameter( m_eventRef , inName , inType , inBufferSize , inData ) ;   
 }
 
+// ----------------------------------------------------------------------------
+// Control Access Support
+// ----------------------------------------------------------------------------
+
+OSStatus wxMacControl::GetData(ControlPartCode inPartCode , ResType inTag , Size inBufferSize , void * inOutBuffer , Size * outActualSize )
+{
+    return ::GetControlData( m_controlRef , inPartCode , inTag , inBufferSize , inOutBuffer , outActualSize ) ;   
+}
+
+OSStatus wxMacControl::GetDataSize(ControlPartCode inPartCode , ResType inTag , Size * outActualSize )
+{
+    return ::GetControlDataSize( m_controlRef , inPartCode , inTag , outActualSize ) ;   
+}
+
+OSStatus wxMacControl::SetData(ControlPartCode inPartCode , ResType inTag , Size inSize , const void * inData)
+{
+    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
+}
+
+OSStatus wxMacControl::SendHICommand( HICommand &command , OptionBits inOptions ) 
+{
+    wxMacCarbonEvent event( kEventClassCommand , kEventCommandProcess ) ;
+    event.SetParameter<HICommand>(kEventParamDirectObject,command) ;
+    return SendEvent( event , inOptions ) ;     
+}
+
+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 ) ;
+}
+
 // ----------------------------------------------------------------------------
 // debugging support
 // ----------------------------------------------------------------------------