The Overlaying NSOutlineView

Hello Folks!

I thought I would do a quick post on how I achieved the “overlaying” NSOutlineView effect within Caffeinated.

Im not going to provide source, meerly the thought process behind it. So here it goes.

Its made up of 2 NSOutlineViews, one embedded within the others NSScrollView. The main NSOutlineView has a custom cell at the top of it which is the same height as the overlaying NSOutlineView. Due to the fact the overlaying NSOutlineView is wrapped within a NSScrollView, you must subclass its scrollview to forward the scrolling events on to its superview – superview, so 2 levels up the display list. Another problem will occur when the main NSScrollView redisplays the main NSOutlineView, this will cause the cells within the main NSOutlineView to draw over the top of the overlaying NSOutlineView. To get around this problem we observe the main NSScrollView for its scrolling notification and redraw the overlaying NSOutlineView when it has been posted.

Another thing you will notice is the shadow and the indent lines. This is meerly produced by subclassing the NSOutlineView class and overriding its drawRect methods and drawing the indent lines. How the shadow works is just by drawing an image below the overlaying NSOutlineView, with custom methods in the delegate, you can easily turn the shadow on and off.

Next part is overriding the keyboard events within the NSOutlineView, so that both of the views act as one when reaching the first and last item within them and selecting the appropriate view. Its actually pretty simple once you get your head around the concept. It does require you to type a fair bit of code, but its worth it ;)

Hope this helps anyone.

Leave a comment

You must be logged in to post a comment.