Skip to content
Browse files

Removed setScrollable and added setDocumentSize for IsScrollable and …

…updated CTTextArea so that TextAreas are always scrollable in both directions given that its "needed" (there is content not visible).
  • Loading branch information...
1 parent 5447ddb commit d8afef2b95da05ff3f480327286ad1a25c4bdc05 @danielohrlund committed Nov 3, 2011
Showing with 51 additions and 68 deletions.
  1. +32 −45 CTTextArea.extern.c
  2. +16 −20 CTTextArea.t
  3. +3 −3 CocoaDef.t
View
77 CTTextArea.extern.c
@@ -8,21 +8,26 @@ Int initTextArea_CTTextArea(World w, Int dummy) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
scrollView = [[NSScrollView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)];
NSSize contentSize = [scrollView contentSize];
- [scrollView setBorderType:NSNoBorder];
- [scrollView setHasVerticalScroller:NO];
- [scrollView setHasHorizontalScroller:NO];
+ [scrollView setBorderType: NSNoBorder];
+ [scrollView setHasVerticalScroller: YES];
+ [scrollView setHasHorizontalScroller: YES];
+
NSTextView *theTextView = [[NSTextView alloc]
- initWithFrame:NSMakeRect(0, 0, contentSize.width, contentSize.height)];
- [theTextView setMinSize:NSMakeSize(0.0, contentSize.height)];
- [theTextView setMaxSize:NSMakeSize(FLT_MAX, FLT_MAX)];
- // [theTextView setVerticallyResizable:YES];
- // [theTextView setHorizontallyResizable:NO];
- [theTextView setAutoresizingMask:NSViewWidthSizable];
- [[theTextView textContainer]
- setContainerSize:NSMakeSize(contentSize.width, FLT_MAX)];
- [[theTextView textContainer] setWidthTracksTextView:YES];
- [scrollView setDocumentView:theTextView];
- [theTextView setString: @"defaultTextAreaString"];
+ initWithFrame: NSMakeRect(0, 0, 1, 1)];
+
+ [theTextView setMinSize:NSMakeSize(0.0, 0.0)];
+ [theTextView setMaxSize:NSMakeSize(1.0, 1.0)];
+
+ [theTextView setVerticallyResizable: YES];
+ [theTextView setHorizontallyResizable: YES];
+ [theTextView setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)];
+
+ [[theTextView textContainer] setContainerSize: NSMakeSize(1, 1)];
+ [[theTextView textContainer] setWidthTracksTextView: NO];
+
+ [scrollView setDocumentView: theTextView];
+
+ [theTextView setString: @""];
[pool drain];
});
return (Int)scrollView;
@@ -34,8 +39,8 @@ TUP0 textAreaSetText_CTTextArea(Int cocoaRef, LIST str, Int dummy) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSScrollView *scrollView = (NSScrollView*) cocoaRef;
NSTextView *theTextView = [scrollView documentView];
- [theTextView setString:[NSString stringWithFormat:@"%s", buf]];
- [theTextView setNeedsDisplay:YES];
+ [theTextView setString: [NSString stringWithFormat:@"%s", buf]];
+ [theTextView setNeedsDisplay: YES];
[theTextView displayIfNeeded];
[pool drain];
free(buf);
@@ -51,7 +56,7 @@ TUP0 textAreaSetPosition_CTTextArea(Int cocoaRef, Position_CocoaDef pos, Int dum
NSTextView *theTextView = [scrollView documentView];
NSPoint p = NSMakePoint(x,y);
[scrollView setFrameOrigin: p];
- [theTextView setNeedsDisplay:YES];
+ [theTextView setNeedsDisplay: YES];
[theTextView displayIfNeeded];
[pool drain];
});
@@ -64,46 +69,28 @@ TUP0 textAreaSetSize_CTTextArea(Int cocoaRef, Size_CocoaDef size, Int dummy) {
NSScrollView *scrollView = (NSScrollView*) cocoaRef;
NSTextView *theTextView = [scrollView documentView];
[scrollView setFrameSize: NSMakeSize(width,height)];
- [theTextView setMinSize:NSMakeSize(width,height)];
- [theTextView setMaxSize:NSMakeSize(FLT_MAX, FLT_MAX)];
- [theTextView setVerticallyResizable:YES];
- [theTextView setHorizontallyResizable:YES];//???
- [theTextView setAutoresizingMask:NSViewWidthSizable];
- [[theTextView textContainer] setContainerSize:NSMakeSize(FLT_MAX, FLT_MAX)];
- [theTextView setNeedsDisplay:YES];
+ [scrollView setNeedsDisplay:YES];
[pool drain];
});
}
-TUP0 textAreaSetHorizontalScroll_CTTextArea(Int cocoaRef, Bool enabled, Int dummy) {
+TUP0 textAreaSetDocumentSize_CTTextArea(Int cocoaRef, Size_CocoaDef size, Int dummy) {
+ int width = size->width_CocoaDef;
+ int height = size->height_CocoaDef;
dispatch_async(dispatch_get_main_queue(), ^{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSScrollView *scrollView = (NSScrollView*) cocoaRef;
NSTextView *theTextView = [scrollView documentView];
- [scrollView setHasHorizontalScroller:enabled];
- [theTextView setHorizontallyResizable:enabled];
- [[theTextView textContainer] setContainerSize:NSMakeSize(FLT_MAX, FLT_MAX)];
- [theTextView setNeedsDisplay:YES];
- [pool drain];
- });
-}
+
+ [theTextView setMaxSize: NSMakeSize(width, height)];
+ [[theTextView textContainer] setContainerSize: NSMakeSize(width, height)];
-TUP0 textAreaSetVerticalScroll_CTTextArea(Int cocoaRef, Bool enabled, Int dummy) {
- dispatch_async(dispatch_get_main_queue(), ^{
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- NSScrollView *scrollView = (NSScrollView*) cocoaRef;
- NSTextView *theTextView = [scrollView documentView];
- [scrollView setHasVerticalScroller:enabled];
- [theTextView setVerticallyResizable:enabled];
- // NSUInteger mask = (enabled) ? [theTextView autoresizingMask]:0;
- // [theTextView setAutoresizingMask:(mask | NSViewHeightSizable)];
- [[theTextView textContainer] setContainerSize:NSMakeSize(FLT_MAX, FLT_MAX)];
-
[theTextView setNeedsDisplay:YES];
[pool drain];
});
-}
-
+}
+
+// TODO: move to extended NSTextView to support more than one textarea!
static float x = 0;
static float y = 0;
View
36 CTTextArea.t
@@ -5,9 +5,7 @@ import COCOA
struct TextArea < Component, HasText, IsScrollable
mkCocoaTextArea :: World -> Class TextArea
-mkCocoaTextArea w = class
- text := ""
-
+mkCocoaTextArea w = class
state := Inactive
getState = request
result state
@@ -31,29 +29,31 @@ mkCocoaTextArea w = class
setResponders rs = request
setRespondersImpl (dts:rs)
- scrollable := (True, True)
- getScrollable = request
- result scrollable
+ documentSize := {width=1; height=1}
+ getDocumentSize = request
+ result documentSize
- setScrollable s = request
- scrollable := s
+ setDocumentSize s = request
+ documentSize := s
if isActive state then
Active ref = state
- (hoz,vert) = s
- textAreaSetHorizontalScroll ref hoz
- textAreaSetVerticalScroll ref vert
+ textAreaSetDocumentSize ref s
+ text := ""
+ getText = request
+ result text
+
appendText s = request
text := text ++ s
+ if isActive state then
+ Active ref = state
+ textAreaSetText ref text
setText s = request
text := s
if isActive state then
Active ref = state
textAreaSetText ref s
-
- getText = request
- result text
destroyComp = request
state := destroyState state
@@ -65,10 +65,7 @@ mkCocoaTextArea w = class
textAreaSetText ref text
textAreaSetPosition ref (<- getPosition)
textAreaSetSize ref (<- getSize)
-
- (hoz,vert) = scrollable
- textAreaSetHorizontalScroll ref hoz
- textAreaSetVerticalScroll ref vert
+ textAreaSetDocumentSize ref documentSize
addResponder dts
result ref
@@ -107,6 +104,5 @@ extern initTextArea :: World -> Request CocoaRef
extern textAreaSetText :: CocoaRef -> String -> Request ()
extern textAreaSetPosition :: CocoaRef -> Position -> Request ()
extern textAreaSetSize :: CocoaRef -> Size -> Request ()
-extern textAreaSetHorizontalScroll :: CocoaRef -> Bool -> Request ()
-extern textAreaSetVerticalScroll :: CocoaRef -> Bool -> Request ()
+extern textAreaSetDocumentSize :: CocoaRef -> Size -> Request ()
extern textAreaScrollTo :: CocoaRef -> Float -> Float -> Request ()
View
6 CocoaDef.t
@@ -121,9 +121,9 @@ struct HasText where
appendText :: String -> Request ()
struct IsScrollable where
- setScrollable :: (Bool, Bool) -> Request ()
- getScrollable :: Request (Bool, Bool)
-
+ setDocumentSize :: Size -> Request ()
+ getDocumentSize :: Request Size
+
struct IsFocusable where
setIsFocusable :: Bool -> Request ()
getIsFocusable :: Request Bool

0 comments on commit d8afef2

Please sign in to comment.
Something went wrong with that request. Please try again.