From 937865ef830e67280fe8d3ca6c634fe8ee38757b Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Mon, 10 Nov 2008 11:17:39 -0800 Subject: [PATCH 1/5] There was a missing @end in CPAlert.j --- AppKit/CPAlert.j | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/AppKit/CPAlert.j b/AppKit/CPAlert.j index d35f3ad2d..4072adbb8 100644 --- a/AppKit/CPAlert.j +++ b/AppKit/CPAlert.j @@ -238,4 +238,6 @@ var CPAlertWarningImage, [CPApp abortModal]; [_alertPanel close]; -} \ No newline at end of file +} + +@end \ No newline at end of file From add1776125b6ea5707cc965a7bc0026fd694d666 Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Mon, 10 Nov 2008 23:16:29 -0800 Subject: [PATCH 2/5] Fix for local CPURLConnection requests (file:///) --- Foundation/CPURLConnection.j | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Foundation/CPURLConnection.j b/Foundation/CPURLConnection.j index 2e639d7f1..91073fcae 100644 --- a/Foundation/CPURLConnection.j +++ b/Foundation/CPURLConnection.j @@ -222,14 +222,15 @@ var CPURLConnectionDelegate = nil; { if (_XMLHTTPRequest.readyState == XMLHTTPRequestComplete) { - var statusCode = _XMLHTTPRequest.status; + var statusCode = _XMLHTTPRequest.status, + url = [_request URL]; if ([_delegate respondsToSelector:@selector(connection:didReceiveResponse:)]) [_delegate connection:self didReceiveResponse:[[CPHTTPURLResponse alloc] _initWithStatusCode:statusCode]]; if (!_isCanceled) { - if (statusCode == 200) + if (statusCode == 200 || (url.indexOf("file:") === 0 && statusCode === 0) || ((url.indexOf("http:") !== 0 || url.indexOf("https:") !== 0) && window.location && window.location.protocol === "file:" && statusCode === 0)) { [_delegate connection:self didReceiveData:_XMLHTTPRequest.responseText]; [_delegate connectionDidFinishLoading:self]; From ac5c59f8babf3b956da8e6fc32f2f289ec038f6c Mon Sep 17 00:00:00 2001 From: Tom Robinson Date: Tue, 11 Nov 2008 02:27:56 -0800 Subject: [PATCH 3/5] Fixed incorrect viewClass/windowClass archiving keys --- AppKit/Cib/_CPCibWindowTemplate.j | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/AppKit/Cib/_CPCibWindowTemplate.j b/AppKit/Cib/_CPCibWindowTemplate.j index addf32c19..1880c35f5 100644 --- a/AppKit/Cib/_CPCibWindowTemplate.j +++ b/AppKit/Cib/_CPCibWindowTemplate.j @@ -5,7 +5,8 @@ var _CPCibWindowTemplateMinSizeKey = @"_CPCibWindowTemplateMinSizeKey", _CPCibWindowTemplateMaxSizeKey = @"_CPCibWindowTemplateMaxSizeKey", - _CPCibWindowTemplateViewClassKey = @"_CPCibWindowTemplateWindowClassKey", + _CPCibWindowTemplateViewClassKey = @"_CPCibWindowTemplateViewClassKey", + _CPCibWindowTemplateWindowClassKey = @"_CPCibWindowTemplateWindowClassKey", _CPCibWindowTemplateWindowRectKey = @"_CPCibWindowTemplateWindowRectKey", _CPCibWindowTemplateWindowStyleMaskKey = @"_CPCibWindowTempatStyleMaskKey", @@ -18,7 +19,7 @@ var _CPCibWindowTemplateMinSizeKey = @"_CPCibWindowTemplateMinSizeKey", CGSize _maxSize; //CGSize _screenRect; - CPString _viewClass; + id _viewClass; //unsigned _wtFlags; CPString _windowClass; CGRect _windowRect; @@ -39,7 +40,7 @@ var _CPCibWindowTemplateMinSizeKey = @"_CPCibWindowTemplateMinSizeKey", _viewClass = [aCoder decodeObjectForKey:_CPCibWindowTemplateViewClassKey]; - _windowClass = [aCoder decodeObjectForKey:_CPCibWindowTemplateViewClassKey]; + _windowClass = [aCoder decodeObjectForKey:_CPCibWindowTemplateWindowClassKey]; _windowRect = [aCoder decodeRectForKey:_CPCibWindowTemplateWindowRectKey]; _windowStyleMask = [aCoder decodeIntForKey:_CPCibWindowTemplateWindowStyleMaskKey]; @@ -57,7 +58,7 @@ var _CPCibWindowTemplateMinSizeKey = @"_CPCibWindowTemplateMinSizeKey", [aCoder encodeObject:_viewClass forKey:_CPCibWindowTemplateViewClassKey]; - [aCoder encodeObject:_windowClass forKey:_CPCibWindowTemplateViewClassKey]; + [aCoder encodeObject:_windowClass forKey:_CPCibWindowTemplateWindowClassKey]; [aCoder encodeRect:_windowRect forKey:_CPCibWindowTemplateWindowRectKey]; [aCoder encodeInt:_windowStyleMask forKey:_CPCibWindowTemplateWindowStyleMaskKey]; From 88fbecb4d3d228ac895104c913b8a27403428c62 Mon Sep 17 00:00:00 2001 From: Tom Robinson Date: Tue, 11 Nov 2008 02:29:33 -0800 Subject: [PATCH 4/5] Intial CPToolbar coding / nib2cib support (still need CPToolbarItem support) --- AppKit/CPToolbar.j | 207 +++++++++++++++++++----------- AppKit/Cib/_CPCibWindowTemplate.j | 5 + Tools/nib2cib/NSAppKit.j | 1 + Tools/nib2cib/NSToolbar.j | 65 ++++++++++ 4 files changed, 205 insertions(+), 73 deletions(-) create mode 100644 Tools/nib2cib/NSToolbar.j diff --git a/AppKit/CPToolbar.j b/AppKit/CPToolbar.j index d444dba3e..67b6dc42c 100644 --- a/AppKit/CPToolbar.j +++ b/AppKit/CPToolbar.j @@ -2,6 +2,9 @@ * CPToolbar.j * AppKit * + * Portions based on NSToolbar.m (11/10/2008) in Cocotron (http://www.cocotron.org/) + * Copyright (c) 2006-2007 Christopher J. W. Lloyd + * * Created by Francisco Tolmasky. * Copyright 2008, 280 North, Inc. * @@ -83,18 +86,18 @@ var CPToolbarConfigurationsByIdentifier = nil; BOOL _showsBaselineSeparator; BOOL _allowsUserCustomization; BOOL _isVisible; - BOOL _needsReloadOfItems; id _delegate; - CPView _toolbarView; - CPArray _itemIdentifiers; - CPArray _allowedItemIdentifiers; + CPDictionary _identifiedItems; + CPArray _defaultItems; + CPArray _allowedItems; + CPArray _selectableItems; CPArray _items; - CPArray _labels; + CPArray _itemsSortedByVisibilityPriority; - CPMutableDictionary _itemIndexes; + CPView _toolbarView; } /* @ignore */ @@ -107,6 +110,20 @@ var CPToolbarConfigurationsByIdentifier = nil; CPToolbarConfigurationsByIdentifier = [CPDictionary dictionary]; } +/* @ignore */ ++ (void)_addToolbar:(CPToolbar)toolbar forIdentifier:(CPString)identifier +{ + var toolbarsSharingIdentifier = [CPToolbarsByIdentifier objectForKey:identifier]; + + if (!toolbarsSharingIdentifier) + { + toolbarsSharingIdentifier = [] + [CPToolbarsByIdentifier setObject:toolbarsSharingIdentifier forKey:identifier]; + } + + [toolbarsSharingIdentifier addObject:toolbar]; +} + /*! Initializes the toolbar with the specified identifier. @param anIdentifier the identifier for the toolbar @@ -119,25 +136,17 @@ var CPToolbarConfigurationsByIdentifier = nil; if (self) { _items = []; - _labels = []; _identifier = anIdentifier; _isVisible = YES; - var toolbarsSharingIdentifier = [CPToolbarsByIdentifier objectForKey:_identifier]; - - if (!toolbarsSharingIdentifier) - { - toolbarsSharingIdentifier = [] - [CPToolbarsByIdentifier setObject:toolbarsSharingIdentifier forKey:_identifier]; - } - - [toolbarsSharingIdentifier addObject:self]; + [CPToolbar _addToolbar:self forIdentifier:_identifier]; } return self; } + /*! Sets the toolbar's display mode. NOT YET IMPLEMENTED. */ @@ -196,10 +205,6 @@ var CPToolbarConfigurationsByIdentifier = nil; _delegate = aDelegate; - // When _delegate is nil, this will be cleared out. - _itemIdentifiers = nil; - _allowedItemIdentifiers = [_delegate toolbarAllowedItemIdentifiers:self]; - [self _reloadToolbarItems]; } @@ -229,36 +234,9 @@ var CPToolbarConfigurationsByIdentifier = nil; if (![_toolbarView superview] || !_delegate) return; - var count = [_itemIdentifiers count]; - - if (!count) - { - _itemIdentifiers = [[_delegate toolbarDefaultItemIdentifiers:self] mutableCopy]; - - count = [_itemIdentifiers count]; - } - [[_toolbarView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)]; - _items = []; - _labels = []; - - var index = 0; - - for (; index < count; ++index) - { - var identifier = _itemIdentifiers[index], - item = [CPToolbarItem _standardItemWithItemIdentifier:identifier]; - - if (!item) - item = [[_delegate toolbar:self itemForItemIdentifier:identifier willBeInsertedIntoToolbar:YES] copy]; - - if (item == nil) - [CPException raise:CPInvalidArgumentException - reason:sprintf(@"_delegate %s returned nil toolbar item returned for identifier %s", _delegate, identifier)]; - - [_items addObject:item]; - } + _items = [[self _defaultToolbarItems] mutableCopy]; // Store items sorted by priority. We want items to be removed first at the end of the array, // items to be removed last at the front. @@ -284,20 +262,6 @@ var CPToolbarConfigurationsByIdentifier = nil; return [_toolbarView visibleItems]; } -/*! - Returns the index of the specified toolbar item - @param anItem the item to obtain the index for -*/ -- (int)indexOfItem:(CPToolbarItem)anItem -{ - var info = [_itemIndexes objectForKey:[anItem hash]]; - - if (!info) - return CPNotFound; - - return info.index; -} - /*! Returns the toolbar items sorted by their visibilityPriority(ies). */ @@ -306,6 +270,113 @@ var CPToolbarConfigurationsByIdentifier = nil; return _itemsSortedByVisibilityPriority; } +/* @ignore */ +- (id)_itemForItemIdentifier:(CPString)identifier willBeInsertedIntoToolbar:(BOOL)toolbar +{ + var item = [_identifiedItems objectForKey:identifier]; + if (!item) + { + item = [CPToolbarItem _standardItemWithItemIdentifier:identifier]; + if (_delegate && !item) + { + item = [_delegate toolbar:self itemForItemIdentifier:identifier willBeInsertedIntoToolbar:toolbar]; + if (!item) + [CPException raise:CPInvalidArgumentException + reason:sprintf(@"_delegate %s returned nil toolbar item returned for identifier %s", _delegate, identifier)]; + } + + [_identifiedItems setObject:item forKey:identifier]; + } + + return item; +} + +/* @ignore */ +- (id)_itemsWithIdentifiers:(CPArray)identifiers +{ + var items = []; + for (var i = 0; i < identifiers.length; i++) + [items addObject:[self _itemForItemIdentifier:identifiers[i] willBeInsertedIntoToolbar:NO]]; + + return items; +} + +/* @ignore */ +-(id)_defaultToolbarItems +{ + if (!_defaultItems) + if ([_delegate respondsToSelector:@selector(toolbarDefaultItemIdentifiers:)]) + _defaultItems = [self _itemsWithIdentifiers:[_delegate toolbarDefaultItemIdentifiers:self]]; + + return _defaultItems; +} + +@end + + +var CPToolbarIdentifierKey = "CPToolbarIdentifierKey", + CPToolbarDisplayModeKey = "CPToolbarDisplayModeKey", + CPToolbarShowsBaselineSeparatorKey = "CPToolbarShowsBaselineSeparatorKey", + CPToolbarAllowsUserCustomizationKey = "CPToolbarAllowsUserCustomizationKey", + CPToolbarIsVisibleKey = "CPToolbarIsVisibleKey", + CPToolbarDelegateKey = "CPToolbarDelegateKey", + CPToolbarIdentifiedItemsKey = "CPToolbarIdentifiedItemsKey", + CPToolbarDefaultItemsKey = "CPToolbarDefaultItemsKey", + CPToolbarAllowedItemsKey = "CPToolbarAllowedItemsKey", + CPToolbarSelectableItemsKey = "CPToolbarSelectableItemsKey"; + +@implementation CPToolbar (CPCoding) + +/* + Initializes the toolbar by unarchiving data from aCoder. + @param aCoder the coder containing the archived CPToolbar. +*/ +- (id)initWithCoder:(CPCoder)aCoder +{ + self = [super init]; + + if (self) + { + _identifier = [aCoder decodeObjectForKey:CPToolbarIdentifierKey]; + _displayMode = [aCoder decodeIntForKey:CPToolbarDisplayModeKey]; + _showsBaselineSeparator = [aCoder decodeBoolForKey:CPToolbarShowsBaselineSeparatorKey]; + _allowsUserCustomization = [aCoder decodeBoolForKey:CPToolbarAllowsUserCustomizationKey]; + _isVisible = [aCoder decodeBoolForKey:CPToolbarIsVisibleKey]; + + _identifiedItems = [aCoder decodeObjectForKey:CPToolbarIdentifiedItemsKey]; + _defaultItems = [aCoder decodeObjectForKey:CPToolbarDefaultItemsKey]; + _allowedItems = [aCoder decodeObjectForKey:CPToolbarAllowedItemsKey]; + _selectableItems = [aCoder decodeObjectForKey:CPToolbarSelectableItemsKey]; + + _items = []; + [CPToolbar _addToolbar:self forIdentifier:_identifier]; + + [self setDelegate:[aCoder decodeObjectForKey:CPToolbarDelegateKey]]; + } + + return self; +} + +/* + Archives this toolbar into the provided coder. + @param aCoder the coder to which the toolbar's instance data will be written. +*/ +- (void)encodeWithCoder:(CPCoder)aCoder +{ + [aCoder encodeObject:_identifier forKey:CPToolbarIdentifierKey]; + [aCoder encodeInt:_displayMode forKey:CPToolbarDisplayModeKey]; + [aCoder encodeBool:_showsBaselineSeparator forKey:CPToolbarShowsBaselineSeparatorKey]; + [aCoder encodeBool:_allowsUserCustomization forKey:CPToolbarAllowsUserCustomizationKey]; + [aCoder encodeBool:_isVisible forKey:CPToolbarIsVisibleKey]; + + [aCoder encodeObject:_identifiedItems forKey:CPToolbarIdentifiedItemsKey]; + [aCoder encodeObject:_defaultItems forKey:CPToolbarDefaultItemsKey]; + [aCoder encodeObject:_allowedItems forKey:CPToolbarAllowedItemsKey]; + [aCoder encodeObject:_selectableItems forKey:CPToolbarSelectableItemsKey]; + + [aCoder encodeConditionalObject:_delegate forKey:CPToolbarDelegateKey]; +} + @end @@ -330,7 +401,7 @@ var _CPToolbarItemInfoMake = function(anIndex, aView, aLabel, aMinWidth) CPIndexSet _flexibleWidthIndexes; CPIndexSet _visibleFlexibleWidthIndexes; - CPMutableDictionary _itemInfos; + CPDictionary _itemInfos; CPArray _visibleItems; CPArray _invisibleItems; @@ -580,16 +651,6 @@ var _CPToolbarItemInfoMake = function(anIndex, aView, aLabel, aMinWidth) } -- (int)indexOfItem:(CPToolbarItem)anItem -{ - var info = [_itemInfos objectForKey:[anItem hash]]; - - if (!info) - return CPNotFound; - - return info.index; -} - - (CPView)viewForItem:(CPToolbarItem)anItem { var info = [_itemInfos objectForKey:[anItem hash]]; diff --git a/AppKit/Cib/_CPCibWindowTemplate.j b/AppKit/Cib/_CPCibWindowTemplate.j index 1880c35f5..a9a168d4e 100644 --- a/AppKit/Cib/_CPCibWindowTemplate.j +++ b/AppKit/Cib/_CPCibWindowTemplate.j @@ -92,6 +92,11 @@ var _CPCibWindowTemplateMinSizeKey = @"_CPCibWindowTemplateMinSizeKey", [_windowView setAutoresizesSubviews:YES]; + if ([_viewClass isKindOfClass:[CPToolbar class]]) + { + [theWindow setToolbar:_viewClass]; + } + return theWindow; } diff --git a/Tools/nib2cib/NSAppKit.j b/Tools/nib2cib/NSAppKit.j index 1a7c357b9..b5e5628d2 100644 --- a/Tools/nib2cib/NSAppKit.j +++ b/Tools/nib2cib/NSAppKit.j @@ -34,6 +34,7 @@ @import "NSSlider.j" @import "NSSplitView.j" @import "NSTextField.j" +@import "NSToolbar.j" @import "NSView.j" @import "NSWindowTemplate.j" @import "WebView.j" diff --git a/Tools/nib2cib/NSToolbar.j b/Tools/nib2cib/NSToolbar.j new file mode 100644 index 000000000..ada676674 --- /dev/null +++ b/Tools/nib2cib/NSToolbar.j @@ -0,0 +1,65 @@ +/* + * NSToolbar.j + * nib2cib + * + * Created by Thomas Robinson. + * Copyright 2008, 280 North, Inc. + * + * 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 CPToolbar (NSCoding) + +- (id)NS_initWithCoder:(CPCoder)aCoder +{ + if (self) + { + _identifier = [aCoder decodeObjectForKey:"NSToolbarIdentifier"]; + _displayMode = [aCoder decodeIntForKey:"NSToolbarDisplayMode"]; + _showsBaselineSeparator = [aCoder decodeBoolForKey:"NSToolbarShowsBaselineSeparator"]; + _allowsUserCustomization = [aCoder decodeBoolForKey:"NSToolbarAllowsUserCustomization"]; + _isVisible = [aCoder decodeBoolForKey:"NSToolbarPrefersToBeShown"]; + + _identifiedItems = [aCoder decodeObjectForKey:"NSToolbarIBIdentifiedItems"]; + _defaultItems = [aCoder decodeObjectForKey:"NSToolbarIBDefaultItems"]; + _allowedItems = [aCoder decodeObjectForKey:"NSToolbarIBAllowedItems"]; + _selectableItems = [aCoder decodeObjectForKey:"NSToolbarIBSelectableItems"]; + + _delegate = [aCoder decodeObjectForKey:"NSToolbarDelegate"]; + } + + return self; +} + +@end + +@implementation NSToolbar : CPToolbar +{ +} + +- (id)initWithCoder:(CPCoder)aCoder +{ + return [self NS_initWithCoder:aCoder]; +} + +- (Class)classForKeyedArchiver +{ + return [CPToolbar class]; +} + +@end From 8adaa2d3c84ad4ddd3c55b50e3cfe80b8e55b437 Mon Sep 17 00:00:00 2001 From: Francisco Ryan Tolmasky I Date: Tue, 11 Nov 2008 12:21:33 -0800 Subject: [PATCH 5/5] Added CGContextSetAlpha VML implementation for use in IE, and fixed a bug where CGContextCanvas.j and CGContextVML.j were being added to AppKit.sj inappropriately. Reviewed by me. --- AppKit/AppKit.steam | 6 ++++++ AppKit/CoreGraphics/CGContext.j | 9 +++++++-- AppKit/CoreGraphics/CGContextVML.j | 3 ++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/AppKit/AppKit.steam b/AppKit/AppKit.steam index 9a6a89952..b2c4d5537 100644 --- a/AppKit/AppKit.steam +++ b/AppKit/AppKit.steam @@ -14,6 +14,9 @@ CPOutlineView.j CPTableColumn.j CPTableView.j + + CoreGraphics/CGContextCanvas.j + CoreGraphics/CGContextVML.j Flags -DPLATFORM_DOM @@ -26,6 +29,9 @@ CPOutlineView.j CPTableColumn.j CPTableView.j + + CoreGraphics/CGContextCanvas.j + CoreGraphics/CGContextVML.j diff --git a/AppKit/CoreGraphics/CGContext.j b/AppKit/CoreGraphics/CGContext.j index e536a52d8..8a2e0bc36 100644 --- a/AppKit/CoreGraphics/CGContext.j +++ b/AppKit/CoreGraphics/CGContext.j @@ -208,14 +208,14 @@ if (!CPFeatureIsCompatible(CPHTMLCanvasFeature)) function CGGStateCreate() { - return { strokeStyle:"#000", fillStyle:"#ccc", lineWidth:1.0, lineJoin:kCGLineJoinMiter, lineCap:kCGLineCapButt, miterLimit:10.0, globalAlpha:1.0, + return { alpha:1.0, strokeStyle:"#000", fillStyle:"#ccc", lineWidth:1.0, lineJoin:kCGLineJoinMiter, lineCap:kCGLineCapButt, miterLimit:10.0, globalAlpha:1.0, blendMode:kCGBlendModeNormal, shadowOffset:_CGSizeMakeZero(), shadowBlur:0.0, shadowColor:NULL, CTM:_CGAffineTransformMakeIdentity() }; } function CGGStateCreateCopy(aGState) { - return { strokeStyle:aGState.strokeStyle, fillStyle:aGState.fillStyle, lineWidth:aGState.lineWidth, + return { alpha:aGState.alpha, strokeStyle:aGState.strokeStyle, fillStyle:aGState.fillStyle, lineWidth:aGState.lineWidth, lineJoin:aGState.lineJoin, lineCap:aGState.lineCap, miterLimit:aGState.miterLimit, globalAlpha:aGState.globalAlpha, blendMode:aGState.blendMode, shadowOffset:aGState.shadowOffset, shadowBlur:aGState.shadowBlur, shadowColor:aGState.shadowColor, CTM:_CGAffineTransformMakeCopy(aGState.CTM) }; @@ -418,6 +418,11 @@ function CGContextSetShadowWithColor(aContext, aSize, aBlur, aColor) gState.shadowColor = aColor; } +function CGContextSetAlpha(aContext, anAlpha) +{ + aContext.gState.alpha = MAX(MIN(anAlpha, 1.0), 0.0); +} + } // END CANVAS IF // GOOD. diff --git a/AppKit/CoreGraphics/CGContextVML.j b/AppKit/CoreGraphics/CGContextVML.j index 264b20587..a85e89089 100644 --- a/AppKit/CoreGraphics/CGContextVML.j +++ b/AppKit/CoreGraphics/CGContextVML.j @@ -111,7 +111,7 @@ function CGContextDrawPath(aContext, aMode) { if (!aContext || CGPathIsEmpty(aContext.path)) return; -var opacity = 1.0; + var elements = aContext.path.elements, i = 0, @@ -120,6 +120,7 @@ var opacity = 1.0; gState = aContext.gState, fill = (aMode == kCGPathFill || aMode == kCGPathFillStroke) ? 1 : 0, stroke = (aMode == kCGPathStroke || aMode == kCGPathFillStroke) ? 1 : 0, + opacity = gState.alpha, vml = [ "