# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1301361945 0 # Node ID 89d4bad9c96e26da95f2a9a4ad88224b84cc00a7 # Parent 28f9810dfebc6522298c01bf6d208592e346b77d Initial attempt at implementing the scrollbox on the Mac. diff -r 28f9810dfebc -r 89d4bad9c96e mac/dw.m --- a/mac/dw.m Sun Mar 27 19:08:45 2011 +0000 +++ b/mac/dw.m Tue Mar 29 01:25:45 2011 +0000 @@ -695,6 +695,21 @@ -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } @end +/* Subclass for a scrollbox type */ +@interface DWScrollBox : NSScrollView +{ + void *userdata; +} +-(void *)userdata; +-(void)setUserdata:(void *)input; +@end + +@implementation DWScrollBox +-(void *)userdata { return userdata; } +-(void)setUserdata:(void *)input { userdata = input; } +-(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } +@end + /* Subclass for a entryfield type */ @interface DWEntryField : NSTextField { @@ -2037,6 +2052,33 @@ _do_resize(box, size.width, size.height); } } + /* Handle laying out scrollviews... if required space is less + * than available space, then expand. Otherwise use required space. + */ + else if([handle isMemberOfClass:[DWScrollBox class]]) + { + int usedx = 0, usedy = 0, usedpadx = 0, usedpady = 0, depth = 0; + DWScrollBox *scrollbox = (DWScrollBox *)handle; + DWBox *contentbox = [scrollbox documentView]; + Box *thisbox = [contentbox box]; + NSSize contentsize = [scrollbox contentSize]; + + /* Get the required space for the box */ + _resize_box(thisbox, &depth, x, y, &usedx, &usedy, 1, &usedpadx, &usedpady); + + if(contentsize.width < usedx) + { + contentsize.width = usedx; + } + if(contentsize.height < usedy) + { + contentsize.height = usedy; + } + [contentbox setFrameSize:contentsize]; + + /* Layout the content of the scrollbox */ + _do_resize(thisbox, contentsize.width, contentsize.height); + } /* Special handling for spinbutton controls */ else if([handle isMemberOfClass:[DWSpinButton class]]) { @@ -2576,10 +2618,13 @@ */ HWND API dw_scrollbox_new( int type, int pad ) { - DWBox *box = dw_box_new(type, pad); - [box setFocusRingType:NSFocusRingTypeExterior]; - NSLog(@"dw_scrollbox_new() unimplemented\n"); - return box; + DWScrollBox *scrollbox = [[DWScrollBox alloc] init]; + DWBox *box = dw_box_new(type, pad); + [scrollbox setHasVerticalScroller:YES]; + [scrollbox setHasHorizontalScroller:YES]; + [scrollbox setBorderType:NSNoBorder]; + [scrollbox setDocumentView:box]; + return scrollbox; } /* @@ -2637,6 +2682,11 @@ NSWindow *window = box; view = [window contentView]; } + else if([ object isMemberOfClass:[ DWScrollBox class ] ]) + { + DWScrollBox *scrollbox = box; + view = [scrollbox documentView]; + } thisbox = [view box]; thisitem = thisbox->items; @@ -2740,6 +2790,11 @@ NSWindow *window = box; view = [window contentView]; } + else if([ object isMemberOfClass:[ DWScrollBox class ] ]) + { + DWScrollBox *scrollbox = box; + view = [scrollbox documentView]; + } thisbox = [view box]; thisitem = thisbox->items; @@ -4981,6 +5036,10 @@ */ void API dw_container_scroll(HWND handle, int direction, long rows) { +#if 0 + DWContainer *cont = handle; + NSScrollView *sv = [cont scrollview]; +#endif NSLog(@"dw_container_scroll() unimplemented\n"); }