Mercurial > dwindows
comparison mac/dw.m @ 1644:2b55465887e1
Color chooser changes for Lion compatibility on Mac.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 06 Apr 2012 22:15:06 +0000 |
parents | 48a61abcd5bb |
children | b2c26ed9031c |
comparison
equal
deleted
inserted
replaced
1643:08da4840dfc3 | 1644:2b55465887e1 |
---|---|
1311 -(void)setDialog:(DWDialog *)input; | 1311 -(void)setDialog:(DWDialog *)input; |
1312 -(DWDialog *)dialog; | 1312 -(DWDialog *)dialog; |
1313 @end | 1313 @end |
1314 | 1314 |
1315 @implementation DWColorChoose | 1315 @implementation DWColorChoose |
1316 -(void)changeColor:(id)sender { pickedcolor = [self color]; } | 1316 -(void)changeColor:(id)sender |
1317 -(BOOL)windowShouldClose:(id)window { DWDialog *d = dialog; dialog = nil; dw_dialog_dismiss(d, pickedcolor); [window orderOut:nil]; return NO; } | 1317 { |
1318 if(!dialog) | |
1319 [self close]; | |
1320 else | |
1321 pickedcolor = [self color]; | |
1322 } | |
1323 -(BOOL)windowShouldClose:(id)window | |
1324 { | |
1325 if(dialog) | |
1326 { | |
1327 DWDialog *d = dialog; | |
1328 dialog = nil; | |
1329 dw_dialog_dismiss(d, pickedcolor); | |
1330 } | |
1331 [self close]; | |
1332 return NO; | |
1333 } | |
1318 -(void)setDialog:(DWDialog *)input { dialog = input; } | 1334 -(void)setDialog:(DWDialog *)input { dialog = input; } |
1319 -(DWDialog *)dialog { return dialog; } | 1335 -(DWDialog *)dialog { return dialog; } |
1320 @end | 1336 @end |
1321 | 1337 |
1322 /* Subclass for a font chooser type */ | 1338 /* Subclass for a font chooser type */ |
5238 * Returns: | 5254 * Returns: |
5239 * The selected color or the current color if cancelled. | 5255 * The selected color or the current color if cancelled. |
5240 */ | 5256 */ |
5241 unsigned long API dw_color_choose(unsigned long value) | 5257 unsigned long API dw_color_choose(unsigned long value) |
5242 { | 5258 { |
5243 NSColor *color = [[NSColor colorWithDeviceRed: DW_RED_VALUE(value)/255.0 green: DW_GREEN_VALUE(value)/255.0 blue: DW_BLUE_VALUE(value)/255.0 alpha: 1] retain]; | |
5244 /* Create the Color Chooser Dialog class. */ | 5259 /* Create the Color Chooser Dialog class. */ |
5245 static DWColorChoose *colorDlg = nil; | 5260 DWColorChoose *colorDlg; |
5246 DWDialog *dialog; | 5261 DWDialog *dialog; |
5247 DW_LOCAL_POOL_IN; | 5262 DW_LOCAL_POOL_IN; |
5248 | 5263 |
5249 if(colorDlg) | 5264 if(![DWColorChoose sharedColorPanelExists]) |
5250 { | |
5251 dialog = [colorDlg dialog]; | |
5252 /* If someone is already waiting just return */ | |
5253 if(dialog) | |
5254 { | |
5255 DW_LOCAL_POOL_OUT; | |
5256 return value; | |
5257 } | |
5258 } | |
5259 else | |
5260 { | 5265 { |
5261 colorDlg = (DWColorChoose *)[DWColorChoose sharedColorPanel]; | 5266 colorDlg = (DWColorChoose *)[DWColorChoose sharedColorPanel]; |
5262 /* Set defaults for the dialog. */ | 5267 /* Set defaults for the dialog. */ |
5263 [colorDlg setContinuous:NO]; | 5268 [colorDlg setContinuous:NO]; |
5264 [colorDlg setTarget:colorDlg]; | 5269 [colorDlg setTarget:colorDlg]; |
5265 [colorDlg setAction:@selector(changeColor:)]; | 5270 [colorDlg setAction:@selector(changeColor:)]; |
5266 } | 5271 } |
5267 | 5272 else |
5273 colorDlg = (DWColorChoose *)[DWColorChoose sharedColorPanel]; | |
5274 | |
5275 /* If someone is already waiting just return */ | |
5276 if([colorDlg dialog]) | |
5277 { | |
5278 DW_LOCAL_POOL_OUT; | |
5279 return value; | |
5280 } | |
5281 | |
5282 unsigned long tempcol = _get_color(value); | |
5283 NSColor *color = [[NSColor colorWithDeviceRed: DW_RED_VALUE(tempcol)/255.0 green: DW_GREEN_VALUE(tempcol)/255.0 blue: DW_BLUE_VALUE(tempcol)/255.0 alpha: 1] retain]; | |
5284 [colorDlg setColor:color]; | |
5285 | |
5268 dialog = dw_dialog_new(colorDlg); | 5286 dialog = dw_dialog_new(colorDlg); |
5269 [colorDlg setColor:color]; | |
5270 [colorDlg setDialog:dialog]; | 5287 [colorDlg setDialog:dialog]; |
5271 [colorDlg makeKeyAndOrderFront:nil]; | 5288 [colorDlg makeKeyAndOrderFront:nil]; |
5272 | 5289 |
5273 /* Wait for them to pick a color */ | 5290 /* Wait for them to pick a color */ |
5274 color = (NSColor *)dw_dialog_wait(dialog); | 5291 color = (NSColor *)dw_dialog_wait(dialog); |
5275 | 5292 |
5276 /* Figure out the value of what they returned */ | 5293 /* Figure out the value of what they returned */ |
5277 CGFloat red, green, blue; | 5294 CGFloat red, green, blue; |
5278 [color getRed:&red green:&green blue:&blue alpha:NULL]; | 5295 [color getRed:&red green:&green blue:&blue alpha:NULL]; |
5279 [color release]; | |
5280 value = DW_RGB((int)(red * 255), (int)(green *255), (int)(blue *255)); | 5296 value = DW_RGB((int)(red * 255), (int)(green *255), (int)(blue *255)); |
5281 DW_LOCAL_POOL_OUT; | 5297 DW_LOCAL_POOL_OUT; |
5282 return value; | 5298 return value; |
5283 } | 5299 } |
5284 | 5300 |