OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
anonymous_namespace{MacIME.mm} Namespace Reference

Functions

id get (id object, const void *key)
void set (id object, const void *key, id value)
bool is_active (id view)
NSString * marked_text (id view)
void set_marked_text (id view, NSString *text, NSRange selected)
void claim_current_key (id view)
NSString * plain_string (id text)
void send_text (id view, NSString *text)
NSTextInputContext * ime_input_context (id self, SEL)
void ime_insert_text (id self, SEL, id text, NSRange)
void ime_set_marked_text (id self, SEL, id text, NSRange selected, NSRange)
void ime_unmark_text (id self, SEL)
BOOL ime_has_marked_text (id self, SEL)
NSRange ime_marked_range (id self, SEL)
NSRange ime_selected_range (id self, SEL)
NSRect ime_first_rect (id self, SEL, NSRange range, NSRangePointer actual_range)
NSAttributedString * ime_attributed_substring (id self, SEL, NSRange range, NSRangePointer actual_range)
NSArray * ime_valid_attributes (id, SEL)
NSUInteger ime_character_index (id, SEL, NSPoint)
void install (Class cls)

Variables

char key_installed
char key_context
char key_active
char key_marked
char key_selected
char key_caret
char key_ime_event

Function Documentation

◆ claim_current_key()

void anonymous_namespace{MacIME.mm}::claim_current_key ( id view)
39{
40 NSEvent* event = [NSApp currentEvent];
41 if (event.type == NSEventTypeKeyDown)
42 set(view, &key_ime_event, event);
43}
void set(id object, const void *key, id value)
Definition MacIME.mm:24
char key_ime_event
Definition MacIME.mm:20

References key_ime_event, and set().

Referenced by ime_insert_text(), ime_set_marked_text(), and ime_unmark_text().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get()

id anonymous_namespace{MacIME.mm}::get ( id object,
const void * key )
22{ return objc_getAssociatedObject(object, key); }

Referenced by ime_first_rect(), ime_input_context(), ime_selected_range(), install(), is_active(), and marked_text().

Here is the caller graph for this function:

◆ ime_attributed_substring()

NSAttributedString * anonymous_namespace{MacIME.mm}::ime_attributed_substring ( id self,
SEL ,
NSRange range,
NSRangePointer actual_range )
109{
110 NSString* text = marked_text(self);
111 const NSRange clamped = text != nil ? NSIntersectionRange(range, NSMakeRange(0, text.length)) : NSMakeRange(0, 0);
112 if (clamped.length == 0)
113 return nil;
114 if (actual_range != nullptr)
115 *actual_range = clamped;
116 return [[[NSAttributedString alloc] initWithString:[text substringWithRange:clamped]] autorelease];
117}
NSString * marked_text(id view)
Definition MacIME.mm:28

References marked_text().

Referenced by install().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ime_character_index()

NSUInteger anonymous_namespace{MacIME.mm}::ime_character_index ( id ,
SEL ,
NSPoint  )
121{ return NSNotFound; }

Referenced by install().

Here is the caller graph for this function:

◆ ime_first_rect()

NSRect anonymous_namespace{MacIME.mm}::ime_first_rect ( id self,
SEL ,
NSRange range,
NSRangePointer actual_range )
98{
99 if (actual_range != nullptr)
100 *actual_range = range;
101 NSView* view = self;
102 NSValue* caret = get(self, &key_caret);
103 // Without a reported cursor, the top-left corner of the canvas.
104 const NSRect rect = caret != nil ? caret.rectValue : NSMakeRect(0, 0, 1, 16);
105 return view.window != nil ? [view.window convertRectToScreen:[view convertRect:rect toView:nil]] : NSZeroRect;
106}
id get(id object, const void *key)
Definition MacIME.mm:22
char key_caret
Definition MacIME.mm:19

References get(), and key_caret.

Referenced by install().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ime_has_marked_text()

BOOL anonymous_namespace{MacIME.mm}::ime_has_marked_text ( id self,
SEL  )
83{ return marked_text(self) != nil; }

References marked_text().

Referenced by install().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ime_input_context()

NSTextInputContext * anonymous_namespace{MacIME.mm}::ime_input_context ( id self,
SEL  )
55{ return is_active(self) ? get(self, &key_context) : nil; }
bool is_active(id view)
Definition MacIME.mm:26
char key_context
Definition MacIME.mm:15

