From bc5c09a3aa3662137da2d781c0b101a598d2650d Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Fri, 16 Apr 2010 06:18:16 +0000 Subject: [PATCH] translating background style BG_PAINT into opaqueness for speed-up of OS redraws, supporting positioning for native carbon controls also on non-composited windows (custom pane in navservices dialogs) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63988 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/osx/carbon/private.h | 1 + include/wx/osx/cocoa/private.h | 1 + include/wx/osx/core/private.h | 1 + include/wx/osx/window.h | 2 ++ src/osx/carbon/window.cpp | 40 ++++++++++++++++++++++++++++++++- src/osx/cocoa/window.mm | 21 ++++++++++++++++- src/osx/window_osx.cpp | 10 +++++++++ 7 files changed, 74 insertions(+), 2 deletions(-) diff --git a/include/wx/osx/carbon/private.h b/include/wx/osx/carbon/private.h index ab9ac47ed4..2f41341999 100644 --- a/include/wx/osx/carbon/private.h +++ b/include/wx/osx/carbon/private.h @@ -433,6 +433,7 @@ public : virtual void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle, bool ignoreBlack = true ); virtual void SetBackgroundColour( const wxColour& col ); + virtual bool SetBackgroundStyle(wxBackgroundStyle style); virtual ControlPartCode HandleKey( SInt16 keyCode, SInt16 charCode, EventModifiers modifiers ); void SetActionProc( ControlActionUPP actionProc ); SInt32 GetViewSize() const; diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h index 893aba3ac2..95d4665637 100644 --- a/include/wx/osx/cocoa/private.h +++ b/include/wx/osx/cocoa/private.h @@ -101,6 +101,7 @@ public : virtual WXWidget GetWXWidget() const { return m_osxView; } virtual void SetBackgroundColour(const wxColour&); + virtual bool SetBackgroundStyle(wxBackgroundStyle style); virtual void GetContentArea( int &left , int &top , int &width , int &height ) const; virtual void Move(int x, int y, int width, int height); diff --git a/include/wx/osx/core/private.h b/include/wx/osx/core/private.h index b3ff76448d..2546818682 100644 --- a/include/wx/osx/core/private.h +++ b/include/wx/osx/core/private.h @@ -215,6 +215,7 @@ public : virtual WXWidget GetWXWidget() const = 0; virtual void SetBackgroundColour( const wxColour& col ) = 0; + virtual bool SetBackgroundStyle(wxBackgroundStyle style) = 0; // all coordinates in native parent widget relative coordinates virtual void GetContentArea( int &left , int &top , int &width , int &height ) const = 0; diff --git a/include/wx/osx/window.h b/include/wx/osx/window.h index 9f5b7ae7bf..54446478ad 100644 --- a/include/wx/osx/window.h +++ b/include/wx/osx/window.h @@ -91,6 +91,8 @@ public: virtual bool SetBackgroundColour( const wxColour &colour ); virtual bool SetForegroundColour( const wxColour &colour ); + virtual bool SetBackgroundStyle(wxBackgroundStyle style); + virtual int GetCharHeight() const; virtual int GetCharWidth() const; diff --git a/src/osx/carbon/window.cpp b/src/osx/carbon/window.cpp index cab7af9aad..7545767b41 100644 --- a/src/osx/carbon/window.cpp +++ b/src/osx/carbon/window.cpp @@ -970,7 +970,17 @@ void wxMacControl::GetContentArea(int &left , int &top , int &width , int &heigh void wxMacControl::Move(int x, int y, int width, int height) { + UInt32 attr = 0 ; + GetWindowAttributes( GetControlOwner(m_controlRef) , &attr ) ; + HIRect hir = CGRectMake(x,y,width,height); + if ( !(attr & kWindowCompositingAttribute) ) + { + HIRect parent; + HIViewGetFrame( HIViewGetSuperview(m_controlRef), &parent ); + hir.origin.x += parent.origin.x; + hir.origin.y += parent.origin.y; + } HIViewSetFrame ( m_controlRef , &hir ); } @@ -980,6 +990,18 @@ void wxMacControl::GetPosition( int &x, int &y ) const GetControlBounds( m_controlRef , &r ); x = r.left; y = r.top; + + UInt32 attr = 0 ; + GetWindowAttributes( GetControlOwner(m_controlRef) , &attr ) ; + + if ( !(attr & kWindowCompositingAttribute) ) + { + HIRect parent; + HIViewGetFrame( HIViewGetSuperview(m_controlRef), &parent ); + x -= parent.origin.x; + y -= parent.origin.y; + } + } void wxMacControl::GetSize( int &width, int &height ) const @@ -1324,6 +1346,22 @@ void wxMacControl::SetBackgroundColour( const wxColour &WXUNUSED(col) ) // HITextViewSetBackgroundColor( m_textView , color ); } +bool wxMacControl::SetBackgroundStyle(wxBackgroundStyle style) +{ + if ( style != wxBG_STYLE_PAINT ) + { + OSStatus err = HIViewChangeFeatures(m_controlRef , 0 , kHIViewIsOpaque); + verify_noerr( err ); + } + else + { + OSStatus err = HIViewChangeFeatures(m_controlRef , kHIViewIsOpaque , 0); + verify_noerr( err ); + } + + return true ; +} + void wxMacControl::SetRange( SInt32 minimum , SInt32 maximum ) { ::SetControl32BitMinimum( m_controlRef , minimum ); @@ -1393,7 +1431,7 @@ void wxMacControl::GetRectInWindowCoords( Rect *r ) OffsetRect( r , (short) hiPoint.x , (short) hiPoint.y ) ; } } - + void wxMacControl::GetBestRect( wxRect *rect ) const { short baselineoffset; diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index 6acdec29ee..195d789478 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -131,6 +131,7 @@ NSRect wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const - (void)setAction:(SEL)aSelector; - (void)setDoubleAction:(SEL)aSelector; - (void)setBackgroundColor:(NSColor*)aColor; +- (void)setOpaque:(BOOL)opaque; - (void)setTextColor:(NSColor *)color; - (void)setImagePosition:(NSCellImagePosition)aPosition; @end @@ -1690,6 +1691,18 @@ void wxWidgetCocoaImpl::SetBackgroundColour( const wxColour &col ) } } +bool wxWidgetCocoaImpl::SetBackgroundStyle( wxBackgroundStyle style ) +{ + BOOL opaque = ( style == wxBG_STYLE_PAINT ); + + if ( [m_osxView respondsToSelector:@selector(setOpaque:) ] ) + { + [m_osxView setOpaque: opaque]; + } + + return true ; +} + void wxWidgetCocoaImpl::SetLabel( const wxString& title, wxFontEncoding encoding ) { if ( [m_osxView respondsToSelector:@selector(setTitle:) ] ) @@ -2088,7 +2101,13 @@ wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now ) wxWidgetCocoaImpl* c = NULL; if ( now->IsNativeWindowWrapper() ) { - c = new wxWidgetCocoaImpl( now, [tlw contentView], true ); + NSView* cv = [tlw contentView]; + c = new wxWidgetCocoaImpl( now, cv, true ); + // increase ref count, because the impl destructor will decrement it again + CFRetain(cv); + if ( !now->IsShown() ) + [cv setHidden:NO]; + } else { diff --git a/src/osx/window_osx.cpp b/src/osx/window_osx.cpp index 04e3a9e127..9625a70906 100644 --- a/src/osx/window_osx.cpp +++ b/src/osx/window_osx.cpp @@ -472,6 +472,16 @@ bool wxWindowMac::SetForegroundColour(const wxColour& col ) return retval; } +bool wxWindowMac::SetBackgroundStyle(wxBackgroundStyle style) +{ + if ( !wxWindowBase::SetBackgroundStyle(style) ) + return false; + + if ( m_peer ) + m_peer->SetBackgroundStyle(style); + return true; +} + bool wxWindowMac::SetBackgroundColour(const wxColour& col ) { if (m_growBox) -- 2.45.2