//
//  PluginController.m
//  DarkKit
//
//  Created by Chad Weider on 4/13/08.
//  Copyright (c) 2008 Chad Weider
//  Some rights reserved: <http://www.opensource.org/licenses/zlib-license.php>
//  
//  This software is provided 'as-is', without any express or implied warranty.
//  In no event will the authors be held liable for any damages arising from the
//  use of this software.
//  
//  Permission is granted to anyone to use this software for any purpose,
//  including commercial applications, and to alter it and redistribute it
//  freely, subject to the following restrictions:
//  
//  1. The origin of this software must not be misrepresented; you must not   
//  claim that you wrote the original software. If you use this software in a
//  product, an acknowledgment in the product documentation would be appreciated
//  but is not required.
//  
//  2. Altered source versions must be plainly marked as such, and must not be
//  misrepresented as being the original software.
//  
//  3. This notice may not be removed or altered from any source distribution.
//

#import "PluginController.h"

@class DKWindow, IBEditableWindow, IBWindowView;

@implementation PluginController

- (void)awakeFromNib
  {
  if(method_exchangeImplementations && 0)
	{
//	Method dkMethod = class_getClassMethod([DKWindow class], @selector(frameViewClassForStyleMask:));
//	IMP dkImplement =  class_getMethodImplementation([DKWindow class], @selector(frameViewClassForStyleMask:));
//	class_addMethod([IBEditableWindow class], @selector(frameViewClassForStyleMask:), dkImplement, method_getTypeEncoding(dkMethod));
//	Method nsMethod = class_getClassMethod([IBEditableWindow class], @selector(frameViewClassForStyleMask:));
	//method_setImplementation(nsMethod, dkImplement);
	NSLog(@"oldsuper: %s", class_getName(class_setSuperclass([IBEditableWindow class], [DKWindow class])));

//	Class hClass = objc_allocateClassPair([NSWindow superclass], "NSWindowHack", 0);
//	class_setIvarLayout(hClass, class_getIvarLayout([NSWindow class]));
//	class_setWeakIvarLayout(hClass, class_getWeakIvarLayout([NSWindow class]));
//	class_setVersion(hClass, class_getVersion([NSWindow class]));
//	
//	 = class_copyIvarList
//	while(ivarList != NULL)
//		{
//		class_addIvar(<#Class cls#>, <#const char * name#>, <#size_t size#>, <#uint8_t alignment#>, <#const char * types#>);
//		ivarList++;
//		}
//	class_copyPropertyList
//	Method *methodList = class_copyMethodList([NSWindow class], NULL);
//	while(methodList != NULL)
//		{
//		class_addMethod(hClass, methodList->method_name, methodList->imp, methodList->method_types);
//		methodList++;
//		}
//	class_copyProtocolList
	}
  else
	[DKWindow poseAsClass:[NSWindow class]];
  
  
  
  NSWindow *darkWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(196, 240, 480, 270) styleMask:(NSTitledWindowMask | NSClosableWindowMask | 1 << 15)  backing:NSBackingStoreBuffered defer:YES];
  [darkWindow setTitle:@"Window"];
  
  IBWindowView *ibWindow = [IBWindowView new];
  [ibWindow setWindowToMimic:darkWindow];
  [ibWindow sizeToFit];
  
  [windowIBTemplate setDraggedView:ibWindow];
    
  NSWindowTemplate *windowTemplate = [NSWindowTemplate new];
  [windowTemplate setValue:[[NSView alloc] initWithFrame:NSMakeRect(196, 240, 480, 270)] forKeyPath:@"windowView"];
  [windowTemplate setValue:@"DKWindow" forKeyPath:@"windowClass"];
  [windowTemplate setTitle:@"Window"];
  [windowTemplate setStyleMask:[darkWindow styleMask] | (1 << 15)];
  [windowTemplate setContentRect:NSMakeRect(196, 240, 480, 270)];
  [windowTemplate setVisibleAtLaunch:YES];
  [windowTemplate setBackingType:NSBackingStoreBuffered];
  [windowTemplate setDeferred:YES];
  [windowIBTemplate setRepresentedObject:windowTemplate];
  [windowIBTemplate setSubtitle:@"DKWindow"];
  
  
//  NSPanel *darkPanel = [[NSPanel alloc] initWithContentRect:NSMakeRect(196, 240, 480, 270) styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSUtilityWindowMask | 1 << 15)  backing:NSBackingStoreBuffered defer:YES];
//  
//  IBWindowView *ibPanel = [IBWindowView new];
//  [ibPanel setWindowToMimic:darkPanel];
//  [ibPanel sizeToFit];
//  
//  [panelIBTemplate setDraggedView:ibPanel];
//  
//  NSWindowTemplate *panelTemplate = [NSWindowTemplate new];
//  [panelTemplate setValue:[[NSView alloc] initWithFrame:NSMakeRect(196, 240, 480, 270)] forKeyPath:@"windowView"];
//  [panelTemplate setValue:@"DKPanel" forKeyPath:@"windowClass"];
//  
//  [panelTemplate setTitle:@"Window"];
//  [panelTemplate setStyleMask:[darkPanel styleMask] | (1 << 15)];
//  [panelTemplate setContentRect:NSMakeRect(196, 240, 480, 270)];
//  [panelTemplate setVisibleAtLaunch:YES];
//  [panelTemplate setBackingType:NSBackingStoreBuffered];
//  [panelTemplate setDeferred:YES];
//  [panelIBTemplate setRepresentedObject:panelTemplate];  
  }

@end
