From 28da8ccacf101cacc32547c260bdbdccee717a6b Mon Sep 17 00:00:00 2001 From: Francisco Tolmasky Date: Sun, 17 May 2009 18:46:28 -0700 Subject: [PATCH 1/4] Prelminary support for radio buttons and checkboxes in nib2cib. Reviewed by me. --- AppKit/AppKit.j | 2 + Tools/nib2cib/NSButton.j | 178 ++++++++++++++++++++++++------------ Tools/nib2cib/NSImageView.j | 2 +- 3 files changed, 124 insertions(+), 58 deletions(-) diff --git a/AppKit/AppKit.j b/AppKit/AppKit.j index 0c67725cb..9f9db4730 100644 --- a/AppKit/AppKit.j +++ b/AppKit/AppKit.j @@ -27,6 +27,7 @@ @import "CPBezierPath.j" @import "CPButton.j" @import "CPButtonBar.j" +@import "CPCheckBox.j" @import "CPCib.j" @import "CPCibLoading.j" @import "CPClipView.j" @@ -53,6 +54,7 @@ @import "CPPasteboard.j" @import "CPPopUpButton.j" @import "CPProgressIndicator.j" +@import "CPRadio.j" @import "CPResponder.j" @import "CPScrollView.j" @import "CPScroller.j" diff --git a/Tools/nib2cib/NSButton.j b/Tools/nib2cib/NSButton.j index 2105c6f06..46a614191 100644 --- a/Tools/nib2cib/NSButton.j +++ b/Tools/nib2cib/NSButton.j @@ -24,79 +24,123 @@ */ @import +@import +@import @import "NSCell.j" @import "NSControl.j" + var _CPButtonBezelStyleHeights = {}; _CPButtonBezelStyleHeights[CPRoundedBezelStyle] = 18; _CPButtonBezelStyleHeights[CPTexturedRoundedBezelStyle] = 20; _CPButtonBezelStyleHeights[CPHUDBezelStyle] = 20; -@implementation CPButton (NSCoding) +@implementation CPRadio (NSCoding) - (id)NS_initWithCoder:(CPCoder)aCoder { self = [super NS_initWithCoder:aCoder]; - + + if (self) + _radioGroup = [CPRadioGroup new]; + + return self; +} + +@end + +@implementation CPButton (NSCoding) + +- (id)NS_initWithCoder:(CPCoder)aCoder +{ + if (![self isKindOfClass:[CPRadio class]] && ![self isKindOfClass:[CPCheckBox class]]) + { + // We need to do a bit of magic to determine if this is a checkbox or radio button. + var cell = [aCoder decodeObjectForKey:@"NSCell"], + alternateImage = [cell alternateImage]; + + if ([alternateImage isKindOfClass:[NSButtonImageSource class]]) + { + if ([alternateImage imageName] === @"NSSwitch") + { + CPLog.warn("Detected check box, switching to CPCheckBox"); + + return [[CPCheckBox alloc] NS_initWithCoder:aCoder]; + } + else if ([alternateImage imageName] === @"NSRadioButton") + { + CPLog.warn("Detected radio, switching to CPRadio"); + + return [[CPRadio alloc] NS_initWithCoder:aCoder]; + } + } + } + + self = [super NS_initWithCoder:aCoder]; + if (self) { - _controlSize = CPRegularControlSize; - var cell = [aCoder decodeObjectForKey:@"NSCell"]; + _controlSize = CPRegularControlSize; + _title = [cell title]; - [self setBordered:[cell isBordered]]; + if (![self isKindOfClass:[CPCheckBox class]] && ![self isKindOfClass:[CPRadio class]]) + { + [self setBordered:[cell isBordered]]; - _bezelStyle = [cell bezelStyle]; - - // clean up: - - switch (_bezelStyle) - { - // implemented: - case CPRoundedBezelStyle: - case CPTexturedRoundedBezelStyle: - case CPHUDBezelStyle: - break; - // approximations: - case CPRoundRectBezelStyle: - _bezelStyle = CPRoundedBezelStyle; - break; - case CPSmallSquareBezelStyle: - case CPThickSquareBezelStyle: - case CPThickerSquareBezelStyle: - case CPRegularSquareBezelStyle: - case CPTexturedSquareBezelStyle: - case CPShadowlessSquareBezelStyle: - _bezelStyle = CPTexturedRoundedBezelStyle; - break; - case CPRecessedBezelStyle: - _bezelStyle = CPHUDBezelStyle; - break; - // unsupported - case CPRoundedDisclosureBezelStyle: - case CPHelpButtonBezelStyle: - case CPCircularBezelStyle: - case CPDisclosureBezelStyle: - CPLog.warn("Unsupported bezel style: " + _bezelStyle); - _bezelStyle = CPHUDBezelStyle; - break; - // error: - default: - CPLog.error("Unknown bezel style: " + _bezelStyle); - _bezelStyle = CPHUDBezelStyle; - } - - //if (_CPButtonBezelStyleHeights[_bezelStyle] != undefined) - { - //CPLog.warn("Adjusting CPButton height from " +_frame.size.height+ " / " + _bounds.size.height+" to " + _CPButtonBezelStyleHeights[_bezelStyle]); - _frame.size.height = 24.0;//_CPButtonBezelStyleHeights[_bezelStyle]; - _bounds.size.height = 24.0;//_CPButtonBezelStyleHeights[_bezelStyle]; + _bezelStyle = [cell bezelStyle]; + + // clean up: + switch (_bezelStyle) + { + // implemented: + case CPRoundedBezelStyle: + case CPTexturedRoundedBezelStyle: + case CPHUDBezelStyle: + break; + // approximations: + case CPRoundRectBezelStyle: + _bezelStyle = CPRoundedBezelStyle; + break; + case CPSmallSquareBezelStyle: + case CPThickSquareBezelStyle: + case CPThickerSquareBezelStyle: + case CPRegularSquareBezelStyle: + case CPTexturedSquareBezelStyle: + case CPShadowlessSquareBezelStyle: + _bezelStyle = CPTexturedRoundedBezelStyle; + break; + case CPRecessedBezelStyle: + _bezelStyle = CPHUDBezelStyle; + break; + // unsupported + case CPRoundedDisclosureBezelStyle: + case CPHelpButtonBezelStyle: + case CPCircularBezelStyle: + case CPDisclosureBezelStyle: + CPLog.warn("Unsupported bezel style: " + _bezelStyle); + _bezelStyle = CPHUDBezelStyle; + break; + // error: + default: + CPLog.error("Unknown bezel style: " + _bezelStyle); + _bezelStyle = CPHUDBezelStyle; + } + + //if (_CPButtonBezelStyleHeights[_bezelStyle] != undefined) + { + //CPLog.warn("Adjusting CPButton height from " +_frame.size.height+ " / " + _bounds.size.height+" to " + _CPButtonBezelStyleHeights[_bezelStyle]); + _frame.size.height = 24.0;//_CPButtonBezelStyleHeights[_bezelStyle]; + _bounds.size.height = 24.0;//_CPButtonBezelStyleHeights[_bezelStyle]; + } } + else + [self setBordered:YES]; } - + return self; } @@ -122,26 +166,46 @@ _CPButtonBezelStyleHeights[CPHUDBezelStyle] = 20; { BOOL _isBordered @accessors(readonly, getter=isBordered); int _bezelStyle @accessors(readonly, getter=bezelStyle); - + CPString _title @accessors(readonly, getter=title); + CPImage _alternateImage @accessors(readonly, getter=alternateImage); } - (id)initWithCoder:(CPCoder)aCoder { self = [super initWithCoder:aCoder]; - + if (self) - { + { var buttonFlags = [aCoder decodeIntForKey:@"NSButtonFlags"], buttonFlags2 = [aCoder decodeIntForKey:@"NSButtonFlags2"]; - + _isBordered = (buttonFlags & 0x00800000) ? YES : NO; _bezelStyle = (buttonFlags2 & 0x7) | ((buttonFlags2 & 0x20) >> 2); - + // NSContents for NSButton is actually the title _title = [aCoder decodeObjectForKey:@"NSContents"]; + + _alternateImage = [aCoder decodeObjectForKey:@"NSAlternateImage"]; } - + + return self; +} + +@end + +@implementation NSButtonImageSource : CPObject +{ + CPString _imageName @accessors(readonly, getter=imageName); +} + +- (id)initWithCoder:(CPCoder)aCoder +{ + self = [super init]; + + if (self) + _imageName = [aCoder decodeObjectForKey:@"NSImageName"]; + return self; } diff --git a/Tools/nib2cib/NSImageView.j b/Tools/nib2cib/NSImageView.j index 8b0bea0c5..871085599 100644 --- a/Tools/nib2cib/NSImageView.j +++ b/Tools/nib2cib/NSImageView.j @@ -91,7 +91,7 @@ NSImageScalingToCPImageScaling[NSImageScaleProportionallyUpOrDown] = CPScalePro @implementation NSImageCell : NSCell { BOOL _animates @accessors; - NSImageAlignmenr _imageAlignment @accessors; + NSImageAlignment _imageAlignment @accessors; NSImageScaling _imageScaling @accessors(readonly, getter=imageScaling); NSImageFrameStyle _frameStyle @accessors; } From b8cac31e85f3227eea52cd66fea9561f1176362f Mon Sep 17 00:00:00 2001 From: Tom Robinson Date: Sun, 17 May 2009 19:50:11 -0700 Subject: [PATCH 2/4] Updated to lastest External repos --- External/browserjs | 2 +- External/jack | 2 +- External/narwhal | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/External/browserjs b/External/browserjs index 5edca7a4f..f1baa3500 160000 --- a/External/browserjs +++ b/External/browserjs @@ -1 +1 @@ -Subproject commit 5edca7a4f764087d943e24117d0abbb18327116c +Subproject commit f1baa3500c9a4a5527682fc82dd50121c0455f9e diff --git a/External/jack b/External/jack index f9308de68..44783d128 160000 --- a/External/jack +++ b/External/jack @@ -1 +1 @@ -Subproject commit f9308de686a08c9aaf7d741efbd6c599108f15f4 +Subproject commit 44783d128cc3f6c624ad8c5e1e9e5b39d75b372c diff --git a/External/narwhal b/External/narwhal index 9fa32b4be..4af9daac0 160000 --- a/External/narwhal +++ b/External/narwhal @@ -1 +1 @@ -Subproject commit 9fa32b4be486651e95677411d4ead0a8c25c212f +Subproject commit 4af9daac0e0ae91d733cc63a765425be4a79e2d8 From 4ff6590e74f5d6492e917c3eb338070192045568 Mon Sep 17 00:00:00 2001 From: Francisco Tolmasky Date: Sun, 17 May 2009 20:03:36 -0700 Subject: [PATCH 3/4] Added support for NSMatrix of radio buttons. Reviewed by me. --- AppKit/CPRadio.j | 53 ++++++++++++++++++++++++++++++++++++++-- Tools/nib2cib/NSAppKit.j | 1 + Tools/nib2cib/NSButton.j | 2 ++ Tools/nib2cib/NSCell.j | 4 +-- 4 files changed, 56 insertions(+), 4 deletions(-) diff --git a/AppKit/CPRadio.j b/AppKit/CPRadio.j index a19df54f0..9212c3de3 100644 --- a/AppKit/CPRadio.j +++ b/AppKit/CPRadio.j @@ -52,8 +52,8 @@ if (self) { - _radioGroup = aRadioGroup || [CPRadioGroup new]; - + [self setRadioGroup:aRadioGroup || [CPRadioGroup new]]; + [self setHighlightsBy:CPContentsCellMask]; [self setShowsStateBy:CPContentsCellMask]; @@ -102,6 +102,29 @@ @end +var CPRadioRadioGroupKey = @"CPRadioRadioGroupKey"; + +@implementation CPRadio (CPCoding) + +- (id)initWithCoder:(CPCoder)aCoder +{ + self = [super initWithCoder:aCoder]; + + if (self) + _radioGroup = [aCoder decodeObjectForKey:CPRadioRadioGroupKey]; + + return self; +} + +- (void)encodeWithCoder:(CPCoder)aCoder +{ + [super encodeWithCoder:aCoder]; + + [aCoder encodeObject:_radioGroup forKey:CPRadioRadioGroupKey]; +} + +@end + @implementation CPRadioGroup : CPObject { CPSet _radios; @@ -157,3 +180,29 @@ } @end + +var CPRadioGroupRadiosKey = @"CPRadioGroupRadiosKey", + CPRadioGroupSelectedRadioKey = @"CPRadioGroupSelectedRadioKey"; + +@implementation CPRadioGroup (CPCoding) + +- (id)initWithCoder:(CPCoder)aCoder +{ + self = [super init]; + + if (self) + { + _radios = [aCoder decodeObjectForKey:CPRadioGroupRadiosKey]; + _selectedRadio = [aCoder decodeObjectForKey:CPRadioGroupSelectedRadioKey]; + } + + return self; +} + +- (void)encodeWithCoder:(CPCoder)aCoder +{ + [aCoder encodeObject:_radios forKey:CPRadioGroupRadiosKey]; + [aCoder encodeObject:_selectedRadio forKey:CPRadioGroupSelectedRadioKey]; +} + +@end diff --git a/Tools/nib2cib/NSAppKit.j b/Tools/nib2cib/NSAppKit.j index d3cd2da45..955c45b20 100644 --- a/Tools/nib2cib/NSAppKit.j +++ b/Tools/nib2cib/NSAppKit.j @@ -32,6 +32,7 @@ @import "NSFont.j" @import "NSIBObjectData.j" @import "NSImageView.j" +@import "NSMatrix.j" @import "NSMenu.j" @import "NSMenuItem.j" @import "NSNibConnector.j" diff --git a/Tools/nib2cib/NSButton.j b/Tools/nib2cib/NSButton.j index 46a614191..b3f9e8fd5 100644 --- a/Tools/nib2cib/NSButton.j +++ b/Tools/nib2cib/NSButton.j @@ -185,6 +185,8 @@ _CPButtonBezelStyleHeights[CPHUDBezelStyle] = 20; // NSContents for NSButton is actually the title _title = [aCoder decodeObjectForKey:@"NSContents"]; + // ... and _objectValue is _state + _objectValue = [self state]; _alternateImage = [aCoder decodeObjectForKey:@"NSAlternateImage"]; } diff --git a/Tools/nib2cib/NSCell.j b/Tools/nib2cib/NSCell.j index 4dcaa4e83..a25a3f25f 100644 --- a/Tools/nib2cib/NSCell.j +++ b/Tools/nib2cib/NSCell.j @@ -53,7 +53,7 @@ { var flags = [aCoder decodeIntForKey:@"NSCellFlags"], flags2 = [aCoder decodeIntForKey:@"NSCellFlags2"]; - + _state = (flags & 0x80000000) ? CPOnState : CPOffState; _isHighlighted = (flags & 0x40000000) ? YES : NO; _isEnabled = (flags & 0x20000000) ? NO : YES; @@ -66,7 +66,7 @@ _wraps = (flags & 0x00100000) ? NO : YES; _alignment = (flags2 & 0x1c000000) >> 26; _controlSize = (flags2 & 0xE0000) >> 17; - + _objectValue = [aCoder decodeObjectForKey:@"NSContents"]; _font = [aCoder decodeObjectForKey:@"NSSupport"]; } From 8fc213a134f9bdac74cb4039d341bbd3b2a7f4b6 Mon Sep 17 00:00:00 2001 From: Francisco Tolmasky Date: Sun, 17 May 2009 20:05:40 -0700 Subject: [PATCH 4/4] Forgot to check in NSMatrix.j Reviewed by me. --- Tools/nib2cib/NSMatrix.j | 62 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Tools/nib2cib/NSMatrix.j diff --git a/Tools/nib2cib/NSMatrix.j b/Tools/nib2cib/NSMatrix.j new file mode 100644 index 000000000..48b78a30d --- /dev/null +++ b/Tools/nib2cib/NSMatrix.j @@ -0,0 +1,62 @@ + +@import +@import + +@import "NSView.j" + + +@implementation NSMatrix : CPObject +{ +} + +- (id)initWithCoder:(CPCoder)aCoder +{ + var view = [[CPView alloc] NS_initWithCoder:aCoder]; + + [view setBackgroundColor:[aCoder decodeObjectForKey:@"NSBackgroundColor"]]; + + var numberOfRows = [aCoder decodeIntForKey:@"NSNumRows"], + numberOfColumns = [aCoder decodeIntForKey:@"NSNumCols"], + cellSize = [aCoder decodeSizeForKey:@"NSCellSize"], + intercellSpacing = [aCoder decodeSizeForKey:@"NSIntercellSpacing"], + cellBackgroundColor = [aCoder decodeObjectForKey:@"NSCellBackgroundColor"], + //cellClassName = [aCoder decodeObjectForKey:@"NSCellClass"];alert("6"); + flags = [aCoder decodeIntForKey:@"NSMatrixFlags"], + cells = [aCoder decodeObjectForKey:@"NSCells"], + selectedCell = [aCoder decodeObjectForKey:@"NSSelectedCell"]; + + if (/*(cellClassName === @"NSButtonCell") &&*/ (flags & 0x40000000)) + { + var radioGroup = [CPRadioGroup new]; + frame = CGRectMake(0.0, 0.0, cellSize.width, cellSize.height); + rowIndex = 0; + + for (; rowIndex < numberOfRows; ++rowIndex) + { + var columnIndex = 0; + + frame.origin.x = 0; + + for (; columnIndex < numberOfColumns; ++columnIndex) + { + var cell = cells[rowIndex * numberOfColumns + columnIndex], + cellView = [[CPRadio alloc] initWithFrame:frame radioGroup:radioGroup]; + + [cellView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable]; + [cellView setTitle:[cell title]]; + [cellView setBackgroundColor:cellBackgroundColor]; + [cellView setObjectValue:[cell objectValue]]; + + [view addSubview:cellView]; + + frame.origin.x = CGRectGetMaxX(frame) + intercellSpacing.width; + } + + frame.origin.y = CGRectGetMaxY(frame) + intercellSpacing.height; + } + } + + return view; +} + +@end