# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1376006018 0 # Node ID 71c8a45b2a35a6f95c6c8bc41acbc78311347dbf # Parent 15d24b5300ecdb5dd5d9c95635b1b70a4a571659 Fixes for Mac code and allocate and free duplicates of title strings. diff -r 15d24b5300ec -r 71c8a45b2a35 mac/dw.m --- a/mac/dw.m Thu Aug 08 20:28:57 2013 +0000 +++ b/mac/dw.m Thu Aug 08 23:53:38 2013 +0000 @@ -399,7 +399,7 @@ case 12: { int (* API treeselectfunc)(HWND, HTREEITEM, char *, void *, void *) = (int (* API)(HWND, HTREEITEM, char *, void *, void *))handler->signalfunction; - char *text = (char *)event; + char *text = NULL; void *user = NULL; id item = nil; @@ -412,10 +412,6 @@ { text = strdup([nstr UTF8String]); } - else - { - text = NULL; - } NSValue *value = [item objectAtIndex:2]; if(value && [value isKindOfClass:[NSValue class]]) @@ -429,6 +425,13 @@ } return result; } + else if(event) + { + void **params = (void **)event; + + text = params[0]; + user = params[1]; + } return treeselectfunc(handler->window, item, text, handler->data, user); } @@ -1983,6 +1986,7 @@ { int z, start, end; int count = (int)[tvcols count]; + void *oldtitle; start = (count * row); end = start + count; @@ -1991,15 +1995,28 @@ { [data removeObjectAtIndex:start]; } + oldtitle = [titles pointerAtIndex:row]; [titles removePointerAtIndex:row]; [rowdatas removePointerAtIndex:row]; if(lastAddPoint > 0 && lastAddPoint > row) { lastAddPoint--; } - } -} --(void)setRow:(int)row title:(void *)input { if(titles && input) { [titles replacePointerAtIndex:row withPointer:input]; } } + if(oldtitle) + free(oldtitle); + } +} +-(void)setRow:(int)row title:(void *)input +{ + if(titles && input) + { + void *oldtitle = [titles pointerAtIndex:row]; + void *newtitle = input ? (void *)strdup((char *)input) : NULL; + [titles replacePointerAtIndex:row withPointer:newtitle]; + if(oldtitle) + free(oldtitle); + } +} -(void)setRowData:(int)row title:(void *)input { if(rowdatas && input) { [rowdatas replacePointerAtIndex:row withPointer:input]; } } -(void *)getRowTitle:(int)row { if(titles && row > -1) { return [titles pointerAtIndex:row]; } return NULL; } -(void *)getRowData:(int)row { if(rowdatas && row > -1) { return [rowdatas pointerAtIndex:row]; } return NULL; } @@ -2008,7 +2025,22 @@ -(int)lastAddPoint { return lastAddPoint; } -(int)lastQueryPoint { return lastQueryPoint; } -(void)setLastQueryPoint:(int)input { lastQueryPoint = input; } --(void)clear { if(data) { [data removeAllObjects]; while([titles count]) { [titles removePointerAtIndex:0]; } } lastAddPoint = 0; } +-(void)clear +{ + if(data) + { + [data removeAllObjects]; + while([titles count]) + { + void *oldtitle = [titles pointerAtIndex:0]; + [titles removePointerAtIndex:0]; + [rowdatas removePointerAtIndex:0]; + if(oldtitle) + free(oldtitle); + } + } + lastAddPoint = 0; +} -(void)setup { SEL swopa = NSSelectorFromString(@"pointerArrayWithWeakObjects"); @@ -2194,8 +2226,13 @@ } -(void)selectionChanged:(id)sender { + void *params[2]; + + params[0] = (void *)[self getRowTitle:(int)[self selectedRow]]; + params[1] = (void *)[self getRowData:(int)[self selectedRow]]; + /* Handler for container class */ - _event_handler(self, (NSEvent *)[self getRowTitle:(int)[self selectedRow]], 12); + _event_handler(self, (NSEvent *)params, 12); /* Handler for listbox class */ _event_handler(self, DW_INT_TO_POINTER((int)[self selectedRow]), 11); }