From 678563a9703d3ca02ee705fe6f1760963f7f846a Mon Sep 17 00:00:00 2001 From: cacaodev Date: Mon, 18 Oct 2010 18:07:11 +0200 Subject: [PATCH 01/11] Accidental globals in CPNotificationCenter and Runtime.js --- Foundation/CPNotificationCenter.j | 2 +- Objective-J/Runtime.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Foundation/CPNotificationCenter.j b/Foundation/CPNotificationCenter.j index 67babfcad..b6c9b5e96 100644 --- a/Foundation/CPNotificationCenter.j +++ b/Foundation/CPNotificationCenter.j @@ -248,7 +248,7 @@ var _CPNotificationCenterPostNotification = function(/* CPNotificationCenter */ else { var key = [anObject UID], - observers = [_objectObservers objectForKey:key]; + observers = [_objectObservers objectForKey:key], count = observers ? observers.length : 0; while (count--) diff --git a/Objective-J/Runtime.js b/Objective-J/Runtime.js index c003bd9ab..77de0a2d1 100644 --- a/Objective-J/Runtime.js +++ b/Objective-J/Runtime.js @@ -440,7 +440,7 @@ class_createInstance = function(/*Class*/ aClass) while (theClass) { - var ivars = theClass.ivars; + var ivars = theClass.ivars, count = ivars.length; while (count--) From 834480ff681f672292ac1ddeb147ac4ec8ea1655 Mon Sep 17 00:00:00 2001 From: Joachim Garth Date: Mon, 18 Oct 2010 03:13:27 +0200 Subject: [PATCH 02/11] Fixed a bug in reverseTransformValue: that caused transformedValue: to be called instead of reverseTransformedValue: --- AppKit/CPKeyValueBinding.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AppKit/CPKeyValueBinding.j b/AppKit/CPKeyValueBinding.j index eda0dc8e3..64ef1f583 100644 --- a/AppKit/CPKeyValueBinding.j +++ b/AppKit/CPKeyValueBinding.j @@ -247,7 +247,7 @@ var CPBindingOperationAnd = 0, valueTransformer = [options objectForKey:CPValueTransformerBindingOption]; if (valueTransformer && [[valueTransformer class] allowsReverseTransformation]) - aValue = [valueTransformer transformedValue:aValue]; + aValue = [valueTransformer reverseTransformedValue:aValue]; return aValue; } From 991e213d028cd3cf843f70a9083e78463a2da20f Mon Sep 17 00:00:00 2001 From: Klaas Pieter Annema Date: Tue, 19 Oct 2010 14:21:00 +0200 Subject: [PATCH 03/11] give CPSearchField it's own theme class Before this change it was not possible to theme CPSearchField separately from a CPTextField. Aristo still just uses the rounded theme style. --- AppKit/CPSearchField.j | 5 +++++ AppKit/Themes/Aristo/ThemeDescriptors.j | 14 +++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/AppKit/CPSearchField.j b/AppKit/CPSearchField.j index 4df6d4722..5e91386c5 100644 --- a/AppKit/CPSearchField.j +++ b/AppKit/CPSearchField.j @@ -68,6 +68,11 @@ var RECENT_SEARCH_PREFIX = @" "; CPTimer _partialStringTimer; } ++ (CPString)themeClass +{ + return @"searchfield" +} + + (void)initialize { if (self != [CPSearchField class]) diff --git a/AppKit/Themes/Aristo/ThemeDescriptors.j b/AppKit/Themes/Aristo/ThemeDescriptors.j index c8b1826f9..23f4b7e1a 100755 --- a/AppKit/Themes/Aristo/ThemeDescriptors.j +++ b/AppKit/Themes/Aristo/ThemeDescriptors.j @@ -777,9 +777,10 @@ var themedButtonValues = nil, ], PatternIsHorizontal), - placeholderColor = [CPColor colorWithCalibratedRed:189.0 / 255.0 green:199.0 / 255.0 blue:211.0 / 255.0 alpha:1.0], + placeholderColor = [CPColor colorWithCalibratedRed:189.0 / 255.0 green:199.0 / 255.0 blue:211.0 / 255.0 alpha:1.0]; - themeValues = + // Global for reuse by CPSearchField + themedRoundedTextFieldValues = [ [@"bezel-color", bezelColor, CPTextFieldStateRounded | CPThemeStateBezeled], [@"bezel-color", bezelFocusedColor, CPTextFieldStateRounded | CPThemeStateBezeled | CPThemeStateEditing], @@ -795,7 +796,7 @@ var themedButtonValues = nil, [@"max-size", CGSizeMake(-1.0, 30.0), CPTextFieldStateRounded | CPThemeStateBezeled] ]; - [self registerThemeValues:themeValues forView:textfield]; + [self registerThemeValues:themedRoundedTextFieldValues forView:textfield]; [textfield setBezeled:YES]; [textfield setBezelStyle:CPTextFieldRoundedBezel]; @@ -807,6 +808,13 @@ var themedButtonValues = nil, return textfield; } ++ (CPSearchField)themedSearchField +{ + var searchField = [[CPSearchField alloc] initWithFrame:CGRectMake(0.0, 0.0, 60.0, 30.0)]; + [self registerThemeValues:nil forView:searchField inherit:themedRoundedTextFieldValues]; + return searchField; +} + + (CPTokenField)themedTokenField { var tokenfield = [[CPTokenField alloc] initWithFrame:CGRectMake(0.0, 0.0, 60.0, 30.0)], From 2eb27a649296ffbbd0db6f669c20ed5a6e6b162b Mon Sep 17 00:00:00 2001 From: Klaas Pieter Annema Date: Tue, 19 Oct 2010 15:07:01 +0200 Subject: [PATCH 04/11] Don't adjust the origin and size of a text field during nib2cib This interferes with Aparajita's auto-sizing of controls in initWithCoder:. Also it's better to calculate the size in initWithCoder: because the theme information is available. --- Tools/nib2cib/NSTextField.j | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Tools/nib2cib/NSTextField.j b/Tools/nib2cib/NSTextField.j index 746879170..9e5fbade0 100644 --- a/Tools/nib2cib/NSTextField.j +++ b/Tools/nib2cib/NSTextField.j @@ -67,14 +67,6 @@ [self setFrameOrigin:CGPointMake(frame.origin.x, frame.origin.y)]; [self setFrameSize:CGSizeMake(frame.size.width, frame.size.height)]; - // Only adjust the origin and size if this is a bezeled textfield - // this makes sure that labels positioned in IB are properly positioned after nibcib - if ([self isBezeled]) - { - [self setFrameOrigin:CGPointMake(frame.origin.x - 4.0, frame.origin.y - 4.0)]; - [self setFrameSize:CGSizeMake(frame.size.width + 8.0, frame.size.height + 8.0)]; - } - CPLog.debug([self stringValue] + " => isBordered=" + [self isBordered] + ", isBezeled=" + [self isBezeled] + ", bezelStyle=" + [self bezelStyle] + "("+[cell stringValue]+", " + [cell placeholderString] + ")"); } From a3766a0f96942fb4b73824a6908c0fc7c84e6381 Mon Sep 17 00:00:00 2001 From: Klaas Pieter Annema Date: Tue, 19 Oct 2010 15:12:53 +0200 Subject: [PATCH 05/11] whitespace cleanup in NSTextField and NSSearchField --- Tools/nib2cib/NSSearchField.j | 6 +++--- Tools/nib2cib/NSTextField.j | 26 +++++++++++++------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Tools/nib2cib/NSSearchField.j b/Tools/nib2cib/NSSearchField.j index 086d560d7..46e149918 100644 --- a/Tools/nib2cib/NSSearchField.j +++ b/Tools/nib2cib/NSSearchField.j @@ -33,7 +33,7 @@ if (self) { var cell = [aCoder decodeObjectForKey:@"NSCell"]; - + [self setRecentsAutosaveName:[cell recentsAutosaveName]]; [self setMaximumRecents:[cell maximumRecents]]; [self setSendsWholeSearchString:[cell sendsWholeSearchString]]; @@ -78,11 +78,11 @@ _recentsAutosaveName = [aCoder decodeObjectForKey:@"NSRecentsAutosaveName"]; _maximumRecents = [aCoder decodeIntForKey:@"NSMaximumRecents"]; _sendsWholeSearchString = [aCoder decodeBoolForKey:@"NSSendsWholeSearchString"] ? YES : NO; - + // These bytes don't seem to be used for anything else but the send immediately flag _sendsSearchStringImmediately = [aCoder decodeBytesForKey:@"NSSearchFieldFlags"] ? YES: NO; } - + return self; } diff --git a/Tools/nib2cib/NSTextField.j b/Tools/nib2cib/NSTextField.j index 9e5fbade0..98933bd36 100644 --- a/Tools/nib2cib/NSTextField.j +++ b/Tools/nib2cib/NSTextField.j @@ -31,37 +31,37 @@ - (id)NS_initWithCoder:(CPCoder)aCoder { self = [super NS_initWithCoder:aCoder]; - + if (self) { var cell = [aCoder decodeObjectForKey:@"NSCell"]; - + if ([cell isEditable] && [[cell font] isEqual:[CPFont boldSystemFontOfSize:12.0]]) [self setFont:[CPFont systemFontOfSize:12.0]]; - [self sendActionOn:CPKeyUpMask|CPKeyDownMask]; - + [self sendActionOn:CPKeyUpMask | CPKeyDownMask]; + [self setEditable:[cell isEditable]]; [self setSelectable:[cell isSelectable]]; - + [self setBordered:[cell isBordered]]; [self setBezeled:[cell isBezeled]]; [self setBezelStyle:[cell bezelStyle]]; [self setDrawsBackground:[cell drawsBackground]]; - + [self setLineBreakMode:[cell lineBreakMode]]; [self setAlignment:[cell alignment]]; [self setTextFieldBackgroundColor:[cell backgroundColor]]; - + [self setPlaceholderString:[cell placeholderString]]; - + var textColor = [cell textColor], defaultColor = [self currentValueForThemeAttribute:@"text-color"]; - + // Don't change the text color if it is not the default, that messes up the theme lookups later if (![textColor isEqual:defaultColor]) [self setTextColor:[cell textColor]]; - + var frame = [self frame]; [self setFrameOrigin:CGPointMake(frame.origin.x, frame.origin.y)]; @@ -69,7 +69,7 @@ CPLog.debug([self stringValue] + " => isBordered=" + [self isBordered] + ", isBezeled=" + [self isBezeled] + ", bezelStyle=" + [self bezelStyle] + "("+[cell stringValue]+", " + [cell placeholderString] + ")"); } - + return self; } @@ -103,7 +103,7 @@ - (id)initWithCoder:(CPCoder)aCoder { self = [super initWithCoder:aCoder]; - + if (self) { _bezelStyle = [aCoder decodeObjectForKey:@"NSTextBezelStyle"] || CPTextFieldSquareBezel; @@ -112,7 +112,7 @@ _textColor = [aCoder decodeObjectForKey:@"NSTextColor"]; _placeholderString = [aCoder decodeObjectForKey:@"NSPlaceholderString"]; } - + return self; } From ad0867ba7d3cc6c9dba2a546edc7e659c8f60ac8 Mon Sep 17 00:00:00 2001 From: Blair Duncan Date: Tue, 19 Oct 2010 16:06:44 -0400 Subject: [PATCH 06/11] Fix for issue 948 Custom Cursors not working --- AppKit/CPCursor.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AppKit/CPCursor.j b/AppKit/CPCursor.j index f693db5aa..56f4987f1 100755 --- a/AppKit/CPCursor.j +++ b/AppKit/CPCursor.j @@ -228,7 +228,7 @@ var currentCursor = nil, currentCursor = self; #if PLATFORM(DOM) - [[self class] _setCursorCSS:_cssString]; + [[self class] _setCursorCSS:_cssString + ", auto"]; #endif } From 696990f035a4f1a620fa4698d103cc29a89ad33e Mon Sep 17 00:00:00 2001 From: Blair Duncan Date: Tue, 19 Oct 2010 16:50:55 -0400 Subject: [PATCH 07/11] Fix for previous fix and modified the test file. --- AppKit/CPCursor.j | 5 +++-- Tests/Manual/CPCursor/AppController.j | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/AppKit/CPCursor.j b/AppKit/CPCursor.j index 56f4987f1..34a076c35 100755 --- a/AppKit/CPCursor.j +++ b/AppKit/CPCursor.j @@ -212,9 +212,10 @@ var currentCursor = nil, - (id)initWithImage:(CPImage)image hotSpot:(CPPoint)hotSpot { - return [self initWithCSSString:"url(" + [image filename] + ")"]; + return [self initWithCSSString:"url(" + [image filename] + "), auto"]; } + - (void)mouseEntered:(CPEvent)event { } @@ -228,7 +229,7 @@ var currentCursor = nil, currentCursor = self; #if PLATFORM(DOM) - [[self class] _setCursorCSS:_cssString + ", auto"]; + [[self class] _setCursorCSS:_cssString]; #endif } diff --git a/Tests/Manual/CPCursor/AppController.j b/Tests/Manual/CPCursor/AppController.j index 516d6e993..ff79fad15 100644 --- a/Tests/Manual/CPCursor/AppController.j +++ b/Tests/Manual/CPCursor/AppController.j @@ -37,6 +37,12 @@ var selectors = ["pointingHandCursor", "resizeDownCursor", "resizeLeftCursor", " [button setTitle:@"set Cursor"]; [contentView addSubview:button]; + var button = [[CPButton alloc] initWithFrame:CGRectMake(270,150,150,24)]; + [button setAction:@selector(setUrlCursor:)]; + [button setTarget:self]; + [button setTitle:@"set Cursor from url"]; + [contentView addSubview:button]; + [theWindow orderFront:self]; // Uncomment the following line to turn on the standard menu bar. //[CPMenu setMenuBarVisible:YES]; @@ -49,4 +55,11 @@ var selectors = ["pointingHandCursor", "resizeDownCursor", "resizeLeftCursor", " [cursor set]; } +-(void)setUrlCursor:(id)sender +{ // note gifs don't animate when they are used as a cursor. + var aImage = [[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:@"spinner.gif"]]; + var cursor = [[CPCursor alloc] initWithImage:aImage hotSpot:CGPointMakeZero()]; + [cursor set]; +} + @end From c9a4821d15bfac4560e6be43e936739b11b43c8e Mon Sep 17 00:00:00 2001 From: Blair Duncan Date: Wed, 20 Oct 2010 01:43:15 -0400 Subject: [PATCH 08/11] Fix for issue 951 - CPResponder flagsChanged does not fire when the key is up --- AppKit/Platform/DOM/CPPlatformWindow+DOM.j | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/AppKit/Platform/DOM/CPPlatformWindow+DOM.j b/AppKit/Platform/DOM/CPPlatformWindow+DOM.j index 8924510f8..62b1b376d 100644 --- a/AppKit/Platform/DOM/CPPlatformWindow+DOM.j +++ b/AppKit/Platform/DOM/CPPlatformWindow+DOM.j @@ -822,7 +822,14 @@ var supportsNativeDragAndDrop = [CPPlatform supportsDragAndDrop]; _capsLockActive = NO; if ([ModifierKeyCodes containsObject:keyCode]) + { + // A modifier key will never fire keypress. We don't need to do any other processing so we just fire it here and break. + event = [CPEvent keyEventWithType:CPFlagsChanged location:location modifierFlags:modifierFlags + timestamp:timestamp windowNumber:windowNumber context:nil + characters:nil charactersIgnoringModifiers:nil isARepeat:NO keyCode:_keyCode]; + break; + } var characters = KeyCodesToUnicodeMap[charCode] || String.fromCharCode(charCode), charactersIgnoringModifiers = characters.toLowerCase(); From afcce49455a243d4f8f2c37a4e5d7a5dfe2a964e Mon Sep 17 00:00:00 2001 From: Klaas Pieter Annema Date: Thu, 15 Jul 2010 12:55:22 +0200 Subject: [PATCH 09/11] improve CPString sizeOfString performance by caching the calculated result --- AppKit/CPStringDrawing.j | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/AppKit/CPStringDrawing.j b/AppKit/CPStringDrawing.j index 859c23926..fbd174592 100644 --- a/AppKit/CPStringDrawing.j +++ b/AppKit/CPStringDrawing.j @@ -24,6 +24,7 @@ @import "CPPlatformString.j" +var CPStringSizeWithFontInWidthCache = {}; @implementation CPString (CPStringDrawing) @@ -50,7 +51,17 @@ - (CGSize)sizeWithFont:(CPFont)aFont inWidth:(float)aWidth { - return [CPPlatformString sizeOfString:self withFont:aFont forWidth:aWidth]; + var cacheKey = self + [aFont cssString] + aWidth; + size = CPStringSizeWithFontInWidthCache[cacheKey]; + + if (size === undefined) + { + size = [CPPlatformString sizeOfString:self withFont:aFont forWidth:aWidth]; + CPStringSizeWithFontInWidthCache[cacheKey] = size; + } + + return size; } + @end From 367efe590e95f398556ff87dbf9c09a81335f79a Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Sat, 17 Jul 2010 12:17:35 -0400 Subject: [PATCH 10/11] Fixed with the new string size optimisation: the cache value was returned by reference and something in the CPButton path for image and text buttons changed it causing text to become misaligned. A defensive copy avoids this problem. --- AppKit/CPStringDrawing.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AppKit/CPStringDrawing.j b/AppKit/CPStringDrawing.j index fbd174592..68eea2803 100644 --- a/AppKit/CPStringDrawing.j +++ b/AppKit/CPStringDrawing.j @@ -60,7 +60,7 @@ var CPStringSizeWithFontInWidthCache = {}; CPStringSizeWithFontInWidthCache[cacheKey] = size; } - return size; + return CGSizeMakeCopy(size); } From 71d02abc28a689594396caca6c7ce5006666782d Mon Sep 17 00:00:00 2001 From: Klaas Pieter Annema Date: Thu, 21 Oct 2010 17:27:32 +0200 Subject: [PATCH 11/11] add global to disable string size caching --- AppKit/CPStringDrawing.j | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/AppKit/CPStringDrawing.j b/AppKit/CPStringDrawing.j index 68eea2803..0f930caf1 100644 --- a/AppKit/CPStringDrawing.j +++ b/AppKit/CPStringDrawing.j @@ -26,6 +26,8 @@ var CPStringSizeWithFontInWidthCache = {}; +CPStringSizeCachingEnabled = YES; + @implementation CPString (CPStringDrawing) /*! @@ -51,7 +53,10 @@ var CPStringSizeWithFontInWidthCache = {}; - (CGSize)sizeWithFont:(CPFont)aFont inWidth:(float)aWidth { - var cacheKey = self + [aFont cssString] + aWidth; + if (!CPStringSizeCachingEnabled) + return [CPPlatformString sizeOfString:self withFont:aFont forWidth:aWidth]; + + var cacheKey = self + [aFont cssString] + aWidth, size = CPStringSizeWithFontInWidthCache[cacheKey]; if (size === undefined) @@ -63,5 +68,4 @@ var CPStringSizeWithFontInWidthCache = {}; return CGSizeMakeCopy(size); } - @end