changeset 811:50ed3e92215b

Changes for dw_window_set_color() so it works on pretty much any control we support. A usage note, dw_window_set_color() on containers should be issued after dw_container_setup() on the Mac... because the foreground color works on the column objects which don't exist until dw_container_setup() is called.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 25 Mar 2011 13:11:28 +0000
parents 746cdd753e7a
children f8bfb19090f9
files mac/dw.m
diffstat 1 files changed, 48 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/mac/dw.m	Thu Mar 24 21:05:25 2011 +0000
+++ b/mac/dw.m	Fri Mar 25 13:11:28 2011 +0000
@@ -6091,32 +6091,64 @@
     id object = handle;
     unsigned long _fore = _get_color(fore);
     unsigned long _back = _get_color(back);
-    NSColor *fg = [NSColor colorWithDeviceRed: DW_RED_VALUE(_fore)/255.0 green: DW_GREEN_VALUE(_fore)/255.0 blue: DW_BLUE_VALUE(_fore)/255.0 alpha: 1];
-    NSColor *bg = [NSColor colorWithDeviceRed: DW_RED_VALUE(_back)/255.0 green: DW_GREEN_VALUE(_back)/255.0 blue: DW_BLUE_VALUE(_back)/255.0 alpha: 1];
-
-    if([object isMemberOfClass:[NSTextFieldCell class]])
-    {
-        NSTextFieldCell *text = object;
-        [text setTextColor:fg];
+    NSColor *fg = NULL;
+    NSColor *bg = NULL;
+    
+    /* Get the NSColor for non-default colors */
+    if(fore != DW_CLR_DEFAULT)
+    {
+        fg = [NSColor colorWithDeviceRed: DW_RED_VALUE(_fore)/255.0 green: DW_GREEN_VALUE(_fore)/255.0 blue: DW_BLUE_VALUE(_fore)/255.0 alpha: 1];
+    }
+    if(back != DW_CLR_DEFAULT)
+    {
+        bg = [NSColor colorWithDeviceRed: DW_RED_VALUE(_back)/255.0 green: DW_GREEN_VALUE(_back)/255.0 blue: DW_BLUE_VALUE(_back)/255.0 alpha: 1];
+    }
+
+    /* Get the textfield from the spinbutton */
+    if([object isMemberOfClass:[DWSpinButton class]])
+    {
+        object = [object textfield];
+    }
+    /* Get the cell on classes using NSCell */
+    if([object isKindOfClass:[NSTextField class]])
+    {
+        id cell = [object cell];
+        
+        if(fg)
+        {
+            [cell setTextColor:fg];
+        }
+    }
+    if([object isKindOfClass:[NSTextField class]] || [object isKindOfClass:[NSButton class]])
+    {
+        id cell = [object cell];
+        
+        if(bg)
+        {
+            [cell setBackgroundColor:bg];
+        }
     }
     else if([object isMemberOfClass:[DWBox class]])
     {
         DWBox *box = object;
 
-        [box setColor:_back];
-    }
-    else if([object isMemberOfClass:[DWButton class]])
-    {
-        DWButton *button = object;
-
-        [[button cell] setBackgroundColor:bg];
+        if(bg)
+        {
+            [box setColor:_back];
+        }
     }
     else if([object isKindOfClass:[NSTableView class]])
     {
         DWContainer *cont = handle;
         
-        [cont setBackgroundColor:bg];
-        [cont setForegroundColor:fg];
+        if(bg)
+        {
+            [cont setBackgroundColor:bg];
+        }
+        if(fg)
+        {
+            [cont setForegroundColor:fg];
+        }
     }
     return 0;
 }