comparison mac/dw.m @ 736:5b48519a7fb2

Added retains to the window menus so they don't get autoreleased when switching between windows with menus. Added release to the dealloc method so they won't stick around forever.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 15 Mar 2011 19:48:20 +0000
parents b75be4860279
children 680c7f365d0d
comparison
equal deleted inserted replaced
735:b75be4860279 736:5b48519a7fb2
540 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowResized:) name:NSWindowDidResizeNotification object:[self window]]; 540 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowResized:) name:NSWindowDidResizeNotification object:[self window]];
541 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeMain:) name:NSWindowDidBecomeMainNotification object:[self window]]; 541 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeMain:) name:NSWindowDidBecomeMainNotification object:[self window]];
542 } 542 }
543 - (void)dealloc 543 - (void)dealloc
544 { 544 {
545 [[NSNotificationCenter defaultCenter] removeObserver:self]; 545 if(windowmenu)
546 [super dealloc]; 546 {
547 [windowmenu release];
548 }
549 [[NSNotificationCenter defaultCenter] removeObserver:self];
550 [super dealloc];
547 } 551 }
548 - (void)windowResized:(NSNotification *)notification; 552 - (void)windowResized:(NSNotification *)notification;
549 { 553 {
550 NSSize size = [self frame].size; 554 NSSize size = [self frame].size;
551 _do_resize(box, size.width, size.height); 555 _do_resize(box, size.width, size.height);
561 { 565 {
562 [DWApp setMainMenu:DWMainMenu]; 566 [DWApp setMainMenu:DWMainMenu];
563 } 567 }
564 _event_handler(self, nil, 13); 568 _event_handler(self, nil, 13);
565 } 569 }
566 -(void)setMenu:(NSMenu *)input { windowmenu = input; } 570 -(void)setMenu:(NSMenu *)input { windowmenu = input; [windowmenu retain]; }
567 -(void)menuHandler:(id)sender { _event_handler(sender, nil, 8); } 571 -(void)menuHandler:(id)sender { _event_handler(sender, nil, 8); }
568 -(void)keyDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 2); _event_handler([self window], theEvent, 2); } 572 -(void)keyDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 2); _event_handler([self window], theEvent, 2); }
569 @end 573 @end
570 574
571 /* Subclass for a button type */ 575 /* Subclass for a button type */
7451 * newthread: True if this is the only thread. 7455 * newthread: True if this is the only thread.
7452 * False if there is already a message loop running. 7456 * False if there is already a message loop running.
7453 */ 7457 */
7454 int API dw_init(int newthread, int argc, char *argv[]) 7458 int API dw_init(int newthread, int argc, char *argv[])
7455 { 7459 {
7456 /* Create the application object */ 7460 /* Create the application object */
7457 DWApp = [NSApplication sharedApplication]; 7461 DWApp = [NSApplication sharedApplication];
7458 /* Create object for handling timers */ 7462 /* Create object for handling timers */
7459 DWHandler = [[DWTimerHandler alloc] init]; 7463 DWHandler = [[DWTimerHandler alloc] init];
7460 /* If we aren't using garbage collection we need autorelease pools */ 7464 /* If we aren't using garbage collection we need autorelease pools */
7461 #if !defined(GARBAGE_COLLECT) 7465 #if !defined(GARBAGE_COLLECT)
7462 pthread_key_create(&_dw_pool_key, NULL); 7466 pthread_key_create(&_dw_pool_key, NULL);
7463 pool = [[NSAutoreleasePool alloc] init]; 7467 pool = [[NSAutoreleasePool alloc] init];
7464 pthread_setspecific(_dw_pool_key, pool); 7468 pthread_setspecific(_dw_pool_key, pool);
7465 #endif 7469 #endif
7466 /* Create a default main menu, with just the application menu */ 7470 /* Create a default main menu, with just the application menu */
7467 DWMainMenu = _generate_main_menu(); 7471 DWMainMenu = _generate_main_menu();
7468 [DWApp setMainMenu:DWMainMenu]; 7472 [DWMainMenu retain];
7469 DWObj = [[DWObject alloc] init]; 7473 [DWApp setMainMenu:DWMainMenu];
7474 DWObj = [[DWObject alloc] init];
7470 /* Create mutexes for thread safety */ 7475 /* Create mutexes for thread safety */
7471 DWRunMutex = dw_mutex_new(); 7476 DWRunMutex = dw_mutex_new();
7472 DWThreadMutex = dw_mutex_new(); 7477 DWThreadMutex = dw_mutex_new();
7473 DWThreadMutex2 = dw_mutex_new(); 7478 DWThreadMutex2 = dw_mutex_new();
7474 /* Use NSThread to start a dummy thread to initialize the threading subsystem */ 7479 /* Use NSThread to start a dummy thread to initialize the threading subsystem */
7475 NSThread *thread = [[ NSThread alloc] initWithTarget:DWObj selector:@selector(uselessThread:) object:nil]; 7480 NSThread *thread = [[ NSThread alloc] initWithTarget:DWObj selector:@selector(uselessThread:) object:nil];
7476 [thread start]; 7481 [thread start];
7477 [thread release]; 7482 [thread release];
7478 return 0; 7483 return 0;
7479 } 7484 }
7480 7485
7481 /* 7486 /*
7482 * Allocates a shared memory region with a name. 7487 * Allocates a shared memory region with a name.
7483 * Parameters: 7488 * Parameters: