mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 20:50:48 +00:00
Auto-resize fixes
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3424 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
436496e3d3
commit
3f83e799bc
4 changed files with 836 additions and 750 deletions
|
@ -1,3 +1,9 @@
|
|||
Wed Dec 9 7:00:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
* NSView.m: Complete rewrite of auto-resize code - now works!
|
||||
* NSBox.m: Fix to make auto-resize work.
|
||||
* GNUAlertPanel.m: Minor tidying for auto-resize.
|
||||
|
||||
Tue Dec 8 1998 Felipe A. Rodriguez <far@ix.netcom.com>
|
||||
|
||||
* NSScroller.m move backend code into frontend, polish code, remove ifdefs.
|
||||
|
|
|
@ -135,6 +135,8 @@ static GNUAlertPanel *reusableAlertPanel = nil;
|
|||
NSRect rect;
|
||||
NSBox *box;
|
||||
|
||||
[self setMaxSize: r.size];
|
||||
[self setMinSize: r.size];
|
||||
[self setTitle: @" "];
|
||||
|
||||
content = [self contentView];
|
||||
|
@ -201,7 +203,7 @@ static GNUAlertPanel *reusableAlertPanel = nil;
|
|||
rect.origin.x = 8.0;
|
||||
messageField = [[NSTextField alloc] initWithFrame: rect];
|
||||
[messageField setAutoresizingMask:
|
||||
NSViewWidthSizable | NSViewHeightSizable];
|
||||
NSViewWidthSizable | NSViewHeightSizable | NSViewMaxYMargin];
|
||||
[messageField setEditable: NO];
|
||||
[messageField setSelectable: NO];
|
||||
[messageField setBordered: NO];
|
||||
|
|
|
@ -226,6 +226,12 @@
|
|||
[self setFrameFromContentFrame: r];
|
||||
}
|
||||
|
||||
- (void) resizeWithOldSuperviewSize: (NSSize)oldSize
|
||||
{
|
||||
[super resizeWithOldSuperviewSize: oldSize];
|
||||
[content_view setFrame: [self calcSizes]];
|
||||
}
|
||||
|
||||
//
|
||||
// Managing the NSView Hierarchy
|
||||
//
|
||||
|
|
180
Source/NSView.m
180
Source/NSView.m
|
@ -623,73 +623,145 @@ id e, o; // to and we have never
|
|||
o = [e nextObject];
|
||||
while (o)
|
||||
{
|
||||
NSRect b = [o bounds];
|
||||
NSSize old_size = b.size; // Resize the subview
|
||||
// Then tell it to
|
||||
[o resizeWithOldSuperviewSize: oldSize]; // resize it's subviews
|
||||
[o resizeSubviewsWithOldSize: old_size];
|
||||
o = [e nextObject];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)resizeWithOldSuperviewSize:(NSSize)oldSize // preliminary FIX ME
|
||||
- (void) resizeWithOldSuperviewSize: (NSSize)oldSize
|
||||
{
|
||||
float change, changePerOption;
|
||||
int options = 0;
|
||||
// do nothing if view
|
||||
if(autoresizingMask == NSViewNotSizable) // is not resizable
|
||||
float changex;
|
||||
float changey;
|
||||
NSSize old_size = bounds.size;
|
||||
BOOL changedOrigin = NO;
|
||||
BOOL changedSize = NO;
|
||||
|
||||
if (autoresizingMask == NSViewNotSizable)
|
||||
return;
|
||||
// determine if X axis
|
||||
if(autoresizingMask & NSViewWidthSizable) // can be resized
|
||||
options++;
|
||||
if(autoresizingMask & NSViewMinXMargin)
|
||||
options++;
|
||||
if(autoresizingMask & NSViewMaxXMargin)
|
||||
options++;
|
||||
// adjust the X axis if
|
||||
if(options >= 1) // any X options are
|
||||
{ // set in the mask
|
||||
change = [super_view frame].size.width - oldSize.width;
|
||||
changePerOption = floor(change/options);
|
||||
|
||||
if(autoresizingMask & NSViewWidthSizable)
|
||||
frame.size.width += changePerOption;
|
||||
if(autoresizingMask & NSViewMinXMargin)
|
||||
frame.origin.x += changePerOption;
|
||||
if(autoresizingMask & NSViewMaxXMargin)
|
||||
frame.size.width += changePerOption;
|
||||
bounds.size.width = frame.size.width;
|
||||
}
|
||||
// determine if Y axis
|
||||
options = 0; // can be resized
|
||||
if(autoresizingMask & NSViewHeightSizable)
|
||||
options++;
|
||||
if(autoresizingMask & NSViewMinYMargin)
|
||||
options++;
|
||||
if(autoresizingMask & NSViewMaxYMargin)
|
||||
options++;
|
||||
// adjust the Y axis if
|
||||
if(options >= 1) // any Y options are
|
||||
{ // set in the mask
|
||||
change = [super_view frame].size.height - oldSize.height;
|
||||
changePerOption = floor(change/options);
|
||||
|
||||
if(autoresizingMask & NSViewHeightSizable)
|
||||
frame.size.height += changePerOption;
|
||||
if(autoresizingMask & NSViewMinYMargin)
|
||||
frame.origin.y += changePerOption;
|
||||
if(autoresizingMask & NSViewMaxYMargin)
|
||||
frame.size.height += changePerOption;
|
||||
bounds.size.height = frame.size.height;
|
||||
}
|
||||
changex = [super_view bounds].size.width - oldSize.width;
|
||||
changey = [super_view bounds].size.height - oldSize.height;
|
||||
|
||||
// adjust the X axis
|
||||
fprintf (stderr, "NSView resizeWithOldSuperviewSize: \n");
|
||||
fprintf (stderr, "Change x,y (%1.2f, %1.2f)\n", changex, changey);
|
||||
fprintf (stderr,
|
||||
"NSView: frame origin (%1.2f, %1.2f), size (%1.2f, %1.2f)\n",
|
||||
"NSView: old origin (%1.2f, %1.2f), size (%1.2f, %1.2f)\n",
|
||||
frame.origin.x, frame.origin.y,
|
||||
frame.size.width, frame.size.height);
|
||||
fprintf (stderr, "NSView: old size (%1.2f, %1.2f)\n",
|
||||
oldSize.width, oldSize.height);
|
||||
|
||||
if (changex)
|
||||
{
|
||||
if (autoresizingMask & NSViewWidthSizable)
|
||||
{
|
||||
float change;
|
||||
|
||||
if (autoresizingMask & NSViewMinXMargin)
|
||||
{
|
||||
if (autoresizingMask & NSViewMaxXMargin)
|
||||
{
|
||||
change = changex/3.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
change = changex/2.0;
|
||||
}
|
||||
frame.origin.x += change;
|
||||
changedOrigin = YES;
|
||||
}
|
||||
else if (autoresizingMask & NSViewMaxXMargin)
|
||||
{
|
||||
change = changex/2.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
change = changex;
|
||||
}
|
||||
bounds.size.width *= (frame.size.width + change);
|
||||
bounds.size.width /= frame.size.width;
|
||||
frame.size.width += change;
|
||||
changedSize = YES;
|
||||
}
|
||||
else if (autoresizingMask & NSViewMinXMargin)
|
||||
{
|
||||
if (autoresizingMask & NSViewMaxXMargin)
|
||||
{
|
||||
frame.origin.x += changex/2.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
frame.origin.x += changex;
|
||||
}
|
||||
changedOrigin = YES;
|
||||
}
|
||||
}
|
||||
|
||||
if (changey)
|
||||
{
|
||||
if (autoresizingMask & NSViewHeightSizable)
|
||||
{
|
||||
float change;
|
||||
|
||||
if (autoresizingMask & NSViewMinYMargin)
|
||||
{
|
||||
if (autoresizingMask & NSViewMaxYMargin)
|
||||
{
|
||||
change = changey/3.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
change = changey/2.0;
|
||||
}
|
||||
frame.origin.y += change;
|
||||
changedOrigin = YES;
|
||||
}
|
||||
else if (autoresizingMask & NSViewMaxYMargin)
|
||||
{
|
||||
change = changey/2.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
change = changey;
|
||||
}
|
||||
bounds.size.height *= (frame.size.height + change);
|
||||
bounds.size.height /= frame.size.height;
|
||||
frame.size.height += change;
|
||||
changedSize = YES;
|
||||
}
|
||||
else if (autoresizingMask & NSViewMinYMargin)
|
||||
{
|
||||
if (autoresizingMask & NSViewMaxYMargin)
|
||||
{
|
||||
frame.origin.y += changey/2.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
frame.origin.y += changey;
|
||||
}
|
||||
changedOrigin = YES;
|
||||
}
|
||||
}
|
||||
|
||||
fprintf (stderr,
|
||||
"NSView: new origin (%1.2f, %1.2f), size (%1.2f, %1.2f)\n",
|
||||
frame.origin.x, frame.origin.y,
|
||||
frame.size.width, frame.size.height);
|
||||
|
||||
if (changedOrigin)
|
||||
{
|
||||
[frameMatrix setFrameOrigin: frame.origin];
|
||||
}
|
||||
if (changedSize)
|
||||
{
|
||||
float sx = frame.size.width / bounds.size.width;
|
||||
float sy = frame.size.height / bounds.size.height;
|
||||
|
||||
[boundsMatrix scaleTo: sx : sy];
|
||||
}
|
||||
if (changedSize || changedOrigin)
|
||||
{
|
||||
[self resizeSubviewsWithOldSize: old_size];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)allocateGState {} // implemented by the
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue