« On Mentor Systems | Main | Dear music industry execs: »

Turning the NSTables

NSTableView and its related classes are probably a few of the most abused in the Cocoa API. We make it put icons and text together, feed it strange new NSCells, change its look, subclass it beyond recognition, and call it funny names.

So here's another NSTableView subclass to add to the pile.

In using the table view like the Finder's file view, I wanted to change how it handled mouse and drag events. I ended up completely overriding at the NSDocument level, so this subclass does two things:

First, it adds the boolean isDragDestination. Changing this boolean forces a redraw of the entire table, to remove or put on the hilight color frame. While isDragDestination is YES, setNeedsDisplayInRect: to the table cause the entire table to redraw, in case of scrolling.

Second, almost all of the NSEvents, selectAll, and deselectAll are overridden to let the delegate decide whether or not the table view should handle the event. For example, returning NO in - [tableView:mouseDown:] will cause the table to ignore mouseDown events and allows the delegate to deal with it instead. They're done as a macro in the .m file, so it should be really easy to add new overrides.

They're free to use however you please. If you like them, let me know, but you're under no obligation. Enjoy.
BTHTweakedTableView.h
BTHTweakedTableView.m

TrackBack

TrackBack URL for this entry:
http://unlogica.com/cgi-bin/mt/mt-tb.cgi/22

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

This page contains a single entry from the blog posted on October 4, 2007 12:22 AM.

The previous post in this blog was On Mentor Systems.

The next post in this blog is Dear music industry execs:.

Many more can be found on the main index page or by looking through the archives.

Creative Commons License
This weblog is licensed under a Creative Commons License.
Powered by
Movable Type 3.35