Scoop API

scoop:scoop.window:0.1.0

src/text/services.scoop

Selected production source · src/text/services.scoop

1package scoop.window
3public struct TextServiceCapabilities(
4 val spelling: Boolean,
5 val grammar: Boolean,
6 val automaticReplacement: Boolean,
7 val dictionary: Boolean,
8 val services: Boolean
9)
11public struct TextCheckingOptions(
12 val spelling: Boolean = true,
13 val grammar: Boolean = true,
14 val replacements: Boolean = false,
15 val language: String? = None
18public enum TextCheckKind {
19 Spelling, Grammar, Replacement
22/** Ranges refer to the exact UTF-8 text passed to checkText. */
23public class TextCheckFinding internal constructor(
24 public val range: Utf8Range,
25 public val kind: TextCheckKind,
26 public val description: String,
27 public val suggestions: Array<String>
30/** Native text services return values; the caller retains its document and undo ownership. */
31public class SystemTextServices internal constructor(private val owner: ApplicationOwner) {
32 public val capabilities: TextServiceCapabilities get() {
33 owner.requireRunning("query text services")
34 return platformTextServiceCapabilities()
35 }
36 public fun checkText(text: String, options: TextCheckingOptions = TextCheckingOptions()): Array<
37 TextCheckFinding
38 > {
39 owner.requireRunning("check text")
40 when (options.language) {
41 case Some(val language) -> for (character in language)
42 requireWindow(character.code != 0, "text checking language contains NUL")
43 case None -> {}
44 }
45 return platformCheckText(text, options)
46 }
47 /** None means unavailable or declined; returned text has not been applied to a document. */
48 public fun performService(name: String, text: String): String? {
49 owner.requireRunning("perform text service")
50 requireWindow(name.byteLength > 0L, "empty text service name")
51 for (character in name)
52 requireWindow(character.code != 0, "text service name contains NUL")
53 return platformPerformTextService(name, text)
54 }
57public val ActiveApplication.textServices: SystemTextServices get() {
58 owner.requireRunning("get text services")
59 return SystemTextServices(owner)
62/** The anchor is a current visible content rectangle, not a guessed document position. */
63public fun Window.showTextDefinition(text: String, anchor: LogicalRect): Boolean {
64 owner.requireOpen()
65 checkRect(anchor)
66 if (text.byteLength == 0L || anchor.size.width <= 0.0 || anchor.size.height <= 0.0)
67 return false
68 return platformShowTextDefinition(owner.pointer!!, text, anchor)