Cocoa: LookupWord handler enabled in TCocoaWSCustomControl.CreateHandle()

This commit is contained in:
rich2014 2024-08-27 00:57:43 +08:00
parent cfbd95b451
commit 0715fcb1c7
2 changed files with 29 additions and 2 deletions

View File

@ -11,6 +11,10 @@ uses
LazUTF8, Graphics, CocoaGDIObjects,
CocoaAll, CocoaPrivate, CocoaCustomControl, CocoaUtils;
const
IM_MESSAGE_WPARAM_GET_IME_HANDLER = 0;
IM_MESSAGE_WPARAM_GET_LW_HANDLER = 1;
type
{ ICocoaIMEControl }

View File

@ -1952,15 +1952,37 @@ end;
{ TCocoaWSCustomControl }
function SendIMCompostionMessage(
const control: TWinControl; const WParam: LclType.WPARAM ): PtrInt;
var
Mess : TLMessage;
begin
FillChar(Mess,SizeOf(Mess),0);
Mess.Msg:= LM_IM_COMPOSITION;
Mess.WParam:= WParam;
Result:= DeliverMessage( control, Mess );
end;
// get IMEHandler by LM_IM_COMPOSITION message
function getControlIMEHandler(const control: TWinControl): ICocoaIMEControl;
var
handle : PtrInt;
begin
handle := SendSimpleMessage(control, LM_IM_COMPOSITION);
handle := SendIMCompostionMessage( control, IM_MESSAGE_WPARAM_GET_IME_HANDLER );
Result := TObject(handle) as ICocoaIMEControl;
end;
// get Lookup Word Handler by LM_IM_COMPOSITION message
function getControlLWHandler(const control: TWinControl): ICocoaLookupWord;
var
handle: PtrInt;
begin
Result:= nil;
handle := SendIMCompostionMessage( control, IM_MESSAGE_WPARAM_GET_LW_HANDLER );
if TObject(handle) is ICocoaLookupWord then
Result:= TObject(handle) as ICocoaLookupWord;
end;
class function TCocoaWSCustomControl.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLHandle;
var
@ -1977,7 +1999,8 @@ begin
// AWinControl is a Full Control Edit (such as SynEdit/ATSynEdit)
ctrl := TCocoaFullControlEdit.alloc.lclInitWithCreateParams(AParams);
lcl := TLCLFullControlEditCallback.Create(ctrl, AWinControl);
TCocoaFullControlEdit(ctrl).imeHandler := imeHandler;
TCocoaFullControlEdit(ctrl).imeHandler:= imeHandler;
TCocoaFullControlEdit(ctrl).lwHandler:= getControlLWHandler(AWinControl);
TCocoaFullControlEdit(ctrl).unmarkText;
end
else