mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 13:10:52 +00:00
Allow read only table views to select the text in a cell.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@23538 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
01df6ea62e
commit
69a8fabe3d
3 changed files with 83 additions and 59 deletions
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
|||
2006-09-17 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Source/NSTableView.m: Changed _isCellEditable into a method
|
||||
[_isCellEditableColumn:row:] and use this everywhere. Have this new
|
||||
method check, if the table column is editable and only when not ask
|
||||
the delegate wether the cell should be editable. The matches the Cocoa
|
||||
behaviour as reported by Quentin Mathe <qmathe@club-internet.fr>.
|
||||
* Source/NSTableView.m (-editColumn:row:withEvent:select:): Allow
|
||||
selection of cell, even when the data source is not editable.
|
||||
* Source/NSTableView.m (-mouseDown:): Abort editing.
|
||||
* Source/NSOutlineView.m (-editColumn:row:withEvent:select:):
|
||||
Similar changes to super class, plus some code reordering and correction.
|
||||
|
||||
2006-09-16 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSColor.m: Fix memory leak (bug #17769)
|
||||
|
|
|
@ -1361,17 +1361,14 @@ static NSImage *unexpandable = nil;
|
|||
NSTableColumn *tb;
|
||||
NSRect drawingRect, imageRect;
|
||||
unsigned length = 0;
|
||||
id item = nil;
|
||||
int level = 0;
|
||||
float indentationFactor = 0.0;
|
||||
NSImage *image = nil;
|
||||
NSCell *imageCell = nil;
|
||||
|
||||
// We refuse to edit cells if the delegate can not accept results
|
||||
// of editing.
|
||||
if (_dataSource_editable == NO)
|
||||
{
|
||||
return;
|
||||
flag = YES;
|
||||
}
|
||||
|
||||
[self scrollRowToVisible: rowIndex];
|
||||
|
@ -1404,14 +1401,13 @@ static NSImage *unexpandable = nil;
|
|||
|
||||
_editedRow = rowIndex;
|
||||
_editedColumn = columnIndex;
|
||||
item = [self itemAtRow: _editedRow];
|
||||
|
||||
// Prepare the cell
|
||||
tb = [_tableColumns objectAtIndex: columnIndex];
|
||||
// NB: need to be released when no longer used
|
||||
_editedCell = [[tb dataCellForRow: rowIndex] copy];
|
||||
|
||||
[_editedCell setEditable: YES];
|
||||
[_editedCell setEditable: _dataSource_editable];
|
||||
[_editedCell setObjectValue: [self _objectValueForTableColumn: tb
|
||||
row: rowIndex]];
|
||||
|
||||
|
@ -1447,29 +1443,32 @@ static NSImage *unexpandable = nil;
|
|||
|
||||
_textObject = [_editedCell setUpFieldEditorAttributes: t];
|
||||
|
||||
// determine which image to use...
|
||||
if ([self isItemExpanded: item])
|
||||
{
|
||||
image = expanded;
|
||||
}
|
||||
else
|
||||
{
|
||||
image = collapsed;
|
||||
}
|
||||
|
||||
if (![self isExpandable: item])
|
||||
{
|
||||
image = unexpandable;
|
||||
}
|
||||
// move the drawing rect over like in the drawRow routine...
|
||||
drawingRect = [self frameOfCellAtColumn: columnIndex row: rowIndex];
|
||||
|
||||
if (tb == [self outlineTableColumn])
|
||||
{
|
||||
id item = nil;
|
||||
NSImage *image = nil;
|
||||
NSCell *imageCell = nil;
|
||||
|
||||
item = [self itemAtRow: _editedRow];
|
||||
// determine which image to use...
|
||||
if ([self isItemExpanded: item])
|
||||
{
|
||||
image = expanded;
|
||||
}
|
||||
else
|
||||
{
|
||||
image = collapsed;
|
||||
}
|
||||
|
||||
if (![self isExpandable: item])
|
||||
{
|
||||
image = unexpandable;
|
||||
}
|
||||
|
||||
level = [self levelForItem: item];
|
||||
indentationFactor = _indentationPerLevel * level;
|
||||
drawingRect.origin.x += indentationFactor + 5 + [image size].width;
|
||||
drawingRect.size.width -= indentationFactor + 5 + [image size].width;
|
||||
|
||||
// create the image cell..
|
||||
imageCell = [[NSCell alloc] initImageCell: image];
|
||||
|
@ -1484,13 +1483,19 @@ static NSImage *unexpandable = nil;
|
|||
imageRect.origin.y = drawingRect.origin.y;
|
||||
}
|
||||
|
||||
// draw...
|
||||
imageRect.size.width = [image size].width;
|
||||
imageRect.size.height = [image size].height;
|
||||
|
||||
// draw...
|
||||
[self lockFocus];
|
||||
[imageCell drawWithFrame: imageRect inView: self];
|
||||
[self unlockFocus];
|
||||
|
||||
// move the drawing rect over like in the drawRow routine...
|
||||
drawingRect.origin.x += indentationFactor + 5 + [image size].width;
|
||||
drawingRect.size.width -= indentationFactor + 5 + [image size].width;
|
||||
|
||||
RELEASE(imageCell);
|
||||
}
|
||||
|
||||
if (flag)
|
||||
|
|
|
@ -130,6 +130,9 @@ typedef struct _tableViewFlags
|
|||
- (void)_setObjectValue: (id)value
|
||||
forTableColumn: (NSTableColumn *)tb
|
||||
row: (int)index;
|
||||
|
||||
- (BOOL) _isCellEditableColumn: (int) columnIndex
|
||||
row: (int) rowIndex;
|
||||
@end
|
||||
|
||||
@interface NSTableView (SelectionHelper)
|
||||
|
@ -1910,23 +1913,6 @@ static void computeNewSelection
|
|||
}
|
||||
}
|
||||
|
||||
static inline BOOL
|
||||
_isCellEditable (id delegate, NSArray *tableColumns,
|
||||
NSTableView *tableView, int row, int column)
|
||||
{
|
||||
{
|
||||
NSTableColumn *tb;
|
||||
tb = [tableColumns objectAtIndex: column];
|
||||
if ([tableView _shouldEditTableColumn: tb
|
||||
row: row] == NO)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
@interface GSTableCornerView : NSView
|
||||
{}
|
||||
@end
|
||||
|
@ -2505,6 +2491,7 @@ _isCellEditable (id delegate, NSArray *tableColumns,
|
|||
{
|
||||
return _backgroundColor;
|
||||
}
|
||||
|
||||
- (void) setUsesAlternatingRowBackgroundColors: (BOOL)useAlternatingRowColors
|
||||
{
|
||||
// FIXME
|
||||
|
@ -3217,7 +3204,7 @@ byExtendingSelection: (BOOL)flag
|
|||
// of editing.
|
||||
if (_dataSource_editable == NO)
|
||||
{
|
||||
return;
|
||||
flag = YES;
|
||||
}
|
||||
|
||||
[self scrollRowToVisible: rowIndex];
|
||||
|
@ -3256,7 +3243,7 @@ byExtendingSelection: (BOOL)flag
|
|||
// NB: need to be released when no longer used
|
||||
_editedCell = [[tb dataCellForRow: rowIndex] copy];
|
||||
|
||||
[_editedCell setEditable: YES];
|
||||
[_editedCell setEditable: _dataSource_editable];
|
||||
[_editedCell setObjectValue: [self _objectValueForTableColumn: tb
|
||||
row: rowIndex]];
|
||||
/* [_dataSource tableView: self
|
||||
|
@ -3373,6 +3360,13 @@ static inline float computePeriod(NSPoint mouseLocationWin,
|
|||
return;
|
||||
}
|
||||
|
||||
/* Stop editing if any */
|
||||
if (_textObject != nil)
|
||||
{
|
||||
[self validateEditing];
|
||||
[self abortEditing];
|
||||
}
|
||||
|
||||
// Determine row and column which were clicked
|
||||
location = [self convertPoint: initialLocation fromView: nil];
|
||||
_clickedRow = [self rowAtPoint: location];
|
||||
|
@ -3381,17 +3375,13 @@ static inline float computePeriod(NSPoint mouseLocationWin,
|
|||
if (clickCount == 2)
|
||||
{
|
||||
// Double-click event
|
||||
NSTableColumn *tb;
|
||||
|
||||
if ([self isRowSelected: _clickedRow] == NO)
|
||||
if (![self isRowSelected: _clickedRow])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
tb = [_tableColumns objectAtIndex: _clickedColumn];
|
||||
if (([tb isEditable] == NO) ||
|
||||
([self _shouldEditTableColumn: tb
|
||||
row: _clickedRow] == NO))
|
||||
if (![self _isCellEditableColumn: _clickedColumn row: _clickedRow ])
|
||||
{
|
||||
// Send double-action but don't edit
|
||||
[self sendAction: _doubleAction to: _target];
|
||||
|
@ -5486,7 +5476,7 @@ static inline float computePeriod(NSPoint mouseLocationWin,
|
|||
// First look for cells in the same row
|
||||
for (j = column + 1; j < _numberOfColumns; j++)
|
||||
{
|
||||
if (_isCellEditable (_delegate, _tableColumns, self, row, j) == YES)
|
||||
if ([self _isCellEditableColumn: j row: row])
|
||||
{
|
||||
[self editColumn: j row: row withEvent: nil select: YES];
|
||||
return YES;
|
||||
|
@ -5500,7 +5490,7 @@ static inline float computePeriod(NSPoint mouseLocationWin,
|
|||
[self selectRow: i byExtendingSelection: NO];
|
||||
for (j = 0; j < _numberOfColumns; j++)
|
||||
{
|
||||
if (_isCellEditable (_delegate, _tableColumns, self, i, j) == YES)
|
||||
if ([self _isCellEditableColumn: j row: i])
|
||||
{
|
||||
[self editColumn: j row: i withEvent: nil select: YES];
|
||||
return YES;
|
||||
|
@ -5509,6 +5499,7 @@ static inline float computePeriod(NSPoint mouseLocationWin,
|
|||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
-(BOOL) _editPreviousEditableCellBeforeRow: (int)row
|
||||
column: (int)column
|
||||
{
|
||||
|
@ -5518,7 +5509,7 @@ static inline float computePeriod(NSPoint mouseLocationWin,
|
|||
// First look for cells in the same row
|
||||
for (j = column - 1; j > -1; j--)
|
||||
{
|
||||
if (_isCellEditable (_delegate, _tableColumns, self, row, j) == YES)
|
||||
if ([self _isCellEditableColumn: j row: row])
|
||||
{
|
||||
[self editColumn: j row: row withEvent: nil select: YES];
|
||||
return YES;
|
||||
|
@ -5532,7 +5523,7 @@ static inline float computePeriod(NSPoint mouseLocationWin,
|
|||
[self selectRow: i byExtendingSelection: NO];
|
||||
for (j = _numberOfColumns - 1; j > -1; j--)
|
||||
{
|
||||
if (_isCellEditable (_delegate, _tableColumns, self, i, j) == YES)
|
||||
if ([self _isCellEditableColumn: j row: i])
|
||||
{
|
||||
[self editColumn: j row: i withEvent: nil select: YES];
|
||||
return YES;
|
||||
|
@ -5541,6 +5532,7 @@ static inline float computePeriod(NSPoint mouseLocationWin,
|
|||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void) _autosaveTableColumns
|
||||
{
|
||||
if (_autosaveTableColumns && _autosaveName != nil)
|
||||
|
@ -6017,13 +6009,27 @@ static inline float computePeriod(NSPoint mouseLocationWin,
|
|||
row: (int) rowIndex
|
||||
{
|
||||
if ([_delegate respondsToSelector:
|
||||
@selector(tableView:shouldEditTableColumn:row:)])
|
||||
@selector(tableView:shouldEditTableColumn:row:)])
|
||||
{
|
||||
if ([_delegate tableView: self shouldEditTableColumn: tableColumn
|
||||
row: rowIndex] == NO)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
return [_delegate tableView: self shouldEditTableColumn: tableColumn
|
||||
row: rowIndex] == NO;
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL) _isCellEditableColumn: (int) columnIndex
|
||||
row: (int) rowIndex
|
||||
|
||||
{
|
||||
NSTableColumn *tableColumn;
|
||||
|
||||
tableColumn = [_tableColumns objectAtIndex: columnIndex];
|
||||
// If the column is editable, the cell always is
|
||||
if (![tableColumn isEditable])
|
||||
{
|
||||
// otherwise ask the delegate, if any.
|
||||
[self _shouldEditTableColumn: tableColumn row: rowIndex];
|
||||
}
|
||||
|
||||
return YES;
|
||||
|
|
Loading…
Reference in a new issue