NSBrowser header view

  • Hi all,

    on GNUstep and MacOSX 10.2 I am used to set header views in browsers
    as follows.

        _modulePopUp = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(0,
    0, 100, 12)];
        [_modulePopUp setBordered:NO];
        [_modulePopUp setFont:[NSFont systemFontOfSize:10.0]];
        [browser setHeaderView:_modulePopUp forColumn:1];

    This works great on these systems. However, on MacOSX 10.5 the popup
    appears at the bottom of the browser?? Is this  a bug or am I missing
    anything?

    Thanks,

      Andreas
  • Huh? NSBrowser does not have headerviews on MacOSX <http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Cla
    sses/NSBrowser_Class/Reference/Reference.html
    >.

    Christiaan

    On 29 Oct 2008, at 8:28 PM, Andreas Höschler wrote:

    > Hi all,
    >
    > on GNUstep and MacOSX 10.2 I am used to set header views in browsers
    > as follows.
    >
    > _modulePopUp = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(0,
    > 0, 100, 12)];
    > [_modulePopUp setBordered:NO];
    > [_modulePopUp setFont:[NSFont systemFontOfSize:10.0]];
    > [browser setHeaderView:_modulePopUp forColumn:1];
    >
    > This works great on these systems. However, on MacOSX 10.5 the popup
    > appears at the bottom of the browser?? Is this  a bug or am I
    > missing anything?
    >
    > Thanks,
    >
    > Andreas
  • Hi Christiaan,

    > >.

    Ugh! Of course not. I was not aware that I had added this method to an
    NSBrowser subclass. If anybody cares, here's the code that works on
    MacOSX 10.5 as well now. :-)

    - (void)setHeaderView:(NSView *)view forColumn:(int)column
    {
        if (view) [_headerViewDic setObject:view forKey:[NSNumber
    numberWithInt:column]];
        else [_headerViewDic removeObjectForKey:[NSNumber
    numberWithInt:column]];
    }

    - (void)drawTitleOfColumn:(int)column inRect:(NSRect)aRect
    {
        NSView *headerView = [_headerViewDic objectForKey:[NSNumber
    numberWithInt:column]];
        if (headerView)
          {
          NSView *currentView = nil;
          NSLog(@"drawTitleOfColumn %d inRect %@ headerView %@", column,
    NSStringFromRect(aRect), headerView);
          if ([headerView superview] != self)
            {
              [self addSubview:headerView];
              if (!_subviewViewDic) _subviewViewDic =
    [[NSMutableDictionary alloc] init];
              [_subviewViewDic setObject:headerView forKey:[NSNumber
    numberWithInt:(int)aRect.origin.x]];
            }
          else
            {
              currentView = [_subviewViewDic objectForKey:[NSNumber
    numberWithInt:(int)aRect.origin.x]];
              if (currentView != nil && headerView != currentView)
                {
                [currentView setFrameOrigin:NSMakePoint(0, -100)]; //
    move it out of the way
                }
            }

          // MacOSX 10.5 is so buggy
          #ifdef __APPLE_CC__ > 54321
          NSRect frame = [self frame];
          aRect.origin.y =  aRect.origin.y +  frame.size.height -
    aRect.size.height;
          #endif
          [headerView setFrame:aRect];
          [headerView setNeedsDisplay:YES];
          }
        else [super drawTitleOfColumn: column inRect:aRect];
    }

    Regards,

      Andreas

    >> on GNUstep and MacOSX 10.2 I am used to set header views in
    >> browsers as follows.
    >>
    >> _modulePopUp = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(0,
    >> 0, 100, 12)];
    >> [_modulePopUp setBordered:NO];
    >> [_modulePopUp setFont:[NSFont systemFontOfSize:10.0]];
    >> [browser setHeaderView:_modulePopUp forColumn:1];
    >>
    >> This works great on these systems. However, on MacOSX 10.5 the
    >> popup appears at the bottom of the browser?? Is this a bug or am I
    >> missing anything?
  • On Wed, Oct 29, 2008 at 1:13 PM, Andreas Höschler <ahoesch...> wrote:

    > // MacOSX 10.5 is so buggy
    > #ifdef __APPLE_CC__ > 54321
    > NSRect frame = [self frame];
    > aRect.origin.y =  aRect.origin.y +  frame.size.height -
    > aRect.size.height;
    > #endif

    It is possible to use an earlier tool chain to bulid something that
    could end up running on Mac OS X 10.5 and then your "fix" would be
    included in the code like it should.

    This code should likely always exist for code compiled for Mac OS X
    and at runtime it should check appkit version, os version or test some
    API availability to decide if the "fix" is needed. Also would it hurt
    to alway do it?

    -Shawn
  • On 29 Oct 2008, at 9:13 PM, Andreas Höschler wrote:

    >
    > // MacOSX 10.5 is so buggy
    > #ifdef __APPLE_CC__ > 54321
    > NSRect frame = [self frame];
    > aRect.origin.y =  aRect.origin.y +  frame.size.height -
    > aRect.size.height;
    > #endif
    >

    I haven't checked this, but I strongly doubt 10.5 is buggy here (if
    anything's buggy here I'd expect perhaps 10.2). Rather, I expect that -
    [NSBrowser isFlipped] is different between various MacOSX versions
    (which is not a bug, but a facto of life, in fact than the bug is
    yours because you disregard this very important property).

    Christiaan
  • On Wed, Oct 29, 2008 at 2:42 PM, Christiaan Hofman <cmhofman...> wrote:

    > I haven't checked this, but I strongly doubt 10.5 is buggy here (if
    > anything's buggy here I'd expect perhaps 10.2). Rather, I expect that
    > -[NSBrowser isFlipped] is different between various MacOSX versions (which
    > is not a bug, but a facto of life, in fact than the bug is yours because you
    > disregard this very important property).

    Good point... I didn't stop to think about what the "fix" trying to
    correct. It likely is a assumption about the view being flipped or not
    that his code needs to consider for it to be correct.

    This is an often overlooked possibility that can bite you, especially
    for code that you don't own/control.

    -Shawn