From 2040e00d7fa3ef9cbe1166c3786755bd97feca9f Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Fri, 16 Jun 2017 08:18:33 -0500 Subject: [PATCH] this project is so dumb --- ui/AppDelegate.h | 1 + ui/AppDelegate.m | 89 ++++++--------------------------------- ui/MainView.h | 4 ++ ui/MainView.m | 20 +++++++++ ui/MainViewController.h | 4 ++ ui/MainViewController.m | 61 +++++++++++++++++++++++++++ ui/MainWindowController.h | 4 ++ ui/MainWindowController.m | 59 ++++++++++++++++++++++++++ ui/ui_darwin.m | 9 ---- 9 files changed, 167 insertions(+), 84 deletions(-) create mode 100644 ui/MainView.h create mode 100644 ui/MainView.m create mode 100644 ui/MainViewController.h create mode 100644 ui/MainViewController.m create mode 100644 ui/MainWindowController.h create mode 100644 ui/MainWindowController.m diff --git a/ui/AppDelegate.h b/ui/AppDelegate.h index a59935b..4ce60d6 100644 --- a/ui/AppDelegate.h +++ b/ui/AppDelegate.h @@ -1,4 +1,5 @@ #import +#import "MainWindowController.h" @interface AppDelegate : NSObject @end diff --git a/ui/AppDelegate.m b/ui/AppDelegate.m index 8218650..e4ce0a8 100644 --- a/ui/AppDelegate.m +++ b/ui/AppDelegate.m @@ -1,94 +1,41 @@ #import "AppDelegate.h" +#import "MainWindowController.h" @implementation AppDelegate // Application Startup ------------------------------------------------------{{{ -- (void) applicationWillFinishLaunching:(NSNotification *)notification { - NSLog(@"applicationWillFinishLaunching notification: %@", notification); - NSLog(@"Main Menu in applicationWillFinishLaunching: %@", [NSApp mainMenu]); -} - - (void) applicationDidFinishLaunching:(NSNotification *)notification { - NSLog(@"applicationDidFinishLaunching notification: %@", notification); - NSLog(@"Main Menu in applicationDidFinishLaunching: %@", [NSApp mainMenu]); + NSLog(@"[AppDelegate] Application Finished Launching"); [self createMenubar]; [self createMainWindow]; + NSLog(@"[AppDelegate] activate NSApp"); [NSApp activateIgnoringOtherApps:YES]; + } // --------------------------------------------------------------------------}}} // Application Termination --------------------------------------------------{{{ - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender { - NSLog(@"applicationShouldTerminate sender: %@", sender); + NSLog(@"[AppDelegate] applicationShouldTerminate sender: %@", sender); return NSTerminateNow; } - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender { - NSLog(@"applicationShouldTerminateAfterLastWindowClosed sender: %@", sender); + NSLog(@"[AppDelegate] applicationShouldTerminateAfterLastWindowClosed sender: %@", sender); return YES; } - (void)applicationWillTerminate:(NSNotification *)notification { - NSLog(@"applicationWillTerminate notification sender: %@", notification); -} - -// --------------------------------------------------------------------------}}} -// Application Active Status ------------------------------------------------{{{ - -- (void)applicationWillBecomeActive:(NSNotification *)notification { - NSLog(@"applicationWillBecomeActive notification: %@", notification); -} - -- (void)applicationDidBecomeActive:(NSNotification *)notification { - NSLog(@"applicationDidBecomeActive notification: %@", notification); -} - -- (void)applicationWillResignActive:(NSNotification *)notification { - NSLog(@"applicationWillResignActive notification: %@", notification); -} - -- (void)applicationDidResignActive:(NSNotification *)notification { - NSLog(@"applicationDidResignActive notification: %@", notification); -} - -// --------------------------------------------------------------------------}}} -// Application Hide Status --------------------------------------------------{{{ - -- (void)applicationWillHide:(NSNotification *)notification { - NSLog(@"applicationWillHide notification: %@", notification); -} - -- (void)applicationDidHide:(NSNotification *)notification { - NSLog(@"applicationDidHide notification: %@", notification); -} - -- (void)applicationWillUnhide:(NSNotification *)notification { - NSLog(@"applicationWillUnhide notification: %@", notification); -} - -- (void)applicationDidUnhide:(NSNotification *)notification { - NSLog(@"applicationDidUnhide notification: %@", notification); -} - -// --------------------------------------------------------------------------}}} -// Application Update Status ------------------------------------------------{{{ - -- (void)applicationWillUpdate:(NSNotification *)notification { - // NSLog(@"applicationWillUpdate notification: %@", notification); -} - -- (void)applicationDidUpdate:(NSNotification *)notification { - // NSLog(@"applicationDidUpdate notification: %@", notification); + NSLog(@"[AppDelegate] applicationWillTerminate notification sender: %@", notification); } // --------------------------------------------------------------------------}}} // Menu Bar -----------------------------------------------------------------{{{ - (void) createMenubar { - NSLog(@"Will create menu bar here"); - NSLog(@"creating menu bar. initial main menu bar: %@", [NSApp mainMenu]); + NSLog(@"[AppDelegate] Creating Menubar"); id mainMenu = [[NSMenu alloc] autorelease]; [mainMenu initWithTitle:@"Main Menu"]; @@ -105,26 +52,18 @@ id quitMenuItem = [[NSMenuItem alloc] autorelease]; [quitMenuItem initWithTitle:@"Quit" action:@selector(terminate:) keyEquivalent:@"q"]; [appMenu addItem:quitMenuItem]; - NSLog(@"assigned to main menu: %@", [NSApp mainMenu]); } // --------------------------------------------------------------------------}}} // Main Window --------------------------------------------------------------{{{ - (void) createMainWindow { - NSUInteger windowStyle = NSTitledWindowMask - | NSClosableWindowMask - | NSResizableWindowMask; - - id window = [NSWindow alloc]; - [window initWithContentRect:NSMakeRect(0, 0, 640, 480) - styleMask:windowStyle - backing:NSBackingStoreBuffered - defer:NO]; - - [window cascadeTopLeftFromPoint:NSMakePoint(20, 20)]; - [window setTitle:@"dws"]; - [window makeKeyAndOrderFront:NSApp]; + NSLog(@"[AppDelegate] Creating Main Window"); + // TODO: make a singleton? retain in a property of appdelegate? + // MainWindowController *windowController = [[[MainWindowController alloc] init] retain]; + MainWindowController *windowController = [[MainWindowController alloc] init]; + // NSLog(@"Window loaded: %d", [windowController isWindowLoaded]); + [windowController showWindow:self]; } // --------------------------------------------------------------------------}}} diff --git a/ui/MainView.h b/ui/MainView.h new file mode 100644 index 0000000..c4d6523 --- /dev/null +++ b/ui/MainView.h @@ -0,0 +1,4 @@ +#import + +@interface MainView : NSView +@end diff --git a/ui/MainView.m b/ui/MainView.m new file mode 100644 index 0000000..6130c3e --- /dev/null +++ b/ui/MainView.m @@ -0,0 +1,20 @@ +#import "MainView.h" + +@implementation MainView + +- (instancetype)initWithFrame:(NSRect)frameRect { + NSLog(@"[MainView] initWithFrame: %@", NSStringFromRect(frameRect)); + self = [super initWithFrame:frameRect]; + + // NSTextField *textField = [[NSTextField alloc] init]; + // [self addSubview:textField]; + // textField.translatesAutoresizingMaskIntoConstraints = NO; + + return self; +} + +- (void) viewDidMoveToWindow { + NSLog(@"[MainView] viewDidMoveToWindow: %@", self.window); +} + +@end diff --git a/ui/MainViewController.h b/ui/MainViewController.h new file mode 100644 index 0000000..c370fca --- /dev/null +++ b/ui/MainViewController.h @@ -0,0 +1,4 @@ +#import + +@interface MainViewController : NSViewController +@end diff --git a/ui/MainViewController.m b/ui/MainViewController.m new file mode 100644 index 0000000..8e27459 --- /dev/null +++ b/ui/MainViewController.m @@ -0,0 +1,61 @@ +#import "MainViewController.h" +#import +#import "MainView.h" + +@implementation MainViewController { + NSButton *firstButton; +} + +- (void) loadView { + NSLog(@"[MainViewController] loadView"); + self.view = [[MainView alloc] initWithFrame:NSMakeRect(0, 0, 640, 480)]; +} + +- (void) viewDidLoad { + NSLog(@"[MainViewController] viewDidLoad"); + [super viewDidLoad]; + + firstButton = [[NSButton alloc] initWithFrame:NSMakeRect(0, 0, 120, 20)]; + [firstButton setButtonType:NSToggleButton]; + [firstButton setTitle:@"fart"]; + + int i=0; + unsigned int mc = 0; + Method * mlist = class_copyMethodList(object_getClass(firstButton), &mc); + NSLog(@"%d methods", mc); + for(i=0;i + +@interface MainWindowController : NSWindowController +@end diff --git a/ui/MainWindowController.m b/ui/MainWindowController.m new file mode 100644 index 0000000..8cc1ce9 --- /dev/null +++ b/ui/MainWindowController.m @@ -0,0 +1,59 @@ +#import "MainWindowController.h" +#import "MainViewController.h" + +@implementation MainWindowController + +- (id) init { + id viewController = [[MainViewController alloc] init]; + NSLog(@"[MainWindowController] init: view loaded: %d", [viewController isViewLoaded]); + + id window = [[NSWindow windowWithContentViewController:viewController] retain]; + NSLog(@"[MainWindowController] window: %@", window); + NSLog(@"[MainWindowController] init (2): view loaded: %d", [viewController isViewLoaded]); + return [self initWithWindow:window]; +} + +- (instancetype) initWithWindow:(NSWindow *)window { + NSLog(@"[MainWindowController] initWithWindow: %@", window); + return [super initWithWindow:window]; +} + +- (instancetype)initWithWindowNibName:(NSString*)windowNibName { + NSLog(@"[MainWindowController] initWithWindowNibName"); + return [super initWithWindowNibName:windowNibName]; +} + +- (instancetype)initWithWindowNibName:(NSString*)windowNibName + owner:(id)owner { + NSLog(@"[MainWindowController] initWithWindowNibNameOwner"); + return [super initWithWindowNibName:windowNibName]; +} + +- (instancetype)initWithWindowNibPath:(NSString *)windowNibPath + owner:(id)owner { + NSLog(@"[MainWindowController initWithWindowNibPath:owner"); + return [super initWithWindowNibPath:windowNibPath + owner:owner]; +} + +- (void) windowWillLoad { + NSLog(@"[MainWindowController] windowWillLoad"); + return [super windowWillLoad]; +} + +- (void) windowDidLoad { + NSLog(@"[MainWindowController] windowDidLoad"); + return [super windowDidLoad]; +} + +- (void) loadWindow { + NSLog(@"[MainWindowController] loadWindow"); + return [super loadWindow]; +} + +- (IBAction) showWindow:(id)sender { + NSLog(@"[MainWindowController] showWindow"); + return [super showWindow:sender]; +} + +@end diff --git a/ui/ui_darwin.m b/ui/ui_darwin.m index 24b7783..5ffd0d7 100644 --- a/ui/ui_darwin.m +++ b/ui/ui_darwin.m @@ -5,23 +5,14 @@ id defaultAutoreleasePool; id appDelegate; void Initialize(void) { - NSLog(@"Initializing with processInfo: %@", [[NSProcessInfo processInfo] arguments]); - NSLog(@"Creating Autorelease Pool"); defaultAutoreleasePool = [NSAutoreleasePool new]; [NSApplication sharedApplication]; - NSLog(@"Setting App Delegate"); [NSApp setDelegate: [[AppDelegate new] autorelease]]; [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; - NSLog(@"Initialization complete"); } int Run(void) { - NSLog(@"Entered Run"); - NSLog(@"Activating App"); - NSLog(@"Running App Event Loop"); [NSApp run]; - NSLog(@"App Event Loop finished. Draining pool."); [defaultAutoreleasePool drain]; - NSLog(@"Leaving Run"); return 0; }