Cocoa: IME: TLCLCommonCallback refactor

This commit is contained in:
rich2014 2023-07-06 23:30:56 +08:00
parent f605a02231
commit b4be9f3898

View File

@ -66,6 +66,12 @@ type
_isCocoaOnlyState: Boolean;
_UTF8Character : array [0..7] of TUTF8Char;
_UTF8Charcount : Integer;
private
procedure send_UTF8KeyPress();
procedure send_CN_CHAR_Message();
procedure send_LM_KEYDOWN_Message();
procedure send_LM_CHAR_Message();
protected
procedure OffsetMousePos(LocInWin: NSPoint; out PtInBounds, PtInClient, PtForChildCtrls: TPoint );
procedure ScreenMousePos(var Point: NSPoint);
procedure KeyEvBeforeDown;
@ -797,30 +803,24 @@ end;
procedure TLCLCommonCallback.KeyEvBeforeDown;
begin
// is the key combination help key (Cmd + ?)
if _SendChar and _IsSysKey and (_UTF8Character[0] = '?') then
Application.ShowHelpForObject(Target);
//Send message to LCL
if _KeyMsg.CharCode = VK_UNKNOWN then
exit;
// create the CN_KEYDOWN message
if _IsSysKey then
_KeyMsg.Msg := CN_SYSKEYDOWN
else
_KeyMsg.Msg := CN_KEYDOWN;
// is the key combination help key (Cmd + ?)
if _SendChar and _IsSysKey and (_UTF8Character[0] = '?') then
Application.ShowHelpForObject(Target);
// widget can filter some keys from being send to cocoa control
//if Widget.FilterKeyPress(IsSysKey, UTF8Character) then Result := noErr;
//Send message to LCL
if _KeyMsg.CharCode <> VK_UNKNOWN then
begin
NotifyApplicationUserInput(Target, _KeyMsg.Msg);
if (DeliverMessage(_KeyMsg) <> 0) or (_KeyMsg.CharCode = VK_UNKNOWN) then
begin
// the LCL handled the key
KeyEvHandled;
Exit;
end;
end;
NotifyApplicationUserInput(Target, _KeyMsg.Msg);
if (DeliverMessage(_KeyMsg) <> 0) or (_KeyMsg.CharCode = VK_UNKNOWN) then
// the LCL handled the key
KeyEvHandled;
end;
procedure TLCLCommonCallback.KeyEvBeforeUp;
@ -843,85 +843,85 @@ begin
end;
end;
procedure TLCLCommonCallback.KeyEvAfterDown(out AllowCocoaHandle: boolean);
procedure TLCLCommonCallback.send_UTF8KeyPress();
var
i: integer;
lclHandled: Boolean;
begin
if (_SendChar) then begin
// send the UTF8 keypress
i := 0;
lclHandled := false;
for i := 0 to _UTF8Charcount -1 do
begin
lclHandled := false;
if Target.IntfUTF8KeyPress(_UTF8Character[i], 1, _IsSysKey) then
lclHandled := true;
end;
if not _sendChar then exit;
if lclHandled then
begin
// the LCL has handled the key
if ForceReturnKeyDown and (_KeyMsg.CharCode = VK_RETURN) then
_SendChar := False
else
KeyEvHandled;
Exit;
end;
//if OrigChar <> _UTF8Character then
//LCLCharToMacEvent(_UTF8Character);
// create the CN_CHAR / CN_SYSCHAR message
if _IsSysKey then
_CharMsg.Msg := CN_SYSCHAR
else
_CharMsg.Msg := CN_CHAR;
//Send message to LCL
if (DeliverMessage(_CharMsg) <> 0) or (_CharMsg.CharCode=VK_UNKNOWN) then
begin
// the LCL handled the key
KeyEvHandled;
Exit;
end;
//if _CharMsg.CharCode <> ord(_KeyChar) then
//LCLCharToMacEvent(Char(_CharMsg.CharCode));
end;
AllowCocoaHandle := False;
if _KeyHandled then Exit;
KeyEvHandled;
// Send an LM_(SYS)KEYDOWN
if _KeyMsg.CharCode <> VK_UNKNOWN then
// send the UTF8 keypress
i := 0;
lclHandled := false;
for i := 0 to _UTF8Charcount -1 do
begin
if _IsSysKey then
_KeyMsg.Msg := LM_SYSKEYDOWN
else
_KeyMsg.Msg := LM_KEYDOWN;
if (DeliverMessage(_KeyMsg) <> 0) or (_KeyMsg.CharCode = VK_UNKNOWN) then
Exit;
lclHandled := false;
if Target.IntfUTF8KeyPress(_UTF8Character[i], 1, _IsSysKey) then
lclHandled := true;
end;
//Send an LM_(SYS)CHAR
if _SendChar then begin
if _IsSysKey then
_CharMsg.Msg := LM_SYSCHAR
if lclHandled then
begin
// the LCL has handled the key
if ForceReturnKeyDown and (_KeyMsg.CharCode = VK_RETURN) then
_SendChar := False
else
_CharMsg.Msg := LM_CHAR;
if DeliverMessage(_CharMsg) <> 0 then
Exit;
KeyEvHandled;
end;
end;
if BlockCocoaKeyBeep then
Exit;
procedure TLCLCommonCallback.send_CN_CHAR_Message();
begin
if not _SendChar then exit;
AllowCocoaHandle := True;
if _IsSysKey then
_CharMsg.Msg := CN_SYSCHAR
else
_CharMsg.Msg := CN_CHAR;
if (DeliverMessage(_CharMsg) <> 0) or (_CharMsg.CharCode=VK_UNKNOWN) then
KeyEvHandled;
end;
procedure TLCLCommonCallback.send_LM_KEYDOWN_Message();
begin
if _KeyMsg.CharCode = VK_UNKNOWN then exit;
if _IsSysKey then
_KeyMsg.Msg := LM_SYSKEYDOWN
else
_KeyMsg.Msg := LM_KEYDOWN;
if (DeliverMessage(_KeyMsg) <> 0) or (_KeyMsg.CharCode = VK_UNKNOWN) then
KeyEvHandled;
end;
procedure TLCLCommonCallback.send_LM_CHAR_Message();
begin
if not _SendChar then exit;
if _IsSysKey then
_CharMsg.Msg := LM_SYSCHAR
else
_CharMsg.Msg := LM_CHAR;
if DeliverMessage(_CharMsg) <> 0 then
KeyEvHandled;
end;
procedure TLCLCommonCallback.KeyEvAfterDown(out AllowCocoaHandle: boolean);
begin
if _KeyHandled then exit;
send_UTF8KeyPress;
if _KeyHandled then exit;
send_CN_CHAR_Message;
if _KeyHandled then exit;
send_LM_KEYDOWN_Message;
if _KeyHandled then exit;
send_LM_CHAR_Message;
end;
procedure TLCLCommonCallback.KeyEvAfterUp;