Using heightOfRowByItem is NSOutlineView

  • With thanks due to I.Savant and Scott Ribe, I've got some results in
    dynamically modifying line heights in an NSOutline.

    I implemented a delegate for the NSOutlineView, with this:

    - (float)outlineView:(NSOutlineView *)outlineView heightOfRowByItem:
    (id)item {

    NSArray * cols = [outlineView tableColumns];
    NSEnumerator * en  = [cols objectEnumerator];
    id col;
    id dcell;
    NSSize cellsize;
    NSRect bounds;
    float highest = 0.0;
    while(col = [en nextObject]){
      dcell = [col dataCellForRow:[outlineView rowForItem:item]];
      cellsize = [dcell cellSize];  // will use this later
      cellsize.height = 100000000.0;
      cellsize.width = 300.00;
      bounds.origin = NSZeroPoint;
      bounds.size  = cellsize;
      [dcell setWraps: YES];
      cellsize = [dcell cellSizeForBounds:bounds];
      if (cellsize.height > highest) {
      highest = cellsize.height;
      }
      NSLog(@"heights: %f %f datacell: %@", bounds.size.height,
    cellsize.height, [dcell objectValue]);
    }

    return highest;
    }

    All fine, as far as it goes. But there are drawing errors, and my
    conclusion is that I need to invoke this more frequently.

    My question: when is - (float)outlineView:(NSOutlineView *)
    outlineView heightOfRowByItem:(id)item  invoked, and should I be
    setting up other delegate methods to call it more frequently? Should
    I set up notifications to trap events that occur when editing,
    collapsing or resizing? In short, how much does Cocoa handle, and how
    much am I responsible for? Anyone have any documentation on this?

    Dan Donaldson
  • Dan,

    I'm hardly the expert, but I don't think it will help to call this
    method on your own; Cocoa has to call it when it needs the result.

    In my implementation, after copious use of NSLog, I determined that
    the value of the cell in question was not always current for the
    specified row when the method was called.  My implementation now finds
    the proper value and invokes setObjectValue: on the cell before doing
    the calculation.  This cleaned up most of the display glitches.

    I don't know if it's the right way, but it's more correct than it was...

    Hope this helps.

    Doug K;

    On 10/17/06, Dan Donaldson <omnivore1...> wrote:
    > With thanks due to I.Savant and Scott Ribe, I've got some results in
    > dynamically modifying line heights in an NSOutline.
    >
    > I implemented a delegate for the NSOutlineView, with this:
    >
    > - (float)outlineView:(NSOutlineView *)outlineView heightOfRowByItem:
    > (id)item {
    >
    > NSArray * cols = [outlineView tableColumns];
    > NSEnumerator * en  = [cols objectEnumerator];
    > id col;
    > id dcell;
    > NSSize cellsize;
    > NSRect bounds;
    > float highest = 0.0;
    > while(col = [en nextObject]){
    > dcell = [col dataCellForRow:[outlineView rowForItem:item]];
    > cellsize = [dcell cellSize];                    // will use this later
    > cellsize.height = 100000000.0;
    > cellsize.width = 300.00;
    > bounds.origin = NSZeroPoint;
    > bounds.size  = cellsize;
    > [dcell setWraps: YES];
    > cellsize = [dcell cellSizeForBounds:bounds];
    > if (cellsize.height > highest) {
    > highest = cellsize.height;
    > }
    > NSLog(@"heights: %f %f datacell: %@", bounds.size.height,
    > cellsize.height, [dcell objectValue]);
    > }
    >
    > return highest;
    > }
    >
    >
    > All fine, as far as it goes. But there are drawing errors, and my
    > conclusion is that I need to invoke this more frequently.
    >
    > My question: when is - (float)outlineView:(NSOutlineView *)
    > outlineView heightOfRowByItem:(id)item  invoked, and should I be
    > setting up other delegate methods to call it more frequently? Should
    > I set up notifications to trap events that occur when editing,
    > collapsing or resizing? In short, how much does Cocoa handle, and how
    > much am I responsible for? Anyone have any documentation on this?
    >
    > Dan Donaldson
    >
    >
    > _______________________________________________
    > Do not post admin requests to the list. They will be ignored.
    > Cocoa-dev mailing list      (<Cocoa-dev...>)
    > Help/Unsubscribe/Update your Subscription:
    > http://lists.apple.com/mailman/options/cocoa-dev/<knowles.doug...>
    >
    > This email sent to <knowles.doug...>
    >
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today