# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1298736424 0 # Node ID e426de6e6c7ca459606d51e38244903af4ed5648 # Parent e6bec2290f3fde05a478f50cda9e437ab946e252 Changes to make the resize function more like on the other platforms. diff -r e6bec2290f3f -r e426de6e6c7c mac/dw.m --- a/mac/dw.m Sat Feb 26 03:17:12 2011 +0000 +++ b/mac/dw.m Sat Feb 26 16:07:04 2011 +0000 @@ -120,7 +120,7 @@ case 4: { int (* API buttonfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction; - int flags = [object pressedMouseButtons]; + int flags = (int)[object pressedMouseButtons]; NSPoint point = [object mouseLocation]; int button = 0; char *which = "pressed"; @@ -224,13 +224,14 @@ /* Subclass for a box type */ @interface DWBox : NSView { - Box box; + Box *box; void *userdata; NSColor *bgcolor; } --(Box)box; +- (id)init; +-(void) dealloc; +-(Box *)box; -(void *)userdata; --(void)setBox:(Box)input; -(void)setUserdata:(void *)input; -(void)drawRect:(NSRect)rect; -(BOOL)isFlipped; @@ -240,9 +241,23 @@ @end @implementation DWBox --(Box)box { return box; } +- (id)init +{ + self = [super init]; + + if (self) + { + box = calloc(1, sizeof(Box)); + } + return self; +} +-(void) dealloc +{ + free(box); + [super dealloc]; +} +-(Box *)box { return box; } -(void *)userdata { return userdata; } --(void)setBox:(Box)input { box = input; } -(void)setUserdata:(void *)input { userdata = input; } -(void)drawRect:(NSRect)rect { @@ -299,7 +314,7 @@ - (void)windowResized:(NSNotification *)notification; { NSSize size = [self frame].size; - _do_resize(&box, size.width, size.height); + _do_resize(box, size.width, size.height); _event_handler([self window], nil, 1); } -(void)windowDidBecomeMain:(id)sender @@ -401,9 +416,9 @@ if([object isMemberOfClass:[DWBox class]]) { DWBox *view = object; - Box box = [view box]; + Box *box = [view box]; NSSize size = [view frame].size; - _do_resize(&box, size.width, size.height); + _do_resize(box, size.width, size.height); } } @end @@ -460,9 +475,9 @@ if([object isMemberOfClass:[DWBox class]]) { DWBox *view = object; - Box box = [view box]; + Box *box = [view box]; NSSize size = [view frame].size; - _do_resize(&box, size.width, size.height); + _do_resize(box, size.width, size.height); } } } @@ -837,8 +852,7 @@ { int size = 0, origsize = 0, z; DWBox *box = thisbox; - Box _tmp = [box box]; - Box *tmp = &_tmp; + Box *tmp = [box box]; if(!tmp) { @@ -916,8 +930,7 @@ { int initialx, initialy; DWBox *box = thisbox->items[z].hwnd; - Box _tmp = [box box]; - Box *tmp = &_tmp; + Box *tmp = [box box]; initialx = x - (*usedx); initialy = y - (*usedy); @@ -979,7 +992,6 @@ nux = *usedx; nuy = *usedy; upx = *usedpadx + (tmp->pad*2); upy = *usedpady + (tmp->pad*2); } - [box setBox:_tmp]; (*depth)++; @@ -992,7 +1004,6 @@ tmp->minwidth = thisbox->items[z].width = initialx - newx; tmp->minheight = thisbox->items[z].height = initialy - newy; - [box setBox:_tmp]; } } @@ -1031,15 +1042,13 @@ if(thisbox->items[z].type == TYPEBOX) { DWBox *box = thisbox->items[z].hwnd; - Box _tmp = [box box]; - Box *tmp = &_tmp; + Box *tmp = [box box]; if(tmp) { tmp->parentxratio = thisbox->items[z].xratio; tmp->parentyratio = thisbox->items[z].yratio; } - [box setBox:_tmp]; } } else @@ -1134,8 +1143,7 @@ if(thisbox->items[z].type == TYPEBOX) { DWBox *box = thisbox->items[z].hwnd; - Box _tmp = [box box]; - Box *tmp = &_tmp; + Box *tmp = [box box]; if(tmp) { @@ -1162,14 +1170,12 @@ tmp->height = thisbox->items[z].height; } } - [box setBox:_tmp]; (*depth)++; _resize_box(tmp, depth, x, y, &nux, &nuy, 3, &nupx, &nupy); (*depth)--; - [box setBox:_tmp]; } } @@ -1220,10 +1226,9 @@ if(view != nil) { - Box box = [view box]; + Box *box = [view box]; NSSize size = [view frame].size; - _do_resize(&box, size.width, size.height); - [view setBox:box]; + _do_resize(box, size.width, size.height); } } else if([handle isMemberOfClass:[DWRender class]]) @@ -1277,10 +1282,8 @@ if(thisbox->items[z].type == TYPEBOX) { DWBox *box = thisbox->items[z].hwnd; - Box _tmp = [box box]; - Box *tmp = &_tmp; + Box *tmp = [box box]; _changebox(tmp, percent, type); - [box setBox:_tmp]; } else { @@ -1695,11 +1698,10 @@ HWND API dw_box_new(int type, int pad) { DWBox *view = [[DWBox alloc] init]; - Box newbox; - memset(&newbox, 0, sizeof(Box)); - newbox.pad = pad; - newbox.type = type; - [view setBox:newbox]; + Box *newbox = [view box]; + memset(newbox, 0, sizeof(Box)); + newbox->pad = pad; + newbox->type = type; return view; } @@ -1733,7 +1735,7 @@ NSObject *object = box; DWBox *view = box; DWBox *this = item; - Box thisbox; + Box *thisbox; int z; Item *tmpitem, *thisitem; @@ -1745,13 +1747,13 @@ } thisbox = [view box]; - thisitem = thisbox.items; + thisitem = thisbox->items; object = item; /* Duplicate the existing data */ - tmpitem = malloc(sizeof(Item)*(thisbox.count+1)); - - for(z=0;zcount+1)); + + for(z=0;zcount;z++) { tmpitem[z+1] = thisitem[z]; } @@ -1782,17 +1784,16 @@ else tmpitem[0].vsize = SIZESTATIC; - thisbox.items = tmpitem; + thisbox->items = tmpitem; /* Update the item count */ - thisbox.count++; + thisbox->count++; /* Add the item to the box */ - [view setBox:thisbox]; [view addSubview:this]; /* Free the old data */ - if(thisbox.count) + if(thisbox->count) free(thisitem); } @@ -1812,7 +1813,7 @@ NSObject *object = box; DWBox *view = box; DWBox *this = item; - Box thisbox; + Box *thisbox; int z; Item *tmpitem, *thisitem; @@ -1824,13 +1825,13 @@ } thisbox = [view box]; - thisitem = thisbox.items; + thisitem = thisbox->items; object = item; /* Duplicate the existing data */ - tmpitem = malloc(sizeof(Item)*(thisbox.count+1)); - - for(z=0;zcount+1)); + + for(z=0;zcount;z++) { tmpitem[z] = thisitem[z]; } @@ -1843,35 +1844,34 @@ /* Fill in the item data appropriately */ if([ object isKindOfClass:[ DWBox class ] ]) - tmpitem[thisbox.count].type = TYPEBOX; + tmpitem[thisbox->count].type = TYPEBOX; else - tmpitem[thisbox.count].type = TYPEITEM; - - tmpitem[thisbox.count].hwnd = item; - tmpitem[thisbox.count].origwidth = tmpitem[thisbox.count].width = width; - tmpitem[thisbox.count].origheight = tmpitem[thisbox.count].height = height; - tmpitem[thisbox.count].pad = pad; + tmpitem[thisbox->count].type = TYPEITEM; + + tmpitem[thisbox->count].hwnd = item; + tmpitem[thisbox->count].origwidth = tmpitem[thisbox->count].width = width; + tmpitem[thisbox->count].origheight = tmpitem[thisbox->count].height = height; + tmpitem[thisbox->count].pad = pad; if(hsize) - tmpitem[thisbox.count].hsize = SIZEEXPAND; + tmpitem[thisbox->count].hsize = SIZEEXPAND; else - tmpitem[thisbox.count].hsize = SIZESTATIC; + tmpitem[thisbox->count].hsize = SIZESTATIC; if(vsize) - tmpitem[thisbox.count].vsize = SIZEEXPAND; + tmpitem[thisbox->count].vsize = SIZEEXPAND; else - tmpitem[thisbox.count].vsize = SIZESTATIC; - - thisbox.items = tmpitem; + tmpitem[thisbox->count].vsize = SIZESTATIC; + + thisbox->items = tmpitem; /* Update the item count */ - thisbox.count++; + thisbox->count++; /* Add the item to the box */ - [view setBox:thisbox]; [view addSubview:this]; /* Free the old data */ - if(thisbox.count) + if(thisbox->count) free(thisitem); } @@ -4177,7 +4177,7 @@ DWNotebook *notebook = handle; NSInteger page = [notebook pageid]; DWNotebookPage *notepage = [[DWNotebookPage alloc] initWithIdentifier:nil]; - [notepage setPageid:page]; + [notepage setPageid:(NSInteger)page]; if(front) { [notebook insertTabViewItem:notepage atIndex:(NSInteger)0]; @@ -5892,6 +5892,9 @@ threadfunc = (void (*)(void *))tmp[0]; threadfunc(tmp[1]); +#if !defined(GARBAGE_COLLECT) + [pool release]; +#endif free(tmp); }