# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1303888992 0 # Node ID 83aceaaef6ed396b7f246e4b49a77d7eba2d6450 # Parent 4be0c9f963f8d0d1c54af514f2bc18bc9e3b7ed4 Added initial support for allowing dW_window_destroy() to remove an item from its containing box on Mac. Getting some crashes when using this in connection with dw_notebook_page_destroy() in HandyFTP... but I need to switch computers so committing it as is. diff -r 4be0c9f963f8 -r 83aceaaef6ed mac/dw.m --- a/mac/dw.m Tue Apr 26 13:44:45 2011 +0000 +++ b/mac/dw.m Wed Apr 27 07:23:12 2011 +0000 @@ -6551,7 +6551,7 @@ DWNotebook *notebook = handle; NSInteger page = [notebook pageid]; DWNotebookPage *notepage = [[DWNotebookPage alloc] initWithIdentifier:nil]; - [notepage setPageid:(NSInteger)page]; + [notepage setPageid:(int)page]; if(front) { [notebook insertTabViewItem:notepage atIndex:(NSInteger)0]; @@ -6560,7 +6560,7 @@ { [notebook addTabViewItem:notepage]; } - [notebook setPageid:(page+1)]; + [notebook setPageid:(int)(page+1)]; [notepage release]; return (unsigned long)page; } @@ -6578,6 +6578,17 @@ if(notepage != nil) { + DWBox *page = [notepage view]; + Box *thisbox = [page box]; + if(thisbox) + { + id object = thisbox->items[0].hwnd; + [object removeFromSuperview]; + [object retain]; + free(thisbox->items); + thisbox->count = 0; + thisbox->items = NULL; + } [notebook removeTabViewItem:notepage]; [notepage release]; } @@ -7147,13 +7158,59 @@ { int _locked_by_me = FALSE; DW_MUTEX_LOCK; - NSObject *object = handle; - + id object = handle; + + /* Handle destroying a top-levle window */ if([ object isKindOfClass:[ NSWindow class ] ]) { NSWindow *window = handle; [window close]; } + /* Handle destroying a control or box */ + else if([object isKindOfClass:[DWBox class]] || [object isKindOfClass:[NSControl class]]) + { + DWBox *parent = (DWBox *)[object superview]; + + if([parent isKindOfClass:[DWBox class]]) + { + Box *thisbox = [parent box]; + int z, index = -1; + Item *tmpitem, *thisitem = thisbox->items; + + [object removeFromSuperview]; + /* Do we need to release? + * [object release]; + */ + + for(z=0;zcount;z++) + { + if(thisitem[z].hwnd == handle) + index = z; + } + + if(index == -1) + { + DW_MUTEX_UNLOCK; + return 0; + } + + tmpitem = malloc(sizeof(Item)*(thisbox->count-1)); + + /* Copy all but the current entry to the new list */ + for(z=0;zcount;z++) + { + tmpitem[z-1] = thisitem[z]; + } + + thisbox->items = tmpitem; + free(thisitem); + thisbox->count--; + } + } DW_MUTEX_UNLOCK; return 0; }