implementAsBlocking static method

NSTextSelectionDataSource implementAsBlocking({
  1. required NSTextRange documentRange(),
  2. required void enumerateSubstringsFromLocation_options_usingBlock_(
    1. NSTextLocation,
    2. NSStringEnumerationOptions,
    3. ObjCBlock<Void Function(NSString?, NSTextRange, NSTextRange?, Pointer<Bool>)>
    ),
  3. required NSTextRange? textRangeForSelectionGranularity_enclosingLocation_(
    1. NSTextSelectionGranularity,
    2. NSTextLocation
    ),
  4. required NSTextLocation? locationFromLocation_withOffset_(
    1. NSTextLocation,
    2. DartNSInteger
    ),
  5. required DartNSInteger offsetFromLocation_toLocation_(
    1. NSTextLocation,
    2. NSTextLocation
    ),
  6. required NSTextSelectionNavigationWritingDirection baseWritingDirectionAtLocation_(
    1. NSTextLocation
    ),
  7. required void enumerateCaretOffsetsInLineFragmentAtLocation_usingBlock_(
    1. NSTextLocation,
    2. ObjCBlock<Void Function(Double, Pointer<ObjCObject>, Bool, Pointer<Bool>)>
    ),
  8. required NSTextRange? lineFragmentRangeForPoint_inContainerAtLocation_(
    1. CGPoint,
    2. NSTextLocation
    ),
  9. void enumerateContainerBoundariesFromLocation_reverse_usingBlock_(
    1. NSTextLocation,
    2. bool,
    3. ObjCBlock<Void Function(Pointer<ObjCObject>, Pointer<Bool>)>
    )?,
  10. NSTextSelectionNavigationLayoutOrientation textLayoutOrientationAtLocation_(
    1. NSTextLocation
    )?,
  11. bool $keepIsolateAlive = true,
})

Builds an object that implements the NSTextSelectionDataSource 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 NSTextSelectionDataSource implementAsBlocking({
  required NSTextRange Function() documentRange,
  required void Function(
    NSTextLocation,
    objc.NSStringEnumerationOptions,
    objc.ObjCBlock<
      ffi.Void Function(
        objc.NSString?,
        NSTextRange,
        NSTextRange?,
        ffi.Pointer<ffi.Bool>,
      )
    >,
  )
  enumerateSubstringsFromLocation_options_usingBlock_,
  required NSTextRange? Function(NSTextSelectionGranularity, NSTextLocation)
  textRangeForSelectionGranularity_enclosingLocation_,
  required NSTextLocation? Function(NSTextLocation, DartNSInteger)
  locationFromLocation_withOffset_,
  required DartNSInteger Function(NSTextLocation, NSTextLocation)
  offsetFromLocation_toLocation_,
  required NSTextSelectionNavigationWritingDirection Function(NSTextLocation)
  baseWritingDirectionAtLocation_,
  required void Function(
    NSTextLocation,
    objc.ObjCBlock<
      ffi.Void Function(
        ffi.Double,
        ffi.Pointer<objc.ObjCObject>,
        ffi.Bool,
        ffi.Pointer<ffi.Bool>,
      )
    >,
  )
  enumerateCaretOffsetsInLineFragmentAtLocation_usingBlock_,
  required NSTextRange? Function(objc.CGPoint, NSTextLocation)
  lineFragmentRangeForPoint_inContainerAtLocation_,
  void Function(
    NSTextLocation,
    bool,
    objc.ObjCBlock<
      ffi.Void Function(ffi.Pointer<objc.ObjCObject>, ffi.Pointer<ffi.Bool>)
    >,
  )?
  enumerateContainerBoundariesFromLocation_reverse_usingBlock_,
  NSTextSelectionNavigationLayoutOrientation Function(NSTextLocation)?
  textLayoutOrientationAtLocation_,
  bool $keepIsolateAlive = true,
}) {
  final builder = objc.ObjCProtocolBuilder(
    debugName: 'NSTextSelectionDataSource',
  );
  NSTextSelectionDataSource.documentRange.implement(builder, documentRange);
  NSTextSelectionDataSource
      .enumerateSubstringsFromLocation_options_usingBlock_
      .implementAsBlocking(
        builder,
        enumerateSubstringsFromLocation_options_usingBlock_,
      );
  NSTextSelectionDataSource
      .textRangeForSelectionGranularity_enclosingLocation_
      .implement(
        builder,
        textRangeForSelectionGranularity_enclosingLocation_,
      );
  NSTextSelectionDataSource.locationFromLocation_withOffset_.implement(
    builder,
    locationFromLocation_withOffset_,
  );
  NSTextSelectionDataSource.offsetFromLocation_toLocation_.implement(
    builder,
    offsetFromLocation_toLocation_,
  );
  NSTextSelectionDataSource.baseWritingDirectionAtLocation_.implement(
    builder,
    baseWritingDirectionAtLocation_,
  );
  NSTextSelectionDataSource
      .enumerateCaretOffsetsInLineFragmentAtLocation_usingBlock_
      .implementAsBlocking(
        builder,
        enumerateCaretOffsetsInLineFragmentAtLocation_usingBlock_,
      );
  NSTextSelectionDataSource.lineFragmentRangeForPoint_inContainerAtLocation_
      .implement(builder, lineFragmentRangeForPoint_inContainerAtLocation_);
  NSTextSelectionDataSource
      .enumerateContainerBoundariesFromLocation_reverse_usingBlock_
      .implementAsBlocking(
        builder,
        enumerateContainerBoundariesFromLocation_reverse_usingBlock_,
      );
  NSTextSelectionDataSource.textLayoutOrientationAtLocation_.implement(
    builder,
    textLayoutOrientationAtLocation_,
  );
  builder.addProtocol($protocol);
  return NSTextSelectionDataSource.castFrom(
    builder.build(keepIsolateAlive: $keepIsolateAlive),
  );
}