Mercurial > dwindows
comparison mac/dw.m @ 937:83aceaaef6ed
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.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 27 Apr 2011 07:23:12 +0000 |
parents | 4be0c9f963f8 |
children | cfcf66a90e8c |
comparison
equal
deleted
inserted
replaced
936:4be0c9f963f8 | 937:83aceaaef6ed |
---|---|
6549 unsigned long API dw_notebook_page_new(HWND handle, ULONG flags, int front) | 6549 unsigned long API dw_notebook_page_new(HWND handle, ULONG flags, int front) |
6550 { | 6550 { |
6551 DWNotebook *notebook = handle; | 6551 DWNotebook *notebook = handle; |
6552 NSInteger page = [notebook pageid]; | 6552 NSInteger page = [notebook pageid]; |
6553 DWNotebookPage *notepage = [[DWNotebookPage alloc] initWithIdentifier:nil]; | 6553 DWNotebookPage *notepage = [[DWNotebookPage alloc] initWithIdentifier:nil]; |
6554 [notepage setPageid:(NSInteger)page]; | 6554 [notepage setPageid:(int)page]; |
6555 if(front) | 6555 if(front) |
6556 { | 6556 { |
6557 [notebook insertTabViewItem:notepage atIndex:(NSInteger)0]; | 6557 [notebook insertTabViewItem:notepage atIndex:(NSInteger)0]; |
6558 } | 6558 } |
6559 else | 6559 else |
6560 { | 6560 { |
6561 [notebook addTabViewItem:notepage]; | 6561 [notebook addTabViewItem:notepage]; |
6562 } | 6562 } |
6563 [notebook setPageid:(page+1)]; | 6563 [notebook setPageid:(int)(page+1)]; |
6564 [notepage release]; | 6564 [notepage release]; |
6565 return (unsigned long)page; | 6565 return (unsigned long)page; |
6566 } | 6566 } |
6567 | 6567 |
6568 /* | 6568 /* |
6576 DWNotebook *notebook = handle; | 6576 DWNotebook *notebook = handle; |
6577 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); | 6577 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); |
6578 | 6578 |
6579 if(notepage != nil) | 6579 if(notepage != nil) |
6580 { | 6580 { |
6581 DWBox *page = [notepage view]; | |
6582 Box *thisbox = [page box]; | |
6583 if(thisbox) | |
6584 { | |
6585 id object = thisbox->items[0].hwnd; | |
6586 [object removeFromSuperview]; | |
6587 [object retain]; | |
6588 free(thisbox->items); | |
6589 thisbox->count = 0; | |
6590 thisbox->items = NULL; | |
6591 } | |
6581 [notebook removeTabViewItem:notepage]; | 6592 [notebook removeTabViewItem:notepage]; |
6582 [notepage release]; | 6593 [notepage release]; |
6583 } | 6594 } |
6584 } | 6595 } |
6585 | 6596 |
7145 */ | 7156 */ |
7146 int API dw_window_destroy(HWND handle) | 7157 int API dw_window_destroy(HWND handle) |
7147 { | 7158 { |
7148 int _locked_by_me = FALSE; | 7159 int _locked_by_me = FALSE; |
7149 DW_MUTEX_LOCK; | 7160 DW_MUTEX_LOCK; |
7150 NSObject *object = handle; | 7161 id object = handle; |
7151 | 7162 |
7163 /* Handle destroying a top-levle window */ | |
7152 if([ object isKindOfClass:[ NSWindow class ] ]) | 7164 if([ object isKindOfClass:[ NSWindow class ] ]) |
7153 { | 7165 { |
7154 NSWindow *window = handle; | 7166 NSWindow *window = handle; |
7155 [window close]; | 7167 [window close]; |
7168 } | |
7169 /* Handle destroying a control or box */ | |
7170 else if([object isKindOfClass:[DWBox class]] || [object isKindOfClass:[NSControl class]]) | |
7171 { | |
7172 DWBox *parent = (DWBox *)[object superview]; | |
7173 | |
7174 if([parent isKindOfClass:[DWBox class]]) | |
7175 { | |
7176 Box *thisbox = [parent box]; | |
7177 int z, index = -1; | |
7178 Item *tmpitem, *thisitem = thisbox->items; | |
7179 | |
7180 [object removeFromSuperview]; | |
7181 /* Do we need to release? | |
7182 * [object release]; | |
7183 */ | |
7184 | |
7185 for(z=0;z<thisbox->count;z++) | |
7186 { | |
7187 if(thisitem[z].hwnd == handle) | |
7188 index = z; | |
7189 } | |
7190 | |
7191 if(index == -1) | |
7192 { | |
7193 DW_MUTEX_UNLOCK; | |
7194 return 0; | |
7195 } | |
7196 | |
7197 tmpitem = malloc(sizeof(Item)*(thisbox->count-1)); | |
7198 | |
7199 /* Copy all but the current entry to the new list */ | |
7200 for(z=0;z<index;z++) | |
7201 { | |
7202 tmpitem[z] = thisitem[z]; | |
7203 } | |
7204 for(z=index+1;z<thisbox->count;z++) | |
7205 { | |
7206 tmpitem[z-1] = thisitem[z]; | |
7207 } | |
7208 | |
7209 thisbox->items = tmpitem; | |
7210 free(thisitem); | |
7211 thisbox->count--; | |
7212 } | |
7156 } | 7213 } |
7157 DW_MUTEX_UNLOCK; | 7214 DW_MUTEX_UNLOCK; |
7158 return 0; | 7215 return 0; |
7159 } | 7216 } |
7160 | 7217 |