mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-16 03:30:42 +00:00
Added beginnings of drawing selection.
Reviewed by me.
This commit is contained in:
1 parent
d131127717
commit
714fc9d5bb
4 files changed
+220
-8
No files matched your search
@@ -175,7 +175,7 @@
|
||||
*/
|
||||
- (BOOL)isFirstResponder
|
||||
{
|
||||
return [[self window] firstResponder] == self;
|
||||
return [[self window] firstResponder] === self;
|
||||
}
|
||||
|
||||
// Setting the Content
|
||||
|
||||
@@ -683,7 +683,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
|
||||
{
|
||||
var string = [self stringValue];
|
||||
|
||||
if ((!string || [string length] === 0) && ![self hasThemeState:CPThemeStateEditing])
|
||||
if ((!string || string.length === 0) && ![self hasThemeState:CPThemeStateEditing])
|
||||
[self setThemeState:CPTextFieldStatePlaceholder];
|
||||
else
|
||||
[self unsetThemeState:CPTextFieldStatePlaceholder];
|
||||
|
||||
+211
-1
@@ -8,7 +8,6 @@
|
||||
|
||||
#include "CoreGraphics/CGGeometry.h"
|
||||
|
||||
|
||||
var CPTableViewDataSource_tableView_setObjectValue_forTableColumn_row_ = 1 << 2,
|
||||
|
||||
CPTableViewDataSource_tableView_acceptDrop_row_dropOperation_ = 1 << 3,
|
||||
@@ -47,6 +46,33 @@ CPTableViewSelectionHighlightStyleSourceList = 1;
|
||||
|
||||
#define NUMBER_OF_COLUMNS() (_tableColumns.length)
|
||||
|
||||
@implementation _CPTableDrawView : CPView
|
||||
{
|
||||
CPTableView _tableView;
|
||||
}
|
||||
|
||||
- (id)initWithTableView:(CPTableView)aTableView
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if (self)
|
||||
_tableView = aTableView;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)drawRect:(CGRect)aRect
|
||||
{
|
||||
var frame = [self frame],
|
||||
context = [[CPGraphicsContext currentContext] graphicsPort];
|
||||
|
||||
CGContextTranslateCTM(context, -_CGRectGetMinX(frame), -_CGRectGetMinY(frame));
|
||||
|
||||
[_tableView _drawRect:aRect];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NEWCPTableView : CPControl
|
||||
{
|
||||
id _dataSource;
|
||||
@@ -88,6 +114,9 @@ CPTableViewSelectionHighlightStyleSourceList = 1;
|
||||
|
||||
CPIndexSet _selectedColumnIndexes;
|
||||
CPIndexSet _selectedRowIndexes;
|
||||
CPInteger _selectionStartRow;
|
||||
|
||||
_CPTableDrawView _tableDrawView;
|
||||
}
|
||||
|
||||
- (id)initWithFrame:(CGRect)aFrame
|
||||
@@ -131,6 +160,10 @@ CPTableViewSelectionHighlightStyleSourceList = 1;
|
||||
|
||||
_selectedColumnIndexes = [CPIndexSet indexSet];
|
||||
_selectedRowIndexes = [CPIndexSet indexSet];
|
||||
|
||||
_tableDrawView = [[_CPTableDrawView alloc] initWithTableView:self];
|
||||
[_tableDrawView setBackgroundColor:[CPColor yellowColor]];
|
||||
[self addSubview:_tableDrawView];
|
||||
}
|
||||
|
||||
return self;
|
||||
@@ -426,18 +459,28 @@ CPTableViewSelectionHighlightStyleSourceList = 1;
|
||||
//Selecting Columns and Rows
|
||||
- (void)selectColumnIndexes:(CPIndexSet)columns byExtendingSelection:(BOOL)shouldExtendSelection
|
||||
{
|
||||
// We deselect all columns when selecting rows.
|
||||
_selectedRowIndexes = [CPIndexSet indexSet];
|
||||
|
||||
if (shouldExtendSelection)
|
||||
[_selectedColumnIndexes addIndexes:columns];
|
||||
else
|
||||
_selectedColumnIndexes = [columns copy];
|
||||
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
|
||||
- (void)selectRowIndexes:(CPIndexSet)rows byExtendingSelection:(BOOL)shouldExtendSelection
|
||||
{
|
||||
// We deselect all rows when selecting columns.
|
||||
_selectedColumnIndexes = [CPIndexSet indexSet];
|
||||
|
||||
if (shouldExtendSelection)
|
||||
[_selectedRowIndexes addIndexes:rows];
|
||||
else
|
||||
_selectedRowIndexes = [rows copy];
|
||||
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
|
||||
- (CPIndexSet)selectedColumnIndexes
|
||||
@@ -1002,6 +1045,10 @@ CPTableViewSelectionHighlightStyleSourceList = 1;
|
||||
// remove?
|
||||
return;
|
||||
}
|
||||
|
||||
// if (!window.blah)
|
||||
// return window.setTimeout(function() { window.blah = true; [self load]; window.blah = false}, 0.0);
|
||||
|
||||
if (window.console && window.console.profile)
|
||||
console.profile("cell-load");
|
||||
|
||||
@@ -1042,6 +1089,10 @@ CPTableViewSelectionHighlightStyleSourceList = 1;
|
||||
_exposedRows = exposedRows;
|
||||
_exposedColumns = exposedColumns;
|
||||
|
||||
[_tableDrawView setFrame:exposedRect];
|
||||
// [_tableDrawView setBounds:exposedRect];
|
||||
[_tableDrawView display];
|
||||
|
||||
if (window.console && window.console.profile)
|
||||
console.profileEnd("cell-load");
|
||||
}
|
||||
@@ -1137,6 +1188,37 @@ _cachedDataViews[dataView.identifier].push(dataView);
|
||||
[_headerView setFrameSize:CGSizeMake(aSize.width, [_headerView frame].size.height)];
|
||||
}
|
||||
|
||||
- (void)_drawRect:(CGRect)aRect
|
||||
{
|
||||
[self highlightSelectionInClipRect:[self _exposedRect]];
|
||||
}
|
||||
|
||||
- (void)highlightSelectionInClipRect:(CGRect)aRect
|
||||
{
|
||||
[[CPColor greenColor] set];
|
||||
|
||||
var context = [[CPGraphicsContext currentContext] graphicsPort];
|
||||
|
||||
if ([_selectedRowIndexes count] >= 1)
|
||||
{
|
||||
var exposedRows = [CPIndexSet indexSetWithIndexesInRange:[self rowsInRect:aRect]],
|
||||
exposedRange = CPMakeRange([exposedRows firstIndex], [exposedRows lastIndex] - [exposedRows firstIndex] + 1),
|
||||
rowArray = [];
|
||||
|
||||
[_selectedRowIndexes getIndexes:rowArray maxCount:-1 inIndexRange:exposedRange];
|
||||
|
||||
var rowArrayIndex = 0,
|
||||
rowArrayCount = rowArray.length;
|
||||
|
||||
for (; rowArrayIndex < rowArrayCount; ++rowArrayIndex)
|
||||
CGContextFillRect(context, [self rectOfRow:rowArray[rowArrayIndex]]);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
- (void)layoutSubviews
|
||||
{
|
||||
[self load];
|
||||
@@ -1188,4 +1270,132 @@ _cachedDataViews[dataView.identifier].push(dataView);
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
/*
|
||||
var type = [anEvent type],
|
||||
point = [self convertPoint:[anEvent locationInWindow] fromView:nil],
|
||||
currentRow = MAX(0, MIN(_numberOfRows-1, [self _rowAtY:point.y]));
|
||||
|
||||
*/
|
||||
|
||||
- (BOOL)startTrackingAt:(CGPoint)aPoint
|
||||
{
|
||||
var row = [self rowAtPoint:aPoint];
|
||||
|
||||
if ([self mouseDownFlags] & CPShiftKeyMask)
|
||||
_selectionAnchor = (ABS([_selectedRowIndexes firstIndex] - row) < ABS([_selectedRowIndexes lastIndex] - row)) ?
|
||||
[_selectedRowIndexes firstIndex] : [_selectedRowIndexes lastIndex];
|
||||
else
|
||||
_selectionAnchor = row;
|
||||
|
||||
[self _updateSelectionWithMouseAtRow:row];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)continueTracking:(CGPoint)lastPoint at:(CGPoint)aPoint
|
||||
{
|
||||
[self _updateSelectionWithMouseAtRow:[self rowAtPoint:aPoint]];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)stopTracking:(CGPoint)lastPoint at:(CGPoint)aPoint mouseIsUp:(BOOL)mouseIsUp
|
||||
{/*
|
||||
_clickedRow = [self rowAtPoint:point];
|
||||
_clickedColumn = [self columnAtPoint:point];
|
||||
|
||||
if ([anEvent clickCount] === 2)
|
||||
{
|
||||
CPLog.warn("edit?!");
|
||||
|
||||
[self sendAction:_doubleAction to:_target];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (![_previousSelectedRowIndexes isEqualToIndexSet:_selectedRowIndexes])
|
||||
{
|
||||
[[CPNotificationCenter defaultCenter] postNotificationName:CPTableViewSelectionDidChangeNotification object:self userInfo:nil];
|
||||
}
|
||||
|
||||
[self sendAction:_action to:_target];
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
- (void)_updateSelectionWithMouseAtRow:(CPInteger)aRow
|
||||
{
|
||||
// If cmd/ctrl was held down XOR the old selection with the proposed selection
|
||||
if ([self mouseDownFlags] & (CPCommandKeyMask | CPControlKeyMask | CPAlternateKeyMask))
|
||||
{
|
||||
if ([_selectedRowIndexes containsIndex:aRow])
|
||||
{
|
||||
newSelection = [_selectedRowIndexes copy];
|
||||
|
||||
[newSelection removeIndex:aRow];
|
||||
}
|
||||
|
||||
else if (_allowsMultipleSelection)
|
||||
{
|
||||
newSelection = [_selectedRowIndexes copy];
|
||||
|
||||
[newSelection addIndex:aRow];
|
||||
}
|
||||
|
||||
else
|
||||
newSelection = [CPIndexSet indexSetWithIndex:aRow];
|
||||
}
|
||||
|
||||
else if (_allowsMultipleSelection)
|
||||
newSelection = [CPIndexSet indexSetWithIndexesInRange:CPMakeRange(MIN(aRow, _selectionStartRow), ABS(aRow - _selectionStartRow) + 1)];
|
||||
|
||||
else if (aRow >= 0 && aRow < _numberOfRows)
|
||||
newSelection = [CPIndexSet indexSetWithIndex:aRow];
|
||||
|
||||
else
|
||||
newSelection = [CPIndexSet indexSet];
|
||||
|
||||
if ([newSelection isEqualToIndexSet:_selectedRowIndexes])
|
||||
return;
|
||||
|
||||
if (_implementedDelegateMethods & CPTableViewDelegate_selectionShouldChangeInTableView_ &&
|
||||
![_delegate selectionShouldChangeInTableView:self])
|
||||
return;
|
||||
|
||||
if (_implementedDelegateMethods & CPTableViewDelegate_tableView_selectionIndexesForProposedSelection_)
|
||||
newSelection = [_delegate tableView:self selectionIndexesForProposedSelection:newSelection];
|
||||
|
||||
if (_implementedDelegateMethods & CPTableViewDelegate_tableView_shouldSelectRow_)
|
||||
{
|
||||
var indexArray = [];
|
||||
|
||||
[newSelection getIndexes:indexArray maxCount:-1 inIndexRange:nil];
|
||||
|
||||
var indexCount = indexArray.length;
|
||||
|
||||
while (indexCount--)
|
||||
{
|
||||
var index = indexArray[indexCount];
|
||||
|
||||
if (![_delegate tableView:self shouldSelectRow:index])
|
||||
[newSelection removeIndex:index];
|
||||
}
|
||||
}
|
||||
|
||||
// if empty selection is not allowed and the new selection has nothing selected, abort
|
||||
if (!_allowsEmptySelection && [newSelection count] === 0)
|
||||
return;
|
||||
|
||||
if ([newSelection isEqualToIndexSet:_selectedRowIndexes])
|
||||
return;
|
||||
|
||||
[self selectRowIndexes:newSelection byExtendingSelection:NO];
|
||||
|
||||
[[CPNotificationCenter defaultCenter]
|
||||
postNotificationName:CPTableViewSelectionIsChangingNotification
|
||||
object:self
|
||||
userInfo:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -23,7 +23,9 @@ CPLogRegister(CPLogConsole);
|
||||
|
||||
tableView = [[NEWCPTableView alloc] initWithFrame:CGRectMake(0.0, 0.0, 500.0, 500.0)];//[view bounds]];
|
||||
|
||||
[tableView setBackgroundColor:[CPColor blueColor]];
|
||||
[tableView setAllowsMultipleSelection:YES];
|
||||
|
||||
// [tableView setBackgroundColor:[CPColor blueColor]];
|
||||
|
||||
var iconView = [[CPImageView alloc] initWithFrame:CGRectMake(16,16,0,0)];
|
||||
|
||||
@@ -40,7 +42,7 @@ CPLogRegister(CPLogConsole);
|
||||
|
||||
var textDataView = [CPTextField new];
|
||||
|
||||
[textDataView setBackgroundColor:[CPColor redColor]];
|
||||
[textDataView setBackgroundColor:[[CPColor redColor] colorWithAlphaComponent:0.5]];
|
||||
|
||||
for (var i = 1; i <= 10; i++)
|
||||
{
|
||||
@@ -50,7 +52,7 @@ CPLogRegister(CPLogConsole);
|
||||
[[column headerView] sizeToFit];
|
||||
//[column setWidth:[[column headerView] frame].size.width + 20];
|
||||
|
||||
[column setWidth:170.0];
|
||||
[column setWidth:200.0];
|
||||
|
||||
[column setDataView:textDataView];
|
||||
|
||||
@@ -103,8 +105,8 @@ CPLogRegister(CPLogConsole);
|
||||
{
|
||||
//CPLog.debug(@"shouldSelectRow %d", rowIndex);
|
||||
for (var i = 2, sqrt = SQRT(rowIndex+1); i <= sqrt; i++)
|
||||
if ((rowIndex+1) % i === 0)
|
||||
return false;
|
||||
if ((rowIndex+1) % i === 0){console.log("NO for " + rowIndex);
|
||||
return false;}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user