Path: blob/master/yabause/src/cocoa/YabauseButtonFormatter.m
2 views
/* Copyright 2011 Lawrence Sebald12This file is part of Yabause.34Yabause is free software; you can redistribute it and/or modify5it under the terms of the GNU General Public License as published by6the Free Software Foundation; either version 2 of the License, or7(at your option) any later version.89Yabause is distributed in the hope that it will be useful,10but WITHOUT ANY WARRANTY; without even the implied warranty of11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12GNU General Public License for more details.1314You should have received a copy of the GNU General Public License15along with Yabause; if not, write to the Free Software16Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA17*/1819#include "YabauseButtonFormatter.h"20#include <objc/runtime.h>2122@implementation YabauseButtonFormatter2324- (NSString *)stringForObjectValue:(id)obj25{26if(![obj isKindOfClass:[NSString class]]) {27return nil;28}2930if([obj length] >= 1) {31return [obj substringToIndex:1];32}33else {34return [NSString string];35}36}3738- (BOOL)getObjectValue:(id *)obj39forString:(NSString *)str40errorDescription:(NSString **)err41{42if(obj) {43if([str length] >= 1) {44*obj = [NSString stringWithString:[str substringToIndex:1]];45}46else {47*obj = [NSString string];48}49}5051return YES;52}5354- (BOOL)isPartialStringValid:(NSString **)partialStringPtr55proposedSelectedRange:(NSRangePointer)proposedSelRangePtr56originalString:(NSString *)origString57originalSelectedRange:(NSRange)origSelRange58errorDescription:(NSString **)error59{60NSString *rs = [[*partialStringPtr substringToIndex:1] uppercaseString];6162*partialStringPtr = rs;63*proposedSelRangePtr = NSMakeRange(0, [rs length]);6465return NO;66}6768- (BOOL)control:(NSControl*)control69textView:(NSTextView*)textView70doCommandBySelector:(SEL)commandSelector71{72BOOL result = NO;7374/* handle all the fun special cases... */75if(commandSelector == @selector(insertNewline:)) {76[textView insertText:@"\u23CE"];77result = YES;78}79else if(commandSelector == @selector(insertTab:)) {80[textView insertText:@"\u21E5"];81result = YES;82}83else if(commandSelector == @selector(cancelOperation:)) {84[textView insertText:@"\u241B"];85result = YES;86}87else if(commandSelector == @selector(deleteBackward:)) {88[textView insertText:@"\u232B"];89result = YES;90}91else if(commandSelector == @selector(moveLeft:)) {92[textView insertText:@"\u2190"];93result = YES;94}95else if(commandSelector == @selector(moveUp:)) {96[textView insertText:@"\u2191"];97result = YES;98}99else if(commandSelector == @selector(moveRight:)) {100[textView insertText:@"\u2192"];101result = YES;102}103else if(commandSelector == @selector(moveDown:)) {104[textView insertText:@"\u2193"];105result = YES;106}107108return result;109}110111@end /* @implementation YabauseButtonFormatter */112113114