]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/window.cpp
added wxWS_EX_VALIDATE_RECURSIVELY
[wxWidgets.git] / src / mac / carbon / window.cpp
index ba71652f8d2749a4db3285dc9d0a9e4561f817ec..07696993a6d6f52c9adecc6f6664eb122f7315de 100644 (file)
@@ -201,23 +201,57 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
                 RgnHandle updateRgn = NULL ;
                 RgnHandle allocatedRgn = NULL ;
                 wxRegion visRegion = thisWindow->MacGetVisibleRegion() ;
+                Rect controlBounds ;
+                if ( thisWindow->GetPeer()->IsCompositing() == false )
+                {
+                    if ( thisWindow->GetPeer()->IsRootControl() == false )
+                    {
+                        GetControlBounds( thisWindow->GetPeer()->GetControlRef() , &controlBounds ) ;
+                    }
+                    else
+                    {
+                        thisWindow->GetPeer()->GetRect( &controlBounds ) ;
+                    }
+                }
+                
                 if ( cEvent.GetParameter<RgnHandle>(kEventParamRgnHandle, &updateRgn) != noErr )
                 {
                     updateRgn = (RgnHandle) visRegion.GetWXHRGN() ;
                 }
                 else
                 {
-                    if ( thisWindow->MacGetLeftBorderSize() != 0 || thisWindow->MacGetTopBorderSize() != 0 )
+                    if ( thisWindow->GetPeer()->IsCompositing() == false )
                     {
-                        // as this update region is in native window locals we must adapt it to wx window local
+                        if ( thisWindow->GetPeer()->IsRootControl() == false )
+                        {
+                            GetControlBounds( thisWindow->GetPeer()->GetControlRef() , &controlBounds ) ;
+                        }
+                        else
+                        {
+                            thisWindow->GetPeer()->GetRect( &controlBounds ) ;
+                        }
                         allocatedRgn = NewRgn() ;
                         CopyRgn( updateRgn , allocatedRgn ) ;
+                        OffsetRgn( allocatedRgn , -controlBounds.left , -controlBounds.top ) ;
                         // hide the given region by the new region that must be shifted
                         wxMacNativeToWindow( thisWindow , allocatedRgn ) ;
-                        updateRgn = allocatedRgn ;
+                        updateRgn = allocatedRgn ;                            
+                    }
+                    else
+                    {
+                        if ( thisWindow->MacGetLeftBorderSize() != 0 || thisWindow->MacGetTopBorderSize() != 0 )
+                        {
+                            // as this update region is in native window locals we must adapt it to wx window local
+                            allocatedRgn = NewRgn() ;
+                            CopyRgn( updateRgn , allocatedRgn ) ;
+                            // hide the given region by the new region that must be shifted
+                            wxMacNativeToWindow( thisWindow , allocatedRgn ) ;
+                            updateRgn = allocatedRgn ;
+                        }
                     }
                 }
-
+                Rect rgnBounds ;
+                GetRegionBounds( updateRgn , &rgnBounds ) ;
 #if wxMAC_DEBUG_REDRAW
                 if ( thisWindow->MacIsUserPane() )
                 {
@@ -241,14 +275,52 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
 #endif
                 {
 #if wxMAC_USE_CORE_GRAPHICS
-                    CGContextRef cgContext = cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef) ;
+                    bool created = false ;
+                    CGContextRef cgContext = 0 ;
+                    if ( cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef, &cgContext) != noErr )
+                    {
+                        wxASSERT( thisWindow->GetPeer()->IsCompositing() == false ) ;
+                        
+                        // this parameter is not provided on non-composited windows
+                        created = true ;
+                        // rest of the code expects this to be already transformed and clipped for local 
+                        CGrafPtr port = GetWindowPort( (WindowRef) thisWindow->MacGetTopLevelWindowRef() ) ;
+                        Rect bounds ;
+                        GetPortBounds( port , &bounds ) ;
+                        CreateCGContextForPort( port , &cgContext ) ;
+
+                        wxMacWindowToNative( thisWindow , updateRgn ) ;
+                        OffsetRgn( updateRgn , controlBounds.left , controlBounds.top ) ;
+                        ClipCGContextToRegion( cgContext , &bounds , updateRgn ) ;
+                        wxMacNativeToWindow( thisWindow , updateRgn ) ;
+                        OffsetRgn( updateRgn , -controlBounds.left , -controlBounds.top ) ;
+
+                        CGContextTranslateCTM( cgContext , 0 , bounds.bottom - bounds.top ) ;
+                        CGContextScaleCTM( cgContext , 1 , -1 ) ;
+                        
+                        CGContextTranslateCTM( cgContext , controlBounds.left , controlBounds.top ) ;
+                        
+                        /*
+                        CGContextSetRGBFillColor( cgContext , 1.0 , 1.0 , 1.0 , 1.0 ) ;
+                        CGContextFillRect(cgContext , CGRectMake( 0 , 0 , 
+                            controlBounds.right - controlBounds.left , 
+                            controlBounds.bottom - controlBounds.top ) );
+                        */
+
+                    }
                     thisWindow->MacSetCGContextRef( cgContext ) ;
