comparison mac/dw.m @ 733:8d5e5b89725f

Fixed the crashing issue with dw_color_choose() it now functions properly. Figured out how to implement dw_window_hide() for top-level windows.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 15 Mar 2011 06:07:08 +0000
parents db3a173e487e
children 668a88a0b930
comparison
equal deleted inserted replaced
732:db3a173e487e 733:8d5e5b89725f
683 -(DWDialog *)dialog; 683 -(DWDialog *)dialog;
684 @end 684 @end
685 685
686 @implementation DWColorChoose 686 @implementation DWColorChoose
687 -(void)changeColor:(id)sender { pickedcolor = [self color]; } 687 -(void)changeColor:(id)sender { pickedcolor = [self color]; }
688 -(BOOL)windowShouldClose:(id)window { dw_dialog_dismiss(dialog, pickedcolor); return YES; } 688 -(BOOL)windowShouldClose:(id)window { DWDialog *d = dialog; dialog = nil; dw_dialog_dismiss(d, pickedcolor); [window orderOut:nil]; return NO; }
689 -(void)setDialog:(DWDialog *)input { dialog = input; } 689 -(void)setDialog:(DWDialog *)input { dialog = input; }
690 -(DWDialog *)dialog { return dialog; } 690 -(DWDialog *)dialog { return dialog; }
691 @end 691 @end
692 692
693 /* Subclass for a splitbar type */ 693 /* Subclass for a splitbar type */
3663 * Returns: 3663 * Returns:
3664 * The selected color or the current color if cancelled. 3664 * The selected color or the current color if cancelled.
3665 */ 3665 */
3666 unsigned long API dw_color_choose(unsigned long value) 3666 unsigned long API dw_color_choose(unsigned long value)
3667 { 3667 {
3668 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];
3668 /* Create the Color Chooser Dialog class. */ 3669 /* Create the Color Chooser Dialog class. */
3669 int created = [NSColorPanel sharedColorPanelExists]; 3670 static DWColorChoose *colorDlg = nil;
3670 DWColorChoose *colorDlg = (DWColorChoose *)[DWColorChoose sharedColorPanel];
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];
3672 DWDialog *dialog; 3671 DWDialog *dialog;
3673 3672
3674 if(created) 3673 if(colorDlg)
3675 { 3674 {
3676 dialog = [colorDlg dialog]; 3675 dialog = [colorDlg dialog];
3677 /* TODO: Something is wrong reopening... crashes on setcolor: */ 3676 /* If someone is already waiting just return */
3678 return value; 3677 if(dialog)
3678 {
3679 return value;
3680 }
3679 } 3681 }
3680 else 3682 else
3681 { 3683 {
3682 dialog = dw_dialog_new(colorDlg); 3684 colorDlg = (DWColorChoose *)[DWColorChoose sharedColorPanel];
3683 /* Set defaults for the dialog. */ 3685 /* Set defaults for the dialog. */
3684 [colorDlg setDialog:dialog];
3685 [colorDlg setContinuous:NO]; 3686 [colorDlg setContinuous:NO];
3686 [colorDlg setTarget:colorDlg]; 3687 [colorDlg setTarget:colorDlg];
3687 [colorDlg setAction:@selector(changeColor:)]; 3688 [colorDlg setAction:@selector(changeColor:)];
3688 } 3689 }
3689 3690
3690 dialog->done = FALSE; 3691 dialog = dw_dialog_new(colorDlg);
3691 [colorDlg setColor:color]; 3692 [colorDlg setColor:color];
3693 [colorDlg setDialog:dialog];
3692 [colorDlg makeKeyAndOrderFront:nil]; 3694 [colorDlg makeKeyAndOrderFront:nil];
3693 3695
3694 /* Wait for them to pick a color */ 3696 /* Wait for them to pick a color */
3695 color = (NSColor *)dw_dialog_wait(dialog); 3697 color = (NSColor *)dw_dialog_wait(dialog);
3696 3698
3697 /* Figure out the value of what they returned */ 3699 /* Figure out the value of what they returned */
3698 double red, green, blue; 3700 double red, green, blue;
3699 [color getRed:&red green:&green blue:&blue alpha:NULL]; 3701 [color getRed:&red green:&green blue:&blue alpha:NULL];
3700 value = DW_RGB((int)(red * 255), (int)(green *255), (int)(blue *255)); 3702 value = DW_RGB((int)(red * 255), (int)(green *255), (int)(blue *255));
3701 [color release];
3702 return value; 3703 return value;
3703 } 3704 }
3704 3705
3705 /* Draw a point on a window (preferably a render window). 3706 /* Draw a point on a window (preferably a render window).
3706 * Parameters: 3707 * Parameters:
5720 NSWindow *window = handle; 5721 NSWindow *window = handle;
5721 if([window isMiniaturized]) 5722 if([window isMiniaturized])
5722 { 5723 {
5723 [window deminiaturize:nil]; 5724 [window deminiaturize:nil];
5724 } 5725 }
5726 [window orderFront:nil];
5725 [[window contentView] windowResized:nil]; 5727 [[window contentView] windowResized:nil];
5726 [[window contentView] windowDidBecomeMain:nil]; 5728 [[window contentView] windowDidBecomeMain:nil];
5727 } 5729 }
5728 return 0; 5730 return 0;
5729 } 5731 }
5733 * Parameters: 5735 * Parameters:
5734 * handle: The window handle to make visible. 5736 * handle: The window handle to make visible.
5735 */ 5737 */
5736 int API dw_window_hide(HWND handle) 5738 int API dw_window_hide(HWND handle)
5737 { 5739 {
5738 /* TODO: Figure out proper dw_window_hide behavior... 5740 NSObject *object = handle;
5739 * individual windows don't appear to be hidable, 5741
5740 * but all application windows can be hidden/deactivated 5742 if([ object isKindOfClass:[ NSWindow class ] ])
5741 * via the NS/DWApplication class. 5743 {
5742 */ 5744 NSWindow *window = handle;
5745
5746 [window orderOut:nil];
5747 }
5743 return 0; 5748 return 0;
5744 } 5749 }
5745 5750
5746 /* 5751 /*
5747 * Sets the colors used by a specified window (widget) handle. 5752 * Sets the colors used by a specified window (widget) handle.