Mercurial > dwindows
diff 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 |
line wrap: on
line diff
--- a/mac/dw.m Sat Dec 29 05:34:04 2012 +0000 +++ b/mac/dw.m Tue Jan 01 23:18:56 2013 +0000 @@ -1006,6 +1006,8 @@ -(NSButtonType)buttonType; -(void)setParent:(DWBox *)input; -(DWBox *)parent; +-(NSColor *)textColor; +-(void)setTextColor:(NSColor *)textColor; @end @implementation DWButton @@ -1043,6 +1045,31 @@ -(NSButtonType)buttonType { return buttonType; } -(void)setParent:(DWBox *)input { parent = input; } -(DWBox *)parent { return parent; } +-(NSColor *)textColor +{ + NSAttributedString *attrTitle = [self attributedTitle]; + NSUInteger len = [attrTitle length]; + NSRange range = NSMakeRange(0, MIN(len, 1)); + NSDictionary *attrs = [attrTitle fontAttributesInRange:range]; + NSColor *textColor = [NSColor controlTextColor]; + if (attrs) { + textColor = [attrs objectForKey:NSForegroundColorAttributeName]; + } + return textColor; +} +-(void)setTextColor:(NSColor *)textColor +{ + NSMutableAttributedString *attrTitle = [[NSMutableAttributedString alloc] + initWithAttributedString:[self attributedTitle]]; + NSUInteger len = [attrTitle length]; + NSRange range = NSMakeRange(0, len); + [attrTitle addAttribute:NSForegroundColorAttributeName + value:textColor + range:range]; + [attrTitle fixAttributesInRange:range]; + [self setAttributedTitle:attrTitle]; + [attrTitle release]; +} -(void)keyDown:(NSEvent *)theEvent { unichar vk = [[theEvent charactersIgnoringModifiers] characterAtIndex:0]; @@ -8467,8 +8494,13 @@ { id cell = [object cell]; + [object setTextColor:(fg ? fg : [NSColor controlTextColor])]; [cell setTextColor:(fg ? fg : [NSColor controlTextColor])]; } + if([object isMemberOfClass:[DWButton class]]) + { + [object setTextColor:(fg ? fg : [NSColor controlTextColor])]; + } if([object isKindOfClass:[NSTextField class]] || [object isKindOfClass:[NSButton class]]) { id cell = [object cell];