]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/window.cpp
missing include for memoryDC
[wxWidgets.git] / src / mac / carbon / window.cpp
index 003444f18546caa4264662d5eb9426b5d76a05a4..9800febda5bb4ef5452191f8c034dfb8b714c22b 100644 (file)
@@ -748,6 +748,7 @@ void wxWindowMac::Init()
 #if wxMAC_USE_CORE_GRAPHICS
     m_cgContextRef = NULL ;
 #endif
+    m_clipChildren = false ;
     // we need a valid font for the encodings
     wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
 }
@@ -1115,17 +1116,17 @@ void wxWindowMac::SetFocus()
 
 void wxWindowMac::DoCaptureMouse()
 {
-    wxTheApp->s_captureWindow = this ;
+    wxApp::s_captureWindow = this ;
 }
 
 wxWindow* wxWindowBase::GetCapture()
 {
-    return wxTheApp->s_captureWindow ;
+    return wxApp::s_captureWindow ;
 }
 
 void wxWindowMac::DoReleaseMouse()
 {
-    wxTheApp->s_captureWindow = NULL ;
+    wxApp::s_captureWindow = NULL ;
 }
 
 #if    wxUSE_DRAG_AND_DROP
@@ -1213,10 +1214,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();
@@ -2260,12 +2265,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 ) ) ;
         
@@ -2273,49 +2281,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 ;
@@ -2339,26 +2329,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    
@@ -2424,12 +2406,11 @@ void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
     if( dx == 0 && dy ==0 )
         return ;
 
-
-    {
-
         int width , height ;
         GetClientSize( &width , &height ) ;
 #if TARGET_API_MAC_OSX
+       if ( 1 /* m_peer->IsCompositing() */ )
+       {
         // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
         // area is scrolled, this does not occur if width and height are 2 pixels less,
         // TODO write optimal workaround
@@ -2447,16 +2428,39 @@ void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
             m_peer->SetNeedsDisplay() ;
 #else
             // this would be the preferred version for fast drawing controls
-            if( UMAGetSystemVersion() < 0x1030 )
-                Update() ;
-            else
+
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
+            if( UMAGetSystemVersion() >= 0x1030 && m_peer->IsCompositing() )
                 HIViewRender(m_peer->GetControlRef()) ;
+            else
+#endif
+                Update() ;
 #endif
         }
         // as the native control might be not a 0/0 wx window coordinates, we have to offset
         scrollrect.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
-        m_peer->ScrollRect( scrollrect , dx , dy ) ;
+        m_peer->ScrollRect( (&scrollrect) , dx , dy ) ;
+
+        // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
+        // either immediate redraw or full invalidate
+#if 0
+        // is the better overall solution, as it does not slow down scrolling
+        m_peer->SetNeedsDisplay() ;
 #else
+        // this would be the preferred version for fast drawing controls       
+
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
+            if( UMAGetSystemVersion() >= 0x1030 && m_peer->IsCompositing() )
+                HIViewRender(m_peer->GetControlRef()) ;
+            else
+#endif
+                Update() ;
+
+#endif
+       }
+       else
+#endif
+       {
 
         wxPoint pos;
         pos.x = pos.y = 0;
@@ -2468,9 +2472,9 @@ void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
             wxClientDC dc(this) ;
             wxMacPortSetter helper(&dc) ;
 
-            m_peer->GetRect( &scrollrect ) ;
-            scrollrect.top += MacGetTopBorderSize() ;
-            scrollrect.left += MacGetLeftBorderSize() ;
+            m_peer->GetRectInWindowCoords( &scrollrect ) ;
+            //scrollrect.top += MacGetTopBorderSize() ;
+            //scrollrect.left += MacGetLeftBorderSize() ;
             scrollrect.bottom = scrollrect.top + height ;
             scrollrect.right = scrollrect.left + width ;
 
@@ -2504,7 +2508,7 @@ void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
             DisposeRgn( formerUpdateRgn ) ;
             DisposeRgn( scrollRgn ) ;
         }
-#endif
+        Update() ;
     }
 
     for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext())
@@ -2588,7 +2592,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 )
@@ -2705,39 +2710,7 @@ void wxWindowMac::ClearBackground()
 void wxWindowMac::Update()
 {
 #if TARGET_API_MAC_OSX
-
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
-    WindowRef window = (WindowRef)MacGetTopLevelWindowRef() ;
-
-    // for composited windows this also triggers a redraw of all
-    // invalid views in the window
-    if( UMAGetSystemVersion() >= 0x1030 )
-        HIWindowFlush(window) ;
-    else
-#endif
-    {
-        // the only way to trigger the redrawing on earlier systems is to call
-        // ReceiveNextEvent
-
-        EventRef currentEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ;
-        UInt32 currentEventClass = 0 ;
-        UInt32 currentEventKind = 0 ;
-        if ( currentEvent != NULL )
-        {
-            currentEventClass = ::GetEventClass( currentEvent ) ;
-            currentEventKind = ::GetEventKind( currentEvent ) ;
-        }
-        if ( currentEventClass != kEventClassMenu )
-        {
-            // when tracking a menu, strange redraw errors occur if we flush now, so leave..
-
-            EventRef theEvent;
-            OSStatus status = noErr ;
-            status = ReceiveNextEvent( 0 , NULL , kEventDurationNoWait , false , &theEvent ) ;
-        }
-        else
-            m_peer->SetNeedsDisplay() ;
-    }
+       MacGetTopLevelWindow()->MacPerformUpdates() ;
 #else
     ::Draw1Control( m_peer->GetControlRef() ) ;
 #endif
@@ -3014,10 +2987,10 @@ void wxWindowMac::MacRepositionScrollBars()
     width -= MacGetLeftBorderSize() + MacGetRightBorderSize();
     height -= MacGetTopBorderSize() + MacGetBottomBorderSize();
 
-    wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
-    wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
-    wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
-    wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
+    wxPoint vPoint(width-scrlsize, 0) ;
+    wxSize vSize(scrlsize, height - adjust) ;
+    wxPoint hPoint(0 , height-scrlsize ) ;
+    wxSize hSize( width - adjust, scrlsize) ;
 /*
     int x = 0 ;
     int y = 0 ;
@@ -3111,21 +3084,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