discuss-gnustep
[Top][All Lists]
Advanced

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

Re: Replacing views with setContentView


From: Andreas Höschler
Subject: Re: Replacing views with setContentView
Date: Tue, 13 Jun 2006 20:28:03 +0200

Hello Fred,

in our apps we have to replace views with setContentView:, e.g. in the
inspector depending on the context. Our code works perfectly on MacOSX
but failed under GNUstep. I spent 2 days on debugging this in the
GNUstep sources. I finally figured out that this has to do with
resizeWithOldSuperviewSize: and probably a no longer valid reference
size after the replacing the contentView. Finally the following
modification fixed the problem (last three lines):

GSWindowDecorationView:

- (void) setFrame: (NSRect)frameRect
{
  NSSize oldSize = _frame.size;
  NSView *cv = [_window contentView];

  frameRect = [isa windowFrameRectForFrameRect: frameRect
                     styleMask: [window styleMask]];

  _autoresizes_subviews = NO;
  [super setFrame: frameRect];

  contentRect = [isa contentRectForWindowFrameRect: frameRect
                     styleMask: [window styleMask]];

  // Safety Check.
// [cv setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
//  [cv resizeWithOldSuperviewSize: oldSize];
  [cv setFrame: contentRect];
}

I don't understand what the author intended to do with this safety
check, but it definitely makes our code fai. I checked 8 applications
after my modification and all behave well. I therefore recommend to
apply this patch.

I tried to understand this change, but failed to. I most cases I would
expect the current GNUstep code to be more or less equivalent to your
code. Where would there be any difference?
The safety check is only about resetting the resize attributes of the
content view, which should not be needed and doesn't make any
difference. And for normal views the resizeWithOldSuperviewSize: method
call should be equivalent to the setFrame: call. What I need to
understand is, why this makes a difference in your case, so what is the
resize behaviour of your content view? And what is the problem you
experience?

I am exchanging the contentView of the window as follows:

- (void)setClientView:(NSView *)view
{
   NSRect rect = [[mainWin contentView] frame];
   [view removeFromSuperviewWithoutNeedingDisplay];
   [view setFrame:rect];
   [mainWin setContentView:view];
   [view setAutoresizesSubviews:NO];    
   [view setAutoresizingMask:0];        
}

The view I am passing to this method is a direct subclass of NSView. This view should not do standard autoresizing of its subviews. I implemented my own mechanism to do so in setFrame:. Now with my GNUstep fix everything works fine. Without the fix resizing of the view (not even initial sizing) does not work. The view gets a wrong width and height!

Regards,

  Andreas






reply via email to

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