PageRenderTime 54ms CodeModel.GetById 17ms app.highlight 16ms RepoModel.GetById 2ms app.codeStats 0ms

/Frameworks/Debug/AppKit/rhino.platform/CPTableView.j

http://github.com/jfahrenkrug/MapKit-HelloWorld
Unknown | 821 lines | 820 code | 1 blank | 0 comment | 0 complexity | af342b2052b3b006a59b340467e4baeb MD5 | raw file
  1i;11;CPControl.ji;15;CPTableColumn.ji;9;CPColor.ji;13;CPTextField.jc;40301;
  2CPTableViewColumnDidMoveNotification = "CPTableViewColumnDidMoveNotification";
  3CPTableViewColumnDidResizeNotification = "CPTableViewColumnDidResizeNotification";
  4CPTableViewSelectionDidChangeNotification = "CPTableViewSelectionDidChangeNotification";
  5CPTableViewSelectionIsChangingNotification = "CPTableViewSelectionIsChangingNotification";
  6var _CPTableViewWillDisplayCellSelector = 1 << 0,
  7    _CPTableViewShouldSelectRowSelector = 1 << 1,
  8    _CPTableViewShouldSelectTableColumnSelector = 1 << 2,
  9    _CPTableViewSelectionShouldChangeSelector = 1 << 3,
 10    _CPTableViewShouldEditTableColumnSelector = 1 << 4,
 11    _CPTableViewSelectionIndexesForProposedSelectionSelector = 1 << 5,
 12    _CPTableViewHeightOfRowSelector = 1 << 6;
 13{var the_class = objj_allocateClassPair(CPControl, "CPTableView"),
 14meta_class = the_class.isa;class_addIvars(the_class, [new objj_ivar("_dataSource"), new objj_ivar("_delegate"), new objj_ivar("_tableColumns"), new objj_ivar("_selectedRowIndexes"), new objj_ivar("_rowHeight"), new objj_ivar("_intercellSpacing"), new objj_ivar("_allowsMultipleSelection"), new objj_ivar("_allowsEmptySelection"), new objj_ivar("_delegateSelectorsCache"), new objj_ivar("_numberOfRows"), new objj_ivar("_hasVariableHeightRows"), new objj_ivar("_columnHeight"), new objj_ivar("_rowHeights"), new objj_ivar("_rowMinYs"), new objj_ivar("_tableCells"), new objj_ivar("_tableColumnViews"), new objj_ivar("_dataViewCache"), new objj_ivar("_objectValueCache"), new objj_ivar("_visibleRows"), new objj_ivar("_visibleColumns"), new objj_ivar("_populatedRows"), new objj_ivar("_populatedColumns"), new objj_ivar("_previousSelectedRowIndexes"), new objj_ivar("_selectionStartRow"), new objj_ivar("_selectionModifier"), new objj_ivar("_currentlySelected"), new objj_ivar("_selectionViews"), new objj_ivar("_selectionViewsPool"), new objj_ivar("_scrollTimer")]);
 15objj_registerClassPair(the_class);
 16objj_addClassForBundle(the_class, objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
 17class_addMethods(the_class, [new objj_method(sel_getUid("initWithFrame:"), function $CPTableView__initWithFrame_(self, _cmd, aFrame)
 18{ with(self)
 19{
 20    self = objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPControl") }, "initWithFrame:", aFrame);
 21    if (self)
 22    {
 23        objj_msgSend(self, "_init");
 24    }
 25    return self;
 26}
 27}), new objj_method(sel_getUid("_init"), function $CPTableView___init(self, _cmd)
 28{ with(self)
 29{
 30    _tableColumns = [];
 31    _selectedRowIndexes = objj_msgSend(CPIndexSet, "indexSet");
 32    _rowHeight = 17.0;
 33    _intercellSpacing = CPSizeMake(3.0, 2.0);
 34    _allowsMultipleSelection = YES;
 35    _allowsEmptySelection = YES;
 36    _tableCells = [];
 37    _tableColumnViews = [];
 38    _dataViewCache = {};
 39    _objectValueCache = [];
 40    _visibleRows = CPMakeRange(0, 0);
 41    _visibleColumns = CPMakeRange(0, 0);
 42    _rowHeights = [];
 43    _rowMinYs = [];
 44}
 45}), new objj_method(sel_getUid("_columnHeight"), function $CPTableView___columnHeight(self, _cmd)
 46{ with(self)
 47{
 48    return _columnHeight;
 49}
 50}), new objj_method(sel_getUid("newCellForRow:column:avoidingRows:"), function $CPTableView__newCellForRow_column_avoidingRows_(self, _cmd, aRowIndex, aColumnIndex, rows)
 51{ with(self)
 52{
 53    var dataView = objj_msgSend(_tableColumns[aColumnIndex], "_newDataViewForRow:avoidingRows:", aRowIndex, rows);
 54    objj_msgSend(dataView, "setFrame:", CGRectMake(0.0, (_hasVariableHeightRows ? _rowMinYs[aRowIndex] : (aRowIndex * (_rowHeight + _intercellSpacing.height))), objj_msgSend(_tableColumns[aColumnIndex], "width"), (_hasVariableHeightRows ? _rowHeights[aRowIndex] : _rowHeight)));
 55    if (objj_msgSend(dataView, "respondsToSelector:", sel_getUid("highlight:")))
 56        objj_msgSend(dataView, "highlight:", objj_msgSend(_selectedRowIndexes, "containsIndex:", aRowIndex));
 57    if (!_objectValueCache[aColumnIndex])
 58        _objectValueCache[aColumnIndex] = [];
 59    if (_objectValueCache[aColumnIndex][aRowIndex] === undefined)
 60        _objectValueCache[aColumnIndex][aRowIndex] = objj_msgSend(_dataSource, "tableView:objectValueForTableColumn:row:", self, _tableColumns[aColumnIndex], aRowIndex);
 61    objj_msgSend(dataView, "setObjectValue:", _objectValueCache[aColumnIndex][aRowIndex]);
 62    return dataView;
 63}
 64}), new objj_method(sel_getUid("clearCells"), function $CPTableView__clearCells(self, _cmd)
 65{ with(self)
 66{
 67    var columnEnd = CPMaxRange(_visibleColumns),
 68        rowEnd = CPMaxRange(_visibleRows);
 69    for (var column = _visibleColumns.location; column < columnEnd; column++)
 70    {
 71        var tableColumn = _tableColumns[column],
 72            tableColumnCells = _tableCells[column];
 73        for (var row = _visibleRows.location; row < rowEnd; row++)
 74        {
 75            var cell = tableColumnCells[row];
 76            if (cell)
 77            {
 78                tableColumnCells[row] = nil;
 79                objj_msgSend(tableColumn, "_markView:inRow:asPurgable:", cell, row, YES);
 80            }
 81            else
 82            {
 83                CPLog.warn("Missing cell? " + row + "," + column);
 84            }
 85        }
 86    }
 87    _visibleColumns = CPMakeRange(0,0);
 88    _visibleRows = CPMakeRange(0,0);
 89}
 90}), new objj_method(sel_getUid("loadTableCellsInRect:"), function $CPTableView__loadTableCellsInRect_(self, _cmd, aRect)
 91{ with(self)
 92{
 93   if (!_dataSource)
 94        return;
 95    var rowStart = MAX(0, objj_msgSend(self, "_rowAtY:", CGRectGetMinY(aRect)) - 1),
 96        rowEnd = MIN(_numberOfRows, objj_msgSend(self, "_rowAtY:", CGRectGetMaxY(aRect)) + 1),
 97        visibleRows = CPMakeRange(rowStart, rowEnd - rowStart),
 98        columnStart = MAX(0, objj_msgSend(self, "_columnAtX:", CGRectGetMinX(aRect))),
 99        columnEnd = MIN(_tableColumns.length, objj_msgSend(self, "_columnAtX:", CGRectGetMaxX(aRect)) + 1),
100        visibleColumns = CPMakeRange(columnStart, columnEnd - columnStart);
101    if (CPEqualRanges(_visibleRows, visibleRows) && CPEqualRanges(_visibleColumns, visibleColumns))
102        return;
103    var unionVisibleRows = CPUnionRange(_visibleRows, visibleRows),
104        unionVisibleColumns = CPUnionRange(_visibleColumns, visibleColumns);
105    if (unionVisibleRows.length * unionVisibleColumns.length <=
106        (_visibleRows.length * _visibleColumns.length) + (visibleRows.length * visibleColumns.length))
107    {
108        var cEnd = CPMaxRange(unionVisibleColumns),
109            rEnd = CPMaxRange(unionVisibleRows),
110            cell;
111        for (var column = unionVisibleColumns.location; column < cEnd; ++column)
112        {
113            var tableColumn = _tableColumns[column],
114                tableColumnCells = _tableCells[column],
115                columnIsVisible = CPLocationInRange(column, visibleColumns),
116                newCells = [];
117            for (var row = unionVisibleRows.location; row < rEnd; ++row)
118            {
119                if (cell = tableColumnCells[row])
120                {
121                    if (!columnIsVisible || !CPLocationInRange(row, visibleRows))
122                    {
123                        tableColumnCells[row] = nil;
124                        objj_msgSend(tableColumn, "_markView:inRow:asPurgable:", cell, row, YES);
125                    }
126                }
127                else
128                {
129                    newCells.push(row);
130                }
131            }
132            while (newCells.length > 0)
133            {
134                var row = newCells.pop();
135                tableColumnCells[row] = objj_msgSend(self, "newCellForRow:column:avoidingRows:", row, column, visibleRows);
136                if (!tableColumnCells[row]._superview)
137                    objj_msgSend(_tableColumnViews[column], "addSubview:", tableColumnCells[row]);
138                else if (tableColumnCells[row]._isHidden)
139                    objj_msgSend(tableColumnCells[row], "setHidden:", NO);
140            }
141            objj_msgSend(tableColumn, "_purge");
142        }
143    }
144    else {
145        var cEnd = CPMaxRange(_visibleColumns),
146            rEnd = CPMaxRange(_visibleRows),
147            cell;
148        for (var column = _visibleColumns.location; column < cEnd; ++column)
149        {
150            var tableColumn = _tableColumns[column],
151                tableColumnCells = _tableCells[column],
152                columnIsVisible = CPLocationInRange(column, visibleColumns);
153            for (var row = _visibleRows.location; row < rEnd; ++row)
154            {
155                if (cell = tableColumnCells[row])
156                {
157                    if (!columnIsVisible || !CPLocationInRange(row, visibleRows))
158                    {
159                        tableColumnCells[row] = nil;
160                        objj_msgSend(tableColumn, "_markView:inRow:asPurgable:", cell, row, YES);
161                    }
162                }
163            }
164        }
165        var cEnd = CPMaxRange(visibleColumns),
166            rEnd = CPMaxRange(visibleRows);
167        for (var column = visibleColumns.location; column < cEnd; ++column)
168        {
169            var tableColumn = _tableColumns[column],
170                tableColumnCells = _tableCells[column];
171            for (var row = visibleRows.location; row < rEnd; ++row)
172            {
173                tableColumnCells[row] = objj_msgSend(self, "newCellForRow:column:avoidingRows:", row, column, visibleRows);
174                if (!tableColumnCells[row]._superview)
175                    objj_msgSend(_tableColumnViews[column], "addSubview:", tableColumnCells[row]);
176                else if (tableColumnCells[row]._isHidden)
177                    objj_msgSend(tableColumnCells[row], "setHidden:", NO);
178            }
179            objj_msgSend(tableColumn, "_purge");
180        }
181    }
182    _visibleRows = visibleRows;
183    _visibleColumns = visibleColumns;
184}
185}), new objj_method(sel_getUid("setIntercellSpacing:"), function $CPTableView__setIntercellSpacing_(self, _cmd, aSize)
186{ with(self)
187{
188    if (_intercellSpacing.width != aSize.width)
189    {
190        var i = 1,
191            delta = aSize.width - _intercellSpacing.width;
192            total = delta;
193        for (; i < _tableColumns.length; ++i, total += delta)
194        {
195            var origin = objj_msgSend(_tableColumnViews[i], "frame").origin;
196            objj_msgSend(_tableColumnViews[i], "setFrameOrigin:", CGPointMake(origin.x + total, origin.y));
197        }
198    }
199    if (_intercellSpacing.height != aSize.height)
200    {
201        var i = 0;
202        for (; i < _tableColumns.length; ++i, total += delta)
203        {
204            objj_msgSend(_tableColumnViews[i], "setFrameSize:", CGSizeMake(objj_msgSend(_tableColumnViews[i], "width"), _numberOfRows * (_rowHeight + _intercellSpacing.height)));
205            var j = 1,
206                y = _rowHeight + _intercellSpacing.height;
207            for (; j < _numberOfRows; ++i, y += _rowHeight + _intercellSpacing.height)
208            {
209                if (!_tableCells[i][j])
210                    continue;
211                objj_msgSend(_tableCells[i][j], "setFrameOrigin:", CPPointMake(0.0, y));
212            }
213        }
214    }
215    _intercellSpacing = CPSizeCreateCopy(aSize);
216}
217}), new objj_method(sel_getUid("intercellSpacing"), function $CPTableView__intercellSpacing(self, _cmd)
218{ with(self)
219{
220    return _intercellSpacing;
221}
222}), new objj_method(sel_getUid("setRowHeight:"), function $CPTableView__setRowHeight_(self, _cmd, aRowHeight)
223{ with(self)
224{
225    if (_rowHeight == aRowHeight)
226        return;
227    _rowHeight = aRowHeight;
228    if (_hasVariableHeightRows)
229        return;
230    for (var row = 0; row < _numberOfRows; ++row)
231        for (var column = 0; column < _tableColumns.length; ++column)
232            objj_msgSend(_tableCells[column][row], "setFrameOrigin:", CPPointMake(0.0, row * (_rowHeight + _intercellSpacing.height)));
233}
234}), new objj_method(sel_getUid("rowHeight"), function $CPTableView__rowHeight(self, _cmd)
235{ with(self)
236{
237    return _rowHeight;
238}
239}), new objj_method(sel_getUid("addTableColumn:"), function $CPTableView__addTableColumn_(self, _cmd, aTableColumn)
240{ with(self)
241{
242    var i = 0,
243        x = _tableColumns.length ? CPRectGetMaxX(objj_msgSend(self, "rectOfColumn:", _tableColumns.length - 1)) + _intercellSpacing.width : 0.0,
244        tableColumnView = objj_msgSend(objj_msgSend(CPView, "alloc"), "initWithFrame:", CPRectMake(x, 0.0, objj_msgSend(aTableColumn, "width"), objj_msgSend(self, "_columnHeight"))),
245        tableColumnCells = [];
246    objj_msgSend(_tableColumns, "addObject:", aTableColumn);
247    objj_msgSend(_tableColumnViews, "addObject:", tableColumnView);
248    objj_msgSend(self, "addSubview:", tableColumnView);
249    objj_msgSend(_tableCells, "addObject:", tableColumnCells);
250    for (; i < _numberOfRows; ++i)
251        _tableCells[_tableColumns.length-1][i] = nil;
252}
253}), new objj_method(sel_getUid("removeTableColumn:"), function $CPTableView__removeTableColumn_(self, _cmd, aTableColumn)
254{ with(self)
255{
256    var frame = objj_msgSend(self, "frame"),
257        width = objj_msgSend(aTableColumn, "width") + _intercellSpacing.width,
258        index = objj_msgSend(_tableColumns, "indexOfObjectIdenticalTo:", aTableColumn);
259    objj_msgSend(_tableColumnViews[i], "removeFromSuperview");
260    objj_msgSend(_tableCells, "removeObjectAtIndex:", index);
261    objj_msgSend(_tableColumns, "removeObjectAtIndex:", index);
262    objj_msgSend(_tableColumnViews, "removeObjectAtIndex:", index);
263    for (; index < _tableColumns.length; ++ index)
264        objj_msgSend(_tableColumnViews[index], "setFrameOrigin:", CPPointMake(CPRectGetMinX(objj_msgSend(_tableColumnViews[index], "frame")) - width, 0.0))
265    objj_msgSend(self, "setFrameSize:", CPSizeMake(CPRectGetWidth(frame) - width, CPRectGetHeight(frame)));
266}
267}), new objj_method(sel_getUid("moveColumn:toColumn:"), function $CPTableView__moveColumn_toColumn_(self, _cmd, fromIndex, toIndex)
268{ with(self)
269{
270    if (fromIndex == toIndex)
271        return;
272}
273}), new objj_method(sel_getUid("tableColumns"), function $CPTableView__tableColumns(self, _cmd)
274{ with(self)
275{
276    return _tableColumns;
277}
278}), new objj_method(sel_getUid("tableColumnWithIdentifier:"), function $CPTableView__tableColumnWithIdentifier_(self, _cmd, anObject)
279{ with(self)
280{
281    for (var i = 0; i < _tableColumns.length; i++)
282        if (objj_msgSend(_tableColumns[i], "isEqual:", anObject))
283            return _tableColumns[i];
284    return nil;
285}
286}), new objj_method(sel_getUid("numberOfColumns"), function $CPTableView__numberOfColumns(self, _cmd)
287{ with(self)
288{
289    return _tableColumns.length;
290}
291}), new objj_method(sel_getUid("numberOfRows"), function $CPTableView__numberOfRows(self, _cmd)
292{ with(self)
293{
294    return _numberOfRows;
295}
296}), new objj_method(sel_getUid("tile"), function $CPTableView__tile(self, _cmd)
297{ with(self)
298{
299    var HEIGHT = 10.0;
300}
301}), new objj_method(sel_getUid("setDataSource:"), function $CPTableView__setDataSource_(self, _cmd, aDataSource)
302{ with(self)
303{
304    if (!objj_msgSend(aDataSource, "respondsToSelector:", sel_getUid("numberOfRowsInTableView:")))
305        objj_msgSend(CPException, "raise:reason:", CPInternalInconsistencyException, "Data source doesn't support 'numberOfRowsInTableView:'");
306    if (!objj_msgSend(aDataSource, "respondsToSelector:", sel_getUid("tableView:objectValueForTableColumn:row:")))
307        objj_msgSend(CPException, "raise:reason:", CPInternalInconsistencyException, "Data source doesn't support 'tableView:objectValueForTableColumn:row:'");
308    _dataSource = aDataSource;
309    objj_msgSend(self, "reloadData");
310}
311}), new objj_method(sel_getUid("dataSource"), function $CPTableView__dataSource(self, _cmd)
312{ with(self)
313{
314    return _dataSource;
315}
316}), new objj_method(sel_getUid("delegate"), function $CPTableView__delegate(self, _cmd)
317{ with(self)
318{
319    return _delegate;
320}
321}), new objj_method(sel_getUid("setDelegate:"), function $CPTableView__setDelegate_(self, _cmd, aDelegate)
322{ with(self)
323{
324    if (_delegate === aDelegate)
325        return;
326    var notificationCenter = objj_msgSend(CPNotificationCenter, "defaultCenter");
327    if (objj_msgSend(_delegate, "respondsToSelector:", sel_getUid("tableViewColumnDidMove:")))
328        objj_msgSend(notificationCenter, "removeObserver:name:object:", _delegate, CPTableViewColumnDidMoveNotification, self);
329    if (objj_msgSend(_delegate, "respondsToSelector:", sel_getUid("tableViewColumnDidResize:")))
330        objj_msgSend(notificationCenter, "removeObserver:name:object:", _delegate, CPTableViewColumnDidResizeNotification, self);
331    if (objj_msgSend(_delegate, "respondsToSelector:", sel_getUid("tableViewSelectionDidChange:")))
332        objj_msgSend(notificationCenter, "removeObserver:name:object:", _delegate, CPTableViewSelectionDidChangeNotification, self);
333    if (objj_msgSend(_delegate, "respondsToSelector:", sel_getUid("tableViewSelectionIsChanging:")))
334        objj_msgSend(notificationCenter, "removeObserver:name:object:", _delegate, CPTableViewSelectionIsChangingNotification, self);
335    _delegate = aDelegate;
336    if (objj_msgSend(_delegate, "respondsToSelector:", sel_getUid("tableViewColumnDidMove:")))
337        objj_msgSend(notificationCenter, "addObserver:selector:name:object:", _delegate, sel_getUid("tableViewColumnDidMove:"), CPTableViewColumnDidMoveNotification, self);
338    if (objj_msgSend(_delegate, "respondsToSelector:", sel_getUid("tableViewColumnDidResize:")))
339        objj_msgSend(notificationCenter, "addObserver:selector:name:object:", _delegate, sel_getUid("tableViewColumnDidResize:"), CPTableViewColumnDidResizeNotification, self);
340    if (objj_msgSend(_delegate, "respondsToSelector:", sel_getUid("tableViewSelectionDidChange:")))
341        objj_msgSend(notificationCenter, "addObserver:selector:name:object:", _delegate, sel_getUid("tableViewSelectionDidChange:"), CPTableViewSelectionDidChangeNotification, self);
342    if (objj_msgSend(_delegate, "respondsToSelector:", sel_getUid("tableViewSelectionIsChanging:")))
343        objj_msgSend(notificationCenter, "addObserver:selector:name:object:", _delegate, sel_getUid("tableViewSelectionIsChanging:"), CPTableViewSelectionIsChangingNotification, self);
344    _delegateSelectorsCache = 0;
345    if (objj_msgSend(_delegate, "respondsToSelector:", sel_getUid("tableView:willDisplayCell:forTableColumn:row:")))
346        _delegateSelectorsCache |= _CPTableViewWillDisplayCellSelector;
347    if (objj_msgSend(_delegate, "respondsToSelector:", sel_getUid("tableView:shouldSelectRow:")))
348        _delegateSelectorsCache |= _CPTableViewShouldSelectRowSelector;
349    if (objj_msgSend(_delegate, "respondsToSelector:", sel_getUid("tableView:shouldSelectTableColumn:")))
350        _delegateSelectorsCache |= _CPTableViewShouldSelectTableColumnSelector;
351    if (objj_msgSend(_delegate, "respondsToSelector:", sel_getUid("selectionShouldChangeInTableView:")))
352        _delegateSelectorsCache |= _CPTableViewSelectionShouldChangeSelector;
353    if (objj_msgSend(_delegate, "respondsToSelector:", sel_getUid("tableView:shouldEditTableColumn:row:")))
354        _delegateSelectorsCache |= _CPTableViewShouldEditTableColumnSelector;
355    if (objj_msgSend(_delegate, "respondsToSelector:", sel_getUid("tableView:selectionIndexesForProposedSelection:")))
356        _delegateSelectorsCache |= _CPTableViewSelectionIndexesForProposedSelectionSelector;
357    if (objj_msgSend(_delegate, "respondsToSelector:", sel_getUid("tableView:heightOfRow:")))
358    {
359        _delegateSelectorsCache |= _CPTableViewHeightOfRowSelector;
360        _hasVariableHeightRows = YES;
361    }
362    else
363        _hasVariableHeightRows = NO;
364}
365}), new objj_method(sel_getUid("noteNumberOfRowsChanged"), function $CPTableView__noteNumberOfRowsChanged(self, _cmd)
366{ with(self)
367{
368    var numberOfRows = objj_msgSend(_dataSource, "numberOfRowsInTableView:", self);
369    if (_numberOfRows != numberOfRows)
370    {
371        _numberOfRows = numberOfRows;
372        objj_msgSend(self, "_recalculateColumnHeight");
373    }
374}
375}), new objj_method(sel_getUid("noteHeightOfRowsWithIndexesChanged:"), function $CPTableView__noteHeightOfRowsWithIndexesChanged_(self, _cmd, indexSet)
376{ with(self)
377{
378    objj_msgSend(self, "_recalculateColumnHeight");
379}
380}), new objj_method(sel_getUid("rectOfRow:"), function $CPTableView__rectOfRow_(self, _cmd, aRowIndex)
381{ with(self)
382{
383    return CPRectMake(0.0, (_hasVariableHeightRows ? _rowMinYs[aRowIndex] : (aRowIndex * (_rowHeight + _intercellSpacing.height))), CPRectGetWidth(objj_msgSend(self, "bounds")), (_hasVariableHeightRows ? _rowHeights[aRowIndex] : _rowHeight));
384}
385}), new objj_method(sel_getUid("rectOfColumn:"), function $CPTableView__rectOfColumn_(self, _cmd, aColumnIndex)
386{ with(self)
387{
388    return objj_msgSend(_tableColumnViews[aColumnIndex], "frame");
389}
390}), new objj_method(sel_getUid("sizeToFit"), function $CPTableView__sizeToFit(self, _cmd)
391{ with(self)
392{
393}
394}), new objj_method(sel_getUid("_recalculateColumnHeight"), function $CPTableView___recalculateColumnHeight(self, _cmd)
395{ with(self)
396{
397    var oldColumnHeight = _columnHeight;
398    if (_hasVariableHeightRows)
399    {
400        _rowMinYs[0] = 0;
401        for (var row = 0; row < _numberOfRows; row++)
402        {
403            _rowHeights[row] = objj_msgSend(_delegate, "tableView:heightOfRow:", self, row);
404            _rowMinYs[row+1] = _rowMinYs[row] + _rowHeights[row] + _intercellSpacing.height;
405        }
406        _columnHeight = _rowMinYs[_numberOfRows];
407    }
408    else
409        _columnHeight = _numberOfRows * (_rowHeight + _intercellSpacing.height);
410    var count = _tableColumnViews.length;
411    while (count--)
412        objj_msgSend(_tableColumnViews[count], "setFrameSize:", CGSizeMake(objj_msgSend(_tableColumns[count], "width"), _columnHeight));
413    objj_msgSend(self, "setFrameSize:", CGSizeMake(CGRectGetWidth(objj_msgSend(self, "frame")), _columnHeight));
414}
415}), new objj_method(sel_getUid("visibleRectInParent"), function $CPTableView__visibleRectInParent(self, _cmd)
416{ with(self)
417{
418    var superview = objj_msgSend(self, "superview");
419    if (!superview)
420        return objj_msgSend(self, "bounds");
421    return objj_msgSend(self, "convertRect:fromView:", CGRectIntersection(objj_msgSend(superview, "bounds"), objj_msgSend(self, "frame")), superview);
422}
423}), new objj_method(sel_getUid("reloadData"), function $CPTableView__reloadData(self, _cmd)
424{ with(self)
425{
426    var oldNumberOfRows = _numberOfRows;
427    _numberOfRows = objj_msgSend(_dataSource, "numberOfRowsInTableView:", self);
428    if (oldNumberOfRows != _numberOfRows)
429    {
430        objj_msgSend(self, "_recalculateColumnHeight");
431        objj_msgSend(self, "setFrameSize:", CGSizeMake(CGRectGetWidth(objj_msgSend(self, "frame")), objj_msgSend(self, "_columnHeight")));
432    }
433    _objectValueCache = [];
434    objj_msgSend(self, "clearCells");
435    objj_msgSend(self, "setNeedsLayout");
436}
437}), new objj_method(sel_getUid("layoutSubviews"), function $CPTableView__layoutSubviews(self, _cmd)
438{ with(self)
439{
440    objj_msgSend(self, "loadTableCellsInRect:", objj_msgSend(self, "visibleRectInParent"));
441}
442}), new objj_method(sel_getUid("displaySoon"), function $CPTableView__displaySoon(self, _cmd)
443{ with(self)
444{
445    objj_msgSend(_scrollTimer, "invalidate");
446    _scrollTimer = objj_msgSend(CPTimer, "scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:", 0.05, self, sel_getUid("displayNow"), nil, NO);
447}
448}), new objj_method(sel_getUid("displayNow"), function $CPTableView__displayNow(self, _cmd)
449{ with(self)
450{
451    objj_msgSend(self, "setNeedsLayout");
452}
453}), new objj_method(sel_getUid("viewDidMoveToSuperview"), function $CPTableView__viewDidMoveToSuperview(self, _cmd)
454{ with(self)
455{
456    objj_msgSend(objj_msgSend(objj_msgSend(self, "enclosingScrollView"), "contentView"), "setPostsBoundsChangedNotifications:", YES);
457    objj_msgSend(objj_msgSend(CPNotificationCenter, "defaultCenter"), "addObserver:selector:name:object:", self, sel_getUid("viewBoundsChanged:"), CPViewBoundsDidChangeNotification, objj_msgSend(objj_msgSend(self, "enclosingScrollView"), "contentView"));
458}
459}), new objj_method(sel_getUid("viewBoundsChanged:"), function $CPTableView__viewBoundsChanged_(self, _cmd, aNotification)
460{ with(self)
461{
462    objj_msgSend(self, "displayNow");
463}
464}), new objj_method(sel_getUid("setAllowsMultipleSelection:"), function $CPTableView__setAllowsMultipleSelection_(self, _cmd, allowsMultipleSelection)
465{ with(self)
466{
467    if (_allowsMultipleSelection === allowsMultipleSelection)
468        return;
469    _allowsMultipleSelection = allowsMultipleSelection;
470}
471}), new objj_method(sel_getUid("allowsMultipleSelection"), function $CPTableView__allowsMultipleSelection(self, _cmd)
472{ with(self)
473{
474    return _allowsMultipleSelection;
475}
476}), new objj_method(sel_getUid("setAllowsEmptySelection:"), function $CPTableView__setAllowsEmptySelection_(self, _cmd, allowsEmptySelection)
477{ with(self)
478{
479    if (_allowsEmptySelection === allowsEmptySelection)
480        return;
481    _allowsEmptySelection = allowsEmptySelection;
482}
483}), new objj_method(sel_getUid("allowsEmptySelection"), function $CPTableView__allowsEmptySelection(self, _cmd)
484{ with(self)
485{
486    return _allowsEmptySelection;
487}
488}), new objj_method(sel_getUid("rowAtPoint:"), function $CPTableView__rowAtPoint_(self, _cmd, aPoint)
489{ with(self)
490{
491    var index = objj_msgSend(self, "_rowAtY:", aPoint.y)
492    if (index >= 0 && index < _numberOfRows)
493        return index;
494    else
495        return CPNotFound;
496}
497}), new objj_method(sel_getUid("columnAtPoint:"), function $CPTableView__columnAtPoint_(self, _cmd, aPoint)
498{ with(self)
499{
500    var index = objj_msgSend(self, "_columnAtX:", aPoint.x)
501    if (index >= 0 && index < _tableColumns.length)
502        return index;
503    else
504        return CPNotFound;
505}
506}), new objj_method(sel_getUid("_rowAtY:"), function $CPTableView___rowAtY_(self, _cmd, y)
507{ with(self)
508{
509    if (_hasVariableHeightRows)
510    {
511        var a = 0,
512            b = _numberOfRows;
513        if (y < _rowMinYs[0])
514            return -1;
515        if (y >= _rowMinYs[_rowMinYs.length-1])
516            return _numberOfRows;
517        while (true)
518        {
519            var half = a + Math.floor((b - a) / 2);
520            if (y < _rowMinYs[half])
521                b = half;
522            else if (half < _numberOfRows-1 && y >= _rowMinYs[half+1])
523                a = half;
524            else
525                return half;
526        }
527    }
528    else
529        return FLOOR(y / (_rowHeight + _intercellSpacing.height));
530}
531}), new objj_method(sel_getUid("_columnAtX:"), function $CPTableView___columnAtX_(self, _cmd, x)
532{ with(self)
533{
534    var a = 0,
535        b = _tableColumns.length;
536    var last = objj_msgSend(_tableColumnViews[_tableColumns.length-1], "frame");
537    if (x < objj_msgSend(_tableColumnViews[0], "frame").origin.x)
538        return -1;
539    if (x >= last.origin.x + last.size.width)
540        return _tableColumns.length;
541    while (true)
542    {
543        var half = a + Math.floor((b - a) / 2);
544        if (x < objj_msgSend(_tableColumnViews[half], "frame").origin.x)
545            b = half;
546        else if (half < _tableColumns.length-1 && x >= objj_msgSend(_tableColumnViews[half+1], "frame").origin.x)
547            a = half;
548        else
549            return half;
550    }
551}
552}), new objj_method(sel_getUid("selectRowIndexes:byExtendingSelection:"), function $CPTableView__selectRowIndexes_byExtendingSelection_(self, _cmd, indexes, extend)
553{ with(self)
554{
555    if (extend)
556        _selectedRowIndexes = objj_msgSend(objj_msgSend(_selectedRowIndexes, "copy"), "addIndexes:", indexes);
557    else if (objj_msgSend(indexes, "count") > 0 || _allowsEmptySelection)
558        _selectedRowIndexes = objj_msgSend(indexes, "copy");
559    objj_msgSend(self, "_drawSelection");
560}
561}), new objj_method(sel_getUid("selectedRowIndexes"), function $CPTableView__selectedRowIndexes(self, _cmd)
562{ with(self)
563{
564    return _selectedRowIndexes;
565}
566}), new objj_method(sel_getUid("numberOfSelectedRows"), function $CPTableView__numberOfSelectedRows(self, _cmd)
567{ with(self)
568{
569    return objj_msgSend(_selectedRowIndexes, "count");
570}
571}), new objj_method(sel_getUid("deselectAll:"), function $CPTableView__deselectAll_(self, _cmd, sender)
572{ with(self)
573{
574    if (!_allowsEmptySelection || objj_msgSend(_selectedRowIndexes, "count") === 0 ||
575            ((_delegateSelectorsCache & _CPTableViewSelectionShouldChangeSelector) && !objj_msgSend(_delegate, "selectionShouldChangeInTableView:", self)))
576        return;
577    objj_msgSend(self, "selectRowIndexes:byExtendingSelection:", objj_msgSend(CPIndexSet, "indexSet"), NO);
578    objj_msgSend(objj_msgSend(CPNotificationCenter, "defaultCenter"), "postNotificationName:object:userInfo:", CPTableViewSelectionDidChangeNotification, self, nil);
579}
580}), new objj_method(sel_getUid("editColumn:row:withEvent:select:"), function $CPTableView__editColumn_row_withEvent_select_(self, _cmd, columnIndex, rowIndex, theEvent, flag)
581{ with(self)
582{
583}
584}), new objj_method(sel_getUid("_updateSelectionWithMouseAtRow:"), function $CPTableView___updateSelectionWithMouseAtRow_(self, _cmd, aRow)
585{ with(self)
586{
587    var newSelection;
588    if (_allowsMultipleSelection)
589        newSelection = objj_msgSend(CPIndexSet, "indexSetWithIndexesInRange:", CPMakeRange(MIN(aRow, _selectionStartRow), ABS(aRow-_selectionStartRow)+1));
590    else if (aRow >= 0 && aRow < _numberOfRows)
591        newSelection = objj_msgSend(CPIndexSet, "indexSetWithIndex:", aRow);
592    else
593        newSelection = objj_msgSend(CPIndexSet, "indexSet");
594    if (_allowsMultipleSelection && _selectionModifier & (CPCommandKeyMask | CPControlKeyMask | CPAlternateKeyMask))
595    {
596        var intersection = objj_msgSend(newSelection, "copy"),
597            difference = objj_msgSend(newSelection, "copy");
598        objj_msgSend(difference, "removeIndexes:", _previousSelectedRowIndexes);
599        objj_msgSend(intersection, "removeIndexes:", difference)
600        objj_msgSend(newSelection, "addIndexes:", _previousSelectedRowIndexes);
601        objj_msgSend(newSelection, "removeIndexes:", intersection);
602    }
603    if (!objj_msgSend(newSelection, "isEqualToIndexSet:", _selectedRowIndexes))
604    {
605        if ((_delegateSelectorsCache & _CPTableViewSelectionShouldChangeSelector) && !objj_msgSend(_delegate, "selectionShouldChangeInTableView:", self))
606            return;
607        if (_delegateSelectorsCache & _CPTableViewSelectionIndexesForProposedSelectionSelector)
608            newSelection = objj_msgSend(_delegate, "tableView:selectionIndexesForProposedSelection:", self, newSelection);
609        else if (_delegateSelectorsCache & _CPTableViewShouldSelectRowSelector)
610        {
611            var indexes = [];
612            objj_msgSend(newSelection, "getIndexes:maxCount:inIndexRange:", indexes, Number.MAX_VALUE, nil);
613            for (var i = 0; i < indexes.length; i++)
614                if (!objj_msgSend(_delegate, "tableView:shouldSelectRow:", self, indexes[i]))
615                    objj_msgSend(newSelection, "removeIndex:", indexes[i]);
616        }
617    }
618    if (!_allowsEmptySelection && objj_msgSend(newSelection, "count") === 0)
619        return;
620    if (!objj_msgSend(newSelection, "isEqualToIndexSet:", _selectedRowIndexes))
621    {
622        objj_msgSend(self, "selectRowIndexes:byExtendingSelection:", newSelection, NO);
623        objj_msgSend(objj_msgSend(CPNotificationCenter, "defaultCenter"), "postNotificationName:object:userInfo:", CPTableViewSelectionIsChangingNotification, self, nil);
624    }
625}
626}), new objj_method(sel_getUid("mouseDown:"), function $CPTableView__mouseDown_(self, _cmd, anEvent)
627{ with(self)
628{
629    objj_msgSend(self, "trackSelection:", anEvent);
630}
631}), new objj_method(sel_getUid("setDoubleAction:"), function $CPTableView__setDoubleAction_(self, _cmd, aSelector)
632{ with(self)
633{
634    _doubleAction = aSelector;
635}
636}), new objj_method(sel_getUid("doubleAction"), function $CPTableView__doubleAction(self, _cmd)
637{ with(self)
638{
639    return _doubleAction;
640}
641}), new objj_method(sel_getUid("clickedColumn"), function $CPTableView__clickedColumn(self, _cmd)
642{ with(self)
643{
644    return _clickedColumn;
645}
646}), new objj_method(sel_getUid("clickedRow"), function $CPTableView__clickedRow(self, _cmd)
647{ with(self)
648{
649    return _clickedRow;
650}
651}), new objj_method(sel_getUid("trackSelection:"), function $CPTableView__trackSelection_(self, _cmd, anEvent)
652{ with(self)
653{
654    var type = objj_msgSend(anEvent, "type"),
655        point = objj_msgSend(self, "convertPoint:fromView:", objj_msgSend(anEvent, "locationInWindow"), nil),
656        currentRow = MAX(0, MIN(_numberOfRows-1, objj_msgSend(self, "_rowAtY:", point.y)));
657    if (type == CPLeftMouseUp)
658    {
659        _clickedRow = objj_msgSend(self, "rowAtPoint:", point);
660        _clickedColumn = objj_msgSend(self, "columnAtPoint:", point);
661        if (objj_msgSend(anEvent, "clickCount") === 2)
662        {
663            CPLog.warn("edit?!");
664            objj_msgSend(self, "sendAction:to:", _doubleAction, _target);
665        }
666        else
667        {
668            if (!objj_msgSend(_previousSelectedRowIndexes, "isEqualToIndexSet:", _selectedRowIndexes))
669            {
670                objj_msgSend(objj_msgSend(CPNotificationCenter, "defaultCenter"), "postNotificationName:object:userInfo:", CPTableViewSelectionDidChangeNotification, self, nil);
671            }
672            objj_msgSend(self, "sendAction:to:", _action, _target);
673        }
674        return;
675    }
676    if (type == CPLeftMouseDown)
677    {
678        _previousSelectedRowIndexes = _selectedRowIndexes;
679        _selectionModifier = objj_msgSend(anEvent, "modifierFlags");
680        if (_selectionModifier & CPShiftKeyMask)
681            _selectionStartRow = (ABS(objj_msgSend(_previousSelectedRowIndexes, "firstIndex") - currentRow) < ABS(objj_msgSend(_previousSelectedRowIndexes, "lastIndex") - currentRow)) ?
682                objj_msgSend(_previousSelectedRowIndexes, "firstIndex") : objj_msgSend(_previousSelectedRowIndexes, "lastIndex");
683        else
684            _selectionStartRow = currentRow;
685        objj_msgSend(self, "_updateSelectionWithMouseAtRow:", currentRow);
686    }
687    else if (type == CPLeftMouseDragged)
688    {
689        objj_msgSend(self, "_updateSelectionWithMouseAtRow:", currentRow);
690    }
691    objj_msgSend(CPApp, "setTarget:selector:forNextEventMatchingMask:untilDate:inMode:dequeue:", self, sel_getUid("trackSelection:"), CPLeftMouseDraggedMask | CPLeftMouseUpMask, nil, nil, YES);
692}
693}), new objj_method(sel_getUid("_drawSelection"), function $CPTableView___drawSelection(self, _cmd)
694{ with(self)
695{
696    if (!_currentlySelected) {
697        _currentlySelected = objj_msgSend(CPIndexSet, "indexSet");
698        _selectionViews = [];
699        _selectionViewsPool = [];
700    }
701    var removeSet = objj_msgSend(_currentlySelected, "copy"),
702        indexesToRemove = [];
703    objj_msgSend(removeSet, "removeIndexes:", _selectedRowIndexes);
704    objj_msgSend(removeSet, "getIndexes:maxCount:inIndexRange:", indexesToRemove, Number.MAX_VALUE, nil);
705    var addSet = objj_msgSend(_selectedRowIndexes, "copy"),
706        indexesToAdd = [];
707    objj_msgSend(addSet, "removeIndexes:", _currentlySelected);
708    objj_msgSend(addSet, "getIndexes:maxCount:inIndexRange:", indexesToAdd, Number.MAX_VALUE, nil);
709    for (var i = 0; i < indexesToRemove.length; i++)
710    {
711        var row = indexesToRemove[i];
712        for (var column = 0; column < _tableColumns.length; column++)
713            if (objj_msgSend(_tableCells[column][row], "respondsToSelector:", sel_getUid("highlight:")))
714                objj_msgSend(_tableCells[column][row], "highlight:", NO);
715    }
716    for (var i = 0; i < indexesToAdd.length; i++)
717    {
718        var row = indexesToAdd[i];
719        for (var column = 0; column < _tableColumns.length; column++)
720            if (objj_msgSend(_tableCells[column][row], "respondsToSelector:", sel_getUid("highlight:")))
721                objj_msgSend(_tableCells[column][row], "highlight:", YES);
722    }
723    for (var i = 0; i < indexesToAdd.length; i++)
724    {
725        var index = indexesToAdd[i],
726            view;
727        if (indexesToRemove.length > 0)
728        {
729            view = _selectionViews[indexesToRemove.pop()];
730        }
731        else if (_selectionViewsPool.length > 0)
732        {
733            view = _selectionViewsPool.pop();
734            objj_msgSend(self, "addSubview:positioned:relativeTo:", view, CPWindowBelow, nil);
735        }
736        else
737        {
738            view = objj_msgSend(objj_msgSend(CPView, "alloc"), "init");
739            objj_msgSend(view, "setBackgroundColor:", objj_msgSend(CPColor, "alternateSelectedControlColor"));
740            objj_msgSend(self, "addSubview:positioned:relativeTo:", view, CPWindowBelow, nil);
741        }
742        _selectionViews[index] = view;
743        var frame = objj_msgSend(self, "rectOfRow:", index);
744        frame.size.height += _intercellSpacing.height - 1;
745        objj_msgSend(view, "setFrame:", frame);
746    }
747    for (var i = 0; i < indexesToRemove.length; i++)
748    {
749        var row = indexesToRemove[i],
750            view = _selectionViews[row];
751        objj_msgSend(view, "removeFromSuperview");
752        _selectionViewsPool.push(view);
753    }
754    _currentlySelected = objj_msgSend(_selectedRowIndexes, "copy");
755}
756})]);
757class_addMethods(meta_class, [new objj_method(sel_getUid("initialize"), function $CPTableView__initialize(self, _cmd)
758{ with(self)
759{
760}
761})]);
762}
763var CPTableViewDataSourceKey = "CPTableViewDataSourceKey",
764    CPTableViewDelegateKey = "CPTableViewDelegateKey",
765    CPTableViewHeaderViewKey = "CPTableViewHeaderViewKey",
766    CPTableViewTableColumnsKey = "CPTableViewTableColumnsKey",
767    CPTableViewRowHeightKey = "CPTableViewRowHeightKey",
768    CPTableViewIntercellSpacingKey = "CPTableViewIntercellSpacingKey",
769    CPTableViewMultipleSelectionKey = "CPTableViewMultipleSelectionKey",
770    CPTableViewEmptySelectionKey = "CPTableViewEmptySelectionKey";
771{
772var the_class = objj_getClass("CPTableView")
773if(!the_class) objj_exception_throw(new objj_exception(OBJJClassNotFoundException, "*** Could not find definition for class \"CPTableView\""));
774var meta_class = the_class.isa;class_addMethods(the_class, [new objj_method(sel_getUid("initWithCoder:"), function $CPTableView__initWithCoder_(self, _cmd, aCoder)
775{ with(self)
776{
777    if (self = objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPControl") }, "initWithCoder:", aCoder))
778    {
779        objj_msgSend(self, "_init");
780        _dataSource = objj_msgSend(aCoder, "decodeObjectForKey:", CPTableViewDataSourceKey);
781        _delegate = objj_msgSend(aCoder, "decodeObjectForKey:", CPTableViewDelegateKey);
782        _rowHeight = objj_msgSend(aCoder, "decodeFloatForKey:", CPTableViewRowHeightKey);
783        _intercellSpacing = objj_msgSend(aCoder, "decodeSizeForKey:", CPTableViewIntercellSpacingKey);
784        _allowsMultipleSelection = objj_msgSend(aCoder, "decodeBoolForKey:", CPTableViewMultipleSelectionKey);
785        _allowsEmptySelection = objj_msgSend(aCoder, "decodeBoolForKey:", CPTableViewEmptySelectionKey);
786        var tableColumns = objj_msgSend(aCoder, "decodeObjectForKey:", CPTableViewTableColumnsKey);
787        for (var i = 0; i < tableColumns.length; i++)
788            objj_msgSend(self, "addTableColumn:", tableColumns[i]);
789    }
790    return self;
791}
792}), new objj_method(sel_getUid("encodeWithCoder:"), function $CPTableView__encodeWithCoder_(self, _cmd, aCoder)
793{ with(self)
794{
795    objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPControl") }, "encodeWithCoder:", aCoder);
796    objj_msgSend(aCoder, "encodeObject:forKey:", _dataSource, CPTableViewDataSourceKey);
797    objj_msgSend(aCoder, "encodeObject:forKey:", _delegate, CPTableViewDelegateKey);
798    objj_msgSend(aCoder, "encodeObject:forKey:", _tableColumns, CPTableViewTableColumnsKey);
799    objj_msgSend(aCoder, "encodeFloat:forKey:", _rowHeight, CPTableViewRowHeightKey);
800    objj_msgSend(aCoder, "encodeSize:forKey:", _intercellSpacing, CPTableViewIntercellSpacingKey);
801    objj_msgSend(aCoder, "encodeBool:forKey:", _allowsMultipleSelection, CPTableViewMultipleSelectionKey);
802    objj_msgSend(aCoder, "encodeBool:forKey:", _allowsEmptySelection, CPTableViewEmptySelectionKey);
803}
804})]);
805}
806{
807var the_class = objj_getClass("CPColor")
808if(!the_class) objj_exception_throw(new objj_exception(OBJJClassNotFoundException, "*** Could not find definition for class \"CPColor\""));
809var meta_class = the_class.isa;class_addMethods(meta_class, [new objj_method(sel_getUid("alternateSelectedControlColor"), function $CPColor__alternateSelectedControlColor(self, _cmd)
810{ with(self)
811{
812    return objj_msgSend(objj_msgSend(CPColor, "alloc"), "_initWithRGBA:", [0.22, 0.46, 0.84, 1.0]);
813}
814}), new objj_method(sel_getUid("secondarySelectedControlColor"), function $CPColor__secondarySelectedControlColor(self, _cmd)
815{ with(self)
816{
817    return objj_msgSend(objj_msgSend(CPColor, "alloc"), "_initWithRGBA:", [0.83, 0.83, 0.83, 1.0]);
818}
819})]);
820}
821