diff --git a/lcl/interfaces/cocoa/cocoaint.pas b/lcl/interfaces/cocoa/cocoaint.pas index df0a6d6a11..e5cf47cdf2 100644 --- a/lcl/interfaces/cocoa/cocoaint.pas +++ b/lcl/interfaces/cocoa/cocoaint.pas @@ -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); diff --git a/lcl/interfaces/cocoa/cocoautils.pas b/lcl/interfaces/cocoa/cocoautils.pas index a2286c487a..ba800351a8 100644 --- a/lcl/interfaces/cocoa/cocoautils.pas +++ b/lcl/interfaces/cocoa/cocoautils.pas @@ -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 }