Merge branch 'master' of git://github.com/280north/cappuccino

This commit is contained in:
stevegeek
2009-09-23 23:20:19 +01:00
8 changed files with 290 additions and 40 deletions
+1
View File
@@ -25,6 +25,7 @@
@import "CPAnimation.j"
@import "CPApplication.j"
@import "CPBezierPath.j"
@import "CPBox.j"
@import "CPButton.j"
@import "CPButtonBar.j"
@import "CPCheckBox.j"
+1 -1
View File
@@ -218,7 +218,7 @@ ACTUAL_FRAME_RATE = 0;
- (void)startAnimation
{
// If we're already animating, or our delegate stops us, animate.
if (_timer || _delegate && [_delegate respondsToSelector:@selector(animationShouldStart)] && ![_delegate animationShouldStart:self])
if (_timer || _delegate && [_delegate respondsToSelector:@selector(animationShouldStart:)] && ![_delegate animationShouldStart:self])
return;
if (_progress === 1.0)
+242
View File
@@ -0,0 +1,242 @@
/*
* CPBox.j
* AppKit
*
* Created by Ross Boucher.
* Copyright 2009, 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 "CPView.j"
// CPBorderType
CPNoBorder = 0;
CPLineBorder = 1;
CPBezelBorder = 2;
CPGrooveBorder = 3;
@implementation CPBox : CPView
{
CPBorderType _borderType;
CPColor _borderColor;
CPColor _fillColor;
float _cornerRadius;
float _borderWidth;
CPSize _contentMargin;
CPView _contentView;
}
+ (id)boxEnclosingView:(CPView)aView
{
var box = [[self alloc] initWithFrame:CGRectMakeZero()],
enclosingView = [aView superview];
[box setFrameFromContentFrame:[aView frame]];
[enclosingView replaceSubview:aView with:box];
[box setContentView:aView];
return box;
}
- (id)initWithFrame:(CPRect)frameRect
{
if (self = [super initWithFrame:frameRect])
{
_fillColor = [CPColor clearColor];
_borderColor = [CPColor blackColor];
_borderWidth = 1.0;
_contentMargin = CGSizeMake(0.0, 0.0);
_contentView = [[CPView alloc] initWithFrame:[self bounds]];
[self addSubview:_contentView];
}
return self;
}
// Configuring Boxes
- (CPRect)borderRect
{
return [self bounds];
}
- (CPBorderType)borderType
{
return _borderType;
}
- (void)setBorderType:(CPBorderType)value
{
_borderType = value;
[self setNeedsDisplay:YES];
}
- (CPColor)borderColor
{
return _borderColor;
}
- (void)setBorderColor:(CPColor)color
{
if ([color isEqual:_borderColor])
return;
_borderColor = color;
[self setNeedsDisplay:YES];
}
- (float)borderWidth
{
return _borderWidth;
}
- (void)setBorderWidth:(float)width
{
if (width === _borderWidth)
return;
_borderWidth = width;
[self setNeedsDisplay:YES];
}
- (float)cornerRadius
{
return _cornerRadius;
}
- (void)setCornerRadius:(float)radius
{
if (radius === _cornerRadius)
return;
_cornerRadius = radius;
[self setNeedsDisplay:YES];
}
- (CPColor)fillColor
{
return _fillColor;
}
- (void)setFillColor:(CPColor)color
{
if ([color isEqual:_fillColor])
return;
_fillColor = color;
[self setNeedsDisplay:YES];
}
- (CPView)contentView
{
return _contentView;
}
- (void)setContentView:(CPView)aView
{
if (aView === _contentView)
return;
[aView setFrame:CGRectInset([self bounds], _contentMargin.width + _borderWidth, _contentMargin.height + _borderWidth)];
[self replaceSubview:_contentView with:aView];
_contentView = aView;
}
- (CPSize)contentViewMargins
{
return _contentMargin;
}
- (void)setContentViewMargins:(CPSize)size
{
if(size.width < 0 || size.height < 0)
[CPException raise:CPGenericException reason:@"Margins must be positive"];
_contentMargin = CGSizeMakeCopy(size);
[self setNeedsDisplay:YES];
}
- (void)setFrameFromContentFrame:(CPRect)aRect
{
[self setFrame:CGRectInset(aRect, -(_contentMargin.width + _borderWidth), -(_contentMargin.height + _borderWidth))];
[self setNeedsDisplay:YES];
}
- (void)sizeToFit
{
var contentFrame = [_contentView frame];
[self setFrameSize:CGSizeMake(contentFrame.size.width + _contentMargin.width * 2,
contentFrame.size.height + _contentMargin.height * 2)];
[_contentView setFrameOrigin:CGPointMake(_contentMargin.width, _contentMargin.height)];
}
- (void)drawRect:(CPRect)rect
{
var bounds = [self bounds],
aContext = [[CPGraphicsContext currentContext] graphicsPort],
border2 = _borderWidth/2,
strokeRect = CGRectMake(bounds.origin.x + border2,
bounds.origin.y + border2,
bounds.size.width - _borderWidth,
bounds.size.height - _borderWidth),
fillRect = CGRectMake(bounds.origin.x + border2,
bounds.origin.y + border2,
bounds.size.width - _borderWidth,
bounds.size.height - _borderWidth);
CGContextSetFillColor(aContext, [self fillColor]);
CGContextSetStrokeColor(aContext, [self borderColor]);
CGContextSetLineWidth(aContext, _borderWidth);
switch(_borderType)
{
case CPLineBorder: CGContextFillRoundedRectangleInRect(aContext, fillRect, _cornerRadius, YES, YES, YES, YES);
CGContextStrokeRoundedRectangleInRect(aContext, strokeRect, _cornerRadius, YES, YES, YES, YES);
break;
case CPBezelBorder: CGContextFillRoundedRectangleInRect(aContext, fillRect, _cornerRadius, YES, YES, YES, YES);
CGContextSetStrokeColor(aContext, [CPColor colorWithWhite:190.0/255.0 alpha:1.0]);
CGContextBeginPath(aContext);
CGContextMoveToPoint(aContext, strokeRect.origin.x, strokeRect.origin.y);
CGContextAddLineToPoint(aContext, CGRectGetMinX(strokeRect), CGRectGetMaxY(strokeRect)),
CGContextAddLineToPoint(aContext, CGRectGetMaxX(strokeRect), CGRectGetMaxY(strokeRect)),
CGContextAddLineToPoint(aContext, CGRectGetMaxX(strokeRect), CGRectGetMinY(strokeRect)),
CGContextStrokePath(aContext);
CGContextSetStrokeColor(aContext, [CPColor colorWithWhite:142.0/255.0 alpha:1.0]);
CGContextBeginPath(aContext);
CGContextMoveToPoint(aContext, bounds.origin.x, strokeRect.origin.y);
CGContextAddLineToPoint(aContext, CGRectGetMaxX(bounds), CGRectGetMinY(strokeRect));
CGContextStrokePath(aContext);
break;
default: break;
}
}
@end
+1 -1
+2 -1
View File
@@ -37,7 +37,8 @@ with (window)
"OBJJ_PREPROCESSOR_DEBUG_SYMBOLS",
"objj_data",
"CPPropertyListCreateData", "CPPropertyListCreateFromData",
"kCFPropertyListXMLFormat_v1_0", "kCFPropertyList280NorthFormat_v1_0"
"kCFPropertyListXMLFormat_v1_0", "kCFPropertyList280NorthFormat_v1_0",
"objj_dictionary"
].forEach(function(v) {
exports[v] = eval(v);
});
+42 -36
View File
@@ -1,6 +1,14 @@
var file = require("file"),
os = require("os")
objj = require("./objj");
var FILE = require("file"),
OS = require("os"),
objj = require("./objj"),
objj_preprocess = objj.objj_preprocess,
IS_FILE = objj.IS_FILE,
GET_CODE = objj.GET_CODE,
IS_LOCAL = objj.IS_LOCAL,
MARKER_IMPORT_STD = objj.MARKER_IMPORT_STD,
MARKER_IMPORT_LOCAL = objj.MARKER_IMPORT_LOCAL,
MARKER_CODE = objj.MARKER_CODE,
GET_PATH = objj.GET_PATH;
require("objj/regexp-rhino-patch");
@@ -10,21 +18,24 @@ var OBJJ_PREPROCESSOR_PREPROCESS = exports.OBJJ_PREPROCESSOR_PREPROCESS
var OBJJ_PREPROCESSOR_COMPRESS = exports.OBJJ_PREPROCESSOR_COMPRESS = 1 << 11;
var OBJJ_PREPROCESSOR_SYNTAX = exports.OBJJ_PREPROCESSOR_SYNTAX = 1 << 12;
var SHRINKSAFE_PATH = file.join(objj.OBJJ_HOME, "shrinksafe", "shrinksafe.jar"),
RHINO_PATH = file.join(objj.OBJJ_HOME, "shrinksafe", "js.jar")
var SHRINKSAFE_PATH = FILE.join(objj.OBJJ_HOME, "shrinksafe", "shrinksafe.jar"),
RHINO_PATH = FILE.join(objj.OBJJ_HOME, "shrinksafe", "js.jar")
function compress(/*String*/ aCode, /*Object*/ flags, /*String*/ tmpFile)
function compress(/*String*/ aCode, /*String*/ FIXME)
{
file.write(tmpFile, aCode, { charset:"UTF-8" });
// FIXME: figure out why this doesn't work on Windows/Cygwin
//var tmpFile = java.io.File.createTempFile("OBJJC", "");
var tmpFile = new java.io.File(FIXME + ".tmp");
tmpFile.deleteOnExit();
tmpFile = tmpFile.getAbsolutePath();
return os.command(["java", "-Dfile.encoding=UTF-8", "-classpath", [RHINO_PATH, SHRINKSAFE_PATH].join(":"), "org.dojotoolkit.shrinksafe.Main", tmpFile]);
FILE.write(tmpFile, aCode, { charset:"UTF-8" });
return OS.command(["java", "-Dfile.encoding=UTF-8", "-classpath", [RHINO_PATH, SHRINKSAFE_PATH].join(":"), "org.dojotoolkit.shrinksafe.Main", tmpFile]);
}
exports.preprocess = function(inFile, outFile, flags, gccArgs)
{
with(objj)
{
print("Statically Preprocessing " + inFile);
if (flags === undefined)
@@ -33,31 +44,28 @@ exports.preprocess = function(inFile, outFile, flags, gccArgs)
var shouldObjjPreprocess = flags & OBJJ_PREPROCESSOR_PREPROCESS,
shouldCheckSyntax = flags & OBJJ_PREPROCESSOR_SYNTAX,
shouldCompress = flags & OBJJ_PREPROCESSOR_COMPRESS;
// FIXME: figure out why this doesn't work on Windows/Cygwin
//var tmpFile = java.io.File.createTempFile("OBJJC", "");
var tmpFile = new java.io.File(outFile + ".tmp");
tmpFile.deleteOnExit();
tmpFile = tmpFile.getAbsolutePath();
// -E JUST preprocess.
// -x c Interpret language as C -- closest thing to JavaScript.
// -P Don't generate #line directives
var gccComponents = ["gcc"]
.concat("-E", "-x", "c", "-P", inFile)
.concat(gccArgs || [])
.concat("-o", shouldObjjPreprocess ? tmpFile : outFile);
os.system(gccComponents);
gccArgs = gccArgs ? gccArgs.join(" ") : "";
var gccCommand = "gcc -E -x c -P " + gccArgs + " " + inFile;
if (!shouldObjjPreprocess)
{
OS.system(gccCommand + " -o" + outFile);
return;
}
var gcc = OS.popen(gccCommand);
// Read file and preprocess it.
var fileContents = file.read(tmpFile, { charset: "UTF-8" });
var fileContents = "",
chunk = "";
while (chunk = gcc.stdout.read())
fileContents += chunk;
// Preprocess contents into fragments.
var fragments = objj_preprocess(fileContents, { path : "/x" }, { path: file.basename(inFile) }, flags),
var fragments = objj_preprocess(fileContents, { path : "/x" }, { path: FILE.basename(inFile) }, flags),
preprocessed = "";
// Writer preprocessed fragments out.
@@ -86,13 +94,13 @@ exports.preprocess = function(inFile, outFile, flags, gccArgs)
" on preprocessed line number "+e.lineNumber+"\n"+
"\t"+lines.slice(Math.max(0, e.lineNumber - 1 - PAD), e.lineNumber+PAD).join("\n\t"));
os.exit(1);
OS.exit(1);
}
}
if (shouldCompress)
{
code = compress("function(){" + code + '}', 0, tmpFile);
code = compress("function(){" + code + '}', outFile);
code = code.substr("function(){".length, code.length - "function(){};\n\n".length);
}
@@ -100,11 +108,9 @@ exports.preprocess = function(inFile, outFile, flags, gccArgs)
preprocessed += MARKER_CODE + ';' + code.length + ';' + code;
}
}
// Write file.
file.write(outFile, preprocessed, { charset: "UTF-8" });
}
FILE.write(outFile, preprocessed, { charset: "UTF-8" });
}
exports.main = function(args)