changeset 856:9dc45928a75f

Added method to do column optimizations like on other platforms. Figure out the maximum width for a column and sizing to that.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 31 Mar 2011 20:58:22 +0000
parents 0103a8751ab4
children 718b91ac19d2
files mac/dw.m
diffstat 1 files changed, 41 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mac/dw.m	Thu Mar 31 19:13:24 2011 +0000
+++ b/mac/dw.m	Thu Mar 31 20:58:22 2011 +0000
@@ -1078,6 +1078,7 @@
 -(void)setLastQueryPoint:(int)input;
 -(void)clear;
 -(void)setup;
+-(void)optimize;
 -(void)setForegroundColor:(NSColor *)input;
 -(void)doubleClicked:(id)sender;
 -(void)keyUp:(NSEvent *)theEvent;
@@ -1226,6 +1227,44 @@
     titles = [[NSPointerArray pointerArrayWithWeakObjects] retain];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selectionChanged:) name:NSTableViewSelectionDidChangeNotification object:self];
 }
+-(void)optimize
+{
+    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];
+            if([column resizingMask] != NSTableColumnNoResizing)
+            {
+                if(rowcount > 0)
+                {
+                    int x;
+                    int width = 0;
+                
+                    for(x=0;x<rowcount;x++)
+                    {
+                        NSCell *cell = [self preparedCellAtColumn:z row:x];
+                        int thiswidth = [cell cellSize].width;
+                    
+                        if(thiswidth > width)
+                        {
+                            width = thiswidth;
+                        }
+                    }
+                    [column setWidth:width];
+                }
+                else
+                {
+                    [column sizeToFit];
+                }
+            }
+        }
+    }
+}
 -(void)setForegroundColor:(NSColor *)input 
 {
     int z, count = (int)[tvcols count];
@@ -5260,7 +5299,8 @@
     int _locked_by_me = FALSE;
     DW_MUTEX_LOCK;
     DWContainer *cont = handle;
-    /*[cont sizeToFit];*/
+    [cont optimize];
+    /* All resizable columns should expand */
     [cont setColumnAutoresizingStyle:NSTableViewUniformColumnAutoresizingStyle];
     DW_MUTEX_UNLOCK;
 }