Fix memory leaks in PSMTabBarControl

This commit is contained in:
Nicolas Weber
2008-07-08 20:18:40 +02:00
committed by Bjorn Winckler
parent 1e2467b3f3
commit e5e3c0d2c1
7 changed files with 29 additions and 21 deletions
@@ -22,6 +22,8 @@
NSImage *_addTabButtonImage;
NSImage *_addTabButtonPressedImage;
NSImage *_addTabButtonRolloverImage;
NSMutableParagraphStyle *truncatingTailParagraphStyle;
NSMutableParagraphStyle *centeredParagraphStyle;
}
- (void)loadImages;
@@ -74,6 +74,9 @@
[_addTabButtonImage release];
[_addTabButtonPressedImage release];
[_addTabButtonRolloverImage release];
[truncatingTailParagraphStyle release];
[centeredParagraphStyle release];
[super dealloc];
}
@@ -283,13 +286,12 @@
[attrStr addAttribute:NSFontAttributeName value:[NSFont systemFontOfSize:11.0] range:range];
// Paragraph Style for Truncating Long Text
static NSMutableParagraphStyle *TruncatingTailParagraphStyle = nil;
if (!TruncatingTailParagraphStyle) {
TruncatingTailParagraphStyle = [[[NSParagraphStyle defaultParagraphStyle] mutableCopy] retain];
[TruncatingTailParagraphStyle setLineBreakMode:NSLineBreakByTruncatingTail];
[TruncatingTailParagraphStyle setAlignment:NSCenterTextAlignment];
if (!truncatingTailParagraphStyle) {
truncatingTailParagraphStyle = [[[NSParagraphStyle defaultParagraphStyle] mutableCopy] retain];
[truncatingTailParagraphStyle setLineBreakMode:NSLineBreakByTruncatingTail];
[truncatingTailParagraphStyle setAlignment:NSCenterTextAlignment];
}
[attrStr addAttribute:NSParagraphStyleAttributeName value:TruncatingTailParagraphStyle range:range];
[attrStr addAttribute:NSParagraphStyleAttributeName value:truncatingTailParagraphStyle range:range];
return attrStr;
}
@@ -371,7 +373,6 @@
attrStr = [[[NSMutableAttributedString alloc] initWithString:contents] autorelease];
NSRange range = NSMakeRange(0, [contents length]);
[attrStr addAttribute:NSFontAttributeName value:[NSFont systemFontOfSize:11.0] range:range];
NSMutableParagraphStyle *centeredParagraphStyle = nil;
if (!centeredParagraphStyle) {
centeredParagraphStyle = [[[NSParagraphStyle defaultParagraphStyle] mutableCopy] retain];
[centeredParagraphStyle setAlignment:NSCenterTextAlignment];
@@ -16,6 +16,8 @@
NSImage *_addTabButtonImage;
NSImage *_addTabButtonPressedImage;
NSImage *_addTabButtonRolloverImage;
NSMutableParagraphStyle *truncatingTailParagraphStyle;
NSMutableParagraphStyle *centeredParagraphStyle;
}
- (void)drawInteriorWithTabCell:(PSMTabBarCell *)cell inView:(NSView*)controlView;
@@ -59,6 +59,9 @@ void MyNSDrawWindowBackground(NSRect rect)
[_addTabButtonImage release];
[_addTabButtonPressedImage release];
[_addTabButtonRolloverImage release];
[truncatingTailParagraphStyle release];
[centeredParagraphStyle release];
[super dealloc];
}
@@ -297,13 +300,12 @@ void MyNSDrawWindowBackground(NSRect rect)
[attrStr addAttribute:NSShadowAttributeName value:shadow range:range];
// Paragraph Style for Truncating Long Text
static NSMutableParagraphStyle *TruncatingTailParagraphStyle = nil;
if (!TruncatingTailParagraphStyle) {
TruncatingTailParagraphStyle = [[[NSParagraphStyle defaultParagraphStyle] mutableCopy] retain];
[TruncatingTailParagraphStyle setLineBreakMode:NSLineBreakByTruncatingTail];
[TruncatingTailParagraphStyle setAlignment:NSCenterTextAlignment];
if (!truncatingTailParagraphStyle) {
truncatingTailParagraphStyle = [[[NSParagraphStyle defaultParagraphStyle] mutableCopy] retain];
[truncatingTailParagraphStyle setLineBreakMode:NSLineBreakByTruncatingTail];
[truncatingTailParagraphStyle setAlignment:NSCenterTextAlignment];
}
[attrStr addAttribute:NSParagraphStyleAttributeName value:TruncatingTailParagraphStyle range:range];
[attrStr addAttribute:NSParagraphStyleAttributeName value:truncatingTailParagraphStyle range:range];
return attrStr;
}
@@ -477,7 +479,6 @@ void MyNSDrawWindowBackground(NSRect rect)
attrStr = [[[NSMutableAttributedString alloc] initWithString:contents] autorelease];
NSRange range = NSMakeRange(0, [contents length]);
[attrStr addAttribute:NSFontAttributeName value:[NSFont systemFontOfSize:11.0] range:range];
NSMutableParagraphStyle *centeredParagraphStyle = nil;
if (!centeredParagraphStyle) {
centeredParagraphStyle = [[[NSParagraphStyle defaultParagraphStyle] mutableCopy] retain];
[centeredParagraphStyle setAlignment:NSCenterTextAlignment];
@@ -324,7 +324,7 @@
if(([self state] == NSOnState) && ([[_controlView styleName] isEqualToString:@"Metal"]))
cellFrame.size.width += 1.0;
[_controlView lockFocus];
NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:cellFrame];
NSBitmapImageRep *rep = [[[NSBitmapImageRep alloc] initWithFocusedViewRect:cellFrame] autorelease];
[_controlView unlockFocus];
NSImage *image = [[[NSImage alloc] initWithSize:[rep size]] autorelease];
[image addRepresentation:rep];
@@ -17,6 +17,8 @@
NSImage *_addTabButtonImage;
NSImage *_addTabButtonPressedImage;
NSImage *_addTabButtonRolloverImage;
NSMutableParagraphStyle *truncatingTailParagraphStyle;
NSMutableParagraphStyle *centeredParagraphStyle;
float leftMargin;
}
@@ -53,6 +53,8 @@
[_addTabButtonImage release];
[_addTabButtonPressedImage release];
[_addTabButtonRolloverImage release];
[truncatingTailParagraphStyle release];
[centeredParagraphStyle release];
[super dealloc];
}
@@ -268,12 +270,11 @@
[attrStr addAttribute:NSFontAttributeName value:[NSFont systemFontOfSize:11.0] range:range];
// Paragraph Style for Truncating Long Text
static NSMutableParagraphStyle *TruncatingTailParagraphStyle = nil;
if (!TruncatingTailParagraphStyle) {
TruncatingTailParagraphStyle = [[[NSParagraphStyle defaultParagraphStyle] mutableCopy] retain];
[TruncatingTailParagraphStyle setLineBreakMode:NSLineBreakByTruncatingTail];
if (!truncatingTailParagraphStyle) {
truncatingTailParagraphStyle = [[[NSParagraphStyle defaultParagraphStyle] mutableCopy] retain];
[truncatingTailParagraphStyle setLineBreakMode:NSLineBreakByTruncatingTail];
}
[attrStr addAttribute:NSParagraphStyleAttributeName value:TruncatingTailParagraphStyle range:range];
[attrStr addAttribute:NSParagraphStyleAttributeName value:truncatingTailParagraphStyle range:range];
return attrStr;
}
@@ -472,7 +473,6 @@
attrStr = [[[NSMutableAttributedString alloc] initWithString:contents] autorelease];
NSRange range = NSMakeRange(0, [contents length]);
[attrStr addAttribute:NSFontAttributeName value:[NSFont systemFontOfSize:11.0] range:range];
NSMutableParagraphStyle *centeredParagraphStyle = nil;
if (!centeredParagraphStyle) {
centeredParagraphStyle = [[[NSParagraphStyle defaultParagraphStyle] mutableCopy] retain];
[centeredParagraphStyle setAlignment:NSCenterTextAlignment];