Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifdef HAVE_CONFIG_H
00009 # include <config.h>
00010 #endif
00011
00012
00013 #import "CocoaLabel.h"
00014
00015 #ifndef COCOA_LABEL_MM
00016 #define COCOA_LABEL_MM
00017
00018 @implementation CocoaLabel
00019
00020 @synthesize fillX;
00021 @synthesize fillY;
00022
00023 - (id)initWithFrame:(NSRect)frame {
00024 self = [super initWithFrame:frame];
00025 if (self) {
00026 fillX = NO;
00027 fillY = NO;
00028 minWidth = 0.0;
00029 }
00030 return self;
00031 }
00032
00033 -(void) dealloc {
00034 [super dealloc];
00035 }
00036
00037 -(NSSize) neededTextSize {
00038 NSString *title = [self stringValue];
00039 if (title && [title length]>0) {
00040 NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
00041 [NSColor blackColor], NSForegroundColorAttributeName,
00042 [self font], NSFontAttributeName,
00043 nil];
00044 return [title sizeWithAttributes:attributes];
00045 }
00046 return NSZeroSize;
00047 }
00048
00049 -(void) computeMinWidth {
00050 NSSize size = [self neededTextSize];
00051 minWidth = size.width+4.0;
00052 }
00053
00054 - (void)setStringValue:(NSString *)aString {
00055
00056
00057 if (aString) {
00058 NSRange htmlRange = [aString rangeOfString:@"<html>"];
00059 if (htmlRange.location != NSNotFound) {
00060 NSRange endHtmlRange = [aString rangeOfString:@"</html>"];
00061 if (endHtmlRange.location != NSNotFound) {
00062 NSString *stringToUse = @"";
00063 NSRange cutRange = NSUnionRange(htmlRange, endHtmlRange);
00064 stringToUse = [aString stringByReplacingCharactersInRange:cutRange withString:@""];
00065 [super setStringValue:stringToUse];
00066 [self computeMinWidth];
00067 return;
00068 }
00069 }
00070 }
00071 [super setStringValue:aString];
00072 [self computeMinWidth];
00073 }
00074
00075
00076
00077
00078
00079
00080
00081
00082 #pragma mark Protocol Methods
00083
00084 - (NSSize) minSize {
00085 return NSMakeSize(minWidth, 17.0);
00086 }
00087
00088 @end
00089
00090 #endif