• 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: IRC-like NSTextView.... ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: IRC-like NSTextView.... ?


  • Subject: Re: IRC-like NSTextView.... ?
  • From: "Kenneth C. Dyke" <email@hidden>
  • Date: Sun, 9 Sep 2001 11:07:02 -0700

On Sunday, September 9, 2001, at 05:47 AM, Luc Heinrich wrote:

On dimanche, septembre 9, 2001, at 12:08 , Andreas Monitzer wrote:

What about using a fixed font (Monaco, Courier etc) and inserting spaces for alignment?

This could be a good (and very simple) workaround, yes, but it implies that users would not be able to customize display fonts (which is usually considered as a pretty important feature in an IRC client).

By the way, I only checked the documentation of my 5G27 build, if tab-stops support is more complete in later builds (5G48 which I did not install, or later) I would be happy to hear about it.

Heh, once upon a time when I was writing an IRC client I wanted to solve the same problem. Eventually I came up with the following solution in my message class. Hopefully just the method implementation will be enough to get you going. 'nickLocation' was the x coordinate
of the rightmost pixel of the nickname part of the text view, and trenchlocation was the x location of the message text.

One neat aspect of doing it this way is that cut/paste into other documents works really nice as well. My app would calculation the nick and trench location based on the worst-case width of the nickname field (like how long would the nickname MMMMMMMMMMM be, etc).

- (void)formatMessageForNickLocation:(float)nickLocation
andTrenchLocation:(float)trenchLocation
{
NSMutableParagraphStyle *style;
NSTextTab *tab1, *tab2;
float nickLength;
NSFont *messageFont;

// Free old string (if it exists)
[messageString release];

// Calculate layout information
messageFont = [messageAttributes messageFont];
nickLength = [messageFont widthOfString:messageNick];

tab1 = [[NSTextTab alloc] initWithType:NSLeftTabStopType
location:nickLocation - nickLength];
tab2 = [[NSTextTab alloc] initWithType:NSLeftTabStopType
location:trenchLocation];

// Set up paragraph attributes.
style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[style setTabStops:[NSArray arrayWithObjects:tab1, tab2, nil]];
[style setHeadIndent:trenchLocation];

// Build attributed string.
messageString = [[NSMutableAttributedString alloc] initWithString:
[NSString stringWithFormat:@"\t%@\t%@\n",messageNick,messageText]
attributes:
[messageAttributes messageAttributes]];
[messageString addAttribute:NSParagraphStyleAttributeName
value:style
range:NSMakeRange(0,[messageString length])];
[messageString addAttribute:NSFontAttributeName
value:messageFont
range:NSMakeRange(0,[messageString length])];

// We don't need to hang on to these...
[tab1 release];
[tab2 release];
[style release];
}

Kenneth Dyke, email@hidden (personal), email@hidden (work)
Sr. Mad Scientist, MacOS X OpenGL Group, Apple Computer, Inc.
C++: The power, elegance and simplicity of a hand grenade.


  • Follow-Ups:
    • Re: IRC-like NSTextView.... ?
      • From: Luc Heinrich <email@hidden>
    • Re: IRC-like NSTextView.... ?
      • From: Luc Heinrich <email@hidden>
References: 
 >Re: IRC-like NSTextView.... ? (From: Luc Heinrich <email@hidden>)

  • Prev by Date: Re: Would Any Developers Use This?
  • Next by Date: Re: Would Any Developers Use This?
  • Previous by thread: Re: IRC-like NSTextView.... ?
  • Next by thread: Re: IRC-like NSTextView.... ?
  • Index(es):
    • Date
    • Thread