Skip to content

Commit

Permalink
Merge branch 'master' into atrstring
Browse files Browse the repository at this point in the history
  • Loading branch information
Ross Boucher committed Nov 11, 2008
2 parents bf72b5c + 8adaa2d commit 75bedef
Show file tree
Hide file tree
Showing 9 changed files with 228 additions and 80 deletions.
6 changes: 6 additions & 0 deletions AppKit/AppKit.steam
Expand Up @@ -14,6 +14,9 @@
<string>CPOutlineView.j</string>
<string>CPTableColumn.j</string>
<string>CPTableView.j</string>
<!-- These get compiled into CGContext -->
<string>CoreGraphics/CGContextCanvas.j</string>
<string>CoreGraphics/CGContextVML.j</string>
</array>
<key>Flags</key>
<string>-DPLATFORM_DOM</string>
Expand All @@ -26,6 +29,9 @@
<string>CPOutlineView.j</string>
<string>CPTableColumn.j</string>
<string>CPTableView.j</string>
<!-- These get compiled into CGContext -->
<string>CoreGraphics/CGContextCanvas.j</string>
<string>CoreGraphics/CGContextVML.j</string>
</array>
</dict>
</array>
Expand Down
4 changes: 3 additions & 1 deletion AppKit/CPAlert.j
Expand Up @@ -238,4 +238,6 @@ var CPAlertWarningImage,

[CPApp abortModal];
[_alertPanel close];
}
}

@end
201 changes: 131 additions & 70 deletions AppKit/CPToolbar.j
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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 */
Expand All @@ -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
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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];
}

Expand Down Expand Up @@ -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.
Expand All @@ -285,25 +263,118 @@ var CPToolbarConfigurationsByIdentifier = nil;
}

/*!
Returns the index of the specified toolbar item
@param anItem the item to obtain the index for
Returns the toolbar items sorted by their <code>visibilityPriority</code>(ies).
*/
- (CPArray)itemsSortedByVisibilityPriority
{
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 <code>aCoder</code>.
@param aCoder the coder containing the archived <objj>CPToolbar</objj>.
*/
- (int)indexOfItem:(CPToolbarItem)anItem
- (id)initWithCoder:(CPCoder)aCoder
{
var info = [_itemIndexes objectForKey:[anItem hash]];
self = [super init];

if (!info)
return CPNotFound;
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 info.index;
return self;
}

/*!
Returns the toolbar items sorted by their <code>visibilityPriority</code>(ies).
/*
Archives this toolbar into the provided coder.
@param aCoder the coder to which the toolbar's instance data will be written.
*/
- (CPArray)itemsSortedByVisibilityPriority
- (void)encodeWithCoder:(CPCoder)aCoder
{
return _itemsSortedByVisibilityPriority;
[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
Expand All @@ -330,7 +401,7 @@ var _CPToolbarItemInfoMake = function(anIndex, aView, aLabel, aMinWidth)
CPIndexSet _flexibleWidthIndexes;
CPIndexSet _visibleFlexibleWidthIndexes;

CPMutableDictionary _itemInfos;
CPDictionary _itemInfos;

CPArray _visibleItems;
CPArray _invisibleItems;
Expand Down Expand Up @@ -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]];
Expand Down
14 changes: 10 additions & 4 deletions AppKit/Cib/_CPCibWindowTemplate.j
Expand Up @@ -5,7 +5,8 @@
var _CPCibWindowTemplateMinSizeKey = @"_CPCibWindowTemplateMinSizeKey",
_CPCibWindowTemplateMaxSizeKey = @"_CPCibWindowTemplateMaxSizeKey",

_CPCibWindowTemplateViewClassKey = @"_CPCibWindowTemplateWindowClassKey",
_CPCibWindowTemplateViewClassKey = @"_CPCibWindowTemplateViewClassKey",
_CPCibWindowTemplateWindowClassKey = @"_CPCibWindowTemplateWindowClassKey",

_CPCibWindowTemplateWindowRectKey = @"_CPCibWindowTemplateWindowRectKey",
_CPCibWindowTemplateWindowStyleMaskKey = @"_CPCibWindowTempatStyleMaskKey",
Expand All @@ -18,7 +19,7 @@ var _CPCibWindowTemplateMinSizeKey = @"_CPCibWindowTemplateMinSizeKey",
CGSize _maxSize;
//CGSize _screenRect;

CPString _viewClass;
id _viewClass;
//unsigned _wtFlags;
CPString _windowClass;
CGRect _windowRect;
Expand All @@ -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];

Expand All @@ -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];

Expand Down Expand Up @@ -91,6 +92,11 @@ var _CPCibWindowTemplateMinSizeKey = @"_CPCibWindowTemplateMinSizeKey",

[_windowView setAutoresizesSubviews:YES];

if ([_viewClass isKindOfClass:[CPToolbar class]])
{
[theWindow setToolbar:_viewClass];
}

return theWindow;
}

Expand Down
9 changes: 7 additions & 2 deletions AppKit/CoreGraphics/CGContext.j
Expand Up @@ -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) };
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 75bedef

Please sign in to comment.