X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/facd6764872eede45605ba7c9dfa0e1d0c708fa2..5fc01d1326a34223746546326a7f616df8bfa991:/src/mac/carbon/window.cpp?ds=sidebyside diff --git a/src/mac/carbon/window.cpp b/src/mac/carbon/window.cpp index d8de01b229..01521d2df9 100644 --- a/src/mac/carbon/window.cpp +++ b/src/mac/carbon/window.cpp @@ -53,9 +53,11 @@ #include #endif +#if TARGET_API_MAC_OSX #ifndef __HIVIEW__ #include #endif +#endif #if wxUSE_DRAG_AND_DROP #include "wx/dnd.h" @@ -103,9 +105,14 @@ pascal OSStatus wxMacSetupControlBackground( ControlRef iControl , SInt16 iMessa static const EventTypeSpec eventList[] = { #if TARGET_API_MAC_OSX - { kEventClassControl , kEventControlDraw } , + { kEventClassControl , kEventControlDraw } , + { kEventClassControl , kEventControlVisibilityChanged } , + { kEventClassControl , kEventControlEnabledStateChanged } , + { kEventClassControl , kEventControlHiliteChanged } , // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only // { kEventClassControl , kEventControlBoundsChanged } , + + {} #else {} #endif @@ -126,7 +133,19 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl { case kEventControlDraw : { - RgnHandle updateRgn = cEvent.GetParameter(kEventParamRgnHandle) ; + RgnHandle updateRgn = NULL ; + + wxRegion visRegion = thisWindow->MacGetVisibleRegion() ; + if ( cEvent.GetParameter(kEventParamRgnHandle, &updateRgn) != noErr ) + { + updateRgn = (RgnHandle) visRegion.GetWXHRGN() ; + } + else + { + // unfortunately this update region may be incorrect (tree ctrl sample ) + // so we have to reset it + updateRgn = (RgnHandle) visRegion.GetWXHRGN() ; + } // GrafPtr myport = cEvent.GetParameter(kEventParamGrafPort,typeGrafPtr) ; #if 0 // in case we would need a coregraphics compliant background erase first @@ -146,6 +165,15 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl result = eventNotHandledErr; } break ; + case kEventControlVisibilityChanged : + thisWindow->MacVisibilityChanged() ; + break ; + case kEventControlEnabledStateChanged : + thisWindow->MacEnabledStateChanged() ; + break ; + case kEventControlHiliteChanged : + thisWindow->MacHiliteChanged() ; + break ; default : break ; } @@ -673,8 +701,18 @@ void wxWindowMac::MacUpdateControlFont() fontStyle.size = m_font.MacGetFontSize() ; fontStyle.flags = kControlUseFontMask | kControlUseFaceMask | kControlUseSizeMask ; } + + fontStyle.just = teJustLeft ; + fontStyle.flags |= kControlUseJustMask ; + if ( ( GetWindowStyle() & wxALIGN_MASK ) & wxALIGN_CENTER_HORIZONTAL ) + fontStyle.just = teJustCenter ; + else if ( ( GetWindowStyle() & wxALIGN_MASK ) & wxALIGN_RIGHT ) + fontStyle.just = teJustRight ; + + fontStyle.foreColor = MAC_WXCOLORREF(GetForegroundColour().GetPixel() ) ; fontStyle.flags |= kControlUseForeColorMask ; + ::SetControlFontStyle( (ControlRef) m_macControl , &fontStyle ); Refresh() ; } @@ -1335,6 +1373,9 @@ void wxWindowMac::DoMoveWindow(int x, int y, int width, int height) wxSize wxWindowMac::DoGetBestSize() const { + if ( m_macIsUserPane || IsTopLevel() ) + return wxWindowBase::DoGetBestSize() ; + Rect bestsize = { 0 , 0 , 0 , 0 } ; short baselineoffset ; int bestWidth, bestHeight ; @@ -1366,6 +1407,7 @@ wxSize wxWindowMac::DoGetBestSize() const bestHeight = 13 ; return wxSize(bestWidth, bestHeight); +// return wxWindowBase::DoGetBestSize() ; } @@ -1388,7 +1430,7 @@ void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags) // ... and don't do anything (avoiding flicker) if it's already ok if ( x == currentX && y == currentY && - width == currentW && height == currentH ) + width == currentW && height == currentH && ( height != -1 && width != -1 ) ) { // TODO REMOVE MacRepositionScrollBars() ; // we might have a real position shift @@ -1487,8 +1529,44 @@ wxString wxWindowMac::GetTitle() const return m_label ; } +bool wxWindowMac::Show(bool show) +{ + if ( !wxWindowBase::Show(show) ) + return FALSE; + + // TODO use visibilityChanged Carbon Event for OSX + bool former = MacIsReallyShown() ; + + SetControlVisibility( (ControlRef) m_macControl , show , true ) ; + if ( former != MacIsReallyShown() ) + MacPropagateVisibilityChanged() ; + return TRUE; +} + +bool wxWindowMac::Enable(bool enable) +{ + wxASSERT( m_macControl != NULL ) ; + if ( !wxWindowBase::Enable(enable) ) + return FALSE; + + bool former = MacIsReallyEnabled() ; + if ( enable ) + EnableControl( (ControlRef) m_macControl ) ; + else + DisableControl( (ControlRef) m_macControl ) ; + + if ( former != MacIsReallyEnabled() ) + MacPropagateEnabledStateChanged() ; + return TRUE; +} + +// +// status change propagations (will be not necessary for OSX later ) +// + void wxWindowMac::MacPropagateVisibilityChanged() { +#if !TARGET_API_MAC_OSX MacVisibilityChanged() ; wxWindowListNode *node = GetChildren().GetFirst(); @@ -1499,22 +1577,61 @@ void wxWindowMac::MacPropagateVisibilityChanged() child->MacPropagateVisibilityChanged( ) ; node = node->GetNext(); } +#endif } -bool wxWindowMac::Show(bool show) +void wxWindowMac::MacPropagateEnabledStateChanged( ) { - if ( !wxWindowBase::Show(show) ) - return FALSE; +#if !TARGET_API_MAC_OSX + MacEnabledStateChanged() ; - // TODO use visibilityChanged Carbon Event for OSX - bool former = MacIsReallyShown() ; + wxWindowListNode *node = GetChildren().GetFirst(); + while ( node ) + { + wxWindowMac *child = node->GetData(); + if ( child->IsEnabled() ) + child->MacPropagateEnabledStateChanged() ; + node = node->GetNext(); + } +#endif +} + +void wxWindowMac::MacPropagateHiliteChanged( ) +{ +#if !TARGET_API_MAC_OSX + MacHiliteChanged() ; - SetControlVisibility( (ControlRef) m_macControl , show , true ) ; - if ( former != MacIsReallyShown() ) - MacPropagateVisibilityChanged() ; - return TRUE; + wxWindowListNode *node = GetChildren().GetFirst(); + while ( node ) + { + wxWindowMac *child = node->GetData(); + // if ( child->IsEnabled() ) + child->MacPropagateHiliteChanged() ; + node = node->GetNext(); + } +#endif +} + +// +// status change notifications +// + +void wxWindowMac::MacVisibilityChanged() +{ +} + +void wxWindowMac::MacHiliteChanged() +{ +} + +void wxWindowMac::MacEnabledStateChanged() +{ } +// +// status queries on the inherited window's state +// + bool wxWindowMac::MacIsReallyShown() { // only under OSX the visibility of the TLW is taken into account @@ -1536,50 +1653,20 @@ bool wxWindowMac::MacIsReallyShown() #endif } -void wxWindowMac::MacVisibilityChanged() -{ -} - -void wxWindowMac::MacPropagateEnabledStateChanged( ) -{ - MacEnabledStateChanged() ; - - wxWindowListNode *node = GetChildren().GetFirst(); - while ( node ) - { - wxWindowMac *child = node->GetData(); - if ( child->IsEnabled() ) - child->MacPropagateEnabledStateChanged() ; - node = node->GetNext(); - } -} - -bool wxWindowMac::Enable(bool enable) -{ - wxASSERT( m_macControl != NULL ) ; - if ( !wxWindowBase::Enable(enable) ) - return FALSE; - - bool former = MacIsReallyEnabled() ; - if ( enable ) - UMAActivateControl( (ControlRef) m_macControl ) ; - else - UMADeactivateControl( (ControlRef) m_macControl ) ; - - if ( former != MacIsReallyEnabled() ) - MacPropagateEnabledStateChanged() ; - return TRUE; -} - bool wxWindowMac::MacIsReallyEnabled() { return IsControlEnabled( (ControlRef) m_macControl ) ; } -void wxWindowMac::MacEnabledStateChanged() +bool wxWindowMac::MacIsReallyHilited() { + return IsControlActive( (ControlRef) m_macControl ) ; } +// +// +// + int wxWindowMac::GetCharHeight() const { wxClientDC dc ( (wxWindowMac*)this ) ; @@ -1620,7 +1707,15 @@ void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y, void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect) { #if TARGET_API_MAC_OSX - HIViewSetNeedsDisplay( (ControlRef) m_macControl , true ) ; + if ( rect == NULL ) + HIViewSetNeedsDisplay( (ControlRef) m_macControl , true ) ; + else + { + RgnHandle update = NewRgn() ; + SetRectRgn( update , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ; + SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , update , update ) ; + HIViewSetNeedsDisplayInRegion( (ControlRef) m_macControl , update , true ) ; + } #else if ( IsControlVisible( (ControlRef) m_macControl ) ) { @@ -1709,15 +1804,12 @@ void wxWindowMac::WarpPointer (int x_pos, int y_pos) void wxWindowMac::OnEraseBackground(wxEraseEvent& event) { - event.Skip() ; -/* if ( m_macBackgroundBrush.Ok() == false || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT ) { event.Skip() ; } else event.GetDC()->Clear() ; -*/ } void wxWindowMac::OnNcPaint( wxNcPaintEvent& event ) @@ -2184,7 +2276,9 @@ wxRegion wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures ) { int x , y ; wxSize size ; - if ( parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) ) + // we have to find a better clipping algorithm here, in order not to clip things + // positioned like status and toolbar + if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ ) { size = parent->GetSize() ; x = y = 0 ; @@ -2224,6 +2318,10 @@ wxRegion wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures ) */ bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr , long time ) { + // we let the OS handle root control redraws + if ( m_macControl == MacGetTopLevelWindow()->GetHandle() ) + return false ; + RgnHandle updatergn = (RgnHandle) updatergnr ; bool handled = false ; @@ -2562,7 +2660,6 @@ void wxWindowMac::OnMouseEvent( wxMouseEvent &event ) x += origin.x ; y += origin.y ; } - ControlRef control ; Point localwhere ; SInt16 controlpart ; @@ -2585,20 +2682,21 @@ void wxWindowMac::OnMouseEvent( wxMouseEvent &event ) if ( event.m_metaDown ) modifiers |= cmdKey ; + + bool handled = false ; + + if ( ::IsControlActive( (ControlRef) m_macControl ) ) { - control = (ControlRef) m_macControl ; - if ( control && ::IsControlActive( control ) ) + controlpart = ::HandleControlClick( (ControlRef) m_macControl , localwhere , modifiers , (ControlActionUPP) -1 ) ; + wxTheApp->s_lastMouseDown = 0 ; + if ( controlpart != kControlNoPart ) { - { - controlpart = ::HandleControlClick( control , localwhere , modifiers , (ControlActionUPP) -1 ) ; - wxTheApp->s_lastMouseDown = 0 ; - if ( control && controlpart != kControlNoPart ) - { - MacHandleControlClick((WXWidget) control , controlpart , false /* mouse not down anymore */ ) ; - } - } + MacHandleControlClick((WXWidget) (ControlRef) m_macControl , controlpart , false /* mouse not down anymore */ ) ; + handled = true ; } } + if ( !handled ) + event.Skip() ; } else { @@ -2611,4 +2709,13 @@ void wxWindowMac::MacHandleControlClick( WXWidget control , wxInt16 controlpart wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ; } +Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size ) +{ + int x ,y , w ,h ; + + window->MacGetBoundsForControl( pos , size , x , y, w, h ) ; + Rect bounds = { y , x , y+h , x+w }; + return bounds ; +} +