Browse Source

Fixes TreeView custom font positioning issues.

woollybah 9 years ago
parent
commit
9604ed793b
1 changed files with 31 additions and 7 deletions
  1. 31 7
      cocoamaxgui.mod/cocoa.macos.m

+ 31 - 7
cocoamaxgui.mod/cocoa.macos.m

@@ -295,6 +295,10 @@ void ScheduleEventDispatch(){
 -(NSMenu*)menuForEvent:(NSEvent *)theEvent;
 -(NSMenu*)menuForEvent:(NSEvent *)theEvent;
 @end
 @end
 
 
+@interface VerticalCenterAlignedBrowserCell : NSBrowserCell {
+}
+
+@end
 @interface NodeItem:NSObject{
 @interface NodeItem:NSObject{
 	TreeView		*owner;
 	TreeView		*owner;
 	NodeItem		*parent;
 	NodeItem		*parent;
@@ -323,9 +327,9 @@ void ScheduleEventDispatch(){
 @public
 @public
 	NSOutlineView	*outline;
 	NSOutlineView	*outline;
 	NSTableColumn	*column,*colin;
 	NSTableColumn	*column,*colin;
-	NSBrowserCell	*cell;
+	VerticalCenterAlignedBrowserCell	*cell;
 	NodeItem		*rootNode;
 	NodeItem		*rootNode;
-	NSDictionary	*textstyle;
+	NSMutableDictionary *textstyle;
 }
 }
 -(id)initWithFrame:(NSRect)rect;
 -(id)initWithFrame:(NSRect)rect;
 -(void)reloadItem:(id)item;
 -(void)reloadItem:(id)item;
@@ -1203,6 +1207,22 @@ tableColumn:(NSTableColumn *)aTableColumn row:(int)row mouseLocation:(NSPoint)mo
 }
 }
 @end
 @end
 
 
+@implementation VerticalCenterAlignedBrowserCell
+
+- (NSRect)titleRectForBounds:(NSRect)theRect {
+    NSRect titleFrame = [super titleRectForBounds:theRect];
+    NSSize titleSize = [[self attributedStringValue] size];
+	titleFrame.origin.x = theRect.origin.x + 2;
+    titleFrame.origin.y = theRect.origin.y - .5 + (theRect.size.height - titleSize.height) / 2.0;
+    return titleFrame;
+}
+
+- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
+    NSRect titleRect = [self titleRectForBounds:cellFrame];
+    [[self attributedStringValue] drawInRect:titleRect];
+}
+
+@end
 // TreeView
 // TreeView
 
 
 @implementation TreeView
 @implementation TreeView
@@ -1223,7 +1243,7 @@ tableColumn:(NSTableColumn *)aTableColumn row:(int)row mouseLocation:(NSPoint)mo
 	column=[[NSTableColumn alloc] init];
 	column=[[NSTableColumn alloc] init];
 	[outline addTableColumn:column];
 	[outline addTableColumn:column];
 	[outline setOutlineTableColumn:column];
 	[outline setOutlineTableColumn:column];
-	cell=[[NSBrowserCell alloc] init];
+	cell=[[VerticalCenterAlignedBrowserCell alloc] init];
 	[cell setLeaf:YES];
 	[cell setLeaf:YES];
 	[cell setScrollable:YES];
 	[cell setScrollable:YES];
 	[column setDataCell:cell];		
 	[column setDataCell:cell];		
@@ -1342,7 +1362,7 @@ tableColumn:(NSTableColumn *)aTableColumn row:(int)row mouseLocation:(NSPoint)mo
 -(void)setTextColor:(NSColor*)color{
 -(void)setTextColor:(NSColor*)color{
 	if (textstyle) {[textstyle release];textstyle=nil;}
 	if (textstyle) {[textstyle release];textstyle=nil;}
 	if (color){
 	if (color){
-		textstyle=[NSDictionary dictionaryWithObjectsAndKeys:color,NSForegroundColorAttributeName,nil];
+		textstyle=[NSMutableDictionary dictionaryWithObjectsAndKeys:color,NSForegroundColorAttributeName,nil];
 		[textstyle retain];	
 		[textstyle retain];	
 	}
 	}
 }
 }
@@ -1351,14 +1371,18 @@ tableColumn:(NSTableColumn *)aTableColumn row:(int)row mouseLocation:(NSPoint)mo
 		NSLayoutManager* layoutManager = [[[NSLayoutManager alloc] init] autorelease];
 		NSLayoutManager* layoutManager = [[[NSLayoutManager alloc] init] autorelease];
 		int i;
 		int i;
 		NSArray *columnsArray = [outline tableColumns];
 		NSArray *columnsArray = [outline tableColumns];
-		for (i= 0; i < [columnsArray count]; i++)
-		[[[columnsArray objectAtIndex:i] dataCell] setFont:font];
-		[outline setRowHeight: [layoutManager defaultLineHeightForFont:font]+1];
+		for (i= 0; i < [columnsArray count]; i++) {
+			[[[columnsArray objectAtIndex:i] dataCell] setFont:font];
+		}
+		[outline setRowHeight: [layoutManager defaultLineHeightForFont:font]+3];
+		
+		[cell setFont:font];
 		[rootNode queueWidthUpdate];
 		[rootNode queueWidthUpdate];
 	}
 	}
 }
 }
 - (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)dcell forTableColumn:(NSTableColumn *)tableColumn item:(id)node{
 - (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)dcell forTableColumn:(NSTableColumn *)tableColumn item:(id)node{
 	if (textstyle){
 	if (textstyle){
+		[textstyle setValue:[cell font] forKey:NSFontAttributeName];
 		NSAttributedString *atext=[[[NSAttributedString alloc] initWithString:[node value] attributes:textstyle] autorelease];
 		NSAttributedString *atext=[[[NSAttributedString alloc] initWithString:[node value] attributes:textstyle] autorelease];
 		[dcell setAttributedStringValue:atext];
 		[dcell setAttributedStringValue:atext];
 	}
 	}