Mercurial > dwindows
comparison mac/dw.m @ 732:db3a173e487e
Fixes for the color chooser... it now works a single time. However...
reopening it either crashes on setColor: or skipping that... later in the run loop.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 15 Mar 2011 03:12:19 +0000 |
parents | 6a589a1a42b0 |
children | 8d5e5b89725f |
comparison
equal
deleted
inserted
replaced
731:6a589a1a42b0 | 732:db3a173e487e |
---|---|
674 | 674 |
675 /* Subclass for a color chooser type */ | 675 /* Subclass for a color chooser type */ |
676 @interface DWColorChoose : NSColorPanel | 676 @interface DWColorChoose : NSColorPanel |
677 { | 677 { |
678 DWDialog *dialog; | 678 DWDialog *dialog; |
679 NSColor *pickedcolor; | |
679 } | 680 } |
680 -(void)changeColor:(id)sender; | 681 -(void)changeColor:(id)sender; |
681 -(void)setDialog:(DWDialog *)input; | 682 -(void)setDialog:(DWDialog *)input; |
683 -(DWDialog *)dialog; | |
682 @end | 684 @end |
683 | 685 |
684 @implementation DWColorChoose | 686 @implementation DWColorChoose |
685 - (void)changeColor:(id)sender | 687 -(void)changeColor:(id)sender { pickedcolor = [self color]; } |
686 { | 688 -(BOOL)windowShouldClose:(id)window { dw_dialog_dismiss(dialog, pickedcolor); return YES; } |
687 dw_dialog_dismiss(dialog, [self color]); | |
688 } | |
689 -(void)setDialog:(DWDialog *)input { dialog = input; } | 689 -(void)setDialog:(DWDialog *)input { dialog = input; } |
690 -(DWDialog *)dialog { return dialog; } | |
690 @end | 691 @end |
691 | 692 |
692 /* Subclass for a splitbar type */ | 693 /* Subclass for a splitbar type */ |
693 @interface DWSplitBar : NSSplitView | 694 @interface DWSplitBar : NSSplitView |
694 #ifdef BUILDING_FOR_SNOW_LEOPARD | 695 #ifdef BUILDING_FOR_SNOW_LEOPARD |
3662 * Returns: | 3663 * Returns: |
3663 * The selected color or the current color if cancelled. | 3664 * The selected color or the current color if cancelled. |
3664 */ | 3665 */ |
3665 unsigned long API dw_color_choose(unsigned long value) | 3666 unsigned long API dw_color_choose(unsigned long value) |
3666 { | 3667 { |
3667 /* Create the File Save Dialog class. */ | 3668 /* Create the Color Chooser Dialog class. */ |
3669 int created = [NSColorPanel sharedColorPanelExists]; | |
3668 DWColorChoose *colorDlg = (DWColorChoose *)[DWColorChoose sharedColorPanel]; | 3670 DWColorChoose *colorDlg = (DWColorChoose *)[DWColorChoose sharedColorPanel]; |
3669 NSColor *color = [NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green: DW_GREEN_VALUE(_foreground)/255.0 blue: DW_BLUE_VALUE(_foreground)/255.0 alpha: 1]; | 3671 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]; |
3670 DWDialog *dialog = dw_dialog_new(colorDlg); | 3672 DWDialog *dialog; |
3671 | 3673 |
3672 /* Set defaults for the dialog. */ | 3674 if(created) |
3675 { | |
3676 dialog = [colorDlg dialog]; | |
3677 /* TODO: Something is wrong reopening... crashes on setcolor: */ | |
3678 return value; | |
3679 } | |
3680 else | |
3681 { | |
3682 dialog = dw_dialog_new(colorDlg); | |
3683 /* Set defaults for the dialog. */ | |
3684 [colorDlg setDialog:dialog]; | |
3685 [colorDlg setContinuous:NO]; | |
3686 [colorDlg setTarget:colorDlg]; | |
3687 [colorDlg setAction:@selector(changeColor:)]; | |
3688 } | |
3689 | |
3690 dialog->done = FALSE; | |
3673 [colorDlg setColor:color]; | 3691 [colorDlg setColor:color]; |
3674 [colorDlg setDialog:dialog]; | |
3675 [colorDlg setContinuous:YES]; | |
3676 [colorDlg setTarget:colorDlg]; | |
3677 [colorDlg setAction:@selector(changeColor:)]; | |
3678 [colorDlg makeKeyAndOrderFront:nil]; | 3692 [colorDlg makeKeyAndOrderFront:nil]; |
3679 | 3693 |
3694 /* Wait for them to pick a color */ | |
3680 color = (NSColor *)dw_dialog_wait(dialog); | 3695 color = (NSColor *)dw_dialog_wait(dialog); |
3696 | |
3697 /* Figure out the value of what they returned */ | |
3698 double red, green, blue; | |
3699 [color getRed:&red green:&green blue:&blue alpha:NULL]; | |
3700 value = DW_RGB((int)(red * 255), (int)(green *255), (int)(blue *255)); | |
3681 [color release]; | 3701 [color release]; |
3682 return _foreground; | 3702 return value; |
3683 } | 3703 } |
3684 | 3704 |
3685 /* Draw a point on a window (preferably a render window). | 3705 /* Draw a point on a window (preferably a render window). |
3686 * Parameters: | 3706 * Parameters: |
3687 * handle: Handle to the window. | 3707 * handle: Handle to the window. |