Re: customizing NSTextView
Re: customizing NSTextView
- Subject: Re: customizing NSTextView
- From: Douglas Davidson <email@hidden>
- Date: Tue, 26 Nov 2002 09:28:54 -0800
On Tuesday, November 26, 2002, at 06:36 AM, Koen van der Drift wrote:
I want to customize the way an NSTextView renders text. Eg, I would
like to
add line and character numbers. What would be the best approach to do
such
thing? Should I go ahead and just subclass the NSTextView for this? Or
would
it be more appropriate to subclass the NSLayoutManager from the
NSTextView?
This depends somewhat on exactly what sort of customization you want.
For decorations that appear in addition to and outside of the normal
flow of text, it would be reasonable to subclass the NSTextView to do
the additional drawing, or else to place the NSTextView within a
superview that does the additional drawing, depending on where the
decorations are to appear. For example, TextEdit in multiple-page mode
places the text views (one for each page) within a superview that adds
a background and some additional lines to delineate the page. This
sort of approach might be reasonable for line numbering, page
numbering, and so forth. Alternatively, if you wished the line numbers
to appear within the boundaries of the text view, you could use an
NSTextView subclass to draw them. That might be seen as cleaner, too,
since the placement of the line numbers depends on knowledge of the
text layout, which is the sort of information the text view already
obtains from its layout manager.
If you wish to customize the actual drawing of the text itself, it is
often useful to subclass NSLayoutManager, since the actual drawing of
glyphs is done by the layout manager. This is especially the case
where your customization depends on attributes of the characters or the
glyphs. This is because the text view when it draws typically just
sends a single long range of glyphs to be drawn to the layout manager,
which then proceeds to break that up into ranges that can be drawn with
a single set of attributes.
Douglas Davidson
_______________________________________________
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.