changeset 793:e328c7746cda

Basic code to handle unchecking other radio buttons attached to the same box when one is selected.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 22 Mar 2011 22:01:05 +0000
parents fc6a626a96cc
children e9bc14c5c72d
files mac/dw.m
diffstat 1 files changed, 58 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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;z<thisbox->count;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)