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

@ -3227,12 +3227,19 @@ typedef enum {
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])
backgroundColor = [rowColors objectAtIndex: (row % rowColorCount)];
// Switch to the alternate color if the backgroundColor is white.
if([backgroundColor isEqual: [NSColor whiteColor]]) if([backgroundColor isEqual: [NSColor whiteColor]])
{ {
selectionColor = [NSColor colorWithCalibratedRed: 0.86 selectionColor = [NSColor colorWithCalibratedRed: 0.86

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,16 +1603,24 @@ 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,
@ -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

@ -5206,6 +5206,9 @@ This method is deprecated, use -columnIndexesInRect:. */
- (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];
} }
@ -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];
@ -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];
} }
} }