comparison mac/dw.m @ 981:536ec60ee433

Don't destroy a pixmap if the handle is null Fix dw_listbox_selected_multi() to return values correctly. Because NSIndexSet are unsigned and the first time you call this function with -1, the lookup fails.
author mhessling@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 06 May 2011 07:50:02 +0000
parents 94dde9b3dfc0
children a4425bb24b77
comparison
equal deleted inserted replaced
980:94dde9b3dfc0 981:536ec60ee433
4104 id object = handle; 4104 id object = handle;
4105 int retval = -1; 4105 int retval = -1;
4106 4106
4107 if([object isMemberOfClass:[DWContainer class]]) 4107 if([object isMemberOfClass:[DWContainer class]])
4108 { 4108 {
4109 NSUInteger result;
4109 DWContainer *cont = handle; 4110 DWContainer *cont = handle;
4110 NSIndexSet *selected = [cont selectedRowIndexes]; 4111 NSIndexSet *selected = [cont selectedRowIndexes];
4111 NSUInteger result = [selected indexGreaterThanIndex:where]; 4112 if( where == -1 )
4113 result = [selected indexGreaterThanOrEqualToIndex:0];
4114 else
4115 result = [selected indexGreaterThanIndex:where];
4112 4116
4113 if(result != NSNotFound) 4117 if(result != NSNotFound)
4114 { 4118 {
4115 retval = (int)result; 4119 retval = (int)result;
4116 } 4120 }
6036 /* Function takes an NSImage and copies it into a flipped NSBitmapImageRep */ 6040 /* Function takes an NSImage and copies it into a flipped NSBitmapImageRep */
6037 void _flip_image(NSImage *tmpimage, NSBitmapImageRep *image, NSSize size) 6041 void _flip_image(NSImage *tmpimage, NSBitmapImageRep *image, NSSize size)
6038 { 6042 {
6039 [NSGraphicsContext saveGraphicsState]; 6043 [NSGraphicsContext saveGraphicsState];
6040 [NSGraphicsContext setCurrentContext:[NSGraphicsContext 6044 [NSGraphicsContext setCurrentContext:[NSGraphicsContext
6041 graphicsContextWithGraphicsPort:[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] graphicsPort] 6045 graphicsContextWithGraphicsPort:[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] graphicsPort]
6042 flipped:YES]]; 6046 flipped:YES]];
6043 [[NSDictionary alloc] initWithObjectsAndKeys:image, NSGraphicsContextDestinationAttributeName, nil]; 6047 [[NSDictionary alloc] initWithObjectsAndKeys:image, NSGraphicsContextDestinationAttributeName, nil];
6044 // make a new transform: 6048 // make a new transform:
6045 NSAffineTransform *t = [NSAffineTransform transform]; 6049 NSAffineTransform *t = [NSAffineTransform transform];
6046 6050
6047 // by scaling Y negatively, we effectively flip the image: 6051 // by scaling Y negatively, we effectively flip the image:
6048 [t scaleXBy:1.0 yBy:-1.0]; 6052 [t scaleXBy:1.0 yBy:-1.0];
6049 6053
6050 // but we also have to translate it back by its height: 6054 // but we also have to translate it back by its height:
6051 [t translateXBy:0.0 yBy:-size.height]; 6055 [t translateXBy:0.0 yBy:-size.height];
6052 6056
6053 // apply the transform: 6057 // apply the transform:
6054 [t concat]; 6058 [t concat];
6055 [tmpimage drawAtPoint:NSMakePoint(0, 0) fromRect:NSMakeRect(0, 0, size.width, size.height) 6059 [tmpimage drawAtPoint:NSMakePoint(0, 0) fromRect:NSMakeRect(0, 0, size.width, size.height)
6056 operation:NSCompositeSourceOver fraction:1.0]; 6060 operation:NSCompositeSourceOver fraction:1.0];
6057 [NSGraphicsContext restoreGraphicsState]; 6061 [NSGraphicsContext restoreGraphicsState];
6058 } 6062 }
6059 6063
6060 /* 6064 /*
6061 * Creates a pixmap from a file. 6065 * Creates a pixmap from a file.
6190 * pixmap: Handle to a pixmap returned by 6194 * pixmap: Handle to a pixmap returned by
6191 * dw_pixmap_new.. 6195 * dw_pixmap_new..
6192 */ 6196 */
6193 void API dw_pixmap_destroy(HPIXMAP pixmap) 6197 void API dw_pixmap_destroy(HPIXMAP pixmap)
6194 { 6198 {
6195 NSBitmapImageRep *image = (NSBitmapImageRep *)pixmap->image; 6199 if ( pixmap )
6196 [image release]; 6200 {
6197 free(pixmap); 6201 NSBitmapImageRep *image = (NSBitmapImageRep *)pixmap->image;
6202 [image release];
6203 free(pixmap);
6204 }
6198 } 6205 }
6199 6206
6200 /* 6207 /*
6201 * Copies from one item to another. 6208 * Copies from one item to another.
6202 * Parameters: 6209 * Parameters: