2
votes

I have implemented a view-based NSOutlineView in my project. I am using floating group rows. Now, I would like to have this NSOutlineView look basically like the Finder list-view (CMD-2) when it is in the "arranged-by" layout (e.g. "by kind": CTRL-CMD-2). That means, the top-most group row should display the column titles and as soon as the next lower group row is starting to nudge the previous one out of the view, the column titles fade in on the second group row (I hope this makes sense).

Is there any out-of-the-box way to achieve this? So far I have successfully subclassed NSTableCellView to show the columns' titles, however, I cannot get the fade-in to work as I cannot seem to find out the position of the group row in relation to the floating one above it.

Regards, Michael

1
I don't see any fading at all in Finder list view. I see a standard NSOutlineView with column headers. Can you post some screenshots of what you mean?Rob Keniger
Rob, thanks for your answer. I edited my original question: I am talking about the "arranged-by" layout which you can invoke by e.g. hitting CTRL-CMD-1 through CTRL-CMD-7. This is AFAIK only available on Lion.Michael Becker

1 Answers

0
votes

I've found a possible way to achieve what I want. In my custom NSTableCellView's drawRect: method, it's of course possibly in a nasty way to find out the view's position relative to the enclosing NSClipView. The relevant code:

- (void)drawRect:(NSRect)dirtyRect {
  // _isGroupView is a member variable which has to be set previously
  // (usually in setObjectValue:) in order for us to know if we're a 
  // group row or not.
  if (_isGroupView) {

    // This is the nasty party:
    NSClipView *clipView = (NSClipView*)self.superview.superview.superview;
    if (![clipView isKindOfClass:[NSClipView class]]) {
      NSLog(@"Error: something is wrong with the scrollbar view hierarchy.");
      return;
    }

    NSRect clipRect = [clipView documentVisibleRect];
    CGFloat distanceToTop = self.superview.frame.origin.y - clipRect.origin.y;
    if (self.superview.frame.origin.y - clipRect.origin.y < self.frame.size.height) {
      // This means, that this NSTableCellView is currently pushing the
      // view above it out of the frame.

      CGFloat alpha = distanceToTop / self.frame.size.height;
      NSColor *blendColor = [[NSColor blackColor] blendedColorWithFraction:alpha    ofColor:[NSColor whiteColor]];

      // ...
      // do stuff with blendColor
      // ...
      // blendColor should now be the appropriate color for the wanted 
      // "fade in" effect.
      // 
    }
  }
}

I hope this makes sense ;-). Any tips are still appreciated!

Cheers, Michael