nstextview scrolling
nstextview scrolling
- Subject: nstextview scrolling
- From: Devon E Bowen <email@hidden>
- Date: Thu, 8 Jan 2004 10:56:26 -0500 (EST)
The recently posted NSTextView info helped me get rid of word wrap in
my NSTextView and enable horizontal scrolling. But I can't get the last
piece of my puzzle solved.
What I'm trying to do is make a simple log window. As events happen, I
want to write a one-line string into the NSTextView. As new message
are added, they should be visible (ie, the scroller should follow them).
This means after each addition I want to do something like a
[log scrollRangeToVisible: NSMakeRange([[log textStorage] length], 0)];
so it's visible. But I only want to do this when the scrollbar is set
to the end already. If the user scrolled up to see something, I don't
want to yank control away! In that case, just append the text and leave
the scrollbar alone.
I was solving this by examining the setting of the vertical scrollbar
before each modification of the NSTextView. I do this with
NSScroller *vert = [[log enclosingScrollView] verticalScroller];
BOOL changeScroll = ([vert floatValue] == 1.0 || [vert isEnabled] == FALSE);
before I make a change. Then, after the change, if changeScroll is set,
I force the scroller to the bottom as explained before. Basically, the
above code means "if the last line of text is visible, make changeScroll
TRUE".
I also had to do this inside the
- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)proposedFrameSize
- (void)windowDidResize:(NSNotification *)aNotification
delegates. Because if you change the size of the window that holds the
NSTextView, a scroller that was previously disabled might become
enabled and need to be set to the bottom.
All this *almost* works. The problem is that, for some bizarre reason,
when you let go of the corner of a window after resizing it, it
fiddles with the scroller in any NSTextView inside of it. Let's say I
have an NSTextView inside of a window and the vertical scroller in
that NSTextView is all the way at the bottom. In other words, the last
line is visible and if I ask it for it's 'floatValue' it says 1.0.
Now, if I click on the lower right corner of the window to resize it,
and then release, it will bump the NSTextView scroller up slightly.
Maybe to 0.93 or something like that. This happens even if I don't
change the size of the window! For no apparent reason. Simply clicking
on the corner and letting go does it.
Since this looks to me like a flaw in the GUI classes, I guess I am
in need of another solution to making determining whether the last
line is already visible. Or I need to fix the one I have. If anyone
has made it this far and has any suggestions, I'd love to hear them!
In any case, thanks for letting me vent...
Devon
_______________________________________________
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.