mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-21 13:59:10 +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
|
var
|
||||||
lastResponder : NSResponder;
|
lastResponder : NSResponder;
|
||||||
newResponder : NSResponder;
|
newResponder : NSResponder;
|
||||||
cb : ICommonCallback;
|
lastCb : ICommonCallback;
|
||||||
|
newCb : ICommonCallback;
|
||||||
begin
|
begin
|
||||||
inc( makeFirstResponderCount );
|
inc( makeFirstResponderCount );
|
||||||
try
|
try
|
||||||
@ -1031,7 +1032,7 @@ begin
|
|||||||
// lastResponder may be changed dynamically.
|
// lastResponder may be changed dynamically.
|
||||||
// for example, when lastResponder is a FieldEditor.
|
// for example, when lastResponder is a FieldEditor.
|
||||||
// see also: TCocoaFieldEditor.lclGetCallback()
|
// see also: TCocoaFieldEditor.lclGetCallback()
|
||||||
cb := getResponderCallback( lastResponder );
|
lastCb := getResponderCallback( lastResponder );
|
||||||
|
|
||||||
// do toggle Focused Control
|
// do toggle Focused Control
|
||||||
// Result=false when the focused control has not been changed
|
// Result=false when the focused control has not been changed
|
||||||
@ -1043,15 +1044,21 @@ begin
|
|||||||
if makeFirstResponderCount > 1 then
|
if makeFirstResponderCount > 1 then
|
||||||
exit;
|
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
|
// 1st: send KillFocus Message first
|
||||||
if Assigned(cb) then
|
if Assigned(lastCb) then
|
||||||
cb.ResignFirstResponder;
|
lastCb.ResignFirstResponder;
|
||||||
|
|
||||||
// 2st: send SetFocus Message
|
// 2st: send SetFocus Message
|
||||||
// TCocoaWindow.makeFirstResponder() may be triggered reentrant here
|
// TCocoaWindow.makeFirstResponder() may be triggered reentrant here
|
||||||
cb := getResponderCallback( self.firstResponder );
|
if Assigned(newCb) then
|
||||||
if Assigned(cb) then
|
newCb.BecomeFirstResponder;
|
||||||
cb.BecomeFirstResponder;
|
|
||||||
|
|
||||||
finally
|
finally
|
||||||
dec( makeFirstResponderCount );
|
dec( makeFirstResponderCount );
|
||||||
|
Loading…
Reference in New Issue
Block a user