How to make multiple columns of an NSOutlineView index?

What would be the easiest or recommended way to make NSOutlineView indent multiple columns? By default, these are only indents in the contour column; and as far as I know, there is no built-in support for indenting other columns.

I have an NSOutlineView that shows a comparison between two sets of hierarchical data. For visual appeal, if any element in the contour column is indented, I would like to deflect the element in the same row in another column with the same sum. (There is also a third column that shows the result of comparing two elements, this column should never be indented.)

Can this be achieved by subclassing NSOutlineView? And what would need to be overridden in a subclass? Or is there an easier way to indent multiple columns?

+3
source share
1 answer

It turns out easier than I expected. Here is a draft of the solution. To indent a column other than a structure column in NSOutlineView, you can:

  • Create a subclass of the NSCell class that you will use for this column, say MYIndentedCell
  • Add indentationan instance variable to MYIndentedCell and provide an access and mutator method for it
  • Override at least drawWithFrame: inView: in MYIndentedCell to:
     - (void) drawWithFrame: (NSRect) frame inView: (NSView *) view
     {
       NSRect newFrame = frame;
       newFrame.origin.x += indentation;
       newFrame.size.width -= indentation;
       [super drawWithFrame: newFrame inView: view];
     }
  • editWithFrame:inView selectWithFrame:inView: , .
  • cellSize, :
     - (NSSize) cellSize
     {
       NSSize cellSize = [super cellSize];
       cellSize.width += indentation;
       return cellSize;
     }
  • , , NSOutlineView, . :
     - (void) outlineView: (NSOutlineView *) view
              willDisplayCell: (id) cell
              forTableColumn: (NSTableColumn *) column
              item: (id) item
     {
       if (column == theColumnToBeIndented) {
         [cell setIndentation:
                  [view indentationPerLevel] * [view levelForItem: item]];
       }
     }

, , , ImageAndTextCell.m Apple SourceView, , .

+2

Source: https://habr.com/ru/post/1736376/


All Articles