References get(), is_active(), and key_context.

Referenced by install().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ime_insert_text()

void anonymous_namespace{MacIME.mm}::ime_insert_text ( id self,
SEL ,
id text,
NSRange  )
58{
59 if (marked_text(self) != nil) {
61 set_marked_text(self, nil, {});
62 }
63 send_text(self, plain_string(text));
64}
NSString * plain_string(id text)
Definition MacIME.mm:45
void claim_current_key(id view)
Definition MacIME.mm:38
void set_marked_text(id view, NSString *text, NSRange selected)
Definition MacIME.mm:30
void send_text(id view, NSString *text)
Definition MacIME.mm:49

References claim_current_key(), marked_text(), plain_string(), send_text(), and set_marked_text().

Referenced by install().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ime_marked_range()

NSRange anonymous_namespace{MacIME.mm}::ime_marked_range ( id self,
SEL  )
86{
87 NSString* text = marked_text(self);
88 return text != nil ? NSMakeRange(0, text.length) : NSMakeRange(NSNotFound, 0);
89}

References marked_text().

Referenced by install().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ime_selected_range()

NSRange anonymous_namespace{MacIME.mm}::ime_selected_range ( id self,
SEL  )
92{
93 NSValue* selected = get(self, &key_selected);
94 return selected != nil ? selected.rangeValue : NSMakeRange(NSNotFound, 0);
95}
char key_selected
Definition MacIME.mm:18

References get(), and key_selected.

Referenced by install().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ime_set_marked_text()

void anonymous_namespace{MacIME.mm}::ime_set_marked_text ( id self,
SEL ,
id text,
NSRange selected,
NSRange  )
67{
69 set_marked_text(self, plain_string(text), selected);
70}

References claim_current_key(), plain_string(), and set_marked_text().

Referenced by install().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ime_unmark_text()

void anonymous_namespace{MacIME.mm}::ime_unmark_text ( id self,
SEL  )
74{
75 NSString* text = [[marked_text(self) retain] autorelease];
76 if (text == nil)
77 return;
79 set_marked_text(self, nil, {});
80 send_text(self, text);
81}

References claim_current_key(), marked_text(), send_text(), and set_marked_text().

Referenced by install().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ime_valid_attributes()

NSArray * anonymous_namespace{MacIME.mm}::ime_valid_attributes ( id ,
SEL  )
119{ return @[]; }

Referenced by install().

Here is the caller graph for this function:

◆ install()

void anonymous_namespace{MacIME.mm}::install ( Class cls)
124{
125 if (get(cls, &key_installed) != nil)
126 return;
127 set(cls, &key_installed, @YES);
128
129 Protocol* protocol = @protocol(NSTextInputClient);
130 class_addProtocol(cls, protocol);
131 const struct { SEL sel; IMP imp; } methods[] = {
132 { @selector(insertText:replacementRange:), (IMP) ime_insert_text },
133 { @selector(setMarkedText:selectedRange:replacementRange:), (IMP) ime_set_marked_text },
134 { @selector(unmarkText), (IMP) ime_unmark_text },
135 { @selector(hasMarkedText), (IMP) ime_has_marked_text },
136 { @selector(markedRange), (IMP) ime_marked_range },
137 { @selector(selectedRange), (IMP) ime_selected_range },
138 { @selector(firstRectForCharacterRange:actualRange:), (IMP) ime_first_rect },
139 { @selector(attributedSubstringForProposedRange:actualRange:), (IMP) ime_attributed_substring },
140 { @selector(validAttributesForMarkedText), (IMP) ime_valid_attributes },
141 { @selector(characterIndexForPoint:), (IMP) ime_character_index },
142 };
143 for (const auto& method : methods)
144 class_addMethod(cls, method.sel, method.imp, protocol_getMethodDescription(protocol, method.sel, YES, YES).types);
145 // The view's own doCommandBySelector: (from wx) stays: keys the input method passes on reach wx unchanged.
146 class_addMethod(cls, @selector(inputContext), (IMP) ime_input_context,
147 method_getTypeEncoding(class_getInstanceMethod([NSView class], @selector(inputContext))));
148}
NSRange ime_selected_range(id self, SEL)
Definition MacIME.mm:91
NSUInteger ime_character_index(id, SEL, NSPoint)
Definition MacIME.mm:121
NSTextInputContext * ime_input_context(id self, SEL)
Definition MacIME.mm:55
NSRange ime_marked_range(id self, SEL)
Definition MacIME.mm:85
NSAttributedString * ime_attributed_substring(id self, SEL, NSRange range, NSRangePointer actual_range)
Definition MacIME.mm:108
BOOL ime_has_marked_text(id self, SEL)
Definition MacIME.mm:83
char key_installed
Definition MacIME.mm:14
void ime_set_marked_text(id self, SEL, id text, NSRange selected, NSRange)
Definition MacIME.mm:66
void ime_unmark_text(id self, SEL)
Definition MacIME.mm:73
NSRect ime_first_rect(id self, SEL, NSRange range, NSRangePointer actual_range)
Definition MacIME.mm:97
NSArray * ime_valid_attributes(id, SEL)
Definition MacIME.mm:119
void ime_insert_text(id self, SEL, id text, NSRange)
Definition MacIME.mm:57

