# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1300831265 0 # Node ID e328c7746cdacc7a8ccc9269cb59a59c0f4da487 # Parent fc6a626a96ccd48714d1cc335960bb380041d94d Basic code to handle unchecking other radio buttons attached to the same box when one is selected. diff -r fc6a626a96cc -r e328c7746cda mac/dw.m --- a/mac/dw.m Tue Mar 22 21:03:35 2011 +0000 +++ b/mac/dw.m Tue Mar 22 22:01:05 2011 +0000 @@ -602,16 +602,53 @@ @interface DWButton : NSButton { void *userdata; + NSButtonType buttonType; + DWBox *parent; } -(void *)userdata; -(void)setUserdata:(void *)input; -(void)buttonClicked:(id)sender; +-(void)setButtonType:(NSButtonType)input; +-(NSButtonType)buttonType; +-(void)setParent:(DWBox *)input; +-(DWBox *)parent; @end @implementation DWButton -(void *)userdata { return userdata; } -(void)setUserdata:(void *)input { userdata = input; } --(void)buttonClicked:(id)sender { _event_handler(self, nil, 8); } +-(void)buttonClicked:(id)sender +{ + _event_handler(self, nil, 8); + if([self buttonType] == NSRadioButton) + { + DWBox *viewbox = [self parent]; + Box *thisbox = [viewbox box]; + int z; + + for(z=0;zcount;z++) + { + if(thisbox->items[z].type != TYPEBOX) + { + id object = thisbox->items[z].hwnd; + + if([object isMemberOfClass:[DWButton class]]) + { + DWButton *button = object; + + if(button != self && [button buttonType] == NSRadioButton) + { + [button setState:NSOffState]; + } + } + } + } + } +} +-(void)setButtonType:(NSButtonType)input { buttonType = input; [super setButtonType:input]; } +-(NSButtonType)buttonType { return buttonType; } +-(void)setParent:(DWBox *)input { parent = input; } +-(DWBox *)parent { return parent; } -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } @end @@ -1903,11 +1940,6 @@ [stepper setFrameOrigin:NSMakePoint(size.width-20,0)]; [stepper setFrameSize:NSMakeSize(20,size.height)]; } - else if([handle isMemberOfClass:[DWGroupBox class]]) - { - DWGroupBox *groupbox = thisbox->items[z].hwnd; - [groupbox sizeToFit]; - } else if([handle isMemberOfClass:[DWRender class]]) { _event_handler(handle, nil, 1); @@ -2544,6 +2576,16 @@ /* Add the item to the box */ [view addSubview:this]; + /* If we are packing a button... */ + if([this isMemberOfClass:[DWButton class]]) + { + DWButton *button = (DWButton *)this; + + /* Save the parent box so radio + * buttons can use it later. + */ + [button setParent:view]; + } /* Free the old data */ if(thisbox->count) @@ -2637,6 +2679,16 @@ /* Add the item to the box */ [view addSubview:this]; + /* If we are packing a button... */ + if([this isMemberOfClass:[DWButton class]]) + { + DWButton *button = (DWButton *)this; + + /* Save the parent box so radio + * buttons can use it later. + */ + [button setParent:view]; + } /* Free the old data */ if(thisbox->count)