comparison mac/dw.m @ 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
comparison
equal deleted inserted replaced
810:746cdd753e7a 811:50ed3e92215b
6089 int API dw_window_set_color(HWND handle, ULONG fore, ULONG back) 6089 int API dw_window_set_color(HWND handle, ULONG fore, ULONG back)
6090 { 6090 {
6091 id object = handle; 6091 id object = handle;
6092 unsigned long _fore = _get_color(fore); 6092 unsigned long _fore = _get_color(fore);
6093 unsigned long _back = _get_color(back); 6093 unsigned long _back = _get_color(back);
6094 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]; 6094 NSColor *fg = NULL;
6095 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]; 6095 NSColor *bg = NULL;
6096 6096
6097 if([object isMemberOfClass:[NSTextFieldCell class]]) 6097 /* Get the NSColor for non-default colors */
6098 { 6098 if(fore != DW_CLR_DEFAULT)
6099 NSTextFieldCell *text = object; 6099 {
6100 [text setTextColor:fg]; 6100 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];
6101 }
6102 if(back != DW_CLR_DEFAULT)
6103 {
6104 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];
6105 }
6106
6107 /* Get the textfield from the spinbutton */
6108 if([object isMemberOfClass:[DWSpinButton class]])
6109 {
6110 object = [object textfield];
6111 }
6112 /* Get the cell on classes using NSCell */
6113 if([object isKindOfClass:[NSTextField class]])
6114 {
6115 id cell = [object cell];
6116
6117 if(fg)
6118 {
6119 [cell setTextColor:fg];
6120 }
6121 }
6122 if([object isKindOfClass:[NSTextField class]] || [object isKindOfClass:[NSButton class]])
6123 {
6124 id cell = [object cell];
6125
6126 if(bg)
6127 {
6128 [cell setBackgroundColor:bg];
6129 }
6101 } 6130 }
6102 else if([object isMemberOfClass:[DWBox class]]) 6131 else if([object isMemberOfClass:[DWBox class]])
6103 { 6132 {
6104 DWBox *box = object; 6133 DWBox *box = object;
6105 6134
6106 [box setColor:_back]; 6135 if(bg)
6107 } 6136 {
6108 else if([object isMemberOfClass:[DWButton class]]) 6137 [box setColor:_back];
6109 { 6138 }
6110 DWButton *button = object;
6111
6112 [[button cell] setBackgroundColor:bg];
6113 } 6139 }
6114 else if([object isKindOfClass:[NSTableView class]]) 6140 else if([object isKindOfClass:[NSTableView class]])
6115 { 6141 {
6116 DWContainer *cont = handle; 6142 DWContainer *cont = handle;
6117 6143
6118 [cont setBackgroundColor:bg]; 6144 if(bg)
6119 [cont setForegroundColor:fg]; 6145 {
6146 [cont setBackgroundColor:bg];
6147 }
6148 if(fg)
6149 {
6150 [cont setForegroundColor:fg];
6151 }
6120 } 6152 }
6121 return 0; 6153 return 0;
6122 } 6154 }
6123 6155
6124 /* 6156 /*