Skip to content

Commit

Permalink
A number of CPTableView improvements, still not built by default.
Browse files Browse the repository at this point in the history
Reviewed by me.
  • Loading branch information
Francisco Ryan Tolmasky I committed Jan 4, 2009
1 parent 0af5bb0 commit ac8ecdb
Show file tree
Hide file tree
Showing 2 changed files with 415 additions and 97 deletions.
133 changes: 125 additions & 8 deletions AppKit/CPTableColumn.j
Expand Up @@ -43,6 +43,10 @@ CPTableColumnAutoresizingMask = 1;
*/
CPTableColumnUserResizingMask = 2;

#define PurgableInfoMake(aView, aRow) { view:(aView), row:(aRow) }
#define PurgableInfoView(anInfo) ((anInfo).view)
#define PurgableInfoRow(anInfo) ((anInfo).row)

/*! @class CPTableColumn
An CPTableColumn object mainly keeps information about the width of the column, its minimum and maximum width; whether the column can be edited or resized; and the cells used to draw the column header and the data in the column. You can change all these attributes of the column by calling the appropriate methods. Please note that the table column does not hold nor has access to the data to be displayed in the column; this data is maintained in the table view's data source.</p>
Expand All @@ -54,6 +58,7 @@ CPTableColumnUserResizingMask = 2;
@implementation CPTableColumn : CPObject
{
CPString _identifier;
CPView _headerView;

CPTableView _tableView;

Expand All @@ -62,6 +67,12 @@ CPTableColumnUserResizingMask = 2;
float _maxWidth;

unsigned _resizingMask;

CPView _dataView;

Object _dataViewData;
Object _dataViewForView;
Object _purgableInfosForDataView;
}

/*!
Expand All @@ -81,8 +92,14 @@ CPTableColumnUserResizingMask = 2;
_minWidth = 8.0;
_maxWidth = 1000.0;

// FIXME
_dataCell = [[CPTextField alloc] initWithFrame:CPRectMakeZero()];
_dataViewData = {};
_dataViewForView = {};
_purgableInfosForDataView = {};

[self setDataView:[[CPTextField alloc] initWithFrame:CPRectMakeZero()]];

_headerView = [[CPTextField alloc] initWithFrame:CPRectMakeZero()];
[_headerView setBackgroundColor:[CPColor greenColor]];
}

return self;
Expand Down Expand Up @@ -229,13 +246,16 @@ CPTableColumnUserResizingMask;
return _isEditable;
}

//Setting the column header view

/*!
Sets the view that draws the column's header.
@param aHeaderView the view that will draws the column header
*/
- (void)setHeaderView:(CPView)aHeaderView

- (void)setHeaderView:(CPView)aView
{
_headerView = aHeaderView;
_headerView = aView;
}

/*!
Expand All @@ -249,17 +269,37 @@ CPTableColumnUserResizingMask;
/*!
Sets the data cell that draws rows in this column.
*/
- (void)setDataCell:(CPCell)aDataCell
- (void)setDataCell:(CPView <CPCoding>)aView
{
[self setDataView:aView];
}

/*
Sets the data view that draws rows in this column.
*/
- (void)setDataView:(CPView <CPCoding>)aView
{
_dataCell = aDataCell;
if (_dataView)
_dataViewData[[_dataView hash]] = nil;

_dataView = aView;
_dataViewData[[aView hash]] = [CPKeyedArchiver archivedDataWithRootObject:aView];
}

/*!
Returns the data cell that draws rows in this column
*/
- (CPCell)dataCell
{
return _dataCell;
return _dataView;
}

/*
Returns the data view that draws rows in this column
*/
- (CPView)dataView
{
return [self dataCell];
}

/*!
Expand All @@ -270,7 +310,84 @@ CPTableColumnUserResizingMask;
*/
- (CPCell)dataCellForRow:(int)aRowIndex
{
return [self dataCell];
return [self dataView];
}

- (CPView)dataViewForRow:(int)aRowIndex
{
return [self dataCellForRow:aRowIndex];
}

- (void)_markViewAsPurgable:(CPView)aView
{
var viewHash = [aView hash],
dataViewHash = [_dataViewForView[viewHash] hash];

if (!_purgableInfosForDataView[dataViewHash])
_purgableInfosForDataView[dataViewHash] = [CPDictionary dictionary];

[_purgableInfosForDataView[dataViewHash] setObject:aView forKey:viewHash];
}

- (void)_markView:(CPView)aView inRow:(unsigned)aRow asPurgable:(BOOL)isPurgable
{
var viewHash = [aView hash],
dataViewHash = [_dataViewForView[viewHash] hash];

if (!_purgableInfosForDataView[dataViewHash])
{
if (!isPurgable)
return;

_purgableInfosForDataView[dataViewHash] = [CPDictionary dictionary];
}

if (!isPurgable)
[_purgableInfosForDataView[dataViewHash] removeObjectForKey:viewHash];
else
[_purgableInfosForDataView[dataViewHash] setObject:PurgableInfoMake(aView, aRow) forKey:viewHash];
}

- (CPView)_newDataViewForRow:(int)aRowIndex avoidingRows:(CPRange)rows
{
var view = [self dataViewForRow:aRowIndex],
viewHash = [view hash],
dataViewHash = [_dataViewForView[viewHash] hash],
purgableInfos = _purgableInfosForDataView[dataViewHash];
//console.warn("ok, a cell is needed");
if (purgableInfos && [purgableInfos count])
{//console.warn("yes, inside");
var keys = [purgableInfos allKeys],
count = keys.length;

while (count--)
{
var key = keys[count],
info = [purgableInfos objectForKey:key];

[purgableInfos removeObjectForKey:key];

if (CPLocationInRange(PurgableInfoRow(info), rows))
continue;
//console.warn("yes, a purged view is usable, its called" + PurgableInfoView(info));
return PurgableInfoView(info);
}
}

var data = _dataViewData[viewHash];

if (!data)
{
_dataViewData[viewHash] = [CPKeyedArchiver archivedDataWithRootObject:view];
data = _dataViewData[viewHash];
}
//console.warn("nope, time for creation");
return [CPKeyedUnarchiver unarchiveObjectWithData:data];
}

@end

_PurgableViewInfoMake = function(aView, aRow)
{
return { view:aView, row:aRow};
}

0 comments on commit ac8ecdb

Please sign in to comment.