implementAsBlocking static method

NSTextInputClient implementAsBlocking({
  1. required void insertText_replacementRange_(
    1. ObjCObjectBase,
    2. NSRange
    ),
  2. required void doCommandBySelector_(
    1. Pointer<ObjCSelector> aSelector
    ),
  3. required void setMarkedText_selectedRange_replacementRange_(
    1. ObjCObjectBase,
    2. NSRange,
    3. NSRange
    ),
  4. required void unmarkText(),
  5. required NSRange selectedRange(),
  6. required NSRange markedRange(),
  7. required bool hasMarkedText(),
  8. required NSAttributedString? attributedSubstringForProposedRange_actualRange_(
    1. NSRange,
    2. NSRangePointer
    ),
  9. required NSArray validAttributesForMarkedText(),
  10. required NSRect firstRectForCharacterRange_actualRange_(
    1. NSRange,
    2. NSRangePointer
    ),
  11. required DartNSInteger characterIndexForPoint_(
    1. NSPoint point
    ),
  12. NSAttributedString attributedString()?,
  13. DartCGFloat fractionOfDistanceThroughGlyphForPoint_(
    1. NSPoint
    )?,
  14. DartCGFloat baselineDeltaForCharacterAtIndex_(
    1. DartNSUInteger
    )?,
  15. DartNSInteger windowLevel()?,
  16. bool drawsVerticallyForCharacterAtIndex_(
    1. DartNSUInteger
    )?,
  17. NSTextCursorAccessoryPlacement preferredTextAccessoryPlacement()?,
  18. NSRect unionRectInVisibleSelectedRange()?,
  19. NSRect documentVisibleRect()?,
  20. bool supportsAdaptiveImageGlyph()?,
  21. void insertAdaptiveImageGlyph_replacementRange_(
    1. NSAdaptiveImageGlyph,
    2. NSRange
    )?,
  22. bool $keepIsolateAlive = true,
})

Builds an object that implements the NSTextInputClient protocol. To implement multiple protocols, use addToBuilder or objc.ObjCProtocolBuilder directly. All methods that can be implemented as blocking listeners will be.

If $keepIsolateAlive is true, this protocol will keep this isolate alive until it is garbage collected by both Dart and ObjC.

Implementation

static NSTextInputClient implementAsBlocking({
  required void Function(objc.ObjCObjectBase, NSRange)
  insertText_replacementRange_,
  required void Function(ffi.Pointer<objc.ObjCSelector>) doCommandBySelector_,
  required void Function(objc.ObjCObjectBase, NSRange, NSRange)
  setMarkedText_selectedRange_replacementRange_,
  required void Function() unmarkText,
  required NSRange Function() selectedRange,
  required NSRange Function() markedRange,
  required bool Function() hasMarkedText,
  required NSAttributedString? Function(NSRange, NSRangePointer)
  attributedSubstringForProposedRange_actualRange_,
  required objc.NSArray Function() validAttributesForMarkedText,
  required NSRect Function(NSRange, NSRangePointer)
  firstRectForCharacterRange_actualRange_,
  required DartNSUInteger Function(NSPoint) characterIndexForPoint_,
  NSAttributedString Function()? attributedString,
  DartCGFloat Function(NSPoint)? fractionOfDistanceThroughGlyphForPoint_,
  DartCGFloat Function(DartNSUInteger)? baselineDeltaForCharacterAtIndex_,
  DartNSInteger Function()? windowLevel,
  bool Function(DartNSUInteger)? drawsVerticallyForCharacterAtIndex_,
  NSTextCursorAccessoryPlacement Function()? preferredTextAccessoryPlacement,
  NSRect Function()? unionRectInVisibleSelectedRange,
  NSRect Function()? documentVisibleRect,
  bool Function()? supportsAdaptiveImageGlyph,
  void Function(NSAdaptiveImageGlyph, NSRange)?
  insertAdaptiveImageGlyph_replacementRange_,
  bool $keepIsolateAlive = true,
}) {
  final builder = objc.ObjCProtocolBuilder(debugName: 'NSTextInputClient');
  NSTextInputClient.insertText_replacementRange_.implementAsBlocking(
    builder,
    insertText_replacementRange_,
  );
  NSTextInputClient.doCommandBySelector_.implementAsBlocking(
    builder,
    doCommandBySelector_,
  );
  NSTextInputClient.setMarkedText_selectedRange_replacementRange_
      .implementAsBlocking(
        builder,
        setMarkedText_selectedRange_replacementRange_,
      );
  NSTextInputClient.unmarkText.implementAsBlocking(builder, unmarkText);
  NSTextInputClient.selectedRange.implement(builder, selectedRange);
  NSTextInputClient.markedRange.implement(builder, markedRange);
  NSTextInputClient.hasMarkedText.implement(builder, hasMarkedText);
  NSTextInputClient.attributedSubstringForProposedRange_actualRange_
      .implement(builder, attributedSubstringForProposedRange_actualRange_);
  NSTextInputClient.validAttributesForMarkedText.implement(
    builder,
    validAttributesForMarkedText,
  );
  NSTextInputClient.firstRectForCharacterRange_actualRange_.implement(
    builder,
    firstRectForCharacterRange_actualRange_,
  );
  NSTextInputClient.characterIndexForPoint_.implement(
    builder,
    characterIndexForPoint_,
  );
  NSTextInputClient.attributedString.implement(builder, attributedString);
  NSTextInputClient.fractionOfDistanceThroughGlyphForPoint_.implement(
    builder,
    fractionOfDistanceThroughGlyphForPoint_,
  );
  NSTextInputClient.baselineDeltaForCharacterAtIndex_.implement(
    builder,
    baselineDeltaForCharacterAtIndex_,
  );
  NSTextInputClient.windowLevel.implement(builder, windowLevel);
  NSTextInputClient.drawsVerticallyForCharacterAtIndex_.implement(
    builder,
    drawsVerticallyForCharacterAtIndex_,
  );
  NSTextInputClient.preferredTextAccessoryPlacement.implement(
    builder,
    preferredTextAccessoryPlacement,
  );
  NSTextInputClient.unionRectInVisibleSelectedRange.implement(
    builder,
    unionRectInVisibleSelectedRange,
  );
  NSTextInputClient.documentVisibleRect.implement(
    builder,
    documentVisibleRect,
  );
  NSTextInputClient.supportsAdaptiveImageGlyph.implement(
    builder,
    supportsAdaptiveImageGlyph,
  );
  NSTextInputClient.insertAdaptiveImageGlyph_replacementRange_
      .implementAsBlocking(
        builder,
        insertAdaptiveImageGlyph_replacementRange_,
      );
  builder.addProtocol($protocol);
  return NSTextInputClient.castFrom(
    builder.build(keepIsolateAlive: $keepIsolateAlive),
  );
}