diff --git a/ChangeLog b/ChangeLog index 24a6c66d1..144ea8294 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2015-09-20 Fred Kiefer + + * Source/GSThemeDrawing.m (-drawTableViewRect:inView:): Use + correct imp type. + * Source/NSButtonCell.m (-setBackgroundColor:): Update the + control view. + * Source/NSSegmentedCell.m (-drawSegment:inFrame:withView:): Draw + image if available. + * Source/NSPopUpButtonCell.m (-initWithCoder:): Add work around + for NSClassSwapper cell replacement. + Patches based on changes by Josh Freeman + 2015-09-19 Fred Kiefer * Headers/AppKit/NSMenu.h, diff --git a/Source/GSThemeDrawing.m b/Source/GSThemeDrawing.m index 08b10ab78..14c5919e3 100644 --- a/Source/GSThemeDrawing.m +++ b/Source/GSThemeDrawing.m @@ -2999,11 +2999,13 @@ typedef enum { // NSLog(@"drawRect : %d-%d", startingRow, endingRow); { SEL sel = @selector(drawRow:clipRect:); - IMP imp = [tableView methodForSelector: sel]; + void (*imp)(id, SEL, NSInteger, NSRect); + + imp = (void (*)(id, SEL, NSInteger, NSRect))[tableView methodForSelector: sel]; for (i = startingRow; i <= endingRow; i++) { - (*imp)(tableView, sel, i, aRect); + imp(tableView, sel, i, aRect); } } } diff --git a/Source/NSButtonCell.m b/Source/NSButtonCell.m index 7647c7e25..24abae61d 100644 --- a/Source/NSButtonCell.m +++ b/Source/NSButtonCell.m @@ -931,6 +931,14 @@ typedef struct _GSButtonCellFlags - (void) setBackgroundColor: (NSColor *)color { ASSIGN(_backgroundColor, color); + + if (_control_view) + { + if ([_control_view isKindOfClass: [NSControl class]]) + { + [(NSControl*)_control_view updateCell: self]; + } + } } - (GSThemeControlState) themeControlState diff --git a/Source/NSPopUpButtonCell.m b/Source/NSPopUpButtonCell.m index 637996e45..729c32d0a 100644 --- a/Source/NSPopUpButtonCell.m +++ b/Source/NSPopUpButtonCell.m @@ -1243,8 +1243,27 @@ static NSImage *_pbc_image[5]; { /* First decode menu, menu items must be available to set the selection */ menu = [aDecoder decodeObjectForKey: @"NSMenu"]; - [self setMenu: nil]; - [self setMenu: menu]; + if (menu) + { + NSEnumerator *menuItemEnumerator; + NSMenuItem *menuItem; + + [self setMenu: nil]; + [self setMenu: menu]; + + // FIXME: This special handling is needed bacause the NSClassSwapper + // might have replaced the cell, but the items still refere to it. + menuItemEnumerator = [[menu itemArray] objectEnumerator]; + + while ((menuItem = [menuItemEnumerator nextObject]) != nil) + { + if (sel_isEqual([menuItem action], @selector(_popUpItemAction:)) + && ([menuItem target] != self)) + { + [menuItem setTarget: self]; + } + } + } if ([aDecoder containsValueForKey: @"NSAltersState"]) { diff --git a/Source/NSSegmentedCell.m b/Source/NSSegmentedCell.m index 92c968da2..e341c7cdc 100644 --- a/Source/NSSegmentedCell.m +++ b/Source/NSSegmentedCell.m @@ -544,28 +544,28 @@ withView: (NSView *)view { id segment = [_items objectAtIndex: seg]; - NSString *label = [segment label]; - NSSize textSize = [label sizeWithAttributes: [NSDictionary dictionary]]; - NSRect textFrame = frame; - CGFloat x_offset = (frame.size.width - textSize.width) / 2; + NSString *label = [self labelForSegment: seg]; + NSImage *segmentImage = [self imageForSegment: seg]; GSThemeControlState state = GSThemeNormalState; BOOL roundedLeft = NO; BOOL roundedRight = NO; - textFrame.origin.x += x_offset; - textFrame.size.width -= x_offset; [segment setFrame: frame]; - if([segment isSelected]) + if ([segment isSelected]) { state = GSThemeSelectedState; } if (seg == 0) - roundedLeft = YES; + { + roundedLeft = YES; + } if (seg == ([_items count] - 1)) - roundedRight = YES; + { + roundedRight = YES; + } [[GSTheme theme] drawSegmentedControlSegment: self withFrame: frame @@ -574,7 +574,32 @@ state: state roundedLeft: roundedLeft roundedRight: roundedRight]; - [self _drawText: [segment label] inFrame: textFrame]; + if (label) + { + NSSize textSize = [label sizeWithAttributes: [self _nonAutoreleasedTypingAttributes]]; + NSRect textFrame = frame; + CGFloat x_offset = (frame.size.width - textSize.width) / 2; + + textFrame.origin.x += x_offset; + textFrame.size.width -= x_offset; + [self _drawText: label inFrame: textFrame]; + } + + if (segmentImage) + { + NSSize size = [segmentImage size]; + NSPoint position; + NSRect destinationRect; + + position.x = MAX(NSMidX(frame) - (size.width/2.), 0.); + position.y = MAX(NSMidY(frame) - (size.height/2.), 0.); + destinationRect = NSMakeRect(position.x, position.y, size.width, size.height); + + [segmentImage drawInRect: destinationRect + fromRect: NSZeroRect + operation: NSCompositeSourceOver + fraction: 1.0]; + } } - (void) drawInteriorWithFrame: (NSRect)cellFrame