Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/280north/cappuccino
Browse files Browse the repository at this point in the history
  • Loading branch information
vijaykiran committed Sep 23, 2008
2 parents 2830fee + 9d5e772 commit 1c0a450
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 75 deletions.
145 changes: 93 additions & 52 deletions AppKit/CPSplitView.j
Expand Up @@ -49,21 +49,22 @@ var CPSplitViewHorizontalImage = nil,
CPArray _DOMDividerElements;
CPString _dividerImagePath;
int _drawingDivider;

BOOL _needsResizeSubviews;
}

/*
@ignore
*/
//+ (void)initialize
//{
// if (self != [CPSplitView class])
// return;
//
// var bundle = [CPBundle bundleForClass:self];
//
// CPSplitViewHorizontalImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPSplitView/CPSplitViewHorizontal.png"] size:CPSizeMake(5.0, 10.0)];
// CPSplitViewVerticalImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPSplitView/CPSplitViewVertical.png"] size:CPSizeMake(10.0, 5.0)];
//}
+ (void)initialize
{
if (self != [CPSplitView class])
return;

var bundle = [CPBundle bundleForClass:self];
CPSplitViewHorizontalImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPSplitView/CPSplitViewHorizontal.png"] size:CPSizeMake(5.0, 10.0)];
CPSplitViewVerticalImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPSplitView/CPSplitViewVertical.png"] size:CPSizeMake(10.0, 5.0)];
}

- (id)initWithFrame:(CGRect)aFrame
{
Expand All @@ -89,20 +90,45 @@ var CPSplitViewHorizontalImage = nil,
return _isVertical;
}

- (void)setVertical:(BOOL)flag
- (void)setVertical:(BOOL)shouldBeVertical
{
[self _setVertical:flag];
if (![self _setVertical:shouldBeVertical])
return;

// Just re-adjust evenly.
var frame = [self frame],
dividerThickness = [self dividerThickness];

[self _postNotificationWillResize];

var eachSize = ROUND((frame.size[_sizeComponent] - dividerThickness * (_subviews.length - 1)) / _subviews.length),
index = 0,
count = _subviews.length;

if ([self isVertical])
for (; index < count; ++index)
[_subviews[index] setFrame:CGRectMake(ROUND((eachSize + dividerThickness) * index), 0, eachSize, frame.size.height)];
else
for (; index < count; ++index)
[_subviews[index] setFrame:CGRectMake(0, ROUND((eachSize + dividerThickness) * index), frame.size.width, eachSize)];

[self adjustSubviews];
[self setNeedsDisplay:YES];

[self _postNotificationDidResize];

}

- (void)_setVertical:(BOOL)flag
- (BOOL)_setVertical:(BOOL)shouldBeVertical
{
_isVertical = flag;
var changed = (_isVertical != shouldBeVertical);

_isVertical = shouldBeVertical;

_originComponent = [self isVertical] ? "x" : "y";
_sizeComponent = [self isVertical] ? "width" : "height";
_dividerImagePath = [self isVertical] ? [CPSplitViewVerticalImage filename] : [CPSplitViewHorizontalImage filename];

_originComponent = [self isVertical] ? "x" : "y";
_sizeComponent = [self isVertical] ? "width" : "height";
_dividerImagePath = [self isVertical] ? [CPSplitViewVerticalImage filename] : [CPSplitViewHorizontalImage filename];
return changed;
}

- (BOOL)isPaneSplitter
Expand All @@ -124,32 +150,10 @@ var CPSplitViewHorizontalImage = nil,
[self setNeedsDisplay:YES];
}

- (void)didAddSubview:(CPView)subview
{
[self adjustSubviews];
}

- (void)adjustSubviews
- (void)didAddSubview:(CPView)aSubview
{
var frame = [self frame],
dividerThickness = [self dividerThickness];

[self _postNotificationWillResize];

var eachSize = ROUND((frame.size[_sizeComponent] - dividerThickness * (_subviews.length - 1)) / _subviews.length),
index = 0,
count = _subviews.length;

if ([self isVertical])
for (; index < count; ++index)
[_subviews[index] setFrame:CGRectMake(ROUND((eachSize + dividerThickness) * index), 0, eachSize, frame.size.height)];
else
for (; index < count; ++index)
[_subviews[index] setFrame:CGRectMake(0, ROUND((eachSize + dividerThickness) * index), frame.size.width, eachSize)];

[self setNeedsDisplay:YES];

[self _postNotificationDidResize];
_needsResizeSubviews = YES;
// [self adjustSubviews];
}

- (BOOL)isSubviewCollapsed:(CPView)subview
Expand Down Expand Up @@ -219,6 +223,39 @@ var CPSplitViewHorizontalImage = nil,
#endif
}

- (void)viewWillDraw
{
[self _adjustSubviewsWithCalculatedSize];
}

