Setting Tab Stops (again)

  • I am trying to set a different collection of tab stops in an NSTextView
    besides the default set, which are 28 points apart. I am setting up a fixed
    point font, and I want a tab stop every 4 columns (5, 9, 13, etc). My window
    is fairly wide, so I am setting up 64 tabs stops. My code looks like:

    NSMutableParagraphStyle *paragraphStyle;
    float    fCharacterWidth, fTabPosition;
    long    lIndex;
    NSMutableArray  *tabArray = [NSMutableArray
    arrayWithCapacity:64];
    NSFont    *textFont = [NSFont
    userFixedPitchFontOfSize:14.0];

    [myTextView setFont:textFont];
    fCharacterWidth = [textFont widthOfString:@"X"];
    fTabPosition = 5.0 * fCharacterWidth;
    [tabArray addObject:[[NSTextTab alloc]
    initWithType:NSLeftTabStopType location:fTabPosition]];
    for(lIndex=1; lIndex<64; ++lIndex)
    {
      fTabPosition += 4.0 * fCharacterWidth;
      [tabArray addObject:[[NSTextTab alloc]
    initWithType:NSLeftTabStopType location:fTabPosition]];
    }
    paragraphStyle = [[NSParagraphStyle defaultParagraphStyle]
    mutableCopy];
    [paragraphStyle setTabStops:tabArray];
    myTextStorage = [myTextView textStorage];
    [myTextStorage
      setAttributes:[NSDictionary
    dictionaryWithObject:paragraphStyle forKey:NSParagraphStyleAttributeName]
      range:NSMakeRange(0,[myTextStorage length])];

    I am assuming this fails because to start with, this NSTextView has no
    contents, so it is setting the attributes of nothing.

    How do I set the default attributes of my NSTextView so that my tab stop
    array sticks, even if the contents of the view are deleted and replaced with
    some other text contents.

    Thanks.

    Michael Christian
    Thomson multimedia Inc.
previous month july 2001 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today