gwenhywfar
4.3.3
|
00001 // 00002 // CocoaRadioButton.m 00003 // CocoaGwenGuiTest 00004 // 00005 // Created by Samuel Strupp on 12.08.10. 00006 // Copyright 2010 Synium Software GmbH. All rights reserved. 00007 // 00008 00009 #ifdef HAVE_CONFIG_H 00010 # include <config.h> 00011 #endif 00012 00013 00014 #import "CocoaRadioButton.h" 00015 00016 00017 @implementation CocoaRadioButton 00018 00019 - (id)initWithFrame:(NSRect)frame { 00020 self = [super initWithFrame:frame]; 00021 if (self) { 00022 [self setBezelStyle:NSRoundedBezelStyle]; 00023 [self setButtonType:NSRadioButton]; 00024 _groupManager = nil; 00025 } 00026 return self; 00027 } 00028 00029 -(void) dealloc { 00030 if (_groupManager) { 00031 [_groupManager removeRadioButton:self]; 00032 [_groupManager release]; 00033 } 00034 [super dealloc]; 00035 } 00036 00037 -(void) computeMinWidth { 00038 NSSize size = [self neededTextSize]; 00039 minWidth = size.width + 22.0; 00040 } 00041 00042 -(void) createNewGroupManagerWithGroupID:(NSInteger)newGroupID { 00043 if (_groupManager) { 00044 [_groupManager removeRadioButton:self]; 00045 [_groupManager release]; 00046 _groupManager = nil; 00047 } 00048 _groupManager = [[CocoaRadioGroupManager alloc] init]; 00049 _groupManager.groupeID = newGroupID; 00050 [_groupManager addRadioButton:self]; 00051 } 00052 00053 -(CocoaRadioGroupManager*) getGroupManager { 00054 return _groupManager; 00055 } 00056 00057 -(void) setGroupManager:(CocoaRadioGroupManager*) newGroupManager { 00058 if (_groupManager) { 00059 [_groupManager removeRadioButton:self]; 00060 [_groupManager release]; 00061 _groupManager = nil; 00062 } 00063 if (newGroupManager) { 00064 _groupManager = [newGroupManager retain]; 00065 [_groupManager addRadioButton:self]; 00066 } 00067 } 00068 00069 - (void)setState:(NSInteger)value { 00070 if (value == NSOnState && _groupManager) { 00071 [_groupManager newOnStateButtonIs:self]; 00072 } 00073 [super setState:value]; 00074 } 00075 00076 -(void) clicked:(id)sender { 00077 if ([self state] == NSOnState && _groupManager) { 00078 [_groupManager newOnStateButtonIs:self]; 00079 } 00080 [super clicked:sender]; 00081 } 00082 00083 /*- (void)drawRect:(NSRect)dirtyRect { 00084 //debug colors 00085 [[NSColor blueColor] set]; 00086 NSRectFill(dirtyRect); 00087 [super drawRect:dirtyRect]; 00088 }*/ 00089 00090 #pragma mark Protocoll Methods 00091 00092 - (NSSize) minSize { 00093 return NSMakeSize(minWidth, 16.0); 00094 } 00095 00096 @end 00097 00098 00099 00100 @implementation CocoaRadioGroupManager 00101 00102 @synthesize groupeID; 00103 00104 - (id)init { 00105 self = [super init]; 00106 if (self) { 00107 memberRadioButtons = [[NSPointerArray pointerArrayWithWeakObjects] retain]; 00108 } 00109 return self; 00110 } 00111 00112 -(void) dealloc { 00113 [memberRadioButtons release]; 00114 [super dealloc]; 00115 } 00116 00117 -(void) removeRadioButton:(CocoaRadioButton*)buttonToRemove { 00118 NSUInteger i; 00119 NSUInteger count = [memberRadioButtons count]; 00120 NSUInteger foundIndex = count; //ungültiger Index 00121 for (i=0; i<count; i++) { 00122 if ([memberRadioButtons pointerAtIndex:i] == buttonToRemove) { 00123 foundIndex = i; 00124 i = count; 00125 } 00126 } 00127 if (foundIndex < count) { 00128 [memberRadioButtons removePointerAtIndex:foundIndex]; 00129 } 00130 } 00131 00132 -(void) addRadioButton:(CocoaRadioButton*)buttonToAdd { 00133 [memberRadioButtons addPointer:buttonToAdd]; 00134 } 00135 00136 -(void) newOnStateButtonIs:(CocoaRadioButton*)newOnStateButton { 00137 for (CocoaRadioButton* r in memberRadioButtons) { 00138 if (r != newOnStateButton) { 00139 [r setState:NSOffState]; 00140 } 00141 } 00142 } 00143 00144 @end 00145