native maxlength support, fixes #10269 (for osx_cocoa)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70356 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -107,6 +107,55 @@ protected :
|
|||||||
|
|
||||||
NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil;
|
NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil;
|
||||||
|
|
||||||
|
// a minimal NSFormatter that just avoids getting too long entries
|
||||||
|
@interface wxMaximumLengthFormatter : NSFormatter
|
||||||
|
{
|
||||||
|
int maxLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation wxMaximumLengthFormatter
|
||||||
|
|
||||||
|
- (id)init
|
||||||
|
{
|
||||||
|
[super init];
|
||||||
|
maxLength = 0;
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) setMaxLength:(int) maxlen
|
||||||
|
{
|
||||||
|
maxLength = maxlen;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString *)stringForObjectValue:(id)anObject
|
||||||
|
{
|
||||||
|
if(![anObject isKindOfClass:[NSString class]])
|
||||||
|
return nil;
|
||||||
|
return [NSString stringWithString:anObject];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)getObjectValue:(id *)obj forString:(NSString *)string errorDescription:(NSString **)error
|
||||||
|
{
|
||||||
|
*obj = [NSString stringWithString:string];
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)isPartialStringValid:(NSString **)partialStringPtr proposedSelectedRange:(NSRangePointer)proposedSelRangePtr
|
||||||
|
originalString:(NSString *)origString originalSelectedRange:(NSRange)origSelRange errorDescription:(NSString **)error
|
||||||
|
{
|
||||||
|
int len = [*partialStringPtr length];
|
||||||
|
if ( maxLength > 0 && len > maxLength )
|
||||||
|
{
|
||||||
|
// TODO wxEVT_COMMAND_TEXT_MAXLEN
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
@implementation wxNSSecureTextField
|
@implementation wxNSSecureTextField
|
||||||
|
|
||||||
+ (void)initialize
|
+ (void)initialize
|
||||||
@@ -688,6 +737,13 @@ void wxNSTextFieldControl::SetStringValue( const wxString &str)
|
|||||||
[m_textField setStringValue: wxCFStringRef( str , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
|
[m_textField setStringValue: wxCFStringRef( str , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxNSTextFieldControl::SetMaxLength(unsigned long len)
|
||||||
|
{
|
||||||
|
wxMaximumLengthFormatter* formatter = [[[wxMaximumLengthFormatter alloc] init] autorelease];
|
||||||
|
[formatter setMaxLength:len];
|
||||||
|
[m_textField setFormatter:formatter];
|
||||||
|
}
|
||||||
|
|
||||||
void wxNSTextFieldControl::Copy()
|
void wxNSTextFieldControl::Copy()
|
||||||
{
|
{
|
||||||
NSText* editor = [m_textField currentEditor];
|
NSText* editor = [m_textField currentEditor];
|
||||||
|
Reference in New Issue
Block a user