changeset 1573:d6e17c8f4de2

Fixed container and listbox not accounting for contents on Mac.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 22 Jan 2012 18:46:20 +0000
parents e6a2e6405d30
children ae5e322584cd
files mac/dw.m
diffstat 1 files changed, 66 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mac/dw.m	Sun Jan 22 12:30:20 2012 +0000
+++ b/mac/dw.m	Sun Jan 22 18:46:20 2012 +0000
@@ -1622,6 +1622,7 @@
 -(void)clear;
 -(void)setup;
 -(void)optimize;
+-(NSSize)getsize;
 -(void)setForegroundColor:(NSColor *)input;
 -(void)doubleClicked:(id)sender;
 -(void)keyUp:(NSEvent *)theEvent;
@@ -1835,6 +1836,70 @@
     titles = [[NSPointerArray pointerArrayWithWeakObjects] retain];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selectionChanged:) name:NSTableViewSelectionDidChangeNotification object:self];
 }
+-(NSSize)getsize
+{
+    int cwidth = 0, cheight = 0;
+    NSSize size = [self frame].size;
+    
+    if(tvcols)
+    {
+        int z;
+        int colcount = (int)[tvcols count];
+        int rowcount = (int)[self numberOfRowsInTableView:self];
+        
+        for(z=0;z<colcount;z++)
+        {
+            NSTableColumn *column = [tvcols objectAtIndex:z];
+            NSCell *colcell = [column headerCell];
+            int width = [colcell cellSize].width;
+            
+            if(rowcount > 0)
+            {
+                int x;
+                
+                for(x=0;x<rowcount;x++)
+                {
+                    NSCell *cell = [self preparedCellAtColumn:z row:x];
+                    int thiswidth = [cell cellSize].width;
+                    
+                    /* If on the first column... add up the heights */
+                    if(z == 0)
+                        cheight += [cell cellSize].height;
+                    
+                    /* Check the image inside the cell to get its width */
+                    if([cell isMemberOfClass:[NSImageCell class]])
+                    {
+                        int index = (int)(x * [tvcols count]) + z;
+                        NSImage *image = [data objectAtIndex:index];
+                        if([image isMemberOfClass:[NSImage class]])
+                        {
+                            thiswidth = [image size].width;
+                        }
+                    }
+                    
+                    if(thiswidth > width)
+                    {
+                        width = thiswidth;
+                    }
+                }
+                /* If the image is missing default the optimized width to 16. */
+                if(!width && [[types objectAtIndex:z] intValue] & DW_CFA_BITMAPORICON)
+                {
+                    width = 16;
+                }
+            }
+            if(width)
+                cwidth += width;
+        }
+    }
+    cwidth += 16;
+    cheight += 16;
+    if(size.width > cwidth)
+        cwidth = size.width;
+    if(size.height > cheight)
+        cheight = size.height;
+    return NSMakeSize(cwidth, cheight);
+}
 -(void)optimize
 {
     if(tvcols)
@@ -3618,7 +3683,7 @@
                 size.height += 16.0;
         }
         else
-            size = [object frame].size;
+            size = [object getsize];
         
         thiswidth = size.width;
         thisheight = size.height;