-                    wxMacCGContextStateSaver sg( cgContext ) ;
+                    {
+                        wxMacCGContextStateSaver sg( cgContext ) ;
 #endif
-                    if ( thisWindow->MacDoRedraw( updateRgn , cEvent.GetTicks() ) )
-                        result = noErr ;
+                        if ( thisWindow->MacDoRedraw( updateRgn , cEvent.GetTicks() ) )
+                            result = noErr ;
 #if wxMAC_USE_CORE_GRAPHICS
-                    thisWindow->MacSetCGContextRef( NULL ) ;
+                        thisWindow->MacSetCGContextRef( NULL ) ;
+                    }
+                    if ( created )
+                    {
+                        CGContextRelease( cgContext ) ;
+                    }
 #endif
                 }
                 if ( allocatedRgn )
@@ -587,7 +659,9 @@ void wxAssociateControlWithMacControl(ControlRef inControl, wxWindow *control)
 
 void wxRemoveMacControlAssociation(wxWindow *control)
 {
-    wxWinMacControlList.DeleteObject(control);
+    // remove all associations pointing to us
+    while ( wxWinMacControlList.DeleteObject(control) )
+        {}
 }
 #else
 
@@ -614,13 +688,22 @@ void wxAssociateControlWithMacControl(ControlRef inControl, wxWindow *control)
 void wxRemoveMacControlAssociation(wxWindow *control)
 {
    // iterate over all the elements in the class
-    MacControlMap::iterator it;
-    for ( it = wxWinMacControlList.begin(); it != wxWinMacControlList.end(); ++it )
+    // is the iterator stable ? as we might have two associations pointing to the same wxWindow
+    // we should go on...
+
+    bool found = true ;
+    while( found )
     {
-        if ( it->second == control )
+        found = false ;
+        MacControlMap::iterator it;
+        for ( it = wxWinMacControlList.begin(); it != wxWinMacControlList.end(); ++it )
         {
-            wxWinMacControlList.erase(it);
-            break;
+            if ( it->second == control )
+            {
+                wxWinMacControlList.erase(it);
+                found = true ;
+                break;
+            }
         }
     }
 }
