Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/yabause/src/cocoa/YabauseButtonFormatter.m
2 views
1
/* Copyright 2011 Lawrence Sebald
2
3
This file is part of Yabause.
4
5
Yabause is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or
8
(at your option) any later version.
9
10
Yabause is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
14
15
You should have received a copy of the GNU General Public License
16
along with Yabause; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
*/
19
20
#include "YabauseButtonFormatter.h"
21
#include <objc/runtime.h>
22
23
@implementation YabauseButtonFormatter
24
25
- (NSString *)stringForObjectValue:(id)obj
26
{
27
if(![obj isKindOfClass:[NSString class]]) {
28
return nil;
29
}
30
31
if([obj length] >= 1) {
32
return [obj substringToIndex:1];
33
}
34
else {
35
return [NSString string];
36
}
37
}
38
39
- (BOOL)getObjectValue:(id *)obj
40
forString:(NSString *)str
41
errorDescription:(NSString **)err
42
{
43
if(obj) {
44
if([str length] >= 1) {
45
*obj = [NSString stringWithString:[str substringToIndex:1]];
46
}
47
else {
48
*obj = [NSString string];
49
}
50
}
51
52
return YES;
53
}
54
55
- (BOOL)isPartialStringValid:(NSString **)partialStringPtr
56
proposedSelectedRange:(NSRangePointer)proposedSelRangePtr
57
originalString:(NSString *)origString
58
originalSelectedRange:(NSRange)origSelRange
59
errorDescription:(NSString **)error
60
{
61
NSString *rs = [[*partialStringPtr substringToIndex:1] uppercaseString];
62
63
*partialStringPtr = rs;
64
*proposedSelRangePtr = NSMakeRange(0, [rs length]);
65
66
return NO;
67
}
68
69
- (BOOL)control:(NSControl*)control
70
textView:(NSTextView*)textView
71
doCommandBySelector:(SEL)commandSelector
72
{
73
BOOL result = NO;
74
75
/* handle all the fun special cases... */
76
if(commandSelector == @selector(insertNewline:)) {
77
[textView insertText:@"\u23CE"];
78
result = YES;
79
}
80
else if(commandSelector == @selector(insertTab:)) {
81
[textView insertText:@"\u21E5"];
82
result = YES;
83
}
84
else if(commandSelector == @selector(cancelOperation:)) {
85
[textView insertText:@"\u241B"];
86
result = YES;
87
}
88
else if(commandSelector == @selector(deleteBackward:)) {
89
[textView insertText:@"\u232B"];
90
result = YES;
91
}
92
else if(commandSelector == @selector(moveLeft:)) {
93
[textView insertText:@"\u2190"];
94
result = YES;
95
}
96
else if(commandSelector == @selector(moveUp:)) {
97
[textView insertText:@"\u2191"];
98
result = YES;
99
}
100
else if(commandSelector == @selector(moveRight:)) {
101
[textView insertText:@"\u2192"];
102
result = YES;
103
}
104
else if(commandSelector == @selector(moveDown:)) {
105
[textView insertText:@"\u2193"];
106
result = YES;
107
}
108
109
return result;
110
}
111
112
@end /* @implementation YabauseButtonFormatter */
113
114