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

View file

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

View file

@ -278,6 +278,7 @@ static NSArray *XmlReferenceAttributes = nil;
@"column" : @"NSMutableArray", @"column" : @"NSMutableArray",
@"tabStops" : @"NSMutableArray", @"tabStops" : @"NSMutableArray",
@"userDefinedRuntimeAttributes" : @"NSMutableArray", @"userDefinedRuntimeAttributes" : @"NSMutableArray",
@"resources" : @"NSMutableArray",
@"customObject" : @"NSCustomObject5", @"customObject" : @"NSCustomObject5",
@"userDefinedRuntimeAttribute" : @"IBUserDefinedRuntimeAttribute5", @"userDefinedRuntimeAttribute" : @"IBUserDefinedRuntimeAttribute5",
//@"outlet" : @"IBOutletConnection5", //@"outlet" : @"IBOutletConnection5",
@ -328,7 +329,7 @@ static NSArray *XmlReferenceAttributes = nil;
XmlKeysDefined = @[ @"NSWTFlags", @"NSvFlags", @"NSBGColor", XmlKeysDefined = @[ @"NSWTFlags", @"NSvFlags", @"NSBGColor",
@"NSSize", //@"IBIsSystemFont", @"NSSize", //@"IBIsSystemFont",
@"NSHeaderClipView", @"NSHScroller", @"NSVScroller", @"NSsFlags", @"NSHeaderClipView", @"NSHScroller", @"NSVScroller", @"NSsFlags",
@"NSTvFlags", @"NScvFlags", @"NSColumnAutoresizingStyle", @"NSTvFlags", @"NScvFlags",
@"NSSupport", @"NSName", @"NSSupport", @"NSName",
@"NSMenuItem", @"NSMenuItem",
@"NSDocView", @"NSDocView",
@ -1553,11 +1554,13 @@ didStartElement: (NSString*)elementName
{ {
NSTableHeaderView *headerView = [self decodeObjectForKey: @"headerView"]; NSTableHeaderView *headerView = [self decodeObjectForKey: @"headerView"];
id object = [[NSClipView alloc] initWithFrame: [headerView frame]]; id object = [[NSClipView alloc] initWithFrame: [headerView frame]];
#if 0 #if 0
[object setAutoresizesSubviews: YES]; [object setAutoresizesSubviews: YES];
[object setAutoresizingMask: NSViewWidthSizable | NSViewMaxYMargin]; [object setAutoresizingMask: NSViewWidthSizable | NSViewMaxYMargin];
[object setDocumentView: headerView];
#endif #endif
[object setNextKeyView: headerView];
[object setDocumentView: headerView];
return object; return object;
} }
@ -1600,17 +1603,25 @@ didStartElement: (NSString*)elementName
NSWarnMLog(@"gridStyleMask: %@", gridStyleMask); NSWarnMLog(@"gridStyleMask: %@", gridStyleMask);
#endif #endif
mask.flags.columnOrdering = [[attributes objectForKey: @"columnReordering"] boolValue]; mask.flags.columnOrdering = YES; // check if present - see below...
mask.flags.columnResizing = [[attributes objectForKey: @"columnResizing"] boolValue]; mask.flags.columnResizing = YES; // check if present - see below...
mask.flags.drawsGrid = (gridStyleMask != nil); mask.flags.drawsGrid = (gridStyleMask != nil);
mask.flags.emptySelection = YES; // check if present - see below... 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.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"]) if ([attributes objectForKey: @"emptySelection"])
mask.flags.emptySelection = [[attributes objectForKey: @"emptySelection"] boolValue]; 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, // Unknown: typeSelect,
return [NSNumber numberWithUnsignedInteger: mask.value]; return [NSNumber numberWithUnsignedInteger: mask.value];
@ -2365,6 +2376,62 @@ didStartElement: (NSString*)elementName
return object; 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... #pragma mark - Overridden decoding methods from base class...
- (id) objectForXib: (GSXibElement*)element - (id) objectForXib: (GSXibElement*)element
{ {
@ -2431,61 +2498,6 @@ didStartElement: (NSString*)elementName
return object; 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 - (id) decodeObjectForXib: (GSXibElement*)element
forClassName: (NSString*)classname forClassName: (NSString*)classname
withID: (NSString*)objID withID: (NSString*)objID
@ -2742,11 +2754,17 @@ didStartElement: (NSString*)elementName
GSXib5Element *element = [objects objectForKey:idString]; GSXib5Element *element = [objects objectForKey:idString];
object = [self objectForXib: element]; object = [self objectForXib: element];
} }
else else if ([currentElement attributeForKey: key])
{ {
// New xib stores values as attributes... // New xib stores values as attributes...
object = [currentElement attributeForKey: key]; object = [currentElement attributeForKey: key];
} }
#if defined(DEBUG)
else // DEBUG ONLY...
{
NSWarnMLog(@"no element/attribute for key: %@", key);
}
#endif
} }
#if 0 #if 0

View file

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