References get(), ime_attributed_substring(), ime_character_index(), ime_first_rect(), ime_has_marked_text(), ime_input_context(), ime_insert_text(), ime_marked_range(), ime_selected_range(), ime_set_marked_text(), ime_unmark_text(), ime_valid_attributes(), key_installed, and set().

Here is the call graph for this function:

◆ is_active()

bool anonymous_namespace{MacIME.mm}::is_active ( id view)
26{ return [get(view, &key_active) boolValue]; }
char key_active
Definition MacIME.mm:16

References get(), and key_active.

Referenced by ime_input_context().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ marked_text()

NSString * anonymous_namespace{MacIME.mm}::marked_text ( id view)
28{ return get(view, &key_marked); }
char key_marked
Definition MacIME.mm:17

References get(), and key_marked.

Referenced by ime_attributed_substring(), ime_has_marked_text(), ime_insert_text(), ime_marked_range(), and ime_unmark_text().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ plain_string()

NSString * anonymous_namespace{MacIME.mm}::plain_string ( id text)
45{ return [text isKindOfClass:[NSAttributedString class]] ? [text string] : text; }

Referenced by ime_insert_text(), and ime_set_marked_text().

Here is the caller graph for this function:

◆ send_text()

void anonymous_namespace{MacIME.mm}::send_text ( id view,
NSString * text )
50{
51 if (text.length > 0)
52 [view performSelector:@selector(insertText:) withObject:text];
53}

Referenced by ime_insert_text(), and ime_unmark_text().

Here is the caller graph for this function:

◆ set()

void anonymous_namespace{MacIME.mm}::set ( id object,
const void * key,
id value )
24{ objc_setAssociatedObject(object, key, value, OBJC_ASSOCIATION_RETAIN_NONATOMIC); }

Referenced by claim_current_key(), install(), and set_marked_text().

Here is the caller graph for this function:

◆ set_marked_text()

void anonymous_namespace{MacIME.mm}::set_marked_text ( id view,
NSString * text,
NSRange selected )
31{
32 const bool composing = text.length > 0;
33 set(view, &key_marked, composing ? text : nil);
34 set(view, &key_selected, composing ? [NSValue valueWithRange:selected] : nil);
35}

References key_marked, key_selected, and set().

Referenced by ime_insert_text(), ime_set_marked_text(), and ime_unmark_text().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ key_active

char anonymous_namespace{MacIME.mm}::key_active

Referenced by is_active().

◆ key_caret

char anonymous_namespace{MacIME.mm}::key_caret

Referenced by ime_first_rect().

◆ key_context

char anonymous_namespace{MacIME.mm}::key_context

Referenced by ime_input_context().

◆ key_ime_event

char anonymous_namespace{MacIME.mm}::key_ime_event

Referenced by claim_current_key().

◆ key_installed

char anonymous_namespace{MacIME.mm}::key_installed

Referenced by install().

◆ key_marked

char anonymous_namespace{MacIME.mm}::key_marked

Referenced by marked_text(), and set_marked_text().

◆ key_selected

char anonymous_namespace{MacIME.mm}::key_selected