Re: Duh (NSTextView & Word Wrapping)
Re: Duh (NSTextView & Word Wrapping)
- Subject: Re: Duh (NSTextView & Word Wrapping)
- From: "Louis C. Sacha" <email@hidden>
- Date: Sat, 27 Dec 2003 16:03:37 -0800
Hello...
This is one of those things that seems like it should be trivial to
do, but it takes a bit of time messing around and a decent knowledge
of the text system architecture (or a willingness to spend some time
reading the documentation and the ability to put all the little
pieces together). I doubt there is any way to do this directly in IB,
although it's fairly easy to do programmatically within the
awakeFromNib method.
(1) The palletized NSTextView in InterfaceBuilder is hardwired for
scrolling in the vertical direction, so the first thing you need to
do is tell the scrollView that it needs to also scroll in the
horizontal direction.
(2) Next, NSTextView inherits a method from NSText
(setHorizontallyResizable:) that allows you to change how the
NSTextView frame interacts with the used text container rect, and
setting the flag to TRUE will cause the NSTextView to resize
horizontally to fit the largest line, similarly to the way it resizes
vertically as the number of lines increases by default.
(3) You also need to reset the maximum width of the NSTextView frame,
since it is set to the width of the NSScrollView contentRect by
default. A very large number (100,000 is the vertical default, I
think) is used to indicate that the NSTextField should grow to any
size, and you can just copy this value from the height of the maxSize
to the width, since by default the NSTextView resizes vertically as
needed.
(4) The NSTextContainer instance attached to the NSTextView watches
changes in the width of the NSTextView to update itself automatically
when the view is resized. This is on by default for the width, so it
needs to be turned off so the text doesn't start wrapping when the
window or view is resized.
(5) The NSTextContainer instance is also the part that controls how
the layoutManager wraps text, so you will need to change the maximum
size of the container, using the same new size from the NSTextView
max frame size used in (3) above.
/* WARNING: Code typed/edited in mail, so user beware... */
So, you can add the following code to your awakeFromNib method:
/* outputField is the IBOutlet to your textView object */
[[outputField enclosingScrollView]
setHasHorizontalScroller:TRUE]; /* (1) */
[outputField setHorizontallyResizable:TRUE]; /* (2) */
NSSize layoutSize = [outputField maxSize]; /* (3) */
layoutSize.width = layoutSize.height;
[outputField setMaxSize:layoutSize];
[[outputField textContainer] setWidthTracksTextView:FALSE]; /* (4) */
[[outputField textContainer] setContainerSize:layoutSize]; /* (5) */
The NSTextView should allow you to type lines of any length without
wrapping the text, and the scroll bars should work correctly as text
is added/typed/pasted into the textView...
Hope that helps,
Louis
Ok, in a fit of stupidity, I'm trying to disable wordwrapping in an
NSTextView, and I cannot for the life of me find the documentation
on how to do so....
Any suggestions (Hari-Kari is out of the question)
Andy
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.