- (void)_adjustSubviewsWithCalculatedSize
{
if (!_needsResizeSubviews)
return;

_needsResizeSubviews = NO;

var subviews = [self subviews],
count = subviews.length,
oldSize = CGSizeMakeZero();

if ([self isVertical])
{
oldSize.width += [self dividerThickness] * (count - 1);
oldSize.height = CGRectGetHeight([self frame]);
}
else
{
oldSize.width = CGRectGetWidth([self frame]);
oldSize.height += [self dividerThickness] * (count - 1);
}

while (count--)
oldSize[_sizeComponent] += [subviews[count] frame].size[_sizeComponent];

[self resizeSubviewsWithOldSize:oldSize];
}

- (BOOL)cursorAtPoint:(CPPoint)aPoint hitDividerAtIndex:(int)anIndex
{
var frame = [_subviews[anIndex] frame],
Expand Down Expand Up @@ -354,6 +391,8 @@ var CPSplitViewHorizontalImage = nil,

- (void)setPosition:(float)position ofDividerAtIndex:(int)dividerIndex
{
[self _adjustSubviewsWithCalculatedSize];

// not sure where this should override other positions?
if ([_delegate respondsToSelector:@selector(splitView:constrainSplitPosition:ofSubviewAt:)])
position = [_delegate splitView:self constrainSplitPosition:position ofSubviewAt:dividerIndex];
Expand Down Expand Up @@ -387,13 +426,22 @@ var CPSplitViewHorizontalImage = nil,

frameB.size[_sizeComponent] = frameB.origin[_originComponent] + frameB.size[_sizeComponent] - realPosition - [self dividerThickness];
frameB.origin[_originComponent] = realPosition + [self dividerThickness];
[_subviews[dividerIndex+1] setFrame:frameB];
[_subviews[dividerIndex + 1] setFrame:frameB];

[self setNeedsDisplay:YES];
}

- (void)resizeSubviewsWithOldSize:(CPSize)oldSize
- (void)setFrameSize:(CGSize)aSize
{
[self _adjustSubviewsWithCalculatedSize];

[super setFrameSize:aSize];

[self setNeedsDisplay:YES];
}

- (void)resizeSubviewsWithOldSize:(CPSize)oldSize
{
if ([_delegate respondsToSelector:@selector(splitView:resizeSubviewsWithOldSize:)])
{
[_delegate splitView:self resizeSubviewsWithOldSize:oldSize];
Expand Down Expand Up @@ -422,8 +470,6 @@ var CPSplitViewHorizontalImage = nil,

[view setFrame:newFrame];
}

[self setNeedsDisplay:YES];

[self _postNotificationDidResize];
}
Expand Down Expand Up @@ -505,8 +551,3 @@ var CPSplitViewDelegateKey = "CPSplitViewDelegateKey",
}

@end

