Mercurial > dwindows
changeset 887:29d8ae25a78c
Implemented dw_entryfield_set_limit() on the Mac using a custom formatter class.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 07 Apr 2011 18:44:07 +0000 |
parents | d94a4fa0359e |
children | cd6ff038e38b |
files | mac/dw.m |
diffstat | 1 files changed, 42 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mac/dw.m Thu Apr 07 18:20:04 2011 +0000 +++ b/mac/dw.m Thu Apr 07 18:44:07 2011 +0000 @@ -761,6 +761,43 @@ -(void)setVCenter:(BOOL)input { vcenter = input; } @end +@interface DWEntryFieldFormatter : NSFormatter +{ + int maxLength; +} +- (void)setMaximumLength:(int)len; +- (int)maximumLength; +@end + +/* This formatter subclass will allow us to limit + * the text length in an entryfield. + */ +@implementation DWEntryFieldFormatter +-(id)init +{ + [super init]; + maxLength = INT_MAX; + return self; +} +-(void)setMaximumLength:(int)len { maxLength = len; } +-(int)maximumLength { return maxLength; } +-(NSString *)stringForObjectValue:(id)object { return (NSString *)object; } +-(BOOL)getObjectValue:(id *)object forString:(NSString *)string errorDescription:(NSString **)error { *object = string; return YES; } +-(BOOL)isPartialStringValid:(NSString **)partialStringPtr + proposedSelectedRange:(NSRangePointer)proposedSelRangePtr + originalString:(NSString *)origString + originalSelectedRange:(NSRange)origSelRange + errorDescription:(NSString **)error +{ + if([*partialStringPtr length] > maxLength) + { + return NO; + } + return YES; +} +-(NSAttributedString *)attributedStringForObjectValue:(id)anObject withDefaultAttributes:(NSDictionary *)attributes { return nil; } +@end + /* Subclass for a entryfield type */ @interface DWEntryField : NSTextField { @@ -3107,7 +3144,11 @@ */ void API dw_entryfield_set_limit(HWND handle, ULONG limit) { - NSLog(@"dw_entryfield_set_limit() unimplemented\n"); + DWEntryField *entry = handle; + DWEntryFieldFormatter *formatter = [[DWEntryFieldFormatter alloc] init]; + + [formatter setMaximumLength:(int)limit]; + [[entry cell] setFormatter:formatter]; } /*