mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-07 09:40:21 +02:00
FIX: COCOA: improved key event handling mechanism by NSTextInputClientProtocol.hasMarkedText() in IME input state
This commit is contained in:
parent
f1c87cd5ae
commit
467026508f
@ -520,6 +520,7 @@ var
|
||||
idx: integer;
|
||||
win : NSWindow;
|
||||
cbnew : ICommonCallback;
|
||||
responder : NSResponder;
|
||||
begin
|
||||
{$ifdef COCOALOOPNATIVE}
|
||||
try
|
||||
@ -528,10 +529,24 @@ begin
|
||||
win := theEvent.window;
|
||||
if not Assigned(win) then win := self.keyWindow;
|
||||
|
||||
responder := nil;
|
||||
cb := nil;
|
||||
|
||||
if Assigned(win) then
|
||||
cb := win.firstResponder.lclGetCallback
|
||||
else
|
||||
cb := nil;
|
||||
begin
|
||||
responder := win.firstResponder;
|
||||
cb := responder.lclGetCallback;
|
||||
if Assigned(cb) and (theEvent.type_=NSKeyDown) then
|
||||
begin
|
||||
// set CocoaOnlyState when NSKeyDown only,
|
||||
// keep last CocoaOnlyState when NSKeyUp
|
||||
if responder.conformsToProtocol(objcprotocol(NSTextInputClientProtocol)) then
|
||||
cb.CocoaOnlyState := NSTextInputClientProtocol(responder).hasMarkedText
|
||||
else
|
||||
cb.CocoaOnlyState := false;
|
||||
end;
|
||||
end;
|
||||
|
||||
try
|
||||
if (theEvent.type_ = NSKeyDown) or (theEvent.type_ = NSKeyUp) or
|
||||
(theEvent.type_ = NSFlagsChanged) then begin
|
||||
@ -558,10 +573,17 @@ begin
|
||||
end;
|
||||
{$endif}
|
||||
|
||||
cb.KeyEvBefore(theEvent, allowcocoa);
|
||||
if allowcocoa then
|
||||
if cb.IsCocoaOnlyState then
|
||||
begin
|
||||
inherited sendEvent(theEvent);
|
||||
cb.KeyEvAfter;
|
||||
end
|
||||
else
|
||||
begin
|
||||
cb.KeyEvBefore(theEvent, allowcocoa);
|
||||
if allowcocoa then
|
||||
inherited sendEvent(theEvent);
|
||||
cb.KeyEvAfter;
|
||||
end;
|
||||
finally
|
||||
if Assigned(wnd) then
|
||||
wnd._keyEvCallback := nil;
|
||||
|
@ -75,6 +75,10 @@ type
|
||||
procedure KeyEvHandled;
|
||||
procedure SetTabSuppress(ASuppress: Boolean);
|
||||
|
||||
// only Cocoa Event Mechanism (no LCL Event), if the IME is in use
|
||||
function IsCocoaOnlyState: Boolean;
|
||||
procedure SetCocoaOnlyState( state:Boolean );
|
||||
|
||||
function scrollWheel(Event: NSEvent): Boolean;
|
||||
function CanFocus: Boolean;
|
||||
// size, pos events
|
||||
@ -115,6 +119,7 @@ type
|
||||
// properties
|
||||
property HasCaret: Boolean read GetHasCaret write SetHasCaret;
|
||||
property IsOpaque: Boolean read GetIsOpaque write SetIsOpaque;
|
||||
property CocoaOnlyState: Boolean read IsCocoaOnlyState write SetCocoaOnlyState;
|
||||
end;
|
||||
|
||||
{ LCLObjectExtension }
|
||||
|
@ -998,6 +998,12 @@ var
|
||||
mn : NSMenu;
|
||||
allowcocoa : Boolean;
|
||||
begin
|
||||
if Assigned(_keyEvCallback) and _keyEvCallback.IsCocoaOnlyState then
|
||||
begin
|
||||
inherited keyDown(event);
|
||||
Exit;
|
||||
end;
|
||||
|
||||
if performKeyEquivalent(event) then
|
||||
Exit;
|
||||
|
||||
|
@ -47,6 +47,7 @@ type
|
||||
_IsSysKey : Boolean;
|
||||
_IsKeyDown : Boolean;
|
||||
_KeyHandled: Boolean;
|
||||
_isCocoaOnlyState: Boolean;
|
||||
_UTF8Character : array [0..7] of TUTF8Char;
|
||||
_UTF8Charcount : Integer;
|
||||
procedure OffsetMousePos(LocInWin: NSPoint; out PtInBounds, PtInClient, PtForChildCtrls: TPoint );
|
||||
@ -86,6 +87,9 @@ type
|
||||
procedure SetTabSuppress(ASuppress: Boolean);
|
||||
function CanFocus: Boolean; virtual;
|
||||
|
||||
function IsCocoaOnlyState: Boolean;
|
||||
procedure SetCocoaOnlyState(state: Boolean);
|
||||
|
||||
procedure MouseClick; virtual;
|
||||
function MouseMove(Event: NSEvent): Boolean; virtual;
|
||||
function scrollWheel(Event: NSEvent): Boolean; virtual;
|
||||
@ -901,6 +905,16 @@ begin
|
||||
_KeyHandled := True;
|
||||
end;
|
||||
|
||||
function TLCLCommonCallback.IsCocoaOnlyState: Boolean;
|
||||
begin
|
||||
Result := _isCocoaOnlyState;
|
||||
end;
|
||||
|
||||
procedure TLCLCommonCallback.SetCocoaOnlyState( state:Boolean );
|
||||
begin
|
||||
_isCocoaOnlyState := state;
|
||||
end;
|
||||
|
||||
procedure TLCLCommonCallback.SetTabSuppress(ASuppress: Boolean);
|
||||
begin
|
||||
SuppressTabDown := ASuppress;
|
||||
|
Loading…
Reference in New Issue
Block a user