moving focus and border handling at one place, adding HITheme implementations, grow-box painting

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32062 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor 2005-02-15 06:15:22 +00:00
parent e2f9288358
commit c79aad8b24

View File

@ -240,15 +240,18 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
} }
} }
#endif #endif
{
#if wxMAC_USE_CORE_GRAPHICS #if wxMAC_USE_CORE_GRAPHICS
CGContextRef cgContext = cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef) ; CGContextRef cgContext = cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef) ;
thisWindow->MacSetCGContextRef( cgContext ) ; thisWindow->MacSetCGContextRef( cgContext ) ;
wxMacCGContextStateSaver sg( cgContext ) ;
#endif #endif
if ( thisWindow->MacDoRedraw( updateRgn , cEvent.GetTicks() ) ) if ( thisWindow->MacDoRedraw( updateRgn , cEvent.GetTicks() ) )
result = noErr ; result = noErr ;
#if wxMAC_USE_CORE_GRAPHICS #if wxMAC_USE_CORE_GRAPHICS
thisWindow->MacSetCGContextRef( NULL ) ; thisWindow->MacSetCGContextRef( NULL ) ;
#endif #endif
}
if ( allocatedRgn ) if ( allocatedRgn )
DisposeRgn( allocatedRgn ) ; DisposeRgn( allocatedRgn ) ;
} }
@ -1720,9 +1723,13 @@ void wxWindowMac::DoMoveWindow(int x, int y, int width, int height)
RectRgn( updateOuter , &rect ) ; RectRgn( updateOuter , &rect ) ;
DiffRgn( updateOuter , updateInner ,updateOuter ) ; DiffRgn( updateOuter , updateInner ,updateOuter ) ;
wxPoint parent(0,0); wxPoint parent(0,0);
#if TARGET_API_MAC_OSX
// no offsetting needed when compositing
#else
GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ; GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
parent -= GetParent()->GetClientAreaOrigin() ; parent -= GetParent()->GetClientAreaOrigin() ;
OffsetRgn( updateOuter , -parent.x , -parent.y ) ; OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
#endif
CopyRgn( updateOuter , updateTotal ) ; CopyRgn( updateOuter , updateTotal ) ;
rect = r ; rect = r ;
@ -2227,13 +2234,6 @@ void wxWindowMac::Thaw()
#endif #endif
} }
/* TODO
void wxWindowMac::OnPaint(wxPaintEvent& event)
{
// why don't we skip that here ?
}
*/
wxWindowMac *wxGetActiveWindow() wxWindowMac *wxGetActiveWindow()
{ {
// actually this is a windows-only concept // actually this is a windows-only concept
@ -2253,13 +2253,6 @@ void wxWindowMac::OnEraseBackground(wxEraseEvent& event)
{ {
event.Skip() ; event.Skip() ;
} }
else if ( m_macBackgroundBrush.MacGetBrushKind() == kwxMacBrushTheme )
{
if ( wxTheApp->MacGetCurrentEvent() != NULL && wxTheApp->MacGetCurrentEventHandlerCallRef() != NULL )
{
CallNextEventHandler((EventHandlerCallRef)wxTheApp->MacGetCurrentEventHandlerCallRef() , (EventRef) wxTheApp->MacGetCurrentEvent() ) ;
}
}
else else
#endif #endif
{ {
@ -2333,16 +2326,89 @@ void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh)
} }
} }
void wxWindowMac::MacPaintBorders( int left , int top ) //
// we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
// our own window origin is at leftOrigin/rightOrigin
//
void wxWindowMac::MacPaintBorders( int leftOrigin , int rightOrigin )
{ {
if( IsTopLevel() ) if( IsTopLevel() )
return ; return ;
Rect rect ; Rect rect ;
bool hasFocus = m_peer->NeedsFocusRect() && m_peer->HasFocus() ;
bool hasBothScrollbars = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;
m_peer->GetRect( &rect ) ; m_peer->GetRect( &rect ) ;
InsetRect( &rect, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ; InsetRect( &rect, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
if ( !IsTopLevel() ) #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
if ( HIThemeDrawFrame != 0)
{
Rect srect = rect ;
HIThemeFrameDrawInfo info ;
memset( &info, 0 , sizeof( info ) ) ;
info.version = 0 ;
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 ;
}
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 ) ;
HIThemeGrowBoxDrawInfo info ;
memset( &info, 0 , sizeof( info ) ) ;
info.version = 0 ;
info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ;
info.kind = kHIThemeGrowBoxKindNone ;
info.size = kHIThemeGrowBoxSizeNormal ;
info.direction = kThemeGrowRight | kThemeGrowDown ;
HIThemeDrawGrowBox( &cgpoint , &info , cgContext , kHIThemeOrientationNormal ) ;
}
}
else
#endif
{ {
wxTopLevelWindowMac* top = MacGetTopLevelWindow(); wxTopLevelWindowMac* top = MacGetTopLevelWindow();
if (top) if (top)
@ -2354,7 +2420,6 @@ void wxWindowMac::MacPaintBorders( int left , int top )
rect.top += pt.y ; rect.top += pt.y ;
rect.bottom += pt.y ; rect.bottom += pt.y ;
} }
}
if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) ) if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
{ {
@ -2372,6 +2437,18 @@ void wxWindowMac::MacPaintBorders( int left , int top )
InsetRect( &srect , border , border ); InsetRect( &srect , border , border );
DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
} }
if ( hasFocus )
{
Rect srect = rect ;
DrawThemeFocusRect( &srect , true ) ;
}
if ( hasBothScrollbars )
{
// GetThemeStandaloneGrowBoxBounds
//DrawThemeStandaloneNoGrowBox
}
}
} }
void wxWindowMac::RemoveChild( wxWindowBase *child ) void wxWindowMac::RemoveChild( wxWindowBase *child )
@ -2857,7 +2934,8 @@ bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr , long time )
Rect updatebounds ; Rect updatebounds ;
GetRegionBounds( updatergn , &updatebounds ) ; GetRegionBounds( updatergn , &updatebounds ) ;
// wxLogDebug("update for %s bounds %d , %d , %d , %d",typeid(*this).name() , updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ; // wxLogDebug(wxT("update for %s bounds %d , %d , %d , %d"),wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
if ( !EmptyRgn(updatergn) ) if ( !EmptyRgn(updatergn) )
{ {
RgnHandle newupdate = NewRgn() ; RgnHandle newupdate = NewRgn() ;
@ -2868,11 +2946,20 @@ bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr , long time )
// first send an erase event to the entire update area // first send an erase event to the entire update area
{ {
wxWindowDC dc(this); // for the toplevel window this really is the entire area
dc.SetClippingRegion(wxRegion(updatergn)); // for all the others only their client area, otherwise they
wxEraseEvent eevent( GetId(), &dc ); // might be drawing with full alpha and eg put blue into
// the grow-box area of a scrolled window (scroll sample)
wxDC* dc ;
if ( IsTopLevel() )
dc = new wxWindowDC(this);
else
dc = new wxClientDC(this);
dc->SetClippingRegion(wxRegion(updatergn));
wxEraseEvent eevent( GetId(), dc );
eevent.SetEventObject( this ); eevent.SetEventObject( this );
GetEventHandler()->ProcessEvent( eevent ); GetEventHandler()->ProcessEvent( eevent );
delete dc ;
} }
// calculate a client-origin version of the update rgn and set m_updateRegion to that // calculate a client-origin version of the update rgn and set m_updateRegion to that
@ -2905,78 +2992,40 @@ bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr , long time )
if (child->IsTopLevel()) continue; if (child->IsTopLevel()) continue;
if (!child->IsShown()) continue; if (!child->IsShown()) continue;
// only draw those in the update region (add a safety margin of 10 pixels for shadow effects
int x,y; int x,y;
child->GetPosition( &x, &y ); child->GetPosition( &x, &y );
int w,h; int w,h;
child->GetSize( &w, &h ); child->GetSize( &w, &h );
Rect childRect = { y , x , y + h , x + w } ; Rect childRect = { y , x , y + h , x + w } ;
OffsetRect( &childRect , clientOrigin.x , clientOrigin.y ) ; OffsetRect( &childRect , clientOrigin.x , clientOrigin.y ) ;
if ( child->MacGetTopBorderSize() ) InsetRect( &childRect , -10 , -10) ;
{
if ( RectInRgn( &childRect , updatergn ) ) if ( RectInRgn( &childRect , updatergn ) )
{ {
#if wxMAC_USE_CORE_GRAPHICS
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
if ( HIThemeDrawFrame )
{
Rect srect = childRect ;
HIThemeFrameDrawInfo info ;
info.version = 0 ;
info.kind = 0 ;
info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ;
if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
{
SInt32 border = 0 ;
GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ;
InsetRect( &srect , border , border );
info.kind = kHIThemeFrameTextFieldSquare ;
}
else if (HasFlag(wxSIMPLE_BORDER))
{
SInt32 border = 0 ;
GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
InsetRect( &srect , border , border );
info.kind = kHIThemeFrameListBox ;
}
CGRect rect = CGRectMake( srect.left , srect.top , srect.right - srect.left ,
srect.bottom - srect.top ) ;
HIThemeDrawFrame( &rect , &info , (CGContextRef) MacGetCGContextRef() , kHIThemeOrientationNormal ) ;
}
#endif
#else
// paint custom borders // paint custom borders
wxNcPaintEvent eventNc( child->GetId() ); wxNcPaintEvent eventNc( child->GetId() );
eventNc.SetEventObject( child ); eventNc.SetEventObject( child );
if ( !child->GetEventHandler()->ProcessEvent( eventNc ) ) if ( !child->GetEventHandler()->ProcessEvent( eventNc ) )
{ {
#if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
if ( HIThemeDrawFrame != 0)
{
child->MacPaintBorders(0,0) ;
}
else
#endif
{
#if !wxMAC_USE_CORE_GRAPHICS
wxWindowDC dc(this) ; wxWindowDC dc(this) ;
dc.SetClippingRegion(wxRegion(updatergn)); dc.SetClippingRegion(wxRegion(updatergn));
wxMacPortSetter helper(&dc) ; wxMacPortSetter helper(&dc) ;
child->MacPaintBorders( dc.m_macLocalOrigin.x + childRect.left , dc.m_macLocalOrigin.y + childRect.top) ; child->MacPaintBorders(0,0) ;
}
#endif #endif
} }
} }
if ( child->m_peer->NeedsFocusRect() && child->m_peer->HasFocus() )
{
#if wxMAC_USE_CORE_GRAPHICS
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
if ( HIThemeDrawFocusRect )
{
CGRect rect = CGRectMake( childRect.left , childRect.top , childRect.right - childRect.left ,
childRect.bottom - childRect.top ) ;
HIThemeDrawFocusRect( &rect , true , (CGContextRef) MacGetCGContextRef() , kHIThemeOrientationNormal ) ;
}
#endif
#else
wxWindowDC dc(this) ;
dc.SetClippingRegion(wxRegion(updatergn));
wxMacPortSetter helper(&dc) ;
Rect r = childRect ;
OffsetRect( &r , dc.m_macLocalOrigin.x , dc.m_macLocalOrigin.y ) ;
DrawThemeFocusRect( &r , true ) ;
#endif
} }
} }
} }
@ -3238,17 +3287,12 @@ void wxWindowMac::OnMouseEvent( wxMouseEvent &event )
} }
void wxWindowMac::OnPaint( wxPaintEvent & event ) void wxWindowMac::OnPaint( wxPaintEvent & event )
{
// in the other case we already have drawn from the OnEraseBackground Handler
if ( !m_macBackgroundBrush.Ok() || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT ||
m_macBackgroundBrush.MacGetBrushKind() != kwxMacBrushTheme )
{ {
if ( wxTheApp->MacGetCurrentEvent() != NULL && wxTheApp->MacGetCurrentEventHandlerCallRef() != NULL ) if ( wxTheApp->MacGetCurrentEvent() != NULL && wxTheApp->MacGetCurrentEventHandlerCallRef() != NULL )
{ {
CallNextEventHandler((EventHandlerCallRef)wxTheApp->MacGetCurrentEventHandlerCallRef() , (EventRef) wxTheApp->MacGetCurrentEvent() ) ; CallNextEventHandler((EventHandlerCallRef)wxTheApp->MacGetCurrentEventHandlerCallRef() , (EventRef) wxTheApp->MacGetCurrentEvent() ) ;
} }
} }
}
void wxWindowMac::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) ) void wxWindowMac::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) )
{ {