changeset 677:99002595f549

Fixes for dw_splitbar_set() not working on an unsized window.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 01 Mar 2011 13:32:40 +0000
parents 9861d264925d
children 0ec8edbb82cf
files mac/dw.m
diffstat 1 files changed, 44 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/mac/dw.m	Tue Mar 01 04:37:11 2011 +0000
+++ b/mac/dw.m	Tue Mar 01 13:32:40 2011 +0000
@@ -459,12 +459,20 @@
 @end
 
 /* Subclass for a splitbar type */
-@interface DWSplitBar : NSSplitView <NSSplitViewDelegate> { }
-- (void)splitViewDidResizeSubviews:(NSNotification *)aNotification;
+@interface DWSplitBar : NSSplitView <NSSplitViewDelegate> 
+{ 
+	void *userdata; 
+    float percent;
+}
+-(void)splitViewDidResizeSubviews:(NSNotification *)aNotification;
+-(void *)userdata;
+-(void)setUserdata:(void *)input;
+-(float)percent;
+-(void)setPercent:(float)input;
 @end
 
 @implementation DWSplitBar
-- (void)splitViewDidResizeSubviews:(NSNotification *)aNotification
+-(void)splitViewDidResizeSubviews:(NSNotification *)aNotification
 {
 	NSArray *views = [self subviews];
 	id object;
@@ -480,6 +488,10 @@
 		}
 	}		
 }
+-(void *)userdata { return userdata; }
+-(void)setUserdata:(void *)input { userdata = input; }
+-(float)percent { return percent; }
+-(void)setPercent:(float)input { percent = input; }
 @end
 
 /* Subclass for a slider type */
@@ -1186,6 +1198,17 @@
 			{
 				_event_handler(handle, nil, 1);
 			}
+			else if([handle isMemberOfClass:[DWSplitBar class]] && size.width > 20 && size.height > 20)
+			{
+                DWSplitBar *split = (DWSplitBar *)handle;
+				float percent = [split percent];
+                
+                if(percent > 0)
+                {
+                    dw_splitbar_set(handle, percent);
+                    [split setPercent:0];
+                }
+			}
 			 
 			if(thisbox->type == DW_HORZ)
                currentx += width + vectorx + (pad * 2);
@@ -3842,15 +3865,27 @@
 	DWSplitBar *split = handle;
     NSRect rect = [split frame];
     float pos;
+    /* Calculate the position based on the size */
     if([split isVertical])
     {
+        pos = rect.size.width * (percent / 100.0);
+    }
+    else
+    {
         pos = rect.size.height * (percent / 100.0);
     }
+    if(pos > 0)
+    {
+        [split setPosition:pos ofDividerAtIndex:0];
+    }
     else
     {
-        pos = rect.size.width * (percent / 100.0);
+        /* If we have no size.. wait until the resize
+         * event when we get an actual size to try 
+         * to set the splitbar again.
+         */
+        [split setPercent:percent];
     }
-	[split setPosition:pos ofDividerAtIndex:0];
 }
 
 /*
@@ -3868,13 +3903,13 @@
     float pos, total, retval = 0.0;
     if([split isVertical])
     {
-        total = rect1.size.height;
-        pos = rect2.size.height;
+        total = rect1.size.width;
+        pos = rect2.size.width;
     }
     else
     {
-        total = rect1.size.width;
-        pos = rect2.size.width;
+        total = rect1.size.height;
+        pos = rect2.size.height;
     }
     if(total > 0)
     {