Re: Horizontally scrolling NSTextView in IB
Re: Horizontally scrolling NSTextView in IB
- Subject: Re: Horizontally scrolling NSTextView in IB
- From: Boyd Collier <email@hidden>
- Date: Thu, 12 Jan 2006 13:40:54 -0800
By coincidence, I was also trying to implement horizontal scrolling
in a document-based application. I followed the example discussed in
Apple's documentation at
http://developer.apple.com/documentation/Cocoa/Conceptual/TextUILayer/
Tasks/TextInScrollView.html#//apple_ref/doc/uid/20000938
which your message led me to (thanks!). However, since I had already
done the coding, including creating a nib file for the document
window, without horizontal scrolling, I made some changes to what I
already so that I could use my already existing instance of
NSTextView rather than allocating one, as is done in Apple's sample
code. But in my first attempt, the text in my document window didn't
scroll horizontally. However, when I changed
[textView setMinSize:NSMakeSize(0.0, contentSize.height)];
to
[textView setMinSize:NSMakeSize(contentSize.width, contentSize.height)];
my text scrolled horizontally. QUESTION: Is this an error in Apple's
documentation, or have I missed something somewhere (I'm new at
cocoa, so this has a high probability)?
Rant: Vertical scrolling is a piece of cake. Seems to me that
horizontal scrolling is common enough that it should be made much
more straightforward to implement.
Thanks in advance to anyone who can give me some hints, criticism,
advice, etc.
Boyd
Here is my code for my document, where I override
windowControllerDidLoadNib and set up horizontal scrolling, using
Apple's sample code:
- (void)windowControllerDidLoadNib:(NSWindowController *) aController {
[super windowControllerDidLoadNib:aController];
NSRect frameRect;
NSWindow *theWindow = [(NSView *)textView window];
frameRect = [(NSView *)textView frame];
NSScrollView *scrollview = [[NSScrollView alloc] initWithFrame:
[[theWindow contentView] frame]];
NSSize contentSize = [scrollview contentSize];
[scrollview setBorderType:NSNoBorder];
[scrollview setHasVerticalScroller:YES];
[scrollview setHasHorizontalScroller:YES]; // changed, for
horizontal scrolling
[scrollview setAutoresizingMask:NSViewWidthSizable |
NSViewHeightSizable]; // should there be parens??
frameRect = NSMakeRect(0,0, contentSize.width, contentSize.height);
[textView setFrame:frameRect];
[[textView enclosingScrollView] setHasHorizontalScroller:YES]; //
added for horizontal scrolling
// [textView setMinSize:NSMakeSize(0.0, contentSize.height)]; // Is
this an error in Apple's documentation??
[textView setMinSize:NSMakeSize(contentSize.width,
contentSize.height)]; // my change to Apple's code
[textView setMaxSize:NSMakeSize(FLT_MAX, FLT_MAX)];
[textView setVerticallyResizable:YES];
[textView setHorizontallyResizable:YES]; // for horizontal
scrolling
[textView setAutoresizingMask:(NSViewWidthSizable |
NSViewHeightSizable)]; // for horizontal scrolling
[[textView textContainer] setContainerSize:NSMakeSize(FLT_MAX,
FLT_MAX)]; // for horizontal scrolling
[[textView textContainer] setWidthTracksTextView:NO]; // for
horizontal scrolling
[scrollview setDocumentView:textView];
[theWindow setContentView:scrollview];
[theWindow makeKeyAndOrderFront:nil];
[theWindow makeFirstResponder:textView];
[self updateView]; // my code, not from Apple doc
}
On Jan 5, 2006, at 3:42 PM, Camillo Lugaresi wrote:
On 05/gen/06, at 21:58, Camillo Lugaresi wrote:
However, I encountered a weird bug with that approach: the
scroller would only grow horizontally to a certain (small) limit,
after which I could continue typing on a single line, but I
couldn't scroll far enough to see its end. This was fixed when I
changed the width of the NSTextView's layout rectangle to a very
big value, then turned it back to match the width of the
NSScrollView. Even though all visible properties in IB were the
same as before, the bug was now gone and the scroller could grow
freely. What happened?
A wild guess is that my maneuver might have increased the
NSTextView's maxSize, but why isn't that visible anywhere in IB?
That guess turned out to be correct, btw:
(gdb) print (NSSize) [cmd_text maxSize]
$1 = {
width = 2000,
height = 10000000
}
Camillo
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden