Merge branch '0.7b' of git@github.com:280north/cappuccino into 0.7b

This commit is contained in:
Ross Boucher
2009-05-17 20:59:39 -07:00
10 changed files with 245 additions and 65 deletions
+2
View File
@@ -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"
+51 -2
View File
@@ -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
+1 -1
+1
View File
@@ -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"
+123 -57
View File
@@ -24,79 +24,123 @@
*/
@import <AppKit/CPButton.j>
@import <AppKit/CPCheckBox.j>
@import <AppKit/CPRadio.j>
@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,48 @@ _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"];
// ... and _objectValue is _state
_objectValue = [self state];
_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;
}
+2 -2
View File
@@ -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"];
}
+1 -1
View File
@@ -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;
}
+62
View File
@@ -0,0 +1,62 @@
@import <Foundation/CPObject.j>
@import <AppKit/CPView.j>
@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