From: Joseph Spiros Date: Sat, 6 Mar 2004 07:03:45 +0000 (+0000) Subject: Adding the ITMultilineTextFieldCell work I've done so far... X-Git-Tag: v0.2~1 X-Git-Url: http://git.ithinksw.org/ITKit.git/commitdiff_plain/c6baa45585d2caea0a6d824a63e308e47f2f52de Adding the ITMultilineTextFieldCell work I've done so far... --- diff --git a/ITKit.xcode/project.pbxproj b/ITKit.xcode/project.pbxproj index 422bfdf..7beefb5 100755 --- a/ITKit.xcode/project.pbxproj +++ b/ITKit.xcode/project.pbxproj @@ -599,6 +599,34 @@ refType = 4; sourceTree = ""; }; + 7C4BBADA05F98C9900734027 = { + fileEncoding = 4; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; + path = ITMultilineTextFieldCell.h; + refType = 4; + sourceTree = ""; + }; + 7C4BBADB05F98C9900734027 = { + fileEncoding = 4; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.objc; + path = ITMultilineTextFieldCell.m; + refType = 4; + sourceTree = ""; + }; + 7C4BBADC05F98C9900734027 = { + fileRef = 7C4BBADA05F98C9900734027; + isa = PBXBuildFile; + settings = { + }; + }; + 7C4BBADD05F98C9900734027 = { + fileRef = 7C4BBADB05F98C9900734027; + isa = PBXBuildFile; + settings = { + }; + }; 7C5B7C93054F6EC9008379B6 = { fileRef = 8DC2EF5B0486A6940098B216; isa = PBXBuildFile; @@ -1594,6 +1622,8 @@ 7C992DF8054F5179000B93EA, 2AC8319B056D037700A7D7E2, 2AC8319C056D037700A7D7E2, + 7C4BBADA05F98C9900734027, + 7C4BBADB05F98C9900734027, ); isa = PBXGroup; name = Cells; @@ -2130,6 +2160,7 @@ 2AC83141056D00F700A7D7E2, 2AC8319D056D037700A7D7E2, 3710912805C0825900ED0F36, + 7C4BBADC05F98C9900734027, ); isa = PBXHeadersBuildPhase; runOnlyForDeploymentPostprocessing = 0; @@ -2189,6 +2220,7 @@ 2AC83142056D00F700A7D7E2, 2AC8319E056D037700A7D7E2, 3710912305C0821000ED0F36, + 7C4BBADD05F98C9900734027, ); isa = PBXSourcesBuildPhase; runOnlyForDeploymentPostprocessing = 0; diff --git a/ITMultilineTextFieldCell.h b/ITMultilineTextFieldCell.h new file mode 100755 index 0000000..59ca9c0 --- /dev/null +++ b/ITMultilineTextFieldCell.h @@ -0,0 +1,15 @@ +// +// ITMultilineTextFieldCell.h +// ITKit +// +// Created by Joseph Spiros on Fri Mar 05 2004. +// Copyright (c) 2004 __MyCompanyName__. All rights reserved. +// + +#import + + +@interface ITMultilineTextFieldCell : NSCell { +} + +@end diff --git a/ITMultilineTextFieldCell.m b/ITMultilineTextFieldCell.m new file mode 100755 index 0000000..74b4749 --- /dev/null +++ b/ITMultilineTextFieldCell.m @@ -0,0 +1,108 @@ +// +// ITMultilineTextFieldCell.m +// ITKit +// +// Created by Joseph Spiros on Fri Mar 05 2004. +// Copyright (c) 2004 __MyCompanyName__. All rights reserved. +// + +#import "ITMultilineTextFieldCell.h" + + +@implementation ITMultilineTextFieldCell + +- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView +{ + /* + Okay, here's the different possibilities for the objectValue of this cell, and how they're displayed: + + NSArray of NSStrings - Draw first line with System Font, following lines with Small System Font + NSArray of NSAttributedStrings - Draw as given + NSArray of both - Draw each line as above! + + The number of lines is determined by the contents of the array... + */ + + NSColor *defaultColor; + NSMutableParagraphStyle *paragraphStyle = [[[NSParagraphStyle defaultParagraphStyle] mutableCopy] autorelease]; + [paragraphStyle setLineBreakMode:NSLineBreakByTruncatingTail]; + NSPoint cellPoint = cellFrame.origin; + NSSize cellSize = cellFrame.size; + + NSRect secondaryLineRect; + + if ([self isHighlighted] && ([self highlightColorWithFrame:cellFrame inView:controlView]!=[NSColor secondarySelectedControlColor])) { + defaultColor = [NSColor whiteColor]; + } else { + defaultColor = [NSColor blackColor]; + } + + // Process the first line... + { + NSDictionary *firstLineAttributes = [NSDictionary dictionaryWithObjectsAndKeys:[NSFont boldSystemFontOfSize:[NSFont systemFontSize]], NSFontAttributeName, defaultColor, NSForegroundColorAttributeName, paragraphStyle, NSParagraphStyleAttributeName, nil]; + + NSRect firstLineRect = NSMakeRect(cellPoint.x+5, cellPoint.y+1, cellSize.width-5, cellSize.height); + + id firstString = [[self objectValue] objectAtIndex:0]; + NSMutableAttributedString *firstAttrString; + + if ([firstString isKindOfClass:[NSAttributedString class]]) { + firstAttrString = [[[NSMutableAttributedString alloc] initWithAttributedString:firstString] autorelease]; + [firstAttrString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0,[firstAttrString length])]; + if ([defaultColor isEqual:[NSColor whiteColor]]) { + [firstAttrString addAttribute:NSForegroundColorAttributeName value:defaultColor range:NSMakeRange(0,[firstAttrString length])]; + } + } else if ([firstString isKindOfClass:[NSString class]]) { + firstAttrString = [[[NSMutableAttributedString alloc] initWithString:firstString attributes:firstLineAttributes] autorelease]; + } else { + firstAttrString = [[[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"Object (%@) is not a string", firstString] attributes:firstLineAttributes] autorelease]; + } + + [controlView lockFocus]; + + [firstAttrString drawInRect:firstLineRect]; + + [controlView unlockFocus]; + + secondaryLineRect = NSMakeRect(cellPoint.x+5, (cellPoint.y+1+[firstAttrString size].height), cellSize.width-5, cellSize.height); + } + + // Process the secondary lines + { + NSDictionary *secondaryLineAttributes = [NSDictionary dictionaryWithObjectsAndKeys:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]], NSFontAttributeName, defaultColor, NSForegroundColorAttributeName, paragraphStyle, NSParagraphStyleAttributeName, nil]; + + NSMutableArray *tMArray = [NSMutableArray arrayWithArray:[self objectValue]]; + [tMArray removeObjectAtIndex:0]; // Remove the first line string... already handled that above! + + NSEnumerator *enumerator = [tMArray objectEnumerator]; + id secondaryString; + + while (secondaryString = [enumerator nextObject]) { + + NSMutableAttributedString *secondaryAttrString; + + if ([secondaryString isKindOfClass:[NSAttributedString class]]) { + secondaryAttrString = [[[NSMutableAttributedString alloc] initWithAttributedString:secondaryString] autorelease]; + [secondaryAttrString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0,[secondaryAttrString length])]; + if ([defaultColor isEqual:[NSColor whiteColor]]) { + [secondaryAttrString addAttribute:NSForegroundColorAttributeName value:defaultColor range:NSMakeRange(0,[secondaryAttrString length])]; + } + } else if ([secondaryString isKindOfClass:[NSString class]]) { + secondaryAttrString = [[[NSMutableAttributedString alloc] initWithString:secondaryString attributes:secondaryLineAttributes] autorelease]; + } else { + secondaryAttrString = [[[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"Object (%@) is not a string", secondaryString] attributes:secondaryLineAttributes] autorelease]; + } + + [controlView lockFocus]; + + [secondaryAttrString drawInRect:secondaryLineRect]; + + [controlView unlockFocus]; + + secondaryLineRect.origin.y = secondaryLineRect.origin.y+[secondaryAttrString size].height; // modify the rect for the next loop, based on the size and location of the most recently processed line. + + } + } +} + +@end diff --git a/Showcase/Controller.h b/Showcase/Controller.h index 18ea801..399b3c9 100755 --- a/Showcase/Controller.h +++ b/Showcase/Controller.h @@ -35,6 +35,9 @@ IBOutlet NSTextField *swShadowSaturation; IBOutlet NSSlider *swEntrySpeedSlider; IBOutlet NSSlider *swExitSpeedSlider; + + // ITMultilineTextFieldCell Support + IBOutlet NSTableView *tableView; } // ITStatusItem Support diff --git a/Showcase/Controller.m b/Showcase/Controller.m index 49e9e35..ba9c278 100755 --- a/Showcase/Controller.m +++ b/Showcase/Controller.m @@ -9,6 +9,7 @@ #import "ITSlideHorizontallyWindowEffect.h" #import "ITSlideVerticallyWindowEffect.h" #import "ITPivotWindowEffect.h" +#import "ITMultilineTextFieldCell.h" #define SW_PAD 24.0 @@ -44,6 +45,10 @@ [[statusWindow exitEffect] setEffectTime:[swExitSpeedSlider floatValue]]; // [tabView setAllowsDragging:YES]; [[NSColorPanel sharedColorPanel] setShowsAlpha:YES]; + + [tableView setRowHeight:200]; + [[tableView tableColumnWithIdentifier:@"custom"] setDataCell:[[[ITMultilineTextFieldCell alloc] init] autorelease]]; + [[tableView tableColumnWithIdentifier:@"image"] setDataCell:[[[NSImageCell alloc] init] autorelease]]; } /*************************************************************************/ @@ -299,5 +304,28 @@ [[note object] setMiniwindowImage:[NSImage imageNamed:@"ITStatusItem"]]; } +/*************************************************************************/ +#pragma mark - +#pragma mark ITMultilineTextFieldCell SUPPORT +/*************************************************************************/ + +- (int)numberOfRowsInTableView:(NSTableView *)aTableView { + return 50; +} + +- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex { + if ([[aTableColumn dataCell] isKindOfClass:[ITMultilineTextFieldCell class]]) { + if (rowIndex%2) { + return [NSArray arrayWithObjects:@"Foo", @"Bar", @"- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex", @"- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex", @"- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex", @"- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex", @"- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex", @"- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex", @"- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex", @"- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex", @"- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex", @"- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex", @"- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex", nil]; + } else { + return [NSArray arrayWithObjects:[[[NSAttributedString alloc] initWithString:@"This is a demo of ITMultilineTextFieldCell" attributes:[NSDictionary dictionaryWithObjectsAndKeys:[NSFont fontWithName:@"Gill Sans" size:48], NSFontAttributeName, [NSColor purpleColor], NSForegroundColorAttributeName, nil]] autorelease], [[[NSAttributedString alloc] initWithString:@"Bar" attributes:[NSDictionary dictionaryWithObjectsAndKeys:[NSFont fontWithName:@"Gadget" size:20], NSFontAttributeName, nil]] autorelease], [[[NSObject alloc] init] autorelease], nil]; + } + } else if ([[aTableColumn dataCell] isKindOfClass:[NSImageCell class]]) { + return [NSImage imageNamed:@"NSApplicationIcon"]; + } else { + return @"I like cheese"; + } +} + @end diff --git a/Showcase/English.lproj/MainMenu.nib/classes.nib b/Showcase/English.lproj/MainMenu.nib/classes.nib index a9358a8..512782e 100755 --- a/Showcase/English.lproj/MainMenu.nib/classes.nib +++ b/Showcase/English.lproj/MainMenu.nib/classes.nib @@ -35,6 +35,7 @@ swVanishDelay = NSTextField; swVanishModePopup = NSPopUpButton; tabView = ITTabView; + tableView = NSTableView; testTextField = ITTextField; useInvertedCheckBox = NSButton; window = NSWindow; diff --git a/Showcase/English.lproj/MainMenu.nib/info.nib b/Showcase/English.lproj/MainMenu.nib/info.nib index 42842c4..03db0ad 100755 --- a/Showcase/English.lproj/MainMenu.nib/info.nib +++ b/Showcase/English.lproj/MainMenu.nib/info.nib @@ -7,7 +7,7 @@ IBEditorPositions 197 - 564 424 153 118 0 0 1056 770 + 624 471 153 118 0 0 1152 842 29 1 271 349 44 0 0 1056 770 @@ -15,9 +15,10 @@ 349.0 IBOpenObjects + 21 197 IBSystem Version - 7C107 + 7D24 diff --git a/Showcase/English.lproj/MainMenu.nib/keyedobjects.nib b/Showcase/English.lproj/MainMenu.nib/keyedobjects.nib index 240f29a..a0b1e18 100755 Binary files a/Showcase/English.lproj/MainMenu.nib/keyedobjects.nib and b/Showcase/English.lproj/MainMenu.nib/keyedobjects.nib differ