comparison mac/dw.m @ 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
comparison
equal deleted inserted replaced
792:fc6a626a96cc 793:e328c7746cda
600 600
601 /* Subclass for a button type */ 601 /* Subclass for a button type */
602 @interface DWButton : NSButton 602 @interface DWButton : NSButton
603 { 603 {
604 void *userdata; 604 void *userdata;
605 NSButtonType buttonType;
606 DWBox *parent;
605 } 607 }
606 -(void *)userdata; 608 -(void *)userdata;
607 -(void)setUserdata:(void *)input; 609 -(void)setUserdata:(void *)input;
608 -(void)buttonClicked:(id)sender; 610 -(void)buttonClicked:(id)sender;
611 -(void)setButtonType:(NSButtonType)input;
612 -(NSButtonType)buttonType;
613 -(void)setParent:(DWBox *)input;
614 -(DWBox *)parent;
609 @end 615 @end
610 616
611 @implementation DWButton 617 @implementation DWButton
612 -(void *)userdata { return userdata; } 618 -(void *)userdata { return userdata; }
613 -(void)setUserdata:(void *)input { userdata = input; } 619 -(void)setUserdata:(void *)input { userdata = input; }
614 -(void)buttonClicked:(id)sender { _event_handler(self, nil, 8); } 620 -(void)buttonClicked:(id)sender
621 {
622 _event_handler(self, nil, 8);
623 if([self buttonType] == NSRadioButton)
624 {
625 DWBox *viewbox = [self parent];
626 Box *thisbox = [viewbox box];
627 int z;
628
629 for(z=0;z<thisbox->count;z++)
630 {
631 if(thisbox->items[z].type != TYPEBOX)
632 {
633 id object = thisbox->items[z].hwnd;
634
635 if([object isMemberOfClass:[DWButton class]])
636 {
637 DWButton *button = object;
638
639 if(button != self && [button buttonType] == NSRadioButton)
640 {
641 [button setState:NSOffState];
642 }
643 }
644 }
645 }
646 }
647 }
648 -(void)setButtonType:(NSButtonType)input { buttonType = input; [super setButtonType:input]; }
649 -(NSButtonType)buttonType { return buttonType; }
650 -(void)setParent:(DWBox *)input { parent = input; }
651 -(DWBox *)parent { return parent; }
615 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } 652 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; }
616 @end 653 @end
617 654
618 /* Subclass for a progress type */ 655 /* Subclass for a progress type */
619 @interface DWPercent : NSProgressIndicator 656 @interface DWPercent : NSProgressIndicator
1901 [textfield setFrameOrigin:NSMakePoint(0,0)]; 1938 [textfield setFrameOrigin:NSMakePoint(0,0)];
1902 [textfield setFrameSize:NSMakeSize(size.width-20,size.height)]; 1939 [textfield setFrameSize:NSMakeSize(size.width-20,size.height)];
1903 [stepper setFrameOrigin:NSMakePoint(size.width-20,0)]; 1940 [stepper setFrameOrigin:NSMakePoint(size.width-20,0)];
1904 [stepper setFrameSize:NSMakeSize(20,size.height)]; 1941 [stepper setFrameSize:NSMakeSize(20,size.height)];
1905 } 1942 }
1906 else if([handle isMemberOfClass:[DWGroupBox class]])
1907 {
1908 DWGroupBox *groupbox = thisbox->items[z].hwnd;
1909 [groupbox sizeToFit];
1910 }
1911 else if([handle isMemberOfClass:[DWRender class]]) 1943 else if([handle isMemberOfClass:[DWRender class]])
1912 { 1944 {
1913 _event_handler(handle, nil, 1); 1945 _event_handler(handle, nil, 1);
1914 } 1946 }
1915 else if([handle isMemberOfClass:[DWSplitBar class]] && size.width > 20 && size.height > 20) 1947 else if([handle isMemberOfClass:[DWSplitBar class]] && size.width > 20 && size.height > 20)
2542 /* Update the item count */ 2574 /* Update the item count */
2543 thisbox->count++; 2575 thisbox->count++;
2544 2576
2545 /* Add the item to the box */ 2577 /* Add the item to the box */
2546 [view addSubview:this]; 2578 [view addSubview:this];
2579 /* If we are packing a button... */
2580 if([this isMemberOfClass:[DWButton class]])
2581 {
2582 DWButton *button = (DWButton *)this;
2583
2584 /* Save the parent box so radio
2585 * buttons can use it later.
2586 */
2587 [button setParent:view];
2588 }
2547 2589
2548 /* Free the old data */ 2590 /* Free the old data */
2549 if(thisbox->count) 2591 if(thisbox->count)
2550 free(thisitem); 2592 free(thisitem);
2551 DW_MUTEX_UNLOCK; 2593 DW_MUTEX_UNLOCK;
2635 /* Update the item count */ 2677 /* Update the item count */
2636 thisbox->count++; 2678 thisbox->count++;
2637 2679
2638 /* Add the item to the box */ 2680 /* Add the item to the box */
2639 [view addSubview:this]; 2681 [view addSubview:this];
2682 /* If we are packing a button... */
2683 if([this isMemberOfClass:[DWButton class]])
2684 {
2685 DWButton *button = (DWButton *)this;
2686
2687 /* Save the parent box so radio
2688 * buttons can use it later.
2689 */
2690 [button setParent:view];
2691 }
2640 2692
2641 /* Free the old data */ 2693 /* Free the old data */
2642 if(thisbox->count) 2694 if(thisbox->count)
2643 free(thisitem); 2695 free(thisitem);
2644 DW_MUTEX_UNLOCK; 2696 DW_MUTEX_UNLOCK;