comparison mac/dw.m @ 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
comparison
equal deleted inserted replaced
886:d94a4fa0359e 887:29d8ae25a78c
757 } 757 }
758 758
759 return newRect; 759 return newRect;
760 } 760 }
761 -(void)setVCenter:(BOOL)input { vcenter = input; } 761 -(void)setVCenter:(BOOL)input { vcenter = input; }
762 @end
763
764 @interface DWEntryFieldFormatter : NSFormatter
765 {
766 int maxLength;
767 }
768 - (void)setMaximumLength:(int)len;
769 - (int)maximumLength;
770 @end
771
772 /* This formatter subclass will allow us to limit
773 * the text length in an entryfield.
774 */
775 @implementation DWEntryFieldFormatter
776 -(id)init
777 {
778 [super init];
779 maxLength = INT_MAX;
780 return self;
781 }
782 -(void)setMaximumLength:(int)len { maxLength = len; }
783 -(int)maximumLength { return maxLength; }
784 -(NSString *)stringForObjectValue:(id)object { return (NSString *)object; }
785 -(BOOL)getObjectValue:(id *)object forString:(NSString *)string errorDescription:(NSString **)error { *object = string; return YES; }
786 -(BOOL)isPartialStringValid:(NSString **)partialStringPtr
787 proposedSelectedRange:(NSRangePointer)proposedSelRangePtr
788 originalString:(NSString *)origString
789 originalSelectedRange:(NSRange)origSelRange
790 errorDescription:(NSString **)error
791 {
792 if([*partialStringPtr length] > maxLength)
793 {
794 return NO;
795 }
796 return YES;
797 }
798 -(NSAttributedString *)attributedStringForObjectValue:(id)anObject withDefaultAttributes:(NSDictionary *)attributes { return nil; }
762 @end 799 @end
763 800
764 /* Subclass for a entryfield type */ 801 /* Subclass for a entryfield type */
765 @interface DWEntryField : NSTextField 802 @interface DWEntryField : NSTextField
766 { 803 {
3105 * handle: Handle to the spinbutton to be set. 3142 * handle: Handle to the spinbutton to be set.
3106 * limit: Number of characters the entryfield will take. 3143 * limit: Number of characters the entryfield will take.
3107 */ 3144 */
3108 void API dw_entryfield_set_limit(HWND handle, ULONG limit) 3145 void API dw_entryfield_set_limit(HWND handle, ULONG limit)
3109 { 3146 {
3110 NSLog(@"dw_entryfield_set_limit() unimplemented\n"); 3147 DWEntryField *entry = handle;
3148 DWEntryFieldFormatter *formatter = [[DWEntryFieldFormatter alloc] init];
3149
3150 [formatter setMaximumLength:(int)limit];
3151 [[entry cell] setFormatter:formatter];
3111 } 3152 }
3112 3153
3113 /* 3154 /*
3114 * Create a new bitmap button window (widget) to be packed. 3155 * Create a new bitmap button window (widget) to be packed.
3115 * Parameters: 3156 * Parameters: