# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1335477438 0 # Node ID d5f39d32c4da1ae7ef751fc59f9031e359fff649 # Parent 86d7bce8f4c605a63ab6be86d46bb2b56a805d86 Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac. diff -r 86d7bce8f4c6 -r d5f39d32c4da mac/dw.m --- a/mac/dw.m Thu Apr 26 21:32:40 2012 +0000 +++ b/mac/dw.m Thu Apr 26 21:57:18 2012 +0000 @@ -3902,6 +3902,136 @@ } /* + * Remove windows (widgets) from the box they are packed into. + * Parameters: + * handle: Window handle of the item to be back. + * Returns: + * DW_ERROR_NONE on success and DW_ERROR_GENERAL on failure. + */ +int API dw_box_remove(HWND handle) +{ + int _locked_by_me = FALSE; + DW_LOCAL_POOL_IN; + DW_MUTEX_LOCK; + id object = handle; + + if([object isKindOfClass:[NSView class]] || [object isKindOfClass:[NSControl class]]) + { + DWBox *parent = (DWBox *)[object superview]; + + /* Some controls are embedded in scrollviews... + * so get the parent of the scrollview in that case. + */ + if(([object isKindOfClass:[NSTableView class]] || [object isMemberOfClass:[DWMLE class]]) + && [parent isMemberOfClass:[NSClipView class]]) + { + object = [parent superview]; + parent = (DWBox *)[object superview]; + } + + if([parent isKindOfClass:[DWBox class]] || [parent isKindOfClass:[DWGroupBox class]]) + { + id window = [object window]; + Box *thisbox = [parent box]; + int z, index = -1; + Item *tmpitem, *thisitem = thisbox->items; + + for(z=0;zcount;z++) + { + if(thisitem[z].hwnd == object) + index = z; + } + + if(index == -1) + { + DW_MUTEX_UNLOCK; + DW_LOCAL_POOL_OUT; + return DW_ERROR_GENERAL; + } + + [object retain]; + [object removeFromSuperview]; + + 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--; + /* Queue a redraw on the top-level window */ + _dw_redraw(window, TRUE); + } + } + DW_MUTEX_UNLOCK; + DW_LOCAL_POOL_OUT; + return DW_ERROR_NONE; +} + +/* + * Remove windows (widgets) from a box at an arbitrary location. + * Parameters: + * box: Window handle of the box to be removed from. + * index: 0 based index of packed items. + * Returns: + * Handle to the removed item on success, 0 on failure. + */ +HWND API dw_box_remove_at_index(HWND box, int index) +{ + int _locked_by_me = FALSE; + DW_LOCAL_POOL_IN; + DW_MUTEX_LOCK; + DWBox *parent = (DWBox *)box; + id object = nil; + + if([parent isKindOfClass:[DWBox class]] || [parent isKindOfClass:[DWGroupBox class]]) + { + id window = [parent window]; + Box *thisbox = [parent box]; + + if(thisbox && index > -1 && index < thisbox->count) + { + int z; + Item *tmpitem, *thisitem = thisbox->items; + + object = thisitem[index].hwnd; + + [object retain]; + [object removeFromSuperview]; + + 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--; + /* Queue a redraw on the top-level window */ + _dw_redraw(window, TRUE); + } + } + DW_MUTEX_UNLOCK; + DW_LOCAL_POOL_OUT; + return 0; +} + +/* * Pack windows (widgets) into a box at an arbitrary location. * Parameters: * box: Window handle of the box to be packed into. @@ -8493,10 +8623,10 @@ if([parent isKindOfClass:[DWBox class]] || [parent isKindOfClass:[DWGroupBox class]]) { + id window = [object window]; Box *thisbox = [parent box]; int z, index = -1; Item *tmpitem, *thisitem = thisbox->items; - id window = [object window]; for(z=0;zcount;z++) {