Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Basic marked text handling
  • Loading branch information
jjgod committed May 31, 2009
1 parent e9cb391 commit a5e2709
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/video/cocoa/SDL_cocoaevents.m
Expand Up @@ -195,7 +195,7 @@ - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sende
/* FIXME: Find a way to stop the beeping, using delegate */

/* Add to support system-wide keyboard shortcuts like CMD+Space */
if ([event modifierFlags] & NSCommandKeyMask)
if (([event modifierFlags] & NSCommandKeyMask) || [event type] == NSFlagsChanged)
[NSApp sendEvent: event];
break;
default:
Expand Down
83 changes: 83 additions & 0 deletions src/video/cocoa/SDL_cocoakeyboard.m
Expand Up @@ -56,6 +56,9 @@

@interface SDLTranslatorResponder : NSTextView
{
NSString *_markedText;
NSRange _markedRange;
NSRange _selectedRange;
}
- (void) doCommandBySelector:(SEL)myselector;
@end
Expand All @@ -68,6 +71,8 @@ - (void) insertText:(id) aString

NSLog(@"insertText: %@", aString);

/* Could be NSString or NSAttributedString, so we have
* to test and convert it before return as SDL event */
if ([aString isKindOfClass: [NSAttributedString class]])
str = [[aString string] UTF8String];
else
Expand All @@ -81,6 +86,84 @@ - (void) doCommandBySelector:(SEL) myselector
NSLog(@"doCommandBySelector, passed down");
[super doCommandBySelector: myselector];
}

- (BOOL) hasMarkedText
{
return _markedText != nil;
}

- (NSRange) markedRange
{
return _markedRange;
}

- (NSRange) selectedRange
{
return _selectedRange;
}

- (void) setMarkedText:(id) aString
selectedRange:(NSRange) selRange
{
if ([aString isKindOfClass: [NSAttributedString class]])
aString = [aString string];

if ([aString length] == 0)
{
[self unmarkText];
return;
}

if (_markedText != aString)
{
[_markedText release];
_markedText = [aString retain];
}

_selectedRange = selRange;
_markedRange = NSMakeRange(0, [aString length]);

NSLog(@"setMarkedText: %@, (%d, %d)", _markedText,
selRange.location, selRange.length);
}

- (void) unmarkText
{
[_markedText release];
_markedText = nil;
}

- (NSRect) firstRectForCharacterRange: (NSRange) theRange
{
return NSMakeRect(0, 0, 0, 0);
}

- (NSAttributedString *) attributedSubstringFromRange: (NSRange) theRange
{
return nil;
}

- (NSInteger) conversationIdentifier
{
return (NSInteger) self;
}

// This method returns the index for character that is
// nearest to thePoint. thPoint is in screen coordinate system.
- (NSUInteger) characterIndexForPoint:(NSPoint) thePoint
{
return 0;
}

// This method is the key to attribute extension.
// We could add new attributes through this method.
// NSInputServer examines the return value of this
// method & constructs appropriate attributed string.
- (NSArray *) validAttributesForMarkedText
{
return [NSArray array];
}

@end

/* This is the original behavior, before support was added for
Expand Down

0 comments on commit a5e2709

Please sign in to comment.