From 222180ffe99a59563dfa98bf25661b5b087835e6 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Tue, 25 Mar 2008 15:36:41 +0000 Subject: [PATCH] adding 10.4 code for making focus events behave as similar to 10.5 as possible git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@52814 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/mac/carbon/window.cpp | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/src/mac/carbon/window.cpp b/src/mac/carbon/window.cpp index 2a583e69e2..e4cb57c133 100644 --- a/src/mac/carbon/window.cpp +++ b/src/mac/carbon/window.cpp @@ -168,11 +168,11 @@ static const EventTypeSpec eventList[] = // { kEventClassControl , kEventControlBoundsChanged } , } ; -wxWindowMac* targetWindow = NULL; - static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) { OSStatus result = eventNotHandledErr ; + static wxWindowMac* targetFocusWindow = NULL; + static wxWindowMac* formerFocusWindow = NULL; wxMacCarbonEvent cEvent( event ) ; @@ -320,6 +320,11 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl case kEventControlFocusPartChanged : // the event is emulated by wxmac for systems lower than 10.5 { + if ( UMAGetSystemVersion() < 0x1050 ) + { + // as it is synthesized here, we have to manually avoid propagation + result = noErr; + } ControlPartCode previousControlPart = cEvent.GetParameter(kEventParamControlPreviousPart , typeControlPartCode ); ControlPartCode currentControlPart = cEvent.GetParameter(kEventParamControlCurrentPart , typeControlPartCode ); @@ -346,9 +351,10 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl inKillFocusEvent = true ; wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId()); event.SetEventObject(thisWindow); - event.SetWindow(targetWindow); + event.SetWindow(targetFocusWindow); thisWindow->HandleWindowEvent(event) ; inKillFocusEvent = false ; + targetFocusWindow = NULL; } } else if ( previousControlPart == 0 ) @@ -366,7 +372,9 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId()); event.SetEventObject(thisWindow); + event.SetWindow(formerFocusWindow); thisWindow->HandleWindowEvent(event) ; + formerFocusWindow = NULL; } } break; @@ -381,8 +389,16 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl #endif ControlPartCode controlPart = cEvent.GetParameter(kEventParamControlPart , typeControlPartCode ); if ( controlPart != kControlFocusNoPart ) - targetWindow = thisWindow; - + { + targetFocusWindow = thisWindow; + wxLogTrace(_T("Focus"), _T("focus to be set(%p)"), wx_static_cast(void*, thisWindow)); + } + else + { + formerFocusWindow = thisWindow; + wxLogTrace(_T("Focus"), _T("focus to be lost(%p)"), wx_static_cast(void*, thisWindow)); + } + ControlPartCode previousControlPart = 0; verify_noerr( HIViewGetFocusPart(controlRef, &previousControlPart)); @@ -409,11 +425,12 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl verify_noerr( err ); wxMacCarbonEvent iEvent( evRef ) ; - iEvent.SetParameter( kEventParamDirectObject , controlRef ) ; - iEvent.SetParameter( kEventParamControlPreviousPart, typeControlPartCode, previousControlPart ) ; - iEvent.SetParameter( kEventParamControlCurrentPart, typeControlPartCode, currentControlPart ) ; + iEvent.SetParameter( kEventParamDirectObject , controlRef ); + iEvent.SetParameter( kEventParamPostTarget, typeEventTargetRef, GetControlEventTarget( controlRef ) ); + iEvent.SetParameter( kEventParamControlPreviousPart, typeControlPartCode, previousControlPart ); + iEvent.SetParameter( kEventParamControlCurrentPart, typeControlPartCode, currentControlPart ); -#if 0 +#if 1 // TODO test this first, avoid double posts etc... PostEventToQueue( GetMainEventQueue(), evRef , kEventPriorityHigh ); #else @@ -1186,9 +1203,11 @@ void wxWindowMac::SetFocus() // 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 + wxLogTrace(_T("Focus"), _T("before wxWindow::SetFocus(%p)"), wx_static_cast(void*, this)); OSStatus err = m_peer->SetFocus( kControlFocusNextPart ) ; if ( err == errCouldntSetFocus ) return ; + wxLogTrace(_T("Focus"), _T("after wxWindow::SetFocus(%p)"), wx_static_cast(void*, this)); SetUserFocusWindow( (WindowRef)MacGetTopLevelWindowRef() ); } -- 2.45.2