cocoa: adding text input client to support national key entries with deadkeys #35788

git-svn-id: trunk@61515 -
This commit is contained in:
dmitry 2019-07-03 18:01:21 +00:00
parent c49189ab7d
commit 610d8c6e98
2 changed files with 97 additions and 0 deletions

View File

@ -84,6 +84,8 @@ type
aloop : TApplicationMainLoop;
isrun : Boolean;
modals : NSMutableDictionary;
inputclient : TCocoaInputClient;
inputctx : NSTextInputContext;
procedure dealloc; override;
{$ifdef COCOALOOPOVERRIDE}
@ -422,6 +424,7 @@ end;
procedure TCocoaApplication.dealloc;
begin
if Assigned(modals) then modals.release;
if Assigned(inputclient) then inputclient.release;
inherited dealloc;
end;
@ -506,6 +509,18 @@ begin
end
else
wnd := nil;
if (theEvent.type_ = NSKeyDown)
and not (win.firstResponder.conformsToProtocol(objcprotocol(NSTextInputClientProtocol))) then
begin
if not Assigned(inputctx) then
begin
inputclient := TCocoaInputClient.alloc.init;
inputctx := NSTextInputContext.alloc.initWithClient(inputclient);
end;
inputctx.handleEvent(theEvent);
end;
cb.KeyEvBefore(theEvent, allowcocoa);
if allowcocoa then
inherited sendEvent(theEvent);

View File

@ -120,6 +120,25 @@ function NSEventRawKeyChar(ev: NSEvent): System.WideChar;
function AllocImageRotatedByDegrees(src: NSImage; degrees: double): NSImage;
function AllocCursorFromCursorByDegrees(src: NSCursor; degrees: double): NSCursor;
type
{ TCocoaInputClient }
TCocoaInputClient = objcclass(NSObject, NSTextInputClientProtocol)
procedure insertText_replacementRange(aString: id; replacementRange: NSRange);
procedure setMarkedText_selectedRange_replacementRange(aString: id; selectedRange: NSRange; replacementRange: NSRange);
procedure unmarkText;
function selectedRange: NSRange;
function markedRange: NSRange;
function hasMarkedText: Boolean;
function attributedSubstringForProposedRange_actualRange(aRange: NSRange; actualRange: NSRangePointer): NSAttributedString;
function validAttributesForMarkedText: NSArray;
function firstRectForCharacterRange_actualRange(aRange: NSRange; actualRange: NSRangePointer): NSRect;
function characterIndexForPoint(aPoint: NSPoint): NSUInteger;
procedure doCommandBySelector(asel: sel); message 'doCommandBySelector:';
end;
implementation
procedure ApplicationWillShowModal;
@ -641,6 +660,69 @@ begin
Result := '';
end;
{ TCocoaInputClient }
procedure TCocoaInputClient.insertText_replacementRange(aString: id;
replacementRange: NSRange);
begin
end;
procedure TCocoaInputClient.setMarkedText_selectedRange_replacementRange(
aString: id; selectedRange: NSRange; replacementRange: NSRange);
begin
end;
procedure TCocoaInputClient.unmarkText;
begin
end;
function TCocoaInputClient.selectedRange: NSRange;
begin
Result.location := 0;
Result.length := 0;
end;
function TCocoaInputClient.markedRange: NSRange;
begin
Result.location := 0;
Result.length := 0;
end;
function TCocoaInputClient.hasMarkedText: Boolean;
begin
Result := false;
end;
function TCocoaInputClient.attributedSubstringForProposedRange_actualRange(
aRange: NSRange; actualRange: NSRangePointer): NSAttributedString;
begin
Result := nil;
end;
function TCocoaInputClient.validAttributesForMarkedText: NSArray;
begin
Result := nil;
end;
function TCocoaInputClient.firstRectForCharacterRange_actualRange(
aRange: NSRange; actualRange: NSRangePointer): NSRect;
begin
Result := NSZeroRect;
end;
function TCocoaInputClient.characterIndexForPoint(aPoint: NSPoint): NSUInteger;
begin
Result := 0;
end;
procedure TCocoaInputClient.doCommandBySelector(asel: sel);
begin
end;
{ NSLCLDebugExtension }