gwenhywfar 5.12.0
CocoaRadioButton.m
Go to the documentation of this file.
1//
2// CocoaRadioButton.m
3// CocoaGwenGuiTest
4//
5// Created by Samuel Strupp on 12.08.10.
6// Copyright 2010 Synium Software GmbH. All rights reserved.
7//
8
9#ifdef HAVE_CONFIG_H
10# include <config.h>
11#endif
12
13
14#import "CocoaRadioButton.h"
15
16
17@implementation CocoaRadioButton
18
19- (id)initWithFrame:(NSRect)frame {
20 self = [super initWithFrame:frame];
21 if (self) {
22 [self setBezelStyle:NSRoundedBezelStyle];
23 [self setButtonType:NSRadioButton];
24 _groupManager = nil;
25 }
26 return self;
27}
28
29-(void) dealloc {
30 if (_groupManager) {
31 [_groupManager removeRadioButton:self];
32 [_groupManager release];
33 }
34 [super dealloc];
35}
36
37-(void) computeMinWidth {
38 NSSize size = [self neededTextSize];
39 minWidth = size.width + 22.0;
40}
41
42-(void) createNewGroupManagerWithGroupID:(NSInteger)newGroupID {
43 if (_groupManager) {
45 [_groupManager release];
46 _groupManager = nil;
47 }
49 _groupManager.groupeID = newGroupID;
51}
52
56
57-(void) setGroupManager:(CocoaRadioGroupManager*) newGroupManager {
58 if (_groupManager) {
60 [_groupManager release];
61 _groupManager = nil;
62 }
63 if (newGroupManager) {
66 }
67}
68
69- (void)setState:(NSInteger)value {
70 if (value == NSOnState && _groupManager) {
71 [_groupManager newOnStateButtonIs:self];
72 }
73 [super setState:value];
74}
75
76-(void) clicked:(id)sender {
77 if ([self state] == NSOnState && _groupManager) {
78 [_groupManager newOnStateButtonIs:self];
79 }
80 [super clicked:sender];
81}
82
83/*- (void)drawRect:(NSRect)dirtyRect {
84 //debug colors
85 [[NSColor blueColor] set];
86 NSRectFill(dirtyRect);
87 [super drawRect:dirtyRect];
88}*/
89
90#pragma mark Protocoll Methods
91
92- (NSSize) minSize {
93 return NSMakeSize(minWidth, 16.0);
94}
95
96@end
97
98
99
100@implementation CocoaRadioGroupManager
101
102@synthesize groupeID;
103
104- (id)init {
105 self = [super init];
106 if (self) {
107 memberRadioButtons = [[NSPointerArray pointerArrayWithWeakObjects] retain];
108 }
109 return self;
110}
111
112-(void) dealloc {
113 [memberRadioButtons release];
114 [super dealloc];
115}
116
117-(void) removeRadioButton:(CocoaRadioButton*)buttonToRemove {
118 NSUInteger i;
119 NSUInteger count = [memberRadioButtons count];
120 NSUInteger foundIndex = count; //ungültiger Index
121 for (i=0; i<count; i++) {
122 if ([memberRadioButtons pointerAtIndex:i] == buttonToRemove) {
123 foundIndex = i;
124 i = count;
125 }
126 }
127 if (foundIndex < count) {
128 [memberRadioButtons removePointerAtIndex:foundIndex];
129 }
130}
131
132-(void) addRadioButton:(CocoaRadioButton*)buttonToAdd {
133 [memberRadioButtons addPointer:buttonToAdd];
134}
135
136-(void) newOnStateButtonIs:(CocoaRadioButton*)newOnStateButton {
138 if (r != newOnStateButton) {
139 [r setState:NSOffState];
140 }
141 }
142}
143
144@end
145
CGFloat minWidth
Definition CocoaButton.h:25
CocoaRadioGroupManager * getGroupManager()
CocoaRadioGroupManager * _groupManager
NSPointerArray * memberRadioButtons
void addRadioButton:(CocoaRadioButton *buttonToAdd)
void removeRadioButton:(CocoaRadioButton *buttonToRemove)