# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1301058688 0 # Node ID 50ed3e92215bdd883db0466b95aa19b1a3cd6d64 # Parent 746cdd753e7a5e0c072edfd1dce9c8a81aab9bde 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. diff -r 746cdd753e7a -r 50ed3e92215b mac/dw.m --- 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; }