Lots of minimal changes.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@33613 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2011-07-23 13:43:33 +00:00
parent 119056ab5f
commit c100baf6b4
8 changed files with 164 additions and 38 deletions

View file

@ -1,3 +1,14 @@
2011-07-23 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSView.m (autoresize): Handle negative flexible space.
Patch by Tim Schmielau <gnustep@chmielau.orangehome.co.uk>
* Tests/gui/NSView/NSView_bounds_scale.m: More detailed testing.
* Source/NSMenuItem.m,
* Source/NSPageLayout.m,
* Source/NSTextField.m,
* Source/NSViewController.m: Add missing #import.
* Source/NSSegmentedCell.m: Declare missing methods.
2011-07-21 Eric Wasylishen <ewasylishen@gmail.com>
* Source/GSToolTips.m (-_timedOut:): Guard against nil tooltip string

View file

@ -29,10 +29,11 @@
*/
#import "config.h"
#import <Foundation/NSUserDefaults.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSAttributedString.h>
#import <Foundation/NSDebug.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSException.h>
#import <Foundation/NSUserDefaults.h>
#import "AppKit/NSCell.h"
#import "AppKit/NSEvent.h"

View file

@ -32,8 +32,10 @@
#import <Foundation/NSDebug.h>
#import <Foundation/NSDecimalNumber.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSNotification.h>
#import <Foundation/NSNumberFormatter.h>
#import <Foundation/NSUserDefaults.h>
#import "AppKit/NSApplication.h"
#import "AppKit/NSFont.h"
#import "AppKit/NSTextField.h"

View file

@ -51,6 +51,8 @@
- (BOOL) isSelected;
- (void) setSelected: (BOOL)flag;
- (BOOL) isEnabled;
- (void) setEnabled: (BOOL)flag;
- (NSMenu *) menu;
- (void) setMenu: (NSMenu *)menu;
- (NSString *) label;

View file

@ -32,6 +32,7 @@
#include "config.h"
#import <Foundation/NSDictionary.h>
#import <Foundation/NSFormatter.h>
#import <Foundation/NSNotification.h>
#import <Foundation/NSString.h>

View file

