• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTextView resizeability and scrolling
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTextView resizeability and scrolling


  • Subject: Re: NSTextView resizeability and scrolling
  • From: Ross Carter <email@hidden>
  • Date: Fri, 11 Sep 2009 13:36:52 -0400


On Sep 10, 2009, at 12:10 AM, Stamenkovic Florijan wrote:

Hi Ross,

Thanks for your reply,

On Sep 09, 2009, at 13:15, Ross Carter wrote:

I've googled for a solution, found nothing. I tried making it by observing the NSViewFrameChangedNotification of the NSTextView from it's parent, and resizing, but this is more tricky then I imagined.

I think you are on the right track. You might want to look at these threads:
http://www.cocoabuilder.com/archive/message/cocoa/2009/4/24/235290
http://www.cocoabuilder.com/archive/message/cocoa/2009/3/16/232453

I took a look. The code you posted in the second thread (having a switch to stop recursive resizing) makes sense. I was thinking along similar lines.


At the bottom I pasted my current code on this. There is a problem though, but one which seems to be connected to having an NSTextView not directly embedded in a scroll view, not so much with my code... In short, NSTextView does not react to the parent view resizing in the standard way (which is easily tested in IB). Perhaps it assumes it is directly embedded in a scroll view. This makes it hard to reconcile with what I am trying to do, even if my added code works OK.

Any thoughts?

As as side question, it seems that an NSTextView has some margins that separate the text from it's outer edges. This makes sense when the NSTextView is in an NSScrollView, but makes it difficult to align the text view when it is not. I can't find any documented API on controlling this. Is it possible?

I think you want to look at setLineFragmentPadding: in NSTextContainer.

That sounds like the right thing, thanks... F



@interface FSEmbeddedTextView2 : NSView {

	IBOutlet NSTextView* textView;
	NSRect textViewFrame;
	BOOL isChangingFrameSize;
}

@end


@implementation FSEmbeddedTextView2

-(void)awakeFromNib
{
	NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
	textViewFrame = [textView frame];
	[nc addObserver:self
		   selector:@selector(embeddedTextViewFrameDidChange:)
			   name:NSViewFrameDidChangeNotification
			 object:textView];
}

-(void)embeddedTextViewFrameDidChange:(NSNotification*)n
{
// if the resize of the text view is happening during a resize of this view
// then it is autosizing at work, and we can ignore it
if(isChangingFrameSize){
textViewFrame = [textView frame];
return;
}


// figure out the size change in the text view
NSRect newTextFrame = [textView frame];
float increaseX = newTextFrame.size.width - textViewFrame.size.width;
float increaseY = newTextFrame.size.height - textViewFrame.size.height;

// reset the text view to where we started
[textView setFrame:textViewFrame];

// resize this view, which will autosize the text view to the new size
// which can accommodate all the text
NSRect newSelfFrame = [self frame];
newSelfFrame.size.width += increaseX;
newSelfFrame.size.height += increaseY;

[self setFrameSize:newSelfFrame.size];
}


-(void)setFrame:(NSRect)newFrame
{
	isChangingFrameSize = YES;
	[super setFrame:newFrame];
	isChangingFrameSize = NO;
}

-(void)setFrameSize:(NSSize)newSize
{
	isChangingFrameSize = YES;
	[super setFrameSize:newSize];
	isChangingFrameSize = NO;
}

-(void)dealloc
{
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
[nc removeObserver:self name:NSViewFrameDidChangeNotification object:textView];
[super dealloc];
}


@end



It looks like you instantiate the NSTextView in the nib. I would start by setting up the NSTextView manually and adding it as a subview to your FSEmbeddedTextView2 instance. Make sure that the textView has its resizing behavior set up correctly (vertical, horizontal, both, depending on your needs). Next, I would make sure that you are getting the frame changed notification and that it is firing embeddedTextViewFrameDidChange:.

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSTextView resizeability and scrolling
      • From: Stamenkovic Florijan <email@hidden>
References: 
 >NSTextView resizeability and scrolling (From: Stamenkovic Florijan <email@hidden>)
 >Re: NSTextView resizeability and scrolling (From: Ross Carter <email@hidden>)
 >Re: NSTextView resizeability and scrolling (From: Stamenkovic Florijan <email@hidden>)

  • Prev by Date: Re: NSSegmentedControl with square edges
  • Next by Date: re: Core Data Manual Migration
  • Previous by thread: Re: NSTextView resizeability and scrolling
  • Next by thread: Re: NSTextView resizeability and scrolling
  • Index(es):
    • Date
    • Thread