From a672d82a64965edcef6260c6fefffb94f76dd096 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Sun, 28 Jul 2013 17:36:23 +0000 Subject: [PATCH] first attempt at adding the minimal set needed for dead-key support, see #15345 git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74613 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/osx/cocoa/window.mm | 95 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 92 insertions(+), 3 deletions(-) diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index 57caf59576..78cd6f99aa 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -109,6 +109,22 @@ NSRect wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const @end // wxNSView +@interface wxNSView(TextInput) + +- (void)insertText:(id)aString replacementRange:(NSRange)replacementRange; +- (void)doCommandBySelector:(SEL)aSelector; +- (void)setMarkedText:(id)aString selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange; +- (void)unmarkText; +- (NSRange)selectedRange; +- (NSRange)markedRange; +- (BOOL)hasMarkedText; +- (NSAttributedString *)attributedSubstringForProposedRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange; +- (NSArray*)validAttributesForMarkedText; +- (NSRect)firstRectForCharacterRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange; +- (NSUInteger)characterIndexForPoint:(NSPoint)aPoint; + +@end + @interface NSView(PossibleMethods) - (void)setTitle:(NSString *)aString; - (void)setStringValue:(NSString *)aString; @@ -836,6 +852,71 @@ void wxWidgetCocoaImpl::SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEve @end // wxNSView +// We need to adopt NSTextInputClient protocol in order to interpretKeyEvents: to work. +// Currently, only insertText:(replacementRange:) is +// implemented here, and the rest of the methods are stubs. +// It is hoped that someday IME-related functionality is implemented in +// wxWidgets and the methods of this protocol are fully working. + +@implementation wxNSView(TextInput) + +void wxOSX_insertText(NSView* self, SEL _cmd, NSString* text); + +- (void)insertText:(id)aString replacementRange:(NSRange)replacementRange +{ + wxOSX_insertText(self, @selector(insertText:), aString); +} + +- (void)doCommandBySelector:(SEL)aSelector +{ + // these are already caught in the keyEvent handler +} + +- (void)setMarkedText:(id)aString selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange +{ +} + +- (void)unmarkText +{ +} + +- (NSRange)selectedRange +{ + return NSMakeRange(NSNotFound, 0); +} + +- (NSRange)markedRange +{ + return NSMakeRange(NSNotFound, 0); +} + +- (BOOL)hasMarkedText +{ + return NO; +} + +- (NSAttributedString *)attributedSubstringForProposedRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange +{ + return nil; +} + +- (NSArray*)validAttributesForMarkedText +{ + return nil; +} + +- (NSRect)firstRectForCharacterRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange +{ + return NSMakeRect(0, 0, 0, 0); +} +- (NSUInteger)characterIndexForPoint:(NSPoint)aPoint +{ + return NSNotFound; +} + +@end // wxNSView(TextInput) + + // // event handlers // @@ -2554,10 +2635,18 @@ void wxWidgetCocoaImpl::InstallEventHandler( WXWidget control ) bool wxWidgetCocoaImpl::DoHandleCharEvent(NSEvent *event, NSString *text) { - wxKeyEvent wxevent(wxEVT_CHAR); - SetupKeyEvent( wxevent, event, text ); + bool result = false; + + for (NSUInteger i = 0; i < [text length]; ++i) + { + wxKeyEvent wxevent(wxEVT_CHAR); + unichar c = [text characterAtIndex:i]; + SetupKeyEvent( wxevent, event, [NSString stringWithCharacters:&c length:1]); - return GetWXPeer()->OSXHandleKeyEvent(wxevent); + result = GetWXPeer()->OSXHandleKeyEvent(wxevent) || result; + } + + return result; } bool wxWidgetCocoaImpl::DoHandleKeyEvent(NSEvent *event) -- 2.45.2