Mercurial > dwindows
comparison mac/dw.m @ 1313:9f12bc79924b
Autorelease fixes for Mac allowing the objects to dealloc when destroyed.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 04 Nov 2011 12:30:23 +0000 |
parents | c5db6c70905c |
children | c969db49606e |
comparison
equal
deleted
inserted
replaced
1312:c5db6c70905c | 1313:9f12bc79924b |
---|---|
3003 * Parameters: | 3003 * Parameters: |
3004 * exitcode: Exit code reported to the operating system. | 3004 * exitcode: Exit code reported to the operating system. |
3005 */ | 3005 */ |
3006 void API dw_exit(int exitcode) | 3006 void API dw_exit(int exitcode) |
3007 { | 3007 { |
3008 _dw_pool_drain(); | |
3008 exit(exitcode); | 3009 exit(exitcode); |
3009 } | 3010 } |
3010 | 3011 |
3011 /* | 3012 /* |
3012 * Free's memory allocated by dynamic windows. | 3013 * Free's memory allocated by dynamic windows. |
3411 | 3412 |
3412 [groupbox setBorderType:NSBezelBorder]; | 3413 [groupbox setBorderType:NSBezelBorder]; |
3413 [groupbox setTitle:[NSString stringWithUTF8String:title]]; | 3414 [groupbox setTitle:[NSString stringWithUTF8String:title]]; |
3414 box->grouphwnd = groupbox; | 3415 box->grouphwnd = groupbox; |
3415 [groupbox setContentView:thisbox]; | 3416 [groupbox setContentView:thisbox]; |
3417 [thisbox autorelease]; | |
3416 return groupbox; | 3418 return groupbox; |
3417 } | 3419 } |
3418 | 3420 |
3419 /* | 3421 /* |
3420 * Create a new scrollable Box to be packed. | 3422 * Create a new scrollable Box to be packed. |
3432 [scrollbox setHasHorizontalScroller:YES]; | 3434 [scrollbox setHasHorizontalScroller:YES]; |
3433 [scrollbox setBorderType:NSNoBorder]; | 3435 [scrollbox setBorderType:NSNoBorder]; |
3434 [scrollbox setDrawsBackground:NO]; | 3436 [scrollbox setDrawsBackground:NO]; |
3435 [scrollbox setBox:box]; | 3437 [scrollbox setBox:box]; |
3436 [scrollbox setDocumentView:tmpbox]; | 3438 [scrollbox setDocumentView:tmpbox]; |
3439 [tmpbox autorelease]; | |
3437 return scrollbox; | 3440 return scrollbox; |
3438 } | 3441 } |
3439 | 3442 |
3440 /* | 3443 /* |
3441 * Returns the position of the scrollbar in the scrollbox | 3444 * Returns the position of the scrollbar in the scrollbox |
3595 /* Update the item count */ | 3598 /* Update the item count */ |
3596 thisbox->count++; | 3599 thisbox->count++; |
3597 | 3600 |
3598 /* Add the item to the box */ | 3601 /* Add the item to the box */ |
3599 [view addSubview:this]; | 3602 [view addSubview:this]; |
3603 /* Enable autorelease on the item... | |
3604 * so it will get destroyed when the parent is. | |
3605 */ | |
3606 [this autorelease]; | |
3600 /* If we are packing a button... */ | 3607 /* If we are packing a button... */ |
3601 if([this isMemberOfClass:[DWButton class]]) | 3608 if([this isMemberOfClass:[DWButton class]]) |
3602 { | 3609 { |
3603 DWButton *button = (DWButton *)this; | 3610 DWButton *button = (DWButton *)this; |
3604 | 3611 |
3838 [stepper setTag:cid]; | 3845 [stepper setTag:cid]; |
3839 [stepper setMinValue:-65536]; | 3846 [stepper setMinValue:-65536]; |
3840 [stepper setMaxValue:65536]; | 3847 [stepper setMaxValue:65536]; |
3841 [stepper setIntValue:atoi(text)]; | 3848 [stepper setIntValue:atoi(text)]; |
3842 [textfield takeIntValueFrom:stepper]; | 3849 [textfield takeIntValueFrom:stepper]; |
3850 [stepper autorelease]; | |
3851 [textfield autorelease]; | |
3843 return spinbutton; | 3852 return spinbutton; |
3844 } | 3853 } |
3845 | 3854 |
3846 /* | 3855 /* |
3847 * Sets the spinbutton value. | 3856 * Sets the spinbutton value. |
4130 } | 4139 } |
4131 [cont setDataSource:cont]; | 4140 [cont setDataSource:cont]; |
4132 [cont setDelegate:cont]; | 4141 [cont setDelegate:cont]; |
4133 [scrollview setDocumentView:cont]; | 4142 [scrollview setDocumentView:cont]; |
4134 [cont setTag:cid]; | 4143 [cont setTag:cid]; |
4144 [cont autorelease]; | |
4135 return cont; | 4145 return cont; |
4136 } | 4146 } |
4137 | 4147 |
4138 /* | 4148 /* |
4139 * Create a new listbox window (widget) to be packed. | 4149 * Create a new listbox window (widget) to be packed. |
4584 [scrollview setAutohidesScrollers:YES]; | 4594 [scrollview setAutohidesScrollers:YES]; |
4585 [scrollview setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable]; | 4595 [scrollview setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable]; |
4586 [scrollview setDocumentView:mle]; | 4596 [scrollview setDocumentView:mle]; |
4587 [mle setAutoresizingMask:NSViewWidthSizable]; | 4597 [mle setAutoresizingMask:NSViewWidthSizable]; |
4588 /* [mle setTag:cid]; Why doesn't this work? */ | 4598 /* [mle setTag:cid]; Why doesn't this work? */ |
4589 [mle release]; | 4599 [mle autorelease]; |
4590 return scrollview; | 4600 return scrollview; |
4591 } | 4601 } |
4592 | 4602 |
4593 /* | 4603 /* |
4594 * Adds text to an MLE box and returns the current point. | 4604 * Adds text to an MLE box and returns the current point. |
5431 [tree setDataSource:tree]; | 5441 [tree setDataSource:tree]; |
5432 [tree setDelegate:tree]; | 5442 [tree setDelegate:tree]; |
5433 [scrollview setDocumentView:tree]; | 5443 [scrollview setDocumentView:tree]; |
5434 [tree setHeaderView:nil]; | 5444 [tree setHeaderView:nil]; |
5435 [tree setTag:cid]; | 5445 [tree setTag:cid]; |
5446 [tree autorelease]; | |
5436 DW_MUTEX_UNLOCK; | 5447 DW_MUTEX_UNLOCK; |
5437 return tree; | 5448 return tree; |
5438 } | 5449 } |
5439 | 5450 |
5440 /* | 5451 /* |
6434 * Returns: | 6445 * Returns: |
6435 * A handle to a splitbar window or NULL on failure. | 6446 * A handle to a splitbar window or NULL on failure. |
6436 */ | 6447 */ |
6437 HWND API dw_splitbar_new(int type, HWND topleft, HWND bottomright, unsigned long cid) | 6448 HWND API dw_splitbar_new(int type, HWND topleft, HWND bottomright, unsigned long cid) |
6438 { | 6449 { |
6439 HWND tmpbox = dw_box_new(DW_VERT, 0); | 6450 id tmpbox = dw_box_new(DW_VERT, 0); |
6440 int _locked_by_me = FALSE; | 6451 int _locked_by_me = FALSE; |
6441 DW_MUTEX_LOCK; | 6452 DW_MUTEX_LOCK; |
6442 DWSplitBar *split = [[DWSplitBar alloc] init]; | 6453 DWSplitBar *split = [[DWSplitBar alloc] init]; |
6443 [split setDelegate:split]; | 6454 [split setDelegate:split]; |
6444 dw_box_pack_start(tmpbox, topleft, 0, 0, TRUE, TRUE, 0); | 6455 dw_box_pack_start(tmpbox, topleft, 0, 0, TRUE, TRUE, 0); |
6445 [split addSubview:tmpbox]; | 6456 [split addSubview:tmpbox]; |
6457 [tmpbox autorelease]; | |
6446 tmpbox = dw_box_new(DW_VERT, 0); | 6458 tmpbox = dw_box_new(DW_VERT, 0); |
6447 dw_box_pack_start(tmpbox, bottomright, 0, 0, TRUE, TRUE, 0); | 6459 dw_box_pack_start(tmpbox, bottomright, 0, 0, TRUE, TRUE, 0); |
6448 [split addSubview:tmpbox]; | 6460 [split addSubview:tmpbox]; |
6461 [tmpbox autorelease]; | |
6449 if(type == DW_VERT) | 6462 if(type == DW_VERT) |
6450 { | 6463 { |
6451 [split setVertical:NO]; | 6464 [split setVertical:NO]; |
6452 } | 6465 } |
6453 else | 6466 else |
7047 * id: An ID to be used for getting the resource from the | 7060 * id: An ID to be used for getting the resource from the |
7048 * resource file. | 7061 * resource file. |
7049 */ | 7062 */ |
7050 HMENUI API dw_menu_new(ULONG cid) | 7063 HMENUI API dw_menu_new(ULONG cid) |
7051 { | 7064 { |
7052 NSMenu *menu = [[[NSMenu alloc] init] autorelease]; | 7065 NSMenu *menu = [[NSMenu alloc] init]; |
7053 [menu setAutoenablesItems:NO]; | 7066 [menu setAutoenablesItems:NO]; |
7054 /* [menu setTag:cid]; Why doesn't this work? */ | 7067 /* [menu setTag:cid]; Why doesn't this work? */ |
7055 return menu; | 7068 return menu; |
7056 } | 7069 } |
7057 | 7070 |
7094 NSView *view = [object isKindOfClass:[NSWindow class]] ? [object contentView] : parent; | 7107 NSView *view = [object isKindOfClass:[NSWindow class]] ? [object contentView] : parent; |
7095 NSWindow *window = [view window]; | 7108 NSWindow *window = [view window]; |
7096 NSEvent *event = [DWApp currentEvent]; | 7109 NSEvent *event = [DWApp currentEvent]; |
7097 if(!window) | 7110 if(!window) |
7098 window = [event window]; | 7111 window = [event window]; |
7112 [thismenu autorelease]; | |
7099 NSPoint p = NSMakePoint(x, [[NSScreen mainScreen] frame].size.height - y); | 7113 NSPoint p = NSMakePoint(x, [[NSScreen mainScreen] frame].size.height - y); |
7100 NSEvent* fake = [NSEvent mouseEventWithType:NSRightMouseDown | 7114 NSEvent* fake = [NSEvent mouseEventWithType:NSRightMouseDown |
7101 location:[window convertScreenToBase:p] | 7115 location:[window convertScreenToBase:p] |
7102 modifierFlags:0 | 7116 modifierFlags:0 |
7103 timestamp:[event timestamp] | 7117 timestamp:[event timestamp] |
7161 accel[1] = 0; | 7175 accel[1] = 0; |
7162 | 7176 |
7163 nstr = [ NSString stringWithUTF8String:newtitle ]; | 7177 nstr = [ NSString stringWithUTF8String:newtitle ]; |
7164 free(newtitle); | 7178 free(newtitle); |
7165 | 7179 |
7166 item = [[DWMenuItem alloc] initWithTitle:nstr | 7180 item = [[[DWMenuItem alloc] initWithTitle:nstr |
7167 action:@selector(menuHandler:) | 7181 action:@selector(menuHandler:) |
7168 keyEquivalent:[ NSString stringWithUTF8String:accel ]]; | 7182 keyEquivalent:[ NSString stringWithUTF8String:accel ]] autorelease]; |
7169 [menu addItem:item]; | 7183 [menu addItem:item]; |
7170 | 7184 |
7171 [item setTag:itemid]; | 7185 [item setTag:itemid]; |
7172 if(flags & DW_MIS_CHECKED) | 7186 if(flags & DW_MIS_CHECKED) |
7173 { | 7187 { |
7295 } | 7309 } |
7296 else | 7310 else |
7297 { | 7311 { |
7298 [notebook addTabViewItem:notepage]; | 7312 [notebook addTabViewItem:notepage]; |
7299 } | 7313 } |
7314 [notepage autorelease]; | |
7300 [notebook setPageid:(int)(page+1)]; | 7315 [notebook setPageid:(int)(page+1)]; |
7301 return (unsigned long)page; | 7316 return (unsigned long)page; |
7302 } | 7317 } |
7303 | 7318 |
7304 /* | 7319 /* |
7936 id object = handle; | 7951 id object = handle; |
7937 | 7952 |
7938 /* Handle destroying a top-levle window */ | 7953 /* Handle destroying a top-levle window */ |
7939 if([ object isKindOfClass:[ NSWindow class ] ]) | 7954 if([ object isKindOfClass:[ NSWindow class ] ]) |
7940 { | 7955 { |
7941 NSWindow *window = handle; | 7956 DWWindow *window = handle; |
7942 [window close]; | 7957 [window close]; |
7943 } | 7958 } |
7944 /* Handle destroying a control or box */ | 7959 /* Handle destroying a control or box */ |
7945 else if([object isKindOfClass:[DWBox class]] || [object isKindOfClass:[DWGroupBox class]] || [object isKindOfClass:[NSControl class]]) | 7960 else if([object isKindOfClass:[DWBox class]] || [object isKindOfClass:[DWGroupBox class]] || [object isKindOfClass:[NSControl class]]) |
7946 { | 7961 { |