@ -1970,7 +1970,7 @@ static void autoresize(CGFloat oldContainerSize,
flexibleSpace += oldContainerSize - oldContentPosition - oldContentSize;
if (flexibleSpace == 0.0)
if (flexibleSpace <= 0.0)
{
/**
* In this code path there is no flexible space so we divide
@ -1994,7 +1994,7 @@ static void autoresize(CGFloat oldContainerSize,
}
}
}
else if (flexibleSpace > 0.0)
else
{
/**
* In this code path we distribute the change proportionately

View file

@ -25,6 +25,7 @@
Boston, MA 02110-1301, USA.
*/
#import <Foundation/NSBundle.h>
#import <Foundation/NSString.h>
#import "AppKit/NSKeyValueBinding.h"
#import "AppKit/NSNib.h"

View file

@ -1,5 +1,6 @@
/*
copyright 2011 HNS <hns@goldelico.com>
Modified by Fred Kiefer on 18.07.11.
*/
#include "Testing.h"
@ -12,35 +13,76 @@ copyright 2011 HNS <hns@goldelico.com>
int CHECK(NSView *view, NSRect frame, NSRect bounds)
{
NSRect r;
NSRect r;
r = [view frame];
if (fabs(r.origin.x - frame.origin.x)>0.001
|| fabs(r.origin.y - frame.origin.y)>0.001
|| fabs(r.size.width - frame.size.width)>0.001
|| fabs(r.size.height - frame.size.height)>0.001)
{
printf("(1) expected frame (%g %g)+(%g %g), got (%g %g)+(%g %g)\n",
frame.origin.x, frame.origin.y, frame.size.width, frame.size.height,
r.origin.x, r.origin.y, r.size.width, r.size.height);
return 0;
}
r = [view bounds];
if (fabs(r.origin.x - bounds.origin.x)>0.001
|| fabs(r.origin.y - bounds.origin.y)>0.001
|| fabs(r.size.width - bounds.size.width)>0.001
|| fabs(r.size.height - bounds.size.height)>0.001)
{
printf("(2) expected bounds (%g %g)+(%g %g), got (%g %g)+(%g %g)\n",
bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height,
r.origin.x, r.origin.y, r.size.width, r.size.height);
return 0;
}
return 1;
}
r = [view frame];
if (fabs(r.origin.x - frame.origin.x)>0.001
|| fabs(r.origin.y - frame.origin.y)>0.001
|| fabs(r.size.width - frame.size.width)>0.001
|| fabs(r.size.height - frame.size.height)>0.001)
{
printf("(1) expected frame (%g %g)+(%g %g), got (%g %g)+(%g %g)\n",
frame.origin.x, frame.origin.y, frame.size.width, frame.size.height,
r.origin.x, r.origin.y, r.size.width, r.size.height);
int CHECK_BOUNDS_ROTATION(NSView *view, CGFloat rot)
{
if (fabs([view boundsRotation] - rot) > 0.001)
{
printf("expected bounds rotation %g got %g\n", rot, [view boundsRotation]);
return 0;
}
return 0;
}
return 1;
}
r = [view bounds];
if (fabs(r.origin.x - bounds.origin.x)>0.001
|| fabs(r.origin.y - bounds.origin.y)>0.001
|| fabs(r.size.width - bounds.size.width)>0.001
|| fabs(r.size.height - bounds.size.height)>0.001)
{
printf("(2) expected bounds (%g %g)+(%g %g), got (%g %g)+(%g %g)\n",
bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height,
r.origin.x, r.origin.y, r.size.width, r.size.height);
return 0;
}
return 1;
int CHECK_MATRIX(NSView *view, CGFloat *ts)
{
NSView *superView = [view superview];
CGFloat tsm[6];
NSPoint res;
res = [view convertPoint: NSMakePoint(0, 0) toView: superView];
tsm[4] = res.x;
tsm[5] = res.y;
res = [view convertPoint: NSMakePoint(1, 0) toView: superView];
tsm[0] = res.x - tsm[4];
tsm[1] = res.y - tsm[5];
res = [view convertPoint: NSMakePoint(0, 1) toView: superView];
tsm[2] = res.x - tsm[4];
tsm[3] = res.y - tsm[5];
if (fabs(ts[0] - tsm[0]) > 0.001
|| fabs(ts[1] - tsm[1]) > 0.001
|| fabs(ts[2] - tsm[2]) > 0.001
|| fabs(ts[3] - tsm[3]) > 0.001
|| fabs(ts[4] - tsm[4]) > 0.001
|| fabs(ts[5] - tsm[5]) > 0.001)
{
printf("expected bounds matrix (%g %g %g %g %g %g) got (%g %g %g %g %g %g)\n", ts[0], ts[1], ts[2], ts[3], ts[4], ts[5],
tsm[0], tsm[1], tsm[2], tsm[3], tsm[4], tsm[5]);
return 0;
}
return 1;
}
int main(int argc, char **argv)
@ -49,36 +91,102 @@ int main(int argc, char **argv)
NSWindow *window;
NSView *view1;
CGFloat ts[6];
int passed = 1;
[NSApplication sharedApplication];
window = [[NSWindow alloc] initWithContentRect: NSMakeRect(100,100,200,200)
styleMask: NSClosableWindowMask
styleMask: NSClosableWindowMask
backing: NSBackingStoreRetained
defer: YES];
view1 = [[NSView alloc] initWithFrame: NSMakeRect(20,20,100,100)];
[[window contentView] addSubview: view1];
[view1 setBounds: NSMakeRect(30.4657, 88.5895, 21.2439, 60.8716)];
passed = CHECK(view1, NSMakeRect(20,20,100,100), NSMakeRect(30.4657, 88.5895, 21.2439, 60.8716)) && passed;
passed = CHECK_BOUNDS_ROTATION(view1, 0) && passed;
ts[0] = 4.70723;
ts[1] = 0;
ts[2] = 0;
ts[3] = 1.64281;
ts[4] = -123.409;
ts[5] = -125.535;
passed = CHECK_MATRIX(view1, ts) && passed;
[view1 setBoundsRotation: 30];
passed = (fabs([view1 boundsRotation] - 30.0) <= 0.001) && passed;
// passed = CHECK(view1, NSMakeRect(20,20,100,100), NSMakeRect(70.5714, 50.9892, 48.8336, 63.3383)) && passed;
passed = CHECK(view1, NSMakeRect(20,20,100,100), NSMakeRect(70.6788, 50.866, 48.8336, 63.3383)) && passed;
passed = CHECK_BOUNDS_ROTATION(view1, 30) && passed;
ts[0] = 4.07658;
ts[1] = 0.821396;
ts[2] = -2.35362;
ts[3] = 1.42271;
ts[4] = -123.409;
ts[5] = -125.535;
passed = CHECK_MATRIX(view1, ts) && passed;
[view1 setBounds:(NSRect){{30.4657, 88.5895}, {21.2439, 60.8716}}];
passed = CHECK(view1, NSMakeRect(20,20,100,100),(NSRect) {{30.4657, 77.9676}, {48.8336, 63.3383}}) && passed;
passed = CHECK_BOUNDS_ROTATION(view1, 30) && passed;
ts[0] = 4.07658;
ts[1] = 0.821396;
ts[2] = -2.35361;
ts[3] = 1.42271;
ts[4] = 104.31;
ts[5] = -131.062;
passed = CHECK_MATRIX(view1, ts) && passed;
[view1 scaleUnitSquareToSize:(NSSize){0.720733, 0.747573}];
passed = CHECK(view1, NSMakeRect(20,20,100,100),(NSRect) {{42.2704, 104.294}, {67.7554, 84.7253}}) && passed;
[view1 setBoundsRotation: 30 - 1e-6];
passed = CHECK_BOUNDS_ROTATION(view1, 30) && passed;
ts[0] = 2.93813;
ts[1] = 0.59201;
ts[2] = -1.7595;
ts[3] = 1.06358;
ts[4] = 104.31;
ts[5] = -131.062;
passed = CHECK_MATRIX(view1, ts) && passed;
[view1 setBoundsRotation:30-1e-6];
passed = (fabs([view1 boundsRotation] - 30.0 + 1e-6) <= 0.001) && passed;
passed = CHECK(view1, NSMakeRect(20,20,100,100),(NSRect) {{39.9801, 104.211}, {66.2393, 85.2544}}) && passed;
[view1 rotateByAngle: 1e-6];
passed = CHECK_BOUNDS_ROTATION(view1, 30 - 1e-6) && passed;
ts[0] = 2.93813;
ts[1] = 0.614059;
ts[2] = -1.69633;
ts[3] = 1.06358;
ts[4] = 104.31;
ts[5] = -131.062;
passed = CHECK_MATRIX(view1, ts) && passed;
[view1 rotateByAngle:1e-6];
passed = CHECK(view1, NSMakeRect(20,20,100,100),(NSRect) {{39.9801, 104.211}, {66.2393, 85.2544}}) && passed;
passed = (fabs([view1 boundsRotation] - 30.0) <= 0.001) && passed;
passed = CHECK_BOUNDS_ROTATION(view1, 30) && passed;
view1 = [[NSView alloc] initWithFrame: NSMakeRect(20,20,100,100)];
[[window contentView] addSubview: view1];
[view1 setBounds: NSMakeRect(30.4657, 88.5895, 21.2439, 60.8716)];
passed = CHECK(view1, NSMakeRect(20,20,100,100), NSMakeRect(30.4657, 88.5895, 21.2439, 60.8716)) && passed;
[view1 scaleUnitSquareToSize:(NSSize){0.720733, 0.747573}];
passed = CHECK(view1, NSMakeRect(20,20,100,100),(NSRect) {{42.2704, 118.503}, {29.4754, 81.4256}}) && passed;
passed = CHECK_BOUNDS_ROTATION(view1, 0) && passed;
[view1 setBoundsRotation:30];
passed = CHECK(view1, NSMakeRect(20,20,100,100),(NSRect) {{95.8587, 66.7535}, {66.2393, 85.2544}}) && passed;
passed = CHECK_BOUNDS_ROTATION(view1, 30) && passed;
view1 = [[NSView alloc] initWithFrame: NSMakeRect(20,20,100,100)];
[[window contentView] addSubview: view1];
[view1 setBounds: NSMakeRect(30.4657, 88.5895, 21.2439, 60.8716)];
passed = CHECK(view1, NSMakeRect(20,20,100,100), NSMakeRect(30.4657, 88.5895, 21.2439, 60.8716)) && passed;
[view1 setBoundsRotation:30];
passed = CHECK(view1, NSMakeRect(20,20,100,100),(NSRect) {{70.6788, 50.866}, {48.8336, 63.3383}}) && passed;
passed = CHECK_BOUNDS_ROTATION(view1, 30) && passed;
[view1 scaleUnitSquareToSize:(NSSize){0.720733, 0.747573}];
passed = CHECK(view1, NSMakeRect(20,20,100,100),(NSRect) {{98.0652, 68.0415}, {67.7554, 84.7252}}) && passed;
passed = CHECK_BOUNDS_ROTATION(view1, 30) && passed;
pass(passed,"NSView -scaleUnitSquareToSize works");
DESTROY(arp);
return 0;
}