// FIXME: once +initialize is fixed for superclasses, remove this and uncomment +initialize
var bundle = [CPBundle bundleForClass:CPSplitView];
CPSplitViewHorizontalImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPSplitView/CPSplitViewHorizontal.png"] size:CPSizeMake(5.0, 10.0)];
CPSplitViewVerticalImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPSplitView/CPSplitViewVertical.png"] size:CPSizeMake(10.0, 5.0)];
22 changes: 16 additions & 6 deletions AppKit/CPView.j
Expand Up @@ -173,11 +173,6 @@ var DOMElementPrototype = nil,
*/
+ (void)initialize
{
#if PLATFORM(DOM)
if ([self instanceMethodForSelector:@selector(drawRect:)] != [CPView instanceMethodForSelector:@selector(drawRect:)])
CustomDrawRectViews[[self hash]] = YES;
#endif

if (self != [CPView class])
return;

Expand Down Expand Up @@ -1380,7 +1375,16 @@ setBoundsOrigin:
- (void)setNeedsDisplayInRect:(CPRect)aRect
{
#if PLATFORM(DOM)
if (!CustomDrawRectViews[[[self class] hash]])
var hash = [[self class] hash],
hasCustomDrawRect = CustomDrawRectViews[hash];

if (!hasCustomDrawRect && typeof hasCustomDrawRect === "undefined")
{
hasCustomDrawRect = [self methodForSelector:@selector(drawRect:)] != [CPView instanceMethodForSelector:@selector(drawRect:)];
CustomDrawRectViews[hash] = hasCustomDrawRect;
}

if (!hasCustomDrawRect)
return;
#endif

Expand Down Expand Up @@ -1431,6 +1435,8 @@ setBoundsOrigin:
*/
- (void)displayRect:(CPRect)aRect
{
[self viewWillDraw];

[self displayRectIgnoringOpacity:aRect inContext:nil];

_dirtyRect = NULL;
Expand All @@ -1446,6 +1452,10 @@ setBoundsOrigin:
[self unlockFocus];
}

- (void)viewWillDraw
{
}

/*
Locks focus on the receiver, so drawing commands apply to it.
*/
Expand Down
2 changes: 1 addition & 1 deletion AppKit/Cib/CPCib.j
Expand Up @@ -24,8 +24,8 @@ import <Foundation/CPObject.j>
import <Foundation/CPURLConnection.j>
import <Foundation/CPURLRequest.j>

import "CPCustomView.j"
import "_CPCibCustomObject.j"
import "_CPCibCustomView.j"
import "_CPCibKeyedUnarchiver.j"
import "_CPCibObjectData.j"
import "_CPCibWindowTemplate.j"
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion Objective-J/plist.js
Expand Up @@ -340,7 +340,7 @@ function CPPropertyListCreateFromXMLData(XMLNodeOrData)
if (XMLNode.string)
{
#if RHINO
XMLNode = DOCUMENT_ELEMENT(Packages.javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(
XMLNode = DOCUMENT_ELEMENT(_documentBuilder.parse(
new Packages.org.xml.sax.InputSource(new Packages.java.io.StringReader(XMLNode.string))));
#else
if (window.ActiveXObject)
Expand Down
43 changes: 29 additions & 14 deletions Tools/Utilities/bridge.js
Expand Up @@ -107,24 +107,23 @@ if (typeof readFile == "undefined") {
var f = new Packages.java.io.File(path);

if (!f.canRead()) {
//alert("can't read: " + f.path)
alert("can't read: " + f.path)
return "";
}

//alert("reading: " + f.getAbsolutePath());
alert("reading: " + f.getAbsolutePath());

var fis = new Packages.java.io.FileInputStream(f);

var b = Packages.java.lang.reflect.Array.newInstance(Packages.java.lang.Byte.TYPE, fis.available());
fis.read(b);

fis.close();

//return String(new Packages.java.lang.String(b));

if (characterCoding)
return new Packages.java.lang.String(b, characterCoding);
return String(new Packages.java.lang.String(b, characterCoding));
else
return new Packages.java.lang.String(b);
return String(new Packages.java.lang.String(b));
}
}
else {
Expand Down Expand Up @@ -283,9 +282,25 @@ if (typeof Packages != "undefined") {
}
};

var xhr_builder = Packages.javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder();
xhr_builder.setErrorHandler(function(exception, methodName) {
//print("xml error!");
var _documentBuilderFactory = Packages.javax.xml.parsers.DocumentBuilderFactory.newInstance();
// setValidating to false doesn't seem to prevent it from downloading the DTD, but lets do it anyway
_documentBuilderFactory.setValidating(false);

_documentBuilder = _documentBuilderFactory.newDocumentBuilder();
// prevent the Java XML parser from downloading the plist DTD from Apple every time we parse a plist
_documentBuilder.setEntityResolver(new Packages.org.xml.sax.EntityResolver({
resolveEntity: function(publicId, systemId) {
//Packages.java.lang.System.out.println("publicId=" + publicId + " systemId=" + systemId);

// TODO: return a local copy of the DTD?
if (String(systemId) == "http://www.apple.com/DTDs/PropertyList-1.0.dtd")
return new Packages.org.xml.sax.InputSource(new Packages.java.io.StringReader(""));

return null;
}
}));
// throw an exception on error
_documentBuilder.setErrorHandler(function(exception, methodName) {
throw exception;
});

Expand Down Expand Up @@ -372,7 +387,7 @@ if (typeof Packages != "undefined") {
}

parseXMLString = function(string) {
return (Packages.javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(
return (_documentBuilder.parse(
new Packages.org.xml.sax.InputSource(
new Packages.java.io.StringReader(string))).getDocumentElement());
}
Expand Down Expand Up @@ -435,23 +450,23 @@ XMLHttpRequest.prototype.send = function(body) {

try {
this.responseText = readFile(this.url);
alert("xhr: " + this.url);
alert("xhr response: " + this.url + " (length="+this.responseText.length+")");
} catch (e) {
alert("read exception: " + this.url);
alert("xhr exception: " + this.url);
this.responseText = "";
this.responseXML = null;
}

if (this.responseText.length > 0) {
try {
this.responseXML = xhr_builder.parse(new Packages.org.xml.sax.InputSource(new Packages.java.io.StringReader(this.responseText)));
this.responseXML = _documentBuilder.parse(new Packages.org.xml.sax.InputSource(new Packages.java.io.StringReader(this.responseText)));
} catch (e) {
this.responseXML = null;
}
this.status = 200;
}
else {
alert("empty file: " + this.url);
alert("xhr empty: " + this.url);
this.status = 404;
}

Expand Down
2 changes: 1 addition & 1 deletion Tools/nib2cib/NSCustomView.j
Expand Up @@ -20,7 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

import <AppKit/CPCustomView.j>
import <AppKit/_CPCibCustomView.j>

import "NSView.j"

Expand Down

0 comments on commit 1c0a450

Please sign in to comment.