comparison mac/dw.m @ 1557:030e9bddc1c9

Fixed some potential Objective-C memory leaks on Mac reported by XCode 4.2.1. Trying to track down an autorelease crash on Lion using dw_main_quit().
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 16 Jan 2012 21:24:11 +0000
parents 4a9c574d5c17
children 9c5d3ac5bec5
comparison
equal deleted inserted replaced
1556:4a9c574d5c17 1557:030e9bddc1c9
551 if([bltdest isMemberOfClass:[NSBitmapImageRep class]]) 551 if([bltdest isMemberOfClass:[NSBitmapImageRep class]])
552 { 552 {
553 [NSGraphicsContext saveGraphicsState]; 553 [NSGraphicsContext saveGraphicsState];
554 [NSGraphicsContext setCurrentContext:[NSGraphicsContext 554 [NSGraphicsContext setCurrentContext:[NSGraphicsContext
555 graphicsContextWithGraphicsPort:[[NSGraphicsContext graphicsContextWithBitmapImageRep:bltdest] graphicsPort] flipped:YES]]; 555 graphicsContextWithGraphicsPort:[[NSGraphicsContext graphicsContextWithBitmapImageRep:bltdest] graphicsPort] flipped:YES]];
556 [[NSDictionary alloc] initWithObjectsAndKeys:bltdest, NSGraphicsContextDestinationAttributeName, nil]; 556 [[[NSDictionary alloc] initWithObjectsAndKeys:bltdest, NSGraphicsContextDestinationAttributeName, nil] autorelease];
557 } 557 }
558 else 558 else
559 { 559 {
560 if([bltdest lockFocusIfCanDraw] == NO) 560 if([bltdest lockFocusIfCanDraw] == NO)
561 { 561 {
2266 { 2266 {
2267 self = [super init]; 2267 self = [super init];
2268 2268
2269 if(self) 2269 if(self)
2270 { 2270 {
2271 textfield = [[NSTextField alloc] init]; 2271 textfield = [[[NSTextField alloc] init] autorelease];
2272 [self addSubview:textfield]; 2272 [self addSubview:textfield];
2273 stepper = [[DWStepper alloc] init]; 2273 stepper = [[[DWStepper alloc] init] autorelease];
2274 [self addSubview:stepper]; 2274 [self addSubview:stepper];
2275 [stepper setParent:self]; 2275 [stepper setParent:self];
2276 [stepper setTextfield:textfield]; 2276 [stepper setTextfield:textfield];
2277 [textfield takeIntValueFrom:stepper]; 2277 [textfield takeIntValueFrom:stepper];
2278 [textfield setDelegate:self]; 2278 [textfield setDelegate:self];
3137 } 3137 }
3138 3138
3139 /* Handle file types */ 3139 /* Handle file types */
3140 if(ext) 3140 if(ext)
3141 { 3141 {
3142 NSArray* fileTypes = [[NSArray alloc] initWithObjects:[NSString stringWithUTF8String:ext], nil]; 3142 NSArray* fileTypes = [[[NSArray alloc] initWithObjects:[NSString stringWithUTF8String:ext], nil] autorelease];
3143 [openDlg setAllowedFileTypes:fileTypes]; 3143 [openDlg setAllowedFileTypes:fileTypes];
3144 } 3144 }
3145 3145
3146 /* Disable multiple selection */ 3146 /* Disable multiple selection */
3147 [openDlg setAllowsMultipleSelection:NO]; 3147 [openDlg setAllowsMultipleSelection:NO];
3174 [saveDlg setCanCreateDirectories:YES]; 3174 [saveDlg setCanCreateDirectories:YES];
3175 3175
3176 /* Handle file types */ 3176 /* Handle file types */
3177 if(ext) 3177 if(ext)
3178 { 3178 {
3179 NSArray* fileTypes = [[NSArray alloc] initWithObjects:[NSString stringWithUTF8String:ext], nil]; 3179 NSArray* fileTypes = [[[NSArray alloc] initWithObjects:[NSString stringWithUTF8String:ext], nil] autorelease];
3180 [saveDlg setAllowedFileTypes:fileTypes]; 3180 [saveDlg setAllowedFileTypes:fileTypes];
3181 } 3181 }
3182 3182
3183 /* Display the dialog. If the OK button was pressed, 3183 /* Display the dialog. If the OK button was pressed,
3184 * process the files. 3184 * process the files.
3879 * limit: Number of characters the entryfield will take. 3879 * limit: Number of characters the entryfield will take.
3880 */ 3880 */
3881 void API dw_entryfield_set_limit(HWND handle, ULONG limit) 3881 void API dw_entryfield_set_limit(HWND handle, ULONG limit)
3882 { 3882 {
3883 DWEntryField *entry = handle; 3883 DWEntryField *entry = handle;
3884 DWEntryFieldFormatter *formatter = [[DWEntryFieldFormatter alloc] init]; 3884 DWEntryFieldFormatter *formatter = [[[DWEntryFieldFormatter alloc] init] autorelease];
3885 3885
3886 [formatter setMaximumLength:(int)limit]; 3886 [formatter setMaximumLength:(int)limit];
3887 [[entry cell] setFormatter:formatter]; 3887 [[entry cell] setFormatter:formatter];
3888 } 3888 }
3889 3889
3981 [stepper setTag:cid]; 3981 [stepper setTag:cid];
3982 [stepper setMinValue:-65536]; 3982 [stepper setMinValue:-65536];
3983 [stepper setMaxValue:65536]; 3983 [stepper setMaxValue:65536];
3984 [stepper setIntValue:atoi(text)]; 3984 [stepper setIntValue:atoi(text)];
3985 [textfield takeIntValueFrom:stepper]; 3985 [textfield takeIntValueFrom:stepper];
3986 [stepper autorelease];
3987 [textfield autorelease];
3988 return spinbutton; 3986 return spinbutton;
3989 } 3987 }
3990 3988
3991 /* 3989 /*
3992 * Sets the spinbutton value. 3990 * Sets the spinbutton value.
4294 DW_MUTEX_LOCK; 4292 DW_MUTEX_LOCK;
4295 DWContainer *cont = _cont_new(cid, multi); 4293 DWContainer *cont = _cont_new(cid, multi);
4296 [cont setHeaderView:nil]; 4294 [cont setHeaderView:nil];
4297 int type = DW_CFA_STRING; 4295 int type = DW_CFA_STRING;
4298 [cont setup]; 4296 [cont setup];
4299 NSTableColumn *column = [[NSTableColumn alloc] init]; 4297 NSTableColumn *column = [[[NSTableColumn alloc] init] autorelease];
4300 [column setEditable:NO]; 4298 [column setEditable:NO];
4301 [cont addTableColumn:column]; 4299 [cont addTableColumn:column];
4302 [cont addColumn:column andType:type]; 4300 [cont addColumn:column andType:type];
4303 DW_MUTEX_UNLOCK; 4301 DW_MUTEX_UNLOCK;
4304 return cont; 4302 return cont;
5146 color = (NSColor *)dw_dialog_wait(dialog); 5144 color = (NSColor *)dw_dialog_wait(dialog);
5147 5145
5148 /* Figure out the value of what they returned */ 5146 /* Figure out the value of what they returned */
5149 CGFloat red, green, blue; 5147 CGFloat red, green, blue;
5150 [color getRed:&red green:&green blue:&blue alpha:NULL]; 5148 [color getRed:&red green:&green blue:&blue alpha:NULL];
5149 [color release];
5151 value = DW_RGB((int)(red * 255), (int)(green *255), (int)(blue *255)); 5150 value = DW_RGB((int)(red * 255), (int)(green *255), (int)(blue *255));
5152 return value; 5151 return value;
5153 } 5152 }
5154 5153
5155 /* Draw a point on a window (preferably a render window). 5154 /* Draw a point on a window (preferably a render window).
5829 int _locked_by_me = FALSE; 5828 int _locked_by_me = FALSE;
5830 DW_MUTEX_LOCK; 5829 DW_MUTEX_LOCK;
5831 DWContainer *cont = _cont_new(cid, multi); 5830 DWContainer *cont = _cont_new(cid, multi);
5832 NSScrollView *scrollview = [cont scrollview]; 5831 NSScrollView *scrollview = [cont scrollview];
5833 [scrollview setHasHorizontalScroller:YES]; 5832 [scrollview setHasHorizontalScroller:YES];
5834 NSTableHeaderView *header = [[NSTableHeaderView alloc] init]; 5833 NSTableHeaderView *header = [[[NSTableHeaderView alloc] init] autorelease];
5835 [cont setHeaderView:header]; 5834 [cont setHeaderView:header];
5836 [cont setTarget:cont]; 5835 [cont setTarget:cont];
5837 [cont setDoubleAction:@selector(doubleClicked:)]; 5836 [cont setDoubleAction:@selector(doubleClicked:)];
5838 DW_MUTEX_UNLOCK; 5837 DW_MUTEX_UNLOCK;
5839 return cont; 5838 return cont;
6079 if(pointer) 6078 if(pointer)
6080 { 6079 {
6081 lastadd = [cont lastAddPoint]; 6080 lastadd = [cont lastAddPoint];
6082 } 6081 }
6083 6082
6084 browsercell = [[DWImageAndTextCell alloc] init]; 6083 browsercell = [[[DWImageAndTextCell alloc] init] autorelease];
6085 [browsercell setImage:icon]; 6084 [browsercell setImage:icon];
6086 [browsercell setStringValue:[ NSString stringWithUTF8String:filename ]]; 6085 [browsercell setStringValue:[ NSString stringWithUTF8String:filename ]];
6087 [cont editCell:browsercell at:(row+lastadd) and:0]; 6086 [cont editCell:browsercell at:(row+lastadd) and:0];
6088 [cont setNeedsDisplay:YES]; 6087 [cont setNeedsDisplay:YES];
6089 DW_MUTEX_UNLOCK; 6088 DW_MUTEX_UNLOCK;
6755 { 6754 {
6756 [NSGraphicsContext saveGraphicsState]; 6755 [NSGraphicsContext saveGraphicsState];
6757 [NSGraphicsContext setCurrentContext:[NSGraphicsContext 6756 [NSGraphicsContext setCurrentContext:[NSGraphicsContext
6758 graphicsContextWithGraphicsPort:[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] graphicsPort] 6757 graphicsContextWithGraphicsPort:[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] graphicsPort]
6759 flipped:YES]]; 6758 flipped:YES]];
6760 [[NSDictionary alloc] initWithObjectsAndKeys:image, NSGraphicsContextDestinationAttributeName, nil]; 6759 [[[NSDictionary alloc] initWithObjectsAndKeys:image, NSGraphicsContextDestinationAttributeName, nil] autorelease];
6761 // make a new transform: 6760 // make a new transform:
6762 NSAffineTransform *t = [NSAffineTransform transform]; 6761 NSAffineTransform *t = [NSAffineTransform transform];
6763 6762
6764 // by scaling Y negatively, we effectively flip the image: 6763 // by scaling Y negatively, we effectively flip the image:
6765 [t scaleXBy:1.0 yBy:-1.0]; 6764 [t scaleXBy:1.0 yBy:-1.0];
6790 char *ext = _dw_get_image_extension( filename ); 6789 char *ext = _dw_get_image_extension( filename );
6791 6790
6792 if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) 6791 if(!(pixmap = calloc(1,sizeof(struct _hpixmap))))
6793 return NULL; 6792 return NULL;
6794 NSString *nstr = [ NSString stringWithUTF8String:filename ]; 6793 NSString *nstr = [ NSString stringWithUTF8String:filename ];
6795 NSImage *tmpimage = [[NSImage alloc] initWithContentsOfFile:nstr]; 6794 NSImage *tmpimage = [[[NSImage alloc] initWithContentsOfFile:nstr] autorelease];
6796 if(!tmpimage && ext) 6795 if(!tmpimage && ext)
6797 { 6796 {
6798 nstr = [nstr stringByAppendingString: [NSString stringWithUTF8String:ext]]; 6797 nstr = [nstr stringByAppendingString: [NSString stringWithUTF8String:ext]];
6799 tmpimage = [[NSImage alloc] initWithContentsOfFile:nstr]; 6798 tmpimage = [[[NSImage alloc] initWithContentsOfFile:nstr] autorelease];
6800 } 6799 }
6801 if(!tmpimage) 6800 if(!tmpimage)
6802 return NULL; 6801 return NULL;
6803 NSSize size = [tmpimage size]; 6802 NSSize size = [tmpimage size];
6804 NSBitmapImageRep *image = [[NSBitmapImageRep alloc] 6803 NSBitmapImageRep *image = [[NSBitmapImageRep alloc]
6835 HPIXMAP pixmap; 6834 HPIXMAP pixmap;
6836 6835
6837 if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) 6836 if(!(pixmap = calloc(1,sizeof(struct _hpixmap))))
6838 return NULL; 6837 return NULL;
6839 NSData *thisdata = [NSData dataWithBytes:data length:len]; 6838 NSData *thisdata = [NSData dataWithBytes:data length:len];
6840 NSImage *tmpimage = [[NSImage alloc] initWithData:thisdata]; 6839 NSImage *tmpimage = [[[NSImage alloc] initWithData:thisdata] autorelease];
6841 if(!tmpimage) 6840 if(!tmpimage)
6842 return NULL; 6841 return NULL;
6843 NSSize size = [tmpimage size]; 6842 NSSize size = [tmpimage size];
6844 NSBitmapImageRep *image = [[NSBitmapImageRep alloc] 6843 NSBitmapImageRep *image = [[NSBitmapImageRep alloc]
6845 initWithBitmapDataPlanes:NULL 6844 initWithBitmapDataPlanes:NULL
8484 NSImageView *iv = handle; 8483 NSImageView *iv = handle;
8485 NSImage *bitmap = nil; 8484 NSImage *bitmap = nil;
8486 8485
8487 if(filename) 8486 if(filename)
8488 { 8487 {
8489 bitmap = [[NSImage alloc] initWithContentsOfFile:[ NSString stringWithUTF8String:filename ]]; 8488 bitmap = [[[NSImage alloc] initWithContentsOfFile:[ NSString stringWithUTF8String:filename ]] autorelease];
8490 } 8489 }
8491 else if(resid > 0 && resid < 65536) 8490 else if(resid > 0 && resid < 65536)
8492 { 8491 {
8493 bitmap = dw_icon_load(0, resid); 8492 bitmap = dw_icon_load(0, resid);
8494 } 8493 }