changeset 1551:cf897886ceeb

Fixed disabling word wrap in the MLE on Mac. Also implemented autosizing of the MLE.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 14 Jan 2012 01:50:39 +0000
parents 78a2e6a51285
children f00f91d15cbf
files mac/dw.m
diffstat 1 files changed, 56 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- 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];
     }
 }