gwenhywfar  4.7.0beta
w_radiobutton.mm
Go to the documentation of this file.
1 /***************************************************************************
2  begin : Aug 10 2010
3  copyright : (C) 2010 by Samuel Strupp
4 
5  ***************************************************************************
6  * Please see toplevel file COPYING for license details *
7  ***************************************************************************/
8 
9 
10 #import "CocoaRadioButton.h"
11 
12 
13 static GWENHYWFAR_CB
16  int index,
17  int value,
18  int doSignal) {
19  NSButton *radioButton;
20 
21  radioButton = (NSButton*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
22  assert(radioButton);
23 
24  switch(prop) {
26  [radioButton setEnabled:(value==0)?NO:YES];
27  return 0;
28 
30  if ([radioButton window]) {
31  [[radioButton window] makeFirstResponder:radioButton];
32  }
33  return 0;
34 
36  NSRect frame = [radioButton frame];
37  frame.size.width = value;
38  [radioButton setFrame:frame];
39  }
40  return 0;
41 
43  NSRect frame = [radioButton frame];
44  frame.size.height = value;
45  [radioButton setFrame:frame];
46  }
47  return 0;
48 
50  if (value==0) [radioButton setState:NSOffState];
51  else [radioButton setState:NSOnState];
52  }
53  return 0;
54 
55  default:
56  break;
57  }
58 
60  "Function is not appropriate for this type of widget (%s)",
62  return GWEN_ERROR_INVALID;
63 }
64 
65 
66 
67 
68 static GWENHYWFAR_CB
71  int index,
72  int defaultValue) {
73  NSButton *radioButton;
74 
75  radioButton = (NSButton*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
76  assert(radioButton);
77 
78  switch(prop) {
80  return ([radioButton isEnabled]==YES)?1:0;
81 
83  if ([radioButton window]) {
84  if ([[radioButton window] firstResponder] == radioButton) return 1;
85  }
86  return 0;
87 
89  return [radioButton frame].size.width;
90 
92  return [radioButton frame].size.height;
93 
95  return ([radioButton state]==NSOnState)?1:0;
96 
97  default:
98  break;
99  }
100 
102  "Function is not appropriate for this type of widget (%s)",
104  return defaultValue;
105 }
106 
107 
108 
109 static GWENHYWFAR_CB
112  int index,
113  const char *value,
114  int doSignal) {
115  NSButton *radioButton;
116 
117  radioButton = (NSButton*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
118  assert(radioButton);
119 
120  switch(prop) {
122  NSString *stringValue = [[NSString alloc] initWithCString:value encoding:NSUTF8StringEncoding];
123  [radioButton setTitle:stringValue];
124  [stringValue release];
125  }
126  return 0;
127  default:
128  break;
129  }
130 
132  "Function is not appropriate for this type of widget (%s)",
134  return GWEN_ERROR_INVALID;
135 }
136 
137 
138 
139 static GWENHYWFAR_CB
142  int index,
143  const char *defaultValue) {
144  NSButton *radioButton;
145 
146  radioButton = (NSButton*)(GWEN_Widget_GetImplData(w, COCOA_DIALOG_WIDGET_REAL));
147  assert(radioButton);
148 
149  switch(prop) {
151  return [[radioButton stringValue] cStringUsingEncoding:NSUTF8StringEncoding];
152  default:
153  break;
154  }
155 
157  "Function is not appropriate for this type of widget (%s)",
159  return defaultValue;
160 }
161 
162 
163 
164 static void CocoaGui_WRadioButton_Toggled_handler(NSButton *button, void* data) {
165  GWEN_WIDGET *w;
166  int rv;
167 
168  DBG_ERROR(0, "Toggled");
169  w=data;
170  assert(w);
176  else if (rv==GWEN_DialogEvent_ResultReject)
178 }
179 
180 
181 
183  CocoaRadioButton *radioButton;
184  const char *s;
185  uint32_t flags;
186  GWEN_WIDGET *wParent;
187 
188  GWEN_WIDGET *wT;
189  int groupId;
190 
191  flags=GWEN_Widget_GetFlags(w);
192  wParent=GWEN_Widget_Tree_GetParent(w);
193  groupId=GWEN_Widget_GetGroupId(w);
194 
195  s=GWEN_Widget_GetText(w, 0);
196 
197  //Create Button
198  radioButton = [[[CocoaRadioButton alloc] initWithFrame:NSMakeRect(0.0, 0.0, 60.0, 24.0)] autorelease];
199  if (flags & GWEN_WIDGET_FLAGS_FILLX) radioButton.fillX = YES;
200  if (flags & GWEN_WIDGET_FLAGS_FILLY) radioButton.fillY = YES;
201  if (s && *s) {
202  NSString *title = [[NSString alloc] initWithCString:s encoding:NSUTF8StringEncoding];
203  [radioButton setTitle:title];
204  [title release];
205  }
206 
207  /* get root widget */
208  wT=wParent;
209  while(GWEN_Widget_Tree_GetParent(wT))
210  wT=GWEN_Widget_Tree_GetParent(wT);
211 
212  // get first radio button of the same group
213  while(wT) {
215  GWEN_Widget_GetGroupId(wT)==groupId)
216  break;
217  wT=GWEN_Widget_Tree_GetBelow(wT);
218  }
219 
220  if (wT && wT!=w) {
222  [radioButton setGroupManager:[sameGroupRadioButton getGroupManager]];
223  }
224  else {
225  [radioButton createNewGroupManagerWithGroupID:groupId];
226  }
227 
228 
229  // set pointers
230  GWEN_Widget_SetImplData(w, COCOA_DIALOG_WIDGET_REAL, (void*) radioButton);
231  GWEN_Widget_SetImplData(w, COCOA_DIALOG_WIDGET_CONTENT, (void*) radioButton);
232 
237 
239  [radioButton setC_ActionPtr:ptr Data:w];
240 
241  if (wParent)
242  GWEN_Widget_AddChildGuiWidget(wParent, w);
243 
244  return 0;
245 }
246 
247