changeset 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 495793f9b503
files dwtest.c mac/dw.m
diffstat 2 files changed, 42 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/dwtest.c	Sat Dec 29 05:34:04 2012 +0000
+++ b/dwtest.c	Tue Jan 01 23:18:56 2013 +0000
@@ -964,6 +964,16 @@
     dw_window_set_color(lbbox, DW_CLR_DARKCYAN, DW_CLR_PALEGRAY);
     dw_window_set_color(buttonbox, DW_CLR_DARKCYAN, DW_CLR_PALEGRAY);
     dw_window_set_color(okbutton, DW_CLR_PALEGRAY, DW_CLR_DARKCYAN);
+#ifdef COLOR_DEBUG
+    dw_window_set_color(copypastefield, DW_CLR_WHITE, DW_CLR_RED);
+    dw_window_set_color(copybutton, DW_CLR_WHITE, DW_CLR_RED);
+    /* Set a color then clear it to make sure it clears correctly */
+    dw_window_set_color(entryfield, DW_CLR_WHITE, DW_CLR_RED);
+    dw_window_set_color(entryfield, DW_CLR_DEFAULT, DW_CLR_DEFAULT);
+    /* Set a color then clear it to make sure it clears correctly... again */
+    dw_window_set_color(pastebutton, DW_CLR_WHITE, DW_CLR_RED);
+    dw_window_set_color(pastebutton, DW_CLR_DEFAULT, DW_CLR_DEFAULT);
+#endif
 
     dw_signal_connect(browsefilebutton, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(browse_file_callback), DW_POINTER(notebookbox1));
     dw_signal_connect(browsefolderbutton, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(browse_folder_callback), DW_POINTER(notebookbox1));
--- 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];