focus fixes for 10.5
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@50127 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -162,6 +162,12 @@ enum
|
|||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
|
||||||
|
enum {
|
||||||
|
kEventControlFocusPartChanged = 164
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const EventTypeSpec eventList[] =
|
static const EventTypeSpec eventList[] =
|
||||||
@@ -184,8 +190,8 @@ static const EventTypeSpec eventList[] =
|
|||||||
{ kEventClassControl , kEventControlActivate } ,
|
{ kEventClassControl , kEventControlActivate } ,
|
||||||
{ kEventClassControl , kEventControlDeactivate } ,
|
{ kEventClassControl , kEventControlDeactivate } ,
|
||||||
#endif
|
#endif
|
||||||
{ kEventClassControl , kEventControlGetFocusPart } ,
|
|
||||||
{ kEventClassControl , kEventControlSetFocusPart } ,
|
{ kEventClassControl , kEventControlSetFocusPart } ,
|
||||||
|
{ kEventClassControl , kEventControlFocusPartChanged } ,
|
||||||
|
|
||||||
{ kEventClassService , kEventServiceGetTypes },
|
{ kEventClassService , kEventServiceGetTypes },
|
||||||
{ kEventClassService , kEventServiceCopy },
|
{ kEventClassService , kEventServiceCopy },
|
||||||
@@ -326,38 +332,27 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
|
|||||||
break ;
|
break ;
|
||||||
#endif // TARGET_API_MAC_OSX
|
#endif // TARGET_API_MAC_OSX
|
||||||
|
|
||||||
// we emulate this event under Carbon CFM
|
//
|
||||||
case kEventControlGetFocusPart :
|
// focus handling
|
||||||
if ( thisWindow->MacIsUserPane() )
|
// different handling on OS X
|
||||||
|
//
|
||||||
|
|
||||||
|
case kEventControlFocusPartChanged :
|
||||||
|
// the event is emulated by wxmac for systems lower than 10.5
|
||||||
{
|
{
|
||||||
// kHIViewEntireView and kHIViewNoPart have the same code, needed for Leopard
|
ControlPartCode previousControlPart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPreviousPart , typeControlPartCode );
|
||||||
cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , kHIViewEntireView );
|
ControlPartCode currentControlPart = cEvent.GetParameter<ControlPartCode>(kEventParamControlCurrentPart , typeControlPartCode );
|
||||||
result = noErr ;
|
if ( currentControlPart == 0 )
|
||||||
}
|
|
||||||
break ;
|
|
||||||
case kEventControlSetFocusPart :
|
|
||||||
{
|
|
||||||
Boolean focusEverything = false ;
|
|
||||||
ControlPartCode controlPart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode );
|
|
||||||
|
|
||||||
#ifdef __WXMAC_OSX__
|
|
||||||
if ( cEvent.GetParameter<Boolean>(kEventParamControlFocusEverything , &focusEverything ) == noErr )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if ( thisWindow->MacIsUserPane() )
|
|
||||||
result = noErr ;
|
|
||||||
|
|
||||||
if ( controlPart == kControlFocusNoPart )
|
|
||||||
{
|
{
|
||||||
|
// kill focus
|
||||||
#if wxUSE_CARET
|
#if wxUSE_CARET
|
||||||
if ( thisWindow->GetCaret() )
|
if ( thisWindow->GetCaret() )
|
||||||
thisWindow->GetCaret()->OnKillFocus();
|
thisWindow->GetCaret()->OnKillFocus();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wxLogTrace(_T("Focus"), _T("focus lost(%p)"), wx_static_cast(void*, thisWindow));
|
wxLogTrace(_T("Focus"), _T("focus lost(%p)"), wx_static_cast(void*, thisWindow));
|
||||||
|
|
||||||
|
// remove this as soon as posting the synthesized event works properly
|
||||||
static bool inKillFocusEvent = false ;
|
static bool inKillFocusEvent = false ;
|
||||||
|
|
||||||
if ( !inKillFocusEvent )
|
if ( !inKillFocusEvent )
|
||||||
@@ -369,23 +364,114 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
|
|||||||
inKillFocusEvent = false ;
|
inKillFocusEvent = false ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else if ( previousControlPart == 0 )
|
||||||
{
|
{
|
||||||
|
// set focus
|
||||||
// panel wants to track the window which was the last to have focus in it
|
// panel wants to track the window which was the last to have focus in it
|
||||||
wxLogTrace(_T("Focus"), _T("focus set(%p)"), wx_static_cast(void*, thisWindow));
|
wxLogTrace(_T("Focus"), _T("focus set(%p)"), wx_static_cast(void*, thisWindow));
|
||||||
wxChildFocusEvent eventFocus((wxWindow*)thisWindow);
|
wxChildFocusEvent eventFocus((wxWindow*)thisWindow);
|
||||||
thisWindow->GetEventHandler()->ProcessEvent(eventFocus);
|
thisWindow->GetEventHandler()->ProcessEvent(eventFocus);
|
||||||
|
|
||||||
#if wxUSE_CARET
|
#if wxUSE_CARET
|
||||||
if ( thisWindow->GetCaret() )
|
if ( thisWindow->GetCaret() )
|
||||||
thisWindow->GetCaret()->OnSetFocus();
|
thisWindow->GetCaret()->OnSetFocus();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId());
|
wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId());
|
||||||
event.SetEventObject(thisWindow);
|
event.SetEventObject(thisWindow);
|
||||||
thisWindow->GetEventHandler()->ProcessEvent(event) ;
|
thisWindow->GetEventHandler()->ProcessEvent(event) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case kEventControlSetFocusPart :
|
||||||
|
{
|
||||||
|
#ifdef __WXMAC_OSX__
|
||||||
|
Boolean focusEverything = false ;
|
||||||
|
if ( cEvent.GetParameter<Boolean>(kEventParamControlFocusEverything , &focusEverything ) == noErr )
|
||||||
|
{
|
||||||
|
// put a breakpoint here to catch focus everything events
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
ControlPartCode controlPart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode );
|
||||||
|
|
||||||
|
ControlPartCode previousControlPart = 0;
|
||||||
|
verify_noerr( HIViewGetFocusPart(controlRef, &previousControlPart));
|
||||||
|
|
||||||
|
if ( thisWindow->MacIsUserPane() )
|
||||||
|
{
|
||||||
|
if ( controlPart != kControlFocusNoPart )
|
||||||
|
cEvent.SetParameter<ControlPartCode>( kEventParamControlPart, typeControlPartCode, 1 ) ;
|
||||||
|
result = noErr ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
result = CallNextEventHandler(handler, event);
|
||||||
|
|
||||||
|
if ( UMAGetSystemVersion() < 0x1050 )
|
||||||
|
{
|
||||||
|
// set back to 0 if problems arise
|
||||||
|
#if 1
|
||||||
|
ControlPartCode currentControlPart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode );
|
||||||
|
// synthesize the event focus changed event
|
||||||
|
EventRef evRef = NULL ;
|
||||||
|
|
||||||
|
OSStatus err = MacCreateEvent(
|
||||||
|
NULL , kEventClassControl , kEventControlFocusPartChanged , TicksToEventTime( TickCount() ) ,
|
||||||
|
kEventAttributeUserEvent , &evRef );
|
||||||
|
verify_noerr( err );
|
||||||
|
|
||||||
|
wxMacCarbonEvent iEvent( evRef ) ;
|
||||||
|
iEvent.SetParameter<ControlRef>( kEventParamDirectObject , controlRef ) ;
|
||||||
|
iEvent.SetParameter<ControlPartCode>( kEventParamControlPreviousPart, typeControlPartCode, previousControlPart ) ;
|
||||||
|
iEvent.SetParameter<ControlPartCode>( kEventParamControlCurrentPart, typeControlPartCode, currentControlPart ) ;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// TODO test this first, avoid double posts etc...
|
||||||
|
PostEventToQueue( GetMainEventQueue(), evRef , kEventPriorityHigh );
|
||||||
|
#else
|
||||||
|
wxMacWindowControlEventHandler( NULL , evRef , data ) ;
|
||||||
|
#endif
|
||||||
|
ReleaseEvent( evRef ) ;
|
||||||
|
#else
|
||||||
|
// old implementation, to be removed if the new one works
|
||||||
|
if ( controlPart == kControlFocusNoPart )
|
||||||
|
{
|
||||||
|
#if wxUSE_CARET
|
||||||
|
if ( thisWindow->GetCaret() )
|
||||||
|
thisWindow->GetCaret()->OnKillFocus();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
wxLogTrace(_T("Focus"), _T("focus lost(%p)"), wx_static_cast(void*, thisWindow));
|
||||||
|
|
||||||
|
static bool inKillFocusEvent = false ;
|
||||||
|
|
||||||
|
if ( !inKillFocusEvent )
|
||||||
|
{
|
||||||
|
inKillFocusEvent = true ;
|
||||||
|
wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId());
|
||||||
|
event.SetEventObject(thisWindow);
|
||||||
|
thisWindow->GetEventHandler()->ProcessEvent(event) ;
|
||||||
|
inKillFocusEvent = false ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// panel wants to track the window which was the last to have focus in it
|
||||||
|
wxLogTrace(_T("Focus"), _T("focus set(%p)"), wx_static_cast(void*, thisWindow));
|
||||||
|
wxChildFocusEvent eventFocus((wxWindow*)thisWindow);
|
||||||
|
thisWindow->GetEventHandler()->ProcessEvent(eventFocus);
|
||||||
|
|
||||||
|
#if wxUSE_CARET
|
||||||
|
if ( thisWindow->GetCaret() )
|
||||||
|
thisWindow->GetCaret()->OnSetFocus();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId());
|
||||||
|
event.SetEventObject(thisWindow);
|
||||||
|
thisWindow->GetEventHandler()->ProcessEvent(event) ;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
break ;
|
break ;
|
||||||
|
|
||||||
case kEventControlHit :
|
case kEventControlHit :
|
||||||
|
Reference in New Issue
Block a user