changeset 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
files mac/dw.m
diffstat 1 files changed, 25 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/mac/dw.m	Fri May 06 06:47:31 2011 +0000
+++ b/mac/dw.m	Fri May 06 07:50:02 2011 +0000
@@ -4106,9 +4106,13 @@
 
     if([object isMemberOfClass:[DWContainer class]])
     {
+        NSUInteger result;
         DWContainer *cont = handle;
         NSIndexSet *selected = [cont selectedRowIndexes];
-        NSUInteger result = [selected indexGreaterThanIndex:where];
+        if( where == -1 )
+           result = [selected indexGreaterThanOrEqualToIndex:0];
+        else
+           result = [selected indexGreaterThanIndex:where];
 
         if(result != NSNotFound)
         {
@@ -6038,22 +6042,22 @@
 {
     [NSGraphicsContext saveGraphicsState];
     [NSGraphicsContext setCurrentContext:[NSGraphicsContext
-                                          graphicsContextWithGraphicsPort:[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] graphicsPort] 
+                                          graphicsContextWithGraphicsPort:[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] graphicsPort]
                                           flipped:YES]];
     [[NSDictionary alloc] initWithObjectsAndKeys:image, NSGraphicsContextDestinationAttributeName, nil];
-    // make a new transform: 
-    NSAffineTransform *t = [NSAffineTransform transform]; 
-    
-    // by scaling Y negatively, we effectively flip the image: 
-    [t scaleXBy:1.0 yBy:-1.0]; 
-    
-    // but we also have to translate it back by its height: 
-    [t translateXBy:0.0 yBy:-size.height]; 
-    
-    // apply the transform: 
-    [t concat]; 
-    [tmpimage drawAtPoint:NSMakePoint(0, 0) fromRect:NSMakeRect(0, 0, size.width, size.height) 
-                operation:NSCompositeSourceOver fraction:1.0];     
+    // make a new transform:
+    NSAffineTransform *t = [NSAffineTransform transform];
+
+    // by scaling Y negatively, we effectively flip the image:
+    [t scaleXBy:1.0 yBy:-1.0];
+
+    // but we also have to translate it back by its height:
+    [t translateXBy:0.0 yBy:-size.height];
+
+    // apply the transform:
+    [t concat];
+    [tmpimage drawAtPoint:NSMakePoint(0, 0) fromRect:NSMakeRect(0, 0, size.width, size.height)
+                operation:NSCompositeSourceOver fraction:1.0];
     [NSGraphicsContext restoreGraphicsState];
 }
 
@@ -6192,9 +6196,12 @@
  */
 void API dw_pixmap_destroy(HPIXMAP pixmap)
 {
-    NSBitmapImageRep *image = (NSBitmapImageRep *)pixmap->image;
-    [image release];
-    free(pixmap);
+    if ( pixmap )
+    {
+       NSBitmapImageRep *image = (NSBitmapImageRep *)pixmap->image;
+       [image release];
+       free(pixmap);
+    }
 }
 
 /*