//
//  AppController.m
//  test
//
//  Created by H. Nikolaus Schaller on 02.10.07.
//  Copyright 2007 Golden Delicious Computers GmbH&Co. KG. All rights reserved.
//

#import "AppController.h"


@implementation AppController

- (void) awakeFromNib;
{
	int i;
	NSData *data;
	NSPropertyListFormat format;
	NSString *error;
#if 0
	{
		NSAffineTransform *atm=[NSAffineTransform new];
		NSSize sz;
		[atm scaleXBy:1.0 yBy:-1.0];	// flip y
		sz=NSMakeSize(-10.0, -30.0);	// how is negative size handled?
		NSLog(@"%@ -> %@", NSStringFromSize(sz), NSStringFromSize([atm transformSize:sz]));
		sz=NSMakeSize(-10.0, 30.0);	// how is positive size handled with flipping?
		NSLog(@"%@ -> %@", NSStringFromSize(sz), NSStringFromSize([atm transformSize:sz]));
		// result: it simply returns -1.0 * sz.height
	}
#endif
	[button setTitle:@"QWERTY"];
	[button setAlternateTitle:@"qwerty"];
	[button setButtonType:7];
	[button setBordered:YES];
	[[button cell] setBezeled:YES];
	[button setTransparent:NO];
	[[button cell] setImageDimsWhenDisabled:YES];
	[button setBezelStyle:10];
	NSLog(@"highlightMask=%02x", [[button cell] highlightsBy]);
	NSLog(@"stateMask=%02x", [[button cell] showsStateBy]);
#if 1
#ifdef __APPLE__
	[[button cell] setHighlightsBy:0];
	for(i=0; i<20; i++)
		{
		id plist;
		[[button cell] setShowsStateBy:i];
//	NSLog(@"buttonType=%d", [button buttonType]);
		NSLog(@"i=%d", i);
		NSLog(@"highlightMask=%02x", [[button cell] highlightsBy]);
		NSLog(@"stateMask=%02x", [[button cell] showsStateBy]);
		data=[NSKeyedArchiver archivedDataWithRootObject:[button cell]];
		plist=[NSPropertyListSerialization propertyListFromData:data mutabilityOption:0 format:&format errorDescription:&error];
		// NSLog(@"plist=%@", plist);
		plist=[plist objectForKey:@"$objects"];
		plist=[plist objectAtIndex:1];
		//NSLog(@"button=%@", plist);
		NSLog(@"cflags=%08x cflags2=%08x, bflags=%08x bflags2=%08x", [[plist objectForKey:@"NSCellFlags"] intValue], [[plist objectForKey:@"NSCellFlags2"] intValue], [[plist objectForKey:@"NSButtonFlags"] intValue], [[plist objectForKey:@"NSButtonFlags2"] intValue]);
		}
#endif
#endif
#if 1
#ifdef __APPLE__
	for(i=0; i<8; i++)
		{
		id plist;
		int bit=1<<i;
		struct { int cflags, cflags2, bflags, bflags2; } v0, v1;
		SEL sel=@selector(setHighlightsBy:);
		
		[[button cell] setHighlightsBy:0];
		data=[NSKeyedArchiver archivedDataWithRootObject:[button cell]];
		plist=[NSPropertyListSerialization propertyListFromData:data mutabilityOption:0 format:&format errorDescription:&error];
		plist=[plist objectForKey:@"$objects"];
		plist=[plist objectAtIndex:1];
		v0.cflags=[[plist objectForKey:@"NSCellFlags"] intValue];
		v0.cflags2=[[plist objectForKey:@"NSCellFlags2"] intValue];
		v0.bflags=[[plist objectForKey:@"NSButtonFlags"] intValue];
		v0.bflags2=[[plist objectForKey:@"NSButtonFlags2"] intValue];
		
		[[button cell] setHighlightsBy:bit];

		data=[NSKeyedArchiver archivedDataWithRootObject:[button cell]];
		plist=[NSPropertyListSerialization propertyListFromData:data mutabilityOption:0 format:&format errorDescription:&error];
		plist=[plist objectForKey:@"$objects"];
		plist=[plist objectAtIndex:1];
		v1.cflags=[[plist objectForKey:@"NSCellFlags"] intValue];
		v1.cflags2=[[plist objectForKey:@"NSCellFlags2"] intValue];
		v1.bflags=[[plist objectForKey:@"NSButtonFlags"] intValue];
		v1.bflags2=[[plist objectForKey:@"NSButtonFlags2"] intValue];
		
		NSLog(@"bit %d of %@ corresponds to cflags=%08x cflags2=%08x bflags=%08x bflags2=%08x", i, NSStringFromSelector(sel), 
			  v0.cflags^v1.cflags,
			  v0.cflags2^v1.cflags2,
			  v0.bflags^v1.bflags,
			  v0.bflags2^v1.bflags2);
		}
#endif
#endif
}

@end
