Mercurial > dwindows
comparison mac/dw.m @ 859:80a88c91ccf6
Implemented vertical centering on text fields.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 01 Apr 2011 01:22:00 +0000 |
parents | 80f3e108fa43 |
children | 93ac372941c4 |
comparison
equal
deleted
inserted
replaced
858:80f3e108fa43 | 859:80a88c91ccf6 |
---|---|
711 -(void *)userdata { return userdata; } | 711 -(void *)userdata { return userdata; } |
712 -(void)setUserdata:(void *)input { userdata = input; } | 712 -(void)setUserdata:(void *)input { userdata = input; } |
713 -(void)setBox:(void *)input { box = input; } | 713 -(void)setBox:(void *)input { box = input; } |
714 -(id)box { return box; } | 714 -(id)box { return box; } |
715 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } | 715 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } |
716 @end | |
717 | |
718 /* Subclass for a textfield that supports vertical centering */ | |
719 @interface DWTextFieldCell : NSTextFieldCell | |
720 { | |
721 BOOL vcenter; | |
722 } | |
723 -(NSRect)drawingRectForBounds:(NSRect)theRect; | |
724 -(void)setVCenter:(BOOL)input; | |
725 @end | |
726 | |
727 @implementation DWTextFieldCell | |
728 -(NSRect)drawingRectForBounds:(NSRect)theRect | |
729 { | |
730 /* Get the parent's idea of where we should draw */ | |
731 NSRect newRect = [super drawingRectForBounds:theRect]; | |
732 | |
733 /* If we are being vertically centered */ | |
734 if(vcenter) | |
735 { | |
736 /* Get our ideal size for current text */ | |
737 NSSize textSize = [self cellSizeForBounds:theRect]; | |
738 | |
739 /* Center that in the proposed rect */ | |
740 float heightDelta = newRect.size.height - textSize.height; | |
741 if (heightDelta > 0) | |
742 { | |
743 newRect.size.height -= heightDelta; | |
744 newRect.origin.y += (heightDelta / 2); | |
745 } | |
746 } | |
747 | |
748 return newRect; | |
749 } | |
750 -(void)setVCenter:(BOOL)input { vcenter = input; } | |
716 @end | 751 @end |
717 | 752 |
718 /* Subclass for a entryfield type */ | 753 /* Subclass for a entryfield type */ |
719 @interface DWEntryField : NSTextField | 754 @interface DWEntryField : NSTextField |
720 { | 755 { |
6480 } | 6515 } |
6481 else if([object isKindOfClass:[NSTextField class]]) | 6516 else if([object isKindOfClass:[NSTextField class]]) |
6482 { | 6517 { |
6483 NSTextField *tf = object; | 6518 NSTextField *tf = object; |
6484 | 6519 |
6485 /* TODO: See if we need to switch to a bitmask */ | 6520 [[tf cell] setAlignment:(style & 0xF)]; |
6486 [[tf cell] setAlignment:style]; | 6521 if(style & DW_DT_VCENTER) |
6522 { | |
6523 [[tf cell] setVCenter:YES]; | |
6524 } | |
6487 } | 6525 } |
6488 else if([object isMemberOfClass:[NSTextView class]]) | 6526 else if([object isMemberOfClass:[NSTextView class]]) |
6489 { | 6527 { |
6490 NSTextView *tv = handle; | 6528 NSTextView *tv = handle; |
6491 [tv setAlignment:(style & mask)]; | 6529 [tv setAlignment:(style & mask)]; |
8217 DWThreadMutex2 = dw_mutex_new(); | 8255 DWThreadMutex2 = dw_mutex_new(); |
8218 /* Use NSThread to start a dummy thread to initialize the threading subsystem */ | 8256 /* Use NSThread to start a dummy thread to initialize the threading subsystem */ |
8219 NSThread *thread = [[ NSThread alloc] initWithTarget:DWObj selector:@selector(uselessThread:) object:nil]; | 8257 NSThread *thread = [[ NSThread alloc] initWithTarget:DWObj selector:@selector(uselessThread:) object:nil]; |
8220 [thread start]; | 8258 [thread start]; |
8221 [thread release]; | 8259 [thread release]; |
8260 [NSTextField setCellClass:[DWTextFieldCell class]]; | |
8222 return 0; | 8261 return 0; |
8223 } | 8262 } |
8224 | 8263 |
8225 /* | 8264 /* |
8226 * Allocates a shared memory region with a name. | 8265 * Allocates a shared memory region with a name. |