gwenhywfar 5.14.1
CocoaLabel.m
Go to the documentation of this file.
1//
2// CocoaLabel.m
3//
4//
5// Created by Samuel Strupp on 10.08.10.
6//
7
8#ifdef HAVE_CONFIG_H
9# include <config.h>
10#endif
11
12
13#import "CocoaLabel.h"
14
15#ifndef COCOA_LABEL_MM
16#define COCOA_LABEL_MM
17
18@implementation CocoaLabel
19
20@synthesize fillX;
21@synthesize fillY;
22
23- (id)initWithFrame:(NSRect)frame {
24 self = [super initWithFrame:frame];
25 if (self) {
26 fillX = NO;
27 fillY = NO;
28 minWidth = 0.0;
29 }
30 return self;
31}
32
33-(void) dealloc {
34 [super dealloc];
35}
36
37-(NSSize) neededTextSize {
38 NSString *title = [self stringValue];
39 if (title && [title length]>0) {
40 NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
41 [NSColor blackColor], NSForegroundColorAttributeName,
42 [self font], NSFontAttributeName,
43 nil];
44 return [title sizeWithAttributes:attributes];
45 }
46 return NSZeroSize;
47}
48
49-(void) computeMinWidth {
50 NSSize size = [self neededTextSize];
51 minWidth = size.width+4.0;
52}
53
54- (void)setStringValue:(NSString *)aString {
55
56 /*remove HTML version if available*/
57 if (aString) {
58 NSRange htmlRange = [aString rangeOfString:@"<html>"];
59 if (htmlRange.location != NSNotFound) {
60 NSRange endHtmlRange = [aString rangeOfString:@"</html>"];
61 if (endHtmlRange.location != NSNotFound) {
62 NSString *stringToUse = @"";
63 NSRange cutRange = NSUnionRange(htmlRange, endHtmlRange);
64 stringToUse = [aString stringByReplacingCharactersInRange:cutRange withString:@""];
65 [super setStringValue:stringToUse];
66 [self computeMinWidth];
67 return;
68 }
69 }
70 }
71 [super setStringValue:aString];
72 [self computeMinWidth];
73}
74
75/*- (void)drawRect:(NSRect)dirtyRect {
76 //debug colors
77 [[NSColor yellowColor] set];
78 NSRectFill(dirtyRect);
79 [super drawRect:dirtyRect];
80}*/
81
82#pragma mark Protocol Methods
83
84- (NSSize) minSize {
85 return NSMakeSize(minWidth, 17.0);
86}
87
88@end
89
90#endif
CGFloat minWidth
Definition CocoaLabel.h:22
NSSize neededTextSize()
Definition CocoaLabel.m:37