# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1326505839 0 # Node ID cf897886ceebb45713b6e617dff5e7c644a17d3e # Parent 78a2e6a51285d4e262fcfa28e8e3387a10d4731d Fixed disabling word wrap in the MLE on Mac. Also implemented autosizing of the MLE. diff -r 78a2e6a51285 -r cf897886ceeb mac/dw.m --- a/mac/dw.m Fri Jan 13 22:01:15 2012 +0000 +++ b/mac/dw.m Sat Jan 14 01:50:39 2012 +0000 @@ -3532,13 +3532,48 @@ thisheight = size.height; } } - /* Container */ - else if([ object isMemberOfClass:[DWContainer class] ]) - { - NSRect rect = [object frame]; + /* MLE and Container */ + else if([ object isMemberOfClass:[DWMLE class] ] || + [ object isMemberOfClass:[DWContainer class] ]) + { + NSSize size; - thiswidth = rect.size.width; - thisheight = rect.size.height; + if([ object isMemberOfClass:[DWMLE class] ]) + { + NSScrollView *sv = [object scrollview]; + NSSize frame = [sv frame].size; + BOOL hscroll = [sv hasHorizontalScroller]; + + if(!hscroll) + { + [[object textContainer] setWidthTracksTextView:NO]; + [[object textContainer] setContainerSize:[object maxSize]]; + [object setHorizontallyResizable:YES]; + [sv setHasHorizontalScroller:YES]; + } + [object sizeToFit]; + size = [object bounds].size; + if(!hscroll) + { + [[object textContainer] setWidthTracksTextView:YES]; + [sv setHasHorizontalScroller:NO]; + } + if(size.width > _DW_SCROLLED_MAX_WIDTH) + { + NSSize max = [object maxSize]; + + [object setMaxSize:NSMakeSize(_DW_SCROLLED_MAX_WIDTH, max.height)]; + [object sizeToFit]; + size = [object bounds].size; + [object setMaxSize:max]; + } + [sv setFrameSize:frame]; + } + else + size = [object frame].size; + + thiswidth = size.width; + thisheight = size.height; if(thiswidth < _DW_SCROLLED_MIN_WIDTH) thiswidth = _DW_SCROLLED_MIN_WIDTH; @@ -3549,9 +3584,8 @@ if(thisheight > _DW_SCROLLED_MAX_HEIGHT) thisheight = _DW_SCROLLED_MAX_HEIGHT; } - /* MLE and Tree */ - else if([ object isMemberOfClass:[DWMLE class] ] || - [ object isMemberOfClass:[DWTree class] ]) + /* Tree */ + else if([ object isMemberOfClass:[DWTree class] ]) { thiswidth = _DW_SCROLLED_MAX_WIDTH; thisheight = _DW_SCROLLED_MAX_HEIGHT; @@ -4677,13 +4711,17 @@ { DWMLE *mle = [[DWMLE alloc] init]; NSScrollView *scrollview = [[NSScrollView alloc] init]; - + NSSize size = [mle maxSize]; + + size.width = size.height; + [mle setMaxSize:size]; [scrollview setBorderType:NSBezelBorder]; [scrollview setHasVerticalScroller:YES]; [scrollview setAutohidesScrollers:YES]; [scrollview setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable]; [scrollview setDocumentView:mle]; - [mle setAutoresizingMask:NSViewWidthSizable]; + [mle setVerticallyResizable:YES]; + [mle setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable]; [mle setScrollview:scrollview]; /* [mle setTag:cid]; Why doesn't this work? */ [mle autorelease]; @@ -4859,13 +4897,19 @@ void API dw_mle_set_word_wrap(HWND handle, int state) { DWMLE *mle = handle; + NSScrollView *sv = [mle scrollview]; + if(state) { - [mle setHorizontallyResizable:NO]; + [[mle textContainer] setWidthTracksTextView:YES]; + [sv setHasHorizontalScroller:NO]; } else { + [[mle textContainer] setWidthTracksTextView:NO]; + [[mle textContainer] setContainerSize:[mle maxSize]]; [mle setHorizontallyResizable:YES]; + [sv setHasHorizontalScroller:YES]; } }