# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1298487075 0 # Node ID 80e253df49fd09d66777e6a5d6c67192c82a378d # Parent 36c6669422d28dd6f07ac723d884b102a1e3ff80 Implementing the menubar and hopefully popup menus. diff -r 36c6669422d2 -r 80e253df49fd mac/dw.m --- a/mac/dw.m Wed Feb 23 15:40:46 2011 +0000 +++ b/mac/dw.m Wed Feb 23 18:51:15 2011 +0000 @@ -116,6 +116,13 @@ return -1; } +NSApplication *DWApp; +NSRunLoop *DWRunLoop; +NSMenu *DWMainMenu; +#if !defined(GARBAGE_COLLECT) +NSAutoreleasePool *pool; +#endif + /* So basically to implement our event handlers... * it looks like we are going to have to subclass * basically everything. Was hoping to add methods @@ -160,8 +167,14 @@ @end /* Subclass for a top-level window */ -@interface DWView : DWBox { } +@interface DWView : DWBox +{ + NSMenu *windowmenu; +} -(BOOL)windowShouldClose:(id)sender; +-(void)setMenu:(NSMenu *)input; +-(void)windowDidBecomeMain:(id)sender; +-(void)menuHandler:(id)sender; @end @implementation DWView @@ -174,6 +187,7 @@ - (void)viewDidMoveToWindow { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowResized:) name:NSWindowDidResizeNotification object:[self window]]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeMain:) name:NSWindowDidBecomeMainNotification object:[self window]]; } - (void)dealloc { @@ -185,6 +199,22 @@ NSSize size = [self frame].size; _do_resize(&box, size.width, size.height); } +-(void)windowDidBecomeMain:(id)sender +{ + if(windowmenu) + { + NSLog(@"Setting local menu"); + [DWApp setMainMenu:windowmenu]; + } + else + { + NSLog(@"Setting global menu"); + [DWApp setMainMenu:DWMainMenu]; + } + +} +-(void)setMenu:(NSMenu *)input { windowmenu = input; NSLog(@"Setting window menu"); } +-(void)menuHandler:(id)sender { _event_handler(sender, nil, 8); } @end /* Subclass for a button type */ @@ -405,11 +435,19 @@ -(void)setUserdata:(void *)input { userdata = input; } @end -NSApplication *DWApp; -NSRunLoop *DWRunLoop; -#if !defined(GARBAGE_COLLECT) -NSAutoreleasePool *pool; -#endif +/* Subclass for a MLE type */ +@interface DWContainer : NSTableView +{ + void *userdata; +} +-(void *)userdata; +-(void)setUserdata:(void *)input; +@end + +@implementation DWContainer +-(void *)userdata { return userdata; } +-(void)setUserdata:(void *)input { userdata = input; } +@end typedef struct { @@ -949,22 +987,8 @@ } } -/* - * Initializes the Dynamic Windows engine. - * Parameters: - * newthread: True if this is the only thread. - * False if there is already a message loop running. - */ -int API dw_init(int newthread, int argc, char *argv[]) -{ - /* Create the application object */ - DWApp = [NSApplication sharedApplication]; - /* Create a run loop for doing manual loops */ - DWRunLoop = [NSRunLoop alloc]; -#if !defined(GARBAGE_COLLECT) - pool = [[NSAutoreleasePool alloc] init]; -#endif - +NSMenu *_generate_main_menu() +{ /* This only works on 10.6 so we have a backup method */ NSString * applicationName = [[NSRunningApplication currentApplication] localizedName]; if(applicationName == nil) @@ -977,15 +1001,13 @@ NSMenuItem * mitem = [mainMenu addItemWithTitle:@"Apple" action:NULL keyEquivalent:@""]; NSMenu * menu = [[[NSMenu alloc] initWithTitle:@"Apple"] autorelease]; - - [DWApp setMainMenu:mainMenu]; - + [DWApp performSelector:@selector(setAppleMenu:) withObject:menu]; /* Setup the Application menu */ NSMenuItem * item = [menu addItemWithTitle:[NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"About", nil), applicationName] - action:@selector(orderFrontStandardAboutPanel:) - keyEquivalent:@""]; + action:@selector(orderFrontStandardAboutPanel:) + keyEquivalent:@""]; [item setTarget:DWApp]; [menu addItem:[NSMenuItem separatorItem]]; @@ -1029,6 +1051,28 @@ [item setTarget:DWApp]; [mainMenu setSubmenu:menu forItem:mitem]; + + return mainMenu; +} + +/* + * Initializes the Dynamic Windows engine. + * Parameters: + * newthread: True if this is the only thread. + * False if there is already a message loop running. + */ +int API dw_init(int newthread, int argc, char *argv[]) +{ + /* Create the application object */ + DWApp = [NSApplication sharedApplication]; + /* Create a run loop for doing manual loops */ + DWRunLoop = [NSRunLoop alloc]; +#if !defined(GARBAGE_COLLECT) + pool = [[NSAutoreleasePool alloc] init]; +#endif + DWMainMenu = _generate_main_menu(); + [DWApp setMainMenu:DWMainMenu]; + return 0; } @@ -2501,8 +2545,16 @@ */ HWND API dw_container_new(ULONG id, int multi) { - NSLog(@"dw_container_new() unimplemented\n"); - return HWND_DESKTOP; + DWContainer *cont = [[DWContainer alloc] init]; + if(multi) + { + [cont setAllowsMultipleSelection:YES]; + } + else + { + [cont setAllowsMultipleSelection:NO]; + } + return cont; } /* @@ -2517,8 +2569,16 @@ */ int API dw_container_setup(HWND handle, unsigned long *flags, char **titles, int count, int separator) { - NSLog(@"dw_container_setup() unimplemented\n"); - return 0; + int z; + DWContainer *cont = handle; + + for(z=0;z