Skip to content

Commit

Permalink
Merge branch '0.7b' of git@github.com:280north/cappuccino into 0.7b
Browse files Browse the repository at this point in the history
  • Loading branch information
Ross Boucher committed May 5, 2009
2 parents 0501f12 + 2176785 commit dd41c31
Show file tree
Hide file tree
Showing 30 changed files with 3,376 additions and 366 deletions.
2 changes: 2 additions & 0 deletions AppKit/AppKit.j
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
@import "CPApplication.j"
@import "CPButton.j"
@import "CPButtonBar.j"
@import "CPCib.j"
@import "CPCibLoading.j"
@import "CPClipView.j"
@import "CPCollectionView.j"
@import "CPColor.j"
Expand Down
100 changes: 76 additions & 24 deletions AppKit/CPApplication.j
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
@import "CPResponder.j"
@import "CPDocumentController.j"

var CPMainCibFile = @"CPMainCibFile",
CPMainCibFileHumanFriendly = @"Main cib file base name";

CPApp = nil;

Expand Down Expand Up @@ -739,44 +741,27 @@ var _CPRunModalLoop = function(anEvent)
@class CPApplication
@return void
*/
@implementation X : CPObject
{
}
- (void)blendDidFinishLoading:(CPBundle)aBundle
{
[CPTheme setDefaultTheme:[CPTheme themeNamed:@"Aristo"]];
_CPApplicationMain()
}
@end
function CPApplicationMain(args, namedArgs)
{
var blend = [[CPBlend alloc] initWithContentsOfURL:[[CPBundle bundleForClass:[CPApplication class]] pathForResource:@"Aristo.blend"]];

[blend loadWithDelegate:[X new]];
}

function _CPApplicationMain(args, namedArgs)
function CPApplicationMain(args, namedArgs)
{
var mainBundle = [CPBundle mainBundle],
principalClass = [mainBundle principalClass];

if (!principalClass)
principalClass = [CPApplication class];

[principalClass sharedApplication];

//[NSBundle loadNibNamed:@"myMain" owner:NSApp];


//FIXME?
if (!args && !namedArgs)
{
var args = [CPApp arguments],
searchParams = window.location.search.substring(1).split("&");
namedArgs = [CPDictionary dictionary];

if([args containsObject:"debug"])
CPLogRegister(CPLogPopup);

for(var i=0; i<searchParams.length; i++)
{
var index = searchParams[i].indexOf('=');
Expand All @@ -786,9 +771,76 @@ function _CPApplicationMain(args, namedArgs)
[namedArgs setObject: searchParams[i].substring(index+1) forKey: searchParams[i].substring(0, index)];
}
}

CPApp._args = args;
CPApp._namedArgs = namedArgs;


[_CPAppBootstrapper performActions];
}

var _CPAppBootstrapperActions = nil;

@implementation _CPAppBootstrapper : CPObject
{
}

+ (void)actions
{
return [@selector(loadDefaultTheme), @selector(loadMainCibFile)];
}

+ (void)performActions
{
if (!_CPAppBootstrapperActions)
_CPAppBootstrapperActions = [self actions];

while (_CPAppBootstrapperActions.length)
{
var action = _CPAppBootstrapperActions.shift();

if (objj_msgSend(self, action))
return;
}

[CPApp run];
}

+ (BOOL)loadDefaultTheme
{
var blend = [[CPBlend alloc] initWithContentsOfURL:[[CPBundle bundleForClass:[CPApplication class]] pathForResource:@"Aristo.blend"]];

[blend loadWithDelegate:self];

return YES;
}

+ (void)blendDidFinishLoading:(CPBundle)aBundle
{
[CPTheme setDefaultTheme:[CPTheme themeNamed:@"Aristo"]];

[self performActions];
}

