Mercurial > dwindows
comparison mac/dw.m @ 1874:71c8a45b2a35
Fixes for Mac code and allocate and free duplicates of title strings.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 08 Aug 2013 23:53:38 +0000 |
parents | 3f571ad9b92e |
children | 0768bbcf67e5 |
comparison
equal
deleted
inserted
replaced
1873:15d24b5300ec | 1874:71c8a45b2a35 |
---|---|
397 } | 397 } |
398 /* Tree class selection event */ | 398 /* Tree class selection event */ |
399 case 12: | 399 case 12: |
400 { | 400 { |
401 int (* API treeselectfunc)(HWND, HTREEITEM, char *, void *, void *) = (int (* API)(HWND, HTREEITEM, char *, void *, void *))handler->signalfunction; | 401 int (* API treeselectfunc)(HWND, HTREEITEM, char *, void *, void *) = (int (* API)(HWND, HTREEITEM, char *, void *, void *))handler->signalfunction; |
402 char *text = (char *)event; | 402 char *text = NULL; |
403 void *user = NULL; | 403 void *user = NULL; |
404 id item = nil; | 404 id item = nil; |
405 | 405 |
406 if([object isKindOfClass:[NSOutlineView class]]) | 406 if([object isKindOfClass:[NSOutlineView class]]) |
407 { | 407 { |
409 NSString *nstr = [item objectAtIndex:1]; | 409 NSString *nstr = [item objectAtIndex:1]; |
410 | 410 |
411 if(nstr) | 411 if(nstr) |
412 { | 412 { |
413 text = strdup([nstr UTF8String]); | 413 text = strdup([nstr UTF8String]); |
414 } | |
415 else | |
416 { | |
417 text = NULL; | |
418 } | 414 } |
419 | 415 |
420 NSValue *value = [item objectAtIndex:2]; | 416 NSValue *value = [item objectAtIndex:2]; |
421 if(value && [value isKindOfClass:[NSValue class]]) | 417 if(value && [value isKindOfClass:[NSValue class]]) |
422 { | 418 { |
426 if(text) | 422 if(text) |
427 { | 423 { |
428 free(text); | 424 free(text); |
429 } | 425 } |
430 return result; | 426 return result; |
427 } | |
428 else if(event) | |
429 { | |
430 void **params = (void **)event; | |
431 | |
432 text = params[0]; | |
433 user = params[1]; | |
431 } | 434 } |
432 | 435 |
433 return treeselectfunc(handler->window, item, text, handler->data, user); | 436 return treeselectfunc(handler->window, item, text, handler->data, user); |
434 } | 437 } |
435 /* Set Focus event */ | 438 /* Set Focus event */ |
1981 { | 1984 { |
1982 if(tvcols) | 1985 if(tvcols) |
1983 { | 1986 { |
1984 int z, start, end; | 1987 int z, start, end; |
1985 int count = (int)[tvcols count]; | 1988 int count = (int)[tvcols count]; |
1989 void *oldtitle; | |
1986 | 1990 |
1987 start = (count * row); | 1991 start = (count * row); |
1988 end = start + count; | 1992 end = start + count; |
1989 | 1993 |
1990 for(z=start;z<end;z++) | 1994 for(z=start;z<end;z++) |
1991 { | 1995 { |
1992 [data removeObjectAtIndex:start]; | 1996 [data removeObjectAtIndex:start]; |
1993 } | 1997 } |
1998 oldtitle = [titles pointerAtIndex:row]; | |
1994 [titles removePointerAtIndex:row]; | 1999 [titles removePointerAtIndex:row]; |
1995 [rowdatas removePointerAtIndex:row]; | 2000 [rowdatas removePointerAtIndex:row]; |
1996 if(lastAddPoint > 0 && lastAddPoint > row) | 2001 if(lastAddPoint > 0 && lastAddPoint > row) |
1997 { | 2002 { |
1998 lastAddPoint--; | 2003 lastAddPoint--; |
1999 } | 2004 } |
2000 } | 2005 if(oldtitle) |
2001 } | 2006 free(oldtitle); |
2002 -(void)setRow:(int)row title:(void *)input { if(titles && input) { [titles replacePointerAtIndex:row withPointer:input]; } } | 2007 } |
2008 } | |
2009 -(void)setRow:(int)row title:(void *)input | |
2010 { | |
2011 if(titles && input) | |
2012 { | |
2013 void *oldtitle = [titles pointerAtIndex:row]; | |
2014 void *newtitle = input ? (void *)strdup((char *)input) : NULL; | |
2015 [titles replacePointerAtIndex:row withPointer:newtitle]; | |
2016 if(oldtitle) | |
2017 free(oldtitle); | |
2018 } | |
2019 } | |
2003 -(void)setRowData:(int)row title:(void *)input { if(rowdatas && input) { [rowdatas replacePointerAtIndex:row withPointer:input]; } } | 2020 -(void)setRowData:(int)row title:(void *)input { if(rowdatas && input) { [rowdatas replacePointerAtIndex:row withPointer:input]; } } |
2004 -(void *)getRowTitle:(int)row { if(titles && row > -1) { return [titles pointerAtIndex:row]; } return NULL; } | 2021 -(void *)getRowTitle:(int)row { if(titles && row > -1) { return [titles pointerAtIndex:row]; } return NULL; } |
2005 -(void *)getRowData:(int)row { if(rowdatas && row > -1) { return [rowdatas pointerAtIndex:row]; } return NULL; } | 2022 -(void *)getRowData:(int)row { if(rowdatas && row > -1) { return [rowdatas pointerAtIndex:row]; } return NULL; } |
2006 -(id)getRow:(int)row and:(int)col { if(data) { int index = (int)(row * [tvcols count]) + col; return [data objectAtIndex:index]; } return nil; } | 2023 -(id)getRow:(int)row and:(int)col { if(data) { int index = (int)(row * [tvcols count]) + col; return [data objectAtIndex:index]; } return nil; } |
2007 -(int)cellType:(int)col { return [[types objectAtIndex:col] intValue]; } | 2024 -(int)cellType:(int)col { return [[types objectAtIndex:col] intValue]; } |
2008 -(int)lastAddPoint { return lastAddPoint; } | 2025 -(int)lastAddPoint { return lastAddPoint; } |
2009 -(int)lastQueryPoint { return lastQueryPoint; } | 2026 -(int)lastQueryPoint { return lastQueryPoint; } |
2010 -(void)setLastQueryPoint:(int)input { lastQueryPoint = input; } | 2027 -(void)setLastQueryPoint:(int)input { lastQueryPoint = input; } |
2011 -(void)clear { if(data) { [data removeAllObjects]; while([titles count]) { [titles removePointerAtIndex:0]; } } lastAddPoint = 0; } | 2028 -(void)clear |
2029 { | |
2030 if(data) | |
2031 { | |
2032 [data removeAllObjects]; | |
2033 while([titles count]) | |
2034 { | |
2035 void *oldtitle = [titles pointerAtIndex:0]; | |
2036 [titles removePointerAtIndex:0]; | |
2037 [rowdatas removePointerAtIndex:0]; | |
2038 if(oldtitle) | |
2039 free(oldtitle); | |
2040 } | |
2041 } | |
2042 lastAddPoint = 0; | |
2043 } | |
2012 -(void)setup | 2044 -(void)setup |
2013 { | 2045 { |
2014 SEL swopa = NSSelectorFromString(@"pointerArrayWithWeakObjects"); | 2046 SEL swopa = NSSelectorFromString(@"pointerArrayWithWeakObjects"); |
2015 | 2047 |
2016 if(![[NSPointerArray class] respondsToSelector:swopa]) | 2048 if(![[NSPointerArray class] respondsToSelector:swopa]) |
2192 /* Handler for column click class */ | 2224 /* Handler for column click class */ |
2193 _event_handler(self, (NSEvent *)index, 17); | 2225 _event_handler(self, (NSEvent *)index, 17); |
2194 } | 2226 } |
2195 -(void)selectionChanged:(id)sender | 2227 -(void)selectionChanged:(id)sender |
2196 { | 2228 { |
2229 void *params[2]; | |
2230 | |
2231 params[0] = (void *)[self getRowTitle:(int)[self selectedRow]]; | |
2232 params[1] = (void *)[self getRowData:(int)[self selectedRow]]; | |
2233 | |
2197 /* Handler for container class */ | 2234 /* Handler for container class */ |
2198 _event_handler(self, (NSEvent *)[self getRowTitle:(int)[self selectedRow]], 12); | 2235 _event_handler(self, (NSEvent *)params, 12); |
2199 /* Handler for listbox class */ | 2236 /* Handler for listbox class */ |
2200 _event_handler(self, DW_INT_TO_POINTER((int)[self selectedRow]), 11); | 2237 _event_handler(self, DW_INT_TO_POINTER((int)[self selectedRow]), 11); |
2201 } | 2238 } |
2202 -(NSMenu *)menuForEvent:(NSEvent *)event | 2239 -(NSMenu *)menuForEvent:(NSEvent *)event |
2203 { | 2240 { |