From da0af131420f72068ded0b89e5c05735de53e0f8 Mon Sep 17 00:00:00 2001 From: Randall Luecke Date: Thu, 12 Aug 2010 13:11:41 -0500 Subject: [PATCH 1/5] Added basic suppport for CPOutlineView in the nib2cib tool Conflicts: AppKit/CPOutlineView.j --- AppKit/CPOutlineView.j | 50 +++++++++++++++++++++++++++ Tools/nib2cib/NSAppKit.j | 1 + Tools/nib2cib/NSOutlineView.j | 65 +++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 Tools/nib2cib/NSOutlineView.j diff --git a/AppKit/CPOutlineView.j b/AppKit/CPOutlineView.j index 414249a0b..42752caff 100644 --- a/AppKit/CPOutlineView.j +++ b/AppKit/CPOutlineView.j @@ -1275,6 +1275,56 @@ var _loadItemInfoForItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anIt @end + +var CPOutlineViewIndentationPerLevelKey = @"CPOutlineViewIndentationPerLevelKey", + CPOutlineViewOutlineTableColumnKey = @"CPOutlineViewOutlineTableColumnKey", + CPOutlineViewDataSourceKey = @"CPOutlineViewDataSourceKey", + CPOutlineViewDelegateKey = @"CPOutlineViewDelegateKey"; + +@implementation CPOutlineView (CPCoding) + +- (id)initWithCoder:(CPCoder)aCoder +{ + self = [super initWithCoder:aCoder]; + + if (self) + { + // The root item has weight "0", thus represents the weight solely of its descendants. + _rootItemInfo = { isExpanded:YES, isExpandable:NO, level:-1, row:-1, children:[], weight:0 }; + + _itemsForRows = []; + _itemInfosForItems = { }; + _disclosureControlsForRows = []; + + [self setIndentationMarkerFollowsDataView:YES]; + [self setDisclosureControlPrototype:[[CPDisclosureButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 10.0, 10.0)]]; + + _outlineTableColumn = [aCoder decodeObjectForKey:CPOutlineViewOutlineTableColumnKey]; + _indentationPerLevel = [aCoder decodeFloatForKey:CPOutlineViewIndentationPerLevelKey]; + + _outlineViewDataSource = [aCoder decodeObjectForKey:CPOutlineViewDataSourceKey]; + _outlineViewDelegate = [aCoder decodeObjectForKey:CPOutlineViewDelegateKey]; + + [super setDataSource:[[_CPOutlineViewTableViewDataSource alloc] initWithOutlineView:self]]; + } + + return self; +} + +- (void)encodeWithCoder:(CPCoder)aCoder +{ + [super encodeWithCoder:aCoder]; + + [aCoder encodeObject:_outlineTableColumn forKey:CPOutlineViewOutlineTableColumnKey]; + [aCoder encodeFloat:_indentationPerLevel forKey:CPOutlineViewIndentationPerLevelKey]; + + [aCoder encodeObject:_outlineViewDataSource forKey:CPOutlineViewDataSourceKey]; + [aCoder encodeObject:_outlineViewDelegate forKey:CPOutlineViewDelegateKey]; +} + +@end + + var colorForDisclosureTriangle = function(isSelected, isHighlighted) { return isSelected ? (isHighlighted diff --git a/Tools/nib2cib/NSAppKit.j b/Tools/nib2cib/NSAppKit.j index 96a3a52b8..2348f1408 100644 --- a/Tools/nib2cib/NSAppKit.j +++ b/Tools/nib2cib/NSAppKit.j @@ -41,6 +41,7 @@ @import "NSMenu.j" @import "NSMenuItem.j" @import "NSNibConnector.j" +@import "NSOutlineView.j" @import "NSPopUpButton.j" @import "NSResponder.j" @import "NSScrollView.j" diff --git a/Tools/nib2cib/NSOutlineView.j b/Tools/nib2cib/NSOutlineView.j new file mode 100644 index 000000000..6cc600273 --- /dev/null +++ b/Tools/nib2cib/NSOutlineView.j @@ -0,0 +1,65 @@ +/* + * NSOutlineView.j + * nib2cib + * + * Created by Andreas Falk. + * Copyright 2009, Andreas Falk. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +@import + + +@implementation CPOutlineView (NSCoding) + +- (id)NS_initWithCoder:(CPCoder)aCoder +{ + self = [super NS_initWithCoder:aCoder]; + + if (self) + { + if([aCoder containsValueForKey:"NSOutlineViewOutlineTableColumnKey"]) + _outlineTableColumn = [aCoder decodeObjectForKey:@"NSOutlineViewOutlineTableColumnKey"]; + else + _outlineTableColumn = [[self tableColumns] objectAtIndex:0]; + + _indentationPerLevel = [aCoder decodeFloatForKey:@"NSOutlineViewIndentationPerLevelKey"]; + + _outlineViewDataSource = [aCoder decodeObjectForKey:@"NSDataSource"]; + _outlineViewDelegate = [aCoder decodeObjectForKey:@"NSDelegate"]; + } + + return self; +} + +@end + + +@implementation NSOutlineView : CPOutlineView +{ +} + +- (id)initWithCoder:(CPCoder)aCoder +{ + return [self NS_initWithCoder:aCoder]; +} + +- (Class)classForKeyedArchiver +{ + return [CPOutlineView class]; +} + +@end From 14fb7695827f21e53348ccd92c2f3c239c0a2967 Mon Sep 17 00:00:00 2001 From: Randall Luecke Date: Thu, 12 Aug 2010 13:29:17 -0500 Subject: [PATCH 2/5] Removed ambiguity in CPDictionary keys type. Closes #700 --- Foundation/CPDictionary.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Foundation/CPDictionary.j b/Foundation/CPDictionary.j index 4fd2d46d8..da628aba6 100755 --- a/Foundation/CPDictionary.j +++ b/Foundation/CPDictionary.j @@ -425,7 +425,7 @@ @param aKey the key for the object's entry @return the object for the entry */ -- (id)objectForKey:(CPString)aKey +- (id)objectForKey:(id)aKey { var object = _buckets[aKey]; From 22c481ff274ded47fbae6a0dd56f6be17ed54eba Mon Sep 17 00:00:00 2001 From: Randall Luecke Date: Thu, 12 Aug 2010 14:18:45 -0500 Subject: [PATCH 3/5] Implemented allKeysForObject: in CPDictionary with tests. --- Foundation/CPDictionary.j | 29 +++++++++++++++++++++++++++++ Tests/Foundation/CPDictionaryTest.j | 21 +++++++++++++-------- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/Foundation/CPDictionary.j b/Foundation/CPDictionary.j index da628aba6..acb4cca1e 100755 --- a/Foundation/CPDictionary.j +++ b/Foundation/CPDictionary.j @@ -337,6 +337,35 @@ return values; } +/*! + Returns a new array containing the keys corresponding to all occurrences of a given object in the receiver. + @param anObject The value to look for in the receiver. + @return A new array containing the keys corresponding to all occurrences of anObject in the receiver. If no object matching anObject is found, returns an empty array. + + Each object in the receiver is sent an isEqual: message to determine if itŐs equal to anObject. + If the check for isEqual fails a check is made to see if the two objects are the same object. This provides compatability for JSObjects. +*/ +- (CPArray)allKeysForObject:(id)anObject +{ + var count = _keys.length, + index = 0, + matchingKeys = [], + thisKey = nil, + thisValue = nil; + + for (; index < count; ++index) + { + thisKey = _keys[index], + thisValue = _buckets[thisKey]; + if (thisValue.isa && anObject && anObject.isa && [thisValue respondsToSelector:@selector(isEqual:)] && [thisValue isEqual:anObject]) + matchingKeys.push(thisKey); + else if (thisValue === anObject) + matchingKeys.push(thisKey); + } + + return matchingKeys; +} + /*! Returns an enumerator that enumerates over all the dictionary's keys. */ diff --git a/Tests/Foundation/CPDictionaryTest.j b/Tests/Foundation/CPDictionaryTest.j index d520f7359..023177beb 100644 --- a/Tests/Foundation/CPDictionaryTest.j +++ b/Tests/Foundation/CPDictionaryTest.j @@ -17,7 +17,7 @@ } } - string_dict = [[CPDictionary alloc] initWithObjects:[@"1", @"2"] forKeys:[@"key1", @"key2"]]; + string_dict = [[CPDictionary alloc] initWithObjects:[@"1", @"2", @"This is a String", @"This is a String"] forKeys:[@"key1", @"key2", @"key3", @"key4"]]; json_dict = [CPDictionary dictionaryWithJSObject:json recursively:YES]; } @@ -90,19 +90,19 @@ - (void)testCount { - [self assert:[string_dict count] equals:2]; + [self assert:[string_dict count] equals:4]; [self assert:[json_dict count] equals:3]; } - (void)testAllKeys { - [self assert:[string_dict allKeys] equals:[@"key2", @"key1"]]; + [self assert:[string_dict allKeys] equals:[@"key4", @"key3", @"key2", @"key1"]]; [self assert:[json_dict allKeys] equals:[@"key1", @"key2", @"key3"]]; } - (void)testAllValues { - [self assert:[string_dict allValues] equals:[@"1", @"2"]]; + [self assert:[string_dict allValues] equals:[@"1", @"2", @"This is a String", @"This is a String"]]; // Had to get object from key to get test passing [self assert:[json_dict allValues] equals:[[json_dict objectForKey:@"key3"], @"This is a string", ['1', '2', '3']]]; } @@ -113,6 +113,11 @@ [self assert:[json_dict objectForKey:@"key1"] equals:['1', '2', '3']]; } +- (void)testAllKeysForObject +{ + [self assert:[string_dict allKeysForObject:@"This is a String"] equals:[@"key4", @"key3"]]; +} + - (void)testKeyEnumerator { var dict = [[CPDictionary alloc] init]; @@ -156,7 +161,7 @@ { [string_dict removeObjectForKey:@"key1"]; [json_dict removeObjectForKey:@"key1"]; - [self assert:[string_dict count] equals:1]; + [self assert:[string_dict count] equals:3]; [self assert:[json_dict count] equals:2]; } @@ -164,7 +169,7 @@ { [string_dict removeObjectsForKeys:[@"key1"]]; [json_dict removeObjectsForKeys:[@"key1", @"key2"]]; - [self assert:[string_dict count] equals:1]; + [self assert:[string_dict count] equals:3]; [self assert:[json_dict count] equals:1]; } @@ -178,10 +183,10 @@ - (void)testAddEntriesFromDictionary { - var dict = [[CPDictionary alloc] initWithObjects:[@"1", @"2"] forKeys:[@"key4", @"key5"]]; + var dict = [[CPDictionary alloc] initWithObjects:[@"1", @"2"] forKeys:[@"key5", @"key6"]]; [string_dict addEntriesFromDictionary:dict] [json_dict addEntriesFromDictionary:dict] - [self assert:[string_dict count] equals:4]; + [self assert:[string_dict count] equals:6]; [self assert:[json_dict count] equals:5]; } From 23e9fd927cf1814e7e03039b6f11f9a27b7a0f00 Mon Sep 17 00:00:00 2001 From: cacaodev Date: Wed, 24 Feb 2010 01:19:52 +0100 Subject: [PATCH 4/5] CPBox: Made CPBezelType the default type instead of none. Slighly grayed stroke color for bezel type & fillColor for all types to better match cocoa Fix contentView autoresizingMask --- AppKit/CPBox.j | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/AppKit/CPBox.j b/AppKit/CPBox.j index 05500b550..bdff6d9c1 100644 --- a/AppKit/CPBox.j +++ b/AppKit/CPBox.j @@ -61,15 +61,16 @@ CPGrooveBorder = 3; self = [super initWithFrame:frameRect]; if (self) - { - _fillColor = [CPColor clearColor]; + { + _borderType = CPBezelBorder; + _fillColor = [CPColor colorWithWhite:0.75 alpha:0.1]; _borderColor = [CPColor blackColor]; _borderWidth = 1.0; _contentMargin = CGSizeMake(0.0, 0.0); _contentView = [[CPView alloc] initWithFrame:[self bounds]]; - + [_contentView setAutoresizingMask:CPViewWidthSizable|CPViewHeightSizable]; [self addSubview:_contentView]; } @@ -161,6 +162,7 @@ CPGrooveBorder = 3; return; [aView setFrame:CGRectInset([self bounds], _contentMargin.width + _borderWidth, _contentMargin.height + _borderWidth)]; + [aView setAutoresizingMask:CPViewWidthSizable|CPViewHeightSizable]; [self replaceSubview:_contentView with:aView]; _contentView = aView; @@ -213,16 +215,17 @@ CPGrooveBorder = 3; bounds.size.height - _borderWidth); CGContextSetFillColor(aContext, [self fillColor]); - CGContextSetStrokeColor(aContext, [self borderColor]); CGContextSetLineWidth(aContext, _borderWidth); switch(_borderType) { - case CPLineBorder: CGContextFillRoundedRectangleInRect(aContext, fillRect, _cornerRadius, YES, YES, YES, YES); + case CPLineBorder: CGContextSetStrokeColor(aContext, [self borderColor]); + CGContextFillRoundedRectangleInRect(aContext, fillRect, _cornerRadius, YES, YES, YES, YES); CGContextStrokeRoundedRectangleInRect(aContext, strokeRect, _cornerRadius, YES, YES, YES, YES); break; - case CPBezelBorder: CGContextFillRoundedRectangleInRect(aContext, fillRect, _cornerRadius, YES, YES, YES, YES); + case CPBezelBorder: CGContextSetStrokeColor(aContext, [CPColor colorWithWhite:0 alpha:0.42]); + CGContextFillRoundedRectangleInRect(aContext, fillRect, _cornerRadius, YES, YES, YES, YES); CGContextSetStrokeColor(aContext, [CPColor colorWithWhite:190.0/255.0 alpha:1.0]); CGContextBeginPath(aContext); CGContextMoveToPoint(aContext, strokeRect.origin.x, strokeRect.origin.y); From ee9da8e31ecdd919af6ed5a7dcfbd2958441c28e Mon Sep 17 00:00:00 2001 From: Randall Luecke Date: Thu, 12 Aug 2010 16:03:24 -0500 Subject: [PATCH 5/5] Only call drawRect: is the view is visible. --- AppKit/CPView.j | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AppKit/CPView.j b/AppKit/CPView.j index 8066cafe5..c153dda8a 100644 --- a/AppKit/CPView.j +++ b/AppKit/CPView.j @@ -1846,6 +1846,9 @@ setBoundsOrigin: - (void)displayRectIgnoringOpacity:(CGRect)aRect inContext:(CPGraphicsContext)aGraphicsContext { + if ([self isHidden]) + return; + #if PLATFORM(DOM) [self lockFocus];