discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSBox bug?


From: Marko Riedel
Subject: NSBox bug?
Date: Wed, 26 Feb 2003 22:20:11 +0100 (CET)

Hi folks,

there seems to be a bug in NSBox's "sizeToFit": as far as I can see,
there are three cases:

(1) if the contentView responds to sizeToFit, then pass it on (this is
okay)

(2) if the contentView has at least one subview, then union the frames
of the subviews (this too is okay)

or

(3) otherwise zap the frame of the contentView.


The bug is caused by (3), namely if the contentView is a perfectly
well-behaved view with no subviews its frame is zapped! In this case
NSBox should leave the frame as is.


Here is the code:

- (void) sizeToFit
{
  NSRect f;

  if ([_content_view respondsToSelector: @selector(sizeToFit)])
    {
      [_content_view sizeToFit];
    }
  else // _content_view !respondsToSelector: sizeToFit
    {   
      NSArray *subviewArray = [_content_view subviews];
      if ([subviewArray count])
        {
          id o, e = [subviewArray objectEnumerator];
          NSRect r = [[e nextObject] frame];
          // Loop through subviews and calculate rect to encompass all
          while ((o = [e nextObject]))
            {
              r = NSUnionRect(r, [o frame]);
            }
          [_content_view setBoundsOrigin: r.origin];
          r.size = [self convertSize: r.size fromView: _content_view];
          [_content_view setAutoresizesSubviews: NO];
          [_content_view setFrameSize: r.size];
          [_content_view setAutoresizesSubviews: YES];
        }
      else // _content_view has no subviews
        {
          [_content_view setFrame: NSZeroRect];
        }
    }

  f = [_content_view frame];

  // The box width should be enough to display the title
  if (_title_position != NSNoTitle)
    {
      NSSize titleSize = [_cell cellSize];
      titleSize.width += 6;
      if (f.size.width < titleSize.width)
        f.size.width = titleSize.width;
    }
  
  if (_super_view != nil)
    [self setFrameFromContentFrame: [self convertRect: f toView: _super_view]];
  else // _super_view == nil
    [self setFrameFromContentFrame: f]; 
}



Best regards,

-- 
+------------------------------------------------------------+
| Marko Riedel, EDV Neue Arbeit gGmbH, mriedel@neuearbeit.de |
| http://www.geocities.com/markoriedelde/index.html          |
+------------------------------------------------------------+






reply via email to

[Prev in Thread] Current Thread [Next in Thread]