X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3083eb85df678aaeac65b9f8bcd9c9a465527e49..7368be43c35fbdfc5cecb190a5d299f173866b37:/src/mac/carbon/window.cpp diff --git a/src/mac/carbon/window.cpp b/src/mac/carbon/window.cpp index 808db5c2be..0d5bf2fab7 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" @@ -64,7 +66,6 @@ #include extern wxList wxPendingDelete; -wxWindowMac* gFocusWindow = NULL ; #ifdef __WXUNIVERSAL__ IMPLEMENT_ABSTRACT_CLASS(wxWindowMac, wxWindowBase) @@ -80,7 +81,7 @@ BEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase) // TODO EVT_PAINT(wxWindowMac::OnPaint) EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged) EVT_INIT_DIALOG(wxWindowMac::OnInitDialog) - EVT_SET_FOCUS(wxWindowMac::OnSetFocus) +// EVT_SET_FOCUS(wxWindowMac::OnSetFocus) EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent) END_EVENT_TABLE() @@ -100,14 +101,27 @@ END_EVENT_TABLE() extern long wxMacTranslateKey(unsigned char key, unsigned char code) ; pascal OSStatus wxMacSetupControlBackground( ControlRef iControl , SInt16 iMessage , SInt16 iDepth , Boolean iIsColor ) ; +#if TARGET_API_MAC_OSX + +#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3 +enum { + kEventControlVisibilityChanged = 157 +}; +#endif + +#endif + static const EventTypeSpec eventList[] = { + { kEventClassControl , kEventControlHit } , #if TARGET_API_MAC_OSX - { kEventClassControl , kEventControlDraw } , + { kEventClassControl , kEventControlDraw } , + { kEventClassControl , kEventControlVisibilityChanged } , + { kEventClassControl , kEventControlEnabledStateChanged } , + { kEventClassControl , kEventControlHiliteChanged } , + { kEventClassControl , kEventControlSetFocusPart } , // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only // { kEventClassControl , kEventControlBoundsChanged } , -#else - {} #endif } ; @@ -124,26 +138,96 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl switch( GetEventKind( event ) ) { +#if TARGET_API_MAC_OSX case kEventControlDraw : { - RgnHandle updateRgn = cEvent.GetParameter(kEventParamRgnHandle) ; + RgnHandle updateRgn = NULL ; + + wxRegion visRegion = thisWindow->MacGetVisibleRegion() ; + if ( cEvent.GetParameter(kEventParamRgnHandle, &updateRgn) != noErr ) + { + updateRgn = (RgnHandle) visRegion.GetWXHRGN() ; + } // GrafPtr myport = cEvent.GetParameter(kEventParamGrafPort,typeGrafPtr) ; -#if 0 // in case we would need a coregraphics compliant background erase first +#if 0 + // in case we would need a coregraphics compliant background erase first + // now usable to track redraws CGContextRef cgContext = cEvent.GetParameter(kEventParamCGContextRef) ; if ( thisWindow->MacIsUserPane() ) { + static float color = 0.5 ; + static channel = 0 ; HIRect bounds; - err = HIViewGetBounds( controlRef, &bounds ); - CGContextSetRGBFillColor( cgContext, 1 , 1 , 1 , 1 ); -// CGContextSetRGBFillColor( cgContext, .95, .95, .95, 1 ); + HIViewGetBounds( controlRef, &bounds ); + CGContextSetRGBFillColor( cgContext, channel == 0 ? color : 0.5 , + channel == 1 ? color : 0.5 , channel == 2 ? color : 0.5 , 1 ); CGContextFillRect( cgContext, bounds ); + color += 0.1 ; + if ( color > 0.9 ) + { + color = 0.5 ; + channel++ ; + if ( channel == 3 ) + channel = 0 ; + } } #endif if ( thisWindow->MacDoRedraw( updateRgn , cEvent.GetTicks() ) ) result = noErr ; + } + break ; + case kEventControlVisibilityChanged : + thisWindow->MacVisibilityChanged() ; + break ; + case kEventControlEnabledStateChanged : + thisWindow->MacEnabledStateChanged() ; + break ; + case kEventControlHiliteChanged : + thisWindow->MacHiliteChanged() ; + break ; + case kEventControlSetFocusPart : + { + Boolean focusEverything = false ; + ControlPartCode controlPart = cEvent.GetParameter(kEventParamControlPart , typeControlPartCode ); + if ( cEvent.GetParameter(kEventParamControlFocusEverything , &focusEverything ) == noErr ) + { + } + if ( controlPart == kControlFocusNoPart ) + { + #if wxUSE_CARET + if ( thisWindow->GetCaret() ) + { + thisWindow->GetCaret()->OnKillFocus(); + } + #endif // wxUSE_CARET + wxFocusEvent event(wxEVT_KILL_FOCUS, thisWindow->GetId()); + event.SetEventObject(thisWindow); + thisWindow->GetEventHandler()->ProcessEvent(event) ; + } else - result = eventNotHandledErr; + { + // panel wants to track the window which was the last to have focus in it + wxChildFocusEvent eventFocus(thisWindow); + thisWindow->GetEventHandler()->ProcessEvent(eventFocus); + + #if wxUSE_CARET + if ( thisWindow->GetCaret() ) + { + thisWindow->GetCaret()->OnSetFocus(); + } + #endif // wxUSE_CARET + + wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId()); + event.SetEventObject(thisWindow); + thisWindow->GetEventHandler()->ProcessEvent(event) ; + } + } + break ; +#endif + case kEventControlHit : + { + result = thisWindow->MacControlHit( handler , event ) ; } break ; default : @@ -231,7 +315,12 @@ static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, Contro void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part) { - MacDoRedraw( MacGetVisibleRegion().GetWXHRGN() , 0 ) ; + RgnHandle rgn = NewRgn() ; + GetClip( rgn ) ; + wxMacWindowStateSaver sv( this ) ; + SectRgn( rgn , (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , rgn ) ; + MacDoRedraw( rgn , 0 ) ; + DisposeRgn( rgn ) ; } wxInt16 wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) @@ -382,7 +471,10 @@ pascal void wxMacLiveScrollbarActionProc( ControlRef control , ControlPartCode p void wxWindowMac::Init() { + m_frozenness = 0 ; +#if WXWIN_COMPATIBILITY_2_4 m_backgroundTransparent = FALSE; +#endif // as all windows are created with WS_VISIBLE style... m_isShown = TRUE; @@ -418,6 +510,8 @@ void wxWindowMac::Init() wxMacSetupControlBackgroundUPP = NewControlColorUPP( wxMacSetupControlBackground ) ; } + // we need a valid font for the encodings + wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); } // Destructor @@ -473,11 +567,6 @@ wxWindowMac::~wxWindowMac() frame->SetLastFocus( NULL ) ; } - if ( gFocusWindow == this ) - { - gFocusWindow = NULL ; - } - DestroyChildren(); // delete our drop target if we've got one @@ -494,6 +583,7 @@ wxWindowMac::~wxWindowMac() void wxWindowMac::MacInstallEventHandler() { + wxAssociateControlWithMacControl( (ControlRef) m_macControl , this ) ; InstallControlEventHandler( (ControlRef) m_macControl, GetwxMacWindowEventHandlerUPP(), GetEventTypeCount(eventList), eventList, this, (EventHandlerRef *)&m_macControlEventHandler); @@ -520,9 +610,10 @@ bool wxWindowMac::Create(wxWindowMac *parent, wxWindowID id, { Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; - UInt32 features = kControlSupportsEmbedding | kControlSupportsLiveFeedback /*| kControlHasSpecialBackground */ | kControlSupportsCalcBestRect | kControlHandlesTracking | kControlSupportsFocus | kControlWantsActivate | kControlWantsIdle; + UInt32 features = kControlSupportsEmbedding | kControlSupportsLiveFeedback | kControlHasSpecialBackground | + kControlSupportsCalcBestRect | kControlHandlesTracking | kControlSupportsFocus | kControlWantsActivate | kControlWantsIdle; - ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds, features, (ControlRef*) &m_macControl); + ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds, kControlSupportsEmbedding , (ControlRef*) &m_macControl); MacPostControlCreate(pos,size) ; #if !TARGET_API_MAC_OSX @@ -563,7 +654,6 @@ void wxWindowMac::MacPostControlCreate(const wxPoint& pos, const wxSize& size) { wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ; - wxAssociateControlWithMacControl( (ControlRef) m_macControl , this ) ; ::SetControlReference( (ControlRef) m_macControl , (long) this ) ; MacInstallEventHandler(); @@ -603,9 +693,14 @@ void wxWindowMac::MacPostControlCreate(const wxPoint& pos, const wxSize& size) void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant ) { - wxASSERT( m_macControl != NULL ) ; + // Don't assert, in case we set the window variant before + // the window is created + // wxASSERT( m_macControl != NULL ) ; + + m_windowVariant = variant ; - m_windowVariant = variant ; + if (!m_macControl) + return; ControlSize size ; ThemeFontID themeFont = kThemeSystemFont ; @@ -673,8 +768,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() ; } @@ -726,73 +831,59 @@ bool wxWindowMac::SetBackgroundColour(const wxColour& col ) bool wxWindowMac::MacCanFocus() const { - wxASSERT( m_macControl != NULL ) ; - - return true ; +#if 0 + // there is currently no way to determinate whether the window is running in full keyboard + // access mode, therefore we cannot rely on these features yet + UInt32 features = 0 ; + GetControlFeatures( (ControlRef) m_macControl , &features ) ; + return features & ( kControlSupportsFocus | kControlGetsFocusOnClick ) ; +#endif + return true ; } void wxWindowMac::SetFocus() { - if ( gFocusWindow == this ) - return ; - if ( AcceptsFocus() ) { - if (gFocusWindow ) - { -#if wxUSE_CARET - // Deal with caret - if ( gFocusWindow->m_caret ) - { - gFocusWindow->m_caret->OnKillFocus(); - } -#endif // wxUSE_CARET -#ifndef __WXUNIVERSAL__ - wxWindow* control = wxDynamicCast( gFocusWindow , wxWindow ) ; - // TODO we must use the built-in focusing - if ( control && control->GetHandle() /* && control->MacIsReallyShown() */ ) - { - UMASetKeyboardFocus( (WindowRef) gFocusWindow->MacGetTopLevelWindowRef() , (ControlRef) control->GetHandle() , kControlFocusNoPart ) ; - control->MacRedrawControl() ; - } +#if !TARGET_API_MAC_OSX + wxWindow* former = FindFocus() ; #endif - // Without testing the window id, for some reason - // a kill focus event can still be sent to - // the control just being focussed. - int thisId = this->m_windowId; - int gFocusWindowId = gFocusWindow->m_windowId; - if (gFocusWindowId != thisId) - { - wxFocusEvent event(wxEVT_KILL_FOCUS, gFocusWindow->m_windowId); - event.SetEventObject(gFocusWindow); - gFocusWindow->GetEventHandler()->ProcessEvent(event) ; - } + OSStatus err = SetKeyboardFocus( (WindowRef) MacGetTopLevelWindowRef() , (ControlRef) GetHandle() , kControlFocusNextPart ) ; + // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only + // leave in case of an error + if ( err == errCouldntSetFocus ) + return ; + +#if !TARGET_API_MAC_OSX + // emulate carbon events when running under carbonlib where they are not natively available + if ( former ) + { + EventRef evRef = NULL ; + verify_noerr( MacCreateEvent( NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) , kEventAttributeUserEvent , + &evRef ) ); + + wxMacCarbonEvent cEvent( evRef ) ; + cEvent.SetParameter( kEventParamDirectObject , (ControlRef) former->GetHandle() ) ; + cEvent.SetParameter(kEventParamControlPart , typeControlPartCode , kControlFocusNoPart ) ; + + wxMacWindowEventHandler( NULL , evRef , former ) ; + ReleaseEvent(evRef) ; } - gFocusWindow = this ; + // send new focus event { - #if wxUSE_CARET - // Deal with caret - if ( m_caret ) - { - m_caret->OnSetFocus(); - } - #endif // wxUSE_CARET - // panel wants to track the window which was the last to have focus in it - wxChildFocusEvent eventFocus(this); - GetEventHandler()->ProcessEvent(eventFocus); - - #ifndef __WXUNIVERSAL__ - wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ; - if ( control && control->GetHandle() ) - { - UMASetKeyboardFocus( (WindowRef) gFocusWindow->MacGetTopLevelWindowRef() , (ControlRef) control->GetHandle() , kControlFocusNextPart ) ; - } - #endif - wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId); - event.SetEventObject(this); - GetEventHandler()->ProcessEvent(event) ; + EventRef evRef = NULL ; + verify_noerr( MacCreateEvent( NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) , kEventAttributeUserEvent , + &evRef ) ); + + wxMacCarbonEvent cEvent( evRef ) ; + cEvent.SetParameter( kEventParamDirectObject , (ControlRef) GetHandle() ) ; + cEvent.SetParameter(kEventParamControlPart , typeControlPartCode , kControlFocusNextPart ) ; + + wxMacWindowEventHandler( NULL , evRef , this ) ; + ReleaseEvent(evRef) ; } +#endif } } @@ -852,10 +943,10 @@ void wxWindowMac::MacGetPositionAndSizeFromControl(int& x, int& y, { Point tlworigin = { 0 , 0 } ; GrafPtr port ; - ::GetPort( &port ) ; - ::SetPort( UMAGetWindowPort( (WindowRef) tlw->MacGetWindowRef() ) ) ; + bool swapped = QDSwapPort( UMAGetWindowPort( (WindowRef) tlw->MacGetWindowRef() ) , &port ) ; ::LocalToGlobal( &tlworigin ) ; - ::SetPort( port ) ; + if ( swapped ) + ::SetPort( port ) ; x = tlworigin.h ; y = tlworigin.v ; } @@ -864,7 +955,7 @@ void wxWindowMac::MacGetPositionAndSizeFromControl(int& x, int& y, bool wxWindowMac::MacGetBoundsForControl(const wxPoint& pos, const wxSize& size, int& x, int& y, - int& w, int& h) const + int& w, int& h , bool adjustOrigin ) const { x = (int)pos.x; y = (int)pos.y; @@ -874,7 +965,8 @@ bool wxWindowMac::MacGetBoundsForControl(const wxPoint& pos, #if !TARGET_API_MAC_OSX GetParent()->MacWindowToRootWindow( &x , &y ) ; #endif - + if ( adjustOrigin ) + AdjustForParentClientOrigin( x , y ) ; return true ; } @@ -1010,7 +1102,8 @@ void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const if ( x ) pt.x = *x ; if ( y ) pt.y = *y ; - HIViewConvertPoint( &pt , (ControlRef) m_macControl , (ControlRef) MacGetTopLevelWindow()->GetHandle() ) ; + if ( !IsTopLevel() ) + HIViewConvertPoint( &pt , (ControlRef) m_macControl , (ControlRef) MacGetTopLevelWindow()->GetHandle() ) ; if ( x ) *x = (int) pt.x ; if ( y ) *y = (int) pt.y ; @@ -1042,7 +1135,8 @@ void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const if ( x ) pt.x = *x ; if ( y ) pt.y = *y ; - HIViewConvertPoint( &pt , (ControlRef) MacGetTopLevelWindow()->GetHandle() , (ControlRef) m_macControl ) ; + if ( !IsTopLevel() ) + HIViewConvertPoint( &pt , (ControlRef) MacGetTopLevelWindow()->GetHandle() , (ControlRef) m_macControl ) ; if ( x ) *x = (int) pt.x ; if ( y ) *y = (int) pt.y ; @@ -1067,6 +1161,30 @@ void wxWindowMac::MacRootWindowToWindow( short *x , short *y ) const if ( y ) *y = y1 ; } +void wxWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , int &bottom ) +{ + RgnHandle rgn = NewRgn() ; + Rect content ; + if ( GetControlRegion( (ControlRef) m_macControl , kControlContentMetaPart , rgn ) == noErr ) + { + GetRegionBounds( rgn , &content ) ; + DisposeRgn( rgn ) ; + } + else + { + GetControlBounds( (ControlRef) m_macControl , &content ) ; + } + Rect structure ; + GetControlBounds( (ControlRef) m_macControl , &structure ) ; +#if !TARGET_API_MAC_OSX + OffsetRect( &content , -structure.left , -structure.top ) ; +#endif + left = content.left - structure.left ; + top = content.top - structure.top ; + right = structure.right - content.right ; + bottom = structure.bottom - content.bottom ; +} + wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const { wxSize sizeTotal = size; @@ -1304,14 +1422,23 @@ void wxWindowMac::DoMoveWindow(int x, int y, int width, int height) if ( doMove || doResize ) { - Rect r = wxMacGetBoundsForControl(this , wxPoint( actualX,actualY), wxSize( actualWidth, actualHeight ) ) ; + // we don't adjust twice for the origin + Rect r = wxMacGetBoundsForControl(this , wxPoint( actualX,actualY), wxSize( actualWidth, actualHeight ) , false ) ; + bool vis = IsControlVisible( (ControlRef) m_macControl ) ; #if TARGET_API_MAC_OSX - SetControlBounds( (ControlRef) m_macControl , &r ) ; + // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not ! + if ( vis ) + SetControlVisibility( (ControlRef)m_macControl , false , true ) ; + HIRect hir = { r.left , r.top , r.right - r.left , r.bottom - r.top } ; + HIViewSetFrame ( (ControlRef) m_macControl , &hir ) ; + if ( vis ) + SetControlVisibility( (ControlRef)m_macControl , true , true ) ; #else - if ( doMove ) - MoveControl( (ControlRef) m_macControl , r.left , r.top ) ; - if ( doSize ) - SizeControl( (ControlRef) m_macControl , r.right-r.left , r.bottom-r.top ) ; + if ( vis ) + SetControlVisibility( (ControlRef)m_macControl , false , true ) ; + SetControlBounds( (ControlRef) m_macControl , &r ) ; + if ( vis ) + SetControlVisibility( (ControlRef)m_macControl , true , true ) ; #endif MacRepositionScrollBars() ; if ( doMove ) @@ -1335,6 +1462,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 +1496,7 @@ wxSize wxWindowMac::DoGetBestSize() const bestHeight = 13 ; return wxSize(bestWidth, bestHeight); +// return wxWindowBase::DoGetBestSize() ; } @@ -1388,7 +1519,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 +1618,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 +1666,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 +1742,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,8 +1796,32 @@ 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 ) ; + wxPoint origin = GetClientAreaOrigin() ; + OffsetRgn( update, origin.x , origin.y ) ; + HIViewSetNeedsDisplayInRegion( (ControlRef) m_macControl , update , true ) ; + } #else +/* + RgnHandle updateRgn = NewRgn() ; + if ( rect == NULL ) + { + CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ; + } + else + { + SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ; + SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ; + } + InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ; + DisposeRgn(updateRgn) ; +*/ if ( IsControlVisible( (ControlRef) m_macControl ) ) { SetControlVisibility( (ControlRef) m_macControl , false , false ) ; @@ -1670,6 +1870,51 @@ void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect) #endif } +void wxWindowMac::Freeze() +{ +#if TARGET_API_MAC_OSX + if ( !m_frozenness++ ) + { + HIViewSetDrawingEnabled( (HIViewRef) m_macControl , false ) ; + } +#endif +} + +#if TARGET_API_MAC_OSX +static void InvalidateControlAndChildren( HIViewRef control ) +{ + HIViewSetNeedsDisplay( control , true ) ; + UInt16 childrenCount = 0 ; + OSStatus err = CountSubControls( control , &childrenCount ) ; + if ( err == errControlIsNotEmbedder ) + return ; + wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ; + + for ( UInt16 i = childrenCount ; i >=1 ; --i ) + { + HIViewRef child ; + err = GetIndexedSubControl( control , i , & child ) ; + if ( err == errControlIsNotEmbedder ) + return ; + InvalidateControlAndChildren( child ) ; + } +} +#endif + +void wxWindowMac::Thaw() +{ +#if TARGET_API_MAC_OSX + wxASSERT_MSG( m_frozenness > 0, _T("Thaw() without matching Freeze()") ); + + if ( !--m_frozenness ) + { + HIViewSetDrawingEnabled( (HIViewRef) m_macControl , true ) ; + InvalidateControlAndChildren( (HIViewRef) m_macControl ) ; + // HIViewSetNeedsDisplay( (HIViewRef) m_macControl , true ) ; + } +#endif +} + void wxWindowMac::MacRedrawControl() { /* @@ -1709,15 +1954,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 ) @@ -2042,7 +2284,9 @@ void wxWindowMac::MacOnScroll(wxScrollEvent &event ) // Get the window with the focus wxWindowMac *wxWindowBase::FindFocus() { - return gFocusWindow ; + ControlRef control ; + GetKeyboardFocus( GetUserFocusWindow() , &control ) ; + return wxFindControlFromMacControl( control ) ; } void wxWindowMac::OnSetFocus(wxFocusEvent& event) @@ -2072,11 +2316,17 @@ void wxWindowMac::OnInternalIdle() // Raise the window to the top of the Z order void wxWindowMac::Raise() { +#if TARGET_API_MAC_OSX + HIViewSetZOrder((ControlRef)m_macControl,kHIViewZOrderAbove, NULL) ; +#endif } // Lower the window to the bottom of the Z order void wxWindowMac::Lower() { +#if TARGET_API_MAC_OSX + HIViewSetZOrder((ControlRef)m_macControl,kHIViewZOrderBelow, NULL) ; +#endif } @@ -2184,7 +2434,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 ; @@ -2544,62 +2796,6 @@ void wxWindowMac::OnMouseEvent( wxMouseEvent &event ) if ( ! GetEventHandler()->ProcessEvent(evtCtx) ) event.Skip() ; } - else if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK ) - { - - int x = event.m_x ; - int y = event.m_y ; - - if ( MacGetTopLevelWindow()->MacUsesCompositing() == false ) - { - // OS Needs it in tlw content area coordinates - MacClientToRootWindow( &x , &y ) ; - } - else - { - // OS Needs it in window not client coordinates - wxPoint origin = GetClientAreaOrigin() ; - x += origin.x ; - y += origin.y ; - } - ControlRef control ; - Point localwhere ; - SInt16 controlpart ; - - localwhere.h = x ; - localwhere.v = y ; - - short modifiers = 0; - - if ( !event.m_leftDown && !event.m_rightDown ) - modifiers |= btnState ; - - if ( event.m_shiftDown ) - modifiers |= shiftKey ; - - if ( event.m_controlDown ) - modifiers |= controlKey ; - - if ( event.m_altDown ) - modifiers |= optionKey ; - - if ( event.m_metaDown ) - modifiers |= cmdKey ; - { - control = (ControlRef) m_macControl ; - if ( control && ::IsControlActive( control ) ) - { - { - controlpart = ::HandleControlClick( control , localwhere , modifiers , (ControlActionUPP) -1 ) ; - wxTheApp->s_lastMouseDown = 0 ; - if ( control && controlpart != kControlNoPart ) - { - MacHandleControlClick((WXWidget) control , controlpart , false /* mouse not down anymore */ ) ; - } - } - } - } - } else { event.Skip() ; @@ -2608,16 +2804,20 @@ void wxWindowMac::OnMouseEvent( wxMouseEvent &event ) void wxWindowMac::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) ) { - wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ; } -Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size ) +Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin ) { int x ,y , w ,h ; - window->MacGetBoundsForControl( pos , size , x , y, w, h ) ; + window->MacGetBoundsForControl( pos , size , x , y, w, h , adjustForOrigin) ; Rect bounds = { y , x , y+h , x+w }; return bounds ; } +wxInt32 wxWindowMac::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) +{ + return eventNotHandledErr ; +} +