this project is so dumb

master
Jordan Orelli 7 years ago
parent 3dff82bbad
commit 2040e00d7f

@ -1,4 +1,5 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#import "MainWindowController.h"
@interface AppDelegate : NSObject <NSApplicationDelegate> @interface AppDelegate : NSObject <NSApplicationDelegate>
@end @end

@ -1,94 +1,41 @@
#import "AppDelegate.h" #import "AppDelegate.h"
#import "MainWindowController.h"
@implementation AppDelegate @implementation AppDelegate
// Application Startup ------------------------------------------------------{{{ // Application Startup ------------------------------------------------------{{{
- (void) applicationWillFinishLaunching:(NSNotification *)notification {
NSLog(@"applicationWillFinishLaunching notification: %@", notification);
NSLog(@"Main Menu in applicationWillFinishLaunching: %@", [NSApp mainMenu]);
}
- (void) applicationDidFinishLaunching:(NSNotification *)notification { - (void) applicationDidFinishLaunching:(NSNotification *)notification {
NSLog(@"applicationDidFinishLaunching notification: %@", notification); NSLog(@"[AppDelegate] Application Finished Launching");
NSLog(@"Main Menu in applicationDidFinishLaunching: %@", [NSApp mainMenu]);
[self createMenubar]; [self createMenubar];
[self createMainWindow]; [self createMainWindow];
NSLog(@"[AppDelegate] activate NSApp");
[NSApp activateIgnoringOtherApps:YES]; [NSApp activateIgnoringOtherApps:YES];
} }
// --------------------------------------------------------------------------}}} // --------------------------------------------------------------------------}}}
// Application Termination --------------------------------------------------{{{ // Application Termination --------------------------------------------------{{{
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender { - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender {
NSLog(@"applicationShouldTerminate sender: %@", sender); NSLog(@"[AppDelegate] applicationShouldTerminate sender: %@", sender);
return NSTerminateNow; return NSTerminateNow;
} }
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender { - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender {
NSLog(@"applicationShouldTerminateAfterLastWindowClosed sender: %@", sender); NSLog(@"[AppDelegate] applicationShouldTerminateAfterLastWindowClosed sender: %@", sender);
return YES; return YES;
} }
- (void)applicationWillTerminate:(NSNotification *)notification { - (void)applicationWillTerminate:(NSNotification *)notification {
NSLog(@"applicationWillTerminate notification sender: %@", notification); NSLog(@"[AppDelegate] 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);
} }
// --------------------------------------------------------------------------}}} // --------------------------------------------------------------------------}}}
// Menu Bar -----------------------------------------------------------------{{{ // Menu Bar -----------------------------------------------------------------{{{
- (void) createMenubar { - (void) createMenubar {
NSLog(@"Will create menu bar here"); NSLog(@"[AppDelegate] Creating Menubar");
NSLog(@"creating menu bar. initial main menu bar: %@", [NSApp mainMenu]);
id mainMenu = [[NSMenu alloc] autorelease]; id mainMenu = [[NSMenu alloc] autorelease];
[mainMenu initWithTitle:@"Main Menu"]; [mainMenu initWithTitle:@"Main Menu"];
@ -105,26 +52,18 @@
id quitMenuItem = [[NSMenuItem alloc] autorelease]; id quitMenuItem = [[NSMenuItem alloc] autorelease];
[quitMenuItem initWithTitle:@"Quit" action:@selector(terminate:) keyEquivalent:@"q"]; [quitMenuItem initWithTitle:@"Quit" action:@selector(terminate:) keyEquivalent:@"q"];
[appMenu addItem:quitMenuItem]; [appMenu addItem:quitMenuItem];
NSLog(@"assigned to main menu: %@", [NSApp mainMenu]);
} }
// --------------------------------------------------------------------------}}} // --------------------------------------------------------------------------}}}
// Main Window --------------------------------------------------------------{{{ // Main Window --------------------------------------------------------------{{{
- (void) createMainWindow { - (void) createMainWindow {
NSUInteger windowStyle = NSTitledWindowMask NSLog(@"[AppDelegate] Creating Main Window");
| NSClosableWindowMask // TODO: make a singleton? retain in a property of appdelegate?
| NSResizableWindowMask; // MainWindowController *windowController = [[[MainWindowController alloc] init] retain];
MainWindowController *windowController = [[MainWindowController alloc] init];
id window = [NSWindow alloc]; // NSLog(@"Window loaded: %d", [windowController isWindowLoaded]);
[window initWithContentRect:NSMakeRect(0, 0, 640, 480) [windowController showWindow:self];
styleMask:windowStyle
backing:NSBackingStoreBuffered
defer:NO];
[window cascadeTopLeftFromPoint:NSMakePoint(20, 20)];
[window setTitle:@"dws"];
[window makeKeyAndOrderFront:NSApp];
} }
// --------------------------------------------------------------------------}}} // --------------------------------------------------------------------------}}}

@ -0,0 +1,4 @@
#import <Cocoa/Cocoa.h>
@interface MainView : NSView
@end

@ -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

@ -0,0 +1,4 @@
#import <Cocoa/Cocoa.h>
@interface MainViewController : NSViewController
@end

@ -0,0 +1,61 @@
#import "MainViewController.h"
#import <objc/runtime.h>
#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<mc;i++)
NSLog(@"Method no #%d: %s", i, sel_getName(method_getName(mlist[i])));
[self.view addSubview:firstButton];
}
- (void) viewWillAppear {
NSLog(@"[MainViewController] viewWillAppear");
return [super viewWillAppear];
}
- (void) viewDidAppear {
NSLog(@"[MainViewController] viewDidAppear");
return [super viewDidAppear];
}
- (void) viewWillDisappear {
NSLog(@"[MainViewController] viewWillDisappear");
return [super viewWillDisappear];
}
- (void) viewDidDisappear {
NSLog(@"[MainViewController] viewDidDisappear");
return [super viewDidDisappear];
}
- (void) viewWillLayout {
NSLog(@"[MainViewController] viewWillLayout");
return [super viewWillLayout];
}
- (void) viewDidLayout {
NSLog(@"[MainViewController] viewDidLayout");
return [super viewDidLayout];
}
@end

@ -0,0 +1,4 @@
#import <Cocoa/Cocoa.h>
@interface MainWindowController : NSWindowController
@end

@ -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

@ -5,23 +5,14 @@ id defaultAutoreleasePool;
id appDelegate; id appDelegate;
void Initialize(void) { void Initialize(void) {
NSLog(@"Initializing with processInfo: %@", [[NSProcessInfo processInfo] arguments]);
NSLog(@"Creating Autorelease Pool");
defaultAutoreleasePool = [NSAutoreleasePool new]; defaultAutoreleasePool = [NSAutoreleasePool new];
[NSApplication sharedApplication]; [NSApplication sharedApplication];
NSLog(@"Setting App Delegate");
[NSApp setDelegate: [[AppDelegate new] autorelease]]; [NSApp setDelegate: [[AppDelegate new] autorelease]];
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
NSLog(@"Initialization complete");
} }
int Run(void) { int Run(void) {
NSLog(@"Entered Run");
NSLog(@"Activating App");
NSLog(@"Running App Event Loop");
[NSApp run]; [NSApp run];
NSLog(@"App Event Loop finished. Draining pool.");
[defaultAutoreleasePool drain]; [defaultAutoreleasePool drain];
NSLog(@"Leaving Run");
return 0; return 0;
} }

Loading…
Cancel
Save