On 15 Jul '08, at 8:08 PM, TARUN CHAPLOT wrote:

I am very new to objective C and working on some application which needs to create Chat bubbles similar to iChat. Can anybody help me to find some documentation or the sample code which will help me to make chat bubbles using custom cell.

A custom cell isn't a good way to go about this! If you do that, you have to do text layout inside every cell to compute its height, which is quite expensive, and has to be recalculated any time the view changes width. It also makes it impossible to select text in more than one cell.

iChat used an NSTextView subclass for the chat display, which overrode -drawViewBackgroundInRect (?) to draw the bubbles before the regular text-view code drew the text on top. To find the bounds of the bubbles it searched the backing store for text ranges marked with a custom attribute that indicated they were chat messages, then asked the layout manager for the bounding box of each glyph range. That's the gist of it; the details got very nasty, especially making it perform well as the number of messages increased.

In Leopard I believe they switched to using a WebView with a special CSS stylesheet. Safari supports some CSS 3 selectors that make this a lot easier than it's been in the past; in particular, there's a selector to specify a single background image for a block that slices the image into 9 pieces that get applied to the center, edges and corners.

It's probably pretty clear that this is not a newbie project. : ( Ironically, I did start working on the first iChat prototype the day I left the Cocoa training class, but my first implementation used an NSMatrix with a cell for each balloon, which is how I learned that this approach doesn't work very well. It's fairly simple, though. You just make an NSMatrix of NSTextFieldCells and add a row for every message. You can subclass NSTextFieldCell and override one of the drawing methods to draw the balloon background (at the time I just made an NSBezierPath and filled and outlined it with a solid color.)

—Jens

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list ([email protected])

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/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to