+ (BOOL)loadMainCibFile
{
var mainBundle = [CPBundle mainBundle],
mainCibFile = [mainBundle objectForInfoDictionaryKey:CPMainCibFile] || [mainBundle objectForInfoDictionaryKey:CPMainCibFileHumanFriendly];

if (mainCibFile)
{
[CPBundle loadCibFile:[mainBundle pathForResource:mainCibFile]
externalNameTable:[CPDictionary dictionaryWithObject:CPApp forKey:CPCibOwner]
loadDelegate:self];

return YES;
}

return NO;
}

+ (void)cibDidFinishLoading:(CPCib)aCib
{
[self performActions];
}

@end
38 changes: 29 additions & 9 deletions AppKit/CPSlider.j
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ CPCircularSlider = 1;
double _minValue;
double _maxValue;
double _altIncrementValue;

BOOL _isVertical;
}

+ (id)themedAttributes
Expand All @@ -54,6 +56,8 @@ CPCircularSlider = 1;
[self setObjectValue:50.0];

[self setContinuous:YES];

[self _recalculateIsVertical];
}

return self;
Expand Down Expand Up @@ -226,26 +230,40 @@ CPCircularSlider = 1;
return _altIncrementValue;
}

- (int)isVertical
- (void)setFrameSize:(CGSize)aSize
{
[super setFrameSize:aSize];
[self _recalculateIsVertical];
}

- (void)_recalculateIsVertical
{
// Recalculate isVertical.
var bounds = [self bounds],
width = CGRectGetWidth(bounds),
height = CGRectGetHeight(bounds);
width = _CGRectGetWidth(bounds),
height = _CGRectGetHeight(bounds);

return width < height ? 1 : (width > height ? 0 : -1);
_isVertical = width < height ? 1 : (width > height ? 0 : -1);

if (_isVertical === 1)
_controlState |= CPControlStateVertical;
else if (_isVertical === 0)
_controlState &= ~CPControlStateVertical;
}

- (int)isVertical
{
return _isVertical;
}

- (void)layoutSubviews
{
var trackView = [self layoutEphemeralSubviewNamed:@"track-view"
positioned:CPWindowBelow
relativeToEphemeralSubviewNamed:@"knob-view"];

if (trackView)
if ([self isVertical])
[trackView setBackgroundColor:[self currentValueForThemedAttributeName:@"track-color"]];
else
[trackView setBackgroundColor:[self currentValueForThemedAttributeName:@"track-color"]];
[trackView setBackgroundColor:[self currentValueForThemedAttributeName:@"track-color"]];

var knobView = [self layoutEphemeralSubviewNamed:@"knob-view"
positioned:CPWindowAbove
Expand Down Expand Up @@ -385,6 +403,8 @@ var CPSliderMinValueKey = "CPSliderMinValueKey",

[self setContinuous:YES];

[self _recalculateIsVertical];

[self setNeedsLayout];
[self setNeedsDisplay:YES];
}
Expand Down
2 changes: 1 addition & 1 deletion AppKit/CPTableView.j
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ var _CPTableViewWillDisplayCellSelector = 1 << 0,

[_tableCells removeObjectAtIndex:index];
[_tableColumns removeObjectAtIndex:index];
[_tabelColumnViews removeObjectAtIndex:index];
[_tableColumnViews removeObjectAtIndex:index];

// Shift remaining column views to the left.
for (; index < _tableColumns.length; ++ index)
Expand Down
6 changes: 4 additions & 2 deletions AppKit/CPTextField.j
Original file line number Diff line number Diff line change
Expand Up @@ -753,10 +753,12 @@ CPTextFieldStatePlaceholder = 1 << 13;
if (_controlState & CPTextFieldStatePlaceholder)
string = [self placeholderString];
else
{
string = [self stringValue];

if ([self isSecure])
string = secureStringForString(string);
if ([self isSecure])
string = secureStringForString(string);
}

[contentView setText:string];

Expand Down
69 changes: 57 additions & 12 deletions AppKit/Cib/CPCib.j
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,47 @@ var CPCibObjectDataKey = @"CPCibObjectDataKey";
CPData _data;
CPBundle _bundle;
BOOL _awakenCustomResources;

id _loadDelegate;
}

