comparison mac/dw.m @ 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
comparison
equal deleted inserted replaced
676:9861d264925d 677:99002595f549
457 } 457 }
458 -(void)setDialog:(DWDialog *)input { dialog = input; } 458 -(void)setDialog:(DWDialog *)input { dialog = input; }
459 @end 459 @end
460 460
461 /* Subclass for a splitbar type */ 461 /* Subclass for a splitbar type */
462 @interface DWSplitBar : NSSplitView <NSSplitViewDelegate> { } 462 @interface DWSplitBar : NSSplitView <NSSplitViewDelegate>
463 - (void)splitViewDidResizeSubviews:(NSNotification *)aNotification; 463 {
464 void *userdata;
465 float percent;
466 }
467 -(void)splitViewDidResizeSubviews:(NSNotification *)aNotification;
468 -(void *)userdata;
469 -(void)setUserdata:(void *)input;
470 -(float)percent;
471 -(void)setPercent:(float)input;
464 @end 472 @end
465 473
466 @implementation DWSplitBar 474 @implementation DWSplitBar
467 - (void)splitViewDidResizeSubviews:(NSNotification *)aNotification 475 -(void)splitViewDidResizeSubviews:(NSNotification *)aNotification
468 { 476 {
469 NSArray *views = [self subviews]; 477 NSArray *views = [self subviews];
470 id object; 478 id object;
471 479
472 for(object in views) 480 for(object in views)
478 NSSize size = [view frame].size; 486 NSSize size = [view frame].size;
479 _do_resize(box, size.width, size.height); 487 _do_resize(box, size.width, size.height);
480 } 488 }
481 } 489 }
482 } 490 }
491 -(void *)userdata { return userdata; }
492 -(void)setUserdata:(void *)input { userdata = input; }
493 -(float)percent { return percent; }
494 -(void)setPercent:(float)input { percent = input; }
483 @end 495 @end
484 496
485 /* Subclass for a slider type */ 497 /* Subclass for a slider type */
486 @interface DWSlider : NSSlider 498 @interface DWSlider : NSSlider
487 { 499 {
1184 } 1196 }
1185 else if([handle isMemberOfClass:[DWRender class]]) 1197 else if([handle isMemberOfClass:[DWRender class]])
1186 { 1198 {
1187 _event_handler(handle, nil, 1); 1199 _event_handler(handle, nil, 1);
1188 } 1200 }
1201 else if([handle isMemberOfClass:[DWSplitBar class]] && size.width > 20 && size.height > 20)
1202 {
1203 DWSplitBar *split = (DWSplitBar *)handle;
1204 float percent = [split percent];
1205
1206 if(percent > 0)
1207 {
1208 dw_splitbar_set(handle, percent);
1209 [split setPercent:0];
1210 }
1211 }
1189 1212
1190 if(thisbox->type == DW_HORZ) 1213 if(thisbox->type == DW_HORZ)
1191 currentx += width + vectorx + (pad * 2); 1214 currentx += width + vectorx + (pad * 2);
1192 if(thisbox->type == DW_VERT) 1215 if(thisbox->type == DW_VERT)
1193 currenty += height + vectory + (pad * 2); 1216 currenty += height + vectory + (pad * 2);
3840 void API dw_splitbar_set(HWND handle, float percent) 3863 void API dw_splitbar_set(HWND handle, float percent)
3841 { 3864 {
3842 DWSplitBar *split = handle; 3865 DWSplitBar *split = handle;
3843 NSRect rect = [split frame]; 3866 NSRect rect = [split frame];
3844 float pos; 3867 float pos;
3868 /* Calculate the position based on the size */
3845 if([split isVertical]) 3869 if([split isVertical])
3870 {
3871 pos = rect.size.width * (percent / 100.0);
3872 }
3873 else
3846 { 3874 {
3847 pos = rect.size.height * (percent / 100.0); 3875 pos = rect.size.height * (percent / 100.0);
3848 } 3876 }
3877 if(pos > 0)
3878 {
3879 [split setPosition:pos ofDividerAtIndex:0];
3880 }
3849 else 3881 else
3850 { 3882 {
3851 pos = rect.size.width * (percent / 100.0); 3883 /* If we have no size.. wait until the resize
3884 * event when we get an actual size to try
3885 * to set the splitbar again.
3886 */
3887 [split setPercent:percent];
3852 } 3888 }
3853 [split setPosition:pos ofDividerAtIndex:0];
3854 } 3889 }
3855 3890
3856 /* 3891 /*
3857 * Gets the position of a splitbar (pecentage). 3892 * Gets the position of a splitbar (pecentage).
3858 * Parameters: 3893 * Parameters:
3866 NSView *view = [subviews objectAtIndex:0]; 3901 NSView *view = [subviews objectAtIndex:0];
3867 NSRect rect2 = [view frame]; 3902 NSRect rect2 = [view frame];
3868 float pos, total, retval = 0.0; 3903 float pos, total, retval = 0.0;
3869 if([split isVertical]) 3904 if([split isVertical])
3870 { 3905 {
3871 total = rect1.size.height; 3906 total = rect1.size.width;
3872 pos = rect2.size.height; 3907 pos = rect2.size.width;
3873 } 3908 }
3874 else 3909 else
3875 { 3910 {
3876 total = rect1.size.width; 3911 total = rect1.size.height;
3877 pos = rect2.size.width; 3912 pos = rect2.size.height;
3878 } 3913 }
3879 if(total > 0) 3914 if(total > 0)
3880 { 3915 {
3881 retval = pos / total; 3916 retval = pos / total;
3882 } 3917 }