Fix table header column resizing using XIB 5 loading

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/branches/gnustep_testplant_branch@40313 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Marcian Lytwyn 2017-01-30 21:19:28 +00:00
parent ee842f0a0e
commit 00fa6f5863
4 changed files with 187 additions and 158 deletions

View file

@ -131,7 +131,7 @@ typedef struct _tableViewFlags
NSColor *_gridColor;
NSColor *_backgroundColor;
NSTableViewSelectionHighlightStyle _selectionHighlightStyle;
CGFloat _rowHeight;
CGFloat _rowHeight;
NSSize _intercellSpacing;
id _delegate;
NSTableHeaderView *_headerView;
@ -142,8 +142,8 @@ typedef struct _tableViewFlags
NSInteger _clickedRow;
NSInteger _clickedColumn;
NSTableColumn *_highlightedTableColumn;
NSMutableIndexSet *_selectedColumns;
NSMutableIndexSet *_selectedRows;
NSMutableIndexSet *_selectedColumns;
NSMutableIndexSet *_selectedRows;
NSInteger _selectedColumn;
NSInteger _selectedRow;
BOOL _allowsMultipleSelection;

View file

@ -2918,7 +2918,7 @@ typedef enum {
}
- (void)drawTableHeaderRect: (NSRect)aRect
inView: (NSView *)view
inView: (NSView *)view
{
NSTableHeaderView *tableHeaderView = (NSTableHeaderView *)view;
NSTableView *tableView = [tableHeaderView tableView];
@ -2996,15 +2996,15 @@ typedef enum {
}
- (void) drawPopUpButtonCellInteriorWithFrame: (NSRect)cellFrame
withCell: (NSCell *)cell
inView: (NSView *)controlView
withCell: (NSCell *)cell
inView: (NSView *)controlView
{
// Default implementation of this method does nothing.
}
- (void) drawTableViewBackgroundInClipRect: (NSRect)aRect
inView: (NSView *)view
withBackgroundColor: (NSColor *)backgroundColor
inView: (NSView *)view
withBackgroundColor: (NSColor *)backgroundColor
{
NSTableView *tableView = (NSTableView *)view;
@ -3012,45 +3012,45 @@ typedef enum {
NSRectFill (aRect);
if ([tableView usesAlternatingRowBackgroundColors])
{
const CGFloat rowHeight = [tableView rowHeight];
NSInteger startingRow = [tableView rowAtPoint: NSMakePoint(0, NSMinY(aRect))];
NSInteger endingRow;
NSInteger i;
NSArray *rowColors = [NSColor controlAlternatingRowBackgroundColors];
const NSUInteger rowColorCount = [rowColors count];
NSRect rowRect;
if (rowHeight <= 0
|| rowColorCount == 0
|| aRect.size.height <= 0)
return;
if (startingRow <= 0)
startingRow = 0;
rowRect = [tableView rectOfRow: startingRow];
rowRect.origin.x = aRect.origin.x;
rowRect.size.width = aRect.size.width;
endingRow = startingRow + ceil(aRect.size.height / rowHeight);
for (i = startingRow; i <= endingRow; i++)
{
NSColor *color = [rowColors objectAtIndex: (i % rowColorCount)];
[color set];
NSRectFill(rowRect);
rowRect.origin.y += rowHeight;
}
}
{
const CGFloat rowHeight = [tableView rowHeight];
NSInteger startingRow = [tableView rowAtPoint: NSMakePoint(0, NSMinY(aRect))];
NSInteger endingRow;
NSInteger i;
NSArray *rowColors = [NSColor controlAlternatingRowBackgroundColors];
const NSUInteger rowColorCount = [rowColors count];
NSRect rowRect;
if (rowHeight <= 0
|| rowColorCount == 0
|| aRect.size.height <= 0)
return;
if (startingRow <= 0)
startingRow = 0;
rowRect = [tableView rectOfRow: startingRow];
rowRect.origin.x = aRect.origin.x;
rowRect.size.width = aRect.size.width;
endingRow = startingRow + ceil(aRect.size.height / rowHeight);
for (i = startingRow; i <= endingRow; i++)
{
NSColor *color = [rowColors objectAtIndex: (i % rowColorCount)];
[color set];
NSRectFill(rowRect);
rowRect.origin.y += rowHeight;
}
}
}
- (void) drawTableViewGridInClipRect: (NSRect)aRect
inView: (NSView *)view
inView: (NSView *)view
{
NSTableView *tableView = (NSTableView *)view;
@ -3115,7 +3115,7 @@ typedef enum {
}
- (void) drawTableViewRect: (NSRect)aRect
inView: (NSView *)view
inView: (NSView *)view
{
int startingRow;
int endingRow;
@ -3185,24 +3185,24 @@ typedef enum {
// Set the fill color
{
NSColor *selectionColor;
selectionColor = [self colorNamed: @"highlightedTableRowBackgroundColor"
state: GSThemeNormalState];
state: GSThemeNormalState];
if (selectionColor == nil)
{
// Switch to the alternate color of the backgroundColor is white.
if([backgroundColor isEqual: [NSColor whiteColor]])
{
selectionColor = [NSColor colorWithCalibratedRed: 0.86
green: 0.92
blue: 0.99
alpha: 1.0];
}
else
{
selectionColor = [NSColor whiteColor];
}
// Switch to the alternate color of the backgroundColor is white.
if([backgroundColor isEqual: [NSColor whiteColor]])
{
selectionColor = [NSColor colorWithCalibratedRed: 0.86
green: 0.92
blue: 0.99
alpha: 1.0];
}
else
{
selectionColor = [NSColor whiteColor];
}
}
[selectionColor set];
}
@ -3216,41 +3216,48 @@ typedef enum {
selectedRowsCount = [selectedRows count];
if (selectedRowsCount == 0)
return;
return;
/* highlight selected rows */
startingRow = [tableView rowAtPoint: NSMakePoint(0, NSMinY(clipRect))];
endingRow = [tableView rowAtPoint: NSMakePoint(0, NSMaxY(clipRect))];
if (startingRow == -1)
startingRow = 0;
startingRow = 0;
if (endingRow == -1)
endingRow = numberOfRows - 1;
endingRow = numberOfRows - 1;
// FIXME: Take alternating row coloring into account...
NSArray *rowColors = [NSColor controlAlternatingRowBackgroundColors];
const NSUInteger rowColorCount = [rowColors count];
row = [selectedRows indexGreaterThanOrEqualToIndex: startingRow];
while ((row != NSNotFound) && (row <= endingRow))
{
NSColor *selectionColor = nil;
// Switch to the alternate color of the backgroundColor is white.
if([backgroundColor isEqual: [NSColor whiteColor]])
{
selectionColor = [NSColor colorWithCalibratedRed: 0.86
{
NSColor *selectionColor = nil;
if ([tableView usesAlternatingRowBackgroundColors])
backgroundColor = [rowColors objectAtIndex: (row % rowColorCount)];
// Switch to the alternate color if the backgroundColor is white.
if([backgroundColor isEqual: [NSColor whiteColor]])
{
selectionColor = [NSColor colorWithCalibratedRed: 0.86
green: 0.92
blue: 0.99
alpha: 1.0];
}
else
{
selectionColor = [NSColor whiteColor];
}
}
else
{
selectionColor = [NSColor whiteColor];
}
//NSHighlightRect(NSIntersectionRect([tableView rectOfRow: row],
// clipRect));
[selectionColor set];
NSRectFill(NSIntersectionRect([tableView rectOfRow: row], clipRect));
row = [selectedRows indexGreaterThanIndex: row];
}
//NSHighlightRect(NSIntersectionRect([tableView rectOfRow: row],
// clipRect));
[selectionColor set];
NSRectFill(NSIntersectionRect([tableView rectOfRow: row], clipRect));
row = [selectedRows indexGreaterThanIndex: row];
}
}
else // Selecting columns
{
@ -3281,9 +3288,9 @@ typedef enum {
}
}
- (void) drawTableViewRow: (int)rowIndex
clipRect: (NSRect)clipRect
inView: (NSView *)view
- (void) drawTableViewRow: (int)rowIndex
clipRect: (NSRect)clipRect
inView: (NSView *)view
{
NSTableView *tableView = (NSTableView *)view;
// int numberOfRows = [tableView numberOfRows];

View file

@ -278,6 +278,7 @@ static NSArray *XmlReferenceAttributes = nil;
@"column" : @"NSMutableArray",
@"tabStops" : @"NSMutableArray",
@"userDefinedRuntimeAttributes" : @"NSMutableArray",
@"resources" : @"NSMutableArray",
@"customObject" : @"NSCustomObject5",
@"userDefinedRuntimeAttribute" : @"IBUserDefinedRuntimeAttribute5",
//@"outlet" : @"IBOutletConnection5",
@ -328,7 +329,7 @@ static NSArray *XmlReferenceAttributes = nil;
XmlKeysDefined = @[ @"NSWTFlags", @"NSvFlags", @"NSBGColor",
@"NSSize", //@"IBIsSystemFont",
@"NSHeaderClipView", @"NSHScroller", @"NSVScroller", @"NSsFlags",
@"NSTvFlags", @"NScvFlags",
@"NSColumnAutoresizingStyle", @"NSTvFlags", @"NScvFlags",
@"NSSupport", @"NSName",
@"NSMenuItem",
@"NSDocView",
@ -1553,11 +1554,13 @@ didStartElement: (NSString*)elementName
{
NSTableHeaderView *headerView = [self decodeObjectForKey: @"headerView"];
id object = [[NSClipView alloc] initWithFrame: [headerView frame]];
#if 0
[object setAutoresizesSubviews: YES];
[object setAutoresizingMask: NSViewWidthSizable | NSViewMaxYMargin];
[object setDocumentView: headerView];
#endif
[object setNextKeyView: headerView];
[object setDocumentView: headerView];
return object;
}
@ -1600,17 +1603,25 @@ didStartElement: (NSString*)elementName
NSWarnMLog(@"gridStyleMask: %@", gridStyleMask);
#endif
mask.flags.columnOrdering = [[attributes objectForKey: @"columnReordering"] boolValue];
mask.flags.columnResizing = [[attributes objectForKey: @"columnResizing"] boolValue];
mask.flags.columnOrdering = YES; // check if present - see below...
mask.flags.columnResizing = YES; // check if present - see below...
mask.flags.drawsGrid = (gridStyleMask != nil);
mask.flags.emptySelection = YES; // check if present - see below...
mask.flags.multipleSelection = [[attributes objectForKey: @"multipleSelection"] boolValue];
mask.flags.multipleSelection = YES; // check if present - see below...
mask.flags.columnSelection = [[attributes objectForKey: @"columnSelection"] boolValue];
mask.flags.columnAutosave = [[attributes objectForKey: @"autosaveColumns"] boolValue];
mask.flags.columnAutosave = YES; // check if present - see below...
if ([attributes objectForKey: @"columnReordering"])
mask.flags.columnOrdering = [[attributes objectForKey: @"columnReordering"] boolValue];
if ([attributes objectForKey: @"columnResizing"])
mask.flags.columnResizing = [[attributes objectForKey: @"columnResizing"] boolValue];
if ([attributes objectForKey: @"emptySelection"])
mask.flags.emptySelection = [[attributes objectForKey: @"emptySelection"] boolValue];
if ([attributes objectForKey: @"multipleSelection"])
mask.flags.multipleSelection = [[attributes objectForKey: @"multipleSelection"] boolValue];
if ([attributes objectForKey: @"autosaveColumns"])
mask.flags.columnAutosave = [[attributes objectForKey: @"autosaveColumns"] boolValue];
// Unknown: typeSelect,
return [NSNumber numberWithUnsignedInteger: mask.value];
@ -2365,6 +2376,62 @@ didStartElement: (NSString*)elementName
return object;
}
#pragma mark - Object creation support methods...
- (id) nibInstantiate: (id)object
{
id theObject = object;
// Check whether object needs to be instantiated and awaken...
if ([theObject respondsToSelector: @selector(nibInstantiate)])
{
// If this is the file's owner see if there is a value in the context...
if ([theObject isKindOfClass: [NSCustomObject5 class]])
{
// Cross reference the file's owner object from the context data...
if ([[(NSCustomObject5*)theObject userLabel] isEqualToString: @"File's Owner"])
{
if ([_context objectForKey: NSNibOwner])
{
[(NSCustomObject*)theObject setRealObject: [_context objectForKey: NSNibOwner]];
}
}
}
// Instantiate the real object...
theObject = [theObject nibInstantiate];
}
return theObject;
}
- (void) awakeObjectFromNib: (id)object
{
// We are going to awaken objects here - we're assuming that all
// have been nibInstantiated when needed...
if ([object respondsToSelector: @selector(awakeFromNib)])
[object awakeFromNib];
}
- (Ivar) getClassVariableForObject: (id)object forName: (NSString*)property
{
const char *name = [property cString];
Class class = object_getClass(object);
Ivar ivar = class_getInstanceVariable(class, name);
// If not found...
if (ivar == 0)
{
// Try other permutations...
if ([property characterAtIndex: 0] == '_')
{
// Try removing the '_' prefix automatically added by Xcode...
ivar = [self getClassVariableForObject: object forName: [property substringFromIndex: 1]];
}
}
return ivar;
}
#pragma mark - Overridden decoding methods from base class...
- (id) objectForXib: (GSXibElement*)element
{
@ -2431,61 +2498,6 @@ didStartElement: (NSString*)elementName
return object;
}
- (id) nibInstantiate: (id)object
{
id theObject = object;
// Check whether object needs to be instantiated and awaken...
if ([theObject respondsToSelector: @selector(nibInstantiate)])
{
// If this is the file's owner see if there is a value in the context...
if ([theObject isKindOfClass: [NSCustomObject5 class]])
{
// Cross reference the file's owner object from the context data...
if ([[(NSCustomObject5*)theObject userLabel] isEqualToString: @"File's Owner"])
{
if ([_context objectForKey: NSNibOwner])
{
[(NSCustomObject*)theObject setRealObject: [_context objectForKey: NSNibOwner]];
}
}
}
// Instantiate the real object...
theObject = [theObject nibInstantiate];
}
return theObject;
}
- (void) awakeObjectFromNib: (id)object
{
// We are going to awaken objects here - we're assuming that all
// have been nibInstantiated when needed...
if ([object respondsToSelector: @selector(awakeFromNib)])
[object awakeFromNib];
}
- (Ivar) getClassVariableForObject: (id)object forName: (NSString*)property
{
const char *name = [property cString];
Class class = object_getClass(object);
Ivar ivar = class_getInstanceVariable(class, name);
// If not found...
if (ivar == 0)
{
// Try other permutations...
if ([property characterAtIndex: 0] == '_')
{
// Try removing the '_' prefix automatically added by Xcode...
ivar = [self getClassVariableForObject: object forName: [property substringFromIndex: 1]];
}
}
return ivar;
}
- (id) decodeObjectForXib: (GSXibElement*)element
forClassName: (NSString*)classname
withID: (NSString*)objID
@ -2742,11 +2754,17 @@ didStartElement: (NSString*)elementName
GSXib5Element *element = [objects objectForKey:idString];
object = [self objectForXib: element];
}
else
else if ([currentElement attributeForKey: key])
{
// New xib stores values as attributes...
object = [currentElement attributeForKey: key];
}
#if defined(DEBUG)
else // DEBUG ONLY...
{
NSWarnMLog(@"no element/attribute for key: %@", key);
}
#endif
}
#if 0

View file

@ -5175,8 +5175,8 @@ This method is deprecated, use -columnIndexesInRect:. */
- (void) drawRow: (NSInteger)rowIndex clipRect: (NSRect)clipRect
{
[[GSTheme theme] drawTableViewRow: rowIndex
clipRect: clipRect
inView: self];
clipRect: clipRect
inView: self];
}
- (void) noteHeightOfRowsWithIndexesChanged: (NSIndexSet*)indexes
@ -5187,27 +5187,30 @@ This method is deprecated, use -columnIndexesInRect:. */
- (void) drawGridInClipRect: (NSRect)aRect
{
[[GSTheme theme] drawTableViewGridInClipRect: aRect
inView: self];
inView: self];
}
- (void) highlightSelectionInClipRect: (NSRect)clipRect
{
[[GSTheme theme] highlightTableViewSelectionInClipRect: clipRect
inView: self
selectingColumns: _selectingColumns];
inView: self
selectingColumns: _selectingColumns];
}
- (void) drawBackgroundInClipRect: (NSRect)clipRect
{
[[GSTheme theme] drawTableViewBackgroundInClipRect: clipRect
inView: self
withBackgroundColor: _backgroundColor];
inView: self
withBackgroundColor: _backgroundColor];
}
- (void) drawRect: (NSRect)aRect
{
if ([[self autosaveName] isEqualToString:@"ConnectionList"])
NSLog(@"%s:%ld:aRect: %@ clipFrame: %@", __PRETTY_FUNCTION__, (long)__LINE__,
NSStringFromRect(aRect), NSStringFromRect([[self superview] frame]));
[[GSTheme theme] drawTableViewRect: aRect
inView: self];
inView: self];
}
- (BOOL) isOpaque
@ -5923,6 +5926,8 @@ This method is deprecated, use -columnIndexesInRect:. */
if ([aDecoder containsValueForKey: @"NSColumnAutoresizingStyle"])
{
_columnAutoresizingStyle = [aDecoder decodeIntForKey: @"NSColumnAutoresizingStyle"];
if ([[self autosaveName] isEqualToString: @"ConnectionList"])
NSLog(@"%s:%ld: _columnAutoresizingStyle: %ld", __PRETTY_FUNCTION__, (long)__LINE__, _columnAutoresizingStyle);
if (_columnAutoresizingStyle == NSTableViewUniformColumnAutoresizingStyle)
{
[self setAutoresizesAllColumnsToFit:YES];
@ -6065,7 +6070,7 @@ This method is deprecated, use -columnIndexesInRect:. */
}
- (void) _userResizedTableColumn: (NSInteger)index
width: (CGFloat)width
width: (CGFloat)width
{
[[_tableColumns objectAtIndex: index] setWidth: width];
}
@ -6081,8 +6086,7 @@ This method is deprecated, use -columnIndexesInRect:. */
respondsToSelector:
@selector(tableView:mouseDownInHeaderOfTableColumn:)])
{
[_delegate tableView: self
mouseDownInHeaderOfTableColumn: tc];
[_delegate tableView: self mouseDownInHeaderOfTableColumn: tc];
}
}