- (id)initWithContentsOfURL:(CPURL)aURL
{
self = [super init];

if (self)
{
_data = [CPURLConnection sendSynchronousRequest:[CPURLRequest requestWithURL:aURL] returningResponse:nil error:nil];
_awakenCustomResources = YES;
}

return self;
}

- (id)initWithCibNamed:(CPString)aName bundle:(CPBundle)aBundle
- (id)initWithContentsOfURL:(CPURL)aURL loadDelegate:(id)aLoadDelegate
{
self = [self initWithContentsOfURL:aName];
self = [super init];

if (self)
{
_bundle = aBundle;
[CPURLConnection connectionWithRequest:[CPURLRequest requestWithURL:aURL] delegate:self];

_awakenCustomResources = YES;

_loadDelegate = aLoadDelegate;
}


return self;
}

- (id)initWithCibNamed:(CPString)aName bundle:(CPBundle)aBundle loadDelegate:(id)aLoadDelegate
{
// If aBundle is nil, use mainBundle, but ONLY for searching for the nib, not for resources later.
self = [self initWithContentsOfURL:[aBundle || [CPBundle mainBundle] pathForResource:aName] loadDelegate:aLoadDelegate];

if (self)
_bundle = aBundle;

return self;
}

Expand All @@ -82,7 +99,13 @@ var CPCibObjectDataKey = @"CPCibObjectDataKey";

- (BOOL)instantiateCibWithExternalNameTable:(CPDictionary)anExternalNameTable
{
var unarchiver = [[_CPCibKeyedUnarchiver alloc] initForReadingWithData:_data bundle:_bundle awakenCustomResources:_awakenCustomResources],
var bundle = _bundle,
owner = [anExternalNameTable objectForKey:CPCibOwner];

if (!bundle && owner)
bundle = [CPBundle bundleForClass:[owner class]];

var unarchiver = [[_CPCibKeyedUnarchiver alloc] initForReadingWithData:_data bundle:bundle awakenCustomResources:_awakenCustomResources],
replacementClasses = [anExternalNameTable objectForKey:CPCibReplacementClasses];

if (replacementClasses)
Expand All @@ -99,8 +122,7 @@ var CPCibObjectDataKey = @"CPCibObjectDataKey";
if (!objectData || ![objectData isKindOfClass:[_CPCibObjectData class]])
return NO;

var owner = [anExternalNameTable objectForKey:CPCibOwner],
topLevelObjects = [anExternalNameTable objectForKey:CPCibTopLevelObjects];
var topLevelObjects = [anExternalNameTable objectForKey:CPCibTopLevelObjects];

[objectData instantiateWithOwner:owner topLevelObjects:topLevelObjects]
[objectData establishConnectionsWithOwner:owner topLevelObjects:topLevelObjects];
Expand All @@ -122,8 +144,31 @@ var CPCibObjectDataKey = @"CPCibObjectDataKey";

- (BOOL)instantiateCibWithOwner:(id)anOwner topLevelObjects:(CPArray)topLevelObjects
{
[CPDictionary dictionaryWithObjectsAndKeys:anOwner, CPCibOwner, topLevelObjects, CPCibTopLevelObjects];
return [self instantiate];
return [self instantiateCibWithExternalNameTable:[CPDictionary dictionaryWithObjectsAndKeys:anOwner, CPCibOwner, topLevelObjects, CPCibTopLevelObjects]];
}

@end

@implementation CPCib (CPURLConnectionDelegate)

- (void)connection:(CPURLConnection)aConnection didReceiveData:(CPString)data
{
_data = [CPData dataWithString:data];

if ([_loadDelegate respondsToSelector:@selector(cibDidFinishLoading:)])
[_loadDelegate cibDidFinishLoading:self];
}

- (void)connection:(CPURLConnection)aConnection didFailWithError:(CPError)anError
{
alert("cib: connection failed.");

_loadDelegate = nil;
}

- (void)connectionDidFinishLoading:(CPURLConnection)aConnection
{
_loadDelegate = nil;
}

@end

0 comments on commit dd41c31

Please sign in to comment.