Mercurial > dwindows
comparison mac/dw.m @ 1849:b5e1ccc76e58
Added code to set the foreground color on Mac buttons...
background color cannot be set, it is image based.
Also added defaultly disabled color test code to the testing application.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 01 Jan 2013 23:18:56 +0000 |
parents | 68f923e57542 |
children | 4790589f52a9 |
comparison
equal
deleted
inserted
replaced
1848:68f923e57542 | 1849:b5e1ccc76e58 |
---|---|
1004 -(void)buttonClicked:(id)sender; | 1004 -(void)buttonClicked:(id)sender; |
1005 -(void)setButtonType:(NSButtonType)input; | 1005 -(void)setButtonType:(NSButtonType)input; |
1006 -(NSButtonType)buttonType; | 1006 -(NSButtonType)buttonType; |
1007 -(void)setParent:(DWBox *)input; | 1007 -(void)setParent:(DWBox *)input; |
1008 -(DWBox *)parent; | 1008 -(DWBox *)parent; |
1009 -(NSColor *)textColor; | |
1010 -(void)setTextColor:(NSColor *)textColor; | |
1009 @end | 1011 @end |
1010 | 1012 |
1011 @implementation DWButton | 1013 @implementation DWButton |
1012 -(void *)userdata { return userdata; } | 1014 -(void *)userdata { return userdata; } |
1013 -(void)setUserdata:(void *)input { userdata = input; } | 1015 -(void)setUserdata:(void *)input { userdata = input; } |
1041 } | 1043 } |
1042 -(void)setButtonType:(NSButtonType)input { buttonType = input; [super setButtonType:input]; } | 1044 -(void)setButtonType:(NSButtonType)input { buttonType = input; [super setButtonType:input]; } |
1043 -(NSButtonType)buttonType { return buttonType; } | 1045 -(NSButtonType)buttonType { return buttonType; } |
1044 -(void)setParent:(DWBox *)input { parent = input; } | 1046 -(void)setParent:(DWBox *)input { parent = input; } |
1045 -(DWBox *)parent { return parent; } | 1047 -(DWBox *)parent { return parent; } |
1048 -(NSColor *)textColor | |
1049 { | |
1050 NSAttributedString *attrTitle = [self attributedTitle]; | |
1051 NSUInteger len = [attrTitle length]; | |
1052 NSRange range = NSMakeRange(0, MIN(len, 1)); | |
1053 NSDictionary *attrs = [attrTitle fontAttributesInRange:range]; | |
1054 NSColor *textColor = [NSColor controlTextColor]; | |
1055 if (attrs) { | |
1056 textColor = [attrs objectForKey:NSForegroundColorAttributeName]; | |
1057 } | |
1058 return textColor; | |
1059 } | |
1060 -(void)setTextColor:(NSColor *)textColor | |
1061 { | |
1062 NSMutableAttributedString *attrTitle = [[NSMutableAttributedString alloc] | |
1063 initWithAttributedString:[self attributedTitle]]; | |
1064 NSUInteger len = [attrTitle length]; | |
1065 NSRange range = NSMakeRange(0, len); | |
1066 [attrTitle addAttribute:NSForegroundColorAttributeName | |
1067 value:textColor | |
1068 range:range]; | |
1069 [attrTitle fixAttributesInRange:range]; | |
1070 [self setAttributedTitle:attrTitle]; | |
1071 [attrTitle release]; | |
1072 } | |
1046 -(void)keyDown:(NSEvent *)theEvent | 1073 -(void)keyDown:(NSEvent *)theEvent |
1047 { | 1074 { |
1048 unichar vk = [[theEvent charactersIgnoringModifiers] characterAtIndex:0]; | 1075 unichar vk = [[theEvent charactersIgnoringModifiers] characterAtIndex:0]; |
1049 if(vk == VK_RETURN || vk == VK_SPACE) | 1076 if(vk == VK_RETURN || vk == VK_SPACE) |
1050 { | 1077 { |
8465 /* Get the cell on classes using NSCell */ | 8492 /* Get the cell on classes using NSCell */ |
8466 if([object isKindOfClass:[NSTextField class]]) | 8493 if([object isKindOfClass:[NSTextField class]]) |
8467 { | 8494 { |
8468 id cell = [object cell]; | 8495 id cell = [object cell]; |
8469 | 8496 |
8497 [object setTextColor:(fg ? fg : [NSColor controlTextColor])]; | |
8470 [cell setTextColor:(fg ? fg : [NSColor controlTextColor])]; | 8498 [cell setTextColor:(fg ? fg : [NSColor controlTextColor])]; |
8499 } | |
8500 if([object isMemberOfClass:[DWButton class]]) | |
8501 { | |
8502 [object setTextColor:(fg ? fg : [NSColor controlTextColor])]; | |
8471 } | 8503 } |
8472 if([object isKindOfClass:[NSTextField class]] || [object isKindOfClass:[NSButton class]]) | 8504 if([object isKindOfClass:[NSTextField class]] || [object isKindOfClass:[NSButton class]]) |
8473 { | 8505 { |
8474 id cell = [object cell]; | 8506 id cell = [object cell]; |
8475 | 8507 |