+#pragma mark NSTextInput implementation
+
+- (NSInputContext *)inputContext
+{
+ if ([self isStarted] && eventModel == NPEventModelCarbon)
+ return nil;
+
+ return [super inputContext];
+}
+
+- (BOOL)hasMarkedText
+{
+ ASSERT(eventModel == NPEventModelCocoa);
+ ASSERT([self isStarted]);
+
+ if (textInputFuncs && textInputFuncs->hasMarkedText)
+ return textInputFuncs->hasMarkedText(plugin);
+
+ return NO;
+}
+
+- (void)insertText:(id)aString
+{
+ ASSERT(eventModel == NPEventModelCocoa);
+ ASSERT([self isStarted]);
+
+ if (textInputFuncs && textInputFuncs->insertText)
+ textInputFuncs->insertText(plugin, aString);
+}
+
+- (NSRange)markedRange
+{
+ ASSERT(eventModel == NPEventModelCocoa);
+ ASSERT([self isStarted]);
+
+ if (textInputFuncs && textInputFuncs->markedRange)
+ return textInputFuncs->markedRange(plugin);
+
+ return NSMakeRange(NSNotFound, 0);
+}
+
+- (NSRange)selectedRange
+{
+ ASSERT(eventModel == NPEventModelCocoa);
+ ASSERT([self isStarted]);
+
+ if (textInputFuncs && textInputFuncs->selectedRange)
+ return textInputFuncs->selectedRange(plugin);
+
+ return NSMakeRange(NSNotFound, 0);
+}
+
+- (void)setMarkedText:(id)aString selectedRange:(NSRange)selRange
+{
+ ASSERT(eventModel == NPEventModelCocoa);
+ ASSERT([self isStarted]);
+
+ if (textInputFuncs && textInputFuncs->setMarkedText)
+ textInputFuncs->setMarkedText(plugin, aString, selRange);
+}
+
+- (void)unmarkText
+{
+ ASSERT(eventModel == NPEventModelCocoa);
+ ASSERT([self isStarted]);
+
+ if (textInputFuncs && textInputFuncs->unmarkText)
+ textInputFuncs->unmarkText(plugin);
+}
+
+- (NSArray *)validAttributesForMarkedText
+{
+ ASSERT(eventModel == NPEventModelCocoa);
+ ASSERT([self isStarted]);
+
+ if (textInputFuncs && textInputFuncs->validAttributesForMarkedText)
+ return textInputFuncs->validAttributesForMarkedText(plugin);
+
+ return [NSArray array];
+}
+
+- (NSAttributedString *)attributedSubstringFromRange:(NSRange)theRange
+{
+ ASSERT(eventModel == NPEventModelCocoa);
+ ASSERT([self isStarted]);
+
+ if (textInputFuncs && textInputFuncs->attributedSubstringFromRange)
+ return textInputFuncs->attributedSubstringFromRange(plugin, theRange);
+
+ return nil;
+}
+
+- (NSUInteger)characterIndexForPoint:(NSPoint)thePoint
+{
+ ASSERT(eventModel == NPEventModelCocoa);
+ ASSERT([self isStarted]);
+
+ if (textInputFuncs && textInputFuncs->characterIndexForPoint) {
+ // Convert the point to window coordinates
+ NSPoint point = [[self window] convertScreenToBase:thePoint];
+
+ // And view coordinates
+ point = [self convertPoint:point fromView:nil];
+
+ return textInputFuncs->characterIndexForPoint(plugin, point);
+ }
+
+ return NSNotFound;
+}
+
+- (void)doCommandBySelector:(SEL)aSelector
+{
+ ASSERT(eventModel == NPEventModelCocoa);
+ ASSERT([self isStarted]);
+
+ if (textInputFuncs && textInputFuncs->doCommandBySelector)
+ textInputFuncs->doCommandBySelector(plugin, aSelector);
+}
+
+- (NSRect)firstRectForCharacterRange:(NSRange)theRange
+{
+ ASSERT(eventModel == NPEventModelCocoa);
+ ASSERT([self isStarted]);
+
+ if (textInputFuncs && textInputFuncs->firstRectForCharacterRange) {
+ NSRect rect = textInputFuncs->firstRectForCharacterRange(plugin, theRange);
+
+ // Convert the rect to window coordinates
+ rect = [self convertRect:rect toView:nil];
+
+ // Convert the rect location to screen coordinates
+ rect.origin = [[self window] convertBaseToScreen:rect.origin];
+
+ return rect;
+ }
+
+ return NSZeroRect;
+}
+
+// test for 10.4 because of <rdar://problem/4243463>
+#ifdef BUILDING_ON_TIGER
+- (long)conversationIdentifier
+{
+ return (long)self;
+}
+#else
+- (NSInteger)conversationIdentifier
+{
+ return (NSInteger)self;
+}
+#endif
+