Commits

Anonymous committed 9ea74dd

Fixed repeated gradients in instances of StyledTextFieldCell should the glyph be taller than the distance between its ascender & descender line by reverting the gradient calculation code, basing it on the size of the controlView. Minor housekeeping.

Comments (0)

Files changed (4)

 
 - (void) drawRect:(NSRect)rect {
 
+	if ((self.bounds.size.width == 0) || (self.bounds.size.height == 0)) return;
+	
 	if (hasGradient) {
 
 		NSGradient *gradient = [[NSGradient alloc] initWithStartingColor:fillStartingColor endingColor:fillEndingColor];

BWSelectableToolbar.m

 	NSArray *defaultItemIdentfiers = [super _defaultItemIdentifiers];
 	NSArray *defaultIBItemIdentifiers = [NSArray arrayWithObjects:@"NSToolbarSeparatorItem",@"NSToolbarSpaceItem",@"NSToolbarFlexibleSpaceItem",nil];
 	
-	NSArray *idealDefaultItemIdentifiers = [NSArray arrayWithObjects:@"0D5950D1-D4A8-44C6-9DBC-251CFEF852E2",@"BWToolbarShowColorsItem",
-											@"BWToolbarShowFontsItem",@"7E6A9228-C9F3-4F21-8054-E4BF3F2F6BA8",nil];
+	NSArray *idealDefaultItemIdentifiers = [NSArray arrayWithObjects:@"0D5950D1-D4A8-44C6-9DBC-251CFEF852E2",@"BWToolbarShowColorsItem", @"BWToolbarShowFontsItem",@"7E6A9228-C9F3-4F21-8054-E4BF3F2F6BA8",nil];
 	
 	if ([defaultItemIdentfiers isEqualToArray:defaultIBItemIdentifiers])
 	{
 		[self setEditableToolbar:self];
 		
 		if ([helper contentViewsByIdentifier].count == 0)
-			[helper setInitialIBWindowSize:[[[self editableToolbar] _window] frame].size];
+		[helper setInitialIBWindowSize:[[[self editableToolbar] _window] frame].size];
 			
-		[[NSNotificationCenter defaultCenter] addObserver:self 
-												 selector:@selector(windowDidResize:)
-													 name:NSWindowDidResizeNotification 
-												   object:[[self editableToolbar] _window]];
+		[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidResize:) name:NSWindowDidResizeNotification object:[[self editableToolbar] _window]];
 
 	}
 	

BWSelectableToolbarIntegration.m

 	[super ibDocument:fp8 willStartSimulatorWithContext:fp12];
 	
 	// Simulating seems to work fine in IB 3.1.1 (672) so we won't show the alert if the user is running that version
-	if ([[IBDocument currentIBFrameworkVersion] intValue] != 672)
+	if ([[IBDocument currentIBFrameworkVersion] intValue] <= 672)
 	{
 		NSAlert *alert = [NSAlert alertWithMessageText:@"Toolbar not compatible with simulator" defaultButton:@"OK" alternateButton:nil otherButton:nil informativeTextWithFormat:@"The selectable toolbar is not yet compatible with the IB simulator. Quit the simulator and revert to the last saved document. Sorry for the inconvenience."];
 		[alert runModal];

BWStyledTextFieldCell.m

 
 #pragma mark Shadow-specific code
 
-- (void)changeShadow
-{
+- (void)changeShadow {
+
 	NSShadow *tempShadow = [[[NSShadow alloc] init] autorelease];
 	[tempShadow setShadowColor:shadowColor];
 		
 	if ([[self controlView] window] == nil)
 		return;
 	
-	if (self.hasGradient)
-	{	
-		float textHeight = [[self font] ascender] - [[self font] descender];
-		
-		NSSize boundSizeWithFullWidth = NSMakeSize([self controlView].frame.size.width,ceilf(textHeight));
-		
-		NSImage *image = [[[NSImage alloc] initWithSize:boundSizeWithFullWidth] autorelease];
-		
-		NSGradient *gradient = [[[NSGradient alloc] initWithStartingColor:self.startingColor endingColor:self.endingColor] autorelease];
-		
-		[image lockFocus];
-		[gradient drawInRect:NSMakeRect(0,0,boundSizeWithFullWidth.width,boundSizeWithFullWidth.height) angle:270];
-		[image unlockFocus];
-		
-		NSColor *color = [NSColor colorWithPatternImage:image];
-		
-		[self setTextColor:color];
-	}
+	if (!self.hasGradient) return;
+	
+	NSSize boundSizeWithFullWidth = NSMakeSize(
+							   
+		[self controlView].frame.size.width,
+		[self controlView].frame.size.height
+						   
+	);
+	
+	NSLog(@"Bound size: %f, %f", [self controlView].frame.size.width, [self controlView].frame.size.height);
+	
+	NSImage *image = [[[NSImage alloc] initWithSize:boundSizeWithFullWidth] autorelease];
+	
+	NSGradient *gradient = [[[NSGradient alloc] initWithStartingColor:self.startingColor endingColor:self.endingColor] autorelease];
+	
+	[image lockFocus];
+	[gradient drawInRect:NSMakeRect(0,0,boundSizeWithFullWidth.width,boundSizeWithFullWidth.height) angle:270];
+	[image unlockFocus];
+	
+	NSColor *color = [NSColor colorWithPatternImage:image];
+	
+	[self setTextColor:color];
+
 }
 
 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
     }
 }
 
-- (void)setSolidColor:(NSColor *)color
-{
-	if (solidColor != color) 
-	{
+- (void)setSolidColor:(NSColor *)color {
+
+	if (solidColor == color) return;
+
         [solidColor release];
         solidColor = [color retain];
 		
-		[self setTextColor:solidColor];
-    }
+	[self setTextColor:solidColor];
+	
 }
 
-- (void)setHasGradient:(BOOL)flag
-{
+
+
+
+
+- (void)setHasGradient:(BOOL)flag {
+
 	hasGradient = flag;
 	
-	if (flag)
+	if (flag) {
+		
 		[self applyGradient];
-	else
+		
+	} else {
+
 		[self setTextColor:self.solidColor];
+		
+	}
+
 }
 
-- (void)setShadowIsBelow:(BOOL)flag
-{
+
+
+
+
+- (void)setShadowIsBelow:(BOOL)flag {
+
 	shadowIsBelow = flag;
-	
 	[self changeShadow];
+
 }
 
-- (void)setShadowColor:(NSColor *)color
-{
-	if (shadowColor != color) 
-	{
+
+
+
+
+- (void)setShadowColor:(NSColor *)color {
+
+	if (shadowColor == color) return;
+
         [shadowColor release];
         shadowColor = [color retain];
 		
-		[self changeShadow];
-    }
+	[self changeShadow];
+
 }
 
 @end