1// 2// SubviewTableViewCell.m 3// SubviewTableViewRuleEditor 4// 5// Created by Joar Wingfors on Sat Feb 15 2003. 6// Copyright (c) 2003 joar.com. All rights reserved. 7// 8 9#import "SubviewTableViewCell.h" 10 11#import "SubviewTableViewController.h" 12#import "PXLayerDetailsView.h" 13 14@implementation SubviewTableViewCell 15 16- (void) addSubview:(NSView *) view 17{ 18 // Weak reference 19 subview = view; 20} 21 22- (void) dealloc 23{ 24 subview = nil; 25 [super dealloc]; 26} 27 28- (NSView *) view 29{ 30 return subview; 31} 32 33- (void) drawWithFrame:(NSRect) cellFrame inView:(NSView *) controlView 34{ 35 if ([[self view] isKindOfClass:[PXLayerDetailsView class]]) 36 { 37 if ([self isHighlighted]) 38 { 39 [[[self view] opacityText] setTextColor:[NSColor whiteColor]]; 40 } 41 else 42 { 43 [[[self view] opacityText] setTextColor:[NSColor blackColor]]; 44 } 45 } 46 [super drawWithFrame: cellFrame inView: controlView]; 47 [[self view] setFrame: cellFrame]; 48 if([[self view] superview] != controlView) 49 { 50 [controlView addSubview:[self view]]; 51 } 52} 53 54- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView 55{ 56 NSImage *gradient; 57 /* Determine whether we should draw a blue or grey gradient. */ 58 /* We will automatically redraw when our parent view loses/gains focus, 59 or when our parent window loses/gains main/key status. */ 60 if (([[controlView window] firstResponder] == controlView) && 61 [[controlView window] isMainWindow] && 62 [[controlView window] isKeyWindow]) { 63 gradient = [NSImage imageNamed:@"highlight_blue.tiff"]; 64 } else { 65 gradient = [NSImage imageNamed:@"highlight_grey.tiff"]; 66 } 67 68 /* Make sure we draw the gradient the correct way up. */ 69 [gradient setFlipped:YES]; 70 int i = 0; 71 72 if ([self isHighlighted]) { 73 [controlView lockFocus]; 74 75 /* We're selected, so draw the gradient background. */ 76 NSSize gradientSize = [gradient size]; 77 for (i = cellFrame.origin.x; i < (cellFrame.origin.x + cellFrame.size.width); i += gradientSize.width) { 78 [gradient drawInRect:NSMakeRect(i, cellFrame.origin.y, gradientSize.width, cellFrame.size.height) 79 fromRect:NSMakeRect(0, 0, gradientSize.width, gradientSize.height) 80 operation:NSCompositeSourceOver 81 fraction:1.0]; 82 } 83 84 /* Now draw our text in white. *//* 85 NSRect inset = cellFrame; 86 inset.origin.x += 2; // Nasty to hard-code this. Can we get it to draw its own content, or determine correct inset? 87 NSMutableDictionary *attrs = [NSMutableDictionary dictionaryWithDictionary:[[self attributedStringValue] attributesAtIndex:0 effectiveRange:NULL]]; 88 [attrs setValue:[NSColor whiteColor] forKey:@"NSColor"]; 89 [[self stringValue] drawInRect:inset withAttributes:attrs];*/ 90 91 [controlView unlockFocus]; 92 } else { 93 /* We're not selected, so ask our superclass to draw our content normally. */ 94 //cellFrame.origin.y += 4; 95 //cellFrame.size.height -= 4; 96 cellFrame.origin.y -= 4; 97 cellFrame.origin.y += 8; 98 [super drawInteriorWithFrame:cellFrame inView:controlView]; 99 } 100} 101 102- copyWithZone:(NSZone *)zone 103{ 104 id new = [[[self class] allocWithZone:zone] init]; 105 [new addSubview:([subview conformsToProtocol:@protocol(NSCopying)] ? [subview copy] : subview)]; 106 return new; 107} 108 109@end 110