mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-09 23:08:05 +02:00
Cocoa: avoid sending unnecessary KillFocus/SentFocus messages and keep consistent with win32
This commit is contained in:
parent
4746c886bd
commit
3bfa4b5a16
@ -1019,7 +1019,8 @@ function TCocoaWindow.makeFirstResponder( aResponder : NSResponder ): ObjCBOOL;
|
||||
var
|
||||
lastResponder : NSResponder;
|
||||
newResponder : NSResponder;
|
||||
cb : ICommonCallback;
|
||||
lastCb : ICommonCallback;
|
||||
newCb : ICommonCallback;
|
||||
begin
|
||||
inc( makeFirstResponderCount );
|
||||
try
|
||||
@ -1031,7 +1032,7 @@ begin
|
||||
// lastResponder may be changed dynamically.
|
||||
// for example, when lastResponder is a FieldEditor.
|
||||
// see also: TCocoaFieldEditor.lclGetCallback()
|
||||
cb := getResponderCallback( lastResponder );
|
||||
lastCb := getResponderCallback( lastResponder );
|
||||
|
||||
// do toggle Focused Control
|
||||
// Result=false when the focused control has not been changed
|
||||
@ -1043,15 +1044,21 @@ begin
|
||||
if makeFirstResponderCount > 1 then
|
||||
exit;
|
||||
|
||||
// new Responder was not finalized until here
|
||||
newCb := getResponderCallback( self.firstResponder );
|
||||
|
||||
// different Controls in Cocoa may correspond to the same LCL Control
|
||||
// for example TextField and its FieldEditor both correspond to the same TEdit
|
||||
if lastCb = newCb then exit;
|
||||
|
||||
// 1st: send KillFocus Message first
|
||||
if Assigned(cb) then
|
||||
cb.ResignFirstResponder;
|
||||
if Assigned(lastCb) then
|
||||
lastCb.ResignFirstResponder;
|
||||
|
||||
// 2st: send SetFocus Message
|
||||
// TCocoaWindow.makeFirstResponder() may be triggered reentrant here
|
||||
cb := getResponderCallback( self.firstResponder );
|
||||
if Assigned(cb) then
|
||||
cb.BecomeFirstResponder;
|
||||
if Assigned(newCb) then
|
||||
newCb.BecomeFirstResponder;
|
||||
|
||||
finally
|
||||
dec( makeFirstResponderCount );
|
||||
|
Loading…
Reference in New Issue
Block a user