X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a3bf7524f394af039efe196a186f7969cbabcc19..163dc80eff2faed2c3c1fb3ee6b46eb5ae9d70f9:/src/mac/carbon/window.cpp diff --git a/src/mac/carbon/window.cpp b/src/mac/carbon/window.cpp index 51406e6bb7..a5c56e4202 100644 --- a/src/mac/carbon/window.cpp +++ b/src/mac/carbon/window.cpp @@ -100,10 +100,6 @@ END_EVENT_TABLE() void wxWindowMac::Init() { - // generic - InitBase(); - - m_isBeingDeleted = FALSE; m_backgroundTransparent = FALSE; // as all windows are created with WS_VISIBLE style... @@ -116,8 +112,6 @@ void wxWindowMac::Init() m_hScrollBar = NULL ; m_vScrollBar = NULL ; - - m_label = wxEmptyString; } // Destructor @@ -174,15 +168,8 @@ wxWindowMac::~wxWindowMac() gFocusWindow = NULL ; } - // CS: copied from MSW : - // VS: destroy children first and _then_ detach *this from its parent. - // If we'd do it the other way around, children wouldn't be able - // find their parent frame (see above). DestroyChildren(); - if ( m_parent ) - m_parent->RemoveChild(this); - // delete our drop target if we've got one #if wxUSE_DRAG_AND_DROP if ( m_dropTarget != NULL ) @@ -231,6 +218,10 @@ bool wxWindowMac::Create(wxWindowMac *parent, wxWindowID id, MacCreateScrollBars( style ) ; } #endif + + wxWindowCreateEvent event(this); + GetEventHandler()->AddPendingEvent(event); + return TRUE; } @@ -634,7 +625,7 @@ void wxWindowMac::DoMoveWindow(int x, int y, int width, int height) bool partialRepaint = false ; - if ( HasFlag(wxNO_FULL_REPAINT_ON_RESIZE) ) + if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE) ) { wxPoint oldPos( m_x , m_y ) ; wxPoint newPos( actualX , actualY ) ; @@ -647,12 +638,40 @@ void wxWindowMac::DoMoveWindow(int x, int y, int width, int height) oldRgn = NewRgn() ; newRgn = NewRgn() ; diffRgn = NewRgn() ; + + // invalidate the differences between the old and the new area + SetRectRgn(oldRgn , oldPos.x , oldPos.y , oldPos.x + m_width , oldPos.y + m_height ) ; SetRectRgn(newRgn , newPos.x , newPos.y , newPos.x + actualWidth , newPos.y + actualHeight ) ; DiffRgn( newRgn , oldRgn , diffRgn ) ; InvalWindowRgn( (WindowRef) MacGetRootWindow() , diffRgn ) ; DiffRgn( oldRgn , newRgn , diffRgn ) ; InvalWindowRgn( (WindowRef) MacGetRootWindow() , diffRgn ) ; + + // we also must invalidate the border areas, someone might optimize this one day to invalidate only the really + // changing pixels... + + if ( MacGetLeftBorderSize() != 0 || MacGetRightBorderSize() != 0 || + MacGetTopBorderSize() != 0 || MacGetBottomBorderSize() != 0 ) + { + RgnHandle innerOldRgn, innerNewRgn ; + innerOldRgn = NewRgn() ; + innerNewRgn = NewRgn() ; + + SetRectRgn(innerOldRgn , oldPos.x + MacGetLeftBorderSize() , oldPos.y + MacGetTopBorderSize() , + oldPos.x + m_width - MacGetRightBorderSize() , oldPos.y + m_height - MacGetBottomBorderSize() ) ; + DiffRgn( oldRgn , innerOldRgn , diffRgn ) ; + InvalWindowRgn( (WindowRef) MacGetRootWindow() , diffRgn ) ; + + SetRectRgn(innerNewRgn , newPos.x + MacGetLeftBorderSize() , newPos.y + MacGetTopBorderSize() , + newPos.x + actualWidth - MacGetRightBorderSize() , newPos.y + actualHeight - MacGetBottomBorderSize() ) ; + DiffRgn( newRgn , innerNewRgn , diffRgn ) ; + InvalWindowRgn( (WindowRef) MacGetRootWindow() , diffRgn ) ; + + DisposeRgn( innerOldRgn ) ; + DisposeRgn( innerNewRgn ) ; + } + DisposeRgn(oldRgn) ; DisposeRgn(newRgn) ; DisposeRgn(diffRgn) ; @@ -827,7 +846,7 @@ void wxWindowMac::MacSuperEnabled( bool enabled ) bool wxWindowMac::MacIsReallyShown() const { - if ( m_isShown && (m_parent != NULL) ) { + if ( m_isShown && (m_parent != NULL && !IsTopLevel() ) ) { return m_parent->MacIsReallyShown(); } return m_isShown; @@ -1076,23 +1095,38 @@ void wxWindowMac::MacPaintBorders( int left , int top ) { if( IsTopLevel() ) return ; + + int major,minor; + wxGetOsVersion( &major, &minor ); RGBColor white = { 0xFFFF, 0xFFFF , 0xFFFF } ; - RGBColor black = { 0x0000, 0x0000 , 0x0000 } ; RGBColor face = { 0xDDDD, 0xDDDD , 0xDDDD } ; - RGBColor shadow = { 0x4444, 0x4444 , 0x4444 } ; + + RGBColor darkShadow = { 0x0000, 0x0000 , 0x0000 } ; + RGBColor lightShadow = { 0x4444, 0x4444 , 0x4444 } ; + // OS X has lighter border edges than classic: + if (major >= 10) + { + darkShadow.red = 0x8E8E; + darkShadow.green = 0x8E8E; + darkShadow.blue = 0x8E8E; + lightShadow.red = 0xBDBD; + lightShadow.green = 0xBDBD; + lightShadow.blue = 0xBDBD; + } + PenNormal() ; if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) ) { #if wxMAC_USE_THEME_BORDER - Rect rect = { top , left , m_height + top , m_width + left } ; - SInt32 border = 0 ; - /* - GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; - InsetRect( &rect , border , border ); - DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; - */ + Rect rect = { top , left , m_height + top , m_width + left } ; + SInt32 border = 0 ; + /* + GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; + InsetRect( &rect , border , border ); + DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; + */ DrawThemePrimaryGroup(&rect ,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; #else @@ -1106,22 +1140,22 @@ void wxWindowMac::MacPaintBorders( int left , int top ) LineTo( left + m_width - 3 , top + m_height - 3 ); LineTo( left + m_width - 3 , top + 2 ); - RGBForeColor( sunken ? &face : &black ); + RGBForeColor( sunken ? &face : &darkShadow ); MoveTo( left + 0 , top + m_height - 1 ); LineTo( left + m_width - 1 , top + m_height - 1 ); LineTo( left + m_width - 1 , top + 0 ); - RGBForeColor( sunken ? &shadow : &white ); + RGBForeColor( sunken ? &lightShadow : &white ); MoveTo( left + 1 , top + m_height - 3 ); LineTo( left + 1, top + 1 ); LineTo( left + m_width - 3 , top + 1 ); - RGBForeColor( sunken ? &white : &shadow ); + RGBForeColor( sunken ? &white : &lightShadow ); MoveTo( left + 1 , top + m_height - 2 ); LineTo( left + m_width - 2 , top + m_height - 2 ); LineTo( left + m_width - 2 , top + 1 ); - RGBForeColor( sunken ? &black : &face ); + RGBForeColor( sunken ? &darkShadow : &face ); MoveTo( left + 2 , top + m_height - 4 ); LineTo( left + 2 , top + 2 ); LineTo( left + m_width - 4 , top + 2 ); @@ -1129,8 +1163,8 @@ void wxWindowMac::MacPaintBorders( int left , int top ) } else if (HasFlag(wxSIMPLE_BORDER)) { - Rect rect = { top , left , m_height + top , m_width + left } ; - RGBForeColor( &black ) ; + Rect rect = { top , left , m_height + top , m_width + left } ; + RGBForeColor( &darkShadow ) ; FrameRect( &rect ) ; } } @@ -1189,10 +1223,14 @@ void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible, // Does a physical scroll void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) { - wxClientDC dc(this) ; - wxMacPortSetter helper(&dc) ; + if( dx == 0 && dy ==0 ) + return ; + { + wxClientDC dc(this) ; + wxMacPortSetter helper(&dc) ; + int width , height ; GetClientSize( &width , &height ) ; @@ -1206,8 +1244,27 @@ void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) SectRect( &scrollrect , &r , &scrollrect ) ; } ScrollRect( &scrollrect , dx , dy , updateRgn ) ; - InvalWindowRgn( (WindowRef) MacGetRootWindow() , updateRgn ) ; + // we also have to scroll the update rgn in this rectangle + // in order not to loose updates + WindowRef rootWindow = (WindowRef) MacGetRootWindow() ; + RgnHandle formerUpdateRgn = NewRgn() ; + RgnHandle scrollRgn = NewRgn() ; + RectRgn( scrollRgn , &scrollrect ) ; + GetWindowUpdateRgn( rootWindow , formerUpdateRgn ) ; + Point pt = {0,0} ; + LocalToGlobal( &pt ) ; + OffsetRgn( formerUpdateRgn , -pt.h , -pt.v ) ; + SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ; + if ( !EmptyRgn( formerUpdateRgn ) ) + { + MacOffsetRgn( formerUpdateRgn , dx , dy ) ; + SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ; + InvalWindowRgn(rootWindow , formerUpdateRgn ) ; + } + InvalWindowRgn(rootWindow , updateRgn ) ; DisposeRgn( updateRgn ) ; + DisposeRgn( formerUpdateRgn ) ; + DisposeRgn( scrollRgn ) ; } for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext()) @@ -1221,8 +1278,19 @@ void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) child->GetPosition( &x, &y ); int w,h; child->GetSize( &w, &h ); - child->SetSize( x+dx, y+dy, w, h ); + if (rect) + { + wxRect rc(x,y,w,h); + if (rect->Intersects(rc)) + child->SetSize( x+dx, y+dy, w, h ); + } + else + { + child->SetSize( x+dx, y+dy, w, h ); + } } + + Update() ; } @@ -1436,7 +1504,7 @@ bool wxWindowMac::MacSetupCursor( const wxPoint& pt) } bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent& event) -{ +{ if ((event.m_x < m_x) || (event.m_y < m_y) || (event.m_x > (m_x + m_width)) || (event.m_y > (m_y + m_height))) return FALSE; @@ -1523,17 +1591,34 @@ wxString wxWindowMac::MacGetToolTipString( wxPoint &pt ) void wxWindowMac::Update() { - wxTopLevelWindowMac* win = MacGetTopLevelWindow( ) ; - if ( win ) - { - win->MacUpdate( 0 ) ; + wxRegion visRgn = MacGetVisibleRegion( false ) ; + int top = 0 , left = 0 ; + MacWindowToRootWindow( &left , &top ) ; + WindowRef rootWindow = (WindowRef) MacGetRootWindow() ; + RgnHandle updateRgn = NewRgn() ; + // getting the update region in macos local coordinates + GetWindowUpdateRgn( rootWindow , updateRgn ) ; + GrafPtr port ; + ::GetPort( &port ) ; + ::SetPort( UMAGetWindowPort( rootWindow ) ) ; + Point pt = {0,0} ; + LocalToGlobal( &pt ) ; + ::SetPort( port ) ; + OffsetRgn( updateRgn , -pt.h , -pt.v ) ; + // translate to window local coordinates + OffsetRgn( updateRgn , -left , -top ) ; + SectRgn( updateRgn , (RgnHandle) visRgn.GetWXHRGN() , updateRgn ) ; + MacRedraw( updateRgn , 0 , true ) ; + // for flushing and validating we need macos-local coordinates again + OffsetRgn( updateRgn , left , top ) ; #if TARGET_API_MAC_CARBON - if ( QDIsPortBuffered( GetWindowPort( (WindowRef) win->MacGetWindowRef() ) ) ) - { - QDFlushPortBuffer( GetWindowPort( (WindowRef) win->MacGetWindowRef() ) , NULL ) ; - } + if ( QDIsPortBuffered( GetWindowPort( rootWindow ) ) ) + { + QDFlushPortBuffer( GetWindowPort( rootWindow ) , updateRgn ) ; + } #endif - } + ValidWindowRgn( rootWindow , updateRgn ) ; + DisposeRgn( updateRgn ) ; } wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const @@ -1553,92 +1638,101 @@ const wxRegion& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSibling RgnHandle tempRgn = NewRgn() ; RgnHandle tempStaticBoxRgn = NewRgn() ; - SetRectRgn( visRgn , 0 , 0 , m_width , m_height ) ; - - //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox - if ( IsKindOf( CLASSINFO( wxStaticBox ) ) ) + if ( MacIsReallyShown() ) { - int borderTop = 14 ; - int borderOther = 4 ; + SetRectRgn( visRgn , 0 , 0 , m_width , m_height ) ; - SetRectRgn( tempStaticBoxRgn , borderOther , borderTop , m_width - borderOther , m_height - borderOther ) ; - DiffRgn( visRgn , tempStaticBoxRgn , visRgn ) ; - } + //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox + if ( IsKindOf( CLASSINFO( wxStaticBox ) ) ) + { + int borderTop = 14 ; + int borderOther = 4 ; + if ( UMAGetSystemVersion() >= 0x1030 ) + borderTop += 2 ; - if ( !IsTopLevel() ) - { - wxWindow* parent = GetParent() ; - while( parent ) + SetRectRgn( tempStaticBoxRgn , borderOther , borderTop , m_width - borderOther , m_height - borderOther ) ; + DiffRgn( visRgn , tempStaticBoxRgn , visRgn ) ; + } + + if ( !IsTopLevel() ) { - wxSize size = parent->GetSize() ; - int x , y ; - x = y = 0 ; - parent->MacWindowToRootWindow( &x, &y ) ; - MacRootWindowToWindow( &x , &y ) ; - - SetRectRgn( tempRgn , - x + parent->MacGetLeftBorderSize() , y + parent->MacGetTopBorderSize() , - x + size.x - parent->MacGetRightBorderSize(), - y + size.y - parent->MacGetBottomBorderSize()) ; - - SectRgn( visRgn , tempRgn , visRgn ) ; - if ( parent->IsTopLevel() ) - break ; - parent = parent->GetParent() ; + wxWindow* parent = GetParent() ; + while( parent ) + { + wxSize size = parent->GetSize() ; + int x , y ; + x = y = 0 ; + parent->MacWindowToRootWindow( &x, &y ) ; + MacRootWindowToWindow( &x , &y ) ; + + SetRectRgn( tempRgn , + x + parent->MacGetLeftBorderSize() , y + parent->MacGetTopBorderSize() , + x + size.x - parent->MacGetRightBorderSize(), + y + size.y - parent->MacGetBottomBorderSize()) ; + + SectRgn( visRgn , tempRgn , visRgn ) ; + if ( parent->IsTopLevel() ) + break ; + parent = parent->GetParent() ; + } } - } - if ( respectChildrenAndSiblings ) - { - if ( GetWindowStyle() & wxCLIP_CHILDREN ) + if ( respectChildrenAndSiblings ) { - for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext()) + if ( GetWindowStyle() & wxCLIP_CHILDREN ) { - wxWindowMac *child = node->GetData(); - - if ( !child->IsTopLevel() && child->IsShown() ) + for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext()) { - SetRectRgn( tempRgn , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ; - if ( child->IsKindOf( CLASSINFO( wxStaticBox ) ) ) - { - int borderTop = 14 ; - int borderOther = 4 ; + wxWindowMac *child = node->GetData(); - SetRectRgn( tempStaticBoxRgn , child->m_x + borderOther , child->m_y + borderTop , child->m_x + child->m_width - borderOther , child->m_y + child->m_height - borderOther ) ; - DiffRgn( tempRgn , tempStaticBoxRgn , tempRgn ) ; + if ( !child->IsTopLevel() && child->IsShown() ) + { + SetRectRgn( tempRgn , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ; + if ( child->IsKindOf( CLASSINFO( wxStaticBox ) ) ) + { + int borderTop = 14 ; + int borderOther = 4 ; + if ( UMAGetSystemVersion() >= 0x1030 ) + borderTop += 2 ; + + SetRectRgn( tempStaticBoxRgn , child->m_x + borderOther , child->m_y + borderTop , child->m_x + child->m_width - borderOther , child->m_y + child->m_height - borderOther ) ; + DiffRgn( tempRgn , tempStaticBoxRgn , tempRgn ) ; + } + DiffRgn( visRgn , tempRgn , visRgn ) ; } - DiffRgn( visRgn , tempRgn , visRgn ) ; } } - } - if ( (GetWindowStyle() & wxCLIP_SIBLINGS) && GetParent() ) - { - bool thisWindowThrough = false ; - for (wxWindowListNode *node = GetParent()->GetChildren().GetFirst(); node; node = node->GetNext()) + if ( (GetWindowStyle() & wxCLIP_SIBLINGS) && GetParent() ) { - wxWindowMac *sibling = node->GetData(); - if ( sibling == this ) - { - thisWindowThrough = true ; - continue ; - } - if( !thisWindowThrough ) - { - continue ; - } - - if ( !sibling->IsTopLevel() && sibling->IsShown() ) + bool thisWindowThrough = false ; + for (wxWindowListNode *node = GetParent()->GetChildren().GetFirst(); node; node = node->GetNext()) { - SetRectRgn( tempRgn , sibling->m_x - m_x , sibling->m_y - m_y , sibling->m_x + sibling->m_width - m_x , sibling->m_y + sibling->m_height - m_y ) ; - if ( sibling->IsKindOf( CLASSINFO( wxStaticBox ) ) ) + wxWindowMac *sibling = node->GetData(); + if ( sibling == this ) + { + thisWindowThrough = true ; + continue ; + } + if( !thisWindowThrough ) { - int borderTop = 14 ; - int borderOther = 4 ; + continue ; + } - SetRectRgn( tempStaticBoxRgn , sibling->m_x - m_x + borderOther , sibling->m_y - m_y + borderTop , sibling->m_x + sibling->m_width - m_x - borderOther , sibling->m_y + sibling->m_height - m_y - borderOther ) ; - DiffRgn( tempRgn , tempStaticBoxRgn , tempRgn ) ; + if ( !sibling->IsTopLevel() && sibling->IsShown() ) + { + SetRectRgn( tempRgn , sibling->m_x - m_x , sibling->m_y - m_y , sibling->m_x + sibling->m_width - m_x , sibling->m_y + sibling->m_height - m_y ) ; + if ( sibling->IsKindOf( CLASSINFO( wxStaticBox ) ) ) + { + int borderTop = 14 ; + int borderOther = 4 ; + if ( UMAGetSystemVersion() >= 0x1030 ) + borderTop += 2 ; + + SetRectRgn( tempStaticBoxRgn , sibling->m_x - m_x + borderOther , sibling->m_y - m_y + borderTop , sibling->m_x + sibling->m_width - m_x - borderOther , sibling->m_y + sibling->m_height - m_y - borderOther ) ; + DiffRgn( tempRgn , tempStaticBoxRgn , tempRgn ) ; + } + DiffRgn( visRgn , tempRgn , visRgn ) ; } - DiffRgn( visRgn , tempRgn , visRgn ) ; } } } @@ -1691,10 +1785,32 @@ void wxWindowMac::MacRedraw( WXHRGN updatergnr , long time, bool erase) DisposeRgn( ownUpdateRgn ) ; if ( !m_updateRegion.Empty() ) { + wxWindowList hiddenWindows ; + for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext()) + { + wxControl *child = wxDynamicCast( ( wxWindow*)node->GetData() , wxControl ) ; + + if ( child && child->MacGetRootWindow() == window && child->IsShown() && child->GetMacControl() ) + { + SetControlVisibility( (ControlHandle) child->GetMacControl() , false , false ) ; + hiddenWindows.Append( child ) ; + } + } + wxPaintEvent event; event.m_timeStamp = time ; event.SetEventObject(this); GetEventHandler()->ProcessEvent(event); + + for (wxWindowListNode *node = hiddenWindows.GetFirst(); node; node = node->GetNext()) + { + wxControl *child = wxDynamicCast( ( wxWindow*)node->GetData() , wxControl ) ; + + if ( child && child->GetMacControl() ) + { + SetControlVisibility( (ControlHandle) child->GetMacControl() , true , false ) ; + } + } } }