@@ -1130,10 +1213,14 @@ void wxWindowMac::DoGetPosition(int *x, int *y) const
 {
     Rect bounds ;
     m_peer->GetRect( &bounds ) ;
-
+    
     int x1 = bounds.left ;
     int y1 = bounds.top ;
 
+    // get the wx window position from the native one
+    x1 -= MacGetLeftBorderSize() ;
+    y1 -= MacGetTopBorderSize() ;
+
     if ( !IsTopLevel() )
     {
         wxWindow *parent = GetParent();
@@ -1795,7 +1882,7 @@ wxPoint wxWindowMac::GetClientAreaOrigin() const
 {
     RgnHandle rgn = NewRgn() ;
     Rect content ;
-    if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) )
+    if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
     {
         GetRegionBounds( rgn , &content ) ;
     }
@@ -2177,12 +2264,15 @@ void wxWindowMac::MacPaintBorders( int leftOrigin , int rightOrigin )
     bool hasBothScrollbars = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;
 
     m_peer->GetRect( &rect ) ;
-    InsetRect( &rect, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
+    // back to the surrounding frame rectangle
+    InsetRect( &rect, -1 , -1 ) ;
 
 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
     if ( UMAGetSystemVersion() >= 0x1030  )
     {
-        Rect srect = rect ;
+        CGRect cgrect = CGRectMake( rect.left , rect.top , rect.right - rect.left ,
+            rect.bottom - rect.top ) ;
+
         HIThemeFrameDrawInfo info ;
         memset( &info, 0 , sizeof( info ) ) ;
         
@@ -2190,49 +2280,31 @@ void wxWindowMac::MacPaintBorders( int leftOrigin , int rightOrigin )
         info.kind = 0 ;
         info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ;
         info.isFocused = hasFocus ;
-        bool draw = false ;
 
         CGContextRef cgContext = (CGContextRef) GetParent()->MacGetCGContextRef() ;
         wxASSERT( cgContext ) ;
          
         if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
         {
-            SInt32 border = 0 ;
-            GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ;
-            InsetRect( &srect , border , border );
             info.kind = kHIThemeFrameTextFieldSquare ;
-            draw = true ;
+            HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ;
         }
         else if (HasFlag(wxSIMPLE_BORDER))
         {
-            SInt32 border = 0 ;
-            GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
-            InsetRect( &srect , border , border );
             info.kind = kHIThemeFrameListBox ;
-            draw = true ;
-        }
-            
-        if ( draw )
-        {
-            CGRect cgrect = CGRectMake( srect.left , srect.top , srect.right - srect.left ,
-                srect.bottom - srect.top ) ;
             HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ;
         }
         else if ( hasFocus )
         {
-            srect = rect ;
-            CGRect cgrect = CGRectMake( srect.left , srect.top , srect.right - srect.left ,
-                srect.bottom - srect.top ) ;
             HIThemeDrawFocusRect( &cgrect , true , cgContext , kHIThemeOrientationNormal ) ;
         }
         
         m_peer->GetRect( &rect ) ;
         if ( hasBothScrollbars )
         {
-            srect = rect ;
             int size = m_hScrollBar->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL ? 16 : 12 ;
-            CGRect cgrect = CGRectMake( srect.right - size , srect.bottom - size , size , size ) ;
-            CGPoint cgpoint = CGPointMake( srect.right - size , srect.bottom - size ) ;
+            CGRect cgrect = CGRectMake( rect.right - size , rect.bottom - size , size , size ) ;
+            CGPoint cgpoint = CGPointMake( rect.right - size , rect.bottom - size ) ;
             HIThemeGrowBoxDrawInfo info ; 
             memset( &info, 0 , sizeof( info ) ) ;
             info.version = 0 ;
@@ -2256,26 +2328,18 @@ void wxWindowMac::MacPaintBorders( int leftOrigin , int rightOrigin )
 
         if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
         {
-            Rect srect = rect ;
-            SInt32 border = 0 ;
-            GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ;
-            InsetRect( &srect , border , border );
-            DrawThemeEditTextFrame(&srect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
+            DrawThemeEditTextFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
         }
         else if (HasFlag(wxSIMPLE_BORDER))
         {
-            Rect srect = rect ;
-            SInt32 border = 0 ;
-            GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
-            InsetRect( &srect , border , border );
             DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
         }
         
         if ( hasFocus )
         {
-            Rect srect = rect ;
-            DrawThemeFocusRect( &srect , true ) ;
+            DrawThemeFocusRect( &rect , true ) ;
         }
+
         if ( hasBothScrollbars )
         {
             // GetThemeStandaloneGrowBoxBounds    
@@ -2505,7 +2569,8 @@ void wxWindowMac::OnSetFocus(wxFocusEvent& event)
         wxMacWindowStateSaver sv( this ) ;
         Rect rect ;
         m_peer->GetRect( &rect ) ;
-        InsetRect( &rect, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
+        // auf den umgebenden Rahmen zur\9fck
+        InsetRect( &rect, -1 , -1 ) ;
 
         wxTopLevelWindowMac* top = MacGetTopLevelWindow();
         if (top )
@@ -2604,10 +2669,12 @@ bool wxWindowMac::MacSetupCursor( const wxPoint& pt)
 
 wxString wxWindowMac::MacGetToolTipString( wxPoint &pt )
 {
+#if wxUSE_TOOLTIPS
     if ( m_tooltip )
     {
         return m_tooltip->GetTip() ;
     }
+#endif
     return wxEmptyString ;
 }
 
@@ -3026,21 +3093,19 @@ long wxWindowMac::MacGetLeftBorderSize( ) const
     if( IsTopLevel() )
         return 0 ;
 
-    if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
-    {
-        SInt32 border = 3 ;
-          return border ;
-    }
-    else if (  m_windowStyle &wxDOUBLE_BORDER)
+    SInt32 border = 0 ;
+    
+    if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
     {
-          SInt32 border = 3 ;
-          return border ;
+        GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ;
+        border += 1 ; // the metric above is only the 'outset' outside the simple frame rect
     }
-    else if (m_windowStyle &wxSIMPLE_BORDER)
+    else if (HasFlag(wxSIMPLE_BORDER))
     {
-        return 1 ;
+        GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
+        border += 1 ; // the metric above is only the 'outset' outside the simple frame rect
     }
-    return 0 ;
+    return border ;
 }
 
 long wxWindowMac::MacGetRightBorderSize( ) const