Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: paragraph styles in NSTextView--help



I want to use different combinations of paragraph styles in nstextview .

for example : combination of linespacing, paragraphspacing, headindent and
tailindent . These all styles must be activated in a single operation ,such
as in a single buttonclick etc.

You'll want to work with the text storage of the text view and apply the paragraph styles to the text as necessary. Before you modify any attributes of the storage you'll want to call "shouldChangeTextInRange:replacementString:" and afterwards "didChangeText" if you want undo and editing restrictions handled for you. A single change would look something like this:


NSTextView* tv = GetMyTextView();
NSTextStorage* ts = [tv textStorage];
NSRange applyRange = NSMakeRange(0, [ts length]);

if( [tv shouldChangeTextInRange:applyRange replacementString:nil] ) {
// configure paragraph styles as desired and apply
NSMutableParagraphStyle* paraStyle = [[[NSParagraphStyle defaultParagraphStyle] mutableCopy] autorelease];
[paraStyle setHeadIndent:6];
[ts addAttribute:NSParagraphStyleAttributeName value:paraStyle range:applyRange];
[tv didChangeText];
}


You can apply as many distinct styles to different paragraphs as you see fit by changing the NSRange.

~Martin
_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >paragraph styles in NSTextView--help (From: rethish <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.