create a window

master
Jordan Orelli 8 years ago
parent 4cdfa60f8e
commit 3dff82bbad

@ -1,5 +1,4 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject <NSApplicationDelegate> @interface AppDelegate : NSObject <NSApplicationDelegate>
- (void) createMenuBar;
@end @end

@ -12,6 +12,8 @@
- (void) applicationDidFinishLaunching:(NSNotification *)notification { - (void) applicationDidFinishLaunching:(NSNotification *)notification {
NSLog(@"applicationDidFinishLaunching notification: %@", notification); NSLog(@"applicationDidFinishLaunching notification: %@", notification);
NSLog(@"Main Menu in applicationDidFinishLaunching: %@", [NSApp mainMenu]); NSLog(@"Main Menu in applicationDidFinishLaunching: %@", [NSApp mainMenu]);
[self createMenubar];
[self createMainWindow];
[NSApp activateIgnoringOtherApps:YES]; [NSApp activateIgnoringOtherApps:YES];
} }
@ -84,28 +86,48 @@
// --------------------------------------------------------------------------}}} // --------------------------------------------------------------------------}}}
// Menu Bar -----------------------------------------------------------------{{{ // Menu Bar -----------------------------------------------------------------{{{
- (void) createMenuBar { - (void) createMenubar {
NSLog(@"Will create menu bar here"); NSLog(@"Will create menu bar here");
NSLog(@"creating menu bar. initial main menu bar: %@", [NSApp mainMenu]); NSLog(@"creating menu bar. initial main menu bar: %@", [NSApp mainMenu]);
id mainMenu = [NSMenu alloc]; id mainMenu = [[NSMenu alloc] autorelease];
[mainMenu initWithTitle:@"Main Menu"]; [mainMenu initWithTitle:@"Main Menu"];
[NSApp setMainMenu:mainMenu]; [NSApp setMainMenu:mainMenu];
id appMenuItem = [NSMenuItem alloc]; id appMenuItem = [[NSMenuItem alloc] autorelease];
[appMenuItem initWithTitle:@"dws" action:NULL keyEquivalent:@""]; [appMenuItem initWithTitle:@"dws" action:NULL keyEquivalent:@""];
[mainMenu addItem:appMenuItem]; [mainMenu addItem:appMenuItem];
id appMenu = [NSMenu alloc]; id appMenu = [[NSMenu alloc] autorelease];
[appMenu initWithTitle:@"dws"]; [appMenu initWithTitle:@"dws"];
[appMenuItem setSubmenu:appMenu]; [appMenuItem setSubmenu:appMenu];
id quitMenuItem = [NSMenuItem alloc]; 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]); 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];
}
// --------------------------------------------------------------------------}}}
@end @end

@ -10,14 +10,11 @@ void Initialize(void) {
defaultAutoreleasePool = [NSAutoreleasePool new]; defaultAutoreleasePool = [NSAutoreleasePool new];
[NSApplication sharedApplication]; [NSApplication sharedApplication];
NSLog(@"Setting App Delegate"); NSLog(@"Setting App Delegate");
appDelegate = [AppDelegate new]; [NSApp setDelegate: [[AppDelegate new] autorelease]];
[appDelegate createMenuBar];
[NSApp setDelegate: appDelegate];
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
NSLog(@"Initialization complete"); NSLog(@"Initialization complete");
} }
int Run(void) { int Run(void) {
NSLog(@"Entered Run"); NSLog(@"Entered Run");
NSLog(@"Activating App"); NSLog(@"Activating App");

Loading…
Cancel
Save