Re: duplicating NSTextView
Re: duplicating NSTextView
- Subject: Re: duplicating NSTextView
- From: Fred Klein <email@hidden>
- Date: Sat, 26 Jul 2003 09:05:07 +0200
On Friday, Jul 25, 2003, at 18:30 Europe/Zurich, Douglas Davidson wrote:
I am new to Cocoa. I am trying to duplicate programaticaly an
NSTextView in
my Window.
It looks like your code will indeed create a new text view, similar in
size (though perhaps not in other regards) to the original. But
presumably you wanted to duplicate the contents of the original text
view? For that, you need to deal with the text storage. The exact
procedure depends on whether you want the two text views to share a
single backing store--so that changes to one will affect the other--or
whether you want them to have distinct copies of the text.
I really want to have two distinct TextViews. I would like to apply the
prototype pattern so that I can duplicate a set of initial IB controls
(a TextView and a Slider) a bit like Mail does when adding criteria to
a rule.
As I said I am new to Cocoa. I came further as I understood that I need
to actually duplicate the NSScrollView containing the NSTextView. So
far so good.
Here's my code. Did I understand it right or am poorly trying to hack
something that could be done more easily or more cocoa-compliant?
- (NSTextView*)cloneTextView:(NSTextView*)prototype
{
// variable declarations
textFrameRect = [prototype frame];
newTextView = [[NSTextView alloc] initWithFrame:textFrameRect];
[newTextView setEditable:[prototype isEditable]];
// more get/set on properties...
[newTextView setRulerVisible:[prototype isRulerVisible]];
return newTextView;
}
- (NSScrollView*)cloneScrollableTextView:(NSTextView*)prototype
vOffset:(int)vOffset
{
// variable declarations
prototypeScroll = [[prototype superview] superview];
scrollFrameRect = [prototypeScroll frame];
scrollFrameRect = NSOffsetRect(scrollFrameRect, 0.0f, vOffset);
newScrollView = [[NSScrollView alloc] init];
[newScrollView setFrame:scrollFrameRect];
[newScrollView setHasVerticalScroller:[prototypeScroll
hasVerticalScroller]];
// more get/set on properties...
[newScrollView setBorderType:[prototypeScroll borderType]];
newTextView = [self cloneTextView:prototype];
[newScrollView setDocumentView: newTextView];
return newScrollView;
}
Another question if I may.
Why doesn't the scroller of a IB TextView activate (i.e. show the
thumb) as I enter text that taks more lines than can be displayed?
I am looking for a book to support me in my discovery of Cocoa. Would I
find the answers of such questions in the "Learning Cocoa with
Objective C"?
Thank you for you support.
best regards
fred
_______________________________________________
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.