Ask a Question related to Mac Programming, Design and Development.
-
Per Bull Holmen #1
NSTextView problems plus a few others...
Hey
I am trying to make an NSTextView resize itself to fit the text as the
user types. These are the steps I take:
NSView *superView; // Not a scrollview;
NSTextView *textView = [[NSTextView alloc] initWithFrame:textViewFrame];
[textView setDrawsBackground:NO];
[textView setVerticallyResizable:YES];
[textView setHorizontallyResizable:YES];
[superView addSubview:textView];
----
Docu says:
NSText superclass of NSTextView
- (void) setVerticallyResizable: (BOOL) flag
Controls whether the receiver changes its height to fit the height of
its text. If flag is YES it does; if flag is NO it doesn't.
- (void) setHorizontallyResizable: (BOOL) flag
Controls whether the receiver changes its width to fit the width of its
text. If flag is YES it does; if flag is NO it doesn't.
----
This doesn't work as I expected, I get two problems:
1) When the user has written past the textviews width, it doesn't resize
but wraps. I have tried to find a way to prevent it from wrapping,
NSParagraphStyle's NSLineBreakByClipping stops it from wrapping, but the
view still doesn't resize.
2) The view DOES resize the height as expected. But as it resizes, it
jumps down (and up) on its superview.
----
Apart from this I have two questions:
1) How can I get the textview ready for editing immediately after
placing it on the superview (without the user having to click inside it
first)? As I write, I'm thinking maybe by making it first responder
programmatically, but if the answer is something else, please tell me.
2) How can I make my NSView subclasses respond to mouseclicks
immediately (mouseDown etc.) across the applications windows, without
the user first having to click it once to make the window (or is it the
view) active?
Sorry about the length.... :-/ I hope you still are reading and want to
help me... :)
Per
Per Bull Holmen Guest
-
if problems, need help..
user20 and user1 both contains the number: 90 But the result of the trace action still return false..and the movie goes to frame 35.. Any good... -
delegate or subclass NSTextView?
I can't quite figure out if I should focus on using the delegate methods of a NSTextView or if I should work on subclassing it. What I'd like is to... -
problems with preLoadNetThing and fileName (was problems with preLoadNetThing and importFileInto)
You don't want to leave the QT member in your cast when you publish your movie - it's not really there, it's linked. When you run the movie it will... -
NSMutableAttributedString in an NSTextView
In <210720032130382351%sgketcham@comcast.net> Steve Ketcham wrote: Do you mean an NSTableView? Do you mean an NSTableView? It sounds to... -
NSScrollView for NSTextView scrolls then snaps back
I have a text view created in IB that I use to display the contents of the clipboard by doing a paste into the text view. When the text is... -
Per Bull Holmen #2
Re: NSTextView problems plus a few others...
Per Bull Holmen <pbh_news@yahoo.com> wrote:
OK, I figured out these two:> Apart from this I have two questions:
>
> 1) How can I get the textview ready for editing immediately after
> placing it on the superview (without the user having to click inside it
> first)? As I write, I'm thinking maybe by making it first responder
> programmatically, but if the answer is something else, please tell me.
>
> 2) How can I make my NSView subclasses respond to mouseclicks
> immediately (mouseDown etc.) across the applications windows, without
> the user first having to click it once to make the window (or is it the
> view) active?
1) Make the NSTextView first responder.
2) Override the views acceptsFirstMouse: to return YES.
But the main question remains, regarding resizing the NSTextView... is
it a bug in Cocoa that I have to find a workaround for, or is there
something I don't know about NSTextView/the text system?
Per
Per Bull Holmen Guest
-
matt neuburg #3
Re: NSTextView problems plus a few others...
Per Bull Holmen <pbh_news@yahoo.com> wrote:
A textview has a textcontainer; it is the textcontainer that determines> I am trying to make an NSTextView resize itself to fit the text as the
> user types. These are the steps I take:
>
> NSView *superView; // Not a scrollview;
> NSTextView *textView = [[NSTextView alloc] initWithFrame:textViewFrame];
>
> [textView setDrawsBackground:NO];
>
> [textView setVerticallyResizable:YES];
> [textView setHorizontallyResizable:YES];
>
> [superView addSubview:textView];
>
> 1) When the user has written past the textviews width, it doesn't resize
> but wraps. I have tried to find a way to prevent it from wrapping,
> NSParagraphStyle's NSLineBreakByClipping stops it from wrapping, but the
> view still doesn't resize.
>
> 2) The view DOES resize the height as expected. But as it resizes, it
> jumps down (and up) on its superview.
the width and the wrapping. If you don't want to wrap, make the
textcontainer very wide and turn off its widthTracksTextView. There is
an example of how to do this on your hard drive. m.
--
matt neuburg, phd = [email]matt@tidbits.com[/email], [url]http://www.tidbits.com/matt/[/url]
Read TidBITS! It's free and smart. [url]http://www.tidbits.com[/url]
matt neuburg Guest
-
Per Bull Holmen #4
Re: NSTextView problems plus a few others...
matt neuburg <matt@tidbits.com> wrote:
Thanks a lot.> A textview has a textcontainer; it is the textcontainer that determines
> the width and the wrapping. If you don't want to wrap, make the
> textcontainer very wide and turn off its widthTracksTextView. There is
> an example of how to do this on your hard drive. m.
In addition to this I had to set the textviews max size to the same size
as the container. I hoped it would solve the second problem too:
But it didn't... :(>> 2) The view DOES resize the height as expected. But as it resizes, it
>> jumps down (and up) on its superview.
I have now "solved" it with the following dirty hack (don't try this at
home):
[textView setPostsFrameChangedNotifications:YES];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector( fixResize: )
name:NSViewFrameDidChangeNotification
object:textView];
textViewUpperBounds = textViewFrame.origin.y +
textViewFrame.size.height;
textViewHeight = textViewFrame.size.height;
---
-(void)fixResize:(NSNotification *)note {
NSRect textViewFrame = [textView frame];
if( textViewFrame.size.height != textViewHeight ) {
textViewFrame.origin.y = textViewUpperBounds -
textViewFrame.size.height;
[textView setFrame:textViewFrame];
textViewHeight = textViewFrame.size.height;
}
else
textViewUpperBounds = textViewFrame.origin.y +
textViewFrame.size.height;
}
---
This is no good, cause if someone try to both resize and reposition it
in one operation, it will fail. If anybody has a better solution, or an
explanation to why the textview jumps up/down as it changes its height,
please tell me.
Per
Per Bull Holmen Guest
-
matt neuburg #5
Re: NSTextView problems plus a few others...
Per Bull Holmen <pbh_news@yahoo.com> wrote:
Is it really jumping up and down? Remember that the origin is at the> If anybody has a better solution, or an
> explanation to why the textview jumps up/down as it changes its height,
> please tell me.
lower left, not the top. So a change in height will necessarily move the
top. m.
--
matt neuburg, phd = [email]matt@tidbits.com[/email], [url]http://www.tidbits.com/matt/[/url]
Read TidBITS! It's free and smart. [url]http://www.tidbits.com[/url]
matt neuburg Guest
-
Per Bull Holmen #6
Re: NSTextView problems plus a few others...
matt neuburg <matt@tidbits.com> wrote:
Specifically, what happens is that when the textview increases its> Per Bull Holmen <pbh_news@yahoo.com> wrote:
>>> > If anybody has a better solution, or an
> > explanation to why the textview jumps up/down as it changes its height,
> > please tell me.
> Is it really jumping up and down? Remember that the origin is at the
> lower left, not the top. So a change in height will necessarily move the
> top. m.
height, it moves the entire text (and so the frame returned by NSView's
frame method) down on the superview. It looks pretty stupid. When the
text is deleted, so the height is decreased, it jumps up again.
So, when if the frame's size.width gets increased by, say, 15.0, its
origin.y gets decreased by maybe 30.0.
The superview is not flipped, and it is a very simple NSView subclass,
not a scrollview. But the superview itself is placed on a scrollview. It
barely has any customizations, except from drawRect:
Per
Per Bull Holmen Guest
-
Per Bull Holmen #7
Re: NSTextView problems plus a few others...
matt neuburg <matt@tidbits.com> wrote:
Specifically, what happens is that when the textview increases its> Per Bull Holmen <pbh_news@yahoo.com> wrote:
>>> > If anybody has a better solution, or an
> > explanation to why the textview jumps up/down as it changes its height,
> > please tell me.
> Is it really jumping up and down? Remember that the origin is at the
> lower left, not the top. So a change in height will necessarily move the
> top. m.
height, it moves the entire text (and so the frame returned by NSView's
frame method) down on the superview. It looks pretty stupid. When the
text is deleted, so the height is decreased, it jumps up again.
So, if the frame's size.width gets increased by, say, 15.0, its
origin.y gets decreased by maybe 30.0.
The superview is not flipped, and it is a very simple NSView subclass,
not a scrollview. But the superview itself is placed on a scrollview. It
barely has any customizations, except from drawRect:
Per
Per Bull Holmen Guest



Reply With Quote

