Move RANumberFormatter to cocoatouch_menu.m

This commit is contained in:
Twinaphex 2015-04-21 01:14:10 +02:00
parent f435958371
commit dcac3bf21f
3 changed files with 52 additions and 55 deletions

View File

@ -217,13 +217,7 @@ extern id<RetroArch_Platform> apple_platform;
extern void apple_display_alert(const char *message, const char *title);
@interface RANumberFormatter : NSNumberFormatter
#if defined(HAVE_COCOATOUCH)
<UITextFieldDelegate>
#endif
- (id)initWithSetting:(const rarch_setting_t*)setting;
@end
#define BOXSTRING(x) [NSString stringWithUTF8String:x]
#define BOXINT(x) [NSNumber numberWithInt:x]

View File

@ -18,55 +18,6 @@
#include <sys/stat.h>
#include "cocoa_common.h"
// Number formatter class for setting strings
@implementation RANumberFormatter
- (id)initWithSetting:(const rarch_setting_t*)setting
{
if ((self = [super init]))
{
[self setAllowsFloats:(setting->type == ST_FLOAT)];
if (setting->flags & SD_FLAG_HAS_RANGE)
{
[self setMinimum:BOXFLOAT(setting->min)];
[self setMaximum:BOXFLOAT(setting->max)];
}
}
return self;
}
- (BOOL)isPartialStringValid:(NSString*)partialString newEditingString:(NSString**)newString errorDescription:(NSString**)error
{
unsigned i;
bool hasDot = false;
if (partialString.length)
for (i = 0; i < partialString.length; i ++)
{
unichar ch = [partialString characterAtIndex:i];
if (i == 0 && (!self.minimum || self.minimum.intValue < 0) && ch == '-')
continue;
else if (self.allowsFloats && !hasDot && ch == '.')
hasDot = true;
else if (!isdigit(ch))
return NO;
}
return YES;
}
#if defined(HAVE_COCOATOUCH)
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSString* text = (NSString*)[[textField text] stringByReplacingCharactersInRange:range withString:string];
return [self isPartialStringValid:text newEditingString:nil errorDescription:nil];
}
#endif
@end
/* Define compatibility symbols and categories. */
#ifdef HAVE_AVFOUNDATION

View File

@ -27,6 +27,58 @@
#include "../../../menu/menu_entries.h"
#include "../../../menu/drivers/shared.h"
@interface RANumberFormatter : NSNumberFormatter<UITextFieldDelegate>
- (id)initWithSetting:(const rarch_setting_t*)setting;
@end
// Number formatter class for setting strings
@implementation RANumberFormatter
- (id)initWithSetting:(const rarch_setting_t*)setting
{
if ((self = [super init]))
{
[self setAllowsFloats:(setting->type == ST_FLOAT)];
if (setting->flags & SD_FLAG_HAS_RANGE)
{
[self setMinimum:BOXFLOAT(setting->min)];
[self setMaximum:BOXFLOAT(setting->max)];
}
}
return self;
}
- (BOOL)isPartialStringValid:(NSString*)partialString newEditingString:(NSString**)newString errorDescription:(NSString**)error
{
unsigned i;
bool hasDot = false;
if (partialString.length)
for (i = 0; i < partialString.length; i ++)
{
unichar ch = [partialString characterAtIndex:i];
if (i == 0 && (!self.minimum || self.minimum.intValue < 0) && ch == '-')
continue;
else if (self.allowsFloats && !hasDot && ch == '.')
hasDot = true;
else if (!isdigit(ch))
return NO;
}
return YES;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSString* text = (NSString*)[[textField text] stringByReplacingCharactersInRange:range withString:string];
return [self isPartialStringValid:text newEditingString:nil errorDescription:nil];
}
@end
/*********************************************/
/* RunActionSheet */
/* Creates and displays a UIActionSheet with */