Initial work on variable row heights. No drawing support at all yet.

This commit is contained in:
Randall Luecke committed 2010-11-18 01:22:51 -05:00
1 parent 80ec35fd0a
commit 55674e31ea
8 files changed
+516 -13

No files matched your search

+127 -13
View File
@@ -100,6 +100,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
#define NUMBER_OF_COLUMNS() (_tableColumns.length)
#define UPDATE_COLUMN_RANGES_IF_NECESSARY() if (_dirtyTableColumnRangeIndex !== CPNotFound) [self _recalculateTableColumnRanges];
@implementation _CPTableDrawView : CPView
{
CPTableView _tableView;
@@ -180,6 +181,8 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
unsigned _numberOfRows;
CPIndexSet _groupRows;
CPArray _cachedRowHeights;
// Persistence
CPString _autosaveName;
BOOL _autosaveTableColumns;
@@ -275,7 +278,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
_lastSelectedRow = -1;
_currentHighlightedTableColumn = nil;
_sortDescriptors = [CPArray array];
_sortDescriptors = [];
_draggedRowIndexes = [CPIndexSet indexSet];
_verticalMotionCanDrag = YES;
@@ -295,6 +298,15 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
// FIX ME: we have a lot of redundent init stuff in initWithFrame: and initWithCoder: we should move it all into here.
- (void)_init
{
HEIGHT_OF_TABLEVIEW = function()
{
if (!(_implementedDataSourceMethods & CPTableViewDelegate_tableView_heightOfRow_))
return (_rowHeight + _intercellSpacing.height) * _numberOfRows;
var heightObject = _cachedRowHeights[_cachedRowHeights.length];
return heightObject.heightAboveRow + heightObject.height + intercellSpacing.height;
}
_tableViewFlags = 0;
_selectedColumnIndexes = [CPIndexSet indexSet];
@@ -321,6 +333,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
_exposedRows = [CPIndexSet indexSet];
_exposedColumns = [CPIndexSet indexSet];
_cachedDataViews = { };
_cachedRowHeights = [];
_groupRows = [CPIndexSet indexSet];
@@ -430,6 +443,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
_reloadAllRows = YES;
_objectValues = { };
_cachedRowHeights = [];
// This updates the size too.
[self noteNumberOfRowsChanged];
@@ -1130,7 +1144,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
*/
- (int)numberOfRows
{
if (_numberOfRows)
if (_numberOfRows !== nil)
return _numberOfRows;
var contentBindingInfo = [self infoForBinding:@"content"];
@@ -1140,13 +1154,14 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
var destination = [contentBindingInfo objectForKey:CPObservedObjectKey],
keyPath = [contentBindingInfo objectForKey:CPObservedKeyPathKey];
return [[destination valueForKeyPath:keyPath] count];
_numberOfRows = [[destination valueForKeyPath:keyPath] count];
}
else if (_dataSource)
return [_dataSource numberOfRowsInTableView:self];
_numberOfRows = [_dataSource numberOfRowsInTableView:self];
else
_numberOfRows = 0;
return 0;
return _numberOfRows;
}
//Displaying Cell
@@ -1284,6 +1299,10 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
// Complexity:
// O(1)
/*!
Returns a CGRect with the location and size of the column
@param aColumnIndex the index of the column you want the rect of
*/
- (CGRect)rectOfColumn:(CPInteger)aColumnIndex
{
aColumnIndex = +aColumnIndex;
@@ -1297,14 +1316,30 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
var range = _tableColumnRanges[aColumnIndex];
return _CGRectMake(range.location, 0.0, range.length, CGRectGetHeight([self bounds]));
return _CGRectMake(range.location, 0.0, range.length, _CGRectGetHeight([self bounds]));
}
// Complexity:
// O(1)
/*!
Returns a CGRect with the location and size of the row
@param aRowIndex the index of the row you want the rect of
*/
- (CGRect)rectOfRow:(CPInteger)aRowIndex
{
var height = _rowHeight + _intercellSpacing.height;
if (_implementedDataSourceMethods & CPTableViewDelegate_tableView_heightOfRow_)
{
var y = _cachedRowHeights[aRowIndex].heightAboveRow,
height = _cachedRowHeights[aRowIndex].height;
}
else
{
var y = aRowIndex * (_rowHeight + _intercellSpacing.height),
height = _rowHeight;
}
return _CGRectMake(0.0, aRowIndex * height, _CGRectGetWidth([self bounds]), height);
return _CGRectMake(0.0, y, _CGRectGetWidth([self bounds]), height);
}
// Complexity:
@@ -1313,7 +1348,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
Returns a range of indices for the rows that lie wholly or partially within the vertical boundaries of a given rectangle.
@param aRect A rectangle in the coordinate system of the receiver.
*/
// FIX ME: Variable row heights
- (CPRange)rowsInRect:(CGRect)aRect
{
// If we have no rows, then we won't intersect anything.
@@ -1419,26 +1454,64 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
return CPNotFound;
}
//Complexity
// O(1) for static row height
// 0(lg Rows) for variable row heights
- (CPInteger)rowAtPoint:(CGPoint)aPoint
{
if (_implementedDataSourceMethods & CPTableViewDelegate_tableView_heightOfRow_)
{
// FIX ME: binary search plz
var currIndex = [self numberOfRows];//FLOOR([self numberOfRows] / 2);
while(currIndex--)
{
var upperBound = _cachedRowHeights[currIndex].heightAboveRow,
lowerBound = upperBound + _cachedRowHeights[currIndex].height;
if (aPoint.y > upperBound && aPoint.y < lowerBound)
return currIndex;
}
return CPNotFound;
}
var y = aPoint.y,
row = FLOOR(y / (_rowHeight + _intercellSpacing.height));
if (row >= _numberOfRows)
return -1;
return CPNotFound;
return row;
}
/*!
returns a rect for the dataview / cell at the column and row given
if the column or row index is greater than the number of columns or rows a CGZeroRect is returned
@param aColumn index of the column
@param aRow index of the row
*/
- (CGRect)frameOfDataViewAtColumn:(CPInteger)aColumn row:(CPInteger)aRow
{
UPDATE_COLUMN_RANGES_IF_NECESSARY();
if (aColumn > [self numberOfColumns] || aRow > [self numberOfRows])
return _CGRectMakeZero();
var tableColumnRange = _tableColumnRanges[aColumn],
rectOfRow = [self rectOfRow:aRow],
leftInset = FLOOR(_intercellSpacing.width / 2.0),
topInset = FLOOR(_intercellSpacing.height / 2.0);
// FIX ME: this could be cleaned up
if (_implementedDataSourceMethods & CPTableViewDelegate_tableView_heightOfRow_)
{
return _CGRectMake(tableColumnRange.location + leftInset,
_CGRectGetMinY(rectOfRow) + topInset,
tableColumnRange.length - _intercellSpacing.width,
_cachedRowHeights[aRow].height);
}
return _CGRectMake(tableColumnRange.location + leftInset,
_CGRectGetMinY(rectOfRow) + topInset,
tableColumnRange.length - _intercellSpacing.width,
@@ -1634,7 +1707,12 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
var oldNumberOfRows = _numberOfRows;
_numberOfRows = nil;
_numberOfRows = [self numberOfRows];
_cachedRowHeights = [];
// this line serves two purposes
// 1. it updates the _numberOfRows cache with the -numberOfRows call
// 2. it updates the row height cache if needed
[self noteHeightOfRowsWithIndexesChanged:[CPIndexSet indexSetWithIndexesInRange::CPMakeRange(0, [self numberOfRows])];
// remove row indexes from the selection if they no longer exist
var hangingSelections = oldNumberOfRows - _numberOfRows;
@@ -1648,13 +1726,49 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
[self tile];
}
/*!
Informs the receiver that the rows specified in indexSet have changed height.
@param anIndexSet an index set containing the indexes of the rows which changed height
*/
- (void)noteHeightOfRowsWithIndexesChanged:(CPIndexSet)anIndexSet
{
if (!(_implementedDataSourceMethods & CPTableViewDelegate_tableView_heightOfRow_)
return;
// this method will update the height of those rows, but since the cached array also contains
// the height above the row it needs to recalculate for the rows below it too
var i = [anIndexSet firstIndex],
count = _numberOfRows - i,
heightAbove = (i > 0) ? _cachedRowHeights[i - 1].height + _cachedRowHeights[i - 1].heightAboveRow + intercellSpacing.height : 0;
for (; i < count; i++)
{
// update the cache if the user told us to
if ([anIndexSet containsIndex:i])
var height = [_delegate tableView:self heightOfRow:indexesToUpdate];
if (_cachedRowHeight.length > i)
{
// since it exists, update it
_cachedRowHeight[i].height = height;
_cachedRowHeight[i].heightAboveRow = heightAbove;
}
else
_cachedRowHeights[i] = {"height":height, "heightAboveRow":heightAbove};
heightAbove += height + intercellSpacing.height;
}
}
- (void)tile
{
UPDATE_COLUMN_RANGES_IF_NECESSARY();
// FIXME: variable row heights.
var width = _tableColumnRanges.length > 0 ? CPMaxRange([_tableColumnRanges lastObject]) : 0.0,
height = (_rowHeight + _intercellSpacing.height) * _numberOfRows,
height = HEIGHT_OF_TABLEVIEW(),
superview = [self superview];
if ([superview isKindOfClass:[CPClipView class]])
@@ -0,0 +1,83 @@
/*
* AppController.j
* TestTemplate
*
* Created by You on August 10, 2010.
* Copyright 2010, Your Company All rights reserved.
*/
@import <Foundation/CPObject.j>
@implementation AppController : CPObject
{
CPTableView table;
CPTableColumn columnA;
CPTableColumn columnB;
CPTableColumn columnC;
CPTableColumn columnD;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
contentView = [theWindow contentView];
var scroll = [[CPScrollView alloc] initWithFrame:CGRectMake(100,100,700,400)];
table = [[CPTableView alloc] initWithFrame:CGRectMakeZero()];
[table setDataSource:self];
[table setUsesAlternatingRowBackgroundColors:YES];
[table setAlternatingRowBackgroundColors:[[CPColor redColor], [CPColor blueColor]]];
columnA = [[CPTableColumn alloc] initWithIdentifier:"A"];
[table addTableColumn:columnA];
[[columnA headerView] setStringValue:"A"];
[columnA setWidth:175];
columnB = [[CPTableColumn alloc] initWithIdentifier:"B"];
[table addTableColumn:columnB];
[[columnB headerView] setStringValue:"B"];
[columnB setWidth:175]
columnC = [[CPTableColumn alloc] initWithIdentifier:"C"];
[table addTableColumn:columnC];
[[columnC headerView] setStringValue:"C"];
[columnC setWidth:175];
columnD = [[CPTableColumn alloc] initWithIdentifier:"D"];
[table addTableColumn:columnD];
[[columnD headerView] setStringValue:"D"];
[columnD setWidth:175];
columnE = [[CPTableColumn alloc] initWithIdentifier:"E"];
[table addTableColumn:columnE];
[[columnE headerView] setStringValue:"E"];
[columnE setWidth:175];
[scroll setDocumentView:table];
[contentView addSubview:scroll];
[theWindow orderFront:self];
}
- (int)numberOfRowsInTableView:(id)tableView
{
return 10000;
}
- (id)tableView:(id)tableView objectValueForTableColumn:(CPTableColumn)aColumn row:(int)aRow
{
return "Column " + [aColumn identifier] + " Row " + aRow;
}
- (int)tableView:(CPTableView)aTableView heightOfRow:(int)aRow
{
console.log("heightOfRow:");
return 30;
}
@end
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CPApplicationDelegateClass</key>
<string>AppController</string>
<key>CPBundleName</key>
<string>VariableRows</string>
<key>CPPrincipalClass</key>
<string>CPApplication</string>
</dict>
</plist>
@@ -0,0 +1,93 @@
/*
* Jakefile
* VariableRows
*
* Created by You on November 17, 2010.
* Copyright 2010, Your Company All rights reserved.
*/
var ENV = require("system").env,
FILE = require("file"),
JAKE = require("jake"),
task = JAKE.task,
FileList = JAKE.FileList,
app = require("cappuccino/jake").app,
configuration = ENV["CONFIG"] || ENV["CONFIGURATION"] || ENV["c"] || "Debug",
OS = require("os");
app ("VariableRows", function(task)
{
task.setBuildIntermediatesPath(FILE.join("Build", "VariableRows.build", configuration));
task.setBuildPath(FILE.join("Build", configuration));
task.setProductName("VariableRows");
task.setIdentifier("com.yourcompany.VariableRows");
task.setVersion("1.0");
task.setAuthor("Your Company");
task.setEmail("feedback @nospam@ yourcompany.com");
task.setSummary("VariableRows");
task.setSources((new FileList("**/*.j")).exclude(FILE.join("Build", "**")));
task.setResources(new FileList("Resources/**"));
task.setIndexFilePath("index.html");
task.setInfoPlistPath("Info.plist");
if (configuration === "Debug")
task.setCompilerFlags("-DDEBUG -g");
else
task.setCompilerFlags("-O");
});
task ("default", ["VariableRows"], function()
{
printResults(configuration);
});
task ("build", ["default"]);
task ("debug", function()
{
ENV["CONFIGURATION"] = "Debug";
JAKE.subjake(["."], "build", ENV);
});
task ("release", function()
{
ENV["CONFIGURATION"] = "Release";
JAKE.subjake(["."], "build", ENV);
});
task ("run", ["debug"], function()
{
OS.system(["open", FILE.join("Build", "Debug", "VariableRows", "index.html")]);
});
task ("run-release", ["release"], function()
{
OS.system(["open", FILE.join("Build", "Release", "VariableRows", "index.html")]);
});
task ("deploy", ["release"], function()
{
FILE.mkdirs(FILE.join("Build", "Deployment", "VariableRows"));
OS.system(["press", "-f", FILE.join("Build", "Release", "VariableRows"), FILE.join("Build", "Deployment", "VariableRows")]);
printResults("Deployment")
});
task ("desktop", ["release"], function()
{
FILE.mkdirs(FILE.join("Build", "Desktop", "VariableRows"));
require("cappuccino/nativehost").buildNativeHost(FILE.join("Build", "Release", "VariableRows"), FILE.join("Build", "Desktop", "VariableRows", "VariableRows.app"));
printResults("Desktop")
});
task ("run-desktop", ["desktop"], function()
{
OS.system([FILE.join("Build", "Desktop", "VariableRows", "VariableRows.app", "Contents", "MacOS", "NativeHost"), "-i"]);
});
function printResults(configuration)
{
print("----------------------------");
print(configuration+" app built at path: "+FILE.join("Build", configuration, "VariableRows"));
print("----------------------------");
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

@@ -0,0 +1,104 @@
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!--
index-debug.html
VariableRows
Created by You on November 17, 2010.
Copyright 2010, Your Company All rights reserved.
-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta http-equiv="X-UA-Compatible" content="chrome=1" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<link rel="apple-touch-icon" href="Resources/icon.png" />
<link rel="apple-touch-startup-image" href="Resources/default.png" />
<title>VariableRows</title>
<script type="text/javascript">
OBJJ_MAIN_FILE = "main.j";
OBJJ_INCLUDE_PATHS = ["Frameworks/Debug", "Frameworks", "SomethingElse"];
</script>
<script src="Frameworks/Debug/Objective-J/Objective-J.js" type="text/javascript" charset="UTF-8"></script>
<script type="text/javascript">
objj_msgSend_reset();
// DEBUG OPTIONS:
// Uncomment to enable printing of backtraces on exceptions:
//objj_msgSend_decorate(objj_backtrace_decorator);
// Uncomment to supress exceptions that take place inside a message
//objj_msgSend_decorate(objj_supress_exceptions_decorator)
// Uncomment to enable runtime type checking:
//objj_msgSend_decorate(objj_typecheck_decorator);
// Uncomment (along with both above) to print backtraces on type check errors:
//objj_typecheck_prints_backtrace = true;
// Uncomment to disable the default logger (CPLogConsole if window.console exists, CPLogPopup otherwise):
//CPLogUnregister(CPLogDefault);
// Uncomment to enable a specific logger:
//CPLogRegister(CPLogConsole);
//CPLogRegister(CPLogPopup);
</script>
<style type="text/css">
body{margin:0; padding:0;}
#container {position: absolute; top:50%; left:50%;}
#content {width:800px; text-align:center; margin-left: -400px; height:50px; margin-top:-25px; line-height: 50px;}
#content {font-family: "Helvetica", "Arial", sans-serif; font-size: 18px; color: black; text-shadow: 0px 1px 0px white; }
#loadgraphic {margin-right: 0.2em; margin-bottom:-2px;}
</style>
<!--[if lt IE 7]>
<STYLE type="text/css">
#container { position: relative; top: 50%; }
#content { position: relative;}
</STYLE>
<![endif]-->
</head>
<body style="">
<div id="cappuccino-body">
<div id="loadingcontainer" style="background-color: #eeeeee; overflow:hidden; width:100%; height:100%; position: absolute; top: 0; left: 0;">
<script type="text/javascript">
document.write("<div id='container'><p id='content'>" +
"<img id='loadgraphic' width='16' height='16' src='Resources/spinner.gif' /> " +
"Loading VariableRows...</p></div>");
</script>
<noscript>
<div id="container">
<div style="width: 440px; padding: 10px 25px 20px 25px; font-family: sans-serif; background-color: #ffffff; position: relative; left: -245px; top: -120px; text-align: center; -moz-border-radius: 20px; -webkit-border-radius: 20px; color: #555555">
<p style="line-height: 1.4em;">JavaScript is required for this site to work correctly but is either disabled or not supported by your browser.</p>
<p style="font-size:120%; padding:10px;"><a href="http://cappuccino.org/noscript">Show me how to enable JavaScript</a></p>
<p style="font-size:80%;">You may want to upgrade to a newer browser while you're at it:</p>
<ul style="margin:0;padding:0; text-align: center; font-size:80%;" >
<li style="display: inline;"><a href="http://www.apple.com/safari/download/">Safari</a></li>
<li style="display: inline;"><a href="http://www.mozilla.com/en-US/firefox/">Firefox</a></li>
<li style="display: inline;"><a href="http://www.google.com/chrome/">Chrome</a></li>
<li style="display: inline;"><a href="http://www.opera.com/download/">Opera</a></li>
<li style="display: inline;"><a href="http://www.microsoft.com/windows/downloads/ie/getitnow.mspx">Internet Explorer</a></li>
</ul>
</div>
</div>
</noscript>
</div>
</div>
</body>
</html>
@@ -0,0 +1,79 @@
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!--
index.html
VariableRows
Created by You on November 17, 2010.
Copyright 2010, Your Company All rights reserved.
-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta http-equiv="X-UA-Compatible" content="chrome=1" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<link rel="apple-touch-icon" href="Resources/icon.png" />
<link rel="apple-touch-startup-image" href="Resources/default.png" />
<title>VariableRows</title>
<script type="text/javascript">
OBJJ_MAIN_FILE = "main.j";
</script>
<script type="text/javascript" src="Frameworks/Objective-J/Objective-J.js" charset="UTF-8"></script>
<style type="text/css">
body{margin:0; padding:0;}
#container {position: absolute; top:50%; left:50%;}
#content {width:800px; text-align:center; margin-left: -400px; height:50px; margin-top:-25px; line-height: 50px;}
#content {font-family: "Helvetica", "Arial", sans-serif; font-size: 18px; color: black; text-shadow: 0px 1px 0px white; }
#loadgraphic {margin-right: 0.2em; margin-bottom:-2px;}
</style>
<!--[if lt IE 7]>
<STYLE type="text/css">
#container { position: relative; top: 50%; }
#content { position: relative;}
</STYLE>
<![endif]-->
</head>
<body style="">
<div id="cappuccino-body">
<div id="loadingcontainer" style="background-color: #eeeeee; overflow:hidden; width:100%; height:100%; position: absolute; top: 0; left: 0;">
<script type="text/javascript">
document.write("<div id='container'><p id='content'>" +
"<img id='loadgraphic' width='16' height='16' src='Resources/spinner.gif' /> " +
"Loading VariableRows...</p></div>");
</script>
<noscript>
<div id="container">
<div style="width: 440px; padding: 10px 25px 20px 25px; font-family: sans-serif; background-color: #ffffff; position: relative; left: -245px; top: -120px; text-align: center; -moz-border-radius: 20px; -webkit-border-radius: 20px; color: #555555">
<p style="line-height: 1.4em;">JavaScript is required for this site to work correctly but is either disabled or not supported by your browser.</p>
<p style="font-size:120%; padding:10px;"><a href="http://cappuccino.org/noscript">Show me how to enable JavaScript</a></p>
<p style="font-size:80%;">You may want to upgrade to a newer browser while you're at it:</p>
<ul style="margin:0;padding:0; text-align: center; font-size:80%;" >
<li style="display: inline;"><a href="http://www.apple.com/safari/download/">Safari</a></li>
<li style="display: inline;"><a href="http://www.mozilla.com/en-US/firefox/">Firefox</a></li>
<li style="display: inline;"><a href="http://www.google.com/chrome/">Chrome</a></li>
<li style="display: inline;"><a href="http://www.opera.com/download/">Opera</a></li>
<li style="display: inline;"><a href="http://www.microsoft.com/windows/downloads/ie/getitnow.mspx">Internet Explorer</a></li>
</ul>
</div>
</div>
</noscript>
</div>
</div>
</body>
</html>
@@ -0,0 +1,18 @@
/*
* AppController.j
* VariableRows
*
* Created by You on November 17, 2010.
* Copyright 2010, Your Company All rights reserved.
*/
@import <Foundation/Foundation.j>
@import <AppKit/AppKit.j>
@import "AppController.j"
function main(args, namedArgs)
{
CPApplicationMain(args, namedArgs);
}