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/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 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 addf32c19..a9a168d4e 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]; @@ -91,6 +92,11 @@ var _CPCibWindowTemplateMinSizeKey = @"_CPCibWindowTemplateMinSizeKey", [_windowView setAutoresizesSubviews:YES]; + if ([_viewClass isKindOfClass:[CPToolbar class]]) + { + [theWindow setToolbar:_viewClass]; + } + return theWindow; } 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 = [ " + + +@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