Ticket #38850: patch-src-osx-cocoa-window.mm.diff

File patch-src-osx-cocoa-window.mm.diff, 3.2 KB (added by mkae (Marko Käning), 11 years ago)

patch from http://trac.wxwidgets.org/changeset/74613

  • src/osx/cocoa/window.mm

     
    109109
    110110@end // wxNSView
     111
     112@interface wxNSView(TextInput) <NSTextInputClient>
     113
     114- (void)insertText:(id)aString replacementRange:(NSRange)replacementRange;
     115- (void)doCommandBySelector:(SEL)aSelector;
     116- (void)setMarkedText:(id)aString selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange;
     117- (void)unmarkText;
     118- (NSRange)selectedRange;
     119- (NSRange)markedRange;
     120- (BOOL)hasMarkedText;
     121- (NSAttributedString *)attributedSubstringForProposedRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange;
     122- (NSArray*)validAttributesForMarkedText;
     123- (NSRect)firstRectForCharacterRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange;
     124- (NSUInteger)characterIndexForPoint:(NSPoint)aPoint;
     125
     126@end
    111127
    112128@interface NSView(PossibleMethods)
     
    837853@end // wxNSView
    838854
     855// We need to adopt NSTextInputClient protocol in order to interpretKeyEvents: to work.
     856// Currently, only insertText:(replacementRange:) is
     857// implemented here, and the rest of the methods are stubs.
     858// It is hoped that someday IME-related functionality is implemented in
     859// wxWidgets and the methods of this protocol are fully working.
     860
     861@implementation wxNSView(TextInput)
     862
     863void wxOSX_insertText(NSView* self, SEL _cmd, NSString* text);
     864
     865- (void)insertText:(id)aString replacementRange:(NSRange)replacementRange
     866{
     867    wxOSX_insertText(self, @selector(insertText:), aString);
     868}
     869
     870- (void)doCommandBySelector:(SEL)aSelector
     871{
     872    // these are already caught in the keyEvent handler
     873}
     874
     875- (void)setMarkedText:(id)aString selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange
     876{
     877}
     878
     879- (void)unmarkText
     880{
     881}
     882
     883- (NSRange)selectedRange
     884{   
     885    return NSMakeRange(NSNotFound, 0);
     886}
     887
     888- (NSRange)markedRange
     889{
     890    return NSMakeRange(NSNotFound, 0);
     891}
     892
     893- (BOOL)hasMarkedText
     894{
     895    return NO;
     896}
     897
     898- (NSAttributedString *)attributedSubstringForProposedRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange
     899{
     900    return nil;
     901}
     902
     903- (NSArray*)validAttributesForMarkedText
     904{
     905    return nil;
     906}
     907
     908- (NSRect)firstRectForCharacterRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange
     909{
     910    return NSMakeRect(0, 0, 0, 0);
     911}
     912- (NSUInteger)characterIndexForPoint:(NSPoint)aPoint
     913{
     914    return NSNotFound;
     915}
     916
     917@end // wxNSView(TextInput)
     918
     919
    839920//
    840921// event handlers
     
    25552636bool wxWidgetCocoaImpl::DoHandleCharEvent(NSEvent *event, NSString *text)
    25562637{
    2557     wxKeyEvent wxevent(wxEVT_CHAR);
    2558     SetupKeyEvent( wxevent, event, text );
    2559 
    2560     return GetWXPeer()->OSXHandleKeyEvent(wxevent);
     2638    bool result = false;
     2639   
     2640    for (NSUInteger i = 0; i < [text length]; ++i)
     2641    {
     2642        wxKeyEvent wxevent(wxEVT_CHAR);
     2643        unichar c = [text characterAtIndex:i];
     2644        SetupKeyEvent( wxevent, event, [NSString stringWithCharacters:&c length:1]);
     2645
     2646        result = GetWXPeer()->OSXHandleKeyEvent(wxevent) || result;
     2647    }
     2648   
     2649    return result;
    